source: branches/0.17.x/abcl/src/org/armedbear/lisp/StandardMethod.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: 10.3 KB
Line 
1/*
2 * StandardMethod.java
3 *
4 * Copyright (C) 2005 Peter Graves
5 * $Id: StandardMethod.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 StandardMethod extends StandardObject
37{
38  public StandardMethod()
39  {
40    super(StandardClass.STANDARD_METHOD,
41          StandardClass.STANDARD_METHOD.getClassLayout().getLength());
42  }
43
44  protected StandardMethod(LispClass cls, int length)
45  {
46    super(cls, length);
47  }
48
49  public StandardMethod(StandardGenericFunction gf,
50                        Function fastFunction,
51                        LispObject lambdaList,
52                        LispObject specializers)
53  {
54    this();
55    slots[StandardMethodClass.SLOT_INDEX_GENERIC_FUNCTION] = gf;
56    slots[StandardMethodClass.SLOT_INDEX_LAMBDA_LIST] = lambdaList;
57    slots[StandardMethodClass.SLOT_INDEX_SPECIALIZERS] = specializers;
58    slots[StandardMethodClass.SLOT_INDEX_QUALIFIERS] = NIL;
59    slots[StandardMethodClass.SLOT_INDEX_FUNCTION] = NIL;
60    slots[StandardMethodClass.SLOT_INDEX_FAST_FUNCTION] = fastFunction;
61    slots[StandardMethodClass.SLOT_INDEX_DOCUMENTATION] = NIL;
62  }
63
64  // ### method-lambda-list
65  // generic function
66  private static final Primitive METHOD_LAMBDA_LIST =
67    new Primitive("method-lambda-list", PACKAGE_SYS, true, "method")
68    {
69      @Override
70      public LispObject execute(LispObject arg)
71      {
72          return checkStandardMethod(arg).slots[StandardMethodClass.SLOT_INDEX_LAMBDA_LIST];
73      }
74    };
75
76  // ### set-method-lambda-list
77  private static final Primitive SET_METHOD_LAMBDA_LIST =
78    new Primitive("set-method-lambda-list", PACKAGE_SYS, true,
79                  "method lambda-list")
80    {
81      @Override
82      public LispObject execute(LispObject first, LispObject second)
83
84      {
85          checkStandardMethod(first).slots[StandardMethodClass.SLOT_INDEX_LAMBDA_LIST] = second;
86          return second;
87      }
88    };
89
90  // ### method-qualifiers
91  private static final Primitive _METHOD_QUALIFIERS =
92    new Primitive("%method-qualifiers", PACKAGE_SYS, true, "method")
93    {
94      @Override
95      public LispObject execute(LispObject arg)
96      {
97          return checkStandardMethod(arg).slots[StandardMethodClass.SLOT_INDEX_QUALIFIERS];
98      }
99    };
100
101  // ### set-method-qualifiers
102  private static final Primitive SET_METHOD_QUALIFIERS =
103    new Primitive("set-method-qualifiers", PACKAGE_SYS, true,
104                  "method qualifiers")
105    {
106      @Override
107      public LispObject execute(LispObject first, LispObject second)
108
109      {         
110          checkStandardMethod(first).slots[StandardMethodClass.SLOT_INDEX_QUALIFIERS] = second;
111          return second;
112      }
113    };
114
115  // ### method-documentation
116  private static final Primitive METHOD_DOCUMENTATION =
117    new Primitive("method-documentation", PACKAGE_SYS, true, "method")
118    {
119      @Override
120      public LispObject execute(LispObject arg)
121      {
122          return checkStandardMethod(arg).slots[StandardMethodClass.SLOT_INDEX_DOCUMENTATION];
123      }
124    };
125
126  // ### set-method-documentation
127  private static final Primitive SET_METHOD_DOCUMENTATION =
128    new Primitive("set-method-documentation", PACKAGE_SYS, true,
129                  "method documentation")
130    {
131      @Override
132      public LispObject execute(LispObject first, LispObject second)
133
134      {
135          checkStandardMethod(first).slots[StandardMethodClass.SLOT_INDEX_DOCUMENTATION] = second;
136          return second;
137      }
138    };
139
140  public LispObject getFunction()
141  {
142    return slots[StandardMethodClass.SLOT_INDEX_FUNCTION];
143  }
144
145  @Override
146  public String writeToString()
147  {
148    LispObject genericFunction =
149      slots[StandardMethodClass.SLOT_INDEX_GENERIC_FUNCTION];
150    if (genericFunction instanceof StandardGenericFunction)
151      {
152        LispObject name =
153          ((StandardGenericFunction)genericFunction).getGenericFunctionName();
154        if (name != null)
155          {
156            FastStringBuffer sb = new FastStringBuffer();
157            sb.append(getLispClass().getSymbol().writeToString());
158            sb.append(' ');
159            sb.append(name.writeToString());
160            LispObject specializers =
161              slots[StandardMethodClass.SLOT_INDEX_SPECIALIZERS];
162            if (specializers != null)
163              {
164                LispObject specs = specializers;
165                LispObject names = NIL;
166                while (specs != NIL)
167                  {
168                    LispObject spec = specs.car();
169                    if (spec instanceof LispClass)
170                      names = names.push(((LispClass)spec).getSymbol());
171                    else
172                      names = names.push(spec);
173                    specs = specs.cdr();
174                  }
175                sb.append(' ');
176                sb.append(names.nreverse().writeToString());
177              }
178            return unreadableString(sb.toString());
179          }
180      }
181    return super.writeToString();
182  }
183
184  // ### %method-generic-function
185  private static final Primitive _METHOD_GENERIC_FUNCTION =
186    new Primitive("%method-generic-function", PACKAGE_SYS, true)
187    {
188      @Override
189      public LispObject execute(LispObject arg)
190      {
191          return checkStandardMethod(arg).slots[StandardMethodClass.SLOT_INDEX_GENERIC_FUNCTION];
192      }
193    };
194
195  // ### %set-method-generic-function
196  private static final Primitive _SET_METHOD_GENERICFUNCTION =
197    new Primitive("%set-method-generic-function", PACKAGE_SYS, true)
198    {
199      @Override
200      public LispObject execute(LispObject first, LispObject second)
201
202      {
203          checkStandardMethod(first).slots[StandardMethodClass.SLOT_INDEX_GENERIC_FUNCTION] = second;
204          return second;
205      }
206    };
207
208  // ### %method-function
209  private static final Primitive _METHOD_FUNCTION =
210    new Primitive("%method-function", PACKAGE_SYS, true, "method")
211    {
212      @Override
213      public LispObject execute(LispObject arg)
214      {
215          return checkStandardMethod(arg).slots[StandardMethodClass.SLOT_INDEX_FUNCTION];
216      }
217    };
218
219  // ### %set-method-function
220  private static final Primitive _SET_METHOD_FUNCTION =
221    new Primitive("%set-method-function", PACKAGE_SYS, true,
222                  "method function")
223    {
224      @Override
225      public LispObject execute(LispObject first, LispObject second)
226
227      {
228          checkStandardMethod(first).slots[StandardMethodClass.SLOT_INDEX_FUNCTION] = second;
229          return second;
230      }
231    };
232
233  // ### %method-fast-function
234  private static final Primitive _METHOD_FAST_FUNCTION =
235    new Primitive("%method-fast-function", PACKAGE_SYS, true, "method")
236    {
237      @Override
238      public LispObject execute(LispObject arg)
239      {
240          return checkStandardMethod(arg).slots[StandardMethodClass.SLOT_INDEX_FAST_FUNCTION];
241      }
242    };
243
244  // ### %set-method-fast-function
245  private static final Primitive _SET_METHOD_FAST_FUNCTION =
246    new Primitive("%set-method-fast-function", PACKAGE_SYS, true,
247                  "method fast-function")
248    {
249      @Override
250      public LispObject execute(LispObject first, LispObject second)
251
252      {
253          checkStandardMethod(first).slots[StandardMethodClass.SLOT_INDEX_FAST_FUNCTION] = second;
254          return second;
255      }
256    };
257
258  // ### %method-specializers
259  private static final Primitive _METHOD_SPECIALIZERS =
260    new Primitive("%method-specializers", PACKAGE_SYS, true, "method")
261    {
262      @Override
263      public LispObject execute(LispObject arg)
264      {
265          return checkStandardMethod(arg).slots[StandardMethodClass.SLOT_INDEX_SPECIALIZERS];
266      }
267    };
268
269  // ### %set-method-specializers
270  private static final Primitive _SET_METHOD_SPECIALIZERS =
271    new Primitive("%set-method-specializers", PACKAGE_SYS, true,
272                  "method specializers")
273    {
274      @Override
275      public LispObject execute(LispObject first, LispObject second)
276
277      {
278          checkStandardMethod(first).slots[StandardMethodClass.SLOT_INDEX_SPECIALIZERS] = second;
279          return second;
280      }
281    };
282
283  private static final StandardGenericFunction METHOD_SPECIALIZERS =
284    new StandardGenericFunction("method-specializers",
285                                PACKAGE_MOP,
286                                true,
287                                _METHOD_SPECIALIZERS,
288                                list(Symbol.METHOD),
289                                list(StandardClass.STANDARD_METHOD));
290
291  private static final StandardGenericFunction METHOD_QUALIFIERS =
292    new StandardGenericFunction("method-qualifiers",
293                                PACKAGE_MOP,
294                                true,
295                                _METHOD_QUALIFIERS,
296                                list(Symbol.METHOD),
297                                list(StandardClass.STANDARD_METHOD));
298
299        final public static StandardMethod checkStandardMethod(LispObject first)
300        {
301                if (first instanceof StandardMethod)
302                        return (StandardMethod) first;
303                return (StandardMethod) type_error(first, Symbol.METHOD);
304        }
305
306}
Note: See TracBrowser for help on using the repository browser.