Code Generators

The MJr compiler supports multiple target languages through the use of a language-agnostic intermediate representation (IR), and a number of “code generator” classes which each convert the IR to a target language.

Code generator classes inherit from the abstract base class CodeGen.Base. To write a code generator for a new target language, the subclass must have:

Expression precedences from EXPR_WRITE_FUNCS, BINARY_OPS and UNARY_OPS are used by the base class to write parentheses around expressions when necessary. If some target language uses different symbols instead of ‘(’ and ‘)’ for this purpose, they should be provided as the subclass’s LPAREN and RPAREN properties.