01: /*
02: * Jatha - a Common LISP-compatible LISP library in Java.
03: * Copyright (C) 1997-2005 Micheal Scott Hewett
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: *
20: * For further information, please contact Micheal Hewett at
21: * hewett@cs.stanford.edu
22: *
23: *
24: */
25:
26: package org.jatha.machine;
27:
28: import org.jatha.Jatha;
29: import org.jatha.dynatype.*;
30:
31: /**
32: * JPG : Not an original jatha opcode
33: * opLDR (op LoaD Rest) has been added to handle user-defined functions with
34: * a variable number of args (with &rest keyword in the list of parameters)
35: *
36: * opLDR pushes the value of a local variable onto
37: * the S register and removes two values from the C register.
38: * The values on the C register are the constant 'LDR'
39: * and the pair (i, j), which are indices into the
40: * value of the E register which is a list of lists.
41: * The j index points the beginning of the list of parameters to push onto S register.
42: * <p>
43: * This class contributed by Jean-Pierre Gaillardon, April 2005
44: * </p>
45: * @see SECDMachine
46: *
47: */
48: class opLDR extends SECDop {
49: /**
50: * It calls <tt>SECDop()</tt> with the machine argument
51: * and the label of this instruction.
52: * @see SECDMachine
53: */
54: public opLDR(Jatha lisp) {
55: super (lisp, "LDR");
56: }
57:
58: public void Execute(SECDMachine machine) {
59: LispValue indexes;
60:
61: indexes = machine.C.value().second();
62:
63: machine.S.push(getRestListAt(indexes, machine.E.value()));
64:
65: machine.C.pop();
66: machine.C.pop();
67: }
68:
69: /**
70: * @param ij_indexes a dot paired (i . j) i is the list index, j the index in this list
71: * @param valueList the list of lists
72: * @return the "rest parameter" whose index is superior to j in list number i
73: */
74: private LispValue getRestListAt(LispValue ij_indexes,
75: LispValue valueList) {
76: long i, j;
77:
78: i = ((LispInteger) (ij_indexes.car())).getLongValue();
79: j = ((LispInteger) (ij_indexes.cdr())).getLongValue();
80:
81: LispValue subList = loc(i, valueList);
82: for (int idx = 1; idx < j; idx++) {
83: subList = subList.cdr();
84: }
85: return subList;
86: }
87:
88: public LispValue grindef(LispValue code, int indentAmount) {
89: indent(indentAmount);
90:
91: System.out.print(functionName);
92: indent(6);
93: code.second().internal_princ(System.out);
94:
95: f_lisp.NEWLINE.internal_princ(System.out);
96:
97: return code.cdr().cdr();
98: }
99: }
|