evm v0.1.14 EVM.Stack
Operations to read / write to the EVM’s stack.
Link to this section Summary
Functions
Returns the length of the stack
Peeks at head of stack, returns nil if stack is empty
Peeks at n elements of stack, and raises if unsufficient elements exist
Pops value from stack, returning a new stack with value popped
Pops multiple values off of stack, returning a new stack less that many elements
Pushes value onto stack
Link to this section Types
Link to this section Functions
Returns the length of the stack.
Examples
iex> EVM.Stack.length([1, 2, 3])
3
iex> EVM.Stack.length([])
0
Peeks at head of stack, returns nil if stack is empty.
Examples
iex> EVM.Stack.peek([])
nil
iex> EVM.Stack.peek([1, 2])
1
Peeks at n elements of stack, and raises if unsufficient elements exist.
Examples
iex> EVM.Stack.peek_n([1, 2, 3], 2)
[1, 2]
iex> EVM.Stack.peek_n([1, 2, 3], 4)
[1, 2, 3]
Pops value from stack, returning a new stack with value popped.
This function raises if stack is empty.
Examples
iex> EVM.Stack.pop([1, 2, 3])
{1, [2, 3]}
iex> EVM.Stack.pop([5])
{5, []}
iex> EVM.Stack.pop([])
** (FunctionClauseError) no function clause matching in EVM.Stack.pop/1
Pops multiple values off of stack, returning a new stack less that many elements.
Raises if stack contains insufficient elements.
## Examples
iex> EVM.Stack.pop_n([1, 2, 3], 0)
{[], [1, 2, 3]}
iex> EVM.Stack.pop_n([1, 2, 3], 1)
{[1], [2, 3]}
iex> EVM.Stack.pop_n([1, 2, 3], 2)
{[1, 2], [3]}
iex> EVM.Stack.pop_n([1, 2, 3], 4)
{[1, 2, 3], []}