I continue to work on my Modula-2 compiler. This one is more elaborate. Wip.

Eric Streit 1c93f19dbf docs: two-phase analysis and plan (no restart; middle-of-compiler) 1 周之前
bootstrap 96bb449314 bootstrap: drive the fixpoint with M2make; explicit cross-stage FileIO selection 1 周之前
compiler 53943fa2fe AST module (Stage A) + fix array-of-record element stride 1 周之前
docs 1c93f19dbf docs: two-phase analysis and plan (no restart; middle-of-compiler) 1 周之前
runtime 05d9bd0417 stdlib: StdChans, TimeString, wrapclock, wraptime, wrapc 1 周之前
stdlib 05d9bd0417 stdlib: StdChans, TimeString, wrapclock, wraptime, wrapc 1 周之前
tools 619bff9a99 gaps 1-5: libc, enum/char sets, MIN/MAX+ sized types, set builtins, forward types 1 周之前
vendor 8d68fea6f6 v3 step 1 — minimal integer pipeline to QBE (5/5 tests green) 3 周之前
.gitignore 6826b2e2c2 topspeed corpus: build the sidecar and validate it on TS-V3 (631/662) 1 周之前
README.md abc41a7320 v3 step 4.3 — separate compilation: single-image sessions (87/87 tests green) 2 周之前
m2make.md 2f243ed497 m2make: build-order front-end for M2/gm2 (topo-sort imports, incremental build); FileIO argv starts at 1 2 周之前

README.md

m2compiler-V3 — modern Modula-2, Coco/R frontend, QBE backend

A from-scratch Modula-2 compiler in the Blaise spirit (phased, test-guarded, self-hosting as the end goal): a Coco/R-generated frontend in GNU Modula-2, a fresh QBE SSA backend, and a length-prefixed runtime data model. Modern syntax follows the Benjamin R10 specs where they don't break classic code (Kowarsch/Redux cleanups: # not <>, NOT/AND/OR only, no B/C octals, 0x hex, // comments).

Prerequisites

  • GNU Modula-2 (gm2 -fiso; developed with GCC 16.0.1 experimental)
  • Coco/R CR V1.53 (CRBIN env var, defaults to the sibling CocoGm2/CR used here)
  • qbe (default target amd64_sysv; pin: vendor/qbe-pin.txt)
  • cc, timeout, standard shell tools

Build and test

cd compiler
./build.sh      # M2.atg -> scanner/parser/driver -> ./M2
./run_tests.sh  # M2 -> gen_ssa/*.ssa -> qbe -> cc -> exit codes

Pipeline per test: ./M2 tests/foo.mod writes gen_ssa/FOO.ssa; a global VAR ExitCode : INTEGER selects the process exit code (else 0). Reject tests assert on .LST messages; every error also prints as file:line:col: message on stdout.

Layout (Blaise-adapted)

compiler/src/      M2.atg, frames, FileIO, SymTab, QbeGen (+ generated)
compiler/tests/    t_*.mod (check/reject/run) + showcase<N>.mod tours
compiler/gen_ssa/  build outputs (gitignored)
runtime/syslib/    always-linked runtime (SYSTEM, Storage, SysIO, …)
stdlib/            opt-in libraries (Strings, TextIO, …; classic form)
tools/             syntax helpers (redux-check direction)
bootstrap/         stage1/2/3 + fixpoint.sh (self-hosting proof)
vendor/            qbe toolchain pin
docs/              plan.md, summary_stepN.md (one file per step)

Language status (at v3-step4.3, 87/87 green)

Lowers today: program modules; CONST/VAR/TYPE (scalars, subranges, enums declared, arrays, records, sets, pointers); ARRAY/RECORD/SET/POINTER, WITH, IN; whole array/record copy; NEW/DISPOSE; all scalar arithmetic, relations, boolean connectives; IF/CASE/WHILE/REPEAT/LOOP/FOR; procedures with value/VAR params, functions, recursion, FORWARD, nested procedures (static-link display); separate compilation (lib.def lib.mod prog.mod in one run → one image, FROM/IMPORT, qualified L.x, opaque-type completion). Parse-now/lower-later (230): enum literals, Clarion-form CLASS (declared + checked; class lowering pending), HIGH/LEN, procedure-type variables.

Long-term rules already locked: every ARRAY is LONGCARD count

  • elements (all arrays, inline, element counts, no NUL); UCHAR = 32-bit codepoint, UString = count + codepoints, UTF-8 at the edges with hard lex errors; self-hosting bar is byte-identical .ssa over three stages.

Working conventions

  • Grammar grows section by section in compiler/src/M2.atg (kept LL(1)-clean — Coco/R must report no errors).
  • Every step keeps the full suite green; per-step record in docs/summary_stepN.md; showcase<N>.mod tours each stage.
  • Tags v3-step1[.sub] / v3-step2 mark green states; no pushes without asking (see git.txt for the remote recipe).