gnu.expr

Class LambdaExp

public class LambdaExp extends ScopeExp

Class used to implement Scheme lambda expressions.
Field Summary
Expressionbody
FieldclosureEnvField
If non-null, this is a Field that is used for implementing lexical closures.
Expression[]defaultArgs
LambdaExpfirstChild
Keyword[]keywords
intmax_args
Maximum number of actual arguments; -1 if variable.
intmin_args
Minumnum number of parameters.
DeclarationnameDecl
If non-null, a Declaration whose value is (only) this LambdaExp.
LambdaExpnextSibling
protected static intNEXT_AVAIL_FLAG
static intNO_FIELD
static intOVERLOADABLE_FIELD
ApplyExpreturnContinuation
The unique caller that calls this lambda.
TypereturnType
If non-null, the type of values returned by this function.
FieldstaticLinkField
Field in heapFrame.getType() that contains the static link.
static intSEQUENCE_RESULT
Constructor Summary
LambdaExp()
LambdaExp(int args)
LambdaExp(Expression body)
Method Summary
voidallocChildClasses(Compilation comp)
voidallocFrame(Compilation comp)
voidapply(CallContext ctx)
voidcapture(Declaration decl)
voidcompile(Compilation comp, Target target)
voidcompileBody(Compilation comp)
voidcompileEnd(Compilation comp)
FieldcompileSetField(Compilation comp)
VariabledeclareClosureEnv()
VariabledeclareThis(ClassType clas)
voidgenerateApplyMethods(Compilation comp)
intgetCallConvention()
Specify the calling convention used for this function.
LambdaExpgetCaller()
For an INLINE_ONLY function, return the function it gets inlined in.
booleangetCanCall()
booleangetCanRead()
protected ClassTypegetCompiledClassType(Compilation comp)
Return the ClassType of the Procedure this is being compiled into.
protected StringgetExpClassName()
ClassTypegetHeapFrameType()
booleangetImportsLexVars()
True iff this lambda "captures" (uses) lexical variables from outside.
booleangetInlineOnly()
True iff this lambda is only "called" inline.
MethodgetMainMethod()
Get the method that contains the actual body of the procedure.
MethodgetMethod(int argCount)
Select the method used given an argument count.
booleangetNeedsClosureEnv()
booleangetNeedsStaticLink()
True if a child lambda uses lexical variables from outside.
LambdaExpgetOwningLambda()
ObjectgetProperty(Object key, Object defaultValue)
TypegetReturnType()
The return type of this function, i.e the type of its returned values.
TypegetType()
intincomingArgs()
Number of argument variable actually passed by the caller.
Expressioninline(ApplyExp exp, InlineCalls walker, Declaration decl)
booleanisClassGenerated()
True if a class is generated for this procedure.
booleanisClassMethod()
True if this is a method in an ClassExp.
booleanisHandlingTailCalls()
booleanisModuleBody()
True iff this is the dummy top-level function of a module body.
voidloadHeapFrame(Compilation comp)
Generate code to load heapFrame on the JVM stack.
protected booleanmustCompile()
LambdaExpouterLambda()
LambdaExpouterLambdaNotInline()
Return the closest outer non-inlined LambdaExp.
voidprint(OutPort out)
TyperestArgType()
Return the parameter type of the "keyword/rest" parameters.
voidsetCanCall(boolean called)
voidsetCanRead(boolean read)
voidsetClassMethod(boolean isMethod)
voidsetExceptions(ReferenceExp[] exceptions)
voidsetImportsLexVars(boolean importsLexVars)
voidsetImportsLexVars()
voidsetInlineOnly(boolean inlineOnly)
voidsetNeedsStaticLink(boolean needsStaticLink)
voidsetNeedsStaticLink()
voidsetProperty(Object key, Object value)
voidsetReturnType(Type returnType)
voidsetType(ClassType type)
StringtoString()
booleanvariable_args()
protected Expressionwalk(ExpWalker walker)
protected voidwalkChildren(ExpWalker walker)
protected voidwalkChildrenOnly(ExpWalker walker)
protected voidwalkProperties(ExpWalker walker)

Field Detail

body

public Expression body

closureEnvField

public Field closureEnvField
If non-null, this is a Field that is used for implementing lexical closures. If getName() is "closureEnv", it is our parent's heapFrame, which is an instance of one of our siblings. (Otherwise, we use "this" as the implicit "closureEnv" field.)

defaultArgs

public Expression[] defaultArgs

firstChild

public LambdaExp firstChild

keywords

public Keyword[] keywords

max_args

public int max_args
Maximum number of actual arguments; -1 if variable.

min_args

public int min_args
Minumnum number of parameters. Does not count implicit isThisParameter().

nameDecl

public Declaration nameDecl
If non-null, a Declaration whose value is (only) this LambdaExp.

nextSibling

public LambdaExp nextSibling

NEXT_AVAIL_FLAG

protected static final int NEXT_AVAIL_FLAG

NO_FIELD

public static final int NO_FIELD

OVERLOADABLE_FIELD

public static final int OVERLOADABLE_FIELD

returnContinuation

public ApplyExp returnContinuation
The unique caller 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. (With a little more analysis, we could also allow multiple non-self tail-calls as long as they all are ultimately called from the same place.) This is used to see if we can inline the function at its unique call site.

returnType

public Type returnType
If non-null, the type of values returned by this function. If null, the return type has not been set or calculated yet.

staticLinkField

public 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.

SEQUENCE_RESULT

public static final int SEQUENCE_RESULT

Constructor Detail

LambdaExp

public LambdaExp()

LambdaExp

public LambdaExp(int args)

LambdaExp

public LambdaExp(Expression body)

Method Detail

allocChildClasses

public void allocChildClasses(Compilation comp)

allocFrame

public void allocFrame(Compilation comp)

apply

public void apply(CallContext ctx)

capture

public void capture(Declaration decl)

compile

public void compile(Compilation comp, Target target)

compileBody

public void compileBody(Compilation comp)

compileEnd

public void compileEnd(Compilation comp)

compileSetField

public Field compileSetField(Compilation comp)

declareClosureEnv

public Variable declareClosureEnv()

declareThis

public Variable declareThis(ClassType clas)

generateApplyMethods

public void generateApplyMethods(Compilation comp)

getCallConvention

public int getCallConvention()
Specify the calling convention used for this function.

Returns: One of the CALL_WITH_xxx values in Compilation.

getCaller

public LambdaExp getCaller()
For an INLINE_ONLY function, return the function it gets inlined in.

getCanCall

public final boolean getCanCall()

getCanRead

public final boolean getCanRead()

getCompiledClassType

protected ClassType getCompiledClassType(Compilation comp)
Return the ClassType of the Procedure this is being compiled into.

getExpClassName

protected final String getExpClassName()

getHeapFrameType

public ClassType getHeapFrameType()

getImportsLexVars

public final boolean getImportsLexVars()
True iff this lambda "captures" (uses) lexical variables from outside.

getInlineOnly

public final boolean getInlineOnly()
True iff this lambda is only "called" inline.

getMainMethod

public final Method getMainMethod()
Get the method that contains the actual body of the procedure. (The other methods are just stubs that call that method.)

getMethod

public final Method getMethod(int argCount)
Select the method used given an argument count.

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.

getOwningLambda

public LambdaExp getOwningLambda()

getProperty

public Object getProperty(Object key, Object defaultValue)

getReturnType

public final Type getReturnType()
The return type of this function, i.e the type of its returned values.

getType

public Type getType()

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.

inline

public Expression inline(ApplyExp exp, InlineCalls walker, Declaration decl)

isClassGenerated

public final boolean isClassGenerated()
True if a class is generated for this procedure.

isClassMethod

public final boolean isClassMethod()
True if this is a method in an ClassExp.

isHandlingTailCalls

public final boolean isHandlingTailCalls()

isModuleBody

public final boolean isModuleBody()
True iff this is the dummy top-level function of a module body.

loadHeapFrame

public void loadHeapFrame(Compilation comp)
Generate code to load heapFrame on the JVM stack.

mustCompile

protected boolean mustCompile()

outerLambda

public LambdaExp outerLambda()

outerLambdaNotInline

public LambdaExp outerLambdaNotInline()
Return the closest outer non-inlined LambdaExp.

print

public void print(OutPort out)

restArgType

public final Type restArgType()
Return the parameter type of the "keyword/rest" parameters.

setCanCall

public final void setCanCall(boolean called)

setCanRead

public final void setCanRead(boolean read)

setClassMethod

public final void setClassMethod(boolean isMethod)

setExceptions

public void setExceptions(ReferenceExp[] exceptions)

setImportsLexVars

public final void setImportsLexVars(boolean importsLexVars)

setImportsLexVars

public final void setImportsLexVars()

setInlineOnly

public final void setInlineOnly(boolean inlineOnly)

setNeedsStaticLink

public final void setNeedsStaticLink(boolean needsStaticLink)

setNeedsStaticLink

public final void setNeedsStaticLink()

setProperty

public void setProperty(Object key, Object value)

setReturnType

public final void setReturnType(Type returnType)

setType

public void setType(ClassType type)

toString

public String toString()

variable_args

public final boolean variable_args()

walk

protected Expression walk(ExpWalker walker)

walkChildren

protected void walkChildren(ExpWalker walker)

walkChildrenOnly

protected final void walkChildrenOnly(ExpWalker walker)

walkProperties

protected final void walkProperties(ExpWalker walker)