State for a single expression or module.
For each top-level thing (expression or file) we compile or evaluate
we create a new Compilation.
BODY_PARSED
public static final int BODY_PARSED
State code indicating the entire module has been parsed.
CALL_WITH_CONSUMER
public static final int CALL_WITH_CONSUMER
Function results are written to the current CallContext's Consumer.
CALL_WITH_CONTINUATIONS
public static final int CALL_WITH_CONTINUATIONS
Support for full continuations. Not implemented.
CALL_WITH_RETURN
public static final int CALL_WITH_RETURN
Plain calling convention, using regular Java parameters and returns.
CALL_WITH_TAILCALLS
public static final int CALL_WITH_TAILCALLS
Like CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls.
CALL_WITH_UNSPECIFIED
public static final int CALL_WITH_UNSPECIFIED
CLASS_WRITTEN
public static final int CLASS_WRITTEN
State code indicating that bytecode has been written to its target.
COMPILED
public static final int COMPILED
State code indicating the bytecode has been generated.
COMPILE_SETUP
public static final int COMPILE_SETUP
State code that various compile-only data has been determined.
ERROR_SEEN
public static final int ERROR_SEEN
PROLOG_PARSED
public static final int PROLOG_PARSED
We have determined the module name and class, but not finished parsing.
PROLOG_PARSING
public static final int PROLOG_PARSING
State code for initial pre-parse looking for module name.
RESOLVED
public static final int RESOLVED
State code for lexical bindings having been resolved.
WALKED
public static final int WALKED
State code when various inlining and optimization passes are done.
apply0args
public static Type[] apply0args
apply0method
public static Method apply0method
apply1args
public static Type[] apply1args
apply1method
public static Method apply1method
apply2args
public static Type[] apply2args
apply2method
public static Method apply2method
apply3method
public static Method apply3method
apply4method
public static Method apply4method
applyCpsMethod
public static Method applyCpsMethod
applyNargs
public static Type[] applyNargs
applyNmethod
public static Method applyNmethod
applymethods
public static Method[] applymethods
argsCallContextField
public static Field argsCallContextField
classPrefix
public String classPrefix
If non-null: a prefix for generateClassName to prepend to names.
classPrefixDefault
public static String classPrefixDefault
currentOptions
public Options currentOptions
current_scope
protected ScopeExp current_scope
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.
defaultCallConvention
public static int defaultCallConvention
The default calling convention.
One of the following CALL_WITHG_xxx values.
emitSourceDebugExtAttr
public static boolean emitSourceDebugExtAttr
exprStack
public Stack exprStack
A help vector for building expressions.
falseConstant
public static final Field falseConstant
fewerClasses
public static boolean fewerClasses
If true, minimize the number of classes generated.
Do this even if it makes things a little slower.
generateApplet
public boolean generateApplet
True if we should generate an Applet.
generateAppletDefault
public static boolean generateAppletDefault
generateMain
public boolean generateMain
True if we should generate a main(String[]) method.
generateMainDefault
public static boolean generateMainDefault
generateServlet
public boolean generateServlet
True if we should generate an Servlet.
generateServletDefault
public static boolean generateServletDefault
getCallContextInstanceMethod
public static Method getCallContextInstanceMethod
getCurrentEnvironmentMethod
public static Method getCurrentEnvironmentMethod
getLocation1EnvironmentMethod
public static final Method getLocation1EnvironmentMethod
getLocation2EnvironmentMethod
public static final Method getLocation2EnvironmentMethod
getLocationMethod
public static final Method getLocationMethod
getProcedureBindingMethod
public static final Method getProcedureBindingMethod
getSymbolProcedureMethod
public static final Method getSymbolProcedureMethod
getSymbolValueMethod
public static final Method getSymbolValueMethod
immediate
public boolean immediate
True if the compiled result will be immediately loaded.
inlineOk
public static boolean inlineOk
int1Args
public static final Type[] int1Args
javaIntegerType
public static ClassType javaIntegerType
javaStringType
public static ClassType javaStringType
lexical
public NameLookup lexical
Current lexical scope - map name to Declaration.
method
public Method method
The current method.
moduleClass
public ClassType moduleClass
Generated class that extends ModuleBody. Normally same as mainClass.
moduleStatic
public static int moduleStatic
If moduleStatic > 0, (module-static #t) is implied by default.
If moduleStatic == 2, calls run.
If moduleStatic <320, (module-static #f) is implied by default.
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.
noArgsField
public static Field noArgsField
objArrayType
public static final ArrayType objArrayType
options
public static Options options
pcCallContextField
public static Field pcCallContextField
pendingImports
public Stack pendingImports
procCallContextField
public static Field procCallContextField
scmBooleanType
public static ClassType scmBooleanType
scmKeywordType
public static ClassType scmKeywordType
scmListType
public static ClassType scmListType
scmNamedType
public static ClassType scmNamedType
scmPairType
public static ClassType scmPairType
scmSequenceType
public static ClassType scmSequenceType
string1Arg
public static final Type[] string1Arg
sym1Arg
public static final Type[] sym1Arg
trueConstant
public static final Field trueConstant
typeCallContext
public static ClassType typeCallContext
typeClassType
public static ClassType typeClassType
typeConsumer
public static final ClassType typeConsumer
typeEnvironment
public static ClassType typeEnvironment
typeLanguage
public static ClassType typeLanguage
typeLocation
public static ClassType typeLocation
typeMethodProc
public static ClassType typeMethodProc
typeModuleBody
public static ClassType typeModuleBody
typeModuleMethod
public static ClassType typeModuleMethod
typeModuleWithContext
public static ClassType typeModuleWithContext
typeObjectType
public static ClassType typeObjectType
typeProcedure
public static ClassType typeProcedure
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
typeProcedureArray
public static ClassType[] typeProcedureArray
typeProcedureN
public static ClassType typeProcedureN
typeRunnable
public static ClassType typeRunnable
typeServlet
public static ClassType typeServlet
addClass
public void addClass(ClassType new_class)
addMainClass
public void addMainClass(ModuleExp module)
allocLocalField
public Field allocLocalField(Type type,
String name)
compileConstant
public void compileConstant(Object value)
Emit code to "evaluate" a compile-time constant.
This is the normal external interface.
value
- the value to be compiled
compileConstant
public void compileConstant(Object value,
Target target)
compileConstantToField
public Field compileConstantToField(Object value)
compileToArchive
public void compileToArchive(ModuleExp mexp,
String fname)
throws java.io.IOException
currentLambda
public LambdaExp currentLambda()
currentModule
public ModuleExp currentModule()
The same as getModule, until we allow nested modules.
currentScope
public ScopeExp currentScope()
demangle2
public static char demangle2(char char1,
char char2)
Demangle a three-character mangling starting with '$'.
UNFINISHED!
demangleName
public static String demangleName(String name)
demangleName
public static String demangleName(String name,
boolean reversible)
error
public void error(char severity,
String message)
error
public void error(char severity,
String message,
String code,
Declaration decl)
error
public void error(char severity,
String message,
SourceLocator location)
error
public void error(char severity,
Declaration decl,
String msg1,
String msg2)
findForImmediateLiterals
public static Compilation findForImmediateLiterals(int key)
findNamedClass
public ClassType findNamedClass(String name)
Search this Compilation for a ClassType with a given name.
name
- the name of the class desired
- the matching ClassType, or null if none is found
freeLocalField
public void freeLocalField(Field field)
generateApplyMethodsWithContext
public void generateApplyMethodsWithContext(LambdaExp lexp)
Generate ModuleBody's apply(CallContext) method
Use the applyMethods vector, which contains methods that
implement the (public, readable) methods of the current module.
generateApplyMethodsWithoutContext
public void generateApplyMethodsWithoutContext(LambdaExp lexp)
Generate ModuleBody's apply0...applyN methods.
Use the applyMethods vector, which contains methods that
implement the (public, readable) methods of the current module.
generateClassName
public String generateClassName(String hint)
Generate an unused class name.
hint
- the requested name (or prefix)
generateConstructor
public final void generateConstructor(LambdaExp lexp)
generateMatchMethods
public void generateMatchMethods(LambdaExp lexp)
getBooleanOption
public final boolean getBooleanOption(String key)
Get a named boolean option.
getBooleanOption
public final boolean getBooleanOption(String key,
boolean defaultValue)
Get a named boolean option.
getColumnNumber
public final int getColumnNumber()
Return current column number.
The "first" column is column 1; unknown is -1.
- getColumnNumber in interface SourceLocator
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.
getLanguage
public Language getLanguage()
getLineNumber
public final int getLineNumber()
Return current line number.
The "first" line is line 1; unknown is -1.
- getLineNumber in interface SourceLocator
getModuleType
public final ClassType getModuleType()
getState
public int getState()
Returns a code indicating how far along
we are in the parsing/compilation process.
inlineOk
public boolean inlineOk(Procedure proc)
isPedantic
public boolean isPedantic()
isStableSourceLocation
public boolean isStableSourceLocation()
True if position is unlikely to change.
True for an expression but not an input file.
- isStableSourceLocation in interface SourceLocator
isStatic
public boolean isStatic()
isValidJavaName
public static boolean isValidJavaName(String name)
letEnter
public void letEnter()
letStart
public void letStart()
loadCallContext
public final void loadCallContext()
Generate code to push the current CallContext on the JVM stack.
loadClassRef
public void loadClassRef(String className)
Generate code to load a named Class without initializing it.
loadClassRef
public void loadClassRef(ClassType clas)
lookup
public Declaration lookup(Object name,
int namespace)
loopEnter
public void loopEnter()
Done handling loop variables, and pushes them into the lexical scope.
Ready to parse the loop condition.
loopStart
public void loopStart()
Start a new loop.
(We could make this implied by the first loopVaribale call ???)
mangleName
public static String mangleName(String name)
mangleName
public static String mangleName(String name,
boolean reversible)
Convert a string to a safe Java identifier.
reversible
- if we should use an invertible mapping.
mangleName
public static String mangleName(String name,
int kind)
Convert a string to a safe Java identifier.
kind
- -1 - non-reversible;
0: reversible, except that '$' is not mapped;
1: reversible
mangleNameIfNeeded
public static String mangleNameIfNeeded(String name)
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.
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.
outputClass
public void outputClass(String directory)
throws IOException
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.
pop
public final void pop()
process
public void process(int wantedState)
Parse/walk/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).
wantedState
- the desired value of getState().
pushNewModule
public ModuleExp pushNewModule(String filename)
pushScope
public final void pushScope(ScopeExp scope)
registerForImmediateLiterals
public static int registerForImmediateLiterals(Compilation comp)
resolve
public Object resolve(Object name,
boolean function)
setColumn
public void setColumn(int column)
setCurrent
public static void setCurrent(Compilation comp)
setCurrentScope
public void setCurrentScope(ScopeExp scope)
Set currentScope()
.
Also update the nesting
object.
setFile
public void setFile(String filename)
setLine
public void setLine(Object location)
setLine
public void setLine(String filename,
int line,
int column)
setLine
public final void setLine(Expression position)
setLine
public void setLine(int line)
setModule
public void setModule(ModuleExp mexp)
setState
public void setState(int state)
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.
syntaxError
public Expression syntaxError(String message)
Handle syntax errors (at rewrite time).
message
- an error message to print out
toString
public String toString()
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 defines when in
immediate mode (in Scheme using define-class or similar).
usingCPStyle
public boolean usingCPStyle()
usingTailCalls
public boolean usingTailCalls()
walkModule
public void walkModule(ModuleExp mexp)
Shared processing for both compiling/eval.