# Step: V3 compiler corpus runs Tag `v3-corpus-run`. V3 suite **152/152**, fixpoint OK. ## Why The TopSpeed corpus validated the *sidecar grammar*, not V3 the compiler (the sidecar is a separate `TSM2` binary built from `TopSpeed-V3-M2.atg`; it reuses V3's `SymTab`/`QbeGen`/`FileIO` sources but never runs `compiler/M2`). So this work runs **V3 itself** over two real Modula-2 corpora and fixes what it finds. Harness: `tools/v3-corpus/corpus.sh` — compiles each file with `compiler/M2` in a scratch tree, together with its sibling DEFINITION and the DEFINITION of every module it imports (`$V3_LIBS` search path), and splits failures into CRASH / LIB (unresolved import) / LANG (real gap). ## Corpora and results **1. gm2 testsuite** (`gm2/pim/pass` + `gm2/iso/run/pass`, 612 files): | | no libs | with `$V3_LIBS` | | --- | --- | --- | | **compile-OK** | 242 | **272** | | CRASH | 0 | 0 | | LIB | 185 | **9** | | LANG | 185 | **331** | **2. gm2 standard libraries** (`m2pim`/`m2iso`/`m2log`/`m2cor`/`m2min`, 336 files): | | no libs | with `$V3_LIBS` | | --- | --- | --- | | **compile-OK** | 78 | **115** | | LIB | 176 | **0** | | LANG | 82 | **221** | (With the import path set, LIB noise is gone and the true LANG counts are visible.) ## Fixes landed 1. **Long-line buffer overflow** (`v3-fix-longline-crash`) — `GetLine` wrote past a 256-byte listing buffer; a long line (an 860-char enum) overflowed the stack. Fixed (`GetLine` truncates, buffer 4096, bounded caret loop); CRASH → 0. 2. **`EXPORT QUALIFIED`** in DEFINITION modules (`v3-export-qualified`). 3. **`SYSTEM` facilities** — predefine `BYTE`/`SBYTE`/`WORD`/`SWORD`/ `LONGWORD`/`SHORTADDR`/`LONGADDR`/`PROC`/`LOC` (mapped onto V3's integer family / `ADDRESS`) so `FROM SYSTEM IMPORT BYTE;` and `ARRAY OF BYTE` resolve. 4. **Anchored subranges** `T[lo..hi]` (`INTEGER [-1 .. 24]`). 5. **Unnamed procedure-type parameters** (`PROCEDURE (VAR ARRAY OF REAL)`) plus **open arrays in procedure types** and structural proc-type formal compatibility (`ParamTypesOk`), so assigning a procedure with an open-array parameter to a procedure variable works. 6. **Harness import resolution** — `corpus.sh` now finds and passes the `.def` of each imported module (`$V3_LIBS`), removing the LIB noise. ## Remaining LANG gaps - **`ARRAY OF T`** (index-type arrays, e.g. `ARRAY btype OF INTEGER` in `array2`/`array3`) — V3 only has `ARRAY [lo..hi] OF` / `ARRAY OF`. The big one. - **`undeclared identifier`** — SYSTEM facilities beyond the set above, and small library holes. - **gm2-specific syntax** — `PROCEDURE __BUILTIN__ name(…)`, C-name pragmas, ISO module attributes (not V3's dialect; skip). - **`not supported yet`** — deliberate `230`s (array constructors, …). ## Reproduce ```sh cd tools/v3-corpus ./corpus.sh # testsuite, no libs G=$HOME/bin/Modula2/Gm2/lib/gcc/x86_64-pc-linux-gnu/16.0.1/m2 V3_LIBS="$G/m2pim:$G/m2iso:$G/m2log:$G/m2cor:$G/m2min" ./corpus.sh V3_LIBS="$G/m2pim:$G/m2iso:$G/m2log:$G/m2cor:$G/m2min" \ ./corpus.sh "$G/m2pim" "$G/m2iso" "$G/m2log" "$G/m2cor" "$G/m2min" ``` ## Suggested next steps 1. **`ARRAY OF T`** (index-type arrays) — a real PIM feature. 2. More `SYSTEM` facilities / library holes. 3. Array constructors `array{…}` (codegen). ## Files `tools/v3-corpus/{corpus.sh,README.md}`, `compiler/src/compiler.frm` (long-line), `compiler/src/M2.atg` (`EXPORT QUALIFIED`, anchored subranges, unnamed proc-type params), `compiler/src/SymTab.def`/`.mod` (SYSTEM predefs, `ParamTypesOk`), `compiler/tests/t_longline.mod`, `compiler/run_tests.sh`, this doc.