Skip to content

Commit

Permalink
Use macros to reduce eval_log* boilerplate code (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
koushiro authored May 19, 2024
1 parent f310bad commit 36f25ac
Showing 1 changed file with 14 additions and 42 deletions.
56 changes: 14 additions & 42 deletions interpreter/src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,50 +669,22 @@ pub fn eval_gas<S: GasState, H: RuntimeEnvironment + RuntimeBackend, Tr>(
self::system::gas(machine, handle)
}

pub fn eval_log0<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
_position: usize,
) -> Control<Tr> {
self::system::log(machine, 0, handle)
}

pub fn eval_log1<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
_position: usize,
) -> Control<Tr> {
self::system::log(machine, 1, handle)
}

pub fn eval_log2<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
_position: usize,
) -> Control<Tr> {
self::system::log(machine, 2, handle)
}

pub fn eval_log3<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
_position: usize,
) -> Control<Tr> {
self::system::log(machine, 3, handle)
macro_rules! eval_log {
($($num:expr),*) => {
$(paste::paste! {
pub fn [<eval_log $num>]<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
_position: usize,
) -> Control<Tr> {
self::system::log(machine, $num, handle)
}
})*
};
}

pub fn eval_log4<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
machine: &mut Machine<S>,
handle: &mut H,
_opcode: Opcode,
_position: usize,
) -> Control<Tr> {
self::system::log(machine, 4, handle)
}
eval_log! { 0, 1, 2, 3, 4 }

pub fn eval_suicide<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>(
machine: &mut Machine<S>,
Expand Down

0 comments on commit 36f25ac

Please sign in to comment.