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 Method
static Type[]
static Method
static Type[]
static Method
static Method
static Method
static Method
static Method[]
static Type[]
static Method
static Field
static final int
State code indicating the entire module has been parsed.static final int
Function results are written to the current CallContext's Consumer.static final int
Support for full continuations.static final int
Plain calling convention, using regular Java parameters and returns.static final int
Like CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls.static final int
static final int
State code indicating that bytecode has been written to its target.If non-null: a prefix for generateClassName to prepend to names.static String
static final int
State code that various compile-only data has been determined.static final int
State code indicating the bytecode has been generated.protected ScopeExp
static boolean
static boolean
If true, print out expressions after parsing and before optimizations.static boolean
If true, print out final expressions after optimizations etc.static int
The default calling convention.static int
static boolean
static boolean
static final int
boolean
Compilation was explicitly requested, rather than being a dependency.A help vector for building expressions.static final Field
static Options.OptionInfo
static Method
static Method
static final Method
boolean
True if the compiled result will be immediately loaded.static boolean
static final Type[]
static ClassType
protected Language
Current lexical scope - map name to Declaration.static Options.OptionInfo
static Options.OptionInfo
protected SourceMessages
The current method.static final int
static final int
static final int
static final int
Generated class that extends ModuleBody.static int
Default for whether a module is static.boolean
True if the form is too complex to evaluate,and we must compile it.static Field
static final ArrayType
static Options
static Field
Stack of quads of (ModuleInfo, ScopeExp, position, formSize).static final int
State code when initial tree-walking (PushApply) are done.static Field
static final int
We have determined the module name and class, but not finished parsing.static final int
State code for initial pre-parse looking for module name.static final int
State code for lexical bindings having been resolved.static ClassType
static ClassType
static ClassType
static ClassType
static final Type[]
static final Type[]
static final Field
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static final ClassType
static ClassType
static ClassType
static ClassType
static final ClassType
static ClassType
static final ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType[]
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static ClassType
static final Field
static final int
State code when various inlining and optimization passes are done.static Options.OptionInfo
static Options.OptionInfo
static Options.OptionInfo
static Options.OptionInfo
static Options.OptionInfo
static Options.OptionInfo
static Options.OptionInfo
static Options.OptionInfo
static boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addMainClass
(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.void
void
compileConstant
(Object value) Emit code to "evaluate" a compile-time constant.void
compileConstant
(Object value, Target target) void
compileToArchive
(ModuleExp mexp, String fname) int
The same as getModule, until we allow nested modules.void
Generate code to test if an object is considered true.void
emitPushBoolean
(boolean value) Push language-specific boxed true or false value.void
error
(char severity, Declaration decl, String msg1, String msg2) void
void
error
(char severity, String message, SourceLocator location) void
error
(char severity, String message, String code, SourceLocator decl) static Compilation
findForImmediateLiterals
(int key) findNamedClass
(String name) Search this Compilation for a ClassType with a given name.void
freeLocalField
(Field field) generateCheckMethod
(LambdaExp lexp, LambdaExp parent) void
generateCheckMethods
(LambdaExp parent) generateClassName
(String hint) Generate an unused class name.final void
generateConstructor
(ClassType clas, LambdaExp lexp) final void
generateConstructor
(LambdaExp lexp) boolean
boolean
True if we should generate an Applet.boolean
True if we should generate a Servlet.final boolean
getBooleanOption
(String key) Get a named boolean option.final boolean
getBooleanOption
(String key, boolean defaultValue) Get a named boolean option.final CodeAttr
getCode()
final int
Return current column number.static final Method
getConstructor
(ClassType clas, LambdaExp lexp) final Method
getConstructor
(LambdaExp lexp) static Compilation
final int
Column (one-origin) of end of range; unknown/unspecified is -1.final int
Line number (one-origin) of end of range; unknown/unspecified is -1.final String
Normally same as getSystemId.Generate a method to find a named Class without initializing it.final int
Return current line number.getMinfo()
final ModuleExp
final ClassType
gnu.kawa.io.Path
Get source filename as an absolute Path, or null.final int
Column (one-origin) of start of range; unknown/unspecified is -1.final int
Line number (one-origin) of start of range; unknown/unspecified is -1.int
getState()
Returns a code indicating how far along we are in the parsing/compilation process.boolean
inlineOk
(Expression proc) boolean
boolean
boolean
boolean
boolean
A simple apply function maps actual arguments to formals directly.boolean
True if position is unlikely to change.boolean
isStatic()
letDone
(Expression body) void
letEnter()
void
letStart()
void
letVariable
(Declaration decl, Expression init) letVariable
(Object name, Type type, Expression init) final void
Generate code to push the current CallContext on the JVM stack.void
loadClassRef
(ObjectType clas) Generate code to load a named Class without initializing it.void
loopBody
(Expression body) Deprecated.void
loopCond
(Expression cond) Deprecated.loopDone
(Expression body) Finish building a loop and return resulting expression.void
Done 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 ApplyExp
makeCoercion
(Expression value, Type type) Convenience method to make an Expression that coerces a value.static ApplyExp
makeCoercion
(Expression value, Expression type) Convenience method to make an Expression that coerces a value.makeQuoteExp
(Object value) boolean
static String
Map a URI to a package/class name.static int
void
Note that we have seen a construct that must be compiled, not evaluated.void
outputClass
(String directory) This may not make sense, except for Lisp-like languages.final void
pop()
void
void
process
(int wantedState) Parse/visit/compile this module as needed and requested.void
push
(Declaration decl) void
pushNewModule
(Lexer lexer) void
pushPendingImport
(ModuleInfo info, ScopeExp defs, Translator.FormStack forms, require.DeclSetMapper mapper) final void
static int
static void
restoreCurrent
(Compilation saved) void
setColumn
(int column) static void
setCurrent
(Compilation comp) void
setCurrentScope
(ScopeExp scope) SetcurrentScope()
.void
Generate and set unique module name suitable for a call to eval.void
void
Generate and set unique module name suitable for an interactive session.void
setLine
(int line) final void
setLine
(Expression position) void
void
final void
setLocation
(SourceLocator position) void
setMessages
(SourceMessages messages) void
void
setModuleName
(String name) Set module name - which sets name of generated class.void
setPedantic
(boolean value) void
setPushCurrentScope
(ScopeExp scope) static Compilation
setSaveCurrent
(Compilation comp) void
setSharedModuleDefs
(boolean shared) void
setState
(int state) static void
setupLiterals
(int key) Call-back from compiled code to initialize literals in immediate mode.boolean
syntaxError
(String message) Handle syntax errors (at rewrite time).toString()
void
Called for classes referenced in bytecode.boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
-
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 thenesting
object. -
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:SourceLocator
Return current line number. Normally the same asgetStartLine()
. The "first" line is line 1; unknown is -1.- Specified by:
getLineNumber
in interfaceLocator
- Specified by:
getLineNumber
in interfaceSourceLocator
- Specified by:
getLineNumber
in interfaceSourceLocator
-
getColumnNumber
public final int getColumnNumber()Description copied from interface:SourceLocator
Return current column number. Normally the same asgetStartColumn()
. The "first" column is column 1; unknown is -1.- Specified by:
getColumnNumber
in interfaceLocator
- Specified by:
getColumnNumber
in interfaceSourceLocator
- Specified by:
getColumnNumber
in interfaceSourceLocator
-
getStartLine
public final int getStartLine()Description copied from interface:SourceLocator
Line number (one-origin) of start of range; unknown/unspecified is -1.- Specified by:
getStartLine
in interfaceSourceLocator
-
getStartColumn
public final int getStartColumn()Description copied from interface:SourceLocator
Column (one-origin) of start of range; unknown/unspecified is -1.- Specified by:
getStartColumn
in interfaceSourceLocator
-
getEndLine
public final int getEndLine()Description copied from interface:SourceLocator
Line number (one-origin) of end of range; unknown/unspecified is -1.- Specified by:
getEndLine
in interfaceSourceLocator
-
getEndColumn
public final int getEndColumn()Description copied from interface:SourceLocator
Column (one-origin) of end of range; unknown/unspecified is -1.- Specified by:
getEndColumn
in interfaceSourceLocator
-
getFileName
Description copied from interface:SourceLocator
Normally same as getSystemId.- Specified by:
getFileName
in interfaceSourceLocator
-
getPublicId
- Specified by:
getPublicId
in interfaceLocator
- Specified by:
getPublicId
in interfaceSourceLocator
- Specified by:
getPublicId
in interfaceSourceLocator
-
getSystemId
- Specified by:
getSystemId
in interfaceLocator
- Specified by:
getSystemId
in interfaceSourceLocator
- Specified by:
getSystemId
in interfaceSourceLocator
-
isStableSourceLocation
public boolean isStableSourceLocation()Description copied from interface:SourceLocator
True if position is unlikely to change. True for an expression but not an input file.- Specified by:
isStableSourceLocation
in 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
-