summary_showcase20.md 3.0 KB

Session summary — 2026-09-30: aggregate constructors + showcase20

Suite 159/159; self-hosting fixpoint OK (image 2,639,067 bytes). master, tree clean except the user's uncommitted compiler/toto.mod.

This session added GNU Modula-2 aggregate constructors and showcased them.

Steps, tags and headline commits

Step Tag Commit What
Array constructors v3-array-ctors c03563e T{…} static descriptors
Records + runtime v3-ctor-records 382125a Rec{…}, runtime build
Showcase v3-showcase20 (this commit) constructors end to end

1. Constructors

TypeName{…} (GNU Modula-2) is now an aggregate constructor for arrays and records:

  • Static — when every element is a constant, CtorEnd bakes a pooled descriptor (data $ctoN = { … }) with the same layout as a declared object: array l n, …, record fields in declaration order, nested constructors inlined as aggregate fields (and consumed), strings inlined into matching CHAR-array fields. A CONST of an aggregate type resolves to the descriptor address.
  • Runtime — any non-constant element makes CtorEnd allocate the descriptor on the stack (alloc8) and fill it in place (ElemStore / InitArrHeader+CopyArray / CopyRecord / CopySet), so constructors also work outside CONST.
  • Elements: scalars, nested constructors, strings for ARRAY OF CHAR, and the expr BY n repeat form.

QbeGen.CtorBegin/CtorElem/CtorEnd (CtorElem derives the element type itself); the old TypedSetLit became the unified TypedBraceLit (BITSET{…} stays a set).

2. Showcase

compiler/tests/showcase20.mod (Showcase20, exit 42) exercises:

  • Greet = Name {'H','e','l','l','o','!','!','!'} — CHAR-array CONST;
  • Base = Triple {7, 7 BY 2} — the BY repeat form (7,7,7);
  • p := Person{"Modula", Date{1980, 5, 3}} — static record constructor (string field + inlined nested record);
  • q := Person{"Runtime", Date{i, i+1, i+2}} — runtime record constructor;
  • a := Triple{i, i+1, i+2} — runtime array constructor.

Sum: 21 (Base) + 18 (a) + 3 (p.born.d) = 42.

showcase20 total=42

Tests (159, was 155)

New: Showcase20 (42), plus t_ctor{1..6} (t_ctor1 CHAR-array copy, t_ctor2 BY repeat, t_ctor3 nested strings, t_ctor4 static record, t_ctor5 runtime array, t_ctor6 runtime record).

Corpus (with $V3_LIBS)

gm2 testsuite 283/612 compile-OK (was 242 before this work; 0 CRASH). strcons.mod, testarray.mod, arrayconst{1,2,3}.mod, lazyunique.mod's array constructor now compile.

Resume

cd .../m2compiler-V3
./bootstrap/fixpoint.sh                       # FIXPOINT OK
cd compiler && ./build.sh && ./run_tests.sh   # 159/159

Remaining

  • Set fields in record constructors; constant string concatenation in constructor elements.
  • ARRAY <type> OF T (index-type arrays).
  • MIN/MAX builtins; more SYSTEM facilities.