pub struct Vm {
pub pc: usize,
pub stack: Stack,
pub memory: Memory,
pub repeat: Repeat,
pub cache: LazyCache,
}Expand description
The operation execution state of the VM.
Fields§
§pc: usizeThe program counter, i.e. index of the current operation within the program.
stack: StackThe stack machine.
memory: MemoryThe memory for temporary storage of words.
repeat: RepeatThe repeat stack.
cache: LazyCacheLazily cached data for the VM.
Implementations§
Source§impl Vm
impl Vm
Sourcepub async fn exec_ops<S>(
&mut self,
ops: &[Op],
access: Access<'_>,
state_read: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>where
S: StateRead,
pub async fn exec_ops<S>(
&mut self,
ops: &[Op],
access: Access<'_>,
state_read: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>where
S: StateRead,
Execute the given operations from the current state of the VM.
Upon reaching a Halt operation or reaching the end of the operation
sequence, returns the gas spent and the Vm will be left in the
resulting state.
This is a wrapper around Vm::exec that expects operation access in
the form of a &[Op].
If memory bloat is a concern, consider using the Vm::exec_bytecode
or Vm::exec_bytecode_iter methods which allow for providing a more
compact representation of the operations in the form of mapped bytecode.
Sourcepub async fn exec_bytecode<S, B>(
&mut self,
bytecode_mapped: &BytecodeMapped<B>,
access: Access<'_>,
state_read: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>
pub async fn exec_bytecode<S, B>( &mut self, bytecode_mapped: &BytecodeMapped<B>, access: Access<'_>, state_read: &S, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> Result<Gas, ExecError<S::Error>>
Execute the given mapped bytecode from the current state of the VM.
Upon reaching a Halt operation or reaching the end of the operation
sequence, returns the gas spent and the Vm will be left in the
resulting state.
This is a wrapper around Vm::exec that expects operation access in
the form of &BytecodeMapped.
This can be a more memory efficient alternative to Vm::exec_ops due
to the compact representation of operations in the form of bytecode and
indices.
Sourcepub async fn exec_bytecode_iter<S, I>(
&mut self,
bytecode_iter: I,
access: Access<'_>,
state_read: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>
pub async fn exec_bytecode_iter<S, I>( &mut self, bytecode_iter: I, access: Access<'_>, state_read: &S, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> Result<Gas, ExecError<S::Error>>
Execute the given bytecode from the current state of the VM.
Upon reaching a Halt operation or reaching the end of the operation
sequence, returns the gas spent and the Vm will be left in the
resulting state.
The given bytecode will be mapped lazily during execution. This
can be more efficient than pre-mapping the bytecode and using
Vm::exec_bytecode in the case that execution may fail early.
However, successful execution still requires building the full
BytecodeMapped instance internally. So if bytecode has already been
mapped, Vm::exec_bytecode should be preferred.
Sourcepub async fn exec<S, OA>(
&mut self,
access: Access<'_>,
state_read: &S,
op_access: OA,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>
pub async fn exec<S, OA>( &mut self, access: Access<'_>, state_read: &S, op_access: OA, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> Result<Gas, ExecError<S::Error>>
Execute over the given operation access from the current state of the VM.
Upon reaching a Halt operation or reaching the end of the operation
sequence, returns the gas spent and the Vm will be left in the
resulting state.
The type requirements for the op_access argument can make this
finicky to use directly. You may prefer one of the convenience methods: