gnu.expr

Class LambdaExp

Implemented Interfaces:
org.xml.sax.Locator, Named, Printable, SourceLocator
Known Direct Subclasses:
ClassExp, ModuleExp

public class LambdaExp
extends ScopeExp

Class used to implement Scheme lambda expressions.

Field Summary

protected static int
NEXT_AVAIL_FLAG
static int
NO_FIELD
static int
OVERLOADABLE_FIELD
static int
SEQUENCE_RESULT
Expression
body
Field
closureEnvField
If non-null, this is a Field that is used for implementing lexical closures.
Expression[]
defaultArgs
LambdaExp
firstChild
Keyword[]
keywords
int
max_args
Maximum number of actual arguments; -1 if variable.
int
min_args
Minumnum number of parameters.
Declaration
nameDecl
If non-null, a Declaration whose value is (only) this LambdaExp.
LambdaExp
nextSibling
ApplyExp
returnContinuation
The unique caller that calls this lambda.
Type
returnType
If non-null, the type of values returned by this function.
Field
staticLinkField
Field in heapFrame.getType() that contains the static link.

Fields inherited from class gnu.expr.ScopeExp

frameSize, id, outer

Fields inherited from class gnu.expr.Expression

NEXT_AVAIL_FLAG, flags, noExpressions

Constructor Summary

LambdaExp()
LambdaExp(Expression body)
LambdaExp(int args)

Method Summary

void
allocChildClasses(Compilation comp)
void
allocFrame(Compilation comp)
void
apply(CallContext ctx)
Evaluate the expression.
void
capture(Declaration decl)
void
compile(Compilation comp, Target target)
void
compileBody(Compilation comp)
void
compileEnd(Compilation comp)
Field
compileSetField(Compilation comp)
Variable
declareClosureEnv()
Variable
declareThis(ClassType clas)
void
generateApplyMethods(Compilation comp)
int
getCallConvention()
Specify the calling convention used for this function.
LambdaExp
getCaller()
For an INLINE_ONLY function, return the function it gets inlined in.
boolean
getCanCall()
boolean
getCanRead()
protected ClassType
getCompiledClassType(Compilation comp)
Return the ClassType of the Procedure this is being compiled into.
protected String
getExpClassName()
ClassType
getHeapFrameType()
boolean
getImportsLexVars()
True iff this lambda "captures" (uses) lexical variables from outside.
boolean
getInlineOnly()
True iff this lambda is only "called" inline.
Method
getMainMethod()
Get the method that contains the actual body of the procedure.
Method
getMethod(int argCount)
Select the method used given an argument count.
boolean
getNeedsClosureEnv()
boolean
getNeedsStaticLink()
True if a child lambda uses lexical variables from outside.
LambdaExp
getOwningLambda()
Object
getProperty(Object key, Object defaultValue)
Type
getReturnType()
The return type of this function, i.e the type of its returned values.
Type
getType()
Return the Type used to represent the values of this Expression.
int
incomingArgs()
Number of argument variable actually passed by the caller.
Expression
inline(ApplyExp exp, InlineCalls walker, Declaration decl)
Apply inlining transformations on a given ApplyExp.
boolean
isClassGenerated()
True if a class is generated for this procedure.
boolean
isClassMethod()
True if this is a method in an ClassExp.
boolean
isHandlingTailCalls()
boolean
isModuleBody()
True iff this is the dummy top-level function of a module body.
void
loadHeapFrame(Compilation comp)
Generate code to load heapFrame on the JVM stack.
protected boolean
mustCompile()
LambdaExp
outerLambda()
LambdaExp
outerLambdaNotInline()
Return the closest outer non-inlined LambdaExp.
void
print(OutPort out)
Type
restArgType()
Return the parameter type of the "keyword/rest" parameters.
void
setCanCall(boolean called)
void
setCanRead(boolean read)
void
setClassMethod(boolean isMethod)
void
setExceptions(ReferenceExp[] exceptions)
void
setImportsLexVars()
void
setImportsLexVars(boolean importsLexVars)
void
setInlineOnly(boolean inlineOnly)
void
setNeedsStaticLink()
void
setNeedsStaticLink(boolean needsStaticLink)
void
setProperty(Object key, Object value)
void
setReturnType(Type returnType)
void
setType(ClassType type)
String
toString()
boolean
variable_args()
protected Expression
walk(ExpWalker walker)
protected void
walkChildren(ExpWalker walker)
protected void
walkChildrenOnly(ExpWalker walker)
protected void
walkProperties(ExpWalker walker)

Methods inherited from class gnu.expr.ScopeExp

add, add, addDeclaration, addDeclaration, addDeclaration, countDecls, currentLambda, currentModule, duplicateDeclarationError, firstDecl, getDefine, getNoDefine, getVarScope, lookup, lookup, nesting, popScope, remove, remove, replaceFollowing, setIndexes, toString, walk

Methods inherited from class gnu.expr.Expression

apply, apply0, compile, compile, compile, compileButFirst, compileNotePosition, compileWithPosition, compileWithPosition, eval, eval, getColumnNumber, getFileName, getFlag, getFlags, getLineNumber, getPublicId, getSystemId, getType, inline, isStableSourceLocation, makeWhile, match0, mustCompile, print, print, printLineColumn, setFile, setFlag, setFlag, setLine, setLine, setLine, setLine, setLocation, side_effects, toString, valueIfConstant, walk, walkChildren

Methods inherited from class gnu.mapping.Procedure0

apply0, apply1, apply2, apply3, apply4, applyN, numArgs

Methods inherited from class gnu.mapping.Procedure

apply, apply, apply0, apply1, apply2, apply3, apply4, applyN, check0, check1, check2, check3, check4, checkArgCount, checkN, getSetter, getSourceLocation, match0, match1, match2, match3, match4, matchN, maxArgs, minArgs, numArgs, set0, set1, setN, setSetter, setSourceLocation, toString

Methods inherited from class gnu.mapping.PropertySet

getName, getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol

Field Details

NEXT_AVAIL_FLAG

protected static final int NEXT_AVAIL_FLAG
Field Value:
4096

NO_FIELD

public static final int NO_FIELD
Field Value:
256

OVERLOADABLE_FIELD

public static final int OVERLOADABLE_FIELD
Field Value:
2048

SEQUENCE_RESULT

public static final int SEQUENCE_RESULT
Field Value:
1024

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

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.

Constructor Details

LambdaExp

public LambdaExp()

LambdaExp

public LambdaExp(Expression body)

LambdaExp

public LambdaExp(int args)

Method Details

allocChildClasses

public void allocChildClasses(Compilation comp)

allocFrame

public void allocFrame(Compilation comp)

apply

public void apply(CallContext ctx)
            throws Throwable
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 interface Expression

capture

public void capture(Declaration decl)

compile

public void compile(Compilation comp,
                    Target target)
Overrides:
compile in interface Expression

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)
Overrides:
getProperty in interface PropertySet

getReturnType

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

getType

public Type getType()
Return the Type used to represent the values of this Expression.
Overrides:
getType in interface Expression

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)
Apply inlining transformations on a given ApplyExp. Assumes the ApplyExp's function is the this expression, or can be optimized to this expression.
Overrides:
inline in interface Expression
Parameters:
exp - an application whose function expression can be simplified to this expression.
walker - the context for the current inlining pass
decl - if non-null, a Declaration bound to this expression
Returns:
an Expression equivalent to te passed-in exp.

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()
Overrides:
mustCompile in interface Expression

outerLambda

public LambdaExp outerLambda()

outerLambdaNotInline

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

print

public void print(OutPort out)
Overrides:
print in interface Expression

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()

setImportsLexVars

public final void setImportsLexVars(boolean importsLexVars)

setInlineOnly

public final void setInlineOnly(boolean inlineOnly)

setNeedsStaticLink

public final void setNeedsStaticLink()

setNeedsStaticLink

public final void setNeedsStaticLink(boolean needsStaticLink)

setProperty

public void setProperty(Object key,
                        Object value)
Overrides:
setProperty in interface PropertySet

setReturnType

public final void setReturnType(Type returnType)

setType

public void setType(ClassType type)

toString

public String toString()
Overrides:
toString in interface ScopeExp

variable_args

public final boolean variable_args()

walk

protected Expression walk(ExpWalker walker)
Overrides:
walk in interface ScopeExp

walkChildren

protected void walkChildren(ExpWalker walker)
Overrides:
walkChildren in interface Expression

walkChildrenOnly

protected final void walkChildrenOnly(ExpWalker walker)

walkProperties

protected final void walkProperties(ExpWalker walker)