KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * CompiledFunction.java
3  *
4  * Copyright (C) 2003-2004 Peter Graves
5  * $Id: CompiledFunction.java,v 1.29 2004/09/18 18:43:55 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 class CompiledFunction extends Closure
25 {
26     public CompiledFunction(Symbol symbol, LispObject lambdaList,
27                             LispObject body, Environment env)
28         throws ConditionThrowable
29     {
30         super(null, lambdaList, body, env);
31     }
32
33     public LispObject typep(LispObject typeSpecifier) throws ConditionThrowable
34     {
35         if (typeSpecifier == Symbol.COMPILED_FUNCTION)
36             return T;
37         return super.typep(typeSpecifier);
38     }
39
40     public LispObject execute() throws ConditionThrowable
41     {
42         LispObject[] args = new LispObject[0];
43         return execute(args);
44     }
45
46     public LispObject execute(LispObject arg) throws ConditionThrowable
47     {
48         LispObject[] args = new LispObject[1];
49         args[0] = arg;
50         return execute(args);
51     }
52
53     public LispObject execute(LispObject first, LispObject second)
54         throws ConditionThrowable
55     {
56         LispObject[] args = new LispObject[2];
57         args[0] = first;
58         args[1] = second;
59         return execute(args);
60     }
61
62     public LispObject execute(LispObject first, LispObject second,
63                               LispObject third)
64         throws ConditionThrowable
65     {
66         LispObject[] args = new LispObject[3];
67         args[0] = first;
68         args[1] = second;
69         args[2] = third;
70         return execute(args);
71     }
72
73     public LispObject execute(LispObject first, LispObject second,
74                               LispObject third, LispObject fourth)
75         throws ConditionThrowable
76     {
77         LispObject[] args = new LispObject[4];
78         args[0] = first;
79         args[1] = second;
80         args[2] = third;
81         args[3] = fourth;
82         return execute(args);
83     }
84
85     public LispObject execute(LispObject[] args) throws ConditionThrowable
86     {
87         return signal(new LispError("CompiledFunction.execute(): not implemented"));
88     }
89
90     // ### load-compiled-function
91
private static final Primitive LOAD_COMPILED_FUNCTION =
92         new Primitive("load-compiled-function", PACKAGE_SYS, true,
93                       "pathname")
94     {
95         public LispObject execute(LispObject arg) throws ConditionThrowable
96         {
97             String JavaDoc namestring = null;
98             if (arg instanceof Pathname) {
99                 namestring = ((Pathname)arg).getNamestring();
100             } else if (arg instanceof AbstractString) {
101                 namestring = arg.getStringValue();
102             }
103             if (namestring != null)
104                 return loadCompiledFunction(namestring);
105             return signal(new LispError("Unable to load " + arg.writeToString()));
106         }
107     };
108
109     // ### varlist
110
private static final Primitive1 VARLIST =
111         new Primitive1("varlist", PACKAGE_SYS, false)
112     {
113         public LispObject execute(LispObject arg) throws ConditionThrowable {
114             if (arg instanceof Closure)
115                 return ((Closure)arg).getVariableList();
116             return signal(new TypeError(arg, "compiled function"));
117         }
118     };
119 }
120
Popular Tags