01: /*
02: * AutoloadMacro.java
03: *
04: * Copyright (C) 2003-2004 Peter Graves
05: * $Id: AutoloadMacro.java,v 1.13 2004/07/09 17:39:59 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.lisp;
23:
24: public final class AutoloadMacro extends Autoload {
25: private AutoloadMacro(Symbol symbol) {
26: super (symbol);
27: }
28:
29: private AutoloadMacro(Symbol symbol, String fileName) {
30: super (symbol, fileName, null);
31: }
32:
33: private static void installAutoloadMacro(Symbol symbol,
34: String fileName) throws ConditionThrowable {
35: AutoloadMacro am = new AutoloadMacro(symbol, fileName);
36: if (symbol.getSymbolFunction() instanceof SpecialOperator)
37: put(symbol, Symbol.MACROEXPAND_MACRO, am);
38: else
39: symbol.setSymbolFunction(am);
40: }
41:
42: public void load() throws ConditionThrowable {
43: Load.loadSystemFile(getFileName(), true);
44: }
45:
46: public String writeToString() throws ConditionThrowable {
47: StringBuffer sb = new StringBuffer("#<AUTOLOAD-MACRO ");
48: sb.append(getSymbol().writeToString());
49: sb.append(" \"");
50: sb.append(getFileName());
51: sb.append("\">");
52: return sb.toString();
53: }
54:
55: // ### autoload-macro
56: private static final Primitive AUTOLOAD_MACRO = new Primitive(
57: "autoload-macro", PACKAGE_EXT, true) {
58: public LispObject execute(LispObject first)
59: throws ConditionThrowable {
60: if (first instanceof Symbol) {
61: Symbol symbol = (Symbol) first;
62: installAutoloadMacro(symbol, null);
63: return T;
64: }
65: if (first instanceof Cons) {
66: for (LispObject list = first; list != NIL; list = list
67: .cdr()) {
68: Symbol symbol = checkSymbol(list.car());
69: installAutoloadMacro(symbol, null);
70: }
71: return T;
72: }
73: return signal(new TypeError(first));
74: }
75:
76: public LispObject execute(LispObject first, LispObject second)
77: throws ConditionThrowable {
78: final String fileName = second.getStringValue();
79: if (first instanceof Symbol) {
80: Symbol symbol = (Symbol) first;
81: installAutoloadMacro(symbol, fileName);
82: return T;
83: }
84: if (first instanceof Cons) {
85: for (LispObject list = first; list != NIL; list = list
86: .cdr()) {
87: Symbol symbol = checkSymbol(list.car());
88: installAutoloadMacro(symbol, fileName);
89: }
90: return T;
91: }
92: return signal(new TypeError(first));
93: }
94: };
95: }
|