evm_interpreter/interpreter/
mod.rs

1mod etable;
2mod valids;
3
4use alloc::{boxed::Box, vec::Vec};
5
6pub use self::etable::EtableInterpreter;
7pub use self::valids::Valids;
8
9use crate::{Capture, ExitError, ExitResult};
10
11/// Control state.
12#[derive(Eq, PartialEq, Debug)]
13pub enum Control<Trap> {
14	/// No action.
15	NoAction,
16	/// Continue the execution, increase the PC by N.
17	Continue(usize),
18	/// Exit the execution.
19	Exit(ExitResult),
20	/// Jump to the specified PC.
21	Jump(usize),
22	/// Trapping the execution with the possibility to resume.
23	Trap(Box<Trap>),
24}
25
26/// An interpreter.
27pub trait Interpreter<H> {
28	/// Interpreter state.
29	type State;
30	/// Interpreter trap.
31	type Trap;
32
33	/// Deconstruct the interpreter.
34	fn deconstruct(self) -> (Self::State, Vec<u8>);
35	/// Get a reference to the internal state.
36	fn state(&self) -> &Self::State;
37	/// Get a mutable reference to the internal state.
38	fn state_mut(&mut self) -> &mut Self::State;
39	/// Run the interpreter.
40	fn run(&mut self, handle: &mut H) -> Capture<ExitResult, Self::Trap>;
41}
42
43/// Trap feedback for an interpreter.
44pub trait FeedbackInterpreter<H, Feedback>: Interpreter<H> {
45	/// Feedback to the interpreter.
46	fn feedback(&mut self, feedback: Feedback, handler: &mut H) -> Result<(), ExitError>;
47}
48
49/// An interpreter that allows single stepping.
50pub trait StepInterpreter<H>: Interpreter<H> {
51	/// Step the interpreter.
52	fn step(&mut self, handle: &mut H) -> Result<(), Capture<ExitResult, Self::Trap>>;
53}