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