Used to translate from source to Expression.
The result has macros expanded, lexical names bound, etc, and is
ready for code generation.
This is sometimes called a "compilation environment",
but we modify it as we go along - there is a single Translator for
each top-level form.
exp2Type
public Type exp2Type(Pair typeSpecPair)
Extract a type from the car of a pair.
finishModule
public void finishModule(ModuleExp mexp)
getCurrentSyntax
public Syntax getCurrentSyntax()
getGlobalEnvironment
public final Environment getGlobalEnvironment()
isLexical
public boolean isLexical(Declaration decl)
Return true if decl is lexical and not fluid.
listLength
public static int listLength(Object obj)
Returns the length of a syntax list.
Returns Integer.MIN_VALUE for cyclic lists.
For impure lists returns the negative of one more than
the number of pairs before the "dot".
Similar to LList.listLength, but descends into SyntaxForm.
lookupGlobal
public Declaration lookupGlobal(Object name)
Find global Declaration, creating one if not found.
lookupGlobal
public Declaration lookupGlobal(Object name,
int namespace)
Find global Declaration, creating one if not found.
makeBody
public Expression makeBody(int first,
ScopeExp scope)
Combine a list of zero or more expression forms into a "body".
makePair
public static Pair makePair(Pair pair,
Object car,
Object cdr)
matches
public final boolean matches(Object form,
String literal)
True iff a form matches a literal symbol.
matches
public boolean matches(Object form,
SyntaxForm syntax,
String literal)
namespaceResolve
public Object namespaceResolve(Object name)
noteAccess
public void noteAccess(Object name,
ScopeExp scope)
Note that we reference name in a given scope.
This may be called when defining a macro, at scan-time,
and the name may be bound to a declaration we haven't seen yet.
popForms
public Object popForms(int first)
popPositionOf
public void popPositionOf(Object saved)
Restore line number position from a previous pushPositionOf.
saved
- value returned by matching pushPositionOf.
popRenamedAlias
public void popRenamedAlias(int count)
Remove one or more aliases created by pushRenamedAlias
.
processAccesses
public void processAccesses()
Check references recorded by noteAccess.
Resolve now to a Declaration, and note the access.
This is needed in case an exported macro references a private Declaration.
pushPositionOf
public Object pushPositionOf(Object pair)
Note current line number position from a PairWithPosition.
Return an object to pass to popPositionOf.
pushRenamedAlias
public void pushRenamedAlias(Declaration alias)
Push an alias for a declaration in a scope.
If the name of decl
came from a syntax template
whose immediate scope is templateScope
,
then the same syntax template may contain local variable references
that are also in the same templateScope
.
Such variable references will not look in the current
"physical" scope, where we just created decl
, but
will instead search the "lexical" templateScope.
So that such references can resolve to
decl
, we
create an alias in templateScope
that points
to decl
. We record that we did this in the
renamedLiasStack
, so we can remove the alias later.
resolveModule
public void resolveModule(ModuleExp mexp)
rewrite
public Expression rewrite(Object exp)
Re-write a Scheme expression in S-expression format into internal form.
rewrite
public Expression rewrite(Object exp,
boolean function)
Re-write a Scheme expression in S-expression format into internal form.
rewriteBody
public void rewriteBody(int first)
rewriteInBody
public void rewriteInBody(Object exp)
rewrite_body
public Expression rewrite_body(Object exp)
Re-write a Scheme
rewrite_car
public final Expression rewrite_car(Pair pair,
boolean function)
safeCar
public static Object safeCar(Object obj)
safeCdr
public static Object safeCdr(Object obj)
scanBody
public Object scanBody(Object body,
ScopeExp defs,
boolean makeList)
Recursive helper method for rewrite_body.
Scan body for definitions, adding partially macro-expanded
expressions into the formStack
.
makeList
- if true, return a list representation of the scanned
forms (not including declarations); else forms are push on formStack
- a list of forms if
makeList
(possibly wrapped
in a SyntaxForm
); otherwise null
.
scanForm
public void scanForm(Object st,
ScopeExp defs)
setLine
public static void setLine(Declaration decl,
Object location)
setLine
public static void setLine(Expression exp,
Object location)
setLineOf
public void setLineOf(Expression exp)
Set the line position of the argument to the current position.
stripSyntax
public static Object stripSyntax(Object obj)
wrapSyntax
public static Object wrapSyntax(Object form,
SyntaxForm syntax)