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: ShadowPrimitive.java,v 1.1 2005/05/22 20:15:53 olagus Exp $
26: */package org.jatha.compile;
27:
28: import java.util.Map;
29:
30: import org.jatha.Jatha;
31: import org.jatha.dynatype.*;
32: import org.jatha.machine.*;
33:
34: import org.jatha.compile.args.*;
35:
36: /**
37: * <p>The print name of each symbol in symbols will be extracted and put in as a new symbol in the package, with shadowing on</p>
38: * <p>(shadow symbols &optional package)</p>
39: * <p>symbols should be a list of symbols or a single symbol, a string, or a list of strings</p>
40: * <p>package should be a symbol or string, or a package</p>
41: *
42: * @author <a href="mailto:Ola.Bini@itc.ki.se">Ola Bini</a>
43: * @version $Revision: 1.1 $
44: */
45: public class ShadowPrimitive extends LispPrimitive {
46: private LambdaList args;
47:
48: private LispValue symbolsSym;
49: private LispValue packageSym;
50:
51: public ShadowPrimitive(final Jatha lisp) {
52: super (lisp, "SHADOW", 1, 2);
53: symbolsSym = lisp.EVAL.intern("SYMBOLS");
54: packageSym = lisp.EVAL.intern("PACKAGE");
55: args = new OrdinaryLambdaList(lisp);
56: args.getNormalArguments().add(new NormalArgument(symbolsSym));
57: args.getOptionalArguments().add(
58: new OptionalArgument(packageSym, lisp.PACKAGE_SYMBOL));
59: }
60:
61: public void Execute(final SECDMachine machine) {
62: final LispValue argsList = machine.S.pop();
63: final Map arguments = args.parse(argsList);
64: final LispValue symb = (LispValue) arguments.get(symbolsSym);
65: final LispValue pkg = (LispValue) arguments.get(packageSym);
66: final LispValue pack = f_lisp.findPackage(pkg);
67: machine.S.push(((StandardLispPackage) pack).shadow(symb));
68: machine.C.pop();
69: }
70:
71: // One to two evaluated args.
72: public LispValue CompileArgs(LispCompiler compiler,
73: SECDMachine machine, LispValue args, LispValue valueList,
74: LispValue code) throws CompilerException {
75: return compiler.compileArgsLeftToRight(args, valueList, f_lisp
76: .makeCons(machine.LIS, f_lisp.makeCons(args.length(),
77: code)));
78: }
79: }// ShadowPrimitive
|