| www.delorie.com/gnu/docs/kawa/kawa-tour_13.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The translation phase takes a top-level form (or body),
and generates a ModuleExp, which is a top-level expression.
This is done using a Translator, which keeps track of
lexical bindings and other translation state.
class Translator {
public Expression rewrite (Object exp)
{ ... }
public Expression syntaxError (String message)
{ ... }
...
}
|
The rewrite method converts a Scheme source form to
an Expression. The syntaxError method is called when
a syntax error is seen. It prints out the current
source filename and line number with the given message.
A ModuleExp represents a top-level form.
class ModuleExp extends LambdaExp {
public Object eval_module (Environment env)
{
if (body_is_simple) // Optimization
return body.eval (env);
Object v = eval (env);
return ((ModuleBody) v).run (env);
}
...
}
|
ModuleExp is a sub-class of LambdaExp,
since it is actually a dummy function created by
wrapping the top-level forms in an implicit lambda.
The eval_module method evaluates the top-level forms.
It invokes the eval in LambdaExp (which invokes the compiler).
The result of eval is a ModuleBody (see section 1.8 Procedures),
which we can run. If the body is "simple"
we don't bother actually evaluating the ModuleExp,
since that entails compiling it to a bytecoded class;
we just eval the body instead.
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |