use crate::{
U256,
vm::{
Ext,
evm::{EVMGas, Interpreter, interpreter::Halt},
},
};
use core::ops::ControlFlow;
use revm::interpreter::gas::{BASE, VERYLOW};
pub fn pop<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(EVMGas(BASE))?;
let [_] = interpreter.stack.popn()?;
ControlFlow::Continue(())
}
pub fn push0<E: Ext>(interpreter: &mut Interpreter<E>) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(EVMGas(BASE))?;
interpreter.stack.push(U256::zero())
}
pub fn push<'ext, const N: usize, E: Ext>(
interpreter: &mut Interpreter<'ext, E>,
) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(EVMGas(VERYLOW))?;
let slice = interpreter.bytecode.read_slice(N);
interpreter.stack.push_slice(slice)?;
interpreter.bytecode.relative_jump(N as isize);
ControlFlow::Continue(())
}
pub fn dup<'ext, const N: usize, E: Ext>(
interpreter: &mut Interpreter<'ext, E>,
) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(EVMGas(VERYLOW))?;
interpreter.stack.dup(N)
}
pub fn swap<'ext, const N: usize, E: Ext>(
interpreter: &mut Interpreter<'ext, E>,
) -> ControlFlow<Halt> {
interpreter.ext.charge_or_halt(EVMGas(VERYLOW))?;
assert!(N != 0);
interpreter.stack.exchange(0, N)
}