Struct Vm

Source
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: usize

The program counter, i.e. index of the current operation within the program.

§stack: Stack

The stack machine.

§memory: Memory

The memory for temporary storage of words.

§repeat: Repeat

The repeat stack.

§cache: LazyCache

Lazily cached data for the VM.

Implementations§

Source§

impl Vm

Source

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.

Source

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>>
where S: StateRead, B: Deref<Target = [u8]>,

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.

Source

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>>
where S: StateRead, I: IntoIterator<Item = u8>, I::IntoIter: Unpin,

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.

Source

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>>
where S: StateRead, OA: OpAccess<Op = Op> + Unpin, OA::Error: Into<OpError<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:

Trait Implementations§

Source§

impl Debug for Vm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Vm

Source§

fn default() -> Vm

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Vm

Source§

fn eq(&self, other: &Vm) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.