1use crate::{instructions::InstructionProvider, PrecompileProvider};
2use auto_impl::auto_impl;
3use context::{ContextTr, Evm};
4use interpreter::{Interpreter, InterpreterAction, InterpreterTypes};
5
6#[auto_impl(&mut, Box)]
10pub trait EvmTr {
11 type Context: ContextTr;
13 type Instructions: InstructionProvider;
15 type Precompiles: PrecompileProvider<Self::Context>;
17
18 fn run_interpreter(
21 &mut self,
22 interpreter: &mut Interpreter<
23 <Self::Instructions as InstructionProvider>::InterpreterTypes,
24 >,
25 ) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output;
26
27 fn ctx(&mut self) -> &mut Self::Context;
29
30 fn ctx_ref(&self) -> &Self::Context;
32
33 fn ctx_instructions(&mut self) -> (&mut Self::Context, &mut Self::Instructions);
36
37 fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles);
40}
41
42impl<CTX, INSP, I, P> EvmTr for Evm<CTX, INSP, I, P>
43where
44 CTX: ContextTr,
45 I: InstructionProvider<
46 Context = CTX,
47 InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
48 >,
49 P: PrecompileProvider<CTX>,
50{
51 type Context = CTX;
52 type Instructions = I;
53 type Precompiles = P;
54
55 #[inline]
56 fn run_interpreter(
57 &mut self,
58 interpreter: &mut Interpreter<
59 <Self::Instructions as InstructionProvider>::InterpreterTypes,
60 >,
61 ) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
62 {
63 let context = &mut self.ctx;
64 let instructions = &mut self.instruction;
65 interpreter.run_plain(instructions.instruction_table(), context)
66 }
67 #[inline]
68 fn ctx(&mut self) -> &mut Self::Context {
69 &mut self.ctx
70 }
71
72 #[inline]
73 fn ctx_ref(&self) -> &Self::Context {
74 &self.ctx
75 }
76
77 #[inline]
78 fn ctx_instructions(&mut self) -> (&mut Self::Context, &mut Self::Instructions) {
79 (&mut self.ctx, &mut self.instruction)
80 }
81
82 #[inline]
83 fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles) {
84 (&mut self.ctx, &mut self.precompiles)
85 }
86}