source: branches/0.17.x/abcl/src/org/armedbear/lisp/CompiledClosure.java

Last change on this file was 12254, checked in by ehuelsmann, 16 years ago

Remove 'throws ConditionThrowable?' method annotations:

it's an unchecked exception now, so no need to declare it thrown.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1/*
2 * CompiledClosure.java
3 *
4 * Copyright (C) 2004-2005 Peter Graves
5 * $Id: CompiledClosure.java 12254 2009-11-06 20:07:54Z ehuelsmann $
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 * As a special exception, the copyright holders of this library give you
22 * permission to link this library with independent modules to produce an
23 * executable, regardless of the license terms of these independent
24 * modules, and to copy and distribute the resulting executable under
25 * terms of your choice, provided that you also meet, for each linked
26 * independent module, the terms and conditions of the license of that
27 * module.  An independent module is a module which is not derived from
28 * or based on this library.  If you modify this library, you may extend
29 * this exception to your version of the library, but you are not
30 * obligated to do so.  If you do not wish to do so, delete this
31 * exception statement from your version.
32 */
33
34package org.armedbear.lisp;
35
36public class CompiledClosure extends Closure
37        implements Cloneable
38{
39
40  public ClosureBinding[] ctx;
41
42  public CompiledClosure(LispObject lambdaList)
43
44  {
45    super(list(Symbol.LAMBDA, lambdaList), null);
46  }
47
48  final public CompiledClosure setContext(ClosureBinding[] context)
49  {
50    ctx = context;
51    return this;
52  }
53
54  final public CompiledClosure dup()
55  {
56      CompiledClosure result = null;
57      try {
58    result = (CompiledClosure)super.clone();
59      } catch (CloneNotSupportedException e) {
60      }
61      return result;
62  }
63
64  @Override
65  public LispObject typep(LispObject typeSpecifier)
66  {
67    if (typeSpecifier == Symbol.COMPILED_FUNCTION)
68      return T;
69    return super.typep(typeSpecifier);
70  }
71
72  private final LispObject notImplemented()
73  {
74    return error(new WrongNumberOfArgumentsException(this));
75  }
76
77
78  // Zero args.
79  public LispObject execute()
80  {
81    LispObject[] args = new LispObject[0];
82    return execute(args);
83  }
84
85  // One arg.
86  public LispObject execute( LispObject first)
87
88  {
89    LispObject[] args = new LispObject[1];
90    args[0] = first;
91    return execute(args);
92  }
93
94  // Two args.
95  public LispObject execute( LispObject first,
96                            LispObject second)
97
98  {
99    LispObject[] args = new LispObject[2];
100    args[0] = first;
101    args[1] = second;
102    return execute(args);
103  }
104
105  // Three args.
106  public LispObject execute( LispObject first,
107                            LispObject second, LispObject third)
108
109  {
110    LispObject[] args = new LispObject[3];
111    args[0] = first;
112    args[1] = second;
113    args[2] = third;
114    return execute(args);
115  }
116
117  // Four args.
118  public LispObject execute( LispObject first,
119                            LispObject second, LispObject third,
120                            LispObject fourth)
121
122  {
123    LispObject[] args = new LispObject[4];
124    args[0] = first;
125    args[1] = second;
126    args[2] = third;
127    args[3] = fourth;
128    return execute(args);
129  }
130
131  // Five args.
132  public LispObject execute( LispObject first,
133                            LispObject second, LispObject third,
134                            LispObject fourth, LispObject fifth)
135
136  {
137    LispObject[] args = new LispObject[5];
138    args[0] = first;
139    args[1] = second;
140    args[2] = third;
141    args[3] = fourth;
142    args[4] = fifth;
143    return execute(args);
144  }
145
146  // Six args.
147  public LispObject execute( LispObject first,
148                            LispObject second, LispObject third,
149                            LispObject fourth, LispObject fifth,
150                            LispObject sixth)
151
152  {
153    LispObject[] args = new LispObject[6];
154    args[0] = first;
155    args[1] = second;
156    args[2] = third;
157    args[3] = fourth;
158    args[4] = fifth;
159    args[5] = sixth;
160    return execute(args);
161  }
162
163  // Seven args.
164  public LispObject execute( LispObject first,
165                            LispObject second, LispObject third,
166                            LispObject fourth, LispObject fifth,
167                            LispObject sixth, LispObject seventh)
168
169  {
170    LispObject[] args = new LispObject[7];
171    args[0] = first;
172    args[1] = second;
173    args[2] = third;
174    args[3] = fourth;
175    args[4] = fifth;
176    args[5] = sixth;
177    args[6] = seventh;
178    return execute(args);
179  }
180
181  // Eight args.
182  public LispObject execute( LispObject first,
183                            LispObject second, LispObject third,
184                            LispObject fourth, LispObject fifth,
185                            LispObject sixth, LispObject seventh,
186                            LispObject eighth)
187
188  {
189    LispObject[] args = new LispObject[8];
190    args[0] = first;
191    args[1] = second;
192    args[2] = third;
193    args[3] = fourth;
194    args[4] = fifth;
195    args[5] = sixth;
196    args[6] = seventh;
197    args[7] = eighth;
198    return execute(args);
199  }
200
201  // Arg array.
202  public LispObject execute(LispObject[] args)
203
204  {
205    return notImplemented();
206  }
207
208  // ### load-compiled-function
209  private static final Primitive LOAD_COMPILED_FUNCTION =
210      new Primitive("load-compiled-function", PACKAGE_SYS, true, "source")
211  {
212    @Override
213    public LispObject execute(LispObject arg)
214    {
215      String namestring = null;
216      if (arg instanceof Pathname)
217        namestring = ((Pathname)arg).getNamestring();
218      else if (arg instanceof AbstractString)
219        namestring = arg.getStringValue();
220      if (namestring != null)
221        return loadCompiledFunction(namestring);
222      if(arg instanceof JavaObject) {
223    try {
224        return loadCompiledFunction((byte[]) arg.javaInstance(byte[].class));
225    } catch(Throwable t) {
226        Debug.trace(t);
227        return error(new LispError("Unable to load " + arg.writeToString()));
228    }
229      }
230      return error(new LispError("Unable to load " + arg.writeToString()));
231    }
232  };
233
234  // ### varlist
235  private static final Primitive VARLIST =
236      new Primitive("varlist", PACKAGE_SYS, false)
237  {
238    @Override
239    public LispObject execute(LispObject arg)
240    {
241      if (arg instanceof Closure)
242        return ((Closure)arg).getVariableList();
243      return type_error(arg, Symbol.COMPILED_FUNCTION);
244    }
245  };
246}
Note: See TracBrowser for help on using the repository browser.