| java.lang.Object gnu.expr.Compilation
All known Subclasses: kawa.lang.Translator,
Compilation | public class Compilation implements SourceLocator(Code) | | State for a single expression or module.
For each top-level thing (expression or file) we compile or evaluate
we create a new Compilation.
|
Field Summary | |
final public static int | BODY_PARSED State code indicating the entire module has been parsed. | final public static int | CALL_WITH_CONSUMER Function results are written to the current CallContext's Consumer. | final public static int | CALL_WITH_CONTINUATIONS Support for full continuations. | final public static int | CALL_WITH_RETURN Plain calling convention, using regular Java parameters and returns. | final public static int | CALL_WITH_TAILCALLS Like CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls. | final public static int | CALL_WITH_UNSPECIFIED | final public static int | CLASS_WRITTEN State code indicating that bytecode has been written to its target. | final public static int | COMPILED State code indicating the bytecode has been generated. | final public static int | COMPILE_SETUP State code that various compile-only data has been determined. | final public static int | ERROR_SEEN | final public static int | PROLOG_PARSED We have determined the module name and class, but not finished parsing. | final public static int | PROLOG_PARSING State code for initial pre-parse looking for module name. | final public static int | RESOLVED State code for lexical bindings having been resolved. | final public static int | WALKED State code when various inlining and optimization passes are done. | public static Type[] | apply0args | public static Method | apply0method | public static Type[] | apply1args | public static Method | apply1method | public static Type[] | apply2args | public static Method | apply2method | public static Method | apply3method | public static Method | apply4method | public static Method | applyCpsMethod | public static Type[] | applyNargs | public static Method | applyNmethod | public static Method[] | applymethods | public static Field | argsCallContextField | Variable | callContextVar If non-null, contains the value of the current CallContext. | Variable | callContextVarForInit | static Method | checkArgCountMethod | public String | classPrefix If non-null: a prefix for generateClassName to prepend to names. | public static String | classPrefixDefault | ClassType[] | classes | Initializer | clinitChain Rembembers stuff to do in of main class. | Method | clinitMethod | public ClassType | curClass | public LambdaExp | curLambda | public Options | currentOptions | protected ScopeExp | current_scope | public static boolean | debugPrintExpr If true, print out expressions after parsing and before optimizations. | public static boolean | debugPrintFinalExpr If true, print out final expressions after optimizations etc. | public static int | defaultCallConvention The default calling convention.
One of the following CALL_WITHG_xxx values. | public static boolean | emitSourceDebugExtAttr | public Stack | exprStack A help vector for building expressions. | final public static Field | falseConstant | public static boolean | fewerClasses If true, minimize the number of classes generated.
Do this even if it makes things a little slower. | Method | forNameHelper If non-null, a helper method generated by getForNameHelper. | SwitchState | fswitch | Field | fswitchIndex | public boolean | generateApplet True if we should generate an Applet. | public static boolean | generateAppletDefault | public boolean | generateMain True if we should generate a main(String[]) method. | public static boolean | generateMainDefault | public boolean | generateServlet True if we should generate an Servlet. | public static boolean | generateServletDefault | public static Method | getCallContextInstanceMethod | public static Method | getCurrentEnvironmentMethod | final public static Method | getLocation1EnvironmentMethod | final public static Method | getLocation2EnvironmentMethod | final public static Method | getLocationMethod | final public static Method | getProcedureBindingMethod | final public static Method | getSymbolProcedureMethod | final public static Method | getSymbolValueMethod | public boolean | immediate True if the compiled result will be immediately loaded. | public static boolean | inlineOk | final public static Type[] | int1Args | public static ClassType | javaIntegerType | public static ClassType | javaStringType | protected Language | language | public Lexer | lexer | public NameLookup | lexical Current lexical scope - map name to Declaration. | LitTable | litTable | ArrayClassLoader | loader When immediate, the ClassLoader we will load the compiled
classes from. | int | localFieldIndex | public ClassType | mainClass | public ModuleExp | mainLambda | static Method | makeListMethod | int | maxSelectorValue Used by LambdaExp.getSelectorValue if need to allocate new selector. | protected SourceMessages | messages | public Method | method The current method. | int | method_counter | public ModuleInfo | minfo | public ClassType | moduleClass Generated class that extends ModuleBody. | Field | moduleInstanceMainField Used to access the "main" instance. | Variable | moduleInstanceVar Contains "$instance" if the module is static; otherwise null. | public static int | moduleStatic If moduleStatic > 0, (module-static #t) is implied by default.
If moduleStatic == 2, calls run.
If moduleStatic < 0, (module-static #f) is implied by default. | 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. | public static Field | noArgsField | int | numClasses | final public static ArrayType | objArrayType | public static Options | options | public static Field | pcCallContextField | boolean | pedantic | public java.util.Stack | pendingImports | public static Field | procCallContextField | public static ClassType | scmBooleanType | public static ClassType | scmKeywordType | public static ClassType | scmListType | public static ClassType | scmNamedType | public static ClassType | scmPairType | public static ClassType | scmSequenceType | final static Method | setNameMethod | final public static Type[] | string1Arg | final public static Type[] | sym1Arg | public Variable | thisDecl | final public static Field | trueConstant | public static ClassType | typeApplet | public static ClassType | typeCallContext | public static ClassType | typeClass | public static ClassType | typeClassType | final public static ClassType | typeConsumer | public static ClassType | typeEnvironment | public static ClassType | typeLanguage | public static ClassType | typeLocation | public static ClassType | typeMethodProc | public static ClassType | typeModuleBody | public static ClassType | typeModuleMethod | public static ClassType | typeModuleWithContext | public static ClassType | typeObject | public static ClassType | typeObjectType | public static ClassType | typePair | public static ClassType | typeProcedure | public static ClassType | typeProcedure0 | public static ClassType | typeProcedure1 | public static ClassType | typeProcedure2 | public static ClassType | typeProcedure3 | public static ClassType | typeProcedure4 | public static ClassType[] | typeProcedureArray | public static ClassType | typeProcedureN | public static ClassType | typeRunnable | public static ClassType | typeServlet | public static ClassType | typeString | public static ClassType | typeSymbol | public static ClassType | typeType | public static ClassType | typeValues |
Method Summary | |
public void | addClass(ClassType new_class) | public void | addMainClass(ModuleExp module) | public Field | allocLocalField(Type type, String name) | void | callInitMethods(ClassType clas, Vector seen) In an for a generated ClassExp, emit $finit$ calls. | public void | compileConstant(Object value) Emit code to "evaluate" a compile-time constant. | public void | compileConstant(Object value, Target target) | public Field | compileConstantToField(Object value) | public void | compileToArchive(ModuleExp mexp, String fname) | public LambdaExp | currentLambda() | public ModuleExp | currentModule() The same as getModule, until we allow nested modules. | public ScopeExp | currentScope() | public static char | demangle2(char char1, char char2) Demangle a three-character mangling starting with '$'. | public static String | demangleName(String name) | public static String | demangleName(String name, boolean reversible) | public void | error(char severity, String message, SourceLocator location) | public void | error(char severity, String message) | public void | error(char severity, Declaration decl, String msg1, String msg2) | public void | error(char severity, String message, String code, Declaration decl) | public static synchronized Compilation | findForImmediateLiterals(int key) | public ClassType | findNamedClass(String name) Search this Compilation for a ClassType with a given name. | public void | freeLocalField(Field field) | 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. | public void | generateApplyMethodsWithoutContext(LambdaExp lexp) Generate ModuleBody's apply0...applyN methods. | void | generateBytecode() The guts of compiling a module to one or more classes. | public String | generateClassName(String hint) Generate an unused class name. | final public void | generateConstructor(LambdaExp lexp) | final public void | generateConstructor(ClassType clas, LambdaExp lexp) | public void | generateMatchMethods(LambdaExp lexp) | final public boolean | getBooleanOption(String key, boolean defaultValue) Get a named boolean option. | final public boolean | getBooleanOption(String key) Get a named boolean option. | final public CodeAttr | getCode() | final public int | getColumnNumber() | final public Method | getConstructor(LambdaExp lexp) | final public static Method | getConstructor(ClassType clas, LambdaExp lexp) | public static Compilation | getCurrent() | final public String | getFileName() | 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. | public Language | getLanguage() | final public int | getLineNumber() | public SourceMessages | getMessages() | final public ModuleExp | getModule() | final public ClassType | getModuleType() | public String | getPublicId() | public int | getState() Returns a code indicating how far along
we are in the parsing/compilation process. | public String | getSystemId() | public boolean | inlineOk(Expression proc) | public boolean | inlineOk(Procedure proc) | public boolean | isPedantic() | public boolean | isStableSourceLocation() | public boolean | isStatic() | public static boolean | isValidJavaName(String name) | public LetExp | letDone(Expression body) | public void | letEnter() | public void | letStart() | public Declaration | letVariable(Object name, Type type, Expression init) | final public void | loadCallContext() Generate code to push the current CallContext on the JVM stack. | public void | loadClassRef(ClassType clas) | public void | loadClassRef(String className) Generate code to load a named Class without initializing it. | public Declaration | lookup(Object name, int namespace) | public void | loopBody(Expression body) | public void | loopCond(Expression cond) | public void | loopEnter() Done handling loop variables, and pushes them into the lexical scope.
Ready to parse the loop condition. | public Expression | loopRepeat(Expression[] exps) | public Expression | loopRepeat() | public Expression | loopRepeat(Expression exp) | public void | loopStart() Start a new loop. | public Declaration | loopVariable(Object name, Type type, Expression init) | public static String | mangleName(String name) | public static String | mangleName(String name, boolean reversible) Convert a string to a safe Java identifier. | public static String | mangleName(String name, int kind) Convert a string to a safe Java identifier. | public static String | mangleNameIfNeeded(String name) | public static String | mangleURI(String name) Map a URI to a package/class name. | public void | mustCompileHere() Note that we have seen a construct that must be compiled, not evaluated. | public void | outputClass(String directory) | public Expression | parse(Object input) This may not make sense, except for Lisp-like languages.
For those, 'input' an s-expression from the reader. | public void | pop(ScopeExp scope) | final public void | pop() | public void | process(int wantedState) Parse/walk/compile this module as needed and requested. | public void | push(ScopeExp scope) | public void | push(Declaration decl) | void | pushChain(ScopeExp scope, ScopeExp limit) | public ModuleExp | pushNewModule(Lexer lexer) | public ModuleExp | pushNewModule(String filename) | public void | pushPendingImport(ModuleInfo info, ScopeExp defs) | final public void | pushScope(ScopeExp scope) | public static synchronized int | registerForImmediateLiterals(Compilation comp) | public Object | resolve(Object name, boolean function) | public void | setColumn(int column) | public static void | setCurrent(Compilation comp) | public void | setCurrentScope(ScopeExp scope) Set currentScope() . | public void | setFile(String filename) | public void | setLine(int line) | final public void | setLine(Expression position) | public void | setLine(Object location) | public void | setLine(String filename, int line, int column) | final public void | setLocation(SourceLocator position) | public void | setMessages(SourceMessages messages) | public void | setModule(ModuleExp mexp) | public void | setState(int state) | public static void | setupLiterals(int key) Call-back from compiled code to initialize literals in immediate mode.
In non-immediate mode (i.e. | public Expression | syntaxError(String message) Handle syntax errors (at rewrite time). | public String | toString() | public void | usedClass(Type type) Called for classes referenced in bytecode. | public boolean | usingCPStyle() | public boolean | usingTailCalls() | public void | walkModule(ModuleExp mexp) Shared processing for both compiling/eval. |
BODY_PARSED | final public static int BODY_PARSED(Code) | | State code indicating the entire module has been parsed.
|
CALL_WITH_CONSUMER | final public static int CALL_WITH_CONSUMER(Code) | | Function results are written to the current CallContext's Consumer.
|
CALL_WITH_CONTINUATIONS | final public static int CALL_WITH_CONTINUATIONS(Code) | | Support for full continuations. Not implemented.
|
CALL_WITH_RETURN | final public static int CALL_WITH_RETURN(Code) | | Plain calling convention, using regular Java parameters and returns.
|
CALL_WITH_TAILCALLS | final public static int CALL_WITH_TAILCALLS(Code) | | Like CALL_WITH_CONSUMER, but handle full on-stack-growing tail-calls.
|
CALL_WITH_UNSPECIFIED | final public static int CALL_WITH_UNSPECIFIED(Code) | | |
CLASS_WRITTEN | final public static int CLASS_WRITTEN(Code) | | State code indicating that bytecode has been written to its target.
|
COMPILED | final public static int COMPILED(Code) | | State code indicating the bytecode has been generated.
|
COMPILE_SETUP | final public static int COMPILE_SETUP(Code) | | State code that various compile-only data has been determined.
|
ERROR_SEEN | final public static int ERROR_SEEN(Code) | | |
PROLOG_PARSED | final public static int PROLOG_PARSED(Code) | | We have determined the module name and class, but not finished parsing.
|
PROLOG_PARSING | final public static int PROLOG_PARSING(Code) | | State code for initial pre-parse looking for module name.
|
RESOLVED | final public static int RESOLVED(Code) | | State code for lexical bindings having been resolved.
|
WALKED | final public static int WALKED(Code) | | State code when various inlining and optimization passes are done.
|
argsCallContextField | public static Field argsCallContextField(Code) | | |
callContextVar | Variable callContextVar(Code) | | If non-null, contains the value of the current CallContext.
|
classPrefix | public String classPrefix(Code) | | If non-null: a prefix for generateClassName to prepend to names.
|
classPrefixDefault | public static String classPrefixDefault(Code) | | |
debugPrintExpr | public static boolean debugPrintExpr(Code) | | If true, print out expressions after parsing and before optimizations.
|
debugPrintFinalExpr | public static boolean debugPrintFinalExpr(Code) | | If true, print out final expressions after optimizations etc.
|
defaultCallConvention | public static int defaultCallConvention(Code) | | The default calling convention.
One of the following CALL_WITHG_xxx values.
|
emitSourceDebugExtAttr | public static boolean emitSourceDebugExtAttr(Code) | | |
exprStack | public Stack exprStack(Code) | | A help vector for building expressions.
|
falseConstant | final public static Field falseConstant(Code) | | |
fewerClasses | public static boolean fewerClasses(Code) | | If true, minimize the number of classes generated.
Do this even if it makes things a little slower.
|
forNameHelper | Method forNameHelper(Code) | | If non-null, a helper method generated by getForNameHelper.
|
generateApplet | public boolean generateApplet(Code) | | True if we should generate an Applet.
|
generateAppletDefault | public static boolean generateAppletDefault(Code) | | |
generateMain | public boolean generateMain(Code) | | True if we should generate a main(String[]) method.
|
generateMainDefault | public static boolean generateMainDefault(Code) | | |
generateServlet | public boolean generateServlet(Code) | | True if we should generate an Servlet.
|
generateServletDefault | public static boolean generateServletDefault(Code) | | |
getCallContextInstanceMethod | public static Method getCallContextInstanceMethod(Code) | | |
getCurrentEnvironmentMethod | public static Method getCurrentEnvironmentMethod(Code) | | |
getLocation1EnvironmentMethod | final public static Method getLocation1EnvironmentMethod(Code) | | |
getLocation2EnvironmentMethod | final public static Method getLocation2EnvironmentMethod(Code) | | |
getLocationMethod | final public static Method getLocationMethod(Code) | | |
getProcedureBindingMethod | final public static Method getProcedureBindingMethod(Code) | | |
getSymbolProcedureMethod | final public static Method getSymbolProcedureMethod(Code) | | |
getSymbolValueMethod | final public static Method getSymbolValueMethod(Code) | | |
immediate | public boolean immediate(Code) | | True if the compiled result will be immediately loaded.
|
inlineOk | public static boolean inlineOk(Code) | | |
lexical | public NameLookup lexical(Code) | | Current lexical scope - map name to Declaration.
|
localFieldIndex | int localFieldIndex(Code) | | |
maxSelectorValue | int maxSelectorValue(Code) | | Used by LambdaExp.getSelectorValue if need to allocate new selector.
|
method_counter | int method_counter(Code) | | |
moduleClass | public ClassType moduleClass(Code) | | Generated class that extends ModuleBody. Normally same as mainClass.
|
moduleInstanceMainField | Field moduleInstanceMainField(Code) | | Used to access the "main" instance.
This is used for two different purposes, which may be confusing:
-
If we're compiling a static module, then
moduleInstanceMainField is a field in
mainClass named
"$instance" that
points to the single instance of the module.
-
If
moduleClass!=mainClass (typically because we've specified
module-extends ) and the module is non-static then
moduleInstanceMainField is a field in
moduleClass named
"$main" that points back to
mainClass .
|
moduleInstanceVar | Variable moduleInstanceVar(Code) | | Contains "$instance" if the module is static; otherwise null.
|
moduleStatic | public static int moduleStatic(Code) | | If moduleStatic > 0, (module-static #t) is implied by default.
If moduleStatic == 2, calls run.
If moduleStatic < 0, (module-static #f) is implied by default.
|
mustCompile | public boolean mustCompile(Code) | | 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.
|
numClasses | int numClasses(Code) | | |
pcCallContextField | public static Field pcCallContextField(Code) | | |
pedantic | boolean pedantic(Code) | | |
procCallContextField | public static Field procCallContextField(Code) | | |
string1Arg | final public static Type[] string1Arg(Code) | | |
trueConstant | final public static Field trueConstant(Code) | | |
callInitMethods | void callInitMethods(ClassType clas, Vector seen)(Code) | | In an for a generated ClassExp, emit $finit$ calls.
This recursively traverses superclasses, and also calls their $finit$.
Parameters: clas - Class to search for $finit$, and to search supertypes. Parameters: seen - array of seen classes, to avoid duplicate $finit$ calls. |
compileConstant | public void compileConstant(Object value)(Code) | | Emit code to "evaluate" a compile-time constant.
This is the normal external interface.
Parameters: value - the value to be compiled |
currentModule | public ModuleExp currentModule()(Code) | | The same as getModule, until we allow nested modules.
|
demangle2 | public static char demangle2(char char1, char char2)(Code) | | Demangle a three-character mangling starting with '$'.
UNFINISHED!
|
findForImmediateLiterals | public static synchronized Compilation findForImmediateLiterals(int key)(Code) | | |
findNamedClass | public ClassType findNamedClass(String name)(Code) | | Search this Compilation for a ClassType with a given name.
Parameters: name - the name of the class desired the matching ClassType, or null if none is found |
freeLocalField | public void freeLocalField(Field field)(Code) | | |
generateApplyMethodsWithContext | public void generateApplyMethodsWithContext(LambdaExp lexp)(Code) | | 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)(Code) | | Generate ModuleBody's apply0...applyN methods.
Use the applyMethods vector, which contains methods that
implement the (public, readable) methods of the current module.
|
generateBytecode | void generateBytecode()(Code) | | The guts of compiling a module to one or more classes.
Assumes walkModule has been done.
|
generateClassName | public String generateClassName(String hint)(Code) | | Generate an unused class name.
Parameters: hint - the requested name (or prefix) a unique class name. |
generateConstructor | final public void generateConstructor(LambdaExp lexp)(Code) | | |
getBooleanOption | final public boolean getBooleanOption(String key, boolean defaultValue)(Code) | | Get a named boolean option.
|
getBooleanOption | final public boolean getBooleanOption(String key)(Code) | | Get a named boolean option.
|
getColumnNumber | final public int getColumnNumber()(Code) | | |
getForNameHelper | public Method getForNameHelper()(Code) | | 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.
|
getLineNumber | final public int getLineNumber()(Code) | | |
getState | public int getState()(Code) | | Returns a code indicating how far along
we are in the parsing/compilation process.
|
isPedantic | public boolean isPedantic()(Code) | | |
isStableSourceLocation | public boolean isStableSourceLocation()(Code) | | |
isStatic | public boolean isStatic()(Code) | | |
isValidJavaName | public static boolean isValidJavaName(String name)(Code) | | |
letEnter | public void letEnter()(Code) | | |
letStart | public void letStart()(Code) | | |
loadCallContext | final public void loadCallContext()(Code) | | Generate code to push the current CallContext on the JVM stack.
|
loadClassRef | public void loadClassRef(String className)(Code) | | Generate code to load a named Class without initializing it.
|
loopEnter | public void loopEnter()(Code) | | Done handling loop variables, and pushes them into the lexical scope.
Ready to parse the loop condition.
|
loopStart | public void loopStart()(Code) | | Start a new loop.
(We could make this implied by the first loopVaribale call ???)
|
mangleName | public static String mangleName(String name, boolean reversible)(Code) | | Convert a string to a safe Java identifier.
Parameters: reversible - if we should use an invertible mapping. |
mangleName | public static String mangleName(String name, int kind)(Code) | | Convert a string to a safe Java identifier.
Parameters: kind - -1 - non-reversible;0: reversible, except that '$' is not mapped;1: reversible |
mangleURI | public static String mangleURI(String name)(Code) | | Map a URI to a package/class name.
Similar to the JAXB mangling, and that in the Java language spec.
|
mustCompileHere | public void mustCompileHere()(Code) | | 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.
|
parse | public Expression parse(Object input)(Code) | | This may not make sense, except for Lisp-like languages.
For those, 'input' an s-expression from the reader.
|
pop | final public void pop()(Code) | | |
process | public void process(int wantedState)(Code) | | 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).
Parameters: wantedState - the desired value of getState(). |
registerForImmediateLiterals | public static synchronized int registerForImmediateLiterals(Compilation comp)(Code) | | |
setColumn | public void setColumn(int column)(Code) | | |
setCurrentScope | public void setCurrentScope(ScopeExp scope)(Code) | | Set currentScope() .
Also update the nesting object.
|
setLine | public void setLine(int line)(Code) | | |
setLine | public void setLine(String filename, int line, int column)(Code) | | |
setState | public void setState(int state)(Code) | | |
setupLiterals | public static void setupLiterals(int key)(Code) | | 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)(Code) | | Handle syntax errors (at rewrite time).
Parameters: message - an error message to print out an ErrorExp |
usedClass | public void usedClass(Type type)(Code) | | 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()(Code) | | |
usingTailCalls | public boolean usingTailCalls()(Code) | | |
walkModule | public void walkModule(ModuleExp mexp)(Code) | | Shared processing for both compiling/eval.
|
|
|