The LPC Code Compiler: /lib/compiler

The compiler's job is to write an LPC file containing code that implements the behavior specified by a MOO abstract syntax tree.

The LPC file will then be loaded by DGD as an independent object, the "verb" object for the program. The compiler writes at least one function to the file, called main(), which acts as the entry point for the verb. If any fork constructs are part of the program, each of these will also receive its own function in the file, so that they can be called with a delay via DGD's call_out() mechanism.

It should be noted that only a skeleton of the verb's behavior is generated by the compiler. The actual implementation of complex operations is kept in a separate support object that the verb inherits.

The compiler calls the MOO code optimizer first to (hopefully) perform static optimizations on the syntax tree before compiling it.

This description does not yet go into the excruciating detail of how MOO code is compiled into LPC. For the most part the translation is fairly straight-forward. However, idiosyncrasies of execution flow (especially where suspend() is involved) forces compilation to produce code that resembles a virtual stack machine.

The compiler's interface is:

    mixed *ast;
    string file;

    COMPILER->main(ast, file);
No errors are ever generated by the compiler.