Package kawa.lang
Class Translator
java.lang.Object
gnu.expr.Compilation
kawa.lang.Translator
- All Implemented Interfaces:
SourceLocator,SourceLocator,Locator
- Direct Known Subclasses:
SchemeCompilation
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA list of "forms" to be further processed.static classstatic classAn implementationof Values using a linked list.Nested classes/interfaces inherited from interface gnu.text.SourceLocator
SourceLocator.Simple -
Field Summary
FieldsModifier and TypeFieldDescriptionSet if we're processing (as opposed to expanding) adefine-syntaxordefmacro.static final DeclarationA variable to hold the matched values for syntax-case pattern variables.Innermost current scope of pattern variable, from asyntax-case.Fields inherited from class gnu.expr.Compilation
apply0args, apply0method, apply1args, apply1method, apply2args, apply2method, apply3method, apply4method, applyCpsMethod, applymethods, applyNargs, applyNmethod, argsCallContextField, BODY_PARSED, CALL_WITH_CONSUMER, CALL_WITH_CONTINUATIONS, CALL_WITH_RETURN, CALL_WITH_TAILCALLS, CALL_WITH_UNSPECIFIED, CLASS_WRITTEN, classPrefix, classPrefixDefault, COMPILE_SETUP, COMPILED, curClass, curLambda, current_scope, currentOptions, debugPrintANF, debugPrintExpr, debugPrintFinalExpr, defaultCallConvention, defaultClassFileVersion, emitSourceDebugExtAttr, enableANF, ERROR_SEEN, explicit, exprStack, falseConstant, fullTailCallsVariable, getCallContextInstanceMethod, getCurrentEnvironmentMethod, getNextArgMethod, immediate, inlineOk, int1Args, javaStringType, language, lexer, lexical, mainClass, mainLambda, mainMethodVariable, maxErrors, messages, method, MODULE_NONSTATIC, MODULE_STATIC, MODULE_STATIC_DEFAULT, MODULE_STATIC_RUN, moduleClass, moduleStatic, mustCompile, noArgsField, objArrayType, options, pcCallContextField, pendingImports, PRE_WALKED, procCallContextField, PROLOG_PARSED, PROLOG_PARSING, RESOLVED, scmBooleanType, scmKeywordType, scmListType, scmSequenceType, string1Arg, subModuleMap, sym1Arg, thisDecl, trueConstant, typeApplet, typeCallContext, typeCharSequence, typeClass, typeClassType, typeCompiledProc, typeConsumer, typeEnvironment, typeFieldLocation, typeLanguage, typeList, typeLocation, typeLocationProc, typeMethodProc, typeModuleBody, typeObject, typeObjectType, typePair, typeProcedure, typeProcedure0, typeProcedure1, typeProcedure2, typeProcedure3, typeProcedure4, typeProcedureArray, typeProcedureN, typeRunnable, typeRunnableModule, typeServlet, typeStaticFieldLocation, typeString, typeSymbol, typeType, typeValues, voidConsumerInstanceField, WALKED, warnAsError, warnInvokeUnknownMethod, warnUndefinedVariable, warnUninitialized, warnUnknownMember, warnUnreachable, warnUnused, warnVoidUsed, writeImplicitClasses -
Constructor Summary
ConstructorsConstructorDescriptionTranslator(Language language, SourceMessages messages, NameLookup lexical) Translator(Language language, SourceMessages messages, NameLookup lexical, Environment env) -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckDefaultBinding(Symbol symbol, Translator tr) If a symbol is lexically unbound, look for a default binding.intdefine(Object name, SyntaxForm nameSyntax, ScopeExp defs) define(Object name, TemplateScope templateScope, ScopeExp defs) voiderrorIfNonEmpty(Object form) voiderrorWithPosition(String message, Object form) Extract a type from the car of a pair.exp2Type(Pair typeSpecPair, Declaration decl, SyntaxForm syntax) voidfinishModule(ModuleExp mexp) intgetCompletions(Environment env, String nameStart, Object property, String namespaceUri, List<? super String> matches) final Environmentfinal booleanstatic intlistLength(Object obj) Returns the length of a syntax list.lookupGlobal(Object name) Find global Declaration, creating one if not found.lookupGlobal(Object name, int namespace) Find global Declaration, creating one if not found.static StringmakeBody(Expression[] exps) Combine a 'body' consisting of a list of expression.protected ExpressionCombine a list of zero or more expression forms into a "body".static PairmakeRenamedAlias(Declaration decl, ScopeExp templateScope) makeRenamedAlias(Object name, Declaration decl, ScopeExp templateScope) final booleanTrue iff a form matches a literal symbol.booleanmatches(Object form, SyntaxForm syntax, Symbol literal) booleanmatches(Object form, SyntaxForm syntax, String literal) matchQuoted(Pair pair) namespaceResolve(Expression context, Expression member) namespaceResolve(Namespace ns, Expression member) namespaceResolve(Object name) namespaceResolvePrefix(Expression context) voidnoteAccess(Object name, ScopeExp scope) Note that we reference name in a given scope.This may not make sense, except for Lisp-like languages.Pop from formStack all forms that come after beforeFirst.voidpopPositionOf(Object saved) Restore line number position from a previous pushPositionOf.voidpopRenamedAlias(int count) Remove one or more aliases created bypushRenamedAlias.voidvoidCheck references recorded by noteAccess.voidpushPositionOf(Object pos) Note current line number position from a PairWithPosition.voidpushRenamedAlias(Declaration alias) Push an alias for a declaration in a scope.voidpushScanContext(LambdaExp lambda) intvoidresolveModule(ModuleExp mexp) Re-write a Scheme expression in S-expression format into internal form.Re-write a Scheme expression in S-expression format into internal form.Re-write a Scheme expression in S-expression format into internal form.rewrite_body(Object exp) Re-write a Scheme 'body' in S-expression format into internal form.final Expressionrewrite_car(Pair pair, boolean function) final Expressionrewrite_car(Pair pair, ScopeExp templateScope) final Expressionrewrite_car(Pair pair, SyntaxForm syntax) final Expressionrewrite_car_for_lookup(Pair pair) Similar to rewrite_car.rewrite_lookup(Expression part1, Expression part2, boolean function) rewrite_pair(Pair p, boolean function) rewrite_with_position(Object exp, boolean function, PairWithPosition pair) protected voidrewriteBody(LList forms) voidrewriteInBody(Object exp) static Objectstatic ObjectRecursive helper method for rewrite_body.voidfinal booleanstatic voidsetLine(Declaration decl, Object location) static voidsetLine(Expression exp, Object location) voidsetLineOf(Expression exp) Set the line position of the argument to the current position.static ObjectstripSyntax(Object obj) static ObjectwrapSyntax(Object form, SyntaxForm syntax) Methods inherited from class gnu.expr.Compilation
addClass, addMainClass, allocLocalField, applyFunction, asBooleanValue, cleanupAfterCompilation, compileConstant, compileConstant, compileToArchive, currentCallConvention, currentLambda, currentModule, currentScope, emitCoerceToBoolean, emitPushBoolean, error, error, error, error, findForImmediateLiterals, findNamedClass, freeLocalField, generateCheckMethod, generateCheckMethods, generateClassName, generateConstructor, generateConstructor, generateMainMethod, generatingApplet, generatingServlet, getBooleanOption, getBooleanOption, getCode, getColumnNumber, getConstructor, getConstructor, getCurrent, getEndColumn, getEndLine, getFileName, getForNameHelper, getLanguage, getLineNumber, getMessages, getMinfo, getModule, getModuleType, getPublicId, getSourceAbsPath, getStartColumn, getStartLine, getState, getSystemId, inlineOk, inlineOk, isApplyFunction, isInteractive, isPedantic, isSimpleApplyFunction, isStableSourceLocation, isStatic, letDone, letEnter, letStart, letVariable, letVariable, loadCallContext, loadClassRef, loopBody, loopCond, loopDone, loopEnter, loopRepeat, loopRepeatDone, loopStart, loopVariable, makeCoercion, makeCoercion, makeQuoteExp, makeRunnable, mangleURI, maxErrors, mustCompileHere, outputClass, pop, pop, process, push, push, pushNewModule, pushPendingImport, pushScope, registerForImmediateLiterals, resolve, restoreCurrent, setColumn, setCurrent, setCurrentScope, setEvalName, setFile, setInteractiveName, setLine, setLine, setLine, setLine, setLocation, setMessages, setModule, setModuleName, setPedantic, setPopCurrentScope, setPushCurrentScope, setSaveCurrent, setSharedModuleDefs, setState, setupLiterals, sharedModuleDefs, syntaxError, toString, usedClass, usingCallContext, usingCPStyle, usingTailCalls, warnAsError, warnInvokeUnknownMethod, warnUndefinedVariable, warnUninitialized, warnUnknownMember, warnUnreachable, warnUnused, warnVoidUsed
-
Field Details
-
currentMacroDefinition
Set if we're processing (as opposed to expanding) adefine-syntaxordefmacro. -
patternScope
Innermost current scope of pattern variable, from asyntax-case. -
templateScopeDecl
-
matchArray
A variable to hold the matched values for syntax-case pattern variables. -
pendingForm
-
curMethodLambda
-
xmlElementNamespaces
-
getNamedPartDecl
-
formStack
-
-
Constructor Details
-
Translator
-
Translator
-
-
Method Details
-
getGlobalEnvironment
- Overrides:
getGlobalEnvironmentin classCompilation
-
parse
Description copied from class:CompilationThis may not make sense, except for Lisp-like languages. For those, 'input' an s-expression from the reader.- Overrides:
parsein classCompilation
-
rewrite_car
-
rewrite_car
-
rewrite_car
-
rewrite_car_for_lookup
Similar to rewrite_car. However, we check for (quasiquote exp) specially, and handle that directly. This is in case quasiquote isn't in scope. -
getCurrentSyntax
-
keywordsAreSelfEvaluating
public final boolean keywordsAreSelfEvaluating() -
selfEvaluatingSymbol
-
matches
True iff a form matches a literal symbol. -
matches
-
matches
-
matchQuoted
-
lookup
- Overrides:
lookupin classCompilation
-
lookupGlobal
Find global Declaration, creating one if not found. -
lookupGlobal
Find global Declaration, creating one if not found. -
rewrite_pair
-
rewrite_lookup
-
namespaceResolvePrefix
-
namespaceResolve
-
namespaceResolve
-
stripSyntax
-
safeCar
-
safeCdr
-
listLength
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 handles SyntaxForm more efficiently. -
rewriteInBody
-
getCompletions
-
namespaceResolve
-
rewrite
Re-write a Scheme expression in S-expression format into internal form. -
rewrite
Re-write a Scheme expression in S-expression format into internal form. -
rewrite
Re-write a Scheme expression in S-expression format into internal form.- Parameters:
mode- either 'N' (normal), 'F' (function application context), 'M' (macro-checking) or 'Q' (colon-form in quote).
-
checkDefaultBinding
If a symbol is lexically unbound, look for a default binding. The default implementation does the following: If the symbol is the name of an existing Java class, return that class. Handles both with and without (semi-deprecated) angle-brackets:<java.lang.Integer>andjava.lang.Integer. Also handles arrays, such asjava.lang.String[]. If the symbol starts with'@'parse as an annotation class. Recognizes quanties with units, such as2mand3m/s^2. Handles the xml and unit namespaces.- Returns:
- null if no binding, otherwise an Expression. FIXME: This method should be refactored. The quantities parsing should be moved to its own method at least.
-
lookupStandardEntity
-
setLine
-
setLine
-
pushPositionOf
Note current line number position from a PairWithPosition. Return an object to pass to popPositionOf. -
popPositionOf
Restore line number position from a previous pushPositionOf.- Parameters:
saved- value returned by matching pushPositionOf.
-
errorWithPosition
-
errorIfNonEmpty
-
setLineOf
Set the line position of the argument to the current position. -
exp2Type
Extract a type from the car of a pair. -
exp2Type
-
rewrite_with_position
-
wrapSyntax
-
popForms
Pop from formStack all forms that come after beforeFirst. -
scanForm
-
scanBody
Recursive helper method for rewrite_body. Scan body for definitions, adding partially macro-expanded expressions into theformStack.- Parameters:
makeList- if true, return a list representation of the scanned forms (not including declarations); else forms are push on formStack- Returns:
- a list of forms if
makeList(possibly wrapped in aSyntaxForm); otherwisenull.
-
makePair
-
rewrite_body
Re-write a Scheme 'body' in S-expression format into internal form. -
rewriteBody
-
makeBody
Combine a list of zero or more expression forms into a "body". -
appendBodyValues
public boolean appendBodyValues() -
makeBody
Combine a 'body' consisting of a list of expression. -
noteAccess
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. -
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. -
finishModule
-
resolveModule
-
makeRenamedAlias
-
makeRenamedAlias
-
pushRenamedAlias
Push an alias for a declaration in a scope. If the name ofdeclcame from a syntax template whose immediate scope istemplateScope, then the same syntax template may contain local variable references that are also in the sametemplateScope. Such variable references will not look in the current "physical" scope, where we just createddecl, but will instead search the "lexical"templateScope. So that such references can resolve todecl, we create an alias intemplateScopethat points todecl. We record that we did this in therenamedAliasStack, so we can remove the alias later. -
renamedAliasCount
public int renamedAliasCount() -
popRenamedAlias
public void popRenamedAlias(int count) Remove one or more aliases created bypushRenamedAlias. -
define
-
define
-
define
-
pushForm
-
getScanContext
-
curScanNesting
public int curScanNesting() -
getScanContextStack
-
pushScanContext
-
popScanContext
public void popScanContext()
-