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>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
impl Stack
pub fn new() -> Self
pub fn new_with_values(values: Vec<Value>) -> Self
pub(super) fn into_values(self) -> Vec<Value>
Sourcepub fn peek_value(&self) -> Option<Value>
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
Sourcepub fn push_value<C: Config>(
&mut self,
value: Value,
) -> Result<(), RuntimeError>
pub fn push_value<C: Config>( &mut self, value: Value, ) -> Result<(), RuntimeError>
Push a value to the value stack
Sourcepub fn get_local(&self, idx: usize) -> &Value
pub fn get_local(&self, idx: usize) -> &Value
Returns a shared reference to a specific local by its index in the current call frame.
Sourcepub fn get_local_mut(&mut self, idx: usize) -> &mut Value
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.
Sourcepub fn current_call_frame(&self) -> &CallFrame
pub fn current_call_frame(&self) -> &CallFrame
Get a shared reference to the current CallFrame
Sourcepub fn pop_call_frame(&mut self) -> (FuncAddr, usize, usize)
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
Sourcepub 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>
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.
Sourcepub fn call_frame_count(&self) -> usize
pub fn call_frame_count(&self) -> usize
Returns how many call frames 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 remove_in_between(&mut self, remove_count: usize, keep_count: usize)
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,
Stackwill containremove_countfewer elements keep_counttopmost elements will be identical before and after the operation- all elements below the
remove_count + keep_counttopmost stack entry remain