Skip to content

Implement the optimiser: constant folding, dead code, comparison-branch peephole #14

Description

@kameronbrooks

Plan item #24. optimize() in compiler.ts is an empty stub.

Obvious first passes, in rough order of value:

  • Constant folding of scalar BinaryOp expressions (the compile-time-value machinery was made trustworthy in the Compound assignment %= does not parse #7 fix).
  • Dead-code removal after OP_JUMP / OP_TERM.
  • OP_NOOP elimination with label fixup (blocked on the scoped-labels refactor, plan #25 — the padding OP_NOOPs exist to flush pending labels).
  • comparison + OP_BRANCH_FALSE → single comparison-branch opcode (the 18 comparison-branch opcodes exist and their operand order was fixed in #21; this peephole is what would finally emit them).

Every pass must be mirrored or verified on the WebAssembly backend via the differential suite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions