-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use interpreter::{ | ||
table::{make_instruction_table, InstructionTable}, | ||
Host, Interpreter, InterpreterAction, InterpreterTypes, | ||
}; | ||
use std::boxed::Box; | ||
|
||
pub trait InstructionExecutor: Clone + Default { | ||
type InterpreterTypes: InterpreterTypes; | ||
type CTX; | ||
type Output; | ||
|
||
fn run( | ||
&mut self, | ||
context: &mut Self::CTX, | ||
interpreter: &mut Interpreter<Self::InterpreterTypes>, | ||
) -> Self::Output; | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct EthInstructionExecutor<WIRE: InterpreterTypes, HOST> { | ||
instruction_table: Box<InstructionTable<WIRE, HOST>>, | ||
} | ||
|
||
pub trait InstructionExecutorGetter { | ||
type InstructionExecutor: InstructionExecutor; | ||
|
||
fn executor(&mut self) -> &mut Self::InstructionExecutor; | ||
} | ||
|
||
impl<WIRE, HOST> Clone for EthInstructionExecutor<WIRE, HOST> | ||
where | ||
WIRE: InterpreterTypes, | ||
{ | ||
fn clone(&self) -> Self { | ||
Self { | ||
instruction_table: self.instruction_table.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl<WIRE, HOST> EthInstructionExecutor<WIRE, HOST> | ||
where | ||
WIRE: InterpreterTypes, | ||
HOST: Host, | ||
{ | ||
pub fn new() -> Self { | ||
Self { | ||
instruction_table: Box::new(make_instruction_table::<WIRE, HOST>()), | ||
} | ||
} | ||
} | ||
|
||
impl<IT, CTX> InstructionExecutor for EthInstructionExecutor<IT, CTX> | ||
where | ||
IT: InterpreterTypes, | ||
CTX: Host, | ||
{ | ||
type InterpreterTypes = IT; | ||
type CTX = CTX; | ||
/// TODO Interpreter action could be tied to InterpreterTypes so we can | ||
/// set custom actions from instructions. | ||
type Output = InterpreterAction; | ||
|
||
fn run( | ||
&mut self, | ||
context: &mut Self::CTX, | ||
interpreter: &mut Interpreter<Self::InterpreterTypes>, | ||
) -> Self::Output { | ||
interpreter.run_plain(&self.instruction_table, context) | ||
} | ||
} | ||
|
||
impl<WIRE, HOST> Default for EthInstructionExecutor<WIRE, HOST> | ||
where | ||
WIRE: InterpreterTypes, | ||
HOST: Host, | ||
{ | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters