Package gnu.expr
Class Compilation
java.lang.Object
gnu.expr.Compilation
- All Implemented Interfaces:
SourceLocator,SourceLocator,Locator
- Direct Known Subclasses:
Translator
State for a single expression or module.
For each top-level thing (expression or file) we compile or evaluate
we create a new Compilation.
-
Nested Class Summary
Nested classes/interfaces inherited from interface gnu.text.SourceLocator
SourceLocator.Simple -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Type[]static Methodstatic Type[]static Methodstatic Type[]static Methodstatic Methodstatic Methodstatic Methodstatic Method[]static Type[]static Methodstatic Fieldstatic final intState code indicating the entire module has been parsed.static final intFunction results are written to the current CallContext's Consumer.static final intSupport for full continuations.static final intPlain calling convention, using regular Java parameters and returns.static final intLike CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls.static final intstatic final intState code indicating that bytecode has been written to its target.If non-null: a prefix for generateClassName to prepend to names.static Stringstatic final intState code that various compile-only data has been determined.static final intState code indicating the bytecode has been generated.protected ScopeExpstatic booleanstatic booleanIf true, print out expressions after parsing and before optimizations.static booleanIf true, print out final expressions after optimizations etc.static intThe default calling convention.static intstatic booleanstatic booleanstatic final intbooleanCompilation was explicitly requested, rather than being a dependency.A help vector for building expressions.static final Fieldstatic Options.OptionInfostatic Methodstatic Methodstatic final MethodbooleanTrue if the compiled result will be immediately loaded.static booleanstatic final Type[]static ClassTypeprotected LanguageCurrent lexical scope - map name to Declaration.static Options.OptionInfostatic Options.OptionInfoprotected SourceMessagesThe current method.static final intstatic final intstatic final intstatic final intGenerated class that extends ModuleBody.static intDefault for whether a module is static.booleanTrue if the form is too complex to evaluate,and we must compile it.static Fieldstatic final ArrayTypestatic Optionsstatic FieldStack of quads of (ModuleInfo, ScopeExp, position, formSize).static final intState code when initial tree-walking (PushApply) are done.static Fieldstatic final intWe have determined the module name and class, but not finished parsing.static final intState code for initial pre-parse looking for module name.static final intState code for lexical bindings having been resolved.static ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic final Type[]static final Type[]static final Fieldstatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic final ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic final ClassTypestatic ClassTypestatic final ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassType[]static ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic ClassTypestatic final Fieldstatic final intState code when various inlining and optimization passes are done.static Options.OptionInfostatic Options.OptionInfostatic Options.OptionInfostatic Options.OptionInfostatic Options.OptionInfostatic Options.OptionInfostatic Options.OptionInfostatic Options.OptionInfostatic boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddMainClass(ModuleExp module) allocLocalField(Type type, String name) applyFunction(Expression func) A language-dependent "apply" function for generic application.asBooleanValue(ConditionalTarget target, Type stackType) Hook for language-specific handling in ConditionalTarget.voidvoidcompileConstant(Object value) Emit code to "evaluate" a compile-time constant.voidcompileConstant(Object value, Target target) voidcompileToArchive(ModuleExp mexp, String fname) intThe same as getModule, until we allow nested modules.voidGenerate code to test if an object is considered true.voidemitPushBoolean(boolean value) Push language-specific boxed true or false value.voiderror(char severity, Declaration decl, String msg1, String msg2) voidvoiderror(char severity, String message, SourceLocator location) voiderror(char severity, String message, String code, SourceLocator decl) static CompilationfindForImmediateLiterals(int key) findNamedClass(String name) Search this Compilation for a ClassType with a given name.voidfreeLocalField(Field field) generateCheckMethod(LambdaExp lexp, LambdaExp parent) voidgenerateCheckMethods(LambdaExp parent) generateClassName(String hint) Generate an unused class name.final voidgenerateConstructor(ClassType clas, LambdaExp lexp) final voidgenerateConstructor(LambdaExp lexp) booleanbooleanTrue if we should generate an Applet.booleanTrue if we should generate a Servlet.final booleangetBooleanOption(String key) Get a named boolean option.final booleangetBooleanOption(String key, boolean defaultValue) Get a named boolean option.final CodeAttrgetCode()final intReturn current column number.static final MethodgetConstructor(ClassType clas, LambdaExp lexp) final MethodgetConstructor(LambdaExp lexp) static Compilationfinal intColumn (one-origin) of end of range; unknown/unspecified is -1.final intLine number (one-origin) of end of range; unknown/unspecified is -1.final StringNormally same as getSystemId.Generate a method to find a named Class without initializing it.final intReturn current line number.getMinfo()final ModuleExpfinal ClassTypegnu.kawa.io.PathGet source filename as an absolute Path, or null.final intColumn (one-origin) of start of range; unknown/unspecified is -1.final intLine number (one-origin) of start of range; unknown/unspecified is -1.intgetState()Returns a code indicating how far along we are in the parsing/compilation process.booleaninlineOk(Expression proc) booleanbooleanbooleanbooleanbooleanA simple apply function maps actual arguments to formals directly.booleanTrue if position is unlikely to change.booleanisStatic()letDone(Expression body) voidletEnter()voidletStart()voidletVariable(Declaration decl, Expression init) letVariable(Object name, Type type, Expression init) final voidGenerate code to push the current CallContext on the JVM stack.voidloadClassRef(ObjectType clas) Generate code to load a named Class without initializing it.voidloopBody(Expression body) Deprecated.voidloopCond(Expression cond) Deprecated.loopDone(Expression body) Finish building a loop and return resulting expression.voidDone handling loop variables, and pushes them into the lexical scope.loopRepeat(LambdaExp loop, Expression... exps) Recurse to next iteration of specified loop.loopRepeatDone(Expression... exps) Combine loopRepeat and loopDone.Start a new loop.loopVariable(Object name, Type type, Expression init) Add a new loop variable, with initializer.static ApplyExpmakeCoercion(Expression value, Type type) Convenience method to make an Expression that coerces a value.static ApplyExpmakeCoercion(Expression value, Expression type) Convenience method to make an Expression that coerces a value.makeQuoteExp(Object value) booleanstatic StringMap a URI to a package/class name.static intvoidNote that we have seen a construct that must be compiled, not evaluated.voidoutputClass(String directory) This may not make sense, except for Lisp-like languages.final voidpop()voidvoidprocess(int wantedState) Parse/visit/compile this module as needed and requested.voidpush(Declaration decl) voidpushNewModule(Lexer lexer) voidpushPendingImport(ModuleInfo info, ScopeExp defs, Translator.FormStack forms, require.DeclSetMapper mapper) final voidstatic intstatic voidrestoreCurrent(Compilation saved) voidsetColumn(int column) static voidsetCurrent(Compilation comp) voidsetCurrentScope(ScopeExp scope) SetcurrentScope().voidGenerate and set unique module name suitable for a call to eval.voidvoidGenerate and set unique module name suitable for an interactive session.voidsetLine(int line) final voidsetLine(Expression position) voidvoidfinal voidsetLocation(SourceLocator position) voidsetMessages(SourceMessages messages) voidvoidsetModuleName(String name) Set module name - which sets name of generated class.voidsetPedantic(boolean value) voidsetPushCurrentScope(ScopeExp scope) static CompilationsetSaveCurrent(Compilation comp) voidsetSharedModuleDefs(boolean shared) voidsetState(int state) static voidsetupLiterals(int key) Call-back from compiled code to initialize literals in immediate mode.booleansyntaxError(String message) Handle syntax errors (at rewrite time).toString()voidCalled for classes referenced in bytecode.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanboolean
-
Field Details
-
mustCompile
public boolean mustCompileTrue if the form is too complex to evaluate,and we must compile it. This is because it contains a construct we know how to compile, but not evaluate, and it it outside a function (which we always compile). This can be a let scope, or primitive procedure. -
curClass
-
mainClass
-
moduleClass
Generated class that extends ModuleBody. Normally same as mainClass. -
curLambda
-
mainLambda
-
thisDecl
-
PROLOG_PARSING
public static final int PROLOG_PARSINGState code for initial pre-parse looking for module name.- See Also:
-
PROLOG_PARSED
public static final int PROLOG_PARSEDWe have determined the module name and class, but not finished parsing.- See Also:
-
BODY_PARSED
public static final int BODY_PARSEDState code indicating the entire module has been parsed.- See Also:
-
RESOLVED
public static final int RESOLVEDState code for lexical bindings having been resolved.- See Also:
-
PRE_WALKED
public static final int PRE_WALKEDState code when initial tree-walking (PushApply) are done.- See Also:
-
WALKED
public static final int WALKEDState code when various inlining and optimization passes are done.- See Also:
-
COMPILE_SETUP
public static final int COMPILE_SETUPState code that various compile-only data has been determined.- See Also:
-
COMPILED
public static final int COMPILEDState code indicating the bytecode has been generated.- See Also:
-
CLASS_WRITTEN
public static final int CLASS_WRITTENState code indicating that bytecode has been written to its target.- See Also:
-
ERROR_SEEN
public static final int ERROR_SEEN- See Also:
-
lexer
-
pendingImports
Stack of quads of (ModuleInfo, ScopeExp, position, formSize). -
subModuleMap
-
writeImplicitClasses
public static boolean writeImplicitClasses -
debugPrintExpr
public static boolean debugPrintExprIf true, print out expressions after parsing and before optimizations. -
debugPrintFinalExpr
public static boolean debugPrintFinalExprIf true, print out final expressions after optimizations etc. -
debugPrintANF
public static boolean debugPrintANF -
enableANF
public static boolean enableANF -
options
-
fullTailCallsVariable
-
mainMethodVariable
-
warnUnreachable
-
warnVoidUsed
-
warnUninitialized
-
warnUndefinedVariable
-
warnUnknownMember
-
warnInvokeUnknownMethod
-
warnUnused
-
warnAsError
-
maxErrors
-
currentOptions
-
defaultClassFileVersion
public static int defaultClassFileVersion -
defaultCallConvention
public static int defaultCallConventionThe default calling convention. One of the following CALL_WITH_xxx values. -
CALL_WITH_UNSPECIFIED
public static final int CALL_WITH_UNSPECIFIED- See Also:
-
CALL_WITH_RETURN
public static final int CALL_WITH_RETURNPlain calling convention, using regular Java parameters and returns.- See Also:
-
CALL_WITH_CONSUMER
public static final int CALL_WITH_CONSUMERFunction results are written to the current CallContext's Consumer.- See Also:
-
CALL_WITH_TAILCALLS
public static final int CALL_WITH_TAILCALLSLike CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls.- See Also:
-
CALL_WITH_CONTINUATIONS
public static final int CALL_WITH_CONTINUATIONSSupport for full continuations. Not implemented.- See Also:
-
MODULE_NONSTATIC
public static final int MODULE_NONSTATIC- See Also:
-
MODULE_STATIC_DEFAULT
public static final int MODULE_STATIC_DEFAULT- See Also:
-
MODULE_STATIC
public static final int MODULE_STATIC- See Also:
-
MODULE_STATIC_RUN
public static final int MODULE_STATIC_RUN- See Also:
-
moduleStatic
public static int moduleStaticDefault for whether a module is static. IfmoduleStatic > 0, then(module-static #t)is implied by default. IfmoduleStatic == MODULE_STATIC_RUN, then<clinit>callsrun. IfmoduleStatic < 0, then(module-static #f)is implied by default. -
immediate
public boolean immediateTrue if the compiled result will be immediately loaded. -
explicit
public boolean explicitCompilation was explicitly requested, rather than being a dependency. -
method
The current method. -
typeObject
-
scmBooleanType
-
typeString
-
typeCharSequence
-
javaStringType
-
scmKeywordType
-
scmSequenceType
-
typeList
-
scmListType
-
typePair
-
objArrayType
-
typeRunnable
-
typeRunnableModule
-
typeType
-
typeObjectType
-
typeClass
-
typeClassType
-
typeProcedure
-
typeLanguage
-
typeEnvironment
-
typeLocation
-
typeLocationProc
-
typeFieldLocation
-
typeStaticFieldLocation
-
typeSymbol
-
trueConstant
-
falseConstant
-
voidConsumerInstanceField
-
int1Args
-
string1Arg
-
sym1Arg
-
getCurrentEnvironmentMethod
-
apply0args
-
apply1args
-
apply2args
-
applyNargs
-
apply0method
-
apply1method
-
apply2method
-
apply3method
-
apply4method
-
applyNmethod
-
applymethods
-
typeProcedure0
-
typeProcedure1
-
typeProcedure2
-
typeProcedure3
-
typeProcedure4
-
typeProcedureN
-
typeModuleBody
-
typeApplet
-
typeServlet
-
typeCallContext
-
typeConsumer
-
getCallContextInstanceMethod
-
typeValues
-
noArgsField
-
pcCallContextField
-
typeMethodProc
-
typeCompiledProc
-
argsCallContextField
-
procCallContextField
-
applyCpsMethod
-
typeProcedureArray
-
getNextArgMethod
-
inlineOk
public static boolean inlineOk -
classPrefixDefault
-
classPrefix
If non-null: a prefix for generateClassName to prepend to names. -
emitSourceDebugExtAttr
public static boolean emitSourceDebugExtAttr -
language
-
exprStack
A help vector for building expressions. -
lexical
Current lexical scope - map name to Declaration. -
current_scope
-
messages
-
-
Constructor Details
-
Compilation
-
-
Method Details
-
getState
public int getState()Returns a code indicating how far along we are in the parsing/compilation process. -
setState
public void setState(int state) -
isPedantic
public boolean isPedantic() -
setPedantic
public void setPedantic(boolean value) -
pushPendingImport
public void pushPendingImport(ModuleInfo info, ScopeExp defs, Translator.FormStack forms, require.DeclSetMapper mapper) -
generateMainMethod
public boolean generateMainMethod() -
warnUnreachable
public boolean warnUnreachable() -
warnUndefinedVariable
public boolean warnUndefinedVariable() -
warnUnknownMember
public boolean warnUnknownMember() -
warnInvokeUnknownMethod
public boolean warnInvokeUnknownMethod() -
warnUnused
public boolean warnUnused() -
warnUninitialized
public boolean warnUninitialized() -
warnVoidUsed
public boolean warnVoidUsed() -
warnAsError
public boolean warnAsError() -
maxErrors
public static int maxErrors() -
getBooleanOption
Get a named boolean option. -
getBooleanOption
Get a named boolean option. -
currentCallConvention
public int currentCallConvention() -
usingCPStyle
public boolean usingCPStyle() -
usingTailCalls
public boolean usingTailCalls() -
usingCallContext
public boolean usingCallContext() -
getCode
-
generatingApplet
public boolean generatingApplet()True if we should generate an Applet. -
generatingServlet
public boolean generatingServlet()True if we should generate a Servlet. -
getModuleType
-
compileConstant
Emit code to "evaluate" a compile-time constant. This is the normal external interface.- Parameters:
value- the value to be compiled
-
inlineOk
-
inlineOk
-
isApplyFunction
-
isSimpleApplyFunction
A simple apply function maps actual arguments to formals directly. E.g. no distribution of multiple values. -
compileConstant
-
emitPushBoolean
public void emitPushBoolean(boolean value) Push language-specific boxed true or false value. -
emitCoerceToBoolean
public void emitCoerceToBoolean()Generate code to test if an object is considered true. Assume the object has been pushed on the JVM stack. Generate code to push (unboxed) true or false as appropriate. -
asBooleanValue
Hook for language-specific handling in ConditionalTarget.- Parameters:
stackType- Value to be treated as boolean, already pushed.- Returns:
- null if we've handled the conditional transfer; otherwise type value has been converted to (usually booleanType).
-
findNamedClass
Search this Compilation for a ClassType with a given name.- Parameters:
name- the name of the class desired- Returns:
- the matching ClassType, or null if none is found
-
mangleURI
Map a URI to a package/class name. Similar to the JAXB mangling, and that in the Java language spec. -
generateClassName
Generate an unused class name.- Parameters:
hint- the requested name (or prefix)- Returns:
- a unique class name.
-
outputClass
- Throws:
IOException
-
cleanupAfterCompilation
public void cleanupAfterCompilation() -
compileToArchive
- Throws:
IOException
-
addClass
-
makeRunnable
public boolean makeRunnable() -
addMainClass
-
getConstructor
-
getConstructor
-
generateConstructor
-
generateConstructor
-
generateCheckMethod
-
generateCheckMethods
-
process
public void process(int wantedState) Parse/visit/compile this module as needed and requested. This method does not process any dependent modules (expect indirectly, such as may be done by a require form).- Parameters:
wantedState- the desired value of getState().
-
allocLocalField
-
loadCallContext
public final void loadCallContext()Generate code to push the current CallContext on the JVM stack. -
freeLocalField
-
parse
This may not make sense, except for Lisp-like languages. For those, 'input' an s-expression from the reader. -
getLanguage
-
currentLambda
-
getModule
-
setModule
-
isStatic
public boolean isStatic() -
isInteractive
public boolean isInteractive() -
currentModule
The same as getModule, until we allow nested modules. -
mustCompileHere
public void mustCompileHere()Note that we have seen a construct that must be compiled, not evaluated. If we are not inside a lambda (which is always compiled), but only inside the outer-most ModuleExp, note that it must be compiled. -
currentScope
-
setCurrentScope
SetcurrentScope(). Also update thenestingobject. -
setPushCurrentScope
-
setPopCurrentScope
-
pushNewModule
-
push
-
pushScope
-
pop
-
pop
public final void pop() -
push
-
lookup
-
usedClass
Called for classes referenced in bytecode. Since this only does something when immediate, we only care about classes referenced in the bytecode when immediate. It is used to ensure that we can inherit from classes defined when in immediate mode (in Scheme using define-class or similar). -
setModuleName
Set module name - which sets name of generated class. -
setInteractiveName
public void setInteractiveName()Generate and set unique module name suitable for an interactive session. -
setEvalName
public void setEvalName()Generate and set unique module name suitable for a call to eval. -
getMessages
-
setMessages
-
error
-
error
-
error
-
error
-
syntaxError
Handle syntax errors (at rewrite time).- Parameters:
message- an error message to print out- Returns:
- an ErrorExp
-
getLineNumber
public final int getLineNumber()Description copied from interface:SourceLocatorReturn current line number. Normally the same asgetStartLine(). The "first" line is line 1; unknown is -1.- Specified by:
getLineNumberin interfaceLocator- Specified by:
getLineNumberin interfaceSourceLocator- Specified by:
getLineNumberin interfaceSourceLocator
-
getColumnNumber
public final int getColumnNumber()Description copied from interface:SourceLocatorReturn current column number. Normally the same asgetStartColumn(). The "first" column is column 1; unknown is -1.- Specified by:
getColumnNumberin interfaceLocator- Specified by:
getColumnNumberin interfaceSourceLocator- Specified by:
getColumnNumberin interfaceSourceLocator
-
getStartLine
public final int getStartLine()Description copied from interface:SourceLocatorLine number (one-origin) of start of range; unknown/unspecified is -1.- Specified by:
getStartLinein interfaceSourceLocator
-
getStartColumn
public final int getStartColumn()Description copied from interface:SourceLocatorColumn (one-origin) of start of range; unknown/unspecified is -1.- Specified by:
getStartColumnin interfaceSourceLocator
-
getEndLine
public final int getEndLine()Description copied from interface:SourceLocatorLine number (one-origin) of end of range; unknown/unspecified is -1.- Specified by:
getEndLinein interfaceSourceLocator
-
getEndColumn
public final int getEndColumn()Description copied from interface:SourceLocatorColumn (one-origin) of end of range; unknown/unspecified is -1.- Specified by:
getEndColumnin interfaceSourceLocator
-
getFileName
Description copied from interface:SourceLocatorNormally same as getSystemId.- Specified by:
getFileNamein interfaceSourceLocator
-
getPublicId
- Specified by:
getPublicIdin interfaceLocator- Specified by:
getPublicIdin interfaceSourceLocator- Specified by:
getPublicIdin interfaceSourceLocator
-
getSystemId
- Specified by:
getSystemIdin interfaceLocator- Specified by:
getSystemIdin interfaceSourceLocator- Specified by:
getSystemIdin interfaceSourceLocator
-
isStableSourceLocation
public boolean isStableSourceLocation()Description copied from interface:SourceLocatorTrue if position is unlikely to change. True for an expression but not an input file.- Specified by:
isStableSourceLocationin interfaceSourceLocator
-
setFile
-
setLine
public void setLine(int line) -
setColumn
public void setColumn(int column) -
setLine
-
setLine
-
setLocation
-
setLine
-
getSourceAbsPath
public gnu.kawa.io.Path getSourceAbsPath()Get source filename as an absolute Path, or null. Return null if there is no actual file, such as a<string>. Note theModuleInfo.getSourceAbsPath()is similar, but this version is not canonicalized. -
letStart
public void letStart() -
letVariable
-
letVariable
-
letEnter
public void letEnter() -
letDone
-
loopStart
Start a new loop. This provides the functionality of Scheme 'named let'. -
loopVariable
Add a new loop variable, with initializer. -
loopEnter
public void loopEnter()Done handling loop variables, and pushes them into the lexical scope. Ready to parse the loop condition. -
loopCond
Deprecated. -
loopBody
Deprecated. -
loopRepeat
Recurse to next iteration of specified loop. -
loopDone
Finish building a loop and return resulting expression. -
loopRepeatDone
Combine loopRepeat and loopDone. Assume loopCond and loopBody have been called. -
applyFunction
A language-dependent "apply" function for generic application. -
makeQuoteExp
-
makeCoercion
Convenience method to make an Expression that coerces a value.- Parameters:
value- to be coercedtype- to coerce value to- Returns:
- expression that coerces value to type
-
makeCoercion
Convenience method to make an Expression that coerces a value.- Parameters:
value- to be coercedtype- to coerce value to- Returns:
- expression that coerces value to type
-
loadClassRef
Generate code to load a named Class without initializing it. -
getForNameHelper
Generate a method to find a named Class without initializing it. Generate a static helper method "class$" like javac generates for 'CLASS.class', but does not initialize CLASS. Also, we don't bother catching exceptions, since the JVM doesn't require us to. I.e. generates: public static class $(String name) { return Class.forName(name, false, Class.forName(THISCLASSNAME).getClassLoader()); } Note that we want the result to use the same ClassLoader as the caller, which is why we generate a static helper method. -
getGlobalEnvironment
-
resolve
-
setupLiterals
public static void setupLiterals(int key) Call-back from compiled code to initialize literals in immediate mode. In non-immediate mode (i.e. generating class files) the compiler emits code to "re-construct" literal values. However, in immediate mode that would be wasteful, plus we would get values that are similar (equals) to but not necessarily identical (eq) to the compile-time literal. So we need to pass the literal values to the compiled code, by using reflection to initialize various static fields. This method does that. It is called at the start of the generated static initializer, which helps makes things more consistent between immediate and non-immediate mode. -
registerForImmediateLiterals
-
findForImmediateLiterals
-
getCurrent
-
setCurrent
-
setSaveCurrent
-
restoreCurrent
-
toString
-
getMinfo
-