www.delorie.com/gnu/docs/kawa/kawa-tour_10.html   search  
 
Buy GNU books!


Kawa: Compiling Scheme to Java

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.9 Overview of compilation

These are the stages of compilation:

Reading
The first compilation stage reads the input from a file, from a string, or from the interactive command interpreter. The result is one or more Scheme forms (S-expressions), usually lists. If reading commands interactively, only a single form is read; if reading from a file or string, all the forms are read until end-of-file or end-of-string; in either case, the result is treated as the body of a dummy function (i.e. a ModuleBody).

Translation
The source form body is rewritten into an Expression object, specifically a ModuleExp. This stage handles macro expansion and lexical name binding. Many (future) optimizations can be done in this phase by annotating and re-arranging Expression trees.

Code generation
The resulting ModuleExp is compiled into one or more byte-coded classes. This is done by invoking the virtual compile method recursively on the Expressions, which generates instructions (using the codegen package) to evaluate the expression and leave the result on the Java operand stack. At the end we ask the codegen package to write out the resulting classes and methods. They can be written to a file (for future use), or into byte arrays in memory.

Loading
The compiled bytecodes are loaded into the Kawa interpreter. In the case of code that is compiled and then immediately executed, the compiled code can be immediately turned into Java classes using the Java ClassLoader feature. (That is how the read-eval-print loop works.) An instance of the compiled sub-class of ModuleBody is created and run, which normally produces various side-effects.


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright © 2003   by The Free Software Foundation     Updated Jun 2003