001: package sisc.exprs;
002:
003: import sisc.data.*;
004:
005: import java.io.*;
006: import sisc.interpreter.*;
007: import sisc.ser.Serializer;
008: import sisc.ser.Deserializer;
009: import sisc.env.SymbolicEnvironment;
010: import sisc.util.ExpressionVisitor;
011: import sisc.util.FreeReference;
012: import sisc.util.UndefinedVarException;
013:
014: public class FreeReferenceExp extends Expression implements Immediate {
015:
016: private FreeReference ref;
017:
018: public FreeReferenceExp(FreeReference ref) {
019: this .ref = ref;
020: }
021:
022: public FreeReferenceExp(Symbol sym, SymbolicEnvironment senv) {
023: this (new FreeReference(sym, senv));
024: }
025:
026: public Symbol getSym() {
027: return ref.getName();
028: }
029:
030: public void eval(Interpreter r) throws ContinuationException {
031: r.acc = getValue(r);
032: r.nxp = null;
033: }
034:
035: public Value getValue(Interpreter r) throws ContinuationException {
036: try {
037: return ref.getValue();
038: } catch (UndefinedVarException e) {
039: error(r, liMessage(SISCB, "undefinedvar", e.var));
040: return null; //won't get here
041: }
042: }
043:
044: public void serialize(Serializer s) throws IOException {
045: ref.serialize(s);
046: }
047:
048: public Value express() {
049: return new Pair(sym("ref"), ref.express());
050: }
051:
052: public void deserialize(Deserializer s) throws IOException {
053: ref.deserialize(s);
054: }
055:
056: public FreeReferenceExp() {
057: ref = new FreeReference();
058: }
059:
060: public boolean equals(Object o) {
061: if (!(o instanceof FreeReferenceExp))
062: return false;
063: FreeReferenceExp e = (FreeReferenceExp) o;
064: return ref.equals(e.ref);
065: }
066:
067: public int hashCode() {
068: return ref.hashCode();
069: }
070:
071: public boolean visit(ExpressionVisitor v) {
072: return ref.visit(v);
073: }
074:
075: public FreeReference getReference() {
076: return ref;
077: }
078:
079: }
080: /*
081: * The contents of this file are subject to the Mozilla Public
082: * License Version 1.1 (the "License"); you may not use this file
083: * except in compliance with the License. You may obtain a copy of
084: * the License at http://www.mozilla.org/MPL/
085: *
086: * Software distributed under the License is distributed on an "AS
087: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
088: * implied. See the License for the specific language governing
089: * rights and limitations under the License.
090: *
091: * The Original Code is the Second Interpreter of Scheme Code (SISC).
092: *
093: * The Initial Developer of the Original Code is Scott G. Miller.
094: * Portions created by Scott G. Miller are Copyright (C) 2000-2007
095: * Scott G. Miller. All Rights Reserved.
096: *
097: * Contributor(s):
098: * Matthias Radestock
099: *
100: * Alternatively, the contents of this file may be used under the
101: * terms of the GNU General Public License Version 2 or later (the
102: * "GPL"), in which case the provisions of the GPL are applicable
103: * instead of those above. If you wish to allow use of your
104: * version of this file only under the terms of the GPL and not to
105: * allow others to use your version of this file under the MPL,
106: * indicate your decision by deleting the provisions above and
107: * replace them with the notice and other provisions required by
108: * the GPL. If you do not delete the provisions above, a recipient
109: * may use your version of this file under either the MPL or the
110: * GPL.
111: */
|