Package gnu.expr
Class Expression
java.lang.Object
gnu.mapping.PropertySet
gnu.mapping.Procedure
gnu.expr.Expression
- All Implemented Interfaces:
gnu.kawa.format.Printable,Named,SourceLocator,SourceLocator,Locator
- Direct Known Subclasses:
AccessExp,ApplyExp,BeginExp,BlockExp,CaseExp,ErrorExp,ExitExp,IfExp,LangExp,QuoteExp,ScopeExp,SynchronizedExp,TryExp
public abstract class Expression
extends Procedure
implements gnu.kawa.format.Printable, SourceLocator
Abstract class for syntactic forms that evaluate to a value.
Scheme S-expressions get re-written to these before evaluation.
-
Nested Class Summary
Nested classes/interfaces inherited from interface gnu.text.SourceLocator
SourceLocator.Simple -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MethodHandleprotected intprotected static final intstatic final Expression[]protected Typestatic final intFields inherited from class gnu.mapping.Procedure
applyMethodType, applyToConsumerDefault, applyToConsumerMethod, applyToObjectDefault, applyToObjectMethod, compilerKey, compilerXKey, inlineIfConstantSymbol, validateApplyKey, validateXApplyKeyFields inherited from class gnu.mapping.PropertySet
nameKey -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(CallContext ctx) Evaluate the expression.static ObjectapplyMethodExpression(Procedure proc, CallContext ctx) protected TypeIs this a keyword argument? In the future this will return non-null only for explicit literal non-quoted Keywords.final voidcompile(Compilation comp, Type type) final voidcompile(Compilation comp, Declaration lhs) Compile an expression with checking suitable for a known Declaration.abstract voidcompile(Compilation comp, Target target) final voidcompileWithPosition(Compilation comp, Target target) Same as compile, but emit line number beforehard.final voidcompileWithPosition(Compilation comp, Target target, Expression position) Same as 2-argument compileWithPosition, but use some other Expression's line number.protected static ExpressiondeepCopy(Expression exp) static Expression[]deepCopy(Expression[] exps, IdentityHashTable mapper) static ExpressiondeepCopy(Expression exp, IdentityHashTable mapper) Make a deep copy of this expression, if possible.protected ExpressiondeepCopy(IdentityHashTable mapper) final Objecteval(CallContext ctx) final Objecteval(Environment env) final intReturn current column number.final intColumn (one-origin) of end of range; unknown/unspecified is -1.final intLine number (one-origin) of end of range; unknown/unspecified is -1.final StringNormally same as getSystemId.booleangetFlag(int flag) intgetFlags()final intReturn current line number.final intColumn (one-origin) of start of range; unknown/unspecified is -1.final intLine number (one-origin) of start of range; unknown/unspecified is -1.final TypegetType()Return the Type used to represent the values of this Expression.final TypebooleanbooleanTrue if position is unlikely to change.static ExpressionmakeWhile(Object cond, Object body, Compilation parser) Helper method to create a `while' statement.final ExpressionmaybeSetLine(Expression old) protected abstract booleanbooleanTrue if the expression provably never returns.intnumArgs()ReturnminArgs()|(maxArgs<<12).abstract voidprint(gnu.kawa.io.OutPort ps) final voidvoidprintLineColumn(gnu.kawa.io.OutPort out) Print line and column number if specified.final voidvoidsetFlag(boolean setting, int flag) voidsetFlag(int flag) final voidsetLine(int lineno) final voidsetLine(int lineno, int colno) final voidsetLine(int startLine, int startColumn, int endLine, int endColumn) voidsetLine(Compilation comp) Set line number from current position inCompilation.final ExpressionsetLine(Expression old) final voidsetLocation(SourceLocator location) Copies the current location.voidbooleanTrue if evaluating may have side-effects.toString()validateApply(ApplyExp exp, InlineCalls visitor, Type required, Declaration decl) Apply inlining transformations on a given ApplyExp.Return value if it is constant, or null if non-constant or unknown.protected <R,D> R visit(ExpVisitor<R, D> visitor, D d) protected <R,D> void visitChildren(ExpVisitor<R, D> visitor, D d) 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, setSourceLocationMethods inherited from class gnu.mapping.PropertySet
getName, getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol
-
Field Details
-
applyMethodExpression
-
noExpressions
-
type
-
flags
protected int flags -
VALIDATED
public static final int VALIDATED- See Also:
-
NEXT_AVAIL_FLAG
protected static final int NEXT_AVAIL_FLAG- See Also:
-
-
Constructor Details
-
Expression
public Expression()
-
-
Method Details
-
applyMethodExpression
- Throws:
Throwable
-
eval
- Throws:
Throwable
-
eval
- Throws:
Throwable
-
mustCompile
protected abstract boolean mustCompile() -
numArgs
public int numArgs()Description copied from class:ProcedureReturnminArgs()|(maxArgs<<12). We use a single virtual function to reduce the number of methods in the system, as well as the number of virtual method table entries. We shift by 12 so the number can normally be represented using a sipush instruction, without requiring a constant pool entry. -
apply
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?- Throws:
Throwable
-
print
- Specified by:
printin interfacegnu.kawa.format.Printable
-
print
public abstract void print(gnu.kawa.io.OutPort ps) -
printLineColumn
public void printLineColumn(gnu.kawa.io.OutPort out) Print line and column number if specified. This is a helper routine intended for use by print(OutPort). -
compile
-
compileWithPosition
Same as compile, but emit line number beforehard. -
compileWithPosition
Same as 2-argument compileWithPosition, but use some other Expression's line number. -
compile
-
compile
Compile an expression with checking suitable for a known Declaration. Leaves the result on the stack (i.e. does not assign to the lhs). It does coerce the value to a suitable type for the lhs, and throw a hopefully-informative WrongType exception on failure. -
deepCopy
Make a deep copy of this expression, if possible.- Parameters:
mapper- used to lookup parts (expressions, declarations) that have been translated in the parent. Needed for copied Declarations and BlockExps.- Returns:
- a copy, or null if we can't copy.
-
deepCopy
-
deepCopy
-
deepCopy
-
visit
-
visitChildren
-
validateApply
Apply inlining transformations on a given ApplyExp. Assumes the ApplyExp's function is this expression, or can be optimized to this expression.- Parameters:
exp- an application whose function expression can be simplified to this expression.visitor- the context for the current inlining passdecl- if non-null, a Declaration bound to this expression.- Returns:
- an Expression equivalent to the passed-in exp.
-
makeWhile
Helper method to create a `while' statement. -
setLocation
Copies the current location. -
setLine
-
maybeSetLine
-
setFile
-
setLine
public final void setLine(int startLine, int startColumn, int endLine, int endColumn) -
setLine
public final void setLine(int lineno, int colno) -
setLine
public final void setLine(int lineno) -
getFileName
Description copied from interface:SourceLocatorNormally same as getSystemId.- Specified by:
getFileNamein interfaceSourceLocator
-
setLine
Set line number from current position inCompilation. -
getPublicId
- Specified by:
getPublicIdin interfaceLocator- Specified by:
getPublicIdin interfaceSourceLocator- Specified by:
getPublicIdin interfaceSourceLocator
-
getSystemId
- Specified by:
getSystemIdin interfaceLocator- Specified by:
getSystemIdin interfaceSourceLocator- Specified by:
getSystemIdin interfaceSourceLocator
-
getLineNumber
public final int getLineNumber()Description copied from interface:SourceLocatorReturn current line number. Normally the same asgetStartLine(). The "first" line is line 1; unknown is -1.- Specified by:
getLineNumberin interfaceLocator- Specified by:
getLineNumberin interfaceSourceLocator- Specified by:
getLineNumberin interfaceSourceLocator
-
getColumnNumber
public final int getColumnNumber()Description copied from interface:SourceLocatorReturn current column number. Normally the same asgetStartColumn(). The "first" column is column 1; unknown is -1.- Specified by:
getColumnNumberin interfaceLocator- Specified by:
getColumnNumberin interfaceSourceLocator- Specified by:
getColumnNumberin interfaceSourceLocator
-
getStartLine
public final int getStartLine()Description copied from interface:SourceLocatorLine number (one-origin) of start of range; unknown/unspecified is -1.- Specified by:
getStartLinein interfaceSourceLocator
-
getStartColumn
public final int getStartColumn()Description copied from interface:SourceLocatorColumn (one-origin) of start of range; unknown/unspecified is -1.- Specified by:
getStartColumnin interfaceSourceLocator
-
getEndLine
public final int getEndLine()Description copied from interface:SourceLocatorLine number (one-origin) of end of range; unknown/unspecified is -1.- Specified by:
getEndLinein interfaceSourceLocator
-
getEndColumn
public final int getEndColumn()Description copied from interface:SourceLocatorColumn (one-origin) of end of range; unknown/unspecified is -1.- Specified by:
getEndColumnin interfaceSourceLocator
-
isStableSourceLocation
public boolean isStableSourceLocation()Description copied from interface:SourceLocatorTrue if position is unlikely to change. True for an expression but not an input file.- Specified by:
isStableSourceLocationin interfaceSourceLocator
-
getType
Return the Type used to represent the values of this Expression. -
calculateType
-
getTypeRaw
-
setType
-
neverReturns
public boolean neverReturns()True if the expression provably never returns. Currently, this is very limited, not handling infinite recursion (tail- or otherwise), but better analysis is planned. -
checkLiteralKeyword
Is this a keyword argument? In the future this will return non-null only for explicit literal non-quoted Keywords. -
isSingleValue
public boolean isSingleValue() -
valueIfConstant
Return value if it is constant, or null if non-constant or unknown. -
setFlag
public void setFlag(boolean setting, int flag) -
setFlag
public void setFlag(int flag) -
getFlags
public int getFlags() -
getFlag
public boolean getFlag(int flag) -
side_effects
public boolean side_effects()True if evaluating may have side-effects. -
toString
-