source: branches/0.19.x/abcl/src/org/armedbear/lisp/SlotDefinition.java

Last change on this file was 12431, checked in by Mark Evenson, 15 years ago

Replace FastStringBuffer? with java.lang.StringBuilder?.

Phil Hudson suggested in Feburary 2009 that "[FastStringBuffer?] should
be removed with all references to it replaced with
java.lang.StringBuilder? once enough confidence in this change has been
gained." After almost a year of using FastStringBuffer? as a delagate
for StringBuilder?, that confidence has indeed been gained.

One subtlety for use of StringBuilder?: there is no

StringBuilder?(char)

constructor, so use

StringBuilder?(String.valueOf(c))

to construct a new StringBuilder? containing a single char. Otherwise
that char will get promoted to an int, and you will invoke

StringBuilder?(int capacity)

which will "swallow" the first character that you thought you were adding.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.3 KB
Line 
1/*
2 * SlotDefinition.java
3 *
4 * Copyright (C) 2005 Peter Graves
5 * $Id: SlotDefinition.java 12431 2010-02-08 08:05:15Z mevenson $
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
36import static org.armedbear.lisp.Lisp.*;
37
38public final class SlotDefinition extends StandardObject
39{
40  public SlotDefinition()
41  {
42    super(StandardClass.SLOT_DEFINITION,
43          StandardClass.SLOT_DEFINITION.getClassLayout().getLength());
44    slots[SlotDefinitionClass.SLOT_INDEX_LOCATION] = NIL;
45  }
46
47  public SlotDefinition(LispObject name, LispObject readers)
48  {
49    this();
50    Debug.assertTrue(name instanceof Symbol);
51    slots[SlotDefinitionClass.SLOT_INDEX_NAME] = name;
52    slots[SlotDefinitionClass.SLOT_INDEX_INITFUNCTION] = NIL;
53    slots[SlotDefinitionClass.SLOT_INDEX_INITARGS] =
54      new Cons(PACKAGE_KEYWORD.intern(((Symbol)name).getName()));
55    slots[SlotDefinitionClass.SLOT_INDEX_READERS] = readers;
56    slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION] = Keyword.INSTANCE;
57  }
58
59  public SlotDefinition(LispObject name, LispObject readers,
60                        LispObject initForm)
61  {
62    this();
63    Debug.assertTrue(name instanceof Symbol);
64    slots[SlotDefinitionClass.SLOT_INDEX_NAME] = name;
65    slots[SlotDefinitionClass.SLOT_INDEX_INITFUNCTION] = NIL;
66    slots[SlotDefinitionClass.SLOT_INDEX_INITFORM] = initForm;
67    slots[SlotDefinitionClass.SLOT_INDEX_INITARGS] =
68      new Cons(PACKAGE_KEYWORD.intern(((Symbol)name).getName()));
69    slots[SlotDefinitionClass.SLOT_INDEX_READERS] = readers;
70    slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION] = Keyword.INSTANCE;
71  }
72 
73  public static SlotDefinition checkSlotDefination(LispObject obj) {
74          if (obj instanceof SlotDefinition) return (SlotDefinition)obj;
75      return (SlotDefinition)type_error(obj, Symbol.SLOT_DEFINITION);     
76  }
77
78  public final LispObject getName()
79  {
80    return slots[SlotDefinitionClass.SLOT_INDEX_NAME];
81  }
82
83  public final void setLocation(int i)
84  {
85    slots[SlotDefinitionClass.SLOT_INDEX_LOCATION] = Fixnum.getInstance(i);
86  }
87
88  @Override
89  public String writeToString()
90  {
91    StringBuilder sb =
92      new StringBuilder(Symbol.SLOT_DEFINITION.writeToString());
93    LispObject name = slots[SlotDefinitionClass.SLOT_INDEX_NAME];
94    if (name != null && name != NIL)
95      {
96        sb.append(' ');
97        sb.append(name.writeToString());
98      }
99    return unreadableString(sb.toString());
100  }
101
102  // ### make-slot-definition
103  private static final Primitive MAKE_SLOT_DEFINITION =
104    new Primitive("make-slot-definition", PACKAGE_SYS, true, "")
105    {
106      @Override
107      public LispObject execute()
108      {
109        return new SlotDefinition();
110      }
111    };
112
113  // ### %slot-definition-name
114  private static final Primitive _SLOT_DEFINITION_NAME =
115    new Primitive(Symbol._SLOT_DEFINITION_NAME, "slot-definition")
116    {
117      @Override
118      public LispObject execute(LispObject arg)
119      {
120          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_NAME];
121      }
122    };
123
124  // ### set-slot-definition-name
125  private static final Primitive SET_SLOT_DEFINITION_NAME =
126    new Primitive("set-slot-definition-name", PACKAGE_SYS, true,
127                  "slot-definition name")
128    {
129      @Override
130      public LispObject execute(LispObject first, LispObject second)
131
132      {
133          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_NAME] = second;
134          return second;
135      }
136    };
137
138  // ### %slot-definition-initfunction
139  private static final Primitive _SLOT_DEFINITION_INITFUNCTION =
140    new Primitive(Symbol._SLOT_DEFINITION_INITFUNCTION, "slot-definition")
141    {
142      @Override
143      public LispObject execute(LispObject arg)
144      {
145          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_INITFUNCTION];
146      }
147    };
148
149  // ### set-slot-definition-initfunction
150  private static final Primitive SET_SLOT_DEFINITION_INITFUNCTION =
151    new Primitive("set-slot-definition-initfunction", PACKAGE_SYS, true,
152                  "slot-definition initfunction")
153    {
154      @Override
155      public LispObject execute(LispObject first, LispObject second)
156
157      {
158          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_INITFUNCTION] = second;
159          return second;
160      }
161    };
162
163  // ### %slot-definition-initform
164  private static final Primitive _SLOT_DEFINITION_INITFORM =
165    new Primitive("%slot-definition-initform", PACKAGE_SYS, true,
166                  "slot-definition")
167    {
168      @Override
169      public LispObject execute(LispObject arg)
170      {
171          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_INITFORM];
172      }
173    };
174
175  // ### set-slot-definition-initform
176  private static final Primitive SET_SLOT_DEFINITION_INITFORM =
177    new Primitive("set-slot-definition-initform", PACKAGE_SYS, true,
178                  "slot-definition initform")
179    {
180      @Override
181      public LispObject execute(LispObject first, LispObject second)
182
183      {
184          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_INITFORM] = second;
185          return second;
186      }
187    };
188
189  // ### %slot-definition-initargs
190  private static final Primitive _SLOT_DEFINITION_INITARGS =
191    new Primitive(Symbol._SLOT_DEFINITION_INITARGS, "slot-definition")
192    {
193      @Override
194      public LispObject execute(LispObject arg)
195      {
196          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_INITARGS];
197      }
198    };
199
200  // ### set-slot-definition-initargs
201  private static final Primitive SET_SLOT_DEFINITION_INITARGS =
202    new Primitive("set-slot-definition-initargs", PACKAGE_SYS, true,
203                  "slot-definition initargs")
204    {
205      @Override
206      public LispObject execute(LispObject first, LispObject second)
207
208      {
209          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_INITARGS] = second;
210          return second;
211      }
212    };
213
214  // ### %slot-definition-readers
215  private static final Primitive _SLOT_DEFINITION_READERS =
216    new Primitive("%slot-definition-readers", PACKAGE_SYS, true,
217                  "slot-definition")
218    {
219      @Override
220      public LispObject execute(LispObject arg)
221      {
222          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_READERS];
223      }
224    };
225
226  // ### set-slot-definition-readers
227  private static final Primitive SET_SLOT_DEFINITION_READERS =
228    new Primitive("set-slot-definition-readers", PACKAGE_SYS, true,
229                  "slot-definition readers")
230    {
231      @Override
232      public LispObject execute(LispObject first, LispObject second)
233
234      {
235          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_READERS] = second;
236          return second;
237      }
238    };
239
240  // ### %slot-definition-writers
241  private static final Primitive _SLOT_DEFINITION_WRITERS =
242    new Primitive("%slot-definition-writers", PACKAGE_SYS, true,
243                  "slot-definition")
244    {
245      @Override
246      public LispObject execute(LispObject arg)
247      {
248          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_WRITERS];
249      }
250    };
251
252  // ### set-slot-definition-writers
253  private static final Primitive SET_SLOT_DEFINITION_WRITERS =
254    new Primitive("set-slot-definition-writers", PACKAGE_SYS, true,
255                  "slot-definition writers")
256    {
257      @Override
258      public LispObject execute(LispObject first, LispObject second)
259
260      {
261          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_WRITERS] = second;
262          return second;
263      }
264    };
265
266  // ### %slot-definition-allocation
267  private static final Primitive _SLOT_DEFINITION_ALLOCATION =
268    new Primitive("%slot-definition-allocation", PACKAGE_SYS, true,
269                  "slot-definition")
270    {
271      @Override
272      public LispObject execute(LispObject arg)
273      {
274          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION];
275      }
276    };
277
278  // ### set-slot-definition-allocation
279  private static final Primitive SET_SLOT_DEFINITION_ALLOCATION =
280    new Primitive("set-slot-definition-allocation", PACKAGE_SYS, true,
281                  "slot-definition allocation")
282    {
283      @Override
284      public LispObject execute(LispObject first, LispObject second)
285
286      {
287          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION] = second;
288          return second;
289      }
290    };
291
292  // ### %slot-definition-allocation-class
293  private static final Primitive _SLOT_DEFINITION_ALLOCATION_CLASS =
294    new Primitive("%slot-definition-allocation-class", PACKAGE_SYS, true,
295                  "slot-definition")
296    {
297      @Override
298      public LispObject execute(LispObject arg)
299      {
300          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION_CLASS];
301      }
302    };
303
304  // ### set-slot-definition-allocation-class
305  private static final Primitive SET_SLOT_DEFINITION_ALLOCATION_CLASS =
306    new Primitive("set-slot-definition-allocation-class", PACKAGE_SYS, true,
307                  "slot-definition allocation-class")
308    {
309      @Override
310      public LispObject execute(LispObject first, LispObject second)
311
312      {
313          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_ALLOCATION_CLASS] = second;
314          return second;
315      }
316    };
317
318  // ### %slot-definition-location
319  private static final Primitive _SLOT_DEFINITION_LOCATION =
320    new Primitive("%slot-definition-location", PACKAGE_SYS, true, "slot-definition")
321    {
322      @Override
323      public LispObject execute(LispObject arg)
324      {
325          return checkSlotDefination(arg).slots[SlotDefinitionClass.SLOT_INDEX_LOCATION];
326      }
327    };
328
329  // ### set-slot-definition-location
330  private static final Primitive SET_SLOT_DEFINITION_LOCATION =
331    new Primitive("set-slot-definition-location", PACKAGE_SYS, true, "slot-definition location")
332    {
333      @Override
334      public LispObject execute(LispObject first, LispObject second)
335
336      {
337          checkSlotDefination(first).slots[SlotDefinitionClass.SLOT_INDEX_LOCATION] = second;
338          return second;
339      }
340    };
341}
Note: See TracBrowser for help on using the repository browser.