Skip to main content

Module stack

Module stack 

Source
Expand description

Pass 5: Stack Lower – converts ANF IR to Stack IR.

The fundamental challenge: ANF uses named temporaries but Bitcoin Script operates on an anonymous stack. We maintain a “stack map” that tracks which named value lives at which stack position, then emit PICK/ROLL/DUP operations to shuttle values to the top when they are needed.

This matches the TypeScript reference compiler and aligned Go compiler:

  • Private methods are inlined at call sites rather than compiled separately
  • Constructor is skipped
  • @ref: aliases are handled via PICK (non-consuming copy)
  • @this is a compile-time placeholder (push 0)
  • super() is a no-op at stack level

Structs§

StackMethod
A stack-lowered method.

Enums§

PushValue
Typed value for push operations.
StackOp
A single stack-machine operation.

Functions§

lower_to_stack
Lower an ANF program to Stack IR. Private methods are inlined at call sites rather than compiled separately. The constructor is skipped since it’s not emitted to Bitcoin Script.