Commit | Line | Data |
---|---|---|
1d9ee7c7 MD |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef OBJECTSH | |
4 | #define OBJECTSH | |
5 | ||
a54367e2 | 6 | /* Copyright (C) 1996, 1999, 2000 Free Software Foundation, Inc. |
1d9ee7c7 MD |
7 | * |
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. | |
12 | * | |
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. | |
17 | * | |
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. */ | |
46 | \f | |
47 | ||
da7f71d7 MD |
48 | /* This file and objects.c contains those minimal pieces of the Guile |
49 | * Object Oriented Programming System which need to be included in | |
50 | * libguile. | |
51 | * | |
52 | * {Objects and structs} | |
53 | * | |
54 | * Objects are currently based upon structs. Although the struct | |
55 | * implementation will change thoroughly in the future, objects will | |
56 | * still be based upon structs. | |
57 | */ | |
58 | ||
1d9ee7c7 MD |
59 | #include "libguile/__scm.h" |
60 | #include "libguile/struct.h" | |
61 | ||
62 | \f | |
63 | ||
da7f71d7 MD |
64 | /* {Class flags} |
65 | * | |
66 | * These are used for efficient identification of instances of a | |
67 | * certain class or its subclasses when traversal of the inheritance | |
68 | * graph would be too costly. | |
69 | */ | |
a54367e2 MD |
70 | #define SCM_CLASS_FLAGS(class)\ |
71 | SCM_ASWORD (SCM_STRUCT_DATA (class)[scm_struct_i_flags]) | |
da7f71d7 | 72 | #define SCM_OBJ_CLASS_FLAGS(obj)\ |
a54367e2 | 73 | SCM_ASWORD (SCM_STRUCT_VTABLE_DATA (obj)[scm_struct_i_flags]) |
da7f71d7 MD |
74 | #define SCM_SET_CLASS_FLAGS(c, f) (SCM_CLASS_FLAGS (c) |= (f)) |
75 | #define SCM_CLEAR_CLASS_FLAGS(c, f) (SCM_CLASS_FLAGS (c) &= ~(f)) | |
6ee350ad | 76 | #define SCM_CLASSF_MASK SCM_STRUCTF_MASK |
da7f71d7 | 77 | |
82fe8ff1 MD |
78 | #define SCM_CLASSF_ENTITY SCM_STRUCTF_ENTITY |
79 | /* Operator classes need to be identified in the evaluator. | |
80 | (Entities also have SCM_CLASSF_OPERATOR set in their vtable.) */ | |
81 | #define SCM_CLASSF_OPERATOR (1L << 29) | |
da7f71d7 MD |
82 | |
83 | #define SCM_I_OPERATORP(obj)\ | |
c209c88e | 84 | ((SCM_OBJ_CLASS_FLAGS (obj) & SCM_CLASSF_OPERATOR) != 0) |
da7f71d7 MD |
85 | #define SCM_OPERATOR_CLASS(obj)\ |
86 | ((struct scm_metaclass_operator *) SCM_STRUCT_DATA (obj)) | |
87 | #define SCM_OBJ_OPERATOR_CLASS(obj)\ | |
88 | ((struct scm_metaclass_operator *) SCM_STRUCT_VTABLE_DATA (obj)) | |
e34e12f0 | 89 | #define SCM_OPERATOR_PROCEDURE(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->procedure) |
dae5a1e9 | 90 | #define SCM_OPERATOR_SETTER(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->setter) |
da7f71d7 MD |
91 | |
92 | #define SCM_I_ENTITYP(obj)\ | |
c209c88e | 93 | ((SCM_OBJ_CLASS_FLAGS (obj) & SCM_CLASSF_ENTITY) != 0) |
e34e12f0 MD |
94 | #define SCM_ENTITY_PROCEDURE(obj) \ |
95 | (SCM_STRUCT_DATA (obj)[scm_struct_i_procedure]) | |
dae5a1e9 | 96 | #define SCM_ENTITY_SETTER(obj) (SCM_STRUCT_DATA (obj)[scm_struct_i_setter]) |
1d9ee7c7 | 97 | |
2eafbe52 MD |
98 | #define SCM_SET_CLASS_DESTRUCTOR(c, d) SCM_SET_VTABLE_DESTRUCTOR (c, d) |
99 | #define SCM_SET_CLASS_INSTANCE_SIZE(c, s) \ | |
100 | (SCM_STRUCT_DATA (c)[scm_struct_i_size] \ | |
a54367e2 MD |
101 | = SCM_ASSCM ((SCM_ASWORD (SCM_STRUCT_DATA (c)[scm_struct_i_size])\ |
102 | & SCM_STRUCTF_MASK)\ | |
103 | | s)) | |
2eafbe52 | 104 | |
da7f71d7 MD |
105 | /* {Operator classes} |
106 | * | |
107 | * Instances of operator classes can work as operators, i. e., they | |
108 | * can be applied to arguments just as if they were ordinary | |
109 | * procedures. | |
110 | * | |
111 | * For instances of operator classes, the procedures to be applied are | |
112 | * stored in four dedicated slots in the associated class object. | |
113 | * Which one is selected depends on the number of arguments in the | |
114 | * application. | |
115 | * | |
116 | * If zero arguments are passed, the first will be selected. | |
117 | * If one argument is passed, the second will be selected. | |
118 | * If two arguments are passed, the third will be selected. | |
119 | * If three or more arguments are passed, the fourth will be selected. | |
120 | * | |
121 | * This is complicated and may seem gratuitous but has to do with the | |
122 | * architecture of the evaluator. Using only one procedure would | |
123 | * result in a great deal less efficient application, loss of | |
124 | * tail-recursion and would be difficult to reconcile with the | |
125 | * debugging evaluator. | |
126 | * | |
127 | * Also, using this "forked" application in low-level code has the | |
128 | * advantage of speeding up some code. An example is method dispatch | |
129 | * for generic operators applied to few arguments. On the user level, | |
130 | * the "forked" application will be hidden by mechanisms in the GOOPS | |
131 | * package. | |
132 | * | |
133 | * Operator classes have the metaclass <operator-metaclass>. | |
134 | * | |
135 | * An example of an operator class is the class <tk-command>. | |
136 | */ | |
aa3bdf59 | 137 | #define SCM_METACLASS_STANDARD_LAYOUT "" |
1d9ee7c7 MD |
138 | struct scm_metaclass_standard { |
139 | SCM layout; | |
140 | SCM vcell; | |
141 | SCM vtable; | |
142 | SCM print; | |
1d9ee7c7 MD |
143 | }; |
144 | ||
e34e12f0 | 145 | #define SCM_METACLASS_OPERATOR_LAYOUT "popo" |
da7f71d7 MD |
146 | struct scm_metaclass_operator { |
147 | SCM layout; | |
148 | SCM vcell; | |
149 | SCM vtable; | |
150 | SCM print; | |
e34e12f0 | 151 | SCM procedure; |
dae5a1e9 | 152 | SCM setter; |
da7f71d7 MD |
153 | }; |
154 | ||
155 | /* {Entity classes} | |
156 | * | |
157 | * For instances of entity classes (entities), the procedures to be | |
158 | * applied are stored in the instance itself rather than in the class | |
159 | * object as is the case for instances of operator classes (see above). | |
160 | * | |
161 | * An example of an entity class is the class of generic methods. | |
162 | */ | |
82fe8ff1 | 163 | #define SCM_ENTITY_LAYOUT "" |
1d9ee7c7 | 164 | |
6ee350ad MD |
165 | /* {Interface to Goops} |
166 | * | |
167 | * The evaluator contains a multi-method dispatch mechanism. | |
168 | * This interface is used by that mechanism and during creation of | |
169 | * smob and struct classes. | |
170 | */ | |
171 | ||
172 | /* Internal representation of Goops objects. */ | |
a43a8375 MD |
173 | #define SCM_CLASSF_PURE_GENERIC (0x010 << 20) |
174 | #define SCM_CLASSF_GOOPS_VALID (0x080 << 20) | |
175 | #define SCM_CLASSF_GOOPS (0x100 << 20) | |
e34e12f0 MD |
176 | #define scm_si_redefined 6 |
177 | #define scm_si_hashsets 7 | |
a43a8375 MD |
178 | #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x) |
179 | #define SCM_OBJ_CLASS_REDEF(x) (SCM_STRUCT_VTABLE_DATA(x)[scm_si_redefined]) | |
dae5a1e9 | 180 | |
f0574557 MD |
181 | typedef struct scm_effective_slot_definition { |
182 | SCM name; | |
183 | long location; | |
184 | SCM init_value; | |
185 | SCM (*get) (SCM obj, SCM slotdef); | |
186 | SCM (*set) (SCM obj, SCM slotdef, SCM value); | |
187 | } scm_effective_slot_definition; | |
188 | ||
189 | #define SCM_ESLOTDEF(x) ((scm_effective_slot_definition *) SCM_CDR (x)) | |
190 | ||
9de33deb MD |
191 | #define SCM_CMETHOD_CODE(cmethod) SCM_CDR (cmethod) |
192 | #define SCM_CMETHOD_ENV(cmethod) SCM_CAR (cmethod) | |
193 | ||
d0efbe61 MD |
194 | /* Port classes */ |
195 | #define SCM_IN_PCLASS_INDEX 0x000 | |
196 | #define SCM_OUT_PCLASS_INDEX 0x100 | |
197 | #define SCM_INOUT_PCLASS_INDEX 0x200 | |
198 | ||
6ee350ad | 199 | /* Plugin proxy classes for basic types. */ |
1d9ee7c7 | 200 | extern SCM scm_metaclass_standard; |
da7f71d7 | 201 | extern SCM scm_metaclass_operator; |
dae5a1e9 MD |
202 | extern SCM scm_class_boolean, scm_class_char, scm_class_pair; |
203 | extern SCM scm_class_procedure, scm_class_string, scm_class_symbol; | |
9de33deb | 204 | extern SCM scm_class_procedure_with_setter, scm_class_primitive_generic; |
dae5a1e9 MD |
205 | extern SCM scm_class_vector, scm_class_null; |
206 | extern SCM scm_class_real, scm_class_complex, scm_class_integer; | |
6ee350ad | 207 | extern SCM scm_class_unknown; |
d0efbe61 | 208 | extern SCM *scm_port_class; |
6ee350ad | 209 | extern SCM *scm_smob_class; |
dae5a1e9 | 210 | |
9de33deb MD |
211 | extern SCM scm_no_applicable_method; |
212 | ||
6ee350ad MD |
213 | /* Plugin Goops functions. */ |
214 | extern SCM (*scm_make_extended_class) (char *type_name); | |
c1636627 | 215 | extern void (*scm_make_port_classes) (int ptobnum, char *type_name); |
dae5a1e9 | 216 | extern void (*scm_change_object_class) (SCM, SCM, SCM); |
9de33deb | 217 | extern SCM (*scm_memoize_method) (SCM x, SCM args); |
1d9ee7c7 | 218 | |
dae5a1e9 | 219 | extern SCM scm_class_of (SCM obj); |
9de33deb | 220 | extern SCM scm_mcache_lookup_cmethod (SCM cache, SCM args); |
e34e12f0 | 221 | extern SCM scm_mcache_compute_cmethod (SCM cache, SCM args); |
9de33deb MD |
222 | extern SCM scm_call_generic_0 (SCM gf); |
223 | /* The following are declared in __scm.h | |
224 | extern SCM scm_call_generic_1 (SCM gf, SCM a1); | |
225 | extern SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2); | |
226 | */ | |
227 | extern SCM scm_call_generic_3 (SCM gf, SCM a1, SCM a2, SCM a3); | |
228 | extern SCM scm_apply_generic (SCM gf, SCM args); | |
aa3bdf59 | 229 | extern SCM scm_entity_p (SCM obj); |
a43a8375 | 230 | extern SCM scm_operator_p (SCM obj); |
2d5881d5 | 231 | extern SCM scm_set_object_procedure_x (SCM obj, SCM procs); |
a43a8375 | 232 | #ifdef GUILE_DEBUG |
e34e12f0 | 233 | extern SCM scm_object_procedure (SCM obj); |
a43a8375 | 234 | #endif |
2d5881d5 | 235 | extern SCM scm_make_class_object (SCM metaclass, SCM layout); |
2eafbe52 | 236 | extern SCM scm_make_subclass_object (SCM c, SCM layout); |
2d5881d5 | 237 | |
036737fc MD |
238 | extern SCM scm_i_make_class_object (SCM metaclass, SCM layout_string, |
239 | unsigned long flags); | |
7866a09b | 240 | extern void scm_init_objects (void); |
1d9ee7c7 MD |
241 | |
242 | #endif /* OBJECTSH */ |