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: * $Id: Macroexpand1Primitive.java,v 1.3 2007/03/22 02:12:50 mhewett Exp $
26: */package org.jatha.compile;
27:
28: import org.jatha.Jatha;
29: import org.jatha.dynatype.LispPackage;
30: import org.jatha.dynatype.LispValue;
31: import org.jatha.machine.SECDMachine;
32:
33: /**
34: * <p>Returns the expansion of the form named. Otherwise the form will be returned as is.</p>
35: * <p>(macroexpand-1 form)</p>
36: *
37: * @author <a href="mailto:Ola.Bini@itc.ki.se">Ola Bini</a>
38: * @version $Revision: 1.3 $
39: */
40: public class Macroexpand1Primitive extends LispPrimitive {
41: public Macroexpand1Primitive(final Jatha lisp) {
42: super (lisp, "MACROEXPAND-1", 1);
43: }
44:
45: public void Execute(final SECDMachine machine) {
46: final LispValue form = machine.S.pop();
47: final LispValue carForm = form.car();
48: if (carForm.fboundp() == f_lisp.T
49: && carForm.symbol_function() != null
50: && carForm.symbol_function().basic_macrop()) {
51: machine.S.push(f_lisp.eval(f_lisp
52: .makeCons(
53: f_lisp.EVAL.intern("%%%"
54: + carForm.symbol_name()
55: .toStringSimple(),
56: (LispPackage) f_lisp
57: .findPackage("SYSTEM")),
58: quoteList(form.cdr()))));
59: } else {
60: machine.S.push(form);
61: }
62: machine.C.pop();
63: }
64:
65: private LispValue quoteList(final LispValue intern) {
66: LispValue ret = f_lisp.NIL;
67: for (final java.util.Iterator iter = intern.iterator(); iter
68: .hasNext();) {
69: final LispValue curr = (LispValue) iter.next();
70: ret = f_lisp.makeCons(f_lisp.makeList(f_lisp.QUOTE, curr),
71: ret);
72: }
73: return ret.nreverse();
74: }
75: }// Macroexpand1Primitive
|