pub(crate) struct Stack {
    values: Vec<Value>,
    frames: Vec<CallFrame>,
}
Expand description

The stack at runtime containing

  1. Values
  2. Labels
  3. Activations

See https://webassembly.github.io/spec/core/exec/runtime.html#stack

Fields§

§values: Vec<Value>

WASM values on the stack, i.e. the actual data that instructions operate on

§frames: Vec<CallFrame>

Stack frames

Each time a function is called, a new frame is pushed, whenever a function returns, a frame is popped

Implementations§

source§

impl Stack

source

pub fn new() -> Self

source

pub fn drop_value(&mut self)

source

pub fn pop_value(&mut self, ty: ValType) -> Value

Pop a value of the given ValType from the value stack

source

pub fn peek_value(&self, ty: ValType) -> Value

Copy a value of the given ValType from the value stack without removing it

source

pub fn peek_unknown_value(&self) -> Option<Value>

Returns a cloned copy of the top value on the stack, or None if the stack is empty

source

pub fn push_value(&mut self, value: Value)

Push a value to the value stack

source

pub fn get_local(&mut self, idx: usize)

Copy a local variable to the top of the value stack

source

pub fn set_local(&mut self, idx: usize)

Pop value from the top of the value stack, writing it to the given local

source

pub fn tee_local(&mut self, idx: usize)

Copy value from top of the value stack to the given local

source

pub fn current_stackframe(&self) -> &CallFrame

Get a shared reference to the current CallFrame

source

pub fn current_stackframe_mut(&mut self) -> &mut CallFrame

Get a mutable reference to the current CallFrame

source

pub fn pop_stackframe(&mut self) -> usize

Pop a CallFrame from the call stack, returning the return address

source

pub fn push_stackframe( &mut self, func_idx: usize, func_ty: &FuncType, locals: Locals, return_addr: usize )

Push a stackframe to the call stack

Takes the current Self::values’s length as CallFrame::value_stack_base_idx.

source

pub fn callframe_count(&self) -> usize

Returns how many stackframes are on the stack, in total.

source

pub fn pop_tail_iter(&mut self, n: usize) -> Drain<'_, Value>

Pop n elements from the value stack’s tail as an iterator, with the first element being closest to the bottom of the value stack

Note that this is providing the values in reverse order compared to popping n values (which would yield the element closest to the top of the value stack first).

source

pub fn clear_callframe_values(&mut self)

Clear all of the values pushed to the value stack by the current stack frame

Trait Implementations§

source§

impl Default for Stack

source§

fn default() -> Stack

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

Auto Trait Implementations§

§

impl RefUnwindSafe for Stack

§

impl Send for Stack

§

impl Sync for Stack

§

impl Unpin for Stack

§

impl UnwindSafe for Stack

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.