Commit | Line | Data |
---|---|---|
1d9ee7c7 MD |
1 | /* classes: h_files */ |
2 | ||
729dbac3 DH |
3 | #ifndef SCM_OBJECTS_H |
4 | #define SCM_OBJECTS_H | |
1d9ee7c7 | 5 | |
5bb2d903 | 6 | /* Copyright (C) 1996,1999,2000,2001, 2003, 2006, 2008, 2009 Free Software Foundation, Inc. |
0527e687 | 7 | * |
73be1d9e | 8 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
9 | * modify it under the terms of the GNU Lesser General Public License |
10 | * as published by the Free Software Foundation; either version 3 of | |
11 | * the License, or (at your option) any later version. | |
0527e687 | 12 | * |
53befeb7 NJ |
13 | * This library is distributed in the hope that it will be useful, but |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
0527e687 | 17 | * |
73be1d9e MV |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the Free Software | |
53befeb7 NJ |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | * 02110-1301 USA | |
73be1d9e | 22 | */ |
0527e687 | 23 | |
1d9ee7c7 MD |
24 | \f |
25 | ||
da7f71d7 MD |
26 | /* This file and objects.c contains those minimal pieces of the Guile |
27 | * Object Oriented Programming System which need to be included in | |
28 | * libguile. | |
29 | * | |
30 | * {Objects and structs} | |
31 | * | |
32 | * Objects are currently based upon structs. Although the struct | |
33 | * implementation will change thoroughly in the future, objects will | |
34 | * still be based upon structs. | |
35 | */ | |
36 | ||
1d9ee7c7 MD |
37 | #include "libguile/__scm.h" |
38 | #include "libguile/struct.h" | |
39 | ||
40 | \f | |
41 | ||
da7f71d7 MD |
42 | /* {Class flags} |
43 | * | |
44 | * These are used for efficient identification of instances of a | |
45 | * certain class or its subclasses when traversal of the inheritance | |
46 | * graph would be too costly. | |
47 | */ | |
d8c40b9f DH |
48 | #define SCM_CLASS_FLAGS(class) (SCM_STRUCT_DATA (class) [scm_struct_i_flags]) |
49 | #define SCM_OBJ_CLASS_FLAGS(obj) (SCM_STRUCT_VTABLE_DATA (obj) [scm_struct_i_flags]) | |
da7f71d7 MD |
50 | #define SCM_SET_CLASS_FLAGS(c, f) (SCM_CLASS_FLAGS (c) |= (f)) |
51 | #define SCM_CLEAR_CLASS_FLAGS(c, f) (SCM_CLASS_FLAGS (c) &= ~(f)) | |
6ee350ad | 52 | #define SCM_CLASSF_MASK SCM_STRUCTF_MASK |
da7f71d7 | 53 | |
82fe8ff1 MD |
54 | #define SCM_CLASSF_ENTITY SCM_STRUCTF_ENTITY |
55 | /* Operator classes need to be identified in the evaluator. | |
56 | (Entities also have SCM_CLASSF_OPERATOR set in their vtable.) */ | |
57 | #define SCM_CLASSF_OPERATOR (1L << 29) | |
da7f71d7 MD |
58 | |
59 | #define SCM_I_OPERATORP(obj)\ | |
c209c88e | 60 | ((SCM_OBJ_CLASS_FLAGS (obj) & SCM_CLASSF_OPERATOR) != 0) |
da7f71d7 MD |
61 | #define SCM_OPERATOR_CLASS(obj)\ |
62 | ((struct scm_metaclass_operator *) SCM_STRUCT_DATA (obj)) | |
63 | #define SCM_OBJ_OPERATOR_CLASS(obj)\ | |
64 | ((struct scm_metaclass_operator *) SCM_STRUCT_VTABLE_DATA (obj)) | |
e34e12f0 | 65 | #define SCM_OPERATOR_PROCEDURE(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->procedure) |
dae5a1e9 | 66 | #define SCM_OPERATOR_SETTER(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->setter) |
da7f71d7 MD |
67 | |
68 | #define SCM_I_ENTITYP(obj)\ | |
c209c88e | 69 | ((SCM_OBJ_CLASS_FLAGS (obj) & SCM_CLASSF_ENTITY) != 0) |
e34e12f0 | 70 | #define SCM_ENTITY_PROCEDURE(obj) \ |
d8c40b9f | 71 | (SCM_PACK (SCM_STRUCT_DATA (obj) [scm_struct_i_procedure])) |
34d19ef6 | 72 | #define SCM_SET_ENTITY_PROCEDURE(obj, v) \ |
d8c40b9f DH |
73 | (SCM_STRUCT_DATA (obj) [scm_struct_i_procedure] = SCM_UNPACK (v)) |
74 | #define SCM_ENTITY_SETTER(obj) (SCM_PACK (SCM_STRUCT_DATA (obj)[scm_struct_i_setter])) | |
322ec19d ML |
75 | #define SCM_SET_ENTITY_SETTER(obj, v) \ |
76 | (SCM_STRUCT_DATA (obj) [scm_struct_i_setter] = SCM_UNPACK (v)) | |
1d9ee7c7 | 77 | |
2eafbe52 MD |
78 | #define SCM_SET_CLASS_DESTRUCTOR(c, d) SCM_SET_VTABLE_DESTRUCTOR (c, d) |
79 | #define SCM_SET_CLASS_INSTANCE_SIZE(c, s) \ | |
729dbac3 DH |
80 | (SCM_STRUCT_DATA (c)[scm_struct_i_size] \ |
81 | = (SCM_STRUCT_DATA (c) [scm_struct_i_size] & SCM_STRUCTF_MASK) | s) | |
2eafbe52 | 82 | |
da7f71d7 MD |
83 | /* {Operator classes} |
84 | * | |
85 | * Instances of operator classes can work as operators, i. e., they | |
86 | * can be applied to arguments just as if they were ordinary | |
87 | * procedures. | |
88 | * | |
89 | * For instances of operator classes, the procedures to be applied are | |
90 | * stored in four dedicated slots in the associated class object. | |
91 | * Which one is selected depends on the number of arguments in the | |
92 | * application. | |
93 | * | |
94 | * If zero arguments are passed, the first will be selected. | |
95 | * If one argument is passed, the second will be selected. | |
96 | * If two arguments are passed, the third will be selected. | |
97 | * If three or more arguments are passed, the fourth will be selected. | |
98 | * | |
99 | * This is complicated and may seem gratuitous but has to do with the | |
100 | * architecture of the evaluator. Using only one procedure would | |
101 | * result in a great deal less efficient application, loss of | |
102 | * tail-recursion and would be difficult to reconcile with the | |
103 | * debugging evaluator. | |
104 | * | |
105 | * Also, using this "forked" application in low-level code has the | |
106 | * advantage of speeding up some code. An example is method dispatch | |
107 | * for generic operators applied to few arguments. On the user level, | |
108 | * the "forked" application will be hidden by mechanisms in the GOOPS | |
109 | * package. | |
110 | * | |
111 | * Operator classes have the metaclass <operator-metaclass>. | |
112 | * | |
113 | * An example of an operator class is the class <tk-command>. | |
114 | */ | |
aa3bdf59 | 115 | #define SCM_METACLASS_STANDARD_LAYOUT "" |
1d9ee7c7 MD |
116 | struct scm_metaclass_standard { |
117 | SCM layout; | |
118 | SCM vcell; | |
119 | SCM vtable; | |
120 | SCM print; | |
1d9ee7c7 MD |
121 | }; |
122 | ||
e34e12f0 | 123 | #define SCM_METACLASS_OPERATOR_LAYOUT "popo" |
da7f71d7 MD |
124 | struct scm_metaclass_operator { |
125 | SCM layout; | |
126 | SCM vcell; | |
127 | SCM vtable; | |
128 | SCM print; | |
e34e12f0 | 129 | SCM procedure; |
dae5a1e9 | 130 | SCM setter; |
da7f71d7 MD |
131 | }; |
132 | ||
133 | /* {Entity classes} | |
134 | * | |
135 | * For instances of entity classes (entities), the procedures to be | |
136 | * applied are stored in the instance itself rather than in the class | |
137 | * object as is the case for instances of operator classes (see above). | |
138 | * | |
139 | * An example of an entity class is the class of generic methods. | |
140 | */ | |
82fe8ff1 | 141 | #define SCM_ENTITY_LAYOUT "" |
1d9ee7c7 | 142 | |
6ee350ad MD |
143 | /* {Interface to Goops} |
144 | * | |
145 | * The evaluator contains a multi-method dispatch mechanism. | |
146 | * This interface is used by that mechanism and during creation of | |
147 | * smob and struct classes. | |
148 | */ | |
149 | ||
150 | /* Internal representation of Goops objects. */ | |
a43a8375 MD |
151 | #define SCM_CLASSF_PURE_GENERIC (0x010 << 20) |
152 | #define SCM_CLASSF_GOOPS_VALID (0x080 << 20) | |
153 | #define SCM_CLASSF_GOOPS (0x100 << 20) | |
e9385404 MV |
154 | #define scm_si_redefined 5 |
155 | #define scm_si_hashsets 6 | |
a43a8375 | 156 | #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x) |
1c3e63f0 | 157 | #define SCM_OBJ_CLASS_REDEF(x) (SCM_PACK (SCM_STRUCT_VTABLE_DATA (x) [scm_si_redefined])) |
dae5a1e9 | 158 | |
f0574557 MD |
159 | typedef struct scm_effective_slot_definition { |
160 | SCM name; | |
161 | long location; | |
162 | SCM init_value; | |
163 | SCM (*get) (SCM obj, SCM slotdef); | |
164 | SCM (*set) (SCM obj, SCM slotdef, SCM value); | |
165 | } scm_effective_slot_definition; | |
166 | ||
167 | #define SCM_ESLOTDEF(x) ((scm_effective_slot_definition *) SCM_CDR (x)) | |
168 | ||
9de33deb | 169 | #define SCM_CMETHOD_CODE(cmethod) SCM_CDR (cmethod) |
f12745b6 DH |
170 | #define SCM_CMETHOD_FORMALS(cmethod) SCM_CAR (SCM_CMETHOD_CODE (cmethod)) |
171 | #define SCM_CMETHOD_BODY(cmethod) SCM_CDR (SCM_CMETHOD_CODE (cmethod)) | |
9de33deb MD |
172 | #define SCM_CMETHOD_ENV(cmethod) SCM_CAR (cmethod) |
173 | ||
d0efbe61 | 174 | /* Port classes */ |
5bb2d903 LC |
175 | #define SCM_IN_PCLASS_INDEX 0 |
176 | #define SCM_OUT_PCLASS_INDEX SCM_I_MAX_PORT_TYPE_COUNT | |
177 | #define SCM_INOUT_PCLASS_INDEX (2 * SCM_I_MAX_PORT_TYPE_COUNT) | |
d0efbe61 | 178 | |
6ee350ad | 179 | /* Plugin proxy classes for basic types. */ |
33b001fd MV |
180 | SCM_API SCM scm_metaclass_standard; |
181 | SCM_API SCM scm_metaclass_operator; | |
9de33deb | 182 | |
5e890431 | 183 | /* Goops functions. */ |
da0e6c2b | 184 | SCM_API SCM scm_make_extended_class (char const *type_name, int applicablep); |
102dbb6f | 185 | SCM_INTERNAL void scm_i_inherit_applicable (SCM c); |
33b001fd MV |
186 | SCM_API void scm_make_port_classes (long ptobnum, char *type_name); |
187 | SCM_API void scm_change_object_class (SCM, SCM, SCM); | |
188 | SCM_API SCM scm_memoize_method (SCM x, SCM args); | |
189 | ||
33b001fd MV |
190 | SCM_API SCM scm_mcache_lookup_cmethod (SCM cache, SCM args); |
191 | SCM_API SCM scm_mcache_compute_cmethod (SCM cache, SCM args); | |
9de33deb | 192 | /* The following are declared in __scm.h |
33b001fd MV |
193 | SCM_API SCM scm_call_generic_0 (SCM gf); |
194 | SCM_API SCM scm_call_generic_1 (SCM gf, SCM a1); | |
195 | SCM_API SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2); | |
196 | SCM_API SCM scm_apply_generic (SCM gf, SCM args); | |
9de33deb | 197 | */ |
33b001fd MV |
198 | SCM_API SCM scm_call_generic_3 (SCM gf, SCM a1, SCM a2, SCM a3); |
199 | SCM_API SCM scm_entity_p (SCM obj); | |
200 | SCM_API SCM scm_operator_p (SCM obj); | |
201 | SCM_API SCM scm_valid_object_procedure_p (SCM proc); | |
202 | SCM_API SCM scm_set_object_procedure_x (SCM obj, SCM proc); | |
a43a8375 | 203 | #ifdef GUILE_DEBUG |
33b001fd | 204 | SCM_API SCM scm_object_procedure (SCM obj); |
a43a8375 | 205 | #endif |
33b001fd MV |
206 | SCM_API SCM scm_make_class_object (SCM metaclass, SCM layout); |
207 | SCM_API SCM scm_make_subclass_object (SCM c, SCM layout); | |
2d5881d5 | 208 | |
102dbb6f LC |
209 | SCM_INTERNAL SCM scm_i_make_class_object (SCM metaclass, SCM layout_string, |
210 | unsigned long flags); | |
211 | SCM_INTERNAL void scm_init_objects (void); | |
1d9ee7c7 | 212 | |
0527e687 | 213 | #endif /* SCM_OBJECTS_H */ |
89e00824 ML |
214 | |
215 | /* | |
216 | Local Variables: | |
217 | c-file-style: "gnu" | |
218 | End: | |
219 | */ |