summary_two-phase-slice13.md 2.1 KB

Two-phase refactor — slice 13 (CLASS)

Branch ast-stage-c. Suite 178/178; self-hosting fixpoint OK (3,042,040 bytes; slice 12 was 3,034,200).

What landed

Construct AST
CLASS T; … END T; NkClassDecl(name, parents, fields, methods), op = 0
CLASS IMPLEMENTATION T; … END T; NkClassDecl(…, initBody, methodsWithBodies), op = 1
class field/const NkVarDecl (ty) / NkConstDecl
method heading NkProcDecl, op = 0 normal / 3 virtual / 1 forward
method implementation NkProcDecl with the body as child 1

Module-level accumulators (astCls, astClsP/F/M + tails, astMethod) carry the class being parsed; classes are not nested inside one another, so this is safe. ClassRest and ClassImplRest attach child[1] = parents, child[2] = fields/init body, child[3] = methods, and set astDecl so DeclSeq/TypeBlock record the class.

Two bugs found while verifying (both fixed here)

  1. TypeBlock never collected its items. It ran TypeItem/ClassItem in a loop but only the last one's astDecl survived to DeclSeq — a latent slice-6 bug (my earlier test had a single type). TypeBlock now builds an NkDeclSeq like ConstBlock/VarBlock, so all TYPE and class declarations are recorded.
  2. AST.SetChild cannot skip an unset child. The implementation class set child[2]/child[3] while child[1] was unset, so the methods and init body were silently dropped; child[1] is now set to NoNode first. Also reset astStmt before the optional class-BEGIN so a body-less implementation does not inherit the last method's body.

Verified (temporary AST.Dump, then removed)

tests/t_classmethod.mod produced an NkClassDecl (op 0) with NkFieldDecl[x, y] and methods Set/Sum/CopyX, plus the implementation NkClassDecl (op 1) whose methods carry their bodies.

Next

Step 2 (imports, CLASS, nested modules) is now complete. Remaining: the Lower walk + .ssa byte-compare, and the MaxChild cap on CASE arms / WITH designators / call actuals.