001: package sisc.exprs;
002:
003: import java.io.*;
004: import sisc.data.*;
005: import sisc.exprs.fp.OptimismUnwarrantedException;
006: import sisc.exprs.fp.OptimisticHost;
007: import sisc.exprs.fp.Utils;
008: import sisc.interpreter.*;
009: import sisc.io.ValueWriter;
010: import sisc.ser.Serializer;
011: import sisc.ser.Deserializer;
012: import sisc.util.ExpressionVisitor;
013:
014: public class AnnotatedExpr extends Value implements OptimisticHost {
015:
016: public Expression expr;
017: public Value annotation, stripped = FALSE;
018:
019: public AnnotatedExpr(Expression expr, Value annotation) {
020: this .expr = expr;
021: this .annotation = annotation;
022: }
023:
024: public void setHosts() {
025: Utils.linkOptimistic(this , expr, 0);
026: }
027:
028: public final void eval(Interpreter r) throws ContinuationException {
029: expr.eval(r);
030: }
031:
032: public final Value getValue(Interpreter r)
033: throws ContinuationException {
034: do {
035: try {
036: return expr.getValue(r);
037: } catch (OptimismUnwarrantedException uwe) {
038: }
039: } while (true);
040: }
041:
042: public Value express() {
043: return list(sym("annotated"), annotation, expr.express());
044: }
045:
046: public AnnotatedExpr() {
047: }
048:
049: public void serialize(Serializer s) throws IOException {
050: s.writeExpression(expr);
051: s.writeExpression(annotation);
052: s.writeExpression(stripped);
053: }
054:
055: public void display(ValueWriter w) throws IOException {
056: w.append("#@(").append(annotation).append(" . ");
057: if (expr instanceof Value)
058: w.append(((Value) expr));
059: else
060: w.append(expr.express());
061: w.append(')');
062: }
063:
064: public void deserialize(Deserializer s) throws IOException {
065: expr = s.readExpression();
066: annotation = (Value) s.readExpression();
067: stripped = (Value) s.readExpression();
068: }
069:
070: public boolean visit(ExpressionVisitor v) {
071: return v.visit(expr) && v.visit(annotation)
072: && v.visit(stripped);
073: }
074:
075: /* (non-Javadoc)
076: * @see sisc.exprs.OptimisticHost#alter(int, sisc.data.Expression)
077: */
078: public synchronized void alter(Interpreter r, int uexpPosition,
079: Expression replaceWith) {
080: expr = replaceWith;
081: }
082: }
083: /*
084: * The contents of this file are subject to the Mozilla Public
085: * License Version 1.1 (the "License"); you may not use this file
086: * except in compliance with the License. You may obtain a copy of
087: * the License at http://www.mozilla.org/MPL/
088: *
089: * Software distributed under the License is distributed on an "AS
090: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
091: * implied. See the License for the specific language governing
092: * rights and limitations under the License.
093: *
094: * The Original Code is the Second Interpreter of Scheme Code (SISC).
095: *
096: * The Initial Developer of the Original Code is Scott G. Miller.
097: * Portions created by Scott G. Miller are Copyright (C) 2000-2007
098: * Scott G. Miller. All Rights Reserved.
099: *
100: * Contributor(s):
101: * Matthias Radestock
102: *
103: * Alternatively, the contents of this file may be used under the
104: * terms of the GNU General Public License Version 2 or later (the
105: * "GPL"), in which case the provisions of the GPL are applicable
106: * instead of those above. If you wish to allow use of your
107: * version of this file only under the terms of the GPL and not to
108: * allow others to use your version of this file under the MPL,
109: * indicate your decision by deleting the provisions above and
110: * replace them with the notice and other provisions required by
111: * the GPL. If you do not delete the provisions above, a recipient
112: * may use your version of this file under either the MPL or the
113: * GPL.
114: */
|