sisc.data
Class Expression

java.lang.Object
  extended by sisc.util.Util
      extended by sisc.data.Expression
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, ExpressionVisitee, Version
Direct Known Subclasses:
AppEval, AppExp, ApplyValuesContEval, DefineEval, EvalExp, FillRibExp, FixedAppExp_0, FreeReferenceExp, FreeSetEval, IfEval, Interpreter.ThrowSchemeException, LambdaExp, LetrecEval, LexicalReferenceExp, LocalReferenceExp, SetboxEval, UnboxExp, Value

public abstract class Expression
extends Util
implements java.io.Externalizable, ExpressionVisitee

The base class for any and all expressions. An expression is anything in Scheme that can evaluate to a value. In SISC, an expression can be annotated. An annotation is any key/value pair attached to an expression for the duration of its lifetime. Annotations are used to implement procedure properties and source-tracked debugging.

See Also:
Serialized Form

Field Summary
 java.util.Map annotations
           
protected static java.util.Set EMPTYSET
           
 
Fields inherited from class sisc.util.Util
BACKQUOTE, BEGIN, bundles, caseSensitive, EMPTYLIST, EMPTYVEC, EOF, ERRORK, EVAL, EXPSC, EXPTOP, FALSE, FCONT, FIVE, JEXCEPTION, LAMBDA, LOCATION, maxFloatPrecision, MESSAGE, minFloatPrecision, NAME, OTHER, PARENT, permitInterrupts, QUOTE, QUOTESYM, REPORT, SETBANG, SISC, SISC_SPECIFIC, SISCB, SOURCE_COLUMN, SOURCE_FILE, SOURCE_LINE, SYMENV, THIS, TOPLEVEL, TRUE, UNQUOTE, UNQUOTE_SPLICING, VOID, ZV
 
Fields inherited from interface sisc.util.Version
VERSION
 
Constructor Summary
Expression()
           
 
Method Summary
 void deserialize(Deserializer s)
          All Expressions must implement a default (no-argument) constructor.
 void deserializeAnnotations(Deserializer s)
           
abstract  void eval(Interpreter r)
          All expressions can be evaluated to some Scheme value.
abstract  Value express()
          A debugging function, express returns a Scheme value that describes this expression.
 Value getAnnotation(Symbol key)
           
 Value getAnnotation(Symbol key, Value def)
           
 java.util.Set getAnnotationKeys()
           
 Pair getAnnotations()
           
 Symbol getName()
           
 Value getValue(Interpreter r)
          If an expression implements the Immediate interface, it must override getValue, which returns as a Value, the immediate value of this expression.
 void readExternal(java.io.ObjectInput in)
           
 java.lang.Object readResolve()
           
 void serialize(Serializer s)
          All Expressions must implement a default (no-argument) constructor.
 void serializeAnnotations(Serializer s)
           
 Value setAnnotation(Symbol key, Value val)
           
 Value setAnnotation(Symbol key, Value val, Value def)
           
 void setName(Symbol s)
          The following helpers set the 'name annotation, which is used for naming procedures, environments, etc.
 boolean visit(ExpressionVisitor v)
           
 boolean visitAnnotations(ExpressionVisitor v)
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class sisc.util.Util
annotated, annotatedAppEval, append, argCheck, argsToSymbols, assq, bininport, bininstream, binoutport, binoutstream, box, character, charinport, charinreader, charoutport, charoutwriter, charsetFromString, chr, cont, currentClassLoader, env, error, error, error, error, error, error, error, expr, getDefaultCharacterSet, immutablePair, immutableVector, inport, javaExceptionToString, javaWrap, justify, length, liMessage, liMessage, liMessage, liMessage, liMessage, liMessage, liMessage, list, list, list, list, list, makeURL, mapcar, memq, nlib, num, outport, pair, pairToExpressions, pairToExpVect, pairToValues, proc, read, registerBundle, reverse, reverseInPlace, simpleErrorToString, sourceAnnotations, str, string, sym, symbol, symval, truePair, truth, truth, typeError, typeError, updateName, url, url, url, valArrayToList, valArrayToList, valArrayToVec, vec, warn, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTYSET

protected static java.util.Set EMPTYSET

annotations

public java.util.Map annotations
Constructor Detail

Expression

public Expression()
Method Detail

getAnnotation

public Value getAnnotation(Symbol key,
                           Value def)

getAnnotation

public Value getAnnotation(Symbol key)

setAnnotation

public Value setAnnotation(Symbol key,
                           Value val,
                           Value def)

setAnnotation

public Value setAnnotation(Symbol key,
                           Value val)

getAnnotationKeys

public java.util.Set getAnnotationKeys()

getAnnotations

public Pair getAnnotations()

serializeAnnotations

public void serializeAnnotations(Serializer s)
                          throws java.io.IOException
Throws:
java.io.IOException

deserializeAnnotations

public void deserializeAnnotations(Deserializer s)
                            throws java.io.IOException
Throws:
java.io.IOException

visitAnnotations

public boolean visitAnnotations(ExpressionVisitor v)

setName

public void setName(Symbol s)
The following helpers set the 'name annotation, which is used for naming procedures, environments, etc.


getName

public Symbol getName()

eval

public abstract void eval(Interpreter r)
                   throws ContinuationException
All expressions can be evaluated to some Scheme value. This function implements the exact manner in which an expression is evaluated. An expression, when evaluated, performs some action that results in its value being placed in the acc register of the given Interpreter. An expression that immediately evaluates to a value (i.e. does not require that an additional expression be evaluated to obtain its value) must clear the nxp register by setting it to null. Otherwise, nxp should be set to the expression that is to be evaluated next before this method returns.

Parameters:
r - the Interpreter
Throws:
ContinuationException

getValue

public Value getValue(Interpreter r)
               throws ContinuationException,
                      OptimismUnwarrantedException
If an expression implements the Immediate interface, it must override getValue, which returns as a Value, the immediate value of this expression.

Parameters:
r - the Interpreter
Returns:
the immediate value of this expression, or null if the value cannot be obtained immediately.
Throws:
ContinuationException
OptimismUnwarrantedException

express

public abstract Value express()
A debugging function, express returns a Scheme value that describes this expression. See examples in sisc.exprs.*


serialize

public void serialize(Serializer s)
               throws java.io.IOException
All Expressions must implement a default (no-argument) constructor. Those that wish to be serialized to a heap must implement both this and the deserialize method. The Expression may use any method of the Serializer, which implements java.io.DataOutput to write its state.

Parameters:
s - the Serializer
Throws:
java.io.IOException

deserialize

public void deserialize(Deserializer s)
                 throws java.io.IOException
All Expressions must implement a default (no-argument) constructor. Those that wish to b serialized to a heap must implement both this and the serialize method. The Expression may use any method of the DataInput stream and the Deserializer serialization context to read its state.

Parameters:
s - the Deserializer
Throws:
java.io.IOException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readResolve

public java.lang.Object readResolve()
                             throws java.io.ObjectStreamException
Throws:
java.io.ObjectStreamException

visit

public boolean visit(ExpressionVisitor v)
Specified by:
visit in interface ExpressionVisitee