KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > lisp > AutoloadMacro


1 /*
2  * AutoloadMacro.java
3  *
4  * Copyright (C) 2003-2004 Peter Graves
5  * $Id: AutoloadMacro.java,v 1.13 2004/07/09 17:39:59 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 {
26     private AutoloadMacro(Symbol symbol)
27     {
28         super(symbol);
29     }
30
31     private AutoloadMacro(Symbol symbol, String JavaDoc fileName)
32     {
33         super(symbol, fileName, null);
34     }
35
36     private static void installAutoloadMacro(Symbol symbol, String JavaDoc fileName)
37         throws ConditionThrowable
38     {
39         AutoloadMacro am = new AutoloadMacro(symbol, fileName);
40         if (symbol.getSymbolFunction() instanceof SpecialOperator)
41             put(symbol, Symbol.MACROEXPAND_MACRO, am);
42         else
43             symbol.setSymbolFunction(am);
44     }
45
46     public void load() throws ConditionThrowable
47     {
48         Load.loadSystemFile(getFileName(), true);
49     }
50
51     public String JavaDoc writeToString() throws ConditionThrowable
52     {
53         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("#<AUTOLOAD-MACRO ");
54         sb.append(getSymbol().writeToString());
55         sb.append(" \"");
56         sb.append(getFileName());
57         sb.append("\">");
58         return sb.toString();
59     }
60
61     // ### autoload-macro
62
private static final Primitive AUTOLOAD_MACRO =
63         new Primitive("autoload-macro", PACKAGE_EXT, true)
64     {
65         public LispObject execute(LispObject first) throws ConditionThrowable
66         {
67             if (first instanceof Symbol) {
68                 Symbol symbol = (Symbol) first;
69                 installAutoloadMacro(symbol, null);
70                 return T;
71             }
72             if (first instanceof Cons) {
73                 for (LispObject list = first; list != NIL; list = list.cdr()) {
74                     Symbol symbol = checkSymbol(list.car());
75                     installAutoloadMacro(symbol, null);
76                 }
77                 return T;
78             }
79             return signal(new TypeError(first));
80         }
81         public LispObject execute(LispObject first, LispObject second)
82             throws ConditionThrowable
83         {
84             final String JavaDoc fileName = second.getStringValue();
85             if (first instanceof Symbol) {
86                 Symbol symbol = (Symbol) first;
87                 installAutoloadMacro(symbol, fileName);
88                 return T;
89             }
90             if (first instanceof Cons) {
91                 for (LispObject list = first; list != NIL; list = list.cdr()) {
92                     Symbol symbol = checkSymbol(list.car());
93                     installAutoloadMacro(symbol, fileName);
94                 }
95                 return T;
96             }
97             return signal(new TypeError(first));
98         }
99     };
100 }
101
Popular Tags