gnu.expr

Class Expression

public abstract class Expression extends Procedure0 implements Printable, SourceLocator

Abstract class for syntactic forms that evaluate to a value. Scheme S-expressions get re-written to these before evaluation.
Field Summary
protected intflags
static Expression[]noExpressions
protected static intNEXT_AVAIL_FLAG
Method Summary
voidapply(CallContext ctx)
Evaluate the expression.
Objectapply0()
abstract voidcompile(Compilation comp, Target target)
voidcompile(Compilation comp, Type type)
voidcompile(Compilation comp, Declaration lhs)
Compile an expression with checking suitable for a known Declaration.
static voidcompileButFirst(Expression exp, Compilation comp)
Compile all but the first sub-"statement".
voidcompileNotePosition(Compilation comp, Target target, Expression position)
Compile, but take note of line number.
voidcompileWithPosition(Compilation comp, Target target)
Same as compile, but emit line number beforehard.
voidcompileWithPosition(Compilation comp, Target target, Expression position)
Same as 2-argument compileWithPosition, but use some other Expression's line number.
Objecteval(CallContext ctx)
Objecteval(Environment env)
intgetColumnNumber()
StringgetFileName()
booleangetFlag(int flag)
intgetFlags()
intgetLineNumber()
Get the line number of (the start of) this Expression.
StringgetPublicId()
StringgetSystemId()
TypegetType()
Return the Type used to represent the values of this Expression.
Expressioninline(ApplyExp exp, InlineCalls walker, Declaration decl)
Apply inlining transformations on a given ApplyExp.
booleanisStableSourceLocation()
static ExpressionmakeWhile(Object cond, Object body, Compilation parser)
Helper method to create a `while' statement.
intmatch0(CallContext ctx)
protected abstract booleanmustCompile()
voidprint(Consumer out)
abstract voidprint(OutPort ps)
voidprintLineColumn(OutPort out)
Print line and column number if specified.
voidsetFile(String filename)
voidsetFlag(boolean setting, int flag)
voidsetFlag(int flag)
ExpressionsetLine(Expression old)
voidsetLine(int lineno, int colno)
voidsetLine(int lineno)
voidsetLine(Compilation comp)
Set line number from current position in Compilation.
voidsetLocation(SourceLocator location)
Copies the current location.
booleanside_effects()
True if evaluating may have side-effects.
StringtoString()
ObjectvalueIfConstant()
Return value if it is constant, or null if non-constant or unknown.
protected Expressionwalk(ExpWalker walker)
protected voidwalkChildren(ExpWalker walker)

Field Detail

flags

protected int flags

noExpressions

public static final Expression[] noExpressions

NEXT_AVAIL_FLAG

protected static final int NEXT_AVAIL_FLAG

Method Detail

apply

public void apply(CallContext ctx)
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?

apply0

public final Object apply0()

compile

public abstract void compile(Compilation comp, Target target)

compile

public final void compile(Compilation comp, Type type)

compile

public final void compile(Compilation comp, Declaration lhs)
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.

compileButFirst

public static void compileButFirst(Expression exp, Compilation comp)
Compile all but the first sub-"statement". A kludge used for constructor methods, since if the first "statement" is a super-constructor we need to inject initializer expressions.

compileNotePosition

public final void compileNotePosition(Compilation comp, Target target, Expression position)
Compile, but take note of line number.

compileWithPosition

public final void compileWithPosition(Compilation comp, Target target)
Same as compile, but emit line number beforehard.

compileWithPosition

public final void compileWithPosition(Compilation comp, Target target, Expression position)
Same as 2-argument compileWithPosition, but use some other Expression's line number.

eval

public final Object eval(CallContext ctx)

eval

public final Object eval(Environment env)

getColumnNumber

public final int getColumnNumber()

getFileName

public final String getFileName()

getFlag

public boolean getFlag(int flag)

getFlags

public int getFlags()

getLineNumber

public final int getLineNumber()
Get the line number of (the start of) this Expression. The "first" line is line 1; unknown is -1.

getPublicId

public String getPublicId()

getSystemId

public String getSystemId()

getType

public Type getType()
Return the Type used to represent the values of this Expression.

inline

public Expression inline(ApplyExp exp, InlineCalls walker, Declaration decl)
Apply inlining transformations on a given ApplyExp. Assumes the ApplyExp's function is the this expression, or can be optimized to this 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.

isStableSourceLocation

public boolean isStableSourceLocation()

makeWhile

public static Expression makeWhile(Object cond, Object body, Compilation parser)
Helper method to create a `while' statement.

match0

public final int match0(CallContext ctx)

mustCompile

protected abstract boolean mustCompile()

print

public final void print(Consumer out)

print

public abstract void print(OutPort ps)

printLineColumn

public void printLineColumn(OutPort out)
Print line and column number if specified. This is a helper routineintended for use by print(OutPort).

setFile

public final void setFile(String filename)

setFlag

public void setFlag(boolean setting, int flag)

setFlag

public void setFlag(int flag)

setLine

public final Expression setLine(Expression old)

setLine

public final void setLine(int lineno, int colno)

setLine

public final void setLine(int lineno)

setLine

public void setLine(Compilation comp)
Set line number from current position in Compilation.

setLocation

public final void setLocation(SourceLocator location)
Copies the current location.

side_effects

public boolean side_effects()
True if evaluating may have side-effects.

toString

public String toString()

valueIfConstant

public Object valueIfConstant()
Return value if it is constant, or null if non-constant or unknown.

walk

protected Expression walk(ExpWalker walker)

walkChildren

protected void walkChildren(ExpWalker walker)