Commit | Line | Data |
---|---|---|
bab246f3 | 1 | /* Copyright (C) 1995,1996,1999,2000,2001 Free Software Foundation, Inc. |
1d9ee7c7 MD |
2 | * |
3 | * This program is free software; you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License as published by | |
5 | * the Free Software Foundation; either version 2, or (at your option) | |
6 | * any later version. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this software; see the file COPYING. If not, write to | |
15 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
16 | * Boston, MA 02111-1307 USA | |
17 | * | |
18 | * As a special exception, the Free Software Foundation gives permission | |
19 | * for additional uses of the text contained in its release of GUILE. | |
20 | * | |
21 | * The exception is that, if you link the GUILE library with other files | |
22 | * to produce an executable, this does not by itself cause the | |
23 | * resulting executable to be covered by the GNU General Public License. | |
24 | * Your use of that executable is in no way restricted on account of | |
25 | * linking the GUILE library code into it. | |
26 | * | |
27 | * This exception does not however invalidate any other reasons why | |
28 | * the executable file might be covered by the GNU General Public License. | |
29 | * | |
30 | * This exception applies only to the code released by the | |
31 | * Free Software Foundation under the name GUILE. If you copy | |
32 | * code from other Free Software Foundation releases into a copy of | |
33 | * GUILE, as the General Public License permits, the exception does | |
34 | * not apply to the code that you add in this way. To avoid misleading | |
35 | * anyone as to the status of such modified files, you must delete | |
36 | * this exception notice from them. | |
37 | * | |
38 | * If you write modifications of your own for GUILE, it is your choice | |
39 | * whether to permit this exception to apply to your modifications. | |
40 | * If you do not wish that, delete this exception notice. */ | |
1bbd0b84 | 41 | |
1bbd0b84 | 42 | |
1d9ee7c7 MD |
43 | \f |
44 | ||
da7f71d7 MD |
45 | /* This file and objects.h contains those minimal pieces of the Guile |
46 | * Object Oriented Programming System which need to be included in | |
47 | * libguile. See the comments in objects.h. | |
1d9ee7c7 MD |
48 | */ |
49 | ||
a0599745 MD |
50 | #include "libguile/_scm.h" |
51 | ||
52 | #include "libguile/struct.h" | |
53 | #include "libguile/procprop.h" | |
54 | #include "libguile/chars.h" | |
55 | #include "libguile/keywords.h" | |
56 | #include "libguile/smob.h" | |
57 | #include "libguile/eval.h" | |
58 | #include "libguile/alist.h" | |
59 | #include "libguile/ports.h" | |
60 | #include "libguile/strings.h" | |
61 | #include "libguile/vectors.h" | |
62 | ||
63 | #include "libguile/validate.h" | |
64 | #include "libguile/objects.h" | |
1d9ee7c7 MD |
65 | \f |
66 | ||
67 | SCM scm_metaclass_standard; | |
da7f71d7 | 68 | SCM scm_metaclass_operator; |
1d9ee7c7 | 69 | |
ab7288bc MD |
70 | /* These variables are filled in by the object system when loaded. */ |
71 | SCM scm_class_boolean, scm_class_char, scm_class_pair; | |
72 | SCM scm_class_procedure, scm_class_string, scm_class_symbol; | |
9de33deb | 73 | SCM scm_class_procedure_with_setter, scm_class_primitive_generic; |
ab7288bc | 74 | SCM scm_class_vector, scm_class_null; |
ed6e0c83 MD |
75 | SCM scm_class_integer, scm_class_real, scm_class_complex; |
76 | SCM scm_class_unknown; | |
ab7288bc | 77 | |
d0efbe61 | 78 | SCM *scm_port_class = 0; |
ed6e0c83 MD |
79 | SCM *scm_smob_class = 0; |
80 | ||
9de33deb MD |
81 | SCM scm_no_applicable_method; |
82 | ||
ab7288bc | 83 | /* This function is used for efficient type dispatch. */ |
398d8ee1 KN |
84 | SCM_DEFINE (scm_class_of, "class-of", 1, 0, 0, |
85 | (SCM x), | |
99ca0a7f | 86 | "Return the class of @var{x}.") |
398d8ee1 | 87 | #define FUNC_NAME s_scm_class_of |
ab7288bc MD |
88 | { |
89 | switch (SCM_ITAG3 (x)) | |
90 | { | |
91 | case scm_tc3_int_1: | |
92 | case scm_tc3_int_2: | |
93 | return scm_class_integer; | |
94 | ||
95 | case scm_tc3_imm24: | |
7866a09b | 96 | if (SCM_CHARP (x)) |
ab7288bc MD |
97 | return scm_class_char; |
98 | else | |
99 | { | |
100 | switch (SCM_ISYMNUM (x)) | |
101 | { | |
102 | case SCM_ISYMNUM (SCM_BOOL_F): | |
103 | case SCM_ISYMNUM (SCM_BOOL_T): | |
104 | return scm_class_boolean; | |
105 | case SCM_ISYMNUM (SCM_EOL): | |
106 | return scm_class_null; | |
107 | default: | |
108 | return scm_class_unknown; | |
109 | } | |
110 | } | |
111 | ||
112 | case scm_tc3_cons: | |
113 | switch (SCM_TYP7 (x)) | |
114 | { | |
115 | case scm_tcs_cons_nimcar: | |
116 | return scm_class_pair; | |
117 | case scm_tcs_closures: | |
118 | return scm_class_procedure; | |
28b06554 | 119 | case scm_tc7_symbol: |
ab7288bc MD |
120 | return scm_class_symbol; |
121 | case scm_tc7_vector: | |
122 | case scm_tc7_wvect: | |
afe5177e | 123 | #ifdef HAVE_ARRAYS |
ab7288bc MD |
124 | case scm_tc7_bvect: |
125 | case scm_tc7_byvect: | |
126 | case scm_tc7_svect: | |
127 | case scm_tc7_ivect: | |
128 | case scm_tc7_uvect: | |
129 | case scm_tc7_fvect: | |
130 | case scm_tc7_dvect: | |
131 | case scm_tc7_cvect: | |
afe5177e | 132 | #endif |
ab7288bc MD |
133 | return scm_class_vector; |
134 | case scm_tc7_string: | |
ab7288bc MD |
135 | return scm_class_string; |
136 | case scm_tc7_asubr: | |
137 | case scm_tc7_subr_0: | |
138 | case scm_tc7_subr_1: | |
139 | case scm_tc7_cxr: | |
140 | case scm_tc7_subr_3: | |
141 | case scm_tc7_subr_2: | |
142 | case scm_tc7_rpsubr: | |
143 | case scm_tc7_subr_1o: | |
144 | case scm_tc7_subr_2o: | |
145 | case scm_tc7_lsubr_2: | |
146 | case scm_tc7_lsubr: | |
9de33deb MD |
147 | if (SCM_SUBR_GENERIC (x) && *SCM_SUBR_GENERIC (x)) |
148 | return scm_class_primitive_generic; | |
149 | else | |
150 | return scm_class_procedure; | |
ed6e0c83 | 151 | case scm_tc7_cclo: |
ab7288bc MD |
152 | return scm_class_procedure; |
153 | case scm_tc7_pws: | |
154 | return scm_class_procedure_with_setter; | |
155 | ||
ab7288bc MD |
156 | case scm_tc7_smob: |
157 | { | |
5843e5c9 | 158 | scm_t_bits type = SCM_TYP16 (x); |
950cc72b | 159 | if (type != scm_tc16_port_with_ps) |
ed6e0c83 | 160 | return scm_smob_class[SCM_TC2SMOBNUM (type)]; |
55d54750 MD |
161 | x = SCM_PORT_WITH_PS_PORT (x); |
162 | /* fall through to ports */ | |
ab7288bc | 163 | } |
55d54750 | 164 | case scm_tc7_port: |
206d3de3 DH |
165 | return scm_port_class[(SCM_WRTNG & SCM_CELL_WORD_0 (x) |
166 | ? (SCM_RDNG & SCM_CELL_WORD_0 (x) | |
55d54750 MD |
167 | ? SCM_INOUT_PCLASS_INDEX | SCM_PTOBNUM (x) |
168 | : SCM_OUT_PCLASS_INDEX | SCM_PTOBNUM (x)) | |
169 | : SCM_IN_PCLASS_INDEX | SCM_PTOBNUM (x))]; | |
904a077d | 170 | case scm_tcs_struct: |
7151229d MD |
171 | if (SCM_OBJ_CLASS_FLAGS (x) & SCM_CLASSF_GOOPS_VALID) |
172 | return SCM_CLASS_OF (x); | |
173 | else if (SCM_OBJ_CLASS_FLAGS (x) & SCM_CLASSF_GOOPS) | |
ed6e0c83 MD |
174 | { |
175 | /* Goops object */ | |
54778cd3 | 176 | if (! SCM_FALSEP (SCM_OBJ_CLASS_REDEF (x))) |
ed6e0c83 MD |
177 | scm_change_object_class (x, |
178 | SCM_CLASS_OF (x), /* old */ | |
179 | SCM_OBJ_CLASS_REDEF (x)); /* new */ | |
180 | return SCM_CLASS_OF (x); | |
181 | } | |
182 | else | |
183 | { | |
184 | /* ordinary struct */ | |
185 | SCM handle = scm_struct_create_handle (SCM_STRUCT_VTABLE (x)); | |
5843e5c9 | 186 | if (!SCM_FALSEP (SCM_STRUCT_TABLE_CLASS (SCM_CDR (handle)))) |
ed6e0c83 MD |
187 | return SCM_STRUCT_TABLE_CLASS (SCM_CDR (handle)); |
188 | else | |
189 | { | |
190 | SCM name = SCM_STRUCT_TABLE_NAME (SCM_CDR (handle)); | |
5843e5c9 | 191 | SCM class = scm_make_extended_class (!SCM_FALSEP (name) |
b24b5e13 | 192 | ? SCM_SYMBOL_CHARS (name) |
ed6e0c83 | 193 | : 0); |
11f2a643 | 194 | SCM_SET_STRUCT_TABLE_CLASS (SCM_CDR (handle), class); |
ed6e0c83 MD |
195 | return class; |
196 | } | |
197 | } | |
ab7288bc MD |
198 | default: |
199 | if (SCM_CONSP (x)) | |
200 | return scm_class_pair; | |
201 | else | |
202 | return scm_class_unknown; | |
203 | } | |
204 | ||
904a077d | 205 | case scm_tc3_struct: |
ab7288bc MD |
206 | case scm_tc3_tc7_1: |
207 | case scm_tc3_tc7_2: | |
208 | case scm_tc3_closure: | |
209 | /* Never reached */ | |
210 | break; | |
211 | } | |
212 | return scm_class_unknown; | |
213 | } | |
398d8ee1 | 214 | #undef FUNC_NAME |
ab7288bc | 215 | |
5843e5c9 DH |
216 | /* The cache argument for scm_mcache_lookup_cmethod has one of two possible |
217 | * formats: | |
218 | * | |
219 | * Format #1: | |
220 | * (SCM_IM_DISPATCH ARGS N-SPECIALIZED | |
a12be546 MD |
221 | * #((TYPE1 ... ENV FORMALS FORM ...) ...) |
222 | * GF) | |
223 | * | |
5843e5c9 | 224 | * Format #2: |
a12be546 MD |
225 | * (SCM_IM_HASH_DISPATCH ARGS N-SPECIALIZED HASHSET MASK |
226 | * #((TYPE1 ... ENV FORMALS FORM ...) ...) | |
227 | * GF) | |
228 | * | |
229 | * ARGS is either a list of expressions, in which case they | |
230 | * are interpreted as the arguments of an application, or | |
231 | * a non-pair, which is interpreted as a single expression | |
232 | * yielding all arguments. | |
233 | * | |
234 | * SCM_IM_DISPATCH expressions in generic functions always | |
235 | * have ARGS = the symbol `args' or the iloc #@0-0. | |
236 | * | |
237 | * Need FORMALS in order to support varying arity. This | |
238 | * also avoids the need for renaming of bindings. | |
239 | * | |
240 | * We should probably not complicate this mechanism by | |
241 | * introducing "optimizations" for getters and setters or | |
242 | * primitive methods. Getters and setter will normally be | |
243 | * compiled into @slot-[ref|set!] or a procedure call. | |
244 | * They rely on the dispatch performed before executing | |
245 | * the code which contains them. | |
246 | * | |
247 | * We might want to use a more efficient representation of | |
248 | * this form in the future, perhaps after we have introduced | |
249 | * low-level support for syntax-case macros. | |
250 | */ | |
251 | ||
9de33deb MD |
252 | SCM |
253 | scm_mcache_lookup_cmethod (SCM cache, SCM args) | |
254 | { | |
c014a02e | 255 | long i, n, end, mask; |
9de33deb MD |
256 | SCM ls, methods, z = SCM_CDDR (cache); |
257 | n = SCM_INUM (SCM_CAR (z)); /* maximum number of specializers */ | |
258 | methods = SCM_CADR (z); | |
259 | ||
5843e5c9 | 260 | if (SCM_INUMP (methods)) |
9de33deb | 261 | { |
5843e5c9 | 262 | /* cache format #2: compute a hash value */ |
c014a02e ML |
263 | long hashset = SCM_INUM (methods); |
264 | long j = n; | |
bab246f3 DH |
265 | z = SCM_CDDR (z); |
266 | mask = SCM_INUM (SCM_CAR (z)); | |
9de33deb MD |
267 | methods = SCM_CADR (z); |
268 | i = 0; | |
269 | ls = args; | |
5843e5c9 | 270 | if (!SCM_NULLP (ls)) |
a12be546 MD |
271 | do |
272 | { | |
d8c40b9f DH |
273 | i += SCM_STRUCT_DATA (scm_class_of (SCM_CAR (ls))) |
274 | [scm_si_hashsets + hashset]; | |
a12be546 MD |
275 | ls = SCM_CDR (ls); |
276 | } | |
5843e5c9 | 277 | while (j-- && !SCM_NULLP (ls)); |
9de33deb MD |
278 | i &= mask; |
279 | end = i; | |
280 | } | |
5843e5c9 DH |
281 | else /* SCM_VECTORP (methods) */ |
282 | { | |
283 | /* cache format #1: prepare for linear search */ | |
284 | mask = -1; | |
285 | i = 0; | |
286 | end = SCM_VECTOR_LENGTH (methods); | |
287 | } | |
9de33deb MD |
288 | |
289 | /* Search for match */ | |
290 | do | |
291 | { | |
c014a02e | 292 | long j = n; |
9de33deb MD |
293 | z = SCM_VELTS (methods)[i]; |
294 | ls = args; /* list of arguments */ | |
5843e5c9 | 295 | if (!SCM_NULLP (ls)) |
a12be546 MD |
296 | do |
297 | { | |
298 | /* More arguments than specifiers => CLASS != ENV */ | |
54778cd3 | 299 | if (! SCM_EQ_P (scm_class_of (SCM_CAR (ls)), SCM_CAR (z))) |
a12be546 MD |
300 | goto next_method; |
301 | ls = SCM_CDR (ls); | |
302 | z = SCM_CDR (z); | |
303 | } | |
5843e5c9 | 304 | while (j-- && !SCM_NULLP (ls)); |
9de33deb | 305 | /* Fewer arguments than specifiers => CAR != ENV */ |
5843e5c9 DH |
306 | if (SCM_NULLP (SCM_CAR (z)) || SCM_CONSP (SCM_CAR (z))) |
307 | return z; | |
9de33deb MD |
308 | next_method: |
309 | i = (i + 1) & mask; | |
310 | } while (i != end); | |
311 | return SCM_BOOL_F; | |
312 | } | |
313 | ||
314 | SCM | |
a12be546 | 315 | scm_mcache_compute_cmethod (SCM cache, SCM args) |
9de33deb MD |
316 | { |
317 | SCM cmethod = scm_mcache_lookup_cmethod (cache, args); | |
5843e5c9 | 318 | if (SCM_FALSEP (cmethod)) |
9de33deb MD |
319 | /* No match - memoize */ |
320 | return scm_memoize_method (cache, args); | |
321 | return cmethod; | |
322 | } | |
323 | ||
324 | SCM | |
a12be546 | 325 | scm_apply_generic (SCM gf, SCM args) |
9de33deb | 326 | { |
a12be546 | 327 | SCM cmethod = scm_mcache_compute_cmethod (SCM_ENTITY_PROCEDURE (gf), args); |
9de33deb MD |
328 | return scm_eval_body (SCM_CDR (SCM_CMETHOD_CODE (cmethod)), |
329 | SCM_EXTEND_ENV (SCM_CAR (SCM_CMETHOD_CODE (cmethod)), | |
330 | args, | |
331 | SCM_CMETHOD_ENV (cmethod))); | |
332 | } | |
333 | ||
334 | SCM | |
a12be546 | 335 | scm_call_generic_0 (SCM gf) |
9de33deb | 336 | { |
a12be546 | 337 | return scm_apply_generic (gf, SCM_EOL); |
9de33deb MD |
338 | } |
339 | ||
340 | SCM | |
a12be546 | 341 | scm_call_generic_1 (SCM gf, SCM a1) |
9de33deb | 342 | { |
1afff620 | 343 | return scm_apply_generic (gf, scm_list_1 (a1)); |
9de33deb MD |
344 | } |
345 | ||
346 | SCM | |
a12be546 MD |
347 | scm_call_generic_2 (SCM gf, SCM a1, SCM a2) |
348 | { | |
1afff620 | 349 | return scm_apply_generic (gf, scm_list_2 (a1, a2)); |
a12be546 MD |
350 | } |
351 | ||
352 | SCM | |
353 | scm_call_generic_3 (SCM gf, SCM a1, SCM a2, SCM a3) | |
9de33deb | 354 | { |
1afff620 | 355 | return scm_apply_generic (gf, scm_list_3 (a1, a2, a3)); |
9de33deb MD |
356 | } |
357 | ||
a1ec6916 | 358 | SCM_DEFINE (scm_entity_p, "entity?", 1, 0, 0, |
1bbd0b84 | 359 | (SCM obj), |
99ca0a7f | 360 | "Return @code{#t} if @var{obj} is an entity.") |
1bbd0b84 | 361 | #define FUNC_NAME s_scm_entity_p |
19c0dec2 | 362 | { |
0c95b57d | 363 | return SCM_BOOL(SCM_STRUCTP (obj) && SCM_I_ENTITYP (obj)); |
19c0dec2 | 364 | } |
1bbd0b84 | 365 | #undef FUNC_NAME |
19c0dec2 | 366 | |
a1ec6916 | 367 | SCM_DEFINE (scm_operator_p, "operator?", 1, 0, 0, |
1bbd0b84 | 368 | (SCM obj), |
99ca0a7f | 369 | "Return @code{#t} if @var{obj} is an operator.") |
1bbd0b84 | 370 | #define FUNC_NAME s_scm_operator_p |
a43a8375 | 371 | { |
0b5f3f34 | 372 | return SCM_BOOL(SCM_STRUCTP (obj) |
1bbd0b84 GB |
373 | && SCM_I_OPERATORP (obj) |
374 | && !SCM_I_ENTITYP (obj)); | |
a43a8375 | 375 | } |
1bbd0b84 | 376 | #undef FUNC_NAME |
a43a8375 | 377 | |
cec0d28c MV |
378 | /* XXX - What code requires the object procedure to be only of certain |
379 | types? */ | |
380 | ||
381 | SCM_DEFINE (scm_valid_object_procedure_p, "valid-object-procedure?", 1, 0, 0, | |
382 | (SCM proc), | |
383 | "Return @code{#t} iff @var{proc} is a procedure that can be used " | |
384 | "with @code{set-object-procedure}. It is always valid to use " | |
385 | "a closure constructed by @code{lambda}.") | |
386 | #define FUNC_NAME s_scm_valid_object_procedure_p | |
387 | { | |
388 | if (SCM_IMP (proc)) | |
389 | return SCM_BOOL_F; | |
390 | switch (SCM_TYP7 (proc)) | |
391 | { | |
392 | default: | |
393 | return SCM_BOOL_F; | |
394 | case scm_tcs_closures: | |
395 | case scm_tc7_subr_1: | |
396 | case scm_tc7_subr_2: | |
397 | case scm_tc7_subr_3: | |
398 | case scm_tc7_lsubr_2: | |
399 | return SCM_BOOL_T; | |
400 | } | |
401 | } | |
402 | #undef FUNC_NAME | |
403 | ||
a1ec6916 | 404 | SCM_DEFINE (scm_set_object_procedure_x, "set-object-procedure!", 2, 0, 0, |
1bbd0b84 | 405 | (SCM obj, SCM proc), |
cec0d28c | 406 | "Set the object procedure of @var{obj} to @var{proc}.\n" |
99ca0a7f | 407 | "@var{obj} must be either an entity or an operator.") |
1bbd0b84 | 408 | #define FUNC_NAME s_scm_set_object_procedure_x |
47b21050 | 409 | { |
0c95b57d | 410 | SCM_ASSERT (SCM_STRUCTP (obj) |
c1a6fd8f MD |
411 | && ((SCM_CLASS_FLAGS (obj) & SCM_CLASSF_OPERATOR) |
412 | || (SCM_I_ENTITYP (obj) | |
413 | && !(SCM_OBJ_CLASS_FLAGS (obj) | |
414 | & SCM_CLASSF_PURE_GENERIC))), | |
47b21050 MD |
415 | obj, |
416 | SCM_ARG1, | |
1bbd0b84 | 417 | FUNC_NAME); |
cec0d28c | 418 | SCM_ASSERT (scm_valid_object_procedure_p (proc), proc, SCM_ARG2, FUNC_NAME); |
a12be546 | 419 | if (SCM_I_ENTITYP (obj)) |
d8c40b9f | 420 | SCM_SET_ENTITY_PROCEDURE (obj, proc); |
a12be546 MD |
421 | else |
422 | SCM_OPERATOR_CLASS (obj)->procedure = proc; | |
47b21050 MD |
423 | return SCM_UNSPECIFIED; |
424 | } | |
1bbd0b84 | 425 | #undef FUNC_NAME |
47b21050 | 426 | |
a43a8375 | 427 | #ifdef GUILE_DEBUG |
a1ec6916 | 428 | SCM_DEFINE (scm_object_procedure, "object-procedure", 1, 0, 0, |
1bbd0b84 | 429 | (SCM obj), |
99ca0a7f MG |
430 | "Return the object procedure of @var{obj}. @var{obj} must be\n" |
431 | "an entity or an operator.") | |
1bbd0b84 | 432 | #define FUNC_NAME s_scm_object_procedure |
a43a8375 | 433 | { |
0c95b57d | 434 | SCM_ASSERT (SCM_STRUCTP (obj) |
a12be546 MD |
435 | && ((SCM_CLASS_FLAGS (obj) & SCM_CLASSF_OPERATOR) |
436 | || SCM_I_ENTITYP (obj)), | |
1bbd0b84 | 437 | obj, SCM_ARG1, FUNC_NAME); |
a43a8375 | 438 | return (SCM_I_ENTITYP (obj) |
a12be546 MD |
439 | ? SCM_ENTITY_PROCEDURE (obj) |
440 | : SCM_OPERATOR_CLASS (obj)->procedure); | |
a43a8375 | 441 | } |
1bbd0b84 | 442 | #undef FUNC_NAME |
a43a8375 MD |
443 | #endif /* GUILE_DEBUG */ |
444 | ||
ed6e0c83 MD |
445 | /* The following procedures are not a part of Goops but a minimal |
446 | * object system built upon structs. They are here for those who | |
447 | * want to implement their own object system. | |
448 | */ | |
449 | ||
036737fc MD |
450 | SCM |
451 | scm_i_make_class_object (SCM meta, | |
452 | SCM layout_string, | |
c014a02e | 453 | unsigned long flags) |
47b21050 MD |
454 | { |
455 | SCM c; | |
036737fc | 456 | SCM layout = scm_make_struct_layout (layout_string); |
47b21050 MD |
457 | c = scm_make_struct (meta, |
458 | SCM_INUM0, | |
1afff620 | 459 | scm_list_4 (layout, SCM_BOOL_F, SCM_EOL, SCM_EOL)); |
47b21050 MD |
460 | SCM_SET_CLASS_FLAGS (c, flags); |
461 | return c; | |
462 | } | |
463 | ||
a1ec6916 | 464 | SCM_DEFINE (scm_make_class_object, "make-class-object", 2, 0, 0, |
1bbd0b84 | 465 | (SCM metaclass, SCM layout), |
99ca0a7f MG |
466 | "Create a new class object of class @var{metaclass}, with the\n" |
467 | "slot layout specified by @var{layout}.") | |
1bbd0b84 | 468 | #define FUNC_NAME s_scm_make_class_object |
47b21050 | 469 | { |
c014a02e | 470 | unsigned long flags = 0; |
34d19ef6 HWN |
471 | SCM_VALIDATE_STRUCT (1, metaclass); |
472 | SCM_VALIDATE_STRING (2, layout); | |
54778cd3 | 473 | if (SCM_EQ_P (metaclass, scm_metaclass_operator)) |
47b21050 | 474 | flags = SCM_CLASSF_OPERATOR; |
036737fc | 475 | return scm_i_make_class_object (metaclass, layout, flags); |
47b21050 | 476 | } |
1bbd0b84 | 477 | #undef FUNC_NAME |
47b21050 | 478 | |
a1ec6916 | 479 | SCM_DEFINE (scm_make_subclass_object, "make-subclass-object", 2, 0, 0, |
1bbd0b84 | 480 | (SCM class, SCM layout), |
99ca0a7f MG |
481 | "Create a subclass object of @var{class}, with the slot layout\n" |
482 | "specified by @var{layout}.") | |
1bbd0b84 | 483 | #define FUNC_NAME s_scm_make_subclass_object |
47b21050 MD |
484 | { |
485 | SCM pl; | |
34d19ef6 HWN |
486 | SCM_VALIDATE_STRUCT (1, class); |
487 | SCM_VALIDATE_STRING (2, layout); | |
d8c40b9f | 488 | pl = SCM_PACK (SCM_STRUCT_DATA (class) [scm_vtable_index_layout]); |
036737fc | 489 | /* Convert symbol->string */ |
36284627 | 490 | pl = scm_mem2string (SCM_SYMBOL_CHARS (pl), SCM_SYMBOL_LENGTH (pl)); |
036737fc | 491 | return scm_i_make_class_object (SCM_STRUCT_VTABLE (class), |
1afff620 | 492 | scm_string_append (scm_list_2 (pl, layout)), |
036737fc | 493 | SCM_CLASS_FLAGS (class)); |
47b21050 | 494 | } |
1bbd0b84 | 495 | #undef FUNC_NAME |
47b21050 | 496 | |
1d9ee7c7 MD |
497 | void |
498 | scm_init_objects () | |
499 | { | |
500 | SCM ms = scm_makfrom0str (SCM_METACLASS_STANDARD_LAYOUT); | |
3ce4544c | 501 | SCM mt = scm_make_vtable_vtable (ms, SCM_INUM0, |
1afff620 | 502 | scm_list_3 (SCM_BOOL_F, SCM_EOL, SCM_EOL)); |
1d9ee7c7 | 503 | |
da7f71d7 | 504 | SCM os = scm_makfrom0str (SCM_METACLASS_OPERATOR_LAYOUT); |
3ce4544c | 505 | SCM ot = scm_make_vtable_vtable (os, SCM_INUM0, |
1afff620 | 506 | scm_list_3 (SCM_BOOL_F, SCM_EOL, SCM_EOL)); |
da7f71d7 | 507 | |
1d9ee7c7 MD |
508 | SCM es = scm_makfrom0str (SCM_ENTITY_LAYOUT); |
509 | SCM el = scm_make_struct_layout (es); | |
510 | SCM et = scm_make_struct (mt, SCM_INUM0, | |
1afff620 | 511 | scm_list_4 (el, SCM_BOOL_F, SCM_EOL, SCM_EOL)); |
1d9ee7c7 | 512 | |
86d31dfe | 513 | scm_c_define ("<class>", mt); |
1d9ee7c7 | 514 | scm_metaclass_standard = mt; |
86d31dfe | 515 | scm_c_define ("<operator-class>", ot); |
da7f71d7 MD |
516 | scm_metaclass_operator = ot; |
517 | SCM_SET_CLASS_FLAGS (et, SCM_CLASSF_OPERATOR | SCM_CLASSF_ENTITY); | |
135e76f8 | 518 | SCM_SET_CLASS_DESTRUCTOR (et, scm_struct_free_entity); |
86d31dfe | 519 | scm_c_define ("<entity>", et); |
47b21050 | 520 | |
a0599745 | 521 | #include "libguile/objects.x" |
1d9ee7c7 | 522 | } |
89e00824 ML |
523 | |
524 | /* | |
525 | Local Variables: | |
526 | c-file-style: "gnu" | |
527 | End: | |
528 | */ |