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

Link to this function length(stack)
length(t) :: integer

Returns the length of the stack.

Examples

iex> EVM.Stack.length([1, 2, 3])
3

iex> EVM.Stack.length([])
0
Link to this function peek(list)
peek(t) :: EVM.val | nil

Peeks at head of stack, returns nil if stack is empty.

Examples

iex> EVM.Stack.peek([])
nil

iex> EVM.Stack.peek([1, 2])
1
Link to this function peek_n(stack, n)
peek_n(t, integer) :: [EVM.val]

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]
Link to this function pop(stack)
pop(t) :: {EVM.val, t}

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
Link to this function pop_n(stack, n)
pop_n(t, integer) :: {[EVM.val], t}

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], []}
Link to this function push(stack, val)
push(t, EVM.val | [EVM.val]) :: t

Pushes value onto stack.

Examples

iex> EVM.Stack.push([], 5)
[5]

iex> EVM.Stack.push([5], 6)
[6, 5]

iex> EVM.Stack.push([], [5, 6])
[5, 6]