EEVM.Interpreter.Instructions.StackMemoryStorage.StackOps (eevm v0.1.0)

Copy Markdown View Source

Stack manipulation opcodes: POP (0x50), DUP1–DUP16 (0x80–0x8F), and SWAP1–SWAP16 (0x90–0x9F).

Summary

Functions

Applies a stack manipulation opcode to the stack (a list, top first) and returns the new stack.

Functions

stack_op(int, stack)

@spec stack_op(non_neg_integer(), [non_neg_integer()]) :: [non_neg_integer()]

Applies a stack manipulation opcode to the stack (a list, top first) and returns the new stack.

  • POP discards the top element.
  • DUPn pushes a copy of the nth element (DUP1 copies the top).
  • SWAPn exchanges the top element with the one n below it.

The interpreter has already checked that the stack holds the opcode's inputs.

iex> alias EEVM.Interpreter.Instructions.StackMemoryStorage.StackOps
iex> StackOps.stack_op(0x50, [1, 2])
[2]
iex> StackOps.stack_op(0x81, [1, 2, 3])
[2, 1, 2, 3]
iex> StackOps.stack_op(0x91, [1, 2, 3, 4])
[3, 2, 1, 4]