Skip to content

fitzee/mx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mx — Modula-2 Compiler

mx transpiles Modula-2 to C, then calls the system C compiler to produce native executables. It implements PIM4 with optional Modula-2+ extensions (exceptions, reference types, objects, concurrency) via --m2plus.

Why Modula-2?

  • Grammar fits on a page (~40 reserved words)
  • Separate interface (.def) and implementation (.mod) per module
  • No implicit conversions, no header file resolution order issues
  • Strict static type checking

Why mx?

Transpiling to C rather than emitting native code directly gives:

  • Portability — any platform with a C compiler is a target. Cross-compile by setting --cc.
  • Source-level debugging#line directives map back to .mod source in LLDB/GDB.
  • C FFI — bind to any C library with DEFINITION MODULE FOR "C".
  • Inspectable output — generated C is readable.

The toolchain also includes a package manager (mxpkg), an LSP server, a VS Code extension, and 33 libraries (see libs/).

Install

Requires Rust (cargo) and a C compiler (cc/clang/gcc).

git clone https://github.com/fitzee/mx.git && cd mx
make install

Add to your shell profile:

export PATH="$HOME/.mx/bin:$PATH"

OpenSSL 3 is required (brew install openssl@3 on macOS, sudo apt install libssl-dev on Linux). Optional: SQLite3, zlib.

Hello world

cat > hello.mod << 'EOF'
MODULE Hello;
FROM InOut IMPORT WriteString, WriteLn;
BEGIN
  WriteString("Hello, world!");
  WriteLn;
END Hello.
EOF

mx hello.mod -o hello && ./hello

Project builds

mx build     # compile
mx run       # compile and run
mx test      # run tests

VS Code

code --install-extension tools/vscode-m2plus/m2plus-*.vsix

Tooling

docs/ai/ contains structured references for use with coding agents:

  • Language rules and compiler constraints
  • Syntax patterns and idiomatic templates
  • Module resolution and import mechanics
  • API signatures for all 33 libraries
  • Build system and project manifest format

See docs/ai/CLAUDE.md for reading order.

Documentation

Language reference, library APIs, LSP configuration, and contributor guides are in docs/. Version history in RELEASE_NOTES.md.

Project Layout

src/           Compiler (Rust)
libs/          33 libraries (Modula-2)
tools/mxpkg/   Package manager (Modula-2+)
tools/vscode-m2plus/  VS Code extension
examples/      Categorized examples and demos
tests/         Unit, adversarial, conformance
docs/          Documentation

Tests

cargo test                                              # unit tests
bash tests/run_all.sh                                   # integration tests
bash tests/conformance.sh                               # conformance tests
python3 tests/adversarial/run_adversarial.py --mode ci  # adversarial tests

License

MIT License

Copyright (c) 2026 Matt Fitzgerald

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Modula-2 compiler in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors