Package gnu.expr
Class ApplyExp
- java.lang.Object
-
- gnu.mapping.PropertySet
-
- gnu.mapping.Procedure
-
- gnu.expr.Expression
-
- gnu.expr.ApplyExp
-
- All Implemented Interfaces:
gnu.kawa.format.Printable
,Named
,SourceLocator
,SourceLocator
,Locator
- Direct Known Subclasses:
CurryExp
public class ApplyExp extends Expression
This class is used to represent "combination" or "application". A function and arguments are evaluated, and then the function applied.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface gnu.text.SourceLocator
SourceLocator.Simple
-
-
Field Summary
Fields Modifier and Type Field Description int
firstKeywordArgIndex
Index of argument for first keyword argument.int
firstSpliceArg
Index of first argument that is a MakeSplice.static int
INLINE_IF_CONSTANT
static int
IS_SUPER_INIT
static int
MAY_CONTAIN_BACK_JUMP
ApplyExp
nextCall
The next ApplyExp in ((ReferenceExp)func).binding.firstCall list.int
numKeywordArgs
static int
TAILCALL
-
Fields inherited from class gnu.expr.Expression
applyMethodExpression, flags, NEXT_AVAIL_FLAG, noExpressions, type, VALIDATED
-
Fields inherited from class gnu.mapping.Procedure
applyMethodType, applyToConsumerDefault, applyToConsumerMethod, applyToObjectDefault, applyToObjectMethod, compilerKey, compilerXKey, inlineIfConstantSymbol, validateApplyKey, validateXApplyKey
-
Fields inherited from class gnu.mapping.PropertySet
nameKey
-
-
Constructor Summary
Constructors Constructor Description ApplyExp(Method m, Expression... a)
ApplyExp(Expression f, Expression... a)
ApplyExp(Procedure p, Expression... a)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
adjustSplice(ApplyExp src, int delta)
Copy over splice and keyword start indexes.void
apply(CallContext ctx)
Evaluate the expression.protected Type
calculateType()
static void
compile(ApplyExp exp, Compilation comp, Target target)
void
compile(Compilation comp, Target target)
static void
compileArgsToContext(ApplyExp exp, Method setupMethod, Compilation comp)
Expression
deepCopy(IdentityHashTable mapper)
Expression
getArg(int i)
int
getArgCount()
Expression[]
getArgs()
Expression
getFunction()
Object
getFunctionValue()
If getFunction() is constant, return its value; otherwise null.boolean
hasSpliceAllowingKeywords()
Expression
inlineIfConstant(Procedure proc, InlineCalls visitor)
Expression
inlineIfConstant(Procedure proc, SourceMessages messages)
Inline this ApplyExp if parameters are constant.boolean
isAppendValues()
static boolean
isInlineable(Procedure proc)
boolean
isSimple()
boolean
isSimple(int min)
boolean
isSimple(int min, int max)
boolean
isTailCall()
protected boolean
mustCompile()
void
print(gnu.kawa.io.OutPort out)
void
setArg(int i, Expression arg)
void
setArgs(Expression[] args)
ApplyExp
setFuncArgs(Expression func, Expression[] args)
ApplyExp
setFuncArgs(Procedure proc, Expression[] args)
void
setFunction(Expression func)
void
setFunction(Procedure proc)
void
setTailCall(boolean tailCall)
boolean
side_effects()
True if evaluating may have side-effects.int
spliceCount()
String
toString()
protected <R,D>
Rvisit(ExpVisitor<R,D> visitor, D d)
void
visitArgs(InlineCalls visitor)
void
visitArgs(InlineCalls visitor, LambdaExp lexp)
protected <R,D>
voidvisitChildren(ExpVisitor<R,D> visitor, D d)
-
Methods inherited from class gnu.expr.Expression
applyMethodExpression, checkLiteralKeyword, compile, compile, compileWithPosition, compileWithPosition, 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, validateApply, valueIfConstant
-
Methods 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, setSourceLocation
-
Methods inherited from class gnu.mapping.PropertySet
getName, getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol
-
-
-
-
Field Detail
-
TAILCALL
public static final int TAILCALL
- See Also:
- Constant Field Values
-
INLINE_IF_CONSTANT
public static final int INLINE_IF_CONSTANT
- See Also:
- Constant Field Values
-
MAY_CONTAIN_BACK_JUMP
public static final int MAY_CONTAIN_BACK_JUMP
- See Also:
- Constant Field Values
-
IS_SUPER_INIT
public static final int IS_SUPER_INIT
- See Also:
- Constant Field Values
-
nextCall
public ApplyExp nextCall
The next ApplyExp in ((ReferenceExp)func).binding.firstCall list.
-
firstKeywordArgIndex
public int firstKeywordArgIndex
Index of argument for first keyword argument. If zero, no keyword arguments. If non-zero, thenfirstKeywordArgIndex-1
is the index in theargs
array of the first keyword.
-
numKeywordArgs
public int numKeywordArgs
-
firstSpliceArg
public int firstSpliceArg
Index of first argument that is a MakeSplice. The value is -1 is no argument is a splice.
-
-
Constructor Detail
-
ApplyExp
public ApplyExp(Expression f, Expression... a)
-
ApplyExp
public ApplyExp(Procedure p, Expression... a)
-
ApplyExp
public ApplyExp(Method m, Expression... a)
-
-
Method Detail
-
getFunction
public final Expression getFunction()
-
getArgs
public final Expression[] getArgs()
-
getArgCount
public final int getArgCount()
-
setFunction
public void setFunction(Expression func)
-
setFunction
public void setFunction(Procedure proc)
-
setArgs
public void setArgs(Expression[] args)
-
getArg
public Expression getArg(int i)
-
setArg
public void setArg(int i, Expression arg)
-
isTailCall
public final boolean isTailCall()
-
setTailCall
public final void setTailCall(boolean tailCall)
-
setFuncArgs
public ApplyExp setFuncArgs(Expression func, Expression[] args)
-
setFuncArgs
public ApplyExp setFuncArgs(Procedure proc, Expression[] args)
-
getFunctionValue
public final Object getFunctionValue()
If getFunction() is constant, return its value; otherwise null.
-
adjustSplice
public void adjustSplice(ApplyExp src, int delta)
Copy over splice and keyword start indexes.- Parameters:
src
- orginal ApplyExp (may be the same as this)delta
- amount to adjust indexes by
-
spliceCount
public int spliceCount()
-
isSimple
public boolean isSimple()
-
isSimple
public boolean isSimple(int min)
-
isSimple
public boolean isSimple(int min, int max)
-
hasSpliceAllowingKeywords
public boolean hasSpliceAllowingKeywords()
-
isAppendValues
public boolean isAppendValues()
-
mustCompile
protected boolean mustCompile()
- Specified by:
mustCompile
in classExpression
-
apply
public void apply(CallContext ctx) throws 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 classExpression
- Throws:
Throwable
-
compile
public void compile(Compilation comp, Target target)
- Specified by:
compile
in classExpression
-
compile
public static void compile(ApplyExp exp, Compilation comp, Target target)
-
compileArgsToContext
public static void compileArgsToContext(ApplyExp exp, Method setupMethod, Compilation comp)
-
deepCopy
public Expression deepCopy(IdentityHashTable mapper)
- Overrides:
deepCopy
in classExpression
-
visit
protected <R,D> R visit(ExpVisitor<R,D> visitor, D d)
- Overrides:
visit
in classExpression
-
visitArgs
public void visitArgs(InlineCalls visitor)
-
visitArgs
public void visitArgs(InlineCalls visitor, LambdaExp lexp)
-
visitChildren
protected <R,D> void visitChildren(ExpVisitor<R,D> visitor, D d)
- Overrides:
visitChildren
in classExpression
-
print
public void print(gnu.kawa.io.OutPort out)
- Specified by:
print
in classExpression
-
side_effects
public boolean side_effects()
Description copied from class:Expression
True if evaluating may have side-effects.- Overrides:
side_effects
in classExpression
-
calculateType
protected Type calculateType()
- Overrides:
calculateType
in classExpression
-
isInlineable
public static boolean isInlineable(Procedure proc)
-
inlineIfConstant
public final Expression inlineIfConstant(Procedure proc, InlineCalls visitor)
-
inlineIfConstant
public final Expression inlineIfConstant(Procedure proc, SourceMessages messages)
Inline this ApplyExp if parameters are constant.- Parameters:
proc
- the procedure bound to this.func.- Returns:
- the constant result (as a QuoteExp) if inlining was possible; otherwise this ApplyExp. If applying proc throws an exception, print a warning on walker.messages.
-
toString
public String toString()
- Overrides:
toString
in classExpression
-
-