The goal of the experiment: PlanJinn, the autonomous expert-board workflow system, should build a complete Modula-2 toolchain from A to Z — from specification through implementation to the acceptance test suite. Project page: PlanJinn in the AI Workshop.
M2 Modula-2 Toolchain 1.1.1 FINISHED
The M2 Modula-2 Toolchain is a self-contained ISO Modula-2 subset compiler that produces native i386 PE32 Windows executables. The complete pipeline — lexer, parser, semantic analysis, i386 code generator, i386 assembler, COFF object writer and PE32 linker — lives inside a single executable. There is no external assembler, no external linker, no external runtime and no other compiler involved. The project is finished and we will not develop it any further — it is available including the complete source code, for anyone who wants it.
Origin: a PlanJinn test run with a break
This toolchain was never planned as a product. It emerged as a test artifact of the PlanJinn project — and that is exactly how we release it, break included.
PlanJinn drove the provider AgnesAI through definition, structure, implementation and intermediate reviews. Up to that point the toolchain was created roughly seventy percent complete, fully autonomously — without manual code intervention.
A hardware crash of the working machine interrupted the test mid-flight. The autonomous run ended there — the project remained behind as an incomplete intermediate state.
The remaining thirty percent — finishing the pipeline, hardening, the acceptance suite and the release package — were then completed with GLM 5.3 as the provider, again through the PlanJinn workflow.
The outcome is a working, tested compiler — and at the same time proof of what an AI-driven workflow can achieve and where it breaks off. We release it including source code and will not develop it further.
Download
M2 Toolchain 1.1.1 (ZIP) ZIP, approx. 154 KB — binary, complete source code, examples, tests and build scriptAt a glance
What the toolchain can do
Everything in one executable
Lexer, parser, semantic analysis, i386 code generator, i386 assembler, COFF object writer and PE32 linker are integrated. No external tool is needed — not for compiling and not for running the result.
Real PE32 programs
Generated programs are genuine i386 console executables that run natively on Windows and return their result as the process exit code. The integrated linker builds a real PE import table (kernel32: ExitProcess, GetStdHandle, WriteFile).
Standard modules built in
12 builtins from three standard modules (SYSTEM, TEXTIO, WHOLEIO) resolve at compile time. Every builtin is a real i386 routine embedded into each program — real console output without any runtime package.
Deterministic
Two clean compiles of the same source produce byte-identical .s, .obj and .exe outputs. No timestamps, no randomness — reproducible builds included.
Fail-closed
Invalid programs are rejected with clear file(line): error: diagnostics and leave no artifact behind. Errors are never silently compiled away — they are visibly rejected.
Icons embedded
The integrated linker embeds a Modula-2 program icon into the .rsrc section of every generated program; the toolchain itself gets its own icon via windres. Both icons are generated deterministically by script.
Usage
Standard-module builtins
SYSTEM.HALT(int)SYSTEM.ASSERT(bool)TEXTIO.WRITE(s,len)TEXTIO.WRITELN(s,len)WHOLEIO.WRITEINT(n,w)WHOLEIO.WRITELNINT(n,w)WHOLEIO.WRITECARD(n,w)WHOLEIO.WRITELNCARD(n,w)WHOLEIO.WRITEBOOL(b)WHOLEIO.WRITELNBOOL(b)WHOLEIO.WRITECHAR(c)WHOLEIO.WRITELNCHAR(c)Supported ISO Modula-2 subset
| Category | Support |
|---|---|
| Modules | MODULE name; ... BEGIN ... END name. (single unit) |
| Imports | IMPORT TEXTIO, WHOLEIO, SYSTEM; — parsed and validated against the builtin registry |
| Types | INTEGER, CARDINAL, BOOLEAN (SHORTINT/LONGINT alias INTEGER); INTEGER/CARDINAL mix freely, BOOLEAN is strict |
| Declarations | CONST (folded at compile time), module VAR (static storage), flat PROCEDUREs with value and VAR parameters, function procedures with RETURN |
| Statements | Assignment, calls (including parameterless), IF/ELSIF/ELSE, WHILE, REPEAT/UNTIL, FOR/TO/BY (constant step, either sign), EXIT, RETURN |
| Expressions | Full precedence: relations (= # < <= > >=), additive (+ - OR), multiplicative (* DIV MOD AND), unary - NOT, parentheses, integer literals, TRUE/FALSE, function calls; nested (* comments *) |
| Procedures | Mutual recursion without FORWARD (module-level procedures are pre-declared) |
| Strings | Literal "text" as the first argument of TEXTIO.WRITE/WRITELN (stored read-only in .text, byte length passed as a hidden trailing parameter) |
Documented deviations from ISO/IEC 10514-1
DIV/MOD use truncating (C-like) instead of floored semantics · BY steps must be compile-time constants · function procedures need at least one RETURN (no exhaustive path analysis) · everything outside the subset — arrays, records, sets, pointers, REAL, CASE, LOOP, WITH, opaque types, coroutines, exceptions, nested procedures, 45 further standard modules — is rejected with a clear diagnostic rather than silently miscompiled.
How the toolchain was tested
- Generated programs are genuine i386 PE32 console executables that run natively and return their result as the exit code.
- The four standard-module tests additionally assert byte-exact console output (strings, signed and unsigned integers with width padding, TRUE/FALSE).
- Invalid programs are rejected and leave no artifact behind (fail-closed).
- Stress tests: sources up to 54 KB with 400 module variables, 70 procedures, nested loops,
FORwith negative step,VARparameters and mutual recursion. - Determinism: two clean compiles of the same source produce byte-identical outputs.
Building the toolchain from source
The ZIP contains the complete, buildable source tree. You do not have to trust the shipped binary — rebuild it yourself in under a minute.
| Tool | Needed for | Where to get it |
|---|---|---|
| MinGW-w64 GCC (any C99) | compiling the toolchain itself | WinLibs, MSYS2, or winget install BrechtSanders.WinLibs.POSIX.UCRT |
windres (binutils) | embedding the toolchain icon | ships with every MinGW-w64 install |
| Python 3 + Pillow | only to regenerate the icons (optional) | pip install pillow |
The script first compiles the icon via windres (optional — if windres is missing the build continues and produces an icon-less exe with a warning), then runs gcc -std=c99 -O2 over all sources. SOURCE_DATE_EPOCH=1700000000 pins the PE timestamp: two rebuilds of the same tree are byte-identical. If gcc is missing the script stops with a clear message — put MinGW's bin\ on PATH or edit the GCC= line at the top.
Verify your own build
The suite prefers bin\ and falls back to build\ — copying your fresh binary over bin\ guarantees the suite exercises your build, not the shipped one. The Modula-2 pipeline itself needs no external tools at run time; gcc and windres are only needed once, to build the toolchain.
ZIP contents
Status and license
Not under active development
For us this project is finished. We will not develop it further and offer no support. If you want to extend it: the complete source code is included — the acceptance suite shows what to orient yourself on.
CC0 Public Domain
The software is dedicated to the public domain (CC0 1.0): use, copy, modify, publish and distribute it freely, for any purpose, without permission and without conditions. Provided "AS IS", without warranty of any kind.
Publisher: Theo Gottwald, Herrenstr. 11, 76706 Dettenheim, Germany · theo.gottwald@it-berater.org · Created as a test artifact of the PlanJinn project (autonomous expert-board workflow).
Download Activity
Daily activity for every offered download over the rolling last 28 days. Each downloadable file has its own persistent color.