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