summary_two-phase-slice8.md 1.4 KB

Two-phase refactor — slice 8 (CASE + WITH statements)

Branch ast-stage-c. Suite 178/178; self-hosting fixpoint OK (3,021,285 bytes; slice 7 was 3,016,802).

What landed

Statement AST
CASE e OF … END NkCase(selector, arm…)
case alternative NkCaseArm(label…, body)
range label a..b NkSubrange(a, b)
ELSE arm NkCaseArm with op = 1, child 0 = body
WITH d, … DO … END NkWith(designator…, body)

CASE and WITH build their node incrementally, so no local arrays are needed (and per-invocation state is preserved across nested forms): CaseAlt, CaseLabel and WithItem take the enclosing node as a value parameter and append to it. A body-less alternative resets astStmt first so it never appends a stale node.

Verified (temporary AST.Dump of astUnit, then removed)

CASE x OF
  1 : x := 1
| 2, 3..5 : x := 2
ELSE x := 9
END;
WITH r DO x := f END

produced

  • NkCase(x, [ NkCaseArm(1, Block[x:=1]), NkCaseArm(2, Subrange(3,5), Block[x:=2]), NkCaseArm(op=1, Block[x:=9]) ])
  • NkWith(NkDesignator r, Block[ NkAssign(x, f) ])

Deliberately deferred

  • Imports, CLASS, nested modules in the unit AST.
  • Brace/set literals and ResultComp call suffixes.
  • Lower + .ssa byte-compare.

Next

Brace/set literals and ResultComp; imports/CLASS; then the Lower walk.