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_mut(&mut self) -> &mut Self::Context {
32 self.ctx()
33 }
34
35 fn ctx_ref(&self) -> &Self::Context;
37
38 fn ctx_instructions(&mut self) -> (&mut Self::Context, &mut Self::Instructions);
41
42 fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles);
45}
46
47impl<CTX, INSP, I, P> EvmTr for Evm<CTX, INSP, I, P>
48where
49 CTX: ContextTr,
50 I: InstructionProvider<
51 Context = CTX,
52 InterpreterTypes: InterpreterTypes<Output = InterpreterAction>,
53 >,
54 P: PrecompileProvider<CTX>,
55{
56 type Context = CTX;
57 type Instructions = I;
58 type Precompiles = P;
59
60 #[inline]
61 fn run_interpreter(
62 &mut self,
63 interpreter: &mut Interpreter<
64 <Self::Instructions as InstructionProvider>::InterpreterTypes,
65 >,
66 ) -> <<Self::Instructions as InstructionProvider>::InterpreterTypes as InterpreterTypes>::Output
67 {
68 let context = &mut self.ctx;
69 let instructions = &mut self.instruction;
70 interpreter.run_plain(instructions.instruction_table(), context)
71 }
72 #[inline]
73 fn ctx(&mut self) -> &mut Self::Context {
74 &mut self.ctx
75 }
76
77 #[inline]
78 fn ctx_ref(&self) -> &Self::Context {
79 &self.ctx
80 }
81
82 #[inline]
83 fn ctx_instructions(&mut self) -> (&mut Self::Context, &mut Self::Instructions) {
84 (&mut self.ctx, &mut self.instruction)
85 }
86
87 #[inline]
88 fn ctx_precompiles(&mut self) -> (&mut Self::Context, &mut Self::Precompiles) {
89 (&mut self.ctx, &mut self.precompiles)
90 }
91}