Modula-2 Reloaded

A Modern Typesafe & Literate Programming Notation

Site Menu

Project

Specification

Implementation

Recommendations

Reference

Needs Updating

Work in Progress

Wastebasket

Wiki Manual

edit SideBar

Compiler

The Project's Compiler

Work on a bootstrap compiler has begun in April 2015. It is being written in classic Modula-2. Sources are available on our public Bitbucket repository at: https://bitbucket.org/trijezdci/m2r10/src/tip/bootstrap/m2bst.

Architecture

The lexer is a handwritten trie tokeniser using a two-character lookahead. It performs tokenisation only. The parser is a handwritten recursive descent multi-pass design. It performs syntax and type checking and builds a symbol table and abstract syntax tree (AST). A recursive tree-walker will perform transformations on the AST in preparation for code generation. The code generator will expand code-fragment templates to generate output. For each AST node, the code generator's internal library contains one pre-defined code fragment in the target language. The bootstrap compiler will generate readable C99 for bootstrapping on any target platform for which a C99 compiler is available. Initially it will implement a language subset sufficient for bootstrapping.

Bootstrapping

In the first stage the compiler sources written in classic Modula-2 will be translated to C using a classic Modula-2 to C translator. After the resulting C sources have been compiled and built using a C compiler on the target platform, the compiler sources will be converted to Modula-2 R10 syntax. In the second stage the compiler sources, now in Modula-2 R10 will be translated by the bootstrap compiler itself. When the resulting C sources have been compiled and built again, the compiler becomes self-hosting. This process is called bootstrapping.

Post-Bootstrapping

Once the compiler is self-hosting, it will be gradually enhanced to implement the full language and a back end to generate intermediate representation (IR) for the LLVM compiler infrastructure so that the compiler can be hooked into an LLVM backend. Other backends will be added later. At present backends for JVM and CLR are being considered (subject to funding).

Earlier Code Base

An earlier compiler written in C had been under development in 2010 but work had been suspended until the design was finalised. Sources of this work are being salvaged for the new compiler now being written in classic Modula-2.

Intellectual Property

The intellectual property rights to the compiler and its library will be donated to a non-profit organisation charged with promoting the revival of the Modula-2 language in education and industry. The software will be licensed under a permissive BSD style open source license.

Other Compilers

GNU Compiler Collection (GCC)

Gaius Mulley, the developer of GNU Modula-2 has pledged to add support for Modula-2 R10 in GM2. The GM2 compiler is a Modula-2 front-end for the GNU Compiler Collection (GCC). This software is licensed under the GPL open source license.

Compiler Transformation

To aid the transformation of legacy Modula-2 compilers to Modula-2 R10, we have provided two conversion roadmaps.