Skip to content

Commit

Permalink
Remove unnecessary S generic in EtableInterpreter and EtableResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas committed Dec 6, 2023
1 parent 713c737 commit 65b8dd2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
40 changes: 20 additions & 20 deletions interpreter/src/interpreter/etable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@ use crate::{
use alloc::vec::Vec;
use core::ops::{Deref, DerefMut};

pub struct EtableInterpreter<'etable, S, ES> {
pub struct EtableInterpreter<'etable, ES: EtableSet> {
valids: Valids,
position: usize,
machine: Machine<S>,
machine: Machine<ES::State>,
etable: &'etable ES,
}

impl<'etable, S, ES> Deref for EtableInterpreter<'etable, S, ES> {
type Target = Machine<S>;
impl<'etable, ES: EtableSet> Deref for EtableInterpreter<'etable, ES> {
type Target = Machine<ES::State>;

fn deref(&self) -> &Machine<S> {
fn deref(&self) -> &Machine<ES::State> {
&self.machine
}
}

impl<'etable, S, ES> DerefMut for EtableInterpreter<'etable, S, ES> {
fn deref_mut(&mut self) -> &mut Machine<S> {
impl<'etable, ES: EtableSet> DerefMut for EtableInterpreter<'etable, ES> {
fn deref_mut(&mut self) -> &mut Machine<ES::State> {
&mut self.machine
}
}

impl<'etable, S, ES> EtableInterpreter<'etable, S, ES>
impl<'etable, ES> EtableInterpreter<'etable, ES>
where
ES: EtableSet<State = S>,
ES: EtableSet,
{
/// Return a reference of the program counter.
pub const fn position(&self) -> usize {
self.position
}

pub fn new(machine: Machine<S>, etable: &'etable ES) -> Self {
pub fn new(machine: Machine<ES::State>, etable: &'etable ES) -> Self {
let valids = Valids::new(&machine.code[..]);

Self {
Expand All @@ -47,7 +47,7 @@ where
}
}

pub fn deconstruct(self) -> Machine<S> {
pub fn deconstruct(self) -> Machine<ES::State> {
self.machine
}

Expand Down Expand Up @@ -84,18 +84,18 @@ where
}
}

impl<'etable, S, ES> Interpreter for EtableInterpreter<'etable, S, ES> {
type State = S;
impl<'etable, ES: EtableSet> Interpreter for EtableInterpreter<'etable, ES> {
type State = ES::State;

fn machine(&self) -> &Machine<S> {
fn machine(&self) -> &Machine<ES::State> {
&self.machine
}

fn machine_mut(&mut self) -> &mut Machine<S> {
fn machine_mut(&mut self) -> &mut Machine<ES::State> {
&mut self.machine
}

fn deconstruct(self) -> (S, Vec<u8>) {
fn deconstruct(self) -> (ES::State, Vec<u8>) {
(self.machine.state, self.machine.retval)
}

Expand All @@ -108,9 +108,9 @@ impl<'etable, S, ES> Interpreter for EtableInterpreter<'etable, S, ES> {
}
}

impl<'etable, S, H, Tr, ES> RunInterpreter<H, Tr> for EtableInterpreter<'etable, S, ES>
impl<'etable, H, Tr, ES> RunInterpreter<H, Tr> for EtableInterpreter<'etable, ES>
where
ES: EtableSet<State = S, Handle = H, Trap = Tr>,
ES: EtableSet<Handle = H, Trap = Tr>,
{
fn run(&mut self, handle: &mut H) -> Capture<ExitResult, Tr> {
loop {
Expand All @@ -122,9 +122,9 @@ where
}
}

impl<'etable, S, H, Tr, ES> StepInterpreter<H, Tr> for EtableInterpreter<'etable, S, ES>
impl<'etable, H, Tr, ES> StepInterpreter<H, Tr> for EtableInterpreter<'etable, ES>
where
ES: EtableSet<State = S, Handle = H, Trap = Tr>,
ES: EtableSet<Handle = H, Trap = Tr>,
{
#[inline]
fn step(&mut self, handle: &mut H) -> Result<(), Capture<ExitResult, Tr>> {
Expand Down
33 changes: 15 additions & 18 deletions src/standard/invoker/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
RuntimeState,
};
use alloc::{rc::Rc, vec::Vec};
use core::marker::PhantomData;
use primitive_types::H160;

/// A code resolver.
Expand Down Expand Up @@ -64,15 +63,14 @@ impl<S, H> PrecompileSet<S, H> for () {

/// The standard code resolver where the color is an [Etable]. This is usually
/// what you need.
pub struct EtableResolver<'config, 'precompile, 'etable, S, Pre, ES> {
pub struct EtableResolver<'config, 'precompile, 'etable, Pre, ES> {
config: &'config Config,
etable: &'etable ES,
precompiles: &'precompile Pre,
_marker: PhantomData<S>,
}

impl<'config, 'precompile, 'etable, S, Pre, ES>
EtableResolver<'config, 'precompile, 'etable, S, Pre, ES>
impl<'config, 'precompile, 'etable, Pre, ES>
EtableResolver<'config, 'precompile, 'etable, Pre, ES>
{
pub fn new(
config: &'config Config,
Expand All @@ -83,31 +81,30 @@ impl<'config, 'precompile, 'etable, S, Pre, ES>
config,
precompiles,
etable,
_marker: PhantomData,
}
}
}

impl<'config, 'precompile, 'etable, S, H, Pre, ES> Resolver<H>
for EtableResolver<'config, 'precompile, 'etable, S, Pre, ES>
impl<'config, 'precompile, 'etable, H, Pre, ES> Resolver<H>
for EtableResolver<'config, 'precompile, 'etable, Pre, ES>
where
S: AsRef<RuntimeState> + AsMut<RuntimeState>,
ES::State: AsRef<RuntimeState> + AsMut<RuntimeState>,
H: RuntimeBackend,
Pre: PrecompileSet<S, H>,
ES: EtableSet<State = S, Handle = H>,
Pre: PrecompileSet<ES::State, H>,
ES: EtableSet<Handle = H>,
{
type State = S;
type Interpreter = EtableInterpreter<'etable, S, ES>;
type State = ES::State;
type Interpreter = EtableInterpreter<'etable, ES>;

/// Resolve a call (with the target code address).
#[allow(clippy::type_complexity)]
fn resolve_call(
&self,
code_address: H160,
input: Vec<u8>,
mut state: S,
mut state: ES::State,
handler: &mut H,
) -> Result<InvokerControl<Self::Interpreter, (ExitResult, (S, Vec<u8>))>, ExitError> {
) -> Result<InvokerControl<Self::Interpreter, (ExitResult, (ES::State, Vec<u8>))>, ExitError> {
if let Some((r, retval)) =
self.precompiles
.execute(code_address, &input, &mut state, handler)
Expand All @@ -117,7 +114,7 @@ where

let code = handler.code(code_address);

let machine = Machine::<S>::new(
let machine = Machine::<ES::State>::new(
Rc::new(code),
Rc::new(input),
self.config.stack_limit,
Expand All @@ -135,9 +132,9 @@ where
fn resolve_create(
&self,
init_code: Vec<u8>,
state: S,
state: ES::State,
_handler: &mut H,
) -> Result<InvokerControl<Self::Interpreter, (ExitResult, (S, Vec<u8>))>, ExitError> {
) -> Result<InvokerControl<Self::Interpreter, (ExitResult, (ES::State, Vec<u8>))>, ExitError> {
let machine = Machine::new(
Rc::new(init_code),
Rc::new(Vec::new()),
Expand Down

0 comments on commit 65b8dd2

Please sign in to comment.