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: package org.jatha.machine;
26:
27: import org.jatha.Jatha;
28: import org.jatha.dynatype.*;
29:
30: // @date Sat Feb 1 22:18:53 1997
31: /**
32: * opRAP applies a recursive function in an evaluation environment.
33: * It pushes the S, E and C registers on to the D register.
34: * It pushes the car of the topmost S value onto the C register.
35: * ((f.(nil.e)) v.s) (nil.e) (RAP.c) d -->
36: * NIL ((v.e).e) f (s e c.d)
37: * Uses S, E, C and D registers.
38: * Modifes S, E, C and D registers.
39: * @see SECDMachine
40: * @author Micheal S. Hewett hewett@cs.stanford.edu
41: */
42: class opRAP extends SECDop {
43: /**
44: * It calls <tt>SECDop()</tt> with the machine argument
45: * and the label of this instruction.
46: * @see SECDMachine
47: */
48: public opRAP(Jatha lisp) {
49: super (lisp, "RAP");
50: }
51:
52: public void Execute(SECDMachine machine) {
53: LispValue recursiveClosure = machine.S.pop(); /* (f . (nil.e1)) */
54: LispValue v = machine.S.pop(); /* v = list of closures */
55:
56: // machine.E.pop();
57: machine.C.pop();
58:
59: /*
60: System.out.println("\nRAP: closure = " + recursiveClosure);
61: System.out.println("\nRAP: v = " + v);
62: */
63:
64: /*
65: machine.D.push(machine.C.pop());
66: machine.D.push(machine.E.pop());
67: machine.D.push(machine.S.pop());
68: */
69: /*
70: LispValue Evalue = machine.E.value();
71:
72: machine.D.assign(f_lisp.makeCons(machine.S.value(),
73: f_lisp.makeCons(Evalue.cdr(),
74: f_lisp.makeCons(machine.C.value(),
75: machine.D.value()))));
76:
77: */
78: LispValue e2 = machine.E.value();
79: machine.D.assign(f_lisp.makeCons(machine.S.value(), f_lisp
80: .makeCons(e2.cdr(), f_lisp.makeCons(machine.C.value(),
81: machine.D.value()))));
82:
83: machine.C.assign(recursiveClosure.car()); /* f */
84:
85: // The car of E should be rplaca'd with the list of closures
86: //machine.E.assign(f_lisp.makeCons(v, recursiveClosure.cdr().cdr())); // (v . e1)
87: machine.E.value().rplaca(v);
88:
89: machine.S.assign(f_lisp.NIL);
90: }
91: }
|