gnu.expr
Class LambdaExp

java.lang.Object
  |
  +--gnu.expr.Expression
        |
        +--gnu.expr.ScopeExp
              |
              +--gnu.expr.LambdaExp
Direct Known Subclasses:
ModuleExp, ObjectExp

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
           
static int dumpZipCounter
           
static java.lang.String dumpZipPrefix
          Used to control with .zip files dumps are generated.
static java.lang.String fileFunctionName
          The name to give to a dummy implicit function that surrounds a file.
 LambdaExp firstChild
           
protected  int flags
           
 Keyword[] keywords
           
 int max_args
           
 int min_args
           
 java.lang.String name
           
 LambdaExp nextSibling
           
 Field staticLinkField
          Field in heapFrame.getType() that contains the static link.
 
Fields inherited from class gnu.expr.ScopeExp
outer
 
Constructor Summary
LambdaExp()
           
LambdaExp(Expression body)
           
 
Method Summary
 void allocChildClasses(Compilation comp)
           
 void allocFrame(Compilation comp)
           
 ClassType compile(Compilation comp)
           
 void compile(Compilation comp, Target target)
           
 ClassType compileAlloc(Compilation comp)
           
 void compileEnd(Compilation comp)
           
 Field compileSetField(Compilation comp)
           
 Variable declareClosureEnv()
           
 Variable declareThis(ClassType clas)
           
 java.lang.Object eval(Environment env)
           
 java.lang.Class evalToClass()
           
 LambdaExp getCaller()
          For an INLINE_ONLY function, return the function it gets inlined in.
 boolean getCanCall()
           
 boolean getCanRead()
           
 ClassType getCompiledClassType(Compilation comp)
          Return the ClassType of the Procedure this is being compiled into.
 int getFlags()
           
 boolean getImportsLexVars()
          True iff this lambda "captures" (uses) lexical variables from outside.
 boolean getInlineOnly()
          True iff this lambda is only "called" inline.
 java.lang.String getJavaName()
           
 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.
 java.lang.String getName()
           
 boolean getNeedsClosureEnv()
           
 boolean getNeedsStaticLink()
          True if a child lambda uses lexical variables from outside.
 Type getType()
          Return the Type used to represent the values of this Expression.
 int incomingArgs()
          Number of argument variable actually passed by the caller.
 boolean isClassGenerated()
          True if a class is generated for this procedure.
 boolean isClassMethod()
          True if this is a method in an ObjectExp.
 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.
 LambdaExp outerLambda()
           
 LambdaExp outerLambdaNotInline()
          Return the closest outer non-inlined LambdaExp.
 void print(java.io.PrintWriter ps)
           
 Type restArgType()
          Return the parameter type of the "keyword/rest" parameters.
 void setCanCall(boolean called)
           
 void setCanRead(boolean read)
           
 void setClassMethod(boolean isMethod)
           
 void setImportsLexVars()
           
 void setImportsLexVars(boolean importsLexVars)
           
 void setInlineOnly(boolean inlineOnly)
           
 void setName(java.lang.String name)
           
 void setNeedsStaticLink()
           
 void setNeedsStaticLink(boolean needsStaticLink)
           
 java.lang.String toString()
           
 boolean variable_args()
           
 
Methods inherited from class gnu.expr.ScopeExp
add, addDeclaration, addDeclaration, addDeclaration, countDecls, currentLambda, firstDecl, lookup
 
Methods inherited from class gnu.expr.Expression
compile, compileNotePosition, compileWithPosition, getColumn, getFile, getLine, setFile, setLine, setLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name

body

public Expression body

min_args

public int min_args

max_args

public int max_args

keywords

public Keyword[] keywords

defaultArgs

public Expression[] defaultArgs

firstChild

public LambdaExp firstChild

nextSibling

public LambdaExp nextSibling

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.

flags

protected int flags

fileFunctionName

public static java.lang.String fileFunctionName
The name to give to a dummy implicit function that surrounds a file.

dumpZipPrefix

public static java.lang.String dumpZipPrefix
Used to control with .zip files dumps are generated.

dumpZipCounter

public static int dumpZipCounter
Constructor Detail

LambdaExp

public LambdaExp()

LambdaExp

public LambdaExp(Expression body)
Method Detail

getFlags

public int getFlags()

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

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. We don't need a class if this is only called inline. We also don't need a class if all callers are known, and we can invoke a method for this procedure. However, the last optimization is not available when using tail calls.

isHandlingTailCalls

public final boolean isHandlingTailCalls()

variable_args

public final boolean variable_args()

getCompiledClassType

public 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

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.

setName

public void setName(java.lang.String name)

getName

public java.lang.String getName()

getJavaName

public java.lang.String getJavaName()

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.

compile

public ClassType compile(Compilation comp)

compileAlloc

public ClassType compileAlloc(Compilation comp)

compileEnd

public void compileEnd(Compilation comp)

compileSetField

public Field compileSetField(Compilation comp)

compile

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

allocChildClasses

public void allocChildClasses(Compilation comp)

allocFrame

public void allocFrame(Compilation comp)

evalToClass

public java.lang.Class evalToClass()

eval

public java.lang.Object eval(Environment env)
Overrides:
eval in class Expression

print

public void print(java.io.PrintWriter ps)
Overrides:
print in class Expression

toString

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