Struct Vm

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

§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: bool

Propagation of Halt encountered in compute program.

§repeat: Repeat

The repeat stack.

§cache: Arc<LazyCache>

Lazily cached data for the VM.

Implementations§

Source§

impl Vm

Source

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.

Source

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>>
where S: StateReads, B: Deref<Target = [u8]> + Send + Sync,

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.

Source

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>>
where S: StateReads, OA: OpAccess<Op = Op>, OA::Error: Into<OpError<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.

Source

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.

Source

pub fn eval<OA, S>( &mut self, op_access: OA, access: Access, state: &S, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> EvalResult<bool, S::Error>
where OA: OpAccess<Op = Op>, OA::Error: Into<OpError<S::Error>>, S: StateReads,

This is the same as [exec], but retrieves the boolean result from the resulting stack.

Trait Implementations§

Source§

impl Clone for Vm

Source§

fn clone(&self) -> Vm

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.