pub(crate) struct Stack {
values: FixedCapacityVec<Value>,
frames: FixedCapacityVec<CallFrame>,
}Expand description
The stack at runtime containing
- Values
- Labels
- Activations
See https://webassembly.github.io/spec/core/exec/runtime.html#stack
Fields§
§values: FixedCapacityVec<Value>WASM values on the stack, i.e. the actual data that instructions operate on
frames: FixedCapacityVec<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<T: Config>( params_to_base_call_frame: Vec<Value>, base_call_frame_func_ty: &FuncType, base_call_frame_remaining_locals: &[ValType], ) -> Result<Self, RuntimeError>
pub(super) fn into_values(self) -> Vec<Value>
Sourceunsafe fn pop_value_unchecked(&mut self) -> Value
unsafe fn pop_value_unchecked(&mut self) -> Value
Pop a Value from the value stack
§Safety
This will underflow the stack and cause undefined behavior, if the stack is empty. To
check, before pushing, assure that Self::values is not empty.
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(&mut self, value: Value) -> Result<(), RuntimeError>
pub fn push_value(&mut self, value: Value) -> Result<(), RuntimeError>
Push a value to the value stack after veryfing that this will not overflow the stack
Sourceunsafe fn push_value_unchecked(&mut self, value: Value)
unsafe fn push_value_unchecked(&mut self, value: Value)
Push a Value to the value stack
§Safety
This will overflow the stack and cause undefined behavior, if the stack is already full. To
check, before pushing, assure that the Self::values is not full.
Sourcepub fn get_local(&self, idx: LocalIdx) -> &Value
pub fn get_local(&self, idx: LocalIdx) -> &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: LocalIdx) -> &mut Value
pub fn get_local_mut(&mut self, idx: LocalIdx) -> &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
Sourcepub fn pop_call_frame(&mut self) -> Option<(FuncAddr, usize, usize)>
pub fn pop_call_frame(&mut self) -> Option<(FuncAddr, usize, usize)>
Pop a CallFrame from the call stack, returning the caller function store address, return address, and the return stp
Returns None if the base call frame was popped. Its information cannot
be retrieved.
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) -> Vec<Value>
pub fn pop_tail_iter(&mut self, n: usize) -> Vec<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