The EVM stack — a LIFO data structure with a max depth of 1024.
Summary
Functions
Returns the current stack depth.
Returns the maximum stack depth (1024).
Creates a new empty stack.
Peeks at the element at the given depth (0 = top of stack).
Pops the top value from the stack.
Pushes a value onto the stack.
Swaps the top element with the element at the given depth.
Converts the stack to a list (top element first) for inspection.
Types
@type t() :: %EEVM.Interpreter.Stack{ elements: [non_neg_integer()], size: non_neg_integer() }
Functions
@spec depth(t()) :: non_neg_integer()
Returns the current stack depth.
@spec max_depth() :: pos_integer()
Returns the maximum stack depth (1024).
@spec new() :: t()
Creates a new empty stack.
@spec peek(t(), non_neg_integer()) :: {:ok, non_neg_integer()} | {:error, :stack_underflow}
Peeks at the element at the given depth (0 = top of stack).
Used by DUP and SWAP instructions.
@spec pop(t()) :: {:ok, non_neg_integer(), t()} | {:error, :stack_underflow}
Pops the top value from the stack.
Returns {:ok, value, new_stack} or {:error, :stack_underflow}.
@spec push(t(), non_neg_integer()) :: {:ok, t()} | {:error, :stack_overflow}
Pushes a value onto the stack.
Returns {:ok, stack} or {:error, :stack_overflow} if the stack is full.
EVM values are 256-bit unsigned integers. We enforce this with a bitmask.
@spec swap(t(), pos_integer()) :: {:ok, t()} | {:error, :stack_underflow}
Swaps the top element with the element at the given depth.
SWAP1 swaps positions 0 and 1, SWAP2 swaps 0 and 2, etc.
@spec to_list(t()) :: [non_neg_integer()]
Converts the stack to a list (top element first) for inspection.