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 intfirstKeywordArgIndexIndex of argument for first keyword argument.intfirstSpliceArgIndex of first argument that is a MakeSplice.static intINLINE_IF_CONSTANTstatic intIS_SUPER_INITstatic intMAY_CONTAIN_BACK_JUMPApplyExpnextCallThe next ApplyExp in ((ReferenceExp)func).binding.firstCall list.intnumKeywordArgsstatic intTAILCALL-
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 voidadjustSplice(ApplyExp src, int delta)Copy over splice and keyword start indexes.voidapply(CallContext ctx)Evaluate the expression.protected TypecalculateType()static voidcompile(ApplyExp exp, Compilation comp, Target target)voidcompile(Compilation comp, Target target)static voidcompileArgsToContext(ApplyExp exp, Method setupMethod, Compilation comp)ExpressiondeepCopy(IdentityHashTable mapper)ExpressiongetArg(int i)intgetArgCount()Expression[]getArgs()ExpressiongetFunction()ObjectgetFunctionValue()If getFunction() is constant, return its value; otherwise null.booleanhasSpliceAllowingKeywords()ExpressioninlineIfConstant(Procedure proc, InlineCalls visitor)ExpressioninlineIfConstant(Procedure proc, SourceMessages messages)Inline this ApplyExp if parameters are constant.booleanisAppendValues()static booleanisInlineable(Procedure proc)booleanisSimple()booleanisSimple(int min)booleanisSimple(int min, int max)booleanisTailCall()protected booleanmustCompile()voidprint(gnu.kawa.io.OutPort out)voidsetArg(int i, Expression arg)voidsetArgs(Expression[] args)ApplyExpsetFuncArgs(Expression func, Expression[] args)ApplyExpsetFuncArgs(Procedure proc, Expression[] args)voidsetFunction(Expression func)voidsetFunction(Procedure proc)voidsetTailCall(boolean tailCall)booleanside_effects()True if evaluating may have side-effects.intspliceCount()StringtoString()protected <R,D>
Rvisit(ExpVisitor<R,D> visitor, D d)voidvisitArgs(InlineCalls visitor)voidvisitArgs(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-1is the index in theargsarray 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:
mustCompilein classExpression
-
apply
public void apply(CallContext ctx) throws Throwable
Description copied from class:ExpressionEvaluate 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:
applyin classExpression- Throws:
Throwable
-
compile
public void compile(Compilation comp, Target target)
- Specified by:
compilein 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:
deepCopyin classExpression
-
visit
protected <R,D> R visit(ExpVisitor<R,D> visitor, D d)
- Overrides:
visitin 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:
visitChildrenin classExpression
-
print
public void print(gnu.kawa.io.OutPort out)
- Specified by:
printin classExpression
-
side_effects
public boolean side_effects()
Description copied from class:ExpressionTrue if evaluating may have side-effects.- Overrides:
side_effectsin classExpression
-
calculateType
protected Type calculateType()
- Overrides:
calculateTypein 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:
toStringin classExpression
-
-