# m2compiler-V3 — status (2026-10-16) This answers "where are we now?". ## Numbers - Suite **219/219** (`compiler/run_tests.sh`). - Self-hosting **FIXPOINT OK** — stage2 and stage3 images are byte-identical (3,714,376 bytes). - Corpus **372 / 612** sources compile with 0 errors, **0 crashes** (`tools/v3-corpus/corpus.sh` over the gm2 testsuite); the rest are genuine language gaps or unresolved imports. - Branch **`resolve-check`**; tree clean. ## Architecture (current) ``` per unit: Parse -> AST + declarations; each procedure body is skipped and re-parsed at unit end, so forward references bind normally Lower -> walk the AST, emit QBE (the only emitter) Emit -> buffered image, EndModule ``` - **Two-phase parse.** Procedure bodies are deferred (module level) and re-parsed after the unit's declarations, which removed the entire forward-reference mechanism (`FwdVar*`, `Design`'s forward branch). A module body may now call a procedure declared later; a nested-local forward is a plain `201`. `-notwophase` restores the legacy inline parse for debugging. - **No resolve/check pass.** The `Check` module was deleted once it was proven vestigial (gutting it left the emitted `.ssa` byte-identical): binding is late by construction. - **`Lower` is the only emitter**; the AST is the interface. ## Language coverage Program modules; `CONST`/`VAR`/`TYPE` (scalars, subranges, enums, arrays, records incl. variants, sets, pointers); `WITH`/`IN`; whole array/record copy; `NEW`/`DISPOSE`; full expressions and control flow; `GOTO`/labels; procedures (value/`VAR` params, functions, recursion, `FORWARD`, nested procedures, procedure values); Clarion-form `CLASS` (methods, single inheritance, virtual dispatch); PIM coroutines; Unicode (`UCHAR`/`UString`, UTF-8 edges); ISO type conversions `T(x)`; separate compilation (`FROM`/`IMPORT`, qualified `L.x`, opaque types); **generics** (ISO 10514-2 refinement): type/value/procedure parameters, constraints, nested generics, generic classes. ## Landed recently (this thread) - AST + `Lower` (L0–L7) — `Lower` emits the whole session from the AST. - Two-phase parse; forward machinery deleted; `Check` deleted. - Generics increment 3: value/procedure parameters, constraint model, nested generics, generic classes via generic modules. - ISO type conversions `T(x)` (incl. CONST folding): corpus 365 → 372. - Clean `M2` exit codes (0 ok / 1 errors / 2 usage-IO). - Bug fixes: `PopPos` wiping repass diagnostics; global record data size (`w 0` → `l 0` for pointer/`LONGINT`/proc fields); template arithmetic over a type formal; proc-typed formals in DEF/IMPL; imported procedures used as values. - Showcase `showcase23` (generic doubly linked list). ## What remains 1. **Corpus language gaps** — top `LANG` buckets are `not supported yet`, `undeclared identifier`, `invalid call`; separate genuine gaps from missing stdlib imports (`LIB`), then fix the top bounded one. See `docs/analysis_gaps.md`. 2. **The size-sensitive V3 miscompile** — the long-standing "removing `ASTDUMP` from `M2.atg` breaks the fixpoint" has never been root-caused. A real correctness landmine. 3. **Robustness** — fixed table limits resolve silently when exceeded; weak error recovery; error-message polish. 4. **Library holes** — channel/device framework (`docs/wip/`). 5. **Housekeeping** — consolidate `docs/summary_*.md` (see `docs/INDEX.md`); decide on merging/pushing `resolve-check`. ## How to check for yourself ```sh cd compiler ./build.sh # M2.atg -> scanner/parser/driver -> ./M2 ./run_tests.sh # 219/219 cd .. ./bootstrap/fixpoint.sh # FIXPOINT OK (byte-identical stage2/stage3) ```