gnu.expr
Class LambdaExp

java.lang.Object
  extended by gnu.mapping.PropertySet
      extended by gnu.mapping.Procedure
          extended by gnu.mapping.Procedure0
              extended by gnu.expr.Expression
                  extended by gnu.expr.ScopeExp
                      extended by gnu.expr.LambdaExp
All Implemented Interfaces:
Named, Printable, SourceLocator, org.xml.sax.Locator
Direct Known Subclasses:
ClassExp, ModuleExp

public class LambdaExp
extends ScopeExp

Class used to implement Scheme lambda expressions.


Field Summary
 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.
protected static int NEXT_AVAIL_FLAG
           
 LambdaExp nextSibling
           
static int NO_FIELD
           
static int OVERLOADABLE_FIELD
           
 ApplyExp returnContinuation
          The unique caller that calls this lambda.
 Type returnType
          If non-null, the type of values returned by this function.
static int SEQUENCE_RESULT
           
 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
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  java.lang.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()
           
 java.lang.Object getProperty(java.lang.Object key, java.lang.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(java.lang.Object key, java.lang.Object value)
           
 void setReturnType(Type returnType)
           
 void setType(ClassType type)
           
 java.lang.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
 
Methods inherited from class gnu.expr.Expression
apply0, compile, compile, compileButFirst, compileNotePosition, compileWithPosition, compileWithPosition, eval, eval, getColumnNumber, getFileName, getFlag, getFlags, getLineNumber, getPublicId, getSystemId, isStableSourceLocation, makeWhile, match0, print, printLineColumn, setFile, setFlag, setFlag, setLine, setLine, setLine, setLine, setLocation, side_effects, valueIfConstant
 
Methods inherited from class gnu.mapping.Procedure0
apply1, apply2, apply3, apply4, applyN, numArgs
 
Methods inherited from class gnu.mapping.Procedure
apply, check0, check1, check2, check3, check4, checkArgCount, checkN, getSetter, getSourceLocation, match1, match2, match3, match4, matchN, maxArgs, minArgs, set0, set1, setN, setSetter, setSourceLocation
 
Methods inherited from class gnu.mapping.PropertySet
getName, getSymbol, removeProperty, setName, setProperty, setSymbol
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

body

public Expression body

min_args

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


max_args

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


keywords

public Keyword[] keywords

defaultArgs

public Expression[] defaultArgs

firstChild

public LambdaExp firstChild

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.


nameDecl

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


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


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.


NO_FIELD

public static final int NO_FIELD
See Also:
Constant Field Values

SEQUENCE_RESULT

public static final int SEQUENCE_RESULT
See Also:
Constant Field Values

OVERLOADABLE_FIELD

public static final int OVERLOADABLE_FIELD
See Also:
Constant Field Values

NEXT_AVAIL_FLAG

protected static final int NEXT_AVAIL_FLAG
See Also:
Constant Field Values

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.

Constructor Detail

LambdaExp

public LambdaExp()

LambdaExp

public LambdaExp(int args)

LambdaExp

public LambdaExp(Expression body)
Method Detail

capture

public void capture(Declaration decl)

setExceptions

public void setExceptions(ReferenceExp[] exceptions)

getInlineOnly

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


setInlineOnly

public final void setInlineOnly(boolean inlineOnly)

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)

getCanCall

public final boolean getCanCall()

setCanCall

public final void setCanCall(boolean called)

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.


isClassGenerated

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


getCallConvention

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

Returns:
One of the CALL_WITH_xxx values in Compilation.

isHandlingTailCalls

public final boolean isHandlingTailCalls()

variable_args

public final boolean variable_args()

getCompiledClassType

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


getType

public Type getType()
Description copied from class: Expression
Return the Type used to represent the values of this Expression.

Overrides:
getType in class Expression

setType

public void setType(ClassType type)

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

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


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


restArgType

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


outerLambda

public LambdaExp outerLambda()

outerLambdaNotInline

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


getCaller

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


declareThis

public Variable declareThis(ClassType clas)

declareClosureEnv

public Variable declareClosureEnv()

loadHeapFrame

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


compileEnd

public void compileEnd(Compilation comp)

generateApplyMethods

public void generateApplyMethods(Compilation comp)

compileSetField

public Field compileSetField(Compilation comp)

compile

public void compile(Compilation comp,
                    Target target)
Specified by:
compile in class Expression

getHeapFrameType

public ClassType getHeapFrameType()

getOwningLambda

public LambdaExp getOwningLambda()

allocChildClasses

public void allocChildClasses(Compilation comp)

allocFrame

public void allocFrame(Compilation comp)

compileBody

public void compileBody(Compilation comp)

walk

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

walkChildren

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

walkChildrenOnly

protected final void walkChildrenOnly(ExpWalker walker)

walkProperties

protected final void walkProperties(ExpWalker walker)

mustCompile

protected boolean mustCompile()
Specified by:
mustCompile in class Expression

apply

public void apply(CallContext ctx)
           throws java.lang.Throwable
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 class Expression
Throws:
java.lang.Throwable

inline

public Expression inline(ApplyExp exp,
                         InlineCalls walker,
                         Declaration decl)
Description copied from class: Expression
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 class 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.

print

public void print(OutPort out)
Specified by:
print in class Expression

getExpClassName

protected final java.lang.String getExpClassName()

toString

public java.lang.String toString()
Overrides:
toString in class ScopeExp

getProperty

public java.lang.Object getProperty(java.lang.Object key,
                                    java.lang.Object defaultValue)
Overrides:
getProperty in class PropertySet

setProperty

public void setProperty(java.lang.Object key,
                        java.lang.Object value)
Overrides:
setProperty in class PropertySet

getReturnType

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


setReturnType

public final void setReturnType(Type returnType)