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