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 intstatic final MethodHandlestatic final intstatic final StringIf non-null, this is a Field that is used for implementing lexical closures.protected static final intTrue if IS_SUPPLIED_PARAMETER is set on a parameter.protected static final intstatic final intIf this lambda gets inlined this is the containing lambda.Keyword[]intMaximum number of actual arguments; -1 if variable.intMinimum number of actual arguments.If non-null, a Declaration whose value is (only) this LambdaExp.protected static final intstatic final intintNumber of optional arguments, not counting keyword arguments.static final intstatic final intTreat as inlined in outer lambda when determining tailcalls.static final intTrue 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 intField in heapFrame.getType() that contains the static link.Fields inherited from class gnu.expr.Expression
applyMethodExpression, flags, noExpressions, type, VALIDATEDFields inherited from class gnu.mapping.Procedure
applyMethodType, applyToConsumerDefault, applyToConsumerMethod, applyToObjectDefault, applyToObjectMethod, compilerKey, compilerXKey, inlineIfConstantSymbol, validateApplyKey, validateXApplyKeyFields inherited from class gnu.mapping.PropertySet
nameKey -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddParameter(Object name) voidallocChildClasses(Compilation comp) voidallocFrame(Compilation comp) voidapply(CallContext ctx) Evaluate the expression.protected Typevoidcapture(Declaration decl) checkForInitCall(Expression bodyFirst) Check if argument is a this(...) or super(...) initializtion.voidcompile(Compilation comp, Target target) voidcompileBody(Compilation comp) voidcompileEnd(Compilation comp) compileSetField(Compilation comp) declareThis(ClassType clas) voidGet the first expression/statement in the body.intThe calling convention used for this function.For an INLINE_ONLY function, return the function it gets inlined in.final booleanThe ClassType generated for this class.protected ClassTypeReturn the ClassType of the Procedure this is being compiled into.protected final Stringfinal booleanTrue iff this lambda "captures" (uses) lexical variables from outside.final booleanTrue iff this lambda is only "called" inline.final MethodGet the method that contains the actual body of the procedure.final MethodgetMethod(int nonSpliceCount, int spliceCount) Select the method used given an argument count.final booleanfinal booleanTrue if a child lambda uses lexical variables from outside.getProperty(Object key, Object defaultValue) final TypeThe return type of this function, i.e the type of its returned values.intNumber of argument variable actually passed by the caller.booleanTrue if no primitive method is created for this procedure.final booleanbooleanfinal booleanTrue if this is a method in an ClassExp.final booleanfinal booleanTrue iff this is the dummy top-level function of a module body.booleanisNative()voidloadHeapFrame(Compilation comp) Generate code to load heapFrame on the JVM stack.static voidmaybeSetReturnType(LambdaExp lexp, Type type) protected booleanReturn the closest outer non-inlined LambdaExp.voidprint(gnu.kawa.io.OutPort out) voidfinal TypeReturn the parameter type of the "keyword/rest" parameters.voidvoidsetCallConvention(Compilation comp) final voidsetCanRead(boolean read) final voidsetClassMethod(boolean isMethod) final voidsetCoercedReturnType(Type returnType) final voidsetCoercedReturnValue(Expression type, Language language) Modify LambdaExp so result is coerced to given type.voidsetExceptions(Expression[] exceptions) final voidfinal voidsetImportsLexVars(boolean importsLexVars) final voidsetInlineOnly(boolean inlineOnly) final voidsetInlineOnly(Expression returnContinuation, LambdaExp caller) Note this function is inlined in a give context.final voidfinal voidsetNeedsStaticLink(boolean needsStaticLink) voidsetProperty(Object key, Object value) final voidsetReturnType(Type returnType) voidbooleanTrue if evaluating may have side-effects.toString()booleanvalidateApply(ApplyExp exp, InlineCalls visitor, Type required, Declaration decl) Apply inlining transformations on a given ApplyExp.final booleanprotected <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, topLevelMethods 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, valueIfConstantMethods 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, setSourceLocationMethods 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:
calculateTypein 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:
compilein classExpression
-
getHeapFrameType
-
getOwningLambda
-
allocChildClasses
-
pushChild
-
reverseChildList
public void reverseChildList() -
allocFrame
-
compileBody
-
visit
-
visitChildren
- Overrides:
visitChildrenin classExpression
-
visitChildrenOnly
-
visitProperties
-
mustCompile
protected boolean mustCompile()- Specified by:
mustCompilein classExpression
-
apply
Description copied from class:ExpressionEvaluate 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:
applyin classExpression- Throws:
Throwable
-
validateApply
Description copied from class:ExpressionApply inlining transformations on a given ApplyExp. Assumes the ApplyExp's function is this expression, or can be optimized to this expression.- Overrides:
validateApplyin 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:
printin classExpression
-
getExpClassName
-
side_effects
public boolean side_effects()Description copied from class:ExpressionTrue if evaluating may have side-effects.- Overrides:
side_effectsin classExpression
-
toString
-
getProperty
- Overrides:
getPropertyin classPropertySet
-
setProperty
- Overrides:
setPropertyin 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 intoBeginExps. Used to check forinvoke-specialcalls in@initmethods. -
checkForInitCall
Check if argument is a this(...) or super(...) initializtion. If so, return return the corresponding this or super class.
-