pub struct Vm {
pub pc: usize,
pub stack: Stack,
pub memory: Memory,
pub parent_memory: Vec<Arc<Memory>>,
pub halt: bool,
pub repeat: Repeat,
pub cache: Arc<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.
parent_memory: Vec<Arc<Memory>>The stack of parent Memorys.
This is empty at the beginning of execution, but is pushed to each time
we enter a [Compute] op context with the parent’s Memory.
This can also be used to observe the Compute op depth.
halt: boolPropagation of Halt encountered in compute program.
repeat: RepeatThe repeat stack.
cache: Arc<LazyCache>Lazily cached data for the VM.
Implementations§
Source§impl Vm
impl Vm
Sourcepub fn exec_ops<S>(
&mut self,
ops: &[Op],
access: Access,
state_reads: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>where
S: StateReads,
pub fn exec_ops<S>(
&mut self,
ops: &[Op],
access: Access,
state_reads: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>where
S: StateReads,
Execute the given operations from the current state of the VM.
This function uses synchronous state reading and is intended for use with in-memory state implementations.
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
method which allows for providing a more compact representation of the
operations in the form of mapped bytecode.
Sourcepub fn exec_bytecode<S, B>(
&mut self,
bytecode_mapped: &BytecodeMapped<B>,
access: Access,
state_reads: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>
pub fn exec_bytecode<S, B>( &mut self, bytecode_mapped: &BytecodeMapped<B>, access: Access, state_reads: &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.
This function uses synchronous state reading and is intended for use with in-memory state implementations.
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 fn exec<S, OA>(
&mut self,
access: Access,
state_reads: &S,
op_access: OA,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> Result<Gas, ExecError<S::Error>>
pub fn exec<S, OA>( &mut self, access: Access, state_reads: &S, op_access: OA, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> Result<Gas, ExecError<S::Error>>
Execute the given operations synchronously from the current state of the VM.
This function uses synchronous state reading and is intended for use with in-memory state implementations.
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.
Sourcepub fn eval_ops<S>(
&mut self,
ops: &[Op],
access: Access,
state: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> EvalResult<bool, S::Error>where
S: StateReads,
pub fn eval_ops<S>(
&mut self,
ops: &[Op],
access: Access,
state: &S,
op_gas_cost: &impl OpGasCost,
gas_limit: GasLimit,
) -> EvalResult<bool, S::Error>where
S: StateReads,
Evaluate a slice of synchronous operations and return their boolean result.
This is the same as [exec_ops], but retrieves the boolean result from the resulting stack.
Trait Implementations§
impl StructuralPartialEq for Vm
Auto Trait Implementations§
impl Freeze for Vm
impl RefUnwindSafe for Vm
impl Send for Vm
impl Sync for Vm
impl Unpin for Vm
impl UnwindSafe for Vm
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more