Struct Stack

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

Call 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 new_with_values(values: Vec<Value>) -> Self

Source

pub(super) fn into_values(self) -> Vec<Value>

Source

pub fn pop_value(&mut self) -> Value

Pop a value from the value stack

Source

pub fn peek_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<C: Config>( &mut self, value: Value, ) -> Result<(), RuntimeError>

Push a value to the value stack

Source

pub fn get_local(&self, idx: usize) -> &Value

Returns a shared reference to a specific local by its index in the current call frame.

Source

pub fn get_local_mut(&mut self, idx: usize) -> &mut Value

Returns a mutable reference to a specific local by its index in the current call frame.

Source

pub fn current_call_frame(&self) -> &CallFrame

Get a shared reference to the current CallFrame

Source

pub fn pop_call_frame(&mut self) -> (FuncAddr, usize, usize)

Pop a CallFrame from the call stack, returning the caller function store address, return address, and the return stp

Source

pub fn push_call_frame<C: Config>( &mut self, return_func_addr: FuncAddr, func_ty: &FuncType, remaining_locals: &[ValType], return_addr: usize, return_stp: usize, ) -> Result<(), RuntimeError>

Push a call frame to the call stack

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

Source

pub fn call_frame_count(&self) -> usize

Returns how many call frames 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 remove_in_between(&mut self, remove_count: usize, keep_count: usize)

Remove remove_count values from the stack, keeping the topmost keep_count values

From the stack, remove remove_count elements, by sliding down the keep_count topmost values remove_count positions.

Effects

  • after the operation, Stack will contain remove_count fewer elements
  • keep_count topmost elements will be identical before and after the operation
  • all elements below the remove_count + keep_count topmost stack entry remain

Trait Implementations§

Source§

impl Debug for Stack

Source§

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

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

impl Default for Stack

Source§

fn default() -> Stack

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

Auto Trait Implementations§

§

impl Freeze for Stack

§

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

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.