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[]
apply0args
static Method
apply0method
static Type[]
apply1args
static Method
apply1method
static Type[]
apply2args
static Method
apply2method
static Method
apply3method
static Method
apply4method
static Method
applyCpsMethod
static Method[]
applymethods
static Type[]
applyNargs
static Method
applyNmethod
static Field
argsCallContextField
static int
BODY_PARSED
State code indicating the entire module has been parsed.static int
CALL_WITH_CONSUMER
Function results are written to the current CallContext's Consumer.static int
CALL_WITH_CONTINUATIONS
Support for full continuations.static int
CALL_WITH_RETURN
Plain calling convention, using regular Java parameters and returns.static int
CALL_WITH_TAILCALLS
Like CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls.static int
CALL_WITH_UNSPECIFIED
static int
CLASS_WRITTEN
State code indicating that bytecode has been written to its target.String
classPrefix
If non-null: a prefix for generateClassName to prepend to names.static String
classPrefixDefault
static int
COMPILE_SETUP
State code that various compile-only data has been determined.static int
COMPILED
State code indicating the bytecode has been generated.ClassType
curClass
LambdaExp
curLambda
protected ScopeExp
current_scope
Options
currentOptions
static boolean
debugPrintANF
static boolean
debugPrintExpr
If true, print out expressions after parsing and before optimizations.static boolean
debugPrintFinalExpr
If true, print out final expressions after optimizations etc.static int
defaultCallConvention
The default calling convention.static int
defaultClassFileVersion
static boolean
emitSourceDebugExtAttr
static boolean
enableANF
static int
ERROR_SEEN
boolean
explicit
Compilation was explicitly requested, rather than being a dependency.Stack<Expression>
exprStack
A help vector for building expressions.static Field
falseConstant
static Options.OptionInfo
fullTailCallsVariable
static Method
getCallContextInstanceMethod
static Method
getCurrentEnvironmentMethod
static Method
getNextArgMethod
boolean
immediate
True if the compiled result will be immediately loaded.static boolean
inlineOk
static Type[]
int1Args
static ClassType
javaStringType
protected Language
language
Lexer
lexer
NameLookup
lexical
Current lexical scope - map name to Declaration.ClassType
mainClass
ModuleExp
mainLambda
static Options.OptionInfo
mainMethodVariable
static Options.OptionInfo
maxErrors
protected SourceMessages
messages
Method
method
The current method.static int
MODULE_NONSTATIC
static int
MODULE_STATIC
static int
MODULE_STATIC_DEFAULT
static int
MODULE_STATIC_RUN
ClassType
moduleClass
Generated class that extends ModuleBody.static int
moduleStatic
Default for whether a module is static.boolean
mustCompile
True if the form is too complex to evaluate,and we must compile it.static Field
noArgsField
static ArrayType
objArrayType
static Options
options
static Field
pcCallContextField
Stack<Object>
pendingImports
Stack of quads of (ModuleInfo, ScopeExp, position, formSize).static int
PRE_WALKED
State code when initial tree-walking (PushApply) are done.static Field
procCallContextField
static int
PROLOG_PARSED
We have determined the module name and class, but not finished parsing.static int
PROLOG_PARSING
State code for initial pre-parse looking for module name.static int
RESOLVED
State code for lexical bindings having been resolved.static ClassType
scmBooleanType
static ClassType
scmKeywordType
static ClassType
scmListType
static ClassType
scmSequenceType
static Type[]
string1Arg
Map<String,ModuleInfo>
subModuleMap
static Type[]
sym1Arg
Variable
thisDecl
static Field
trueConstant
static ClassType
typeApplet
static ClassType
typeCallContext
static ClassType
typeCharSequence
static ClassType
typeClass
static ClassType
typeClassType
static ClassType
typeCompiledProc
static ClassType
typeConsumer
static ClassType
typeEnvironment
static ClassType
typeFieldLocation
static ClassType
typeLanguage
static ClassType
typeList
static ClassType
typeLocation
static ClassType
typeLocationProc
static ClassType
typeMethodProc
static ClassType
typeModuleBody
static ClassType
typeObject
static ClassType
typeObjectType
static ClassType
typePair
static ClassType
typeProcedure
static ClassType
typeProcedure0
static ClassType
typeProcedure1
static ClassType
typeProcedure2
static ClassType
typeProcedure3
static ClassType
typeProcedure4
static ClassType[]
typeProcedureArray
static ClassType
typeProcedureN
static ClassType
typeRunnable
static ClassType
typeRunnableModule
static ClassType
typeServlet
static ClassType
typeStaticFieldLocation
static ClassType
typeString
static ClassType
typeSymbol
static ClassType
typeType
static ClassType
typeValues
static Field
voidConsumerInstanceField
static int
WALKED
State code when various inlining and optimization passes are done.static Options.OptionInfo
warnAsError
static Options.OptionInfo
warnInvokeUnknownMethod
static Options.OptionInfo
warnUndefinedVariable
static Options.OptionInfo
warnUninitialized
static Options.OptionInfo
warnUnknownMember
static Options.OptionInfo
warnUnreachable
static Options.OptionInfo
warnUnused
static Options.OptionInfo
warnVoidUsed
static boolean
writeImplicitClasses
-
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 void
addClass(ClassType new_class)
void
addMainClass(ModuleExp module)
Field
allocLocalField(Type type, String name)
Expression
applyFunction(Expression func)
A language-dependent "apply" function for generic application.Type
asBooleanValue(ConditionalTarget target, Type stackType)
Hook for language-specific handling in ConditionalTarget.void
cleanupAfterCompilation()
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
currentCallConvention()
LambdaExp
currentLambda()
ModuleExp
currentModule()
The same as getModule, until we allow nested modules.ScopeExp
currentScope()
void
emitCoerceToBoolean()
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
error(char severity, String message)
void
error(char severity, String message, SourceLocator location)
void
error(char severity, String message, String code, SourceLocator decl)
static Compilation
findForImmediateLiterals(int key)
ClassType
findNamedClass(String name)
Search this Compilation for a ClassType with a given name.void
freeLocalField(Field field)
Method
generateCheckMethod(LambdaExp lexp, LambdaExp parent)
void
generateCheckMethods(LambdaExp parent)
String
generateClassName(String hint)
Generate an unused class name.void
generateConstructor(ClassType clas, LambdaExp lexp)
void
generateConstructor(LambdaExp lexp)
boolean
generateMainMethod()
boolean
generatingApplet()
True if we should generate an Applet.boolean
generatingServlet()
True if we should generate a Servlet.boolean
getBooleanOption(String key)
Get a named boolean option.boolean
getBooleanOption(String key, boolean defaultValue)
Get a named boolean option.CodeAttr
getCode()
int
getColumnNumber()
Return current column number.static Method
getConstructor(ClassType clas, LambdaExp lexp)
Method
getConstructor(LambdaExp lexp)
static Compilation
getCurrent()
int
getEndColumn()
Column (one-origin) of end of range; unknown/unspecified is -1.int
getEndLine()
Line number (one-origin) of end of range; unknown/unspecified is -1.String
getFileName()
Normally same as getSystemId.Method
getForNameHelper()
Generate a method to find a named Class without initializing it.Environment
getGlobalEnvironment()
Language
getLanguage()
int
getLineNumber()
Return current line number.SourceMessages
getMessages()
ModuleInfo
getMinfo()
ModuleExp
getModule()
ClassType
getModuleType()
String
getPublicId()
gnu.kawa.io.Path
getSourceAbsPath()
Get source filename as an absolute Path, or null.int
getStartColumn()
Column (one-origin) of start of range; unknown/unspecified is -1.int
getStartLine()
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.String
getSystemId()
boolean
inlineOk(Expression proc)
boolean
inlineOk(Procedure proc)
boolean
isApplyFunction(Expression exp)
boolean
isInteractive()
boolean
isPedantic()
boolean
isSimpleApplyFunction(Expression exp)
A simple apply function maps actual arguments to formals directly.boolean
isStableSourceLocation()
True if position is unlikely to change.boolean
isStatic()
LetExp
letDone(Expression body)
void
letEnter()
void
letStart()
void
letVariable(Declaration decl, Expression init)
Declaration
letVariable(Object name, Type type, Expression init)
void
loadCallContext()
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.Declaration
lookup(Object name, int namespace)
void
loopBody(Expression body)
Deprecated.void
loopCond(Expression cond)
Deprecated.Expression
loopDone(Expression body)
Finish building a loop and return resulting expression.void
loopEnter()
Done handling loop variables, and pushes them into the lexical scope.Expression
loopRepeat(LambdaExp loop, Expression... exps)
Recurse to next iteration of specified loop.Expression
loopRepeatDone(Expression... exps)
Combine loopRepeat and loopDone.LambdaExp
loopStart()
Start a new loop.Declaration
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.QuoteExp
makeQuoteExp(Object value)
boolean
makeRunnable()
static String
mangleURI(String name)
Map a URI to a package/class name.static int
maxErrors()
void
mustCompileHere()
Note that we have seen a construct that must be compiled, not evaluated.void
outputClass(String directory)
Expression
parse(Object input)
This may not make sense, except for Lisp-like languages.void
pop()
void
pop(ScopeExp scope)
void
process(int wantedState)
Parse/visit/compile this module as needed and requested.void
push(Declaration decl)
void
push(ScopeExp scope)
ModuleExp
pushNewModule(Lexer lexer)
void
pushPendingImport(ModuleInfo info, ScopeExp defs, Translator.FormStack forms, require.DeclSetMapper mapper)
void
pushScope(ScopeExp scope)
static int
registerForImmediateLiterals(Compilation comp)
Object
resolve(Object name, boolean function)
static void
restoreCurrent(Compilation saved)
void
setColumn(int column)
static void
setCurrent(Compilation comp)
void
setCurrentScope(ScopeExp scope)
SetcurrentScope()
.void
setEvalName()
Generate and set unique module name suitable for a call to eval.void
setFile(String filename)
void
setInteractiveName()
Generate and set unique module name suitable for an interactive session.void
setLine(int line)
void
setLine(Expression position)
void
setLine(Object location)
void
setLine(String filename, int line, int column)
void
setLocation(SourceLocator position)
void
setMessages(SourceMessages messages)
void
setModule(ModuleExp mexp)
void
setModuleName(String name)
Set module name - which sets name of generated class.void
setPedantic(boolean value)
void
setPopCurrentScope(ScopeExp old)
ScopeExp
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
sharedModuleDefs()
ErrorExp
syntaxError(String message)
Handle syntax errors (at rewrite time).String
toString()
void
usedClass(Type type)
Called for classes referenced in bytecode.boolean
usingCallContext()
boolean
usingCPStyle()
boolean
usingTailCalls()
boolean
warnAsError()
boolean
warnInvokeUnknownMethod()
boolean
warnUndefinedVariable()
boolean
warnUninitialized()
boolean
warnUnknownMember()
boolean
warnUnreachable()
boolean
warnUnused()
boolean
warnVoidUsed()
-
-
-
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 thenesting
object.
-
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: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
public final String getFileName()
Description copied from interface:SourceLocator
Normally same as getSystemId.- Specified by:
getFileName
in interfaceSourceLocator
-
getPublicId
public String getPublicId()
- Specified by:
getPublicId
in interfaceLocator
- Specified by:
getPublicId
in interfaceSourceLocator
- Specified by:
getPublicId
in interfaceSourceLocator
-
getSystemId
public String 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
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()
-
-