001: /*
002: * Jatha - a Common LISP-compatible LISP library in Java.
003: * Copyright (C) 1997-2005 Micheal Scott Hewett
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: *
020: * For further information, please contact Micheal Hewett at
021: * hewett@cs.stanford.edu
022: *
023: */
024: // ===================================================================
025: // Copyright (c) 1997-1998, All rights reserved, by Micheal Hewett
026: //
027: // This software is free for educational and non-profit use.
028: // Any for-profit use must be governed by a license available
029: // from the author, who can be contacted via email at
030: // "hewett@cs.stanford.edu"
031: //
032: // ===================================================================
033: //
034: // SECDop.java - SECD and LISP primitive operations
035: //
036: // 24 Jan 1997
037: // 22 Aug 1998 - Moved individual opcodes to separate files
038: // to satisfy the Java 1.1 compiler.
039: //
040: // -------------------------------------------------------------------
041: package org.jatha.machine;
042:
043: import org.jatha.Jatha;
044: import org.jatha.compile.LispPrimitive;
045: import org.jatha.dynatype.LispInteger;
046: import org.jatha.dynatype.LispValue;
047:
048: // @date Sat Feb 1 21:05:03 1997
049: /**
050: * SECDop is the abstract class that encompasses all SECD
051: * machine ops.
052: *
053: * @see org.jatha.compile.LispPrimitive
054: * @author Micheal S. Hewett hewett@cs.stanford.edu
055: */
056: public abstract class SECDop extends LispPrimitive {
057:
058: /**
059: * @see SECDMachine
060: */
061: public SECDop(Jatha lisp, String opName) {
062: super (lisp, opName);
063: }
064:
065: /**
066: * The output of this function is printed when the
067: * instruction needs to be printed.
068: */
069: public String toString() {
070: return "SECD." + functionName;
071: }
072:
073: /* --- Utility routines --- */
074: public LispValue loc(long y, LispValue z) {
075: if (y == 1)
076: return (z.car());
077: else
078: return loc(y - 1, z.cdr());
079: }
080:
081: /**
082: * Sets the nth position in the list to the new value.
083: * @param y an index into the list
084: * @param values a list of values
085: * @param newValue the new value for the index.
086: */
087: public void setLoc(long y, LispValue values, LispValue newValue) {
088: if (y == 1)
089: values.rplaca(newValue);
090: else
091: setLoc(y - 1, values.cdr(), newValue);
092: }
093:
094: public LispValue getComponentAt(LispValue ij_indexes,
095: LispValue valueList) {
096: long i, j;
097:
098: i = ((LispInteger) (ij_indexes.car())).getLongValue();
099: j = ((LispInteger) (ij_indexes.cdr())).getLongValue();
100:
101: return loc(j, loc(i, valueList));
102: }
103:
104: public void setComponentAt(LispValue ij_indexes,
105: LispValue valueList, LispValue newValue) {
106: long i, j;
107:
108: i = ((LispInteger) (ij_indexes.car())).getLongValue();
109: j = ((LispInteger) (ij_indexes.cdr())).getLongValue();
110:
111: setLoc(j, loc(i, valueList), newValue);
112: }
113: }
114:
115: // The individual opcodes are in separate files.
|