Trait midenc_hir::Stack
source · pub trait Stack: IndexMut<usize, Output = Self::Element> {
type Element: StackElement;
Show 25 methods
// Required methods
fn stack(&self) -> &Vec<Self::Element>;
fn stack_mut(&mut self) -> &mut Vec<Self::Element>;
fn clear(&mut self);
// Provided methods
fn debug(&self) -> DebugStack<'_, Self> { ... }
fn is_empty(&self) -> bool { ... }
fn len(&self) -> usize { ... }
fn peek(&self) -> Option<Self::Element> { ... }
fn peekw(&self) -> Option<[Self::Element; 4]> { ... }
fn padw(&mut self) { ... }
fn push(&mut self, value: Self::Element) { ... }
fn pushw(&mut self, word: [Self::Element; 4]) { ... }
fn pop(&mut self) -> Option<Self::Element> { ... }
fn popw(&mut self) -> Option<[Self::Element; 4]> { ... }
fn drop(&mut self) { ... }
fn dropw(&mut self) { ... }
fn dropn(&mut self, n: usize) { ... }
fn dup(&mut self, n: usize) { ... }
fn dupw(&mut self, n: usize) { ... }
fn swap(&mut self, n: usize) { ... }
fn swapw(&mut self, n: usize) { ... }
fn swapdw(&mut self) { ... }
fn movup(&mut self, n: usize) { ... }
fn movupw(&mut self, n: usize) { ... }
fn movdn(&mut self, n: usize) { ... }
fn movdnw(&mut self, n: usize) { ... }
}Expand description
This trait is used to represent the basic plumbing of the operand stack in Miden Assembly.
Implementations of this trait may attach different semantics to the meaning of elements on the stack. As a result, certain operations which are contingent on the specific value of an element, may behave differently depending on the specific implementation.
In general however, it is expected that use of this trait in a generic context will be rare, if ever the case. As mentioned above, it is meant to handle the common plumbing of an operand stack implementation, but in practice users will be working with a concrete implementation with this trait in scope to provide access to the basic functionality of the stack.
It is expected that implementations will override functions in this trait as necessary to implement custom behavior above and beyond what is provided by the default implementation.
Required Associated Types§
type Element: StackElement
Required Methods§
sourcefn stack(&self) -> &Vec<Self::Element>
fn stack(&self) -> &Vec<Self::Element>
Return a reference to the underlying “raw” stack data structure, a vector
Provided Methods§
sourcefn peek(&self) -> Option<Self::Element>
fn peek(&self) -> Option<Self::Element>
Returns the value on top of the stack, without consuming it
sourcefn peekw(&self) -> Option<[Self::Element; 4]>
fn peekw(&self) -> Option<[Self::Element; 4]>
Returns the word on top of the stack, without consuming it
The top of the stack will be the first element of the word
sourcefn pushw(&mut self, word: [Self::Element; 4])
fn pushw(&mut self, word: [Self::Element; 4])
Pushes word on top of the stack
The first element of word will be on top of the stack
sourcefn popw(&mut self) -> Option<[Self::Element; 4]>
fn popw(&mut self) -> Option<[Self::Element; 4]>
Pops the first word on top of the stack
The top of the stack will be the first element in the result
fn dropn(&mut self, n: usize)
sourcefn dup(&mut self, n: usize)
fn dup(&mut self, n: usize)
Duplicates the value in the nth position on the stack
If n is 0, duplicates the top of the stack.
sourcefn dupw(&mut self, n: usize)
fn dupw(&mut self, n: usize)
Duplicates the nth word on the stack, to the top of the stack.
Valid values for n are 0, 1, 2, or 3.
If n is 0, duplicates the top word of the stack.
sourcefn swap(&mut self, n: usize)
fn swap(&mut self, n: usize)
Swaps the nth value from the top of the stack, with the top of the stack
If n is 1, it swaps the first two elements on the stack.
NOTE: This function will panic if n is 0, or out of bounds.
sourcefn swapw(&mut self, n: usize)
fn swapw(&mut self, n: usize)
Swaps the nth word from the top of the stack, with the word on top of the stack
If n is 1, it swaps the first two words on the stack.
Valid values for n are: 1, 2, 3.
sourcefn movup(&mut self, n: usize)
fn movup(&mut self, n: usize)
Moves the nth value to the top of the stack
If n is 1, this is equivalent to swap(1).
NOTE: This function will panic if n is 0, or out of bounds.
sourcefn movupw(&mut self, n: usize)
fn movupw(&mut self, n: usize)
Moves the nth word to the top of the stack
If n is 1, this is equivalent to swapw(1).
Valid values for n are: 1, 2, 3