session-2026-09-24b.md 2.8 KB

Session save — 2026-09-24 (part b): forward procedure calls

Continues docs/session-2026-09-24.md. HEAD after this: v3-forward-calls (+ the showcase). Suite 111/111.

Landed

  • v3-forward-calls (6cd5ef9) — within-module forward procedure calls solved for self-hosting; M2S and M2P now compile clean under V3. Details in docs/summary_forward-calls.md. In short:
    • CR's parser output hides its forward declarations in a comment by default (-m suppresses FORWARD); V3 is single-pass. Generate without -m for V3 (real FORWARDs), keep -m for the gm2 stage-1 build (gm2's link-time pass rejects FORWARD).
    • Added: empty ELSIF … THEN bodies, BITSET predef (SET OF [0..15]), typed set constructor BITSET{…}, and a driver file-handle leak fix (compiler.frm now closes each source; the host FileIO caps at 16 open files).

Self-compilation status (sources generated without -m)

Source Errors under V3
SymTab 0
QbeGen 0
M2S (scanner) 0
M2P (parser) 0
M2.mod (driver) 12

Remaining for the driver M2.mod

  • Nested modules — ListHandler is a Wirth-style local MODULE … EXPORT StoreError, PrintListing, PrintConsoleErrors, ResetErrors; V3 parses it but marks 230 and does not expose its exports. Needs nested-module lowering (prefixed globals/functions + the enclosing scope seeing the EXPORT list).
  • String building — the driver builds file names with Strings.Delete/Append. V3's descriptor header is both the open-array count and the logical string length (m2setlen), so once Assign shrinks it, Append past the logical length traps. Delete alone is safe. Needs either a string-model decision (keep a separate length) or a compiler.frm rewrite that avoids incremental append.

Then: cross-stage FileIO selection and bootstrap/fixpoint.sh, plausibly driven by M2make; note the stage-aware CR flags (-m for gm2, no -m for V3).

Showcase

compiler/tests/showcase13.mod (exit 42, suite 111/111): FORWARD mutual recursion (Even/Odd) plus BITSET union/membership and the typed set constructor BITSET{…}.

Resume

cd /home/eric/Projets/Projets-Modula2/MyWork/m2compiler-V3/compiler
./build.sh && ./run_tests.sh          # gm2 build (-m), expect 111/111

# V3-facing (FORWARD) re-generation + M2P check:
(cd src && CRFRAMES="$(pwd)" /home/eric/Projets/Projets-Modula2/MyWork/CocoGm2/CR -C M2.atg >/dev/null)
./M2 ../stdlib/storage.def ../stdlib/storage.mod \
     ../runtime/syslib/SysShim.def ../runtime/syslib/SysShim.mod \
     ../runtime/syslib/FileIO.def ../runtime/syslib/FileIO.mod \
     src/SymTab.def src/SymTab.mod src/QbeGen.def src/QbeGen.mod \
     src/M2S.def src/M2S.mod src/M2P.def src/M2P.mod /tmp/gap.mod