Преглед на файлове

showcase13 + session save: FORWARD mutual recursion + BITSET/typed set ctor (111/111)

Eric Streit преди 2 седмици
родител
ревизия
96e3a0ab32
променени са 3 файла, в които са добавени 105 реда и са изтрити 0 реда
  1. 1 0
      compiler/run_tests.sh
  2. 37 0
      compiler/tests/showcase13.mod
  3. 67 0
      docs/session-2026-09-24b.md

+ 1 - 0
compiler/run_tests.sh

@@ -254,6 +254,7 @@ rm -f gen_ssa/_showcase11.txt
 # step 8.2/8.3: const folding, forward types, trailing ';', empty
 # statements, 1-char strings, qualified type names.
 expect_run_files Showcase12 42 showcase12lib.def showcase12lib.mod showcase12.mod
+expect_run showcase13.mod 42
 expect_run_files_out MixProg 0 "7" ../stdlib/textio.def ../stdlib/textio.mod ../stdlib/sysio.def ../stdlib/sysio.mod ../stdlib/files.def ../stdlib/files.mod d_mix_prog.mod
 rm -f gen_ssa/_mix.txt
 

+ 37 - 0
compiler/tests/showcase13.mod

@@ -0,0 +1,37 @@
+MODULE Showcase13;
+// Step showcase: FORWARD declarations driving mutual recursion, plus
+// BITSET set operations (union, membership) and the typed set
+// constructor BITSET{...}. Expected ExitCode: 42.
+
+VAR ExitCode : INTEGER;
+VAR s, t : BITSET;
+VAR n : INTEGER;
+
+// --- mutual recursion via FORWARD -------------------------------
+PROCEDURE Even (k : INTEGER) : BOOLEAN; FORWARD;
+PROCEDURE Odd  (k : INTEGER) : BOOLEAN; FORWARD;
+
+PROCEDURE Even (k : INTEGER) : BOOLEAN;
+BEGIN
+  IF k = 0 THEN RETURN TRUE ELSE RETURN Odd(k - 1) END
+END Even;
+
+PROCEDURE Odd (k : INTEGER) : BOOLEAN;
+BEGIN
+  IF k = 0 THEN RETURN FALSE ELSE RETURN Even(k - 1) END
+END Odd;
+
+BEGIN
+  n := 0;
+  IF Even(8) THEN n := n + 10 END;    // TRUE  -> 10
+  IF Odd(7)  THEN n := n + 11 END;    // TRUE  -> 21
+
+  s := BITSET{1, 3, 5};               // typed set constructor
+  t := BITSET{5, 7};
+  IF 3 IN s THEN n := n + 10 END;     // member -> 31
+
+  s := s + t;                         // union {1, 3, 5, 7}
+  IF 7 IN s THEN n := n + 11 END;     // member -> 42
+
+  ExitCode := n
+END Showcase13.

+ 67 - 0
docs/session-2026-09-24b.md

@@ -0,0 +1,67 @@
+# 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 `FORWARD`s), 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
+
+```sh
+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
+```