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§
- Stack
Method - A stack-lowered method.
Enums§
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.