Package gnu.expr
Class LambdaExp
java.lang.Object
gnu.mapping.PropertySet
gnu.mapping.Procedure
gnu.expr.Expression
gnu.expr.ScopeExp
gnu.expr.LambdaExp
- All Implemented Interfaces:
gnu.kawa.format.Printable
,Named
,SourceLocator
,SourceLocator
,Locator
Class used to implement Scheme lambda expressions.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface gnu.text.SourceLocator
SourceLocator.Simple
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final MethodHandle
static final int
static final String
If non-null, this is a Field that is used for implementing lexical closures.protected static final int
True if IS_SUPPLIED_PARAMETER is set on a parameter.protected static final int
static final int
If this lambda gets inlined this is the containing lambda.Keyword[]
int
Maximum number of actual arguments; -1 if variable.int
Minimum number of actual arguments.If non-null, a Declaration whose value is (only) this LambdaExp.protected static final int
static final int
int
Number of optional arguments, not counting keyword arguments.static final int
static final int
Treat as inlined in outer lambda when determining tailcalls.static final int
True of emitted method should be public.The unique call site that calls this lambda.If non-null, the type of values returned by this function.static final int
Field in heapFrame.getType() that contains the static link.Fields inherited from class gnu.expr.Expression
applyMethodExpression, flags, noExpressions, type, VALIDATED
Fields inherited from class gnu.mapping.Procedure
applyMethodType, applyToConsumerDefault, applyToConsumerMethod, applyToObjectDefault, applyToObjectMethod, compilerKey, compilerXKey, inlineIfConstantSymbol, validateApplyKey, validateXApplyKey
Fields inherited from class gnu.mapping.PropertySet
nameKey
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddParameter
(Object name) void
allocChildClasses
(Compilation comp) void
allocFrame
(Compilation comp) void
apply
(CallContext ctx) Evaluate the expression.protected Type
void
capture
(Declaration decl) checkForInitCall
(Expression bodyFirst) Check if argument is a this(...) or super(...) initializtion.void
compile
(Compilation comp, Target target) void
compileBody
(Compilation comp) void
compileEnd
(Compilation comp) compileSetField
(Compilation comp) declareThis
(ClassType clas) void
Get the first expression/statement in the body.int
The calling convention used for this function.For an INLINE_ONLY function, return the function it gets inlined in.final boolean
The ClassType generated for this class.protected ClassType
Return the ClassType of the Procedure this is being compiled into.protected final String
final boolean
True iff this lambda "captures" (uses) lexical variables from outside.final boolean
True iff this lambda is only "called" inline.final Method
Get the method that contains the actual body of the procedure.final Method
getMethod
(int nonSpliceCount, int spliceCount) Select the method used given an argument count.final boolean
final boolean
True if a child lambda uses lexical variables from outside.getProperty
(Object key, Object defaultValue) final Type
The return type of this function, i.e the type of its returned values.int
Number of argument variable actually passed by the caller.boolean
True if no primitive method is created for this procedure.final boolean
boolean
final boolean
True if this is a method in an ClassExp.final boolean
final boolean
True iff this is the dummy top-level function of a module body.boolean
isNative()
void
loadHeapFrame
(Compilation comp) Generate code to load heapFrame on the JVM stack.static void
maybeSetReturnType
(LambdaExp lexp, Type type) protected boolean
Return the closest outer non-inlined LambdaExp.void
print
(gnu.kawa.io.OutPort out) void
final Type
Return the parameter type of the "keyword/rest" parameters.void
void
setCallConvention
(Compilation comp) final void
setCanRead
(boolean read) final void
setClassMethod
(boolean isMethod) final void
setCoercedReturnType
(Type returnType) final void
setCoercedReturnValue
(Expression type, Language language) Modify LambdaExp so result is coerced to given type.void
setExceptions
(Expression[] exceptions) final void
final void
setImportsLexVars
(boolean importsLexVars) final void
setInlineOnly
(boolean inlineOnly) final void
setInlineOnly
(Expression returnContinuation, LambdaExp caller) Note this function is inlined in a give context.final void
final void
setNeedsStaticLink
(boolean needsStaticLink) void
setProperty
(Object key, Object value) final void
setReturnType
(Type returnType) void
boolean
True if evaluating may have side-effects.toString()
boolean
validateApply
(ApplyExp exp, InlineCalls visitor, Type required, Declaration decl) Apply inlining transformations on a given ApplyExp.final boolean
protected <R,
D> R visit
(ExpVisitor<R, D> visitor, D d) protected <R,
D> void visitChildren
(ExpVisitor<R, D> visitor, D d) protected final <R,
D> void visitChildrenOnly
(ExpVisitor<R, D> visitor, D d) protected final <R,
D> void visitProperties
(ExpVisitor<R, D> visitor, D d) Methods inherited from class gnu.expr.ScopeExp
add, add, addDeclaration, addDeclaration, addDeclaration, clearCallList, countDecls, currentLambda, currentModule, duplicateDeclarationError, firstDecl, getDefine, getNoDefine, getOuter, getVarScope, isClassGenerated, lastDecl, lookup, lookup, nestedIn, nesting, popScope, remove, remove, replaceFollowing, setIndexes, setOuter, topLevel
Methods inherited from class gnu.expr.Expression
applyMethodExpression, checkLiteralKeyword, compile, compile, compileWithPosition, compileWithPosition, deepCopy, deepCopy, deepCopy, deepCopy, eval, eval, getColumnNumber, getEndColumn, getEndLine, getFileName, getFlag, getFlags, getLineNumber, getPublicId, getStartColumn, getStartLine, getSystemId, getType, getTypeRaw, isSingleValue, isStableSourceLocation, makeWhile, maybeSetLine, neverReturns, numArgs, print, printLineColumn, setFile, setFlag, setFlag, setLine, setLine, setLine, setLine, setLine, setLocation, setType, valueIfConstant
Methods inherited from class gnu.mapping.Procedure
apply0, apply1, apply2, apply3, apply4, applyL, applyN, applyToConsumerDefault, applyToObjectDefault, checkArgCount, checkBadCode, getApplyMethod, getApplyToConsumerMethod, getApplyToObjectMethod, getReturnType, getSetter, getSourceLocation, isSideEffectFree, lookupApplyHandle, maxArgs, maxArgs, minArgs, minArgs, set0, set1, setN, setSetter, setSourceLocation
Methods inherited from class gnu.mapping.PropertySet
getName, getSymbol, removeProperty, setName, setProperty, setSymbol
-
Field Details
-
body
-
min_args
public int min_argsMinimum number of actual arguments. Does not count implicit isThisParameter(). -
max_args
public int max_argsMaximum number of actual arguments; -1 if variable. Does not count keyword arguments. -
opt_args
public int opt_argsNumber of optional arguments, not counting keyword arguments. -
keywords
-
firstChild
-
nextSibling
-
returnContinuation
The unique call site that calls this lambda. The value is null if no callers have been seen. A value of unknownContinuation means there are multiple call sites. Tail-recursive calls do not count as multiple call sites. This is used to see if we can inline the function at its unique call site. Usually this is an ApplyExp, but it can also be the "tail position" for some outer expression, such as an IfExp. This allows inlining f in the call 'if (cond) f(x) else f(y)' since both calls have the same return point. -
inlineHome
If this lambda gets inlined this is the containing lambda. Otherwise this is null. -
nameDecl
If non-null, a Declaration whose value is (only) this LambdaExp. -
CLOSURE_ENV_NAME
- See Also:
-
closureEnvField
If non-null, this is a Field that is used for implementing lexical closures. If getName() is CLOSURE_ENV_NAME, it is our parent's heapFrame, which is an instance of one of our siblings. (Otherwise, we use "this" as the implicit "closureEnv" field.) -
staticLinkField
Field in heapFrame.getType() that contains the static link. It is used by child functions to get to outer environments. Its value is this function's closureEnv value. -
NO_FIELD
public static final int NO_FIELD- See Also:
-
SEQUENCE_RESULT
public static final int SEQUENCE_RESULT- See Also:
-
OVERLOADABLE_FIELD
public static final int OVERLOADABLE_FIELD- See Also:
-
ATTEMPT_INLINE
public static final int ATTEMPT_INLINE- See Also:
-
IN_EXPWALKER
public static final int IN_EXPWALKER- See Also:
-
PASSES_TAILCALLS
public static final int PASSES_TAILCALLSTreat as inlined in outer lambda when determining tailcalls.- See Also:
-
PUBLIC_METHOD
public static final int PUBLIC_METHODTrue of emitted method should be public. Needed if PrimProcedure.getMethodFor shold be able to find it.- See Also:
-
ALLOW_OTHER_KEYWORDS
public static final int ALLOW_OTHER_KEYWORDS- See Also:
-
HAS_NONTRIVIAL_PATTERN
protected static final int HAS_NONTRIVIAL_PATTERN- See Also:
-
HAS_NONTRIVIAL_DEFAULT
protected static final int HAS_NONTRIVIAL_DEFAULTTrue if IS_SUPPLIED_PARAMETER is set on a parameter. In that case we generate an extra foo$P method for the actual body. (It might make sense to also do this whenever a default expression is non-literal, but we current don't do that.)- See Also:
-
NEXT_AVAIL_FLAG
protected static final int NEXT_AVAIL_FLAG- See Also:
-
returnType
If non-null, the type of values returned by this function. If null, the return type has not been set or calculated yet. -
applyToConsumer
-
-
Constructor Details
-
LambdaExp
public LambdaExp() -
LambdaExp
public LambdaExp(int args) -
LambdaExp
-
-
Method Details
-
capture
-
addParameter
-
setExceptions
-
getInlineOnly
public final boolean getInlineOnly()True iff this lambda is only "called" inline. -
setInlineOnly
public final void setInlineOnly(boolean inlineOnly) -
inlinedInCheckMethod
public final boolean inlinedInCheckMethod() -
inlinedInCallerOrCheckMethodOnly
public boolean inlinedInCallerOrCheckMethodOnly()True if no primitive method is created for this procedure. Specifically ifgetInlineOnly() || inlinedInCheckMethod()
. -
setInlineOnly
Note this function is inlined in a give context. This is meant to be used during validate-apply processing, for procedures that will be inlined in a compile method. -
getNeedsClosureEnv
public final boolean getNeedsClosureEnv() -
getNeedsStaticLink
public final boolean getNeedsStaticLink()True if a child lambda uses lexical variables from outside. Hence, a child heapFrame needs a staticLink to outer frames. -
setNeedsStaticLink
public final void setNeedsStaticLink(boolean needsStaticLink) -
getImportsLexVars
public final boolean getImportsLexVars()True iff this lambda "captures" (uses) lexical variables from outside. -
setImportsLexVars
public final void setImportsLexVars(boolean importsLexVars) -
setImportsLexVars
public final void setImportsLexVars() -
setNeedsStaticLink
public final void setNeedsStaticLink() -
getCanRead
public final boolean getCanRead() -
setCanRead
public final void setCanRead(boolean read) -
isClassMethod
public final boolean isClassMethod()True if this is a method in an ClassExp. -
setClassMethod
public final void setClassMethod(boolean isMethod) -
isModuleBody
public final boolean isModuleBody()True iff this is the dummy top-level function of a module body. -
isAbstract
public boolean isAbstract() -
isNative
public boolean isNative() -
getCallConvention
public int getCallConvention()The calling convention used for this function. It is derived from Compilation's currentCallConvention.- Returns:
- One of the CALL_WITH_xxx values in Compilation.
-
setCallConvention
-
usingCallContext
public boolean usingCallContext() -
isHandlingTailCalls
public final boolean isHandlingTailCalls() -
variable_args
public final boolean variable_args() -
getCompiledClassType
Return the ClassType of the Procedure this is being compiled into. -
calculateType
- Overrides:
calculateType
in classExpression
-
getClassType
The ClassType generated for this class. Only used for ClassExp (which overrides this method) or ModuleExp. -
setType
-
incomingArgs
public int incomingArgs()Number of argument variable actually passed by the caller. For functions that accept more than 4 argument, or take a variable number, this is 1, since in that all arguments are passed in a single array. -
getMethod
Select the method used given an argument count. -
getMainMethod
Get the method that contains the actual body of the procedure. (The other methods are just stubs that call that method.) -
restArgType
Return the parameter type of the "keyword/rest" parameters. -
outerLambda
-
outerLambdaOrCaller
-
outerLambdaNotInline
Return the closest outer non-inlined LambdaExp. -
getCaller
For an INLINE_ONLY function, return the function it gets inlined in. -
declareThis
-
declareClosureEnv
-
loadHeapFrame
Generate code to load heapFrame on the JVM stack. -
compileEnd
-
generateApplyMethods
-
compileSetField
-
compile
- Specified by:
compile
in classExpression
-
getHeapFrameType
-
getOwningLambda
-
allocChildClasses
-
pushChild
-
reverseChildList
public void reverseChildList() -
allocFrame
-
compileBody
-
visit
-
visitChildren
- Overrides:
visitChildren
in classExpression
-
visitChildrenOnly
-
visitProperties
-
mustCompile
protected boolean mustCompile()- Specified by:
mustCompile
in classExpression
-
apply
Description copied from class:Expression
Evaluate the expression. This is named apply rather than eval so it is compatible with the full-tail-call calling convention, and we can stash an Expression in CallContext's proc field. FIXME - are we making use of this?- Overrides:
apply
in classExpression
- Throws:
Throwable
-
validateApply
Description copied from class:Expression
Apply inlining transformations on a given ApplyExp. Assumes the ApplyExp's function is this expression, or can be optimized to this expression.- Overrides:
validateApply
in classExpression
- Parameters:
exp
- an application whose function expression can be simplified to this expression.visitor
- the context for the current inlining passdecl
- if non-null, a Declaration bound to this expression.- Returns:
- an Expression equivalent to the passed-in exp.
-
print
public void print(gnu.kawa.io.OutPort out) - Specified by:
print
in classExpression
-
getExpClassName
-
side_effects
public boolean side_effects()Description copied from class:Expression
True if evaluating may have side-effects.- Overrides:
side_effects
in classExpression
-
toString
-
getProperty
- Overrides:
getProperty
in classPropertySet
-
setProperty
- Overrides:
setProperty
in classPropertySet
-
getReturnType
The return type of this function, i.e the type of its returned values. -
setReturnType
-
setCoercedReturnType
-
maybeSetReturnType
-
setCoercedReturnValue
Modify LambdaExp so result is coerced to given type. -
getBodyFirstExpression
Get the first expression/statement in the body. It dives down intoBeginExp
s. Used to check forinvoke-special
calls in@init
methods. -
checkForInitCall
Check if argument is a this(...) or super(...) initializtion. If so, return return the corresponding this or super class.
-