Struct wasm::execution::value_stack::Stack
source · pub(crate) struct Stack {
values: Vec<Value>,
frames: Vec<CallFrame>,
}
Expand description
The stack at runtime containing
- Values
- Labels
- 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
impl Stack
pub fn new() -> Self
pub fn drop_value(&mut self)
sourcepub fn pop_value(&mut self, ty: ValType) -> Value
pub fn pop_value(&mut self, ty: ValType) -> Value
Pop a value of the given ValType from the value stack
sourcepub fn peek_value(&self, ty: ValType) -> Value
pub fn peek_value(&self, ty: ValType) -> Value
Copy a value of the given ValType from the value stack without removing it
sourcepub fn peek_unknown_value(&self) -> Option<Value>
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
sourcepub fn push_value(&mut self, value: Value)
pub fn push_value(&mut self, value: Value)
Push a value to the value stack
sourcepub fn set_local(&mut self, idx: usize)
pub fn set_local(&mut self, idx: usize)
Pop value from the top of the value stack, writing it to the given local
sourcepub fn tee_local(&mut self, idx: usize)
pub fn tee_local(&mut self, idx: usize)
Copy value from top of the value stack to the given local
sourcepub fn current_stackframe(&self) -> &CallFrame
pub fn current_stackframe(&self) -> &CallFrame
Get a shared reference to the current CallFrame
sourcepub fn current_stackframe_mut(&mut self) -> &mut CallFrame
pub fn current_stackframe_mut(&mut self) -> &mut CallFrame
Get a mutable reference to the current CallFrame
sourcepub fn pop_stackframe(&mut self) -> usize
pub fn pop_stackframe(&mut self) -> usize
Pop a CallFrame
from the call stack, returning the return address
sourcepub fn push_stackframe(
&mut self,
func_idx: usize,
func_ty: &FuncType,
locals: Locals,
return_addr: usize
)
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
.
sourcepub fn callframe_count(&self) -> usize
pub fn callframe_count(&self) -> usize
Returns how many stackframes are on the stack, in total.
sourcepub fn pop_tail_iter(&mut self, n: usize) -> Drain<'_, Value>
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).
sourcepub fn clear_callframe_values(&mut self)
pub fn clear_callframe_values(&mut self)
Clear all of the values pushed to the value stack by the current stack frame