KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * arglist.java
3  *
4  * Copyright (C) 2003-2004 Peter Graves
5  * $Id: arglist.java,v 1.10 2004/07/10 15:59:36 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 arglist extends Lisp
25 {
26     private static final Functional getFunctional(LispObject obj)
27         throws ConditionThrowable
28     {
29         if (obj instanceof Functional)
30             return (Functional) obj;
31         if (obj instanceof Symbol) {
32             LispObject fun = obj.getSymbolFunction();
33             if (fun instanceof Autoload) {
34                 Autoload autoload = (Autoload) fun;
35                 autoload.load();
36                 fun = (Functional)autoload.getSymbol().getSymbolFunction();
37             }
38             if (fun instanceof Functional) {
39                 Functional func = (Functional) fun;
40                 if (func.getArglist() != null)
41                     return func;
42                 LispObject other =
43                     get(checkSymbol(obj), Symbol.MACROEXPAND_MACRO, NIL);
44                 if (other != null)
45                     return getFunctional(other);
46                 else
47                     return null;
48             }
49         } else if (obj instanceof Cons && obj.car() == Symbol.LAMBDA)
50             return new Closure(obj.cadr(), obj.cddr(), new Environment());
51         return null;
52     }
53
54     // ### arglist
55
private static final Primitive1 ARGLIST =
56         new Primitive1("arglist", PACKAGE_EXT, true)
57     {
58         public LispObject execute(LispObject arg) throws ConditionThrowable
59         {
60             LispThread thread = LispThread.currentThread();
61             Functional functional = getFunctional(arg);
62             LispObject arglist = null;
63             if (functional != null)
64                 arglist = functional.getArglist();
65             final LispObject value1, value2;
66             if (arglist instanceof AbstractString) {
67                 String JavaDoc s = arglist.getStringValue();
68                 // Give the string list syntax.
69
s = "(" + s + ")";
70                 // Bind *PACKAGE* so we use the EXT package if we need
71
// to intern any symbols.
72
Environment oldDynEnv = thread.getDynamicEnvironment();
73                 thread.bindSpecial(_PACKAGE_, PACKAGE_EXT);
74                 try {
75                     arglist = readObjectFromString(s);
76                 }
77                 finally {
78                     thread.setDynamicEnvironment(oldDynEnv);
79                 }
80                 functional.setArglist(arglist);
81             }
82             if (arglist != null) {
83                 value1 = arglist;
84                 value2 = T;
85             } else {
86                 value1 = NIL;
87                 value2 = NIL;
88             }
89             return thread.setValues(value1, value2);
90         }
91     };
92
93     // ### %set-arglist
94
private static final Primitive2 _SET_ARGLIST =
95         new Primitive2("%set-arglist", PACKAGE_SYS, false)
96     {
97         public LispObject execute(LispObject first, LispObject second)
98             throws ConditionThrowable
99         {
100             coerceToFunctional(first).setArglist(second);
101             return second;
102         }
103     };
104 }
105
Popular Tags