1 | /* |
---|
2 | * SlotDefinitionClass.java |
---|
3 | * |
---|
4 | * Copyright (C) 2005 Peter Graves |
---|
5 | * $Id: SlotDefinitionClass.java 14134 2012-08-25 21:14:49Z rschlatte $ |
---|
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 SlotDefinitionClass extends StandardClass |
---|
39 | { |
---|
40 | public static final int SLOT_INDEX_NAME = 0; |
---|
41 | public static final int SLOT_INDEX_INITFUNCTION = 1; |
---|
42 | public static final int SLOT_INDEX_INITFORM = 2; |
---|
43 | public static final int SLOT_INDEX_INITARGS = 3; |
---|
44 | public static final int SLOT_INDEX_READERS = 4; |
---|
45 | public static final int SLOT_INDEX_WRITERS = 5; |
---|
46 | public static final int SLOT_INDEX_ALLOCATION = 6; |
---|
47 | public static final int SLOT_INDEX_ALLOCATION_CLASS = 7; |
---|
48 | public static final int SLOT_INDEX_LOCATION = 8; |
---|
49 | public static final int SLOT_INDEX_TYPE = 9; |
---|
50 | public static final int SLOT_INDEX_DOCUMENTATION = 10; |
---|
51 | |
---|
52 | /** |
---|
53 | * For internal use only. This constructor hardcodes the layout of |
---|
54 | * the class, and can't be used to create arbitrary subclasses of |
---|
55 | * slot-definition since new slots get added at the beginning. |
---|
56 | */ |
---|
57 | public SlotDefinitionClass(Symbol symbol, LispObject cpl) { |
---|
58 | super(symbol, cpl); |
---|
59 | Package pkg = PACKAGE_SYS; |
---|
60 | LispObject[] instanceSlotNames = { |
---|
61 | Symbol.NAME, |
---|
62 | Symbol.INITFUNCTION, |
---|
63 | Symbol.INITFORM, |
---|
64 | Symbol.INITARGS, |
---|
65 | Symbol.READERS, |
---|
66 | Symbol.WRITERS, |
---|
67 | Symbol.ALLOCATION, |
---|
68 | Symbol.ALLOCATION_CLASS, |
---|
69 | Symbol.LOCATION, |
---|
70 | Symbol._TYPE, |
---|
71 | Symbol._DOCUMENTATION |
---|
72 | }; |
---|
73 | setClassLayout(new Layout(this, instanceSlotNames, NIL)); |
---|
74 | //Set up slot definitions so that this class can be extended by users |
---|
75 | LispObject slotDefinitions = NIL; |
---|
76 | for(int i = instanceSlotNames.length - 1; i >= 0; i--) { |
---|
77 | slotDefinitions = slotDefinitions.push(new SlotDefinition(this, instanceSlotNames[i])); |
---|
78 | } |
---|
79 | // The Java class SlotDefinition sets the location slot to NIL |
---|
80 | // in its constructor; here we make Lisp-side subclasses of |
---|
81 | // standard-*-slot-definition do the same. |
---|
82 | LispObject locationSlot = slotDefinitions.nthcdr(SLOT_INDEX_LOCATION).car(); |
---|
83 | SlotDefinition.SET_SLOT_DEFINITION_INITFORM.execute(locationSlot, NIL); |
---|
84 | SlotDefinition.SET_SLOT_DEFINITION_INITFUNCTION.execute(locationSlot, StandardClass.constantlyNil); |
---|
85 | setDirectSlotDefinitions(slotDefinitions); |
---|
86 | setSlotDefinitions(slotDefinitions); |
---|
87 | // Fix initargs of TYPE, DOCUMENTATION slots. |
---|
88 | LispObject typeSlot = slotDefinitions.nthcdr(SLOT_INDEX_TYPE).car(); |
---|
89 | SlotDefinition.SET_SLOT_DEFINITION_INITARGS.execute(typeSlot, list(internKeyword("TYPE"))); |
---|
90 | LispObject documentationSlot = slotDefinitions.nthcdr(SLOT_INDEX_DOCUMENTATION).car(); |
---|
91 | SlotDefinition.SET_SLOT_DEFINITION_INITARGS.execute(documentationSlot, list(internKeyword("DOCUMENTATION"))); |
---|
92 | |
---|
93 | setFinalized(true); |
---|
94 | } |
---|
95 | } |
---|