M2 Modula-2 Toolchain - Compiler Workshop
Other Downloads — Modula-2 subset compiler

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.

29 checks green Native i386 PE32 7-stage pipeline in one exe 12 builtins / 3 standard modules Deterministic builds CC0 Public Domain Authenticode-signed No support, no further development

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.

1
Test run "ISO_Modula2_X86_Toolchain_A2Z" started

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.

2
About 70 % built autonomously with AgnesAI

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.

3
A PC crash stopped the run

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.

4
Completed with GLM 5.3

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.

5
Released as a standalone result

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 script
Downloads so far: --

At a glance

29checks in the acceptance suite, all green
7pipeline stages in one executable
12builtins from SYSTEM, TEXTIO, WHOLEIO
54 KBlargest tested program (stress test)
Capabilities

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

Modula2Toolchain <source.m2> [-o <output.exe>] [--keep-temps] Modula2Toolchain --version | --help Exit codes: 0 success | 1 compile error | 2 usage | 3 assembler error | 4 linker error On any error all artifacts of the run are removed (fail-closed).

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)
Language scope

Supported ISO Modula-2 subset

CategorySupport
ModulesMODULE name; ... BEGIN ... END name. (single unit)
ImportsIMPORT TEXTIO, WHOLEIO, SYSTEM; — parsed and validated against the builtin registry
TypesINTEGER, CARDINAL, BOOLEAN (SHORTINT/LONGINT alias INTEGER); INTEGER/CARDINAL mix freely, BOOLEAN is strict
DeclarationsCONST (folded at compile time), module VAR (static storage), flat PROCEDUREs with value and VAR parameters, function procedures with RETURN
StatementsAssignment, calls (including parameterless), IF/ELSIF/ELSE, WHILE, REPEAT/UNTIL, FOR/TO/BY (constant step, either sign), EXIT, RETURN
ExpressionsFull precedence: relations (= # < <= > >=), additive (+ - OR), multiplicative (* DIV MOD AND), unary - NOT, parentheses, integer literals, TRUE/FALSE, function calls; nested (* comments *)
ProceduresMutual recursion without FORWARD (module-level procedures are pre-declared)
StringsLiteral "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.

Testing

How the toolchain was tested

29checks total
16positive tests (exit codes)
10negative tests (rejection)
1determinism check
2stress programs
powershell -ExecutionPolicy Bypass -File tests\run_all.ps1 <all 29 checks green>
Build it yourself

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.

ToolNeeded forWhere to get it
MinGW-w64 GCC (any C99)compiling the toolchain itselfWinLibs, MSYS2, or winget install BrechtSanders.WinLibs.POSIX.UCRT
windres (binutils)embedding the toolchain iconships with every MinGW-w64 install
Python 3 + Pillowonly to regenerate the icons (optional)pip install pillow
cd Modula2Toolchain_1.1.1 build\build_toolchain.cmd <BUILD OK: build\Modula2Toolchain.exe>

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

copy /y build\Modula2Toolchain.exe bin\ powershell -ExecutionPolicy Bypass -File tests\run_all.ps1 <all 29 checks must be green>

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

Modula2Toolchain_1.1.1/ bin/Modula2Toolchain.exe the toolchain (icon embedded) src/ complete, buildable source (C99) assets/ program and toolchain icons tools/gen_icons.py regenerates icons + embedded payload build/build_toolchain.cmd build script (C99 + windres) examples/ runnable sample programs tests/ full 29-check acceptance suite README.md, version.txt, SHA256SUMS.txt
Status

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.