Package gnu.expr
Class Compilation
- java.lang.Object
-
- gnu.expr.Compilation
-
- All Implemented Interfaces:
SourceLocator,SourceLocator,Locator
- Direct Known Subclasses:
Translator
public class Compilation extends Object implements SourceLocator
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
Fields Modifier and Type Field Description static Type[]apply0argsstatic Methodapply0methodstatic Type[]apply1argsstatic Methodapply1methodstatic Type[]apply2argsstatic Methodapply2methodstatic Methodapply3methodstatic Methodapply4methodstatic MethodapplyCpsMethodstatic Method[]applymethodsstatic Type[]applyNargsstatic MethodapplyNmethodstatic FieldargsCallContextFieldstatic intBODY_PARSEDState code indicating the entire module has been parsed.static intCALL_WITH_CONSUMERFunction results are written to the current CallContext's Consumer.static intCALL_WITH_CONTINUATIONSSupport for full continuations.static intCALL_WITH_RETURNPlain calling convention, using regular Java parameters and returns.static intCALL_WITH_TAILCALLSLike CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls.static intCALL_WITH_UNSPECIFIEDstatic intCLASS_WRITTENState code indicating that bytecode has been written to its target.StringclassPrefixIf non-null: a prefix for generateClassName to prepend to names.static StringclassPrefixDefaultstatic intCOMPILE_SETUPState code that various compile-only data has been determined.static intCOMPILEDState code indicating the bytecode has been generated.ClassTypecurClassLambdaExpcurLambdaprotected ScopeExpcurrent_scopeOptionscurrentOptionsstatic booleandebugPrintANFstatic booleandebugPrintExprIf true, print out expressions after parsing and before optimizations.static booleandebugPrintFinalExprIf true, print out final expressions after optimizations etc.static intdefaultCallConventionThe default calling convention.static intdefaultClassFileVersionstatic booleanemitSourceDebugExtAttrstatic booleanenableANFstatic intERROR_SEENbooleanexplicitCompilation was explicitly requested, rather than being a dependency.Stack<Expression>exprStackA help vector for building expressions.static FieldfalseConstantstatic Options.OptionInfofullTailCallsVariablestatic MethodgetCallContextInstanceMethodstatic MethodgetCurrentEnvironmentMethodstatic MethodgetNextArgMethodbooleanimmediateTrue if the compiled result will be immediately loaded.static booleaninlineOkstatic Type[]int1Argsstatic ClassTypejavaStringTypeprotected LanguagelanguageLexerlexerNameLookuplexicalCurrent lexical scope - map name to Declaration.ClassTypemainClassModuleExpmainLambdastatic Options.OptionInfomainMethodVariablestatic Options.OptionInfomaxErrorsprotected SourceMessagesmessagesMethodmethodThe current method.static intMODULE_NONSTATICstatic intMODULE_STATICstatic intMODULE_STATIC_DEFAULTstatic intMODULE_STATIC_RUNClassTypemoduleClassGenerated class that extends ModuleBody.static intmoduleStaticDefault for whether a module is static.booleanmustCompileTrue if the form is too complex to evaluate,and we must compile it.static FieldnoArgsFieldstatic ArrayTypeobjArrayTypestatic Optionsoptionsstatic FieldpcCallContextFieldStack<Object>pendingImportsStack of quads of (ModuleInfo, ScopeExp, position, formSize).static intPRE_WALKEDState code when initial tree-walking (PushApply) are done.static FieldprocCallContextFieldstatic intPROLOG_PARSEDWe have determined the module name and class, but not finished parsing.static intPROLOG_PARSINGState code for initial pre-parse looking for module name.static intRESOLVEDState code for lexical bindings having been resolved.static ClassTypescmBooleanTypestatic ClassTypescmKeywordTypestatic ClassTypescmListTypestatic ClassTypescmSequenceTypestatic Type[]string1ArgMap<String,ModuleInfo>subModuleMapstatic Type[]sym1ArgVariablethisDeclstatic FieldtrueConstantstatic ClassTypetypeAppletstatic ClassTypetypeCallContextstatic ClassTypetypeCharSequencestatic ClassTypetypeClassstatic ClassTypetypeClassTypestatic ClassTypetypeCompiledProcstatic ClassTypetypeConsumerstatic ClassTypetypeEnvironmentstatic ClassTypetypeFieldLocationstatic ClassTypetypeLanguagestatic ClassTypetypeListstatic ClassTypetypeLocationstatic ClassTypetypeLocationProcstatic ClassTypetypeMethodProcstatic ClassTypetypeModuleBodystatic ClassTypetypeObjectstatic ClassTypetypeObjectTypestatic ClassTypetypePairstatic ClassTypetypeProcedurestatic ClassTypetypeProcedure0static ClassTypetypeProcedure1static ClassTypetypeProcedure2static ClassTypetypeProcedure3static ClassTypetypeProcedure4static ClassType[]typeProcedureArraystatic ClassTypetypeProcedureNstatic ClassTypetypeRunnablestatic ClassTypetypeRunnableModulestatic ClassTypetypeServletstatic ClassTypetypeStaticFieldLocationstatic ClassTypetypeStringstatic ClassTypetypeSymbolstatic ClassTypetypeTypestatic ClassTypetypeValuesstatic FieldvoidConsumerInstanceFieldstatic intWALKEDState code when various inlining and optimization passes are done.static Options.OptionInfowarnAsErrorstatic Options.OptionInfowarnInvokeUnknownMethodstatic Options.OptionInfowarnUndefinedVariablestatic Options.OptionInfowarnUninitializedstatic Options.OptionInfowarnUnknownMemberstatic Options.OptionInfowarnUnreachablestatic Options.OptionInfowarnUnusedstatic Options.OptionInfowarnVoidUsedstatic booleanwriteImplicitClasses
-
Constructor Summary
Constructors Constructor Description Compilation(Language language, SourceMessages messages, NameLookup lexical)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddClass(ClassType new_class)voidaddMainClass(ModuleExp module)FieldallocLocalField(Type type, String name)ExpressionapplyFunction(Expression func)A language-dependent "apply" function for generic application.TypeasBooleanValue(ConditionalTarget target, Type stackType)Hook for language-specific handling in ConditionalTarget.voidcleanupAfterCompilation()voidcompileConstant(Object value)Emit code to "evaluate" a compile-time constant.voidcompileConstant(Object value, Target target)voidcompileToArchive(ModuleExp mexp, String fname)intcurrentCallConvention()LambdaExpcurrentLambda()ModuleExpcurrentModule()The same as getModule, until we allow nested modules.ScopeExpcurrentScope()voidemitCoerceToBoolean()Generate 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)voiderror(char severity, String message)voiderror(char severity, String message, SourceLocator location)voiderror(char severity, String message, String code, SourceLocator decl)static CompilationfindForImmediateLiterals(int key)ClassTypefindNamedClass(String name)Search this Compilation for a ClassType with a given name.voidfreeLocalField(Field field)MethodgenerateCheckMethod(LambdaExp lexp, LambdaExp parent)voidgenerateCheckMethods(LambdaExp parent)StringgenerateClassName(String hint)Generate an unused class name.voidgenerateConstructor(ClassType clas, LambdaExp lexp)voidgenerateConstructor(LambdaExp lexp)booleangenerateMainMethod()booleangeneratingApplet()True if we should generate an Applet.booleangeneratingServlet()True if we should generate a Servlet.booleangetBooleanOption(String key)Get a named boolean option.booleangetBooleanOption(String key, boolean defaultValue)Get a named boolean option.CodeAttrgetCode()intgetColumnNumber()Return current column number.static MethodgetConstructor(ClassType clas, LambdaExp lexp)MethodgetConstructor(LambdaExp lexp)static CompilationgetCurrent()intgetEndColumn()Column (one-origin) of end of range; unknown/unspecified is -1.intgetEndLine()Line number (one-origin) of end of range; unknown/unspecified is -1.StringgetFileName()Normally same as getSystemId.MethodgetForNameHelper()Generate a method to find a named Class without initializing it.EnvironmentgetGlobalEnvironment()LanguagegetLanguage()intgetLineNumber()Return current line number.SourceMessagesgetMessages()ModuleInfogetMinfo()ModuleExpgetModule()ClassTypegetModuleType()StringgetPublicId()gnu.kawa.io.PathgetSourceAbsPath()Get source filename as an absolute Path, or null.intgetStartColumn()Column (one-origin) of start of range; unknown/unspecified is -1.intgetStartLine()Line 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.StringgetSystemId()booleaninlineOk(Expression proc)booleaninlineOk(Procedure proc)booleanisApplyFunction(Expression exp)booleanisInteractive()booleanisPedantic()booleanisSimpleApplyFunction(Expression exp)A simple apply function maps actual arguments to formals directly.booleanisStableSourceLocation()True if position is unlikely to change.booleanisStatic()LetExpletDone(Expression body)voidletEnter()voidletStart()voidletVariable(Declaration decl, Expression init)DeclarationletVariable(Object name, Type type, Expression init)voidloadCallContext()Generate code to push the current CallContext on the JVM stack.voidloadClassRef(ObjectType clas)Generate code to load a named Class without initializing it.Declarationlookup(Object name, int namespace)voidloopBody(Expression body)Deprecated.voidloopCond(Expression cond)Deprecated.ExpressionloopDone(Expression body)Finish building a loop and return resulting expression.voidloopEnter()Done handling loop variables, and pushes them into the lexical scope.ExpressionloopRepeat(LambdaExp loop, Expression... exps)Recurse to next iteration of specified loop.ExpressionloopRepeatDone(Expression... exps)Combine loopRepeat and loopDone.LambdaExploopStart()Start a new loop.DeclarationloopVariable(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.QuoteExpmakeQuoteExp(Object value)booleanmakeRunnable()static StringmangleURI(String name)Map a URI to a package/class name.static intmaxErrors()voidmustCompileHere()Note that we have seen a construct that must be compiled, not evaluated.voidoutputClass(String directory)Expressionparse(Object input)This may not make sense, except for Lisp-like languages.voidpop()voidpop(ScopeExp scope)voidprocess(int wantedState)Parse/visit/compile this module as needed and requested.voidpush(Declaration decl)voidpush(ScopeExp scope)ModuleExppushNewModule(Lexer lexer)voidpushPendingImport(ModuleInfo info, ScopeExp defs, Translator.FormStack forms, require.DeclSetMapper mapper)voidpushScope(ScopeExp scope)static intregisterForImmediateLiterals(Compilation comp)Objectresolve(Object name, boolean function)static voidrestoreCurrent(Compilation saved)voidsetColumn(int column)static voidsetCurrent(Compilation comp)voidsetCurrentScope(ScopeExp scope)SetcurrentScope().voidsetEvalName()Generate and set unique module name suitable for a call to eval.voidsetFile(String filename)voidsetInteractiveName()Generate and set unique module name suitable for an interactive session.voidsetLine(int line)voidsetLine(Expression position)voidsetLine(Object location)voidsetLine(String filename, int line, int column)voidsetLocation(SourceLocator position)voidsetMessages(SourceMessages messages)voidsetModule(ModuleExp mexp)voidsetModuleName(String name)Set module name - which sets name of generated class.voidsetPedantic(boolean value)voidsetPopCurrentScope(ScopeExp old)ScopeExpsetPushCurrentScope(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.booleansharedModuleDefs()ErrorExpsyntaxError(String message)Handle syntax errors (at rewrite time).StringtoString()voidusedClass(Type type)Called for classes referenced in bytecode.booleanusingCallContext()booleanusingCPStyle()booleanusingTailCalls()booleanwarnAsError()booleanwarnInvokeUnknownMethod()booleanwarnUndefinedVariable()booleanwarnUninitialized()booleanwarnUnknownMember()booleanwarnUnreachable()booleanwarnUnused()booleanwarnVoidUsed()
-
-
-
Field Detail
-
mustCompile
public boolean mustCompile
True 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
public ClassType curClass
-
mainClass
public ClassType mainClass
-
moduleClass
public ClassType moduleClass
Generated class that extends ModuleBody. Normally same as mainClass.
-
curLambda
public LambdaExp curLambda
-
mainLambda
public ModuleExp mainLambda
-
thisDecl
public Variable thisDecl
-
PROLOG_PARSING
public static final int PROLOG_PARSING
State code for initial pre-parse looking for module name.- See Also:
- Constant Field Values
-
PROLOG_PARSED
public static final int PROLOG_PARSED
We have determined the module name and class, but not finished parsing.- See Also:
- Constant Field Values
-
BODY_PARSED
public static final int BODY_PARSED
State code indicating the entire module has been parsed.- See Also:
- Constant Field Values
-
RESOLVED
public static final int RESOLVED
State code for lexical bindings having been resolved.- See Also:
- Constant Field Values
-
PRE_WALKED
public static final int PRE_WALKED
State code when initial tree-walking (PushApply) are done.- See Also:
- Constant Field Values
-
WALKED
public static final int WALKED
State code when various inlining and optimization passes are done.- See Also:
- Constant Field Values
-
COMPILE_SETUP
public static final int COMPILE_SETUP
State code that various compile-only data has been determined.- See Also:
- Constant Field Values
-
COMPILED
public static final int COMPILED
State code indicating the bytecode has been generated.- See Also:
- Constant Field Values
-
CLASS_WRITTEN
public static final int CLASS_WRITTEN
State code indicating that bytecode has been written to its target.- See Also:
- Constant Field Values
-
ERROR_SEEN
public static final int ERROR_SEEN
- See Also:
- Constant Field Values
-
lexer
public Lexer lexer
-
pendingImports
public Stack<Object> pendingImports
Stack of quads of (ModuleInfo, ScopeExp, position, formSize).
-
subModuleMap
public Map<String,ModuleInfo> subModuleMap
-
writeImplicitClasses
public static boolean writeImplicitClasses
-
debugPrintExpr
public static boolean debugPrintExpr
If true, print out expressions after parsing and before optimizations.
-
debugPrintFinalExpr
public static boolean debugPrintFinalExpr
If true, print out final expressions after optimizations etc.
-
debugPrintANF
public static boolean debugPrintANF
-
enableANF
public static boolean enableANF
-
options
public static Options options
-
fullTailCallsVariable
public static Options.OptionInfo fullTailCallsVariable
-
mainMethodVariable
public static Options.OptionInfo mainMethodVariable
-
warnUnreachable
public static Options.OptionInfo warnUnreachable
-
warnVoidUsed
public static Options.OptionInfo warnVoidUsed
-
warnUninitialized
public static Options.OptionInfo warnUninitialized
-
warnUndefinedVariable
public static Options.OptionInfo warnUndefinedVariable
-
warnUnknownMember
public static Options.OptionInfo warnUnknownMember
-
warnInvokeUnknownMethod
public static Options.OptionInfo warnInvokeUnknownMethod
-
warnUnused
public static Options.OptionInfo warnUnused
-
warnAsError
public static Options.OptionInfo warnAsError
-
maxErrors
public static Options.OptionInfo maxErrors
-
currentOptions
public Options currentOptions
-
defaultClassFileVersion
public static int defaultClassFileVersion
-
defaultCallConvention
public static int defaultCallConvention
The default calling convention. One of the following CALL_WITH_xxx values.
-
CALL_WITH_UNSPECIFIED
public static final int CALL_WITH_UNSPECIFIED
- See Also:
- Constant Field Values
-
CALL_WITH_RETURN
public static final int CALL_WITH_RETURN
Plain calling convention, using regular Java parameters and returns.- See Also:
- Constant Field Values
-
CALL_WITH_CONSUMER
public static final int CALL_WITH_CONSUMER
Function results are written to the current CallContext's Consumer.- See Also:
- Constant Field Values
-
CALL_WITH_TAILCALLS
public static final int CALL_WITH_TAILCALLS
Like CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls.- See Also:
- Constant Field Values
-
CALL_WITH_CONTINUATIONS
public static final int CALL_WITH_CONTINUATIONS
Support for full continuations. Not implemented.- See Also:
- Constant Field Values
-
MODULE_NONSTATIC
public static final int MODULE_NONSTATIC
- See Also:
- Constant Field Values
-
MODULE_STATIC_DEFAULT
public static final int MODULE_STATIC_DEFAULT
- See Also:
- Constant Field Values
-
MODULE_STATIC
public static final int MODULE_STATIC
- See Also:
- Constant Field Values
-
MODULE_STATIC_RUN
public static final int MODULE_STATIC_RUN
- See Also:
- Constant Field Values
-
moduleStatic
public static int moduleStatic
Default 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 immediate
True if the compiled result will be immediately loaded.
-
explicit
public boolean explicit
Compilation was explicitly requested, rather than being a dependency.
-
method
public Method method
The current method.
-
typeObject
public static ClassType typeObject
-
scmBooleanType
public static ClassType scmBooleanType
-
typeString
public static ClassType typeString
-
typeCharSequence
public static ClassType typeCharSequence
-
javaStringType
public static ClassType javaStringType
-
scmKeywordType
public static ClassType scmKeywordType
-
scmSequenceType
public static ClassType scmSequenceType
-
typeList
public static final ClassType typeList
-
scmListType
public static ClassType scmListType
-
typePair
public static ClassType typePair
-
objArrayType
public static final ArrayType objArrayType
-
typeRunnable
public static ClassType typeRunnable
-
typeRunnableModule
public static ClassType typeRunnableModule
-
typeType
public static ClassType typeType
-
typeObjectType
public static ClassType typeObjectType
-
typeClass
public static ClassType typeClass
-
typeClassType
public static ClassType typeClassType
-
typeProcedure
public static ClassType typeProcedure
-
typeLanguage
public static ClassType typeLanguage
-
typeEnvironment
public static ClassType typeEnvironment
-
typeLocation
public static ClassType typeLocation
-
typeLocationProc
public static final ClassType typeLocationProc
-
typeFieldLocation
public static ClassType typeFieldLocation
-
typeStaticFieldLocation
public static ClassType typeStaticFieldLocation
-
typeSymbol
public static ClassType typeSymbol
-
trueConstant
public static final Field trueConstant
-
falseConstant
public static final Field falseConstant
-
voidConsumerInstanceField
public static final Field voidConsumerInstanceField
-
int1Args
public static final Type[] int1Args
-
string1Arg
public static final Type[] string1Arg
-
sym1Arg
public static final Type[] sym1Arg
-
getCurrentEnvironmentMethod
public static Method getCurrentEnvironmentMethod
-
apply0args
public static Type[] apply0args
-
apply1args
public static Type[] apply1args
-
apply2args
public static Type[] apply2args
-
applyNargs
public static Type[] applyNargs
-
apply0method
public static Method apply0method
-
apply1method
public static Method apply1method
-
apply2method
public static Method apply2method
-
apply3method
public static Method apply3method
-
apply4method
public static Method apply4method
-
applyNmethod
public static Method applyNmethod
-
applymethods
public static Method[] applymethods
-
typeProcedure0
public static ClassType typeProcedure0
-
typeProcedure1
public static ClassType typeProcedure1
-
typeProcedure2
public static ClassType typeProcedure2
-
typeProcedure3
public static ClassType typeProcedure3
-
typeProcedure4
public static ClassType typeProcedure4
-
typeProcedureN
public static ClassType typeProcedureN
-
typeModuleBody
public static ClassType typeModuleBody
-
typeApplet
public static ClassType typeApplet
-
typeServlet
public static ClassType typeServlet
-
typeCallContext
public static ClassType typeCallContext
-
typeConsumer
public static final ClassType typeConsumer
-
getCallContextInstanceMethod
public static Method getCallContextInstanceMethod
-
typeValues
public static ClassType typeValues
-
noArgsField
public static Field noArgsField
-
pcCallContextField
public static Field pcCallContextField
-
typeMethodProc
public static ClassType typeMethodProc
-
typeCompiledProc
public static ClassType typeCompiledProc
-
argsCallContextField
public static Field argsCallContextField
-
procCallContextField
public static Field procCallContextField
-
applyCpsMethod
public static Method applyCpsMethod
-
typeProcedureArray
public static ClassType[] typeProcedureArray
-
getNextArgMethod
public static final Method getNextArgMethod
-
inlineOk
public static boolean inlineOk
-
classPrefixDefault
public static String classPrefixDefault
-
classPrefix
public String classPrefix
If non-null: a prefix for generateClassName to prepend to names.
-
emitSourceDebugExtAttr
public static boolean emitSourceDebugExtAttr
-
language
protected Language language
-
exprStack
public Stack<Expression> exprStack
A help vector for building expressions.
-
lexical
public NameLookup lexical
Current lexical scope - map name to Declaration.
-
current_scope
protected ScopeExp current_scope
-
messages
protected SourceMessages messages
-
-
Constructor Detail
-
Compilation
public Compilation(Language language, SourceMessages messages, NameLookup lexical)
-
-
Method Detail
-
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
public final boolean getBooleanOption(String key, boolean defaultValue)
Get a named boolean option.
-
getBooleanOption
public final boolean getBooleanOption(String key)
Get a named boolean option.
-
currentCallConvention
public int currentCallConvention()
-
usingCPStyle
public boolean usingCPStyle()
-
usingTailCalls
public boolean usingTailCalls()
-
usingCallContext
public boolean usingCallContext()
-
getCode
public final CodeAttr getCode()
-
generatingApplet
public boolean generatingApplet()
True if we should generate an Applet.
-
generatingServlet
public boolean generatingServlet()
True if we should generate a Servlet.
-
sharedModuleDefs
public boolean sharedModuleDefs()
-
setSharedModuleDefs
public void setSharedModuleDefs(boolean shared)
-
getModuleType
public final ClassType getModuleType()
-
compileConstant
public void compileConstant(Object value)
Emit code to "evaluate" a compile-time constant. This is the normal external interface.- Parameters:
value- the value to be compiled
-
inlineOk
public boolean inlineOk(Expression proc)
-
inlineOk
public boolean inlineOk(Procedure proc)
-
isApplyFunction
public boolean isApplyFunction(Expression exp)
-
isSimpleApplyFunction
public boolean isSimpleApplyFunction(Expression exp)
A simple apply function maps actual arguments to formals directly. E.g. no distribution of multiple values.
-
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
public Type asBooleanValue(ConditionalTarget target, Type stackType)
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
public ClassType findNamedClass(String name)
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
public static String mangleURI(String name)
Map a URI to a package/class name. Similar to the JAXB mangling, and that in the Java language spec.
-
generateClassName
public String generateClassName(String hint)
Generate an unused class name.- Parameters:
hint- the requested name (or prefix)- Returns:
- a unique class name.
-
outputClass
public void outputClass(String directory) throws IOException
- Throws:
IOException
-
cleanupAfterCompilation
public void cleanupAfterCompilation()
-
compileToArchive
public void compileToArchive(ModuleExp mexp, String fname) throws IOException
- Throws:
IOException
-
addClass
public void addClass(ClassType new_class)
-
makeRunnable
public boolean makeRunnable()
-
addMainClass
public void addMainClass(ModuleExp module)
-
generateConstructor
public final void generateConstructor(LambdaExp lexp)
-
generateCheckMethods
public void generateCheckMethods(LambdaExp parent)
-
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().
-
loadCallContext
public final void loadCallContext()
Generate code to push the current CallContext on the JVM stack.
-
freeLocalField
public void freeLocalField(Field field)
-
parse
public Expression parse(Object input)
This may not make sense, except for Lisp-like languages. For those, 'input' an s-expression from the reader.
-
getLanguage
public Language getLanguage()
-
currentLambda
public LambdaExp currentLambda()
-
getModule
public final ModuleExp getModule()
-
setModule
public void setModule(ModuleExp mexp)
-
isStatic
public boolean isStatic()
-
isInteractive
public boolean isInteractive()
-
currentModule
public ModuleExp 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
public ScopeExp currentScope()
-
setCurrentScope
public void setCurrentScope(ScopeExp scope)
SetcurrentScope(). Also update thenestingobject.
-
setPopCurrentScope
public void setPopCurrentScope(ScopeExp old)
-
push
public void push(ScopeExp scope)
-
pushScope
public final void pushScope(ScopeExp scope)
-
pop
public void pop(ScopeExp scope)
-
pop
public final void pop()
-
push
public void push(Declaration decl)
-
lookup
public Declaration lookup(Object name, int namespace)
-
usedClass
public void usedClass(Type type)
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
public void setModuleName(String name)
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
public SourceMessages getMessages()
-
setMessages
public void setMessages(SourceMessages messages)
-
error
public void error(char severity, String message, SourceLocator location)
-
error
public void error(char severity, String message)
-
error
public void error(char severity, Declaration decl, String msg1, String msg2)
-
error
public void error(char severity, String message, String code, SourceLocator decl)
-
syntaxError
public ErrorExp syntaxError(String message)
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
public final String getFileName()
Description copied from interface:SourceLocatorNormally same as getSystemId.- Specified by:
getFileNamein interfaceSourceLocator
-
getPublicId
public String getPublicId()
- Specified by:
getPublicIdin interfaceLocator- Specified by:
getPublicIdin interfaceSourceLocator- Specified by:
getPublicIdin interfaceSourceLocator
-
getSystemId
public String 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
public void setFile(String filename)
-
setLine
public void setLine(int line)
-
setColumn
public void setColumn(int column)
-
setLine
public final void setLine(Expression position)
-
setLine
public void setLine(Object location)
-
setLocation
public final void setLocation(SourceLocator position)
-
setLine
public void setLine(String filename, int line, int column)
-
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
public Declaration letVariable(Object name, Type type, Expression init)
-
letVariable
public void letVariable(Declaration decl, Expression init)
-
letEnter
public void letEnter()
-
letDone
public LetExp letDone(Expression body)
-
loopStart
public LambdaExp loopStart()
Start a new loop. This provides the functionality of Scheme 'named let'.
-
loopVariable
public Declaration loopVariable(Object name, Type type, Expression init)
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 public void loopCond(Expression cond)
Deprecated.
-
loopBody
@Deprecated public void loopBody(Expression body)
Deprecated.
-
loopRepeat
public Expression loopRepeat(LambdaExp loop, Expression... exps)
Recurse to next iteration of specified loop.
-
loopDone
public Expression loopDone(Expression body)
Finish building a loop and return resulting expression.
-
loopRepeatDone
public Expression loopRepeatDone(Expression... exps)
Combine loopRepeat and loopDone. Assume loopCond and loopBody have been called.
-
applyFunction
public Expression applyFunction(Expression func)
A language-dependent "apply" function for generic application.
-
makeCoercion
public static ApplyExp makeCoercion(Expression value, Expression type)
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
public static ApplyExp makeCoercion(Expression value, Type type)
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
public void loadClassRef(ObjectType clas)
Generate code to load a named Class without initializing it.
-
getForNameHelper
public Method 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
public Environment getGlobalEnvironment()
-
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
public static int registerForImmediateLiterals(Compilation comp)
-
findForImmediateLiterals
public static Compilation findForImmediateLiterals(int key)
-
getCurrent
public static Compilation getCurrent()
-
setCurrent
public static void setCurrent(Compilation comp)
-
setSaveCurrent
public static Compilation setSaveCurrent(Compilation comp)
-
restoreCurrent
public static void restoreCurrent(Compilation saved)
-
getMinfo
public ModuleInfo getMinfo()
-
-