Commit | Line | Data |
---|---|---|
2132f0d2 | 1 | /* Copyright (C) 1998,1999,2000,2001, 2002 Free Software Foundation, Inc. |
6d77c894 | 2 | * |
80662eda MD |
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. | |
6d77c894 | 7 | * |
80662eda MD |
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. | |
6d77c894 | 12 | * |
80662eda MD |
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. */ | |
41 | \f | |
42 | ||
43 | /* This software is a derivative work of other copyrighted softwares; the | |
44 | * copyright notices of these softwares are placed in the file COPYRIGHTS | |
45 | * | |
46 | * This file is based upon stklos.c from the STk distribution by | |
47 | * Erick Gallesio <eg@unice.fr>. | |
48 | */ | |
49 | ||
50 | #include <stdio.h> | |
51 | ||
52 | #include "libguile/_scm.h" | |
53 | #include "libguile/alist.h" | |
54 | #include "libguile/debug.h" | |
55 | #include "libguile/dynl.h" | |
56 | #include "libguile/dynwind.h" | |
57 | #include "libguile/eval.h" | |
58 | #include "libguile/hashtab.h" | |
59 | #include "libguile/keywords.h" | |
60 | #include "libguile/macros.h" | |
61 | #include "libguile/modules.h" | |
62 | #include "libguile/objects.h" | |
63 | #include "libguile/ports.h" | |
64 | #include "libguile/procprop.h" | |
65 | #include "libguile/random.h" | |
fdc28395 | 66 | #include "libguile/root.h" |
80662eda MD |
67 | #include "libguile/smob.h" |
68 | #include "libguile/strings.h" | |
69 | #include "libguile/strports.h" | |
70 | #include "libguile/vectors.h" | |
71 | #include "libguile/weaks.h" | |
72 | ||
ca83b028 | 73 | #include "libguile/validate.h" |
80662eda MD |
74 | #include "libguile/goops.h" |
75 | ||
80662eda MD |
76 | #define SPEC_OF(x) SCM_SLOT (x, scm_si_specializers) |
77 | ||
34d19ef6 | 78 | #define DEFVAR(v, val) \ |
1afff620 KN |
79 | { scm_eval (scm_list_3 (scm_sym_define_public, (v), (val)), \ |
80 | scm_module_goops); } | |
80662eda MD |
81 | /* Temporary hack until we get the new module system */ |
82 | /*fixme* Should optimize by keeping track of the variable object itself */ | |
fdc28395 KN |
83 | #define GETVAR(v) (SCM_VARIABLE_REF (scm_call_2 (scm_goops_lookup_closure, \ |
84 | (v), SCM_BOOL_F))) | |
80662eda MD |
85 | |
86 | /* Fixme: Should use already interned symbols */ | |
34d19ef6 | 87 | #define CALL_GF1(name, a) (scm_call_1 (GETVAR (scm_str2symbol (name)), \ |
1afff620 | 88 | a)) |
34d19ef6 | 89 | #define CALL_GF2(name, a, b) (scm_call_2 (GETVAR (scm_str2symbol (name)), \ |
1afff620 | 90 | a, b)) |
34d19ef6 | 91 | #define CALL_GF3(name, a, b, c) (scm_call_3 (GETVAR (scm_str2symbol (name)), \ |
1afff620 | 92 | a, b, c)) |
34d19ef6 | 93 | #define CALL_GF4(name, a, b, c, d) (scm_call_4 (GETVAR (scm_str2symbol (name)), \ |
1afff620 | 94 | a, b, c, d)) |
80662eda MD |
95 | |
96 | /* Class redefinition protocol: | |
97 | ||
98 | A class is represented by a heap header h1 which points to a | |
99 | malloc:ed memory block m1. | |
100 | ||
101 | When a new version of a class is created, a new header h2 and | |
102 | memory block m2 are allocated. The headers h1 and h2 then switch | |
103 | pointers so that h1 refers to m2 and h2 to m1. In this way, names | |
104 | bound to h1 will point to the new class at the same time as h2 will | |
105 | be a handle which the GC will us to free m1. | |
106 | ||
107 | The `redefined' slot of m1 will be set to point to h1. An old | |
108 | instance will have it's class pointer (the CAR of the heap header) | |
109 | pointing to m1. The non-immediate `redefined'-slot in m1 indicates | |
110 | the class modification and the new class pointer can be found via | |
111 | h1. | |
112 | */ | |
113 | ||
80662eda MD |
114 | /* The following definition is located in libguile/objects.h: |
115 | #define SCM_OBJ_CLASS_REDEF(x) (SCM_STRUCT_VTABLE_DATA(x)[scm_si_redefined]) | |
116 | */ | |
117 | ||
118 | #define TEST_CHANGE_CLASS(obj, class) \ | |
119 | { \ | |
120 | class = SCM_CLASS_OF (obj); \ | |
121 | if (SCM_OBJ_CLASS_REDEF (obj) != SCM_BOOL_F) \ | |
122 | CALL_GF3 ("change-object-class", \ | |
123 | obj, class, SCM_OBJ_CLASS_REDEF (obj)); \ | |
124 | } | |
125 | ||
126 | #define NXT_MTHD_METHODS(m) (SCM_VELTS (m)[1]) | |
127 | #define NXT_MTHD_ARGS(m) (SCM_VELTS (m)[2]) | |
128 | ||
129 | #define SCM_GOOPS_UNBOUND SCM_UNBOUND | |
130 | #define SCM_GOOPS_UNBOUNDP(x) ((x) == SCM_GOOPS_UNBOUND) | |
131 | ||
132 | static int goops_loaded_p = 0; | |
92c2555f | 133 | static scm_t_rstate *goops_rstate; |
80662eda MD |
134 | |
135 | static SCM scm_goops_lookup_closure; | |
136 | ||
137 | /* Some classes are defined in libguile/objects.c. */ | |
138 | SCM scm_class_top, scm_class_object, scm_class_class; | |
139 | SCM scm_class_entity, scm_class_entity_with_setter; | |
140 | SCM scm_class_generic, scm_class_generic_with_setter, scm_class_method; | |
141 | SCM scm_class_simple_method, scm_class_accessor; | |
142 | SCM scm_class_procedure_class; | |
143 | SCM scm_class_operator_class, scm_class_operator_with_setter_class; | |
144 | SCM scm_class_entity_class; | |
145 | SCM scm_class_number, scm_class_list; | |
146 | SCM scm_class_keyword; | |
147 | SCM scm_class_port, scm_class_input_output_port; | |
148 | SCM scm_class_input_port, scm_class_output_port; | |
149 | SCM scm_class_foreign_class, scm_class_foreign_object; | |
150 | SCM scm_class_foreign_slot; | |
151 | SCM scm_class_self, scm_class_protected; | |
152 | SCM scm_class_opaque, scm_class_read_only; | |
153 | SCM scm_class_protected_opaque, scm_class_protected_read_only; | |
154 | SCM scm_class_scm; | |
155 | SCM scm_class_int, scm_class_float, scm_class_double; | |
156 | ||
157 | SCM_SYMBOL (scm_sym_define_public, "define-public"); | |
158 | ||
159 | static SCM scm_make_unbound (void); | |
160 | static SCM scm_unbound_p (SCM obj); | |
398d8ee1 KN |
161 | static SCM scm_assert_bound (SCM value, SCM obj); |
162 | static SCM scm_at_assert_bound_ref (SCM obj, SCM index); | |
163 | static SCM scm_sys_goops_loaded (void); | |
80662eda MD |
164 | |
165 | /****************************************************************************** | |
166 | * | |
167 | * Compute-cpl | |
168 | * | |
169 | * This version doesn't handle multiple-inheritance. It serves only for | |
dcb410ec | 170 | * booting classes and will be overloaded in Scheme |
80662eda MD |
171 | * |
172 | ******************************************************************************/ | |
173 | ||
174 | #if 0 | |
175 | static SCM | |
176 | compute_cpl (SCM supers, SCM res) | |
177 | { | |
178 | return (SCM_NULLP (supers) | |
179 | ? scm_reverse (res) | |
180 | : compute_cpl (SCM_SLOT (SCM_CAR (supers), scm_si_direct_supers), | |
181 | scm_cons (SCM_CAR (supers), res))); | |
182 | } | |
183 | #endif | |
184 | ||
185 | static SCM | |
186 | map (SCM (*proc) (SCM), SCM ls) | |
187 | { | |
6b80d352 | 188 | if (SCM_NULLP (ls)) |
80662eda | 189 | return ls; |
6b80d352 DH |
190 | else |
191 | { | |
192 | SCM res = scm_cons (proc (SCM_CAR (ls)), SCM_EOL); | |
193 | SCM h = res; | |
194 | ls = SCM_CDR (ls); | |
195 | while (!SCM_NULLP (ls)) | |
196 | { | |
197 | SCM_SETCDR (h, scm_cons (proc (SCM_CAR (ls)), SCM_EOL)); | |
198 | h = SCM_CDR (h); | |
199 | ls = SCM_CDR (ls); | |
200 | } | |
201 | return res; | |
202 | } | |
80662eda MD |
203 | } |
204 | ||
205 | static SCM | |
206 | filter_cpl (SCM ls) | |
207 | { | |
208 | SCM res = SCM_EOL; | |
6b80d352 | 209 | while (!SCM_NULLP (ls)) |
80662eda MD |
210 | { |
211 | SCM el = SCM_CAR (ls); | |
79a3dafe | 212 | if (SCM_FALSEP (scm_c_memq (el, res))) |
80662eda MD |
213 | res = scm_cons (el, res); |
214 | ls = SCM_CDR (ls); | |
215 | } | |
216 | return res; | |
217 | } | |
218 | ||
219 | static SCM | |
220 | compute_cpl (SCM class) | |
221 | { | |
222 | if (goops_loaded_p) | |
223 | return CALL_GF1 ("compute-cpl", class); | |
224 | else | |
225 | { | |
226 | SCM supers = SCM_SLOT (class, scm_si_direct_supers); | |
227 | SCM ls = scm_append (scm_acons (class, supers, | |
228 | map (compute_cpl, supers))); | |
229 | return scm_reverse_x (filter_cpl (ls), SCM_EOL); | |
230 | } | |
231 | } | |
232 | ||
233 | /****************************************************************************** | |
234 | * | |
235 | * compute-slots | |
236 | * | |
237 | ******************************************************************************/ | |
238 | ||
239 | static SCM | |
240 | remove_duplicate_slots (SCM l, SCM res, SCM slots_already_seen) | |
241 | { | |
242 | SCM tmp; | |
243 | ||
244 | if (SCM_NULLP (l)) | |
245 | return res; | |
246 | ||
247 | tmp = SCM_CAAR (l); | |
c312aca7 | 248 | if (!SCM_SYMBOLP (tmp)) |
1afff620 | 249 | scm_misc_error ("%compute-slots", "bad slot name ~S", scm_list_1 (tmp)); |
6d77c894 | 250 | |
79a3dafe | 251 | if (SCM_FALSEP (scm_c_memq (tmp, slots_already_seen))) { |
80662eda MD |
252 | res = scm_cons (SCM_CAR (l), res); |
253 | slots_already_seen = scm_cons (tmp, slots_already_seen); | |
254 | } | |
6d77c894 | 255 | |
80662eda MD |
256 | return remove_duplicate_slots (SCM_CDR (l), res, slots_already_seen); |
257 | } | |
258 | ||
259 | static SCM | |
260 | build_slots_list (SCM dslots, SCM cpl) | |
261 | { | |
262 | register SCM res = dslots; | |
263 | ||
6b80d352 | 264 | for (cpl = SCM_CDR (cpl); !SCM_NULLP (cpl); cpl = SCM_CDR (cpl)) |
1afff620 KN |
265 | res = scm_append (scm_list_2 (SCM_SLOT (SCM_CAR (cpl), |
266 | scm_si_direct_slots), | |
267 | res)); | |
80662eda MD |
268 | |
269 | /* res contains a list of slots. Remove slots which appears more than once */ | |
270 | return remove_duplicate_slots (scm_reverse (res), SCM_EOL, SCM_EOL); | |
271 | } | |
272 | ||
273 | static SCM | |
274 | maplist (SCM ls) | |
275 | { | |
276 | SCM orig = ls; | |
6b80d352 | 277 | while (!SCM_NULLP (ls)) |
80662eda | 278 | { |
c312aca7 | 279 | if (!SCM_CONSP (SCM_CAR (ls))) |
80662eda MD |
280 | SCM_SETCAR (ls, scm_cons (SCM_CAR (ls), SCM_EOL)); |
281 | ls = SCM_CDR (ls); | |
282 | } | |
283 | return orig; | |
284 | } | |
285 | ||
80662eda | 286 | |
23437298 DH |
287 | SCM_DEFINE (scm_sys_compute_slots, "%compute-slots", 1, 0, 0, |
288 | (SCM class), | |
5352393c MG |
289 | "Return a list consisting of the names of all slots belonging to\n" |
290 | "class @var{class}, i. e. the slots of @var{class} and of all of\n" | |
6d77c894 | 291 | "its superclasses.") |
23437298 | 292 | #define FUNC_NAME s_scm_sys_compute_slots |
80662eda | 293 | { |
398d8ee1 | 294 | SCM_VALIDATE_CLASS (1, class); |
80662eda MD |
295 | return build_slots_list (SCM_SLOT (class, scm_si_direct_slots), |
296 | SCM_SLOT (class, scm_si_cpl)); | |
297 | } | |
23437298 DH |
298 | #undef FUNC_NAME |
299 | ||
80662eda MD |
300 | |
301 | /****************************************************************************** | |
302 | * | |
303 | * compute-getters-n-setters | |
6d77c894 TTN |
304 | * |
305 | * This version doesn't handle slot options. It serves only for booting | |
dcb410ec | 306 | * classes and will be overloaded in Scheme. |
80662eda MD |
307 | * |
308 | ******************************************************************************/ | |
309 | ||
310 | SCM_KEYWORD (k_init_value, "init-value"); | |
311 | SCM_KEYWORD (k_init_thunk, "init-thunk"); | |
312 | ||
313 | static SCM | |
314 | compute_getters_n_setters (SCM slots) | |
315 | { | |
316 | SCM res = SCM_EOL; | |
317 | SCM *cdrloc = &res; | |
c014a02e | 318 | long i = 0; |
80662eda | 319 | |
6b80d352 | 320 | for ( ; !SCM_NULLP (slots); slots = SCM_CDR (slots)) |
80662eda MD |
321 | { |
322 | SCM init = SCM_BOOL_F; | |
323 | SCM options = SCM_CDAR (slots); | |
6b80d352 | 324 | if (!SCM_NULLP (options)) |
80662eda MD |
325 | { |
326 | init = scm_get_keyword (k_init_value, options, 0); | |
327 | if (init) | |
1afff620 | 328 | init = scm_closure (scm_list_2 (SCM_EOL, init), SCM_EOL); |
80662eda MD |
329 | else |
330 | init = scm_get_keyword (k_init_thunk, options, SCM_BOOL_F); | |
331 | } | |
332 | *cdrloc = scm_cons (scm_cons (SCM_CAAR (slots), | |
333 | scm_cons (init, | |
334 | SCM_MAKINUM (i++))), | |
335 | SCM_EOL); | |
336 | cdrloc = SCM_CDRLOC (*cdrloc); | |
337 | } | |
338 | return res; | |
339 | } | |
340 | ||
341 | /****************************************************************************** | |
342 | * | |
343 | * initialize-object | |
344 | * | |
345 | ******************************************************************************/ | |
346 | ||
347 | /*fixme* Manufacture keywords in advance */ | |
348 | SCM | |
c014a02e | 349 | scm_i_get_keyword (SCM key, SCM l, long len, SCM default_value, const char *subr) |
80662eda | 350 | { |
c014a02e | 351 | long i; |
23437298 DH |
352 | |
353 | for (i = 0; i != len; i += 2) | |
80662eda | 354 | { |
23437298 DH |
355 | SCM obj = SCM_CAR (l); |
356 | ||
357 | if (!SCM_KEYWORDP (obj)) | |
1afff620 | 358 | scm_misc_error (subr, "bad keyword: ~S", scm_list_1 (obj)); |
23437298 | 359 | else if (SCM_EQ_P (obj, key)) |
80662eda | 360 | return SCM_CADR (l); |
23437298 DH |
361 | else |
362 | l = SCM_CDDR (l); | |
80662eda | 363 | } |
23437298 | 364 | |
80662eda MD |
365 | return default_value; |
366 | } | |
367 | ||
80662eda | 368 | |
23437298 DH |
369 | SCM_DEFINE (scm_get_keyword, "get-keyword", 3, 0, 0, |
370 | (SCM key, SCM l, SCM default_value), | |
5352393c MG |
371 | "Determine an associated value for the keyword @var{key} from\n" |
372 | "the list @var{l}. The list @var{l} has to consist of an even\n" | |
373 | "number of elements, where, starting with the first, every\n" | |
374 | "second element is a keyword, followed by its associated value.\n" | |
375 | "If @var{l} does not hold a value for @var{key}, the value\n" | |
376 | "@var{default_value} is returned.") | |
23437298 | 377 | #define FUNC_NAME s_scm_get_keyword |
80662eda | 378 | { |
c014a02e | 379 | long len; |
23437298 DH |
380 | |
381 | SCM_ASSERT (SCM_KEYWORDP (key), key, SCM_ARG1, FUNC_NAME); | |
80662eda | 382 | len = scm_ilength (l); |
b6311c08 | 383 | if (len < 0 || len % 2 == 1) |
1afff620 | 384 | scm_misc_error (FUNC_NAME, "Bad keyword-value list: ~S", scm_list_1 (l)); |
23437298 DH |
385 | |
386 | return scm_i_get_keyword (key, l, len, default_value, FUNC_NAME); | |
80662eda | 387 | } |
23437298 DH |
388 | #undef FUNC_NAME |
389 | ||
80662eda | 390 | |
80662eda MD |
391 | SCM_KEYWORD (k_init_keyword, "init-keyword"); |
392 | ||
393 | static SCM get_slot_value (SCM class, SCM obj, SCM slotdef); | |
394 | static SCM set_slot_value (SCM class, SCM obj, SCM slotdef, SCM value); | |
395 | ||
398d8ee1 KN |
396 | SCM_DEFINE (scm_sys_initialize_object, "%initialize-object", 2, 0, 0, |
397 | (SCM obj, SCM initargs), | |
6bcefd15 MG |
398 | "Initialize the object @var{obj} with the given arguments\n" |
399 | "@var{initargs}.") | |
398d8ee1 | 400 | #define FUNC_NAME s_scm_sys_initialize_object |
80662eda MD |
401 | { |
402 | SCM tmp, get_n_set, slots; | |
403 | SCM class = SCM_CLASS_OF (obj); | |
c014a02e | 404 | long n_initargs; |
80662eda | 405 | |
398d8ee1 | 406 | SCM_VALIDATE_INSTANCE (1, obj); |
80662eda | 407 | n_initargs = scm_ilength (initargs); |
398d8ee1 | 408 | SCM_ASSERT ((n_initargs & 1) == 0, initargs, SCM_ARG2, FUNC_NAME); |
6d77c894 | 409 | |
80662eda MD |
410 | get_n_set = SCM_SLOT (class, scm_si_getters_n_setters); |
411 | slots = SCM_SLOT (class, scm_si_slots); | |
6d77c894 | 412 | |
80662eda MD |
413 | /* See for each slot how it must be initialized */ |
414 | for (; | |
6b80d352 | 415 | !SCM_NULLP (slots); |
80662eda MD |
416 | get_n_set = SCM_CDR (get_n_set), slots = SCM_CDR (slots)) |
417 | { | |
418 | SCM slot_name = SCM_CAR (slots); | |
419 | SCM slot_value = 0; | |
6d77c894 | 420 | |
6b80d352 | 421 | if (!SCM_NULLP (SCM_CDR (slot_name))) |
80662eda MD |
422 | { |
423 | /* This slot admits (perhaps) to be initialized at creation time */ | |
c014a02e | 424 | long n = scm_ilength (SCM_CDR (slot_name)); |
80662eda | 425 | if (n & 1) /* odd or -1 */ |
398d8ee1 | 426 | SCM_MISC_ERROR ("class contains bogus slot definition: ~S", |
1afff620 | 427 | scm_list_1 (slot_name)); |
80662eda MD |
428 | tmp = scm_i_get_keyword (k_init_keyword, |
429 | SCM_CDR (slot_name), | |
430 | n, | |
431 | 0, | |
398d8ee1 | 432 | FUNC_NAME); |
80662eda MD |
433 | slot_name = SCM_CAR (slot_name); |
434 | if (tmp) | |
435 | { | |
436 | /* an initarg was provided for this slot */ | |
c312aca7 | 437 | if (!SCM_KEYWORDP (tmp)) |
398d8ee1 | 438 | SCM_MISC_ERROR ("initarg must be a keyword. It was ~S", |
1afff620 | 439 | scm_list_1 (tmp)); |
80662eda MD |
440 | slot_value = scm_i_get_keyword (tmp, |
441 | initargs, | |
442 | n_initargs, | |
443 | 0, | |
398d8ee1 | 444 | FUNC_NAME); |
80662eda MD |
445 | } |
446 | } | |
447 | ||
448 | if (slot_value) | |
449 | /* set slot to provided value */ | |
450 | set_slot_value (class, obj, SCM_CAR (get_n_set), slot_value); | |
451 | else | |
452 | { | |
453 | /* set slot to its :init-form if it exists */ | |
454 | tmp = SCM_CADAR (get_n_set); | |
455 | if (tmp != SCM_BOOL_F) | |
456 | { | |
457 | slot_value = get_slot_value (class, obj, SCM_CAR (get_n_set)); | |
458 | if (SCM_GOOPS_UNBOUNDP (slot_value)) | |
459 | { | |
460 | SCM env = SCM_EXTEND_ENV (SCM_EOL, SCM_EOL, SCM_ENV (tmp)); | |
461 | set_slot_value (class, | |
462 | obj, | |
463 | SCM_CAR (get_n_set), | |
f9450cdb | 464 | scm_eval_body (SCM_CLOSURE_BODY (tmp), env)); |
80662eda MD |
465 | } |
466 | } | |
467 | } | |
468 | } | |
6d77c894 | 469 | |
80662eda MD |
470 | return obj; |
471 | } | |
398d8ee1 | 472 | #undef FUNC_NAME |
80662eda MD |
473 | |
474 | ||
475 | SCM_KEYWORD (k_class, "class"); | |
476 | ||
398d8ee1 KN |
477 | SCM_DEFINE (scm_sys_prep_layout_x, "%prep-layout!", 1, 0, 0, |
478 | (SCM class), | |
479 | "") | |
480 | #define FUNC_NAME s_scm_sys_prep_layout_x | |
80662eda | 481 | { |
6b80d352 DH |
482 | SCM slots, nfields; |
483 | unsigned long int n, i; | |
484 | char *s; | |
80662eda | 485 | |
398d8ee1 | 486 | SCM_VALIDATE_INSTANCE (1, class); |
80662eda MD |
487 | slots = SCM_SLOT (class, scm_si_slots); |
488 | nfields = SCM_SLOT (class, scm_si_nfields); | |
489 | if (!SCM_INUMP (nfields) || SCM_INUM (nfields) < 0) | |
398d8ee1 | 490 | SCM_MISC_ERROR ("bad value in nfields slot: ~S", |
1afff620 | 491 | scm_list_1 (nfields)); |
80662eda MD |
492 | n = 2 * SCM_INUM (nfields); |
493 | if (n < sizeof (SCM_CLASS_CLASS_LAYOUT) - 1 | |
494 | && SCM_SUBCLASSP (class, scm_class_class)) | |
398d8ee1 | 495 | SCM_MISC_ERROR ("class object doesn't have enough fields: ~S", |
1afff620 | 496 | scm_list_1 (nfields)); |
6d77c894 | 497 | |
4c9419ac | 498 | s = n > 0 ? scm_malloc (n) : 0; |
80662eda MD |
499 | for (i = 0; i < n; i += 2) |
500 | { | |
6b80d352 DH |
501 | long len; |
502 | SCM type; | |
503 | char p, a; | |
504 | ||
c312aca7 | 505 | if (!SCM_CONSP (slots)) |
6b80d352 | 506 | SCM_MISC_ERROR ("too few slot definitions", SCM_EOL); |
80662eda MD |
507 | len = scm_ilength (SCM_CDAR (slots)); |
508 | type = scm_i_get_keyword (k_class, SCM_CDAR (slots), len, SCM_BOOL_F, | |
398d8ee1 | 509 | FUNC_NAME); |
6b80d352 | 510 | if (SCM_FALSEP (type)) |
80662eda | 511 | { |
6b80d352 DH |
512 | p = 'p'; |
513 | a = 'w'; | |
80662eda MD |
514 | } |
515 | else | |
516 | { | |
6b80d352 DH |
517 | if (!SCM_CLASSP (type)) |
518 | SCM_MISC_ERROR ("bad slot class", SCM_EOL); | |
519 | else if (SCM_SUBCLASSP (type, scm_class_foreign_slot)) | |
520 | { | |
521 | if (SCM_SUBCLASSP (type, scm_class_self)) | |
522 | p = 's'; | |
523 | else if (SCM_SUBCLASSP (type, scm_class_protected)) | |
524 | p = 'p'; | |
525 | else | |
526 | p = 'u'; | |
527 | ||
528 | if (SCM_SUBCLASSP (type, scm_class_opaque)) | |
529 | a = 'o'; | |
530 | else if (SCM_SUBCLASSP (type, scm_class_read_only)) | |
531 | a = 'r'; | |
532 | else | |
533 | a = 'w'; | |
534 | } | |
535 | else | |
536 | { | |
537 | p = 'p'; | |
538 | a = 'w'; | |
539 | } | |
80662eda MD |
540 | } |
541 | s[i] = p; | |
542 | s[i + 1] = a; | |
543 | slots = SCM_CDR (slots); | |
544 | } | |
dcb410ec | 545 | SCM_SET_SLOT (class, scm_si_layout, scm_mem2symbol (s, n)); |
80662eda | 546 | if (s) |
4c9419ac | 547 | free (s); |
80662eda MD |
548 | return SCM_UNSPECIFIED; |
549 | } | |
398d8ee1 | 550 | #undef FUNC_NAME |
80662eda MD |
551 | |
552 | static void prep_hashsets (SCM); | |
553 | ||
398d8ee1 KN |
554 | SCM_DEFINE (scm_sys_inherit_magic_x, "%inherit-magic!", 2, 0, 0, |
555 | (SCM class, SCM dsupers), | |
556 | "") | |
557 | #define FUNC_NAME s_scm_sys_inherit_magic_x | |
80662eda MD |
558 | { |
559 | SCM ls = dsupers; | |
c014a02e | 560 | long flags = 0; |
398d8ee1 | 561 | SCM_VALIDATE_INSTANCE (1, class); |
6b80d352 | 562 | while (!SCM_NULLP (ls)) |
80662eda | 563 | { |
c312aca7 | 564 | SCM_ASSERT (SCM_CONSP (ls) |
80662eda MD |
565 | && SCM_INSTANCEP (SCM_CAR (ls)), |
566 | dsupers, | |
567 | SCM_ARG2, | |
398d8ee1 | 568 | FUNC_NAME); |
80662eda MD |
569 | flags |= SCM_CLASS_FLAGS (SCM_CAR (ls)); |
570 | ls = SCM_CDR (ls); | |
571 | } | |
572 | flags &= SCM_CLASSF_INHERIT; | |
573 | if (flags & SCM_CLASSF_ENTITY) | |
574 | SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_entity); | |
575 | else | |
576 | { | |
c014a02e | 577 | long n = SCM_INUM (SCM_SLOT (class, scm_si_nfields)); |
80662eda MD |
578 | #if 0 |
579 | /* | |
4c9419ac | 580 | * We could avoid calling scm_gc_malloc in the allocation code |
80662eda MD |
581 | * (in which case the following two lines are needed). Instead |
582 | * we make 0-slot instances non-light, so that the light case | |
583 | * can be handled without special cases. | |
584 | */ | |
585 | if (n == 0) | |
586 | SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_0); | |
587 | #endif | |
588 | if (n > 0 && !(flags & SCM_CLASSF_METACLASS)) | |
589 | { | |
590 | /* NOTE: The following depends on scm_struct_i_size. */ | |
591 | flags |= SCM_STRUCTF_LIGHT + n * sizeof (SCM); /* use light representation */ | |
592 | SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_light); | |
593 | } | |
594 | } | |
595 | SCM_SET_CLASS_FLAGS (class, flags); | |
596 | ||
597 | prep_hashsets (class); | |
6d77c894 | 598 | |
80662eda MD |
599 | return SCM_UNSPECIFIED; |
600 | } | |
398d8ee1 | 601 | #undef FUNC_NAME |
80662eda MD |
602 | |
603 | void | |
604 | prep_hashsets (SCM class) | |
605 | { | |
dcb410ec | 606 | unsigned int i; |
80662eda MD |
607 | |
608 | for (i = 0; i < 7; ++i) | |
dcb410ec | 609 | SCM_SET_HASHSET (class, i, scm_c_uniform32 (goops_rstate)); |
80662eda MD |
610 | } |
611 | ||
612 | /******************************************************************************/ | |
613 | ||
614 | SCM | |
615 | scm_basic_basic_make_class (SCM class, SCM name, SCM dsupers, SCM dslots) | |
616 | { | |
617 | SCM z, cpl, slots, nfields, g_n_s; | |
618 | ||
619 | /* Allocate one instance */ | |
620 | z = scm_make_struct (class, SCM_INUM0, SCM_EOL); | |
621 | ||
622 | /* Initialize its slots */ | |
623 | #if 0 | |
1afff620 | 624 | cpl = compute_cpl (dsupers, scm_list_1 (z)); |
80662eda | 625 | #endif |
dcb410ec | 626 | SCM_SET_SLOT (z, scm_si_direct_supers, dsupers); |
80662eda MD |
627 | cpl = compute_cpl (z); |
628 | slots = build_slots_list (maplist (dslots), cpl); | |
629 | nfields = SCM_MAKINUM (scm_ilength (slots)); | |
630 | g_n_s = compute_getters_n_setters (slots); | |
631 | ||
dcb410ec DH |
632 | SCM_SET_SLOT (z, scm_si_name, name); |
633 | SCM_SET_SLOT (z, scm_si_direct_slots, dslots); | |
634 | SCM_SET_SLOT (z, scm_si_direct_subclasses, SCM_EOL); | |
635 | SCM_SET_SLOT (z, scm_si_direct_methods, SCM_EOL); | |
636 | SCM_SET_SLOT (z, scm_si_cpl, cpl); | |
637 | SCM_SET_SLOT (z, scm_si_slots, slots); | |
638 | SCM_SET_SLOT (z, scm_si_nfields, nfields); | |
639 | SCM_SET_SLOT (z, scm_si_getters_n_setters, g_n_s); | |
640 | SCM_SET_SLOT (z, scm_si_redefined, SCM_BOOL_F); | |
641 | SCM_SET_SLOT (z, scm_si_environment, | |
642 | scm_top_level_env (SCM_TOP_LEVEL_LOOKUP_CLOSURE)); | |
80662eda MD |
643 | |
644 | /* Add this class in the direct-subclasses slot of dsupers */ | |
645 | { | |
646 | SCM tmp; | |
dcb410ec DH |
647 | for (tmp = dsupers; !SCM_NULLP (tmp); tmp = SCM_CDR (tmp)) |
648 | SCM_SET_SLOT (SCM_CAR (tmp), scm_si_direct_subclasses, | |
649 | scm_cons (z, SCM_SLOT (SCM_CAR (tmp), | |
650 | scm_si_direct_subclasses))); | |
80662eda MD |
651 | } |
652 | ||
653 | /* Support for the underlying structs: */ | |
654 | SCM_SET_CLASS_FLAGS (z, (class == scm_class_entity_class | |
655 | ? (SCM_CLASSF_GOOPS_OR_VALID | |
656 | | SCM_CLASSF_OPERATOR | |
657 | | SCM_CLASSF_ENTITY) | |
658 | : class == scm_class_operator_class | |
659 | ? SCM_CLASSF_GOOPS_OR_VALID | SCM_CLASSF_OPERATOR | |
660 | : SCM_CLASSF_GOOPS_OR_VALID)); | |
661 | return z; | |
662 | } | |
663 | ||
664 | SCM | |
665 | scm_basic_make_class (SCM class, SCM name, SCM dsupers, SCM dslots) | |
666 | { | |
667 | SCM z = scm_basic_basic_make_class (class, name, dsupers, dslots); | |
668 | scm_sys_inherit_magic_x (z, dsupers); | |
669 | scm_sys_prep_layout_x (z); | |
670 | return z; | |
671 | } | |
672 | ||
673 | /******************************************************************************/ | |
674 | ||
6b80d352 DH |
675 | SCM_SYMBOL (sym_layout, "layout"); |
676 | SCM_SYMBOL (sym_vcell, "vcell"); | |
677 | SCM_SYMBOL (sym_vtable, "vtable"); | |
678 | SCM_SYMBOL (sym_print, "print"); | |
679 | SCM_SYMBOL (sym_procedure, "procedure"); | |
680 | SCM_SYMBOL (sym_setter, "setter"); | |
681 | SCM_SYMBOL (sym_redefined, "redefined"); | |
682 | SCM_SYMBOL (sym_h0, "h0"); | |
683 | SCM_SYMBOL (sym_h1, "h1"); | |
684 | SCM_SYMBOL (sym_h2, "h2"); | |
685 | SCM_SYMBOL (sym_h3, "h3"); | |
686 | SCM_SYMBOL (sym_h4, "h4"); | |
687 | SCM_SYMBOL (sym_h5, "h5"); | |
688 | SCM_SYMBOL (sym_h6, "h6"); | |
689 | SCM_SYMBOL (sym_h7, "h7"); | |
690 | SCM_SYMBOL (sym_name, "name"); | |
691 | SCM_SYMBOL (sym_direct_supers, "direct-supers"); | |
692 | SCM_SYMBOL (sym_direct_slots, "direct-slots"); | |
693 | SCM_SYMBOL (sym_direct_subclasses, "direct-subclasses"); | |
694 | SCM_SYMBOL (sym_direct_methods, "direct-methods"); | |
695 | SCM_SYMBOL (sym_cpl, "cpl"); | |
696 | SCM_SYMBOL (sym_default_slot_definition_class, "default-slot-definition-class"); | |
697 | SCM_SYMBOL (sym_slots, "slots"); | |
698 | SCM_SYMBOL (sym_getters_n_setters, "getters-n-setters"); | |
699 | SCM_SYMBOL (sym_keyword_access, "keyword-access"); | |
700 | SCM_SYMBOL (sym_nfields, "nfields"); | |
701 | SCM_SYMBOL (sym_environment, "environment"); | |
702 | ||
703 | ||
80662eda MD |
704 | static SCM |
705 | build_class_class_slots () | |
706 | { | |
6b80d352 DH |
707 | return scm_list_n ( |
708 | scm_list_3 (sym_layout, k_class, scm_class_protected_read_only), | |
6b80d352 DH |
709 | scm_list_3 (sym_vtable, k_class, scm_class_self), |
710 | scm_list_1 (sym_print), | |
711 | scm_list_3 (sym_procedure, k_class, scm_class_protected_opaque), | |
712 | scm_list_3 (sym_setter, k_class, scm_class_protected_opaque), | |
713 | scm_list_1 (sym_redefined), | |
714 | scm_list_3 (sym_h0, k_class, scm_class_int), | |
715 | scm_list_3 (sym_h1, k_class, scm_class_int), | |
716 | scm_list_3 (sym_h2, k_class, scm_class_int), | |
717 | scm_list_3 (sym_h3, k_class, scm_class_int), | |
718 | scm_list_3 (sym_h4, k_class, scm_class_int), | |
719 | scm_list_3 (sym_h5, k_class, scm_class_int), | |
720 | scm_list_3 (sym_h6, k_class, scm_class_int), | |
721 | scm_list_3 (sym_h7, k_class, scm_class_int), | |
722 | scm_list_1 (sym_name), | |
723 | scm_list_1 (sym_direct_supers), | |
724 | scm_list_1 (sym_direct_slots), | |
725 | scm_list_1 (sym_direct_subclasses), | |
726 | scm_list_1 (sym_direct_methods), | |
727 | scm_list_1 (sym_cpl), | |
728 | scm_list_1 (sym_default_slot_definition_class), | |
729 | scm_list_1 (sym_slots), | |
730 | scm_list_1 (sym_getters_n_setters), | |
731 | scm_list_1 (sym_keyword_access), | |
732 | scm_list_1 (sym_nfields), | |
733 | scm_list_1 (sym_environment), | |
734 | SCM_UNDEFINED); | |
80662eda MD |
735 | } |
736 | ||
737 | static void | |
738 | create_basic_classes (void) | |
739 | { | |
740 | /* SCM slots_of_class = build_class_class_slots (); */ | |
741 | ||
742 | /**** <scm_class_class> ****/ | |
743 | SCM cs = scm_makfrom0str (SCM_CLASS_CLASS_LAYOUT | |
744 | + 2 * scm_vtable_offset_user); | |
38ae064c | 745 | SCM name = scm_str2symbol ("<class>"); |
80662eda MD |
746 | scm_class_class = scm_permanent_object (scm_make_vtable_vtable (cs, |
747 | SCM_INUM0, | |
748 | SCM_EOL)); | |
749 | SCM_SET_CLASS_FLAGS (scm_class_class, (SCM_CLASSF_GOOPS_OR_VALID | |
750 | | SCM_CLASSF_METACLASS)); | |
751 | ||
dcb410ec DH |
752 | SCM_SET_SLOT (scm_class_class, scm_si_name, name); |
753 | SCM_SET_SLOT (scm_class_class, scm_si_direct_supers, SCM_EOL); /* will be changed */ | |
754 | /* SCM_SET_SLOT (scm_class_class, scm_si_direct_slots, slots_of_class); */ | |
755 | SCM_SET_SLOT (scm_class_class, scm_si_direct_subclasses, SCM_EOL); | |
6d77c894 | 756 | SCM_SET_SLOT (scm_class_class, scm_si_direct_methods, SCM_EOL); |
dcb410ec DH |
757 | SCM_SET_SLOT (scm_class_class, scm_si_cpl, SCM_EOL); /* will be changed */ |
758 | /* SCM_SET_SLOT (scm_class_class, scm_si_slots, slots_of_class); */ | |
759 | SCM_SET_SLOT (scm_class_class, scm_si_nfields, SCM_MAKINUM (SCM_N_CLASS_SLOTS)); | |
760 | /* SCM_SET_SLOT (scm_class_class, scm_si_getters_n_setters, | |
761 | compute_getters_n_setters (slots_of_class)); */ | |
762 | SCM_SET_SLOT (scm_class_class, scm_si_redefined, SCM_BOOL_F); | |
763 | SCM_SET_SLOT (scm_class_class, scm_si_environment, | |
764 | scm_top_level_env (SCM_TOP_LEVEL_LOOKUP_CLOSURE)); | |
80662eda MD |
765 | |
766 | prep_hashsets (scm_class_class); | |
767 | ||
768 | DEFVAR(name, scm_class_class); | |
769 | ||
770 | /**** <scm_class_top> ****/ | |
38ae064c | 771 | name = scm_str2symbol ("<top>"); |
80662eda MD |
772 | scm_class_top = scm_permanent_object (scm_basic_make_class (scm_class_class, |
773 | name, | |
774 | SCM_EOL, | |
775 | SCM_EOL)); | |
776 | ||
777 | DEFVAR(name, scm_class_top); | |
6d77c894 | 778 | |
80662eda | 779 | /**** <scm_class_object> ****/ |
38ae064c | 780 | name = scm_str2symbol ("<object>"); |
80662eda MD |
781 | scm_class_object = scm_permanent_object (scm_basic_make_class (scm_class_class, |
782 | name, | |
1afff620 | 783 | scm_list_1 (scm_class_top), |
80662eda MD |
784 | SCM_EOL)); |
785 | ||
786 | DEFVAR (name, scm_class_object); | |
787 | ||
788 | /* <top> <object> and <class> were partially initialized. Correct them here */ | |
1afff620 | 789 | SCM_SET_SLOT (scm_class_object, scm_si_direct_subclasses, scm_list_1 (scm_class_class)); |
80662eda | 790 | |
1afff620 KN |
791 | SCM_SET_SLOT (scm_class_class, scm_si_direct_supers, scm_list_1 (scm_class_object)); |
792 | SCM_SET_SLOT (scm_class_class, scm_si_cpl, scm_list_3 (scm_class_class, scm_class_object, scm_class_top)); | |
80662eda MD |
793 | } |
794 | ||
795 | /******************************************************************************/ | |
796 | ||
398d8ee1 KN |
797 | SCM_DEFINE (scm_instance_p, "instance?", 1, 0, 0, |
798 | (SCM obj), | |
6bcefd15 | 799 | "Return @code{#t} if @var{obj} is an instance.") |
398d8ee1 | 800 | #define FUNC_NAME s_scm_instance_p |
80662eda | 801 | { |
c312aca7 | 802 | return SCM_BOOL (SCM_INSTANCEP (obj)); |
80662eda | 803 | } |
398d8ee1 | 804 | #undef FUNC_NAME |
80662eda | 805 | |
80662eda MD |
806 | |
807 | /****************************************************************************** | |
6d77c894 | 808 | * |
80662eda MD |
809 | * Meta object accessors |
810 | * | |
811 | ******************************************************************************/ | |
398d8ee1 KN |
812 | SCM_DEFINE (scm_class_name, "class-name", 1, 0, 0, |
813 | (SCM obj), | |
6bcefd15 | 814 | "Return the class name of @var{obj}.") |
398d8ee1 | 815 | #define FUNC_NAME s_scm_class_name |
80662eda | 816 | { |
398d8ee1 | 817 | SCM_VALIDATE_CLASS (1, obj); |
6b80d352 | 818 | return scm_slot_ref (obj, sym_name); |
80662eda | 819 | } |
398d8ee1 | 820 | #undef FUNC_NAME |
80662eda | 821 | |
398d8ee1 KN |
822 | SCM_DEFINE (scm_class_direct_supers, "class-direct-supers", 1, 0, 0, |
823 | (SCM obj), | |
6bcefd15 | 824 | "Return the direct superclasses of the class @var{obj}.") |
398d8ee1 | 825 | #define FUNC_NAME s_scm_class_direct_supers |
80662eda | 826 | { |
398d8ee1 | 827 | SCM_VALIDATE_CLASS (1, obj); |
6b80d352 | 828 | return scm_slot_ref (obj, sym_direct_supers); |
80662eda | 829 | } |
398d8ee1 | 830 | #undef FUNC_NAME |
80662eda | 831 | |
398d8ee1 KN |
832 | SCM_DEFINE (scm_class_direct_slots, "class-direct-slots", 1, 0, 0, |
833 | (SCM obj), | |
6bcefd15 | 834 | "Return the direct slots of the class @var{obj}.") |
398d8ee1 | 835 | #define FUNC_NAME s_scm_class_direct_slots |
80662eda | 836 | { |
398d8ee1 | 837 | SCM_VALIDATE_CLASS (1, obj); |
6b80d352 | 838 | return scm_slot_ref (obj, sym_direct_slots); |
80662eda | 839 | } |
398d8ee1 | 840 | #undef FUNC_NAME |
80662eda | 841 | |
398d8ee1 KN |
842 | SCM_DEFINE (scm_class_direct_subclasses, "class-direct-subclasses", 1, 0, 0, |
843 | (SCM obj), | |
6bcefd15 | 844 | "Return the direct subclasses of the class @var{obj}.") |
398d8ee1 | 845 | #define FUNC_NAME s_scm_class_direct_subclasses |
80662eda | 846 | { |
398d8ee1 | 847 | SCM_VALIDATE_CLASS (1, obj); |
6b80d352 | 848 | return scm_slot_ref(obj, sym_direct_subclasses); |
80662eda | 849 | } |
398d8ee1 | 850 | #undef FUNC_NAME |
80662eda | 851 | |
398d8ee1 KN |
852 | SCM_DEFINE (scm_class_direct_methods, "class-direct-methods", 1, 0, 0, |
853 | (SCM obj), | |
6bcefd15 | 854 | "Return the direct methods of the class @var{obj}") |
398d8ee1 | 855 | #define FUNC_NAME s_scm_class_direct_methods |
80662eda | 856 | { |
398d8ee1 | 857 | SCM_VALIDATE_CLASS (1, obj); |
6b80d352 | 858 | return scm_slot_ref (obj, sym_direct_methods); |
80662eda | 859 | } |
398d8ee1 | 860 | #undef FUNC_NAME |
80662eda | 861 | |
398d8ee1 KN |
862 | SCM_DEFINE (scm_class_precedence_list, "class-precedence-list", 1, 0, 0, |
863 | (SCM obj), | |
6bcefd15 | 864 | "Return the class precedence list of the class @var{obj}.") |
398d8ee1 | 865 | #define FUNC_NAME s_scm_class_precedence_list |
80662eda | 866 | { |
398d8ee1 | 867 | SCM_VALIDATE_CLASS (1, obj); |
6b80d352 | 868 | return scm_slot_ref (obj, sym_cpl); |
80662eda | 869 | } |
398d8ee1 | 870 | #undef FUNC_NAME |
80662eda | 871 | |
398d8ee1 KN |
872 | SCM_DEFINE (scm_class_slots, "class-slots", 1, 0, 0, |
873 | (SCM obj), | |
6bcefd15 | 874 | "Return the slot list of the class @var{obj}.") |
398d8ee1 | 875 | #define FUNC_NAME s_scm_class_slots |
80662eda | 876 | { |
398d8ee1 | 877 | SCM_VALIDATE_CLASS (1, obj); |
6b80d352 | 878 | return scm_slot_ref (obj, sym_slots); |
80662eda | 879 | } |
398d8ee1 | 880 | #undef FUNC_NAME |
80662eda | 881 | |
398d8ee1 KN |
882 | SCM_DEFINE (scm_class_environment, "class-environment", 1, 0, 0, |
883 | (SCM obj), | |
6bcefd15 | 884 | "Return the environment of the class @var{obj}.") |
398d8ee1 | 885 | #define FUNC_NAME s_scm_class_environment |
80662eda | 886 | { |
398d8ee1 | 887 | SCM_VALIDATE_CLASS (1, obj); |
6b80d352 | 888 | return scm_slot_ref(obj, sym_environment); |
80662eda | 889 | } |
398d8ee1 | 890 | #undef FUNC_NAME |
80662eda MD |
891 | |
892 | ||
398d8ee1 KN |
893 | SCM_DEFINE (scm_generic_function_name, "generic-function-name", 1, 0, 0, |
894 | (SCM obj), | |
6bcefd15 | 895 | "Return the name of the generic function @var{obj}.") |
398d8ee1 | 896 | #define FUNC_NAME s_scm_generic_function_name |
80662eda | 897 | { |
398d8ee1 | 898 | SCM_VALIDATE_GENERIC (1, obj); |
80662eda MD |
899 | return scm_procedure_property (obj, scm_sym_name); |
900 | } | |
398d8ee1 | 901 | #undef FUNC_NAME |
80662eda | 902 | |
398d8ee1 KN |
903 | SCM_DEFINE (scm_generic_function_methods, "generic-function-methods", 1, 0, 0, |
904 | (SCM obj), | |
6bcefd15 | 905 | "Return the methods of the generic function @var{obj}.") |
398d8ee1 | 906 | #define FUNC_NAME s_scm_generic_function_methods |
80662eda | 907 | { |
398d8ee1 | 908 | SCM_VALIDATE_GENERIC (1, obj); |
38ae064c | 909 | return scm_slot_ref (obj, scm_str2symbol ("methods")); |
80662eda | 910 | } |
398d8ee1 | 911 | #undef FUNC_NAME |
80662eda MD |
912 | |
913 | ||
398d8ee1 KN |
914 | SCM_DEFINE (scm_method_generic_function, "method-generic-function", 1, 0, 0, |
915 | (SCM obj), | |
bb2c02f2 | 916 | "Return the generic function for the method @var{obj}.") |
398d8ee1 | 917 | #define FUNC_NAME s_scm_method_generic_function |
80662eda | 918 | { |
398d8ee1 | 919 | SCM_VALIDATE_METHOD (1, obj); |
38ae064c | 920 | return scm_slot_ref (obj, scm_str2symbol ("generic-function")); |
80662eda | 921 | } |
398d8ee1 | 922 | #undef FUNC_NAME |
80662eda | 923 | |
398d8ee1 KN |
924 | SCM_DEFINE (scm_method_specializers, "method-specializers", 1, 0, 0, |
925 | (SCM obj), | |
6bcefd15 | 926 | "Return specializers of the method @var{obj}.") |
398d8ee1 | 927 | #define FUNC_NAME s_scm_method_specializers |
80662eda | 928 | { |
398d8ee1 | 929 | SCM_VALIDATE_METHOD (1, obj); |
38ae064c | 930 | return scm_slot_ref (obj, scm_str2symbol ("specializers")); |
80662eda | 931 | } |
398d8ee1 | 932 | #undef FUNC_NAME |
80662eda | 933 | |
398d8ee1 KN |
934 | SCM_DEFINE (scm_method_procedure, "method-procedure", 1, 0, 0, |
935 | (SCM obj), | |
6bcefd15 | 936 | "Return the procedure of the method @var{obj}.") |
398d8ee1 | 937 | #define FUNC_NAME s_scm_method_procedure |
80662eda | 938 | { |
398d8ee1 | 939 | SCM_VALIDATE_METHOD (1, obj); |
6b80d352 | 940 | return scm_slot_ref (obj, sym_procedure); |
80662eda | 941 | } |
398d8ee1 | 942 | #undef FUNC_NAME |
80662eda | 943 | |
398d8ee1 KN |
944 | SCM_DEFINE (scm_accessor_method_slot_definition, "accessor-method-slot-definition", 1, 0, 0, |
945 | (SCM obj), | |
6bcefd15 | 946 | "Return the slot definition of the accessor @var{obj}.") |
398d8ee1 | 947 | #define FUNC_NAME s_scm_accessor_method_slot_definition |
80662eda | 948 | { |
398d8ee1 | 949 | SCM_VALIDATE_ACCESSOR (1, obj); |
38ae064c | 950 | return scm_slot_ref (obj, scm_str2symbol ("slot-definition")); |
398d8ee1 KN |
951 | } |
952 | #undef FUNC_NAME | |
80662eda | 953 | |
5e03762c MD |
954 | SCM_DEFINE (scm_sys_tag_body, "%tag-body", 1, 0, 0, |
955 | (SCM body), | |
87e7741d | 956 | "Internal GOOPS magic---don't use this function!") |
5e03762c MD |
957 | #define FUNC_NAME s_scm_sys_tag_body |
958 | { | |
959 | return scm_cons (SCM_IM_LAMBDA, body); | |
87e7741d MD |
960 | } |
961 | #undef FUNC_NAME | |
80662eda MD |
962 | |
963 | /****************************************************************************** | |
964 | * | |
965 | * S l o t a c c e s s | |
966 | * | |
967 | ******************************************************************************/ | |
968 | ||
398d8ee1 KN |
969 | SCM_DEFINE (scm_make_unbound, "make-unbound", 0, 0, 0, |
970 | (), | |
6bcefd15 | 971 | "Return the unbound value.") |
398d8ee1 | 972 | #define FUNC_NAME s_scm_make_unbound |
80662eda MD |
973 | { |
974 | return SCM_GOOPS_UNBOUND; | |
975 | } | |
398d8ee1 | 976 | #undef FUNC_NAME |
80662eda | 977 | |
398d8ee1 KN |
978 | SCM_DEFINE (scm_unbound_p, "unbound?", 1, 0, 0, |
979 | (SCM obj), | |
6bcefd15 | 980 | "Return @code{#t} if @var{obj} is unbound.") |
398d8ee1 | 981 | #define FUNC_NAME s_scm_unbound_p |
80662eda MD |
982 | { |
983 | return SCM_GOOPS_UNBOUNDP (obj) ? SCM_BOOL_T : SCM_BOOL_F; | |
984 | } | |
398d8ee1 | 985 | #undef FUNC_NAME |
80662eda | 986 | |
398d8ee1 KN |
987 | SCM_DEFINE (scm_assert_bound, "assert-bound", 2, 0, 0, |
988 | (SCM value, SCM obj), | |
6bcefd15 MG |
989 | "Return @var{value} if it is bound, and invoke the\n" |
990 | "@var{slot-unbound} method of @var{obj} if it is not.") | |
398d8ee1 | 991 | #define FUNC_NAME s_scm_assert_bound |
80662eda MD |
992 | { |
993 | if (SCM_GOOPS_UNBOUNDP (value)) | |
994 | return CALL_GF1 ("slot-unbound", obj); | |
995 | return value; | |
996 | } | |
398d8ee1 | 997 | #undef FUNC_NAME |
80662eda | 998 | |
398d8ee1 KN |
999 | SCM_DEFINE (scm_at_assert_bound_ref, "@assert-bound-ref", 2, 0, 0, |
1000 | (SCM obj, SCM index), | |
6bcefd15 MG |
1001 | "Like @code{assert-bound}, but use @var{index} for accessing\n" |
1002 | "the value from @var{obj}.") | |
398d8ee1 | 1003 | #define FUNC_NAME s_scm_at_assert_bound_ref |
80662eda MD |
1004 | { |
1005 | SCM value = SCM_SLOT (obj, SCM_INUM (index)); | |
1006 | if (SCM_GOOPS_UNBOUNDP (value)) | |
1007 | return CALL_GF1 ("slot-unbound", obj); | |
1008 | return value; | |
1009 | } | |
398d8ee1 | 1010 | #undef FUNC_NAME |
80662eda | 1011 | |
398d8ee1 KN |
1012 | SCM_DEFINE (scm_sys_fast_slot_ref, "%fast-slot-ref", 2, 0, 0, |
1013 | (SCM obj, SCM index), | |
6bcefd15 | 1014 | "Return the slot value with index @var{index} from @var{obj}.") |
398d8ee1 | 1015 | #define FUNC_NAME s_scm_sys_fast_slot_ref |
80662eda | 1016 | { |
6b80d352 | 1017 | unsigned long int i; |
80662eda | 1018 | |
398d8ee1 KN |
1019 | SCM_VALIDATE_INSTANCE (1, obj); |
1020 | SCM_VALIDATE_INUM (2, index); | |
6b80d352 | 1021 | SCM_ASSERT_RANGE (2, index, SCM_INUM (index) >= 0); |
80662eda | 1022 | i = SCM_INUM (index); |
6b80d352 DH |
1023 | SCM_ASSERT_RANGE (2, index, i < SCM_NUMBER_OF_SLOTS (obj)); |
1024 | ||
80662eda MD |
1025 | return scm_at_assert_bound_ref (obj, index); |
1026 | } | |
ca83b028 DH |
1027 | #undef FUNC_NAME |
1028 | ||
398d8ee1 KN |
1029 | SCM_DEFINE (scm_sys_fast_slot_set_x, "%fast-slot-set!", 3, 0, 0, |
1030 | (SCM obj, SCM index, SCM value), | |
6bcefd15 MG |
1031 | "Set the slot with index @var{index} in @var{obj} to\n" |
1032 | "@var{value}.") | |
398d8ee1 | 1033 | #define FUNC_NAME s_scm_sys_fast_slot_set_x |
80662eda | 1034 | { |
6b80d352 | 1035 | unsigned long int i; |
80662eda | 1036 | |
398d8ee1 KN |
1037 | SCM_VALIDATE_INSTANCE (1, obj); |
1038 | SCM_VALIDATE_INUM (2, index); | |
6b80d352 | 1039 | SCM_ASSERT_RANGE (2, index, SCM_INUM (index) >= 0); |
80662eda | 1040 | i = SCM_INUM (index); |
6b80d352 DH |
1041 | SCM_ASSERT_RANGE (2, index, i < SCM_NUMBER_OF_SLOTS (obj)); |
1042 | ||
dcb410ec | 1043 | SCM_SET_SLOT (obj, i, value); |
ca83b028 | 1044 | |
80662eda MD |
1045 | return SCM_UNSPECIFIED; |
1046 | } | |
ca83b028 DH |
1047 | #undef FUNC_NAME |
1048 | ||
80662eda MD |
1049 | |
1050 | /** Utilities **/ | |
1051 | ||
1052 | /* In the future, this function will return the effective slot | |
1053 | * definition associated with SLOT_NAME. Now it just returns some of | |
1054 | * the information which will be stored in the effective slot | |
1055 | * definition. | |
1056 | */ | |
1057 | ||
1058 | static SCM | |
1059 | slot_definition_using_name (SCM class, SCM slot_name) | |
1060 | { | |
1061 | register SCM slots = SCM_SLOT (class, scm_si_getters_n_setters); | |
6b80d352 | 1062 | for (; !SCM_NULLP (slots); slots = SCM_CDR (slots)) |
80662eda MD |
1063 | if (SCM_CAAR (slots) == slot_name) |
1064 | return SCM_CAR (slots); | |
1065 | return SCM_BOOL_F; | |
1066 | } | |
1067 | ||
1068 | static SCM | |
e81d98ec | 1069 | get_slot_value (SCM class SCM_UNUSED, SCM obj, SCM slotdef) |
80662eda MD |
1070 | { |
1071 | SCM access = SCM_CDDR (slotdef); | |
1072 | /* Two cases here: | |
1073 | * - access is an integer (the offset of this slot in the slots vector) | |
1074 | * - otherwise (car access) is the getter function to apply | |
23437298 | 1075 | */ |
80662eda MD |
1076 | if (SCM_INUMP (access)) |
1077 | return SCM_SLOT (obj, SCM_INUM (access)); | |
1078 | else | |
1079 | { | |
6d77c894 | 1080 | /* We must evaluate (apply (car access) (list obj)) |
80662eda MD |
1081 | * where (car access) is known to be a closure of arity 1 */ |
1082 | register SCM code, env; | |
1083 | ||
1084 | code = SCM_CAR (access); | |
1085 | if (!SCM_CLOSUREP (code)) | |
1086 | return SCM_SUBRF (code) (obj); | |
726d810a | 1087 | env = SCM_EXTEND_ENV (SCM_CLOSURE_FORMALS (code), |
1afff620 | 1088 | scm_list_1 (obj), |
80662eda MD |
1089 | SCM_ENV (code)); |
1090 | /* Evaluate the closure body */ | |
f9450cdb | 1091 | return scm_eval_body (SCM_CLOSURE_BODY (code), env); |
80662eda MD |
1092 | } |
1093 | } | |
1094 | ||
1095 | static SCM | |
1096 | get_slot_value_using_name (SCM class, SCM obj, SCM slot_name) | |
1097 | { | |
1098 | SCM slotdef = slot_definition_using_name (class, slot_name); | |
6b80d352 | 1099 | if (!SCM_FALSEP (slotdef)) |
80662eda MD |
1100 | return get_slot_value (class, obj, slotdef); |
1101 | else | |
1102 | return CALL_GF3 ("slot-missing", class, obj, slot_name); | |
1103 | } | |
1104 | ||
1105 | static SCM | |
e81d98ec | 1106 | set_slot_value (SCM class SCM_UNUSED, SCM obj, SCM slotdef, SCM value) |
80662eda MD |
1107 | { |
1108 | SCM access = SCM_CDDR (slotdef); | |
1109 | /* Two cases here: | |
1110 | * - access is an integer (the offset of this slot in the slots vector) | |
1111 | * - otherwise (cadr access) is the setter function to apply | |
1112 | */ | |
1113 | if (SCM_INUMP (access)) | |
dcb410ec | 1114 | SCM_SET_SLOT (obj, SCM_INUM (access), value); |
80662eda MD |
1115 | else |
1116 | { | |
1117 | /* We must evaluate (apply (cadr l) (list obj value)) | |
1118 | * where (cadr l) is known to be a closure of arity 2 */ | |
1119 | register SCM code, env; | |
1120 | ||
1121 | code = SCM_CADR (access); | |
1122 | if (!SCM_CLOSUREP (code)) | |
1123 | SCM_SUBRF (code) (obj, value); | |
1124 | else | |
1125 | { | |
726d810a | 1126 | env = SCM_EXTEND_ENV (SCM_CLOSURE_FORMALS (code), |
1afff620 | 1127 | scm_list_2 (obj, value), |
80662eda MD |
1128 | SCM_ENV (code)); |
1129 | /* Evaluate the closure body */ | |
f9450cdb | 1130 | scm_eval_body (SCM_CLOSURE_BODY (code), env); |
80662eda MD |
1131 | } |
1132 | } | |
1133 | return SCM_UNSPECIFIED; | |
1134 | } | |
1135 | ||
1136 | static SCM | |
1137 | set_slot_value_using_name (SCM class, SCM obj, SCM slot_name, SCM value) | |
1138 | { | |
1139 | SCM slotdef = slot_definition_using_name (class, slot_name); | |
6b80d352 | 1140 | if (!SCM_FALSEP (slotdef)) |
80662eda MD |
1141 | return set_slot_value (class, obj, slotdef, value); |
1142 | else | |
1143 | return CALL_GF4 ("slot-missing", class, obj, slot_name, value); | |
1144 | } | |
1145 | ||
1146 | static SCM | |
e81d98ec | 1147 | test_slot_existence (SCM class SCM_UNUSED, SCM obj, SCM slot_name) |
80662eda MD |
1148 | { |
1149 | register SCM l; | |
1150 | ||
729dbac3 DH |
1151 | for (l = SCM_ACCESSORS_OF (obj); !SCM_NULLP (l); l = SCM_CDR (l)) |
1152 | if (SCM_EQ_P (SCM_CAAR (l), slot_name)) | |
80662eda MD |
1153 | return SCM_BOOL_T; |
1154 | ||
1155 | return SCM_BOOL_F; | |
1156 | } | |
1157 | ||
80662eda MD |
1158 | /* ======================================== */ |
1159 | ||
23437298 DH |
1160 | SCM_DEFINE (scm_slot_ref_using_class, "slot-ref-using-class", 3, 0, 0, |
1161 | (SCM class, SCM obj, SCM slot_name), | |
1162 | "") | |
1163 | #define FUNC_NAME s_scm_slot_ref_using_class | |
80662eda MD |
1164 | { |
1165 | SCM res; | |
1166 | ||
398d8ee1 KN |
1167 | SCM_VALIDATE_CLASS (1, class); |
1168 | SCM_VALIDATE_INSTANCE (2, obj); | |
1169 | SCM_VALIDATE_SYMBOL (3, slot_name); | |
80662eda MD |
1170 | |
1171 | res = get_slot_value_using_name (class, obj, slot_name); | |
1172 | if (SCM_GOOPS_UNBOUNDP (res)) | |
1173 | return CALL_GF3 ("slot-unbound", class, obj, slot_name); | |
1174 | return res; | |
1175 | } | |
23437298 | 1176 | #undef FUNC_NAME |
80662eda | 1177 | |
23437298 DH |
1178 | |
1179 | SCM_DEFINE (scm_slot_set_using_class_x, "slot-set-using-class!", 4, 0, 0, | |
1180 | (SCM class, SCM obj, SCM slot_name, SCM value), | |
1181 | "") | |
1182 | #define FUNC_NAME s_scm_slot_set_using_class_x | |
80662eda | 1183 | { |
398d8ee1 KN |
1184 | SCM_VALIDATE_CLASS (1, class); |
1185 | SCM_VALIDATE_INSTANCE (2, obj); | |
1186 | SCM_VALIDATE_SYMBOL (3, slot_name); | |
23437298 | 1187 | |
80662eda MD |
1188 | return set_slot_value_using_name (class, obj, slot_name, value); |
1189 | } | |
23437298 DH |
1190 | #undef FUNC_NAME |
1191 | ||
80662eda | 1192 | |
398d8ee1 KN |
1193 | SCM_DEFINE (scm_slot_bound_using_class_p, "slot-bound-using-class?", 3, 0, 0, |
1194 | (SCM class, SCM obj, SCM slot_name), | |
1195 | "") | |
1196 | #define FUNC_NAME s_scm_slot_bound_using_class_p | |
80662eda | 1197 | { |
398d8ee1 KN |
1198 | SCM_VALIDATE_CLASS (1, class); |
1199 | SCM_VALIDATE_INSTANCE (2, obj); | |
1200 | SCM_VALIDATE_SYMBOL (3, slot_name); | |
80662eda MD |
1201 | |
1202 | return (SCM_GOOPS_UNBOUNDP (get_slot_value_using_name (class, obj, slot_name)) | |
1203 | ? SCM_BOOL_F | |
1204 | : SCM_BOOL_T); | |
1205 | } | |
398d8ee1 | 1206 | #undef FUNC_NAME |
80662eda | 1207 | |
398d8ee1 KN |
1208 | SCM_DEFINE (scm_slot_exists_using_class_p, "slot-exists-using-class?", 3, 0, 0, |
1209 | (SCM class, SCM obj, SCM slot_name), | |
1210 | "") | |
1211 | #define FUNC_NAME s_scm_slot_exists_using_class_p | |
1212 | { | |
1213 | SCM_VALIDATE_CLASS (1, class); | |
1214 | SCM_VALIDATE_INSTANCE (2, obj); | |
1215 | SCM_VALIDATE_SYMBOL (3, slot_name); | |
80662eda MD |
1216 | return test_slot_existence (class, obj, slot_name); |
1217 | } | |
398d8ee1 | 1218 | #undef FUNC_NAME |
80662eda MD |
1219 | |
1220 | ||
1221 | /* ======================================== */ | |
1222 | ||
398d8ee1 KN |
1223 | SCM_DEFINE (scm_slot_ref, "slot-ref", 2, 0, 0, |
1224 | (SCM obj, SCM slot_name), | |
6bcefd15 MG |
1225 | "Return the value from @var{obj}'s slot with the name\n" |
1226 | "@var{slot_name}.") | |
398d8ee1 | 1227 | #define FUNC_NAME s_scm_slot_ref |
80662eda MD |
1228 | { |
1229 | SCM res, class; | |
1230 | ||
398d8ee1 | 1231 | SCM_VALIDATE_INSTANCE (1, obj); |
80662eda MD |
1232 | TEST_CHANGE_CLASS (obj, class); |
1233 | ||
1234 | res = get_slot_value_using_name (class, obj, slot_name); | |
1235 | if (SCM_GOOPS_UNBOUNDP (res)) | |
1236 | return CALL_GF3 ("slot-unbound", class, obj, slot_name); | |
1237 | return res; | |
1238 | } | |
398d8ee1 | 1239 | #undef FUNC_NAME |
80662eda | 1240 | |
398d8ee1 KN |
1241 | SCM_DEFINE (scm_slot_set_x, "slot-set!", 3, 0, 0, |
1242 | (SCM obj, SCM slot_name, SCM value), | |
6bcefd15 | 1243 | "Set the slot named @var{slot_name} of @var{obj} to @var{value}.") |
398d8ee1 | 1244 | #define FUNC_NAME s_scm_slot_set_x |
80662eda MD |
1245 | { |
1246 | SCM class; | |
1247 | ||
398d8ee1 | 1248 | SCM_VALIDATE_INSTANCE (1, obj); |
80662eda MD |
1249 | TEST_CHANGE_CLASS(obj, class); |
1250 | ||
1251 | return set_slot_value_using_name (class, obj, slot_name, value); | |
1252 | } | |
398d8ee1 | 1253 | #undef FUNC_NAME |
80662eda | 1254 | |
398d8ee1 | 1255 | const char *scm_s_slot_set_x = s_scm_slot_set_x; |
80662eda | 1256 | |
398d8ee1 KN |
1257 | SCM_DEFINE (scm_slot_bound_p, "slot-bound?", 2, 0, 0, |
1258 | (SCM obj, SCM slot_name), | |
6bcefd15 MG |
1259 | "Return @code{#t} if the slot named @var{slot_name} of @var{obj}\n" |
1260 | "is bound.") | |
398d8ee1 | 1261 | #define FUNC_NAME s_scm_slot_bound_p |
80662eda MD |
1262 | { |
1263 | SCM class; | |
1264 | ||
398d8ee1 | 1265 | SCM_VALIDATE_INSTANCE (1, obj); |
80662eda MD |
1266 | TEST_CHANGE_CLASS(obj, class); |
1267 | ||
1268 | return (SCM_GOOPS_UNBOUNDP (get_slot_value_using_name (class, | |
1269 | obj, | |
1270 | slot_name)) | |
1271 | ? SCM_BOOL_F | |
1272 | : SCM_BOOL_T); | |
1273 | } | |
398d8ee1 | 1274 | #undef FUNC_NAME |
80662eda | 1275 | |
6d77c894 | 1276 | SCM_DEFINE (scm_slot_exists_p, "slot-exists?", 2, 0, 0, |
398d8ee1 | 1277 | (SCM obj, SCM slot_name), |
6bcefd15 | 1278 | "Return @code{#t} if @var{obj} has a slot named @var{slot_name}.") |
6d77c894 | 1279 | #define FUNC_NAME s_scm_slot_exists_p |
80662eda MD |
1280 | { |
1281 | SCM class; | |
1282 | ||
398d8ee1 KN |
1283 | SCM_VALIDATE_INSTANCE (1, obj); |
1284 | SCM_VALIDATE_SYMBOL (2, slot_name); | |
80662eda MD |
1285 | TEST_CHANGE_CLASS (obj, class); |
1286 | ||
1287 | return test_slot_existence (class, obj, slot_name); | |
1288 | } | |
398d8ee1 | 1289 | #undef FUNC_NAME |
80662eda MD |
1290 | |
1291 | ||
1292 | /****************************************************************************** | |
1293 | * | |
1294 | * %allocate-instance (the low level instance allocation primitive) | |
1295 | * | |
1296 | ******************************************************************************/ | |
1297 | ||
1298 | static void clear_method_cache (SCM); | |
1299 | ||
1300 | static SCM | |
c014a02e | 1301 | wrap_init (SCM class, SCM *m, long n) |
80662eda | 1302 | { |
c014a02e | 1303 | long i; |
6d77c894 | 1304 | |
80662eda MD |
1305 | /* Set all slots to unbound */ |
1306 | for (i = 0; i < n; i++) | |
1307 | m[i] = SCM_GOOPS_UNBOUND; | |
1308 | ||
228a24ef DH |
1309 | return scm_double_cell ((((scm_t_bits) SCM_STRUCT_DATA (class)) |
1310 | | scm_tc3_struct), | |
1311 | (scm_t_bits) m, 0, 0); | |
80662eda MD |
1312 | } |
1313 | ||
398d8ee1 KN |
1314 | SCM_DEFINE (scm_sys_allocate_instance, "%allocate-instance", 2, 0, 0, |
1315 | (SCM class, SCM initargs), | |
6bcefd15 MG |
1316 | "Create a new instance of class @var{class} and initialize it\n" |
1317 | "from the arguments @var{initargs}.") | |
398d8ee1 | 1318 | #define FUNC_NAME s_scm_sys_allocate_instance |
80662eda MD |
1319 | { |
1320 | SCM *m; | |
c014a02e | 1321 | long n; |
80662eda | 1322 | |
398d8ee1 | 1323 | SCM_VALIDATE_CLASS (1, class); |
80662eda MD |
1324 | |
1325 | /* Most instances */ | |
1326 | if (SCM_CLASS_FLAGS (class) & SCM_STRUCTF_LIGHT) | |
1327 | { | |
1328 | n = SCM_INUM (SCM_SLOT (class, scm_si_nfields)); | |
4c9419ac | 1329 | m = (SCM *) scm_gc_malloc (n * sizeof (SCM), "struct"); |
80662eda MD |
1330 | return wrap_init (class, m, n); |
1331 | } | |
6d77c894 | 1332 | |
80662eda MD |
1333 | /* Foreign objects */ |
1334 | if (SCM_CLASS_FLAGS (class) & SCM_CLASSF_FOREIGN) | |
1335 | return scm_make_foreign_object (class, initargs); | |
1336 | ||
1337 | n = SCM_INUM (SCM_SLOT (class, scm_si_nfields)); | |
6d77c894 | 1338 | |
80662eda MD |
1339 | /* Entities */ |
1340 | if (SCM_CLASS_FLAGS (class) & SCM_CLASSF_ENTITY) | |
1341 | { | |
4c9419ac MV |
1342 | m = (SCM *) scm_alloc_struct (n, scm_struct_entity_n_extra_words, |
1343 | "entity struct"); | |
80662eda MD |
1344 | m[scm_struct_i_setter] = SCM_BOOL_F; |
1345 | m[scm_struct_i_procedure] = SCM_BOOL_F; | |
1346 | /* Generic functions */ | |
1347 | if (SCM_CLASS_FLAGS (class) & SCM_CLASSF_PURE_GENERIC) | |
1348 | { | |
1349 | SCM gf = wrap_init (class, m, n); | |
1350 | clear_method_cache (gf); | |
1351 | return gf; | |
1352 | } | |
1353 | else | |
1354 | return wrap_init (class, m, n); | |
1355 | } | |
6d77c894 | 1356 | |
80662eda MD |
1357 | /* Class objects */ |
1358 | if (SCM_CLASS_FLAGS (class) & SCM_CLASSF_METACLASS) | |
1359 | { | |
c014a02e | 1360 | long i; |
80662eda MD |
1361 | |
1362 | /* allocate class object */ | |
1363 | SCM z = scm_make_struct (class, SCM_INUM0, SCM_EOL); | |
1364 | ||
dcb410ec | 1365 | SCM_SET_SLOT (z, scm_si_print, SCM_GOOPS_UNBOUND); |
80662eda | 1366 | for (i = scm_si_goops_fields; i < n; i++) |
dcb410ec | 1367 | SCM_SET_SLOT (z, i, SCM_GOOPS_UNBOUND); |
80662eda MD |
1368 | |
1369 | if (SCM_SUBCLASSP (class, scm_class_entity_class)) | |
1370 | SCM_SET_CLASS_FLAGS (z, SCM_CLASSF_OPERATOR | SCM_CLASSF_ENTITY); | |
1371 | else if (SCM_SUBCLASSP (class, scm_class_operator_class)) | |
1372 | SCM_SET_CLASS_FLAGS (z, SCM_CLASSF_OPERATOR); | |
1373 | ||
1374 | return z; | |
1375 | } | |
6d77c894 | 1376 | |
80662eda MD |
1377 | /* Non-light instances */ |
1378 | { | |
4c9419ac | 1379 | m = (SCM *) scm_alloc_struct (n, scm_struct_n_extra_words, "heavy struct"); |
80662eda MD |
1380 | return wrap_init (class, m, n); |
1381 | } | |
1382 | } | |
398d8ee1 | 1383 | #undef FUNC_NAME |
80662eda | 1384 | |
398d8ee1 KN |
1385 | SCM_DEFINE (scm_sys_set_object_setter_x, "%set-object-setter!", 2, 0, 0, |
1386 | (SCM obj, SCM setter), | |
1387 | "") | |
1388 | #define FUNC_NAME s_scm_sys_set_object_setter_x | |
80662eda | 1389 | { |
c312aca7 | 1390 | SCM_ASSERT (SCM_STRUCTP (obj) |
80662eda MD |
1391 | && ((SCM_CLASS_FLAGS (obj) & SCM_CLASSF_OPERATOR) |
1392 | || SCM_I_ENTITYP (obj)), | |
1393 | obj, | |
1394 | SCM_ARG1, | |
398d8ee1 | 1395 | FUNC_NAME); |
80662eda | 1396 | if (SCM_I_ENTITYP (obj)) |
322ec19d | 1397 | SCM_SET_ENTITY_SETTER (obj, setter); |
80662eda MD |
1398 | else |
1399 | SCM_OPERATOR_CLASS (obj)->setter = setter; | |
1400 | return SCM_UNSPECIFIED; | |
1401 | } | |
398d8ee1 | 1402 | #undef FUNC_NAME |
80662eda MD |
1403 | |
1404 | /****************************************************************************** | |
1405 | * | |
1406 | * %modify-instance (used by change-class to modify in place) | |
6d77c894 | 1407 | * |
80662eda MD |
1408 | ******************************************************************************/ |
1409 | ||
398d8ee1 KN |
1410 | SCM_DEFINE (scm_sys_modify_instance, "%modify-instance", 2, 0, 0, |
1411 | (SCM old, SCM new), | |
1412 | "") | |
1413 | #define FUNC_NAME s_scm_sys_modify_instance | |
80662eda | 1414 | { |
398d8ee1 KN |
1415 | SCM_VALIDATE_INSTANCE (1, old); |
1416 | SCM_VALIDATE_INSTANCE (2, new); | |
80662eda | 1417 | |
6d77c894 | 1418 | /* Exchange the data contained in old and new. We exchange rather than |
80662eda MD |
1419 | * scratch the old value with new to be correct with GC. |
1420 | * See "Class redefinition protocol above". | |
1421 | */ | |
1422 | SCM_REDEFER_INTS; | |
1423 | { | |
1424 | SCM car = SCM_CAR (old); | |
1425 | SCM cdr = SCM_CDR (old); | |
1426 | SCM_SETCAR (old, SCM_CAR (new)); | |
1427 | SCM_SETCDR (old, SCM_CDR (new)); | |
1428 | SCM_SETCAR (new, car); | |
1429 | SCM_SETCDR (new, cdr); | |
1430 | } | |
1431 | SCM_REALLOW_INTS; | |
1432 | return SCM_UNSPECIFIED; | |
1433 | } | |
398d8ee1 | 1434 | #undef FUNC_NAME |
80662eda | 1435 | |
398d8ee1 KN |
1436 | SCM_DEFINE (scm_sys_modify_class, "%modify-class", 2, 0, 0, |
1437 | (SCM old, SCM new), | |
1438 | "") | |
1439 | #define FUNC_NAME s_scm_sys_modify_class | |
80662eda | 1440 | { |
398d8ee1 KN |
1441 | SCM_VALIDATE_CLASS (1, old); |
1442 | SCM_VALIDATE_CLASS (2, new); | |
80662eda MD |
1443 | |
1444 | SCM_REDEFER_INTS; | |
1445 | { | |
1446 | SCM car = SCM_CAR (old); | |
1447 | SCM cdr = SCM_CDR (old); | |
1448 | SCM_SETCAR (old, SCM_CAR (new)); | |
1449 | SCM_SETCDR (old, SCM_CDR (new)); | |
729dbac3 | 1450 | SCM_STRUCT_DATA (old)[scm_vtable_index_vtable] = SCM_UNPACK (old); |
80662eda MD |
1451 | SCM_SETCAR (new, car); |
1452 | SCM_SETCDR (new, cdr); | |
729dbac3 | 1453 | SCM_STRUCT_DATA (new)[scm_vtable_index_vtable] = SCM_UNPACK (new); |
80662eda MD |
1454 | } |
1455 | SCM_REALLOW_INTS; | |
1456 | return SCM_UNSPECIFIED; | |
1457 | } | |
398d8ee1 | 1458 | #undef FUNC_NAME |
80662eda | 1459 | |
398d8ee1 KN |
1460 | SCM_DEFINE (scm_sys_invalidate_class, "%invalidate-class", 1, 0, 0, |
1461 | (SCM class), | |
1462 | "") | |
1463 | #define FUNC_NAME s_scm_sys_invalidate_class | |
80662eda | 1464 | { |
398d8ee1 | 1465 | SCM_VALIDATE_CLASS (1, class); |
80662eda MD |
1466 | SCM_CLEAR_CLASS_FLAGS (class, SCM_CLASSF_GOOPS_VALID); |
1467 | return SCM_UNSPECIFIED; | |
1468 | } | |
398d8ee1 | 1469 | #undef FUNC_NAME |
80662eda MD |
1470 | |
1471 | /* When instances change class, they finally get a new body, but | |
1472 | * before that, they go through purgatory in hell. Odd as it may | |
1473 | * seem, this data structure saves us from eternal suffering in | |
1474 | * infinite recursions. | |
1475 | */ | |
1476 | ||
92c2555f | 1477 | static scm_t_bits **hell; |
c014a02e ML |
1478 | static long n_hell = 1; /* one place for the evil one himself */ |
1479 | static long hell_size = 4; | |
2132f0d2 | 1480 | static SCM hell_mutex; |
80662eda | 1481 | |
c014a02e | 1482 | static long |
80662eda MD |
1483 | burnin (SCM o) |
1484 | { | |
c014a02e | 1485 | long i; |
80662eda | 1486 | for (i = 1; i < n_hell; ++i) |
6b80d352 | 1487 | if (SCM_STRUCT_DATA (o) == hell[i]) |
80662eda MD |
1488 | return i; |
1489 | return 0; | |
1490 | } | |
1491 | ||
1492 | static void | |
1493 | go_to_hell (void *o) | |
1494 | { | |
6b80d352 | 1495 | SCM obj = SCM_PACK ((scm_t_bits) o); |
2132f0d2 | 1496 | scm_lock_mutex (hell_mutex); |
80662eda MD |
1497 | if (n_hell == hell_size) |
1498 | { | |
c014a02e | 1499 | long new_size = 2 * hell_size; |
4c9419ac | 1500 | hell = scm_realloc (hell, new_size); |
80662eda MD |
1501 | hell_size = new_size; |
1502 | } | |
6b80d352 | 1503 | hell[n_hell++] = SCM_STRUCT_DATA (obj); |
2132f0d2 | 1504 | scm_unlock_mutex (hell_mutex); |
80662eda MD |
1505 | } |
1506 | ||
1507 | static void | |
1508 | go_to_heaven (void *o) | |
1509 | { | |
2132f0d2 | 1510 | scm_lock_mutex (hell_mutex); |
6b80d352 | 1511 | hell[burnin (SCM_PACK ((scm_t_bits) o))] = hell[--n_hell]; |
2132f0d2 | 1512 | scm_unlock_mutex (hell_mutex); |
80662eda MD |
1513 | } |
1514 | ||
6b80d352 DH |
1515 | |
1516 | SCM_SYMBOL (scm_sym_change_class, "change-class"); | |
1517 | ||
80662eda MD |
1518 | static SCM |
1519 | purgatory (void *args) | |
1520 | { | |
6d77c894 | 1521 | return scm_apply_0 (GETVAR (scm_sym_change_class), |
6b80d352 | 1522 | SCM_PACK ((scm_t_bits) args)); |
80662eda MD |
1523 | } |
1524 | ||
1525 | void | |
e81d98ec | 1526 | scm_change_object_class (SCM obj, SCM old_class SCM_UNUSED, SCM new_class) |
80662eda MD |
1527 | { |
1528 | if (!burnin (obj)) | |
1529 | scm_internal_dynamic_wind (go_to_hell, purgatory, go_to_heaven, | |
6b80d352 DH |
1530 | (void *) SCM_UNPACK (scm_list_2 (obj, new_class)), |
1531 | (void *) SCM_UNPACK (obj)); | |
80662eda MD |
1532 | } |
1533 | ||
1534 | /****************************************************************************** | |
1535 | * | |
6d77c894 TTN |
1536 | * GGGG FFFFF |
1537 | * G F | |
1538 | * G GG FFF | |
1539 | * G G F | |
80662eda MD |
1540 | * GGG E N E R I C F U N C T I O N S |
1541 | * | |
1542 | * This implementation provides | |
1543 | * - generic functions (with class specializers) | |
1544 | * - multi-methods | |
6d77c894 | 1545 | * - next-method |
80662eda MD |
1546 | * - a hard-coded MOP for standard gf, which can be overloaded for non-std gf |
1547 | * | |
1548 | ******************************************************************************/ | |
1549 | ||
1550 | SCM_KEYWORD (k_name, "name"); | |
1551 | ||
1552 | SCM_SYMBOL (sym_no_method, "no-method"); | |
1553 | ||
1554 | static SCM list_of_no_method; | |
1555 | ||
1556 | SCM_SYMBOL (scm_sym_args, "args"); | |
1557 | ||
1558 | SCM | |
1559 | scm_make_method_cache (SCM gf) | |
1560 | { | |
1afff620 KN |
1561 | return scm_list_5 (SCM_IM_DISPATCH, |
1562 | scm_sym_args, | |
1563 | SCM_MAKINUM (1), | |
1564 | scm_c_make_vector (SCM_INITIAL_MCACHE_SIZE, | |
1565 | list_of_no_method), | |
1566 | gf); | |
80662eda MD |
1567 | } |
1568 | ||
1569 | static void | |
1570 | clear_method_cache (SCM gf) | |
1571 | { | |
322ec19d ML |
1572 | SCM cache = scm_make_method_cache (gf); |
1573 | SCM_SET_ENTITY_PROCEDURE (gf, cache); | |
dcb410ec | 1574 | SCM_SET_SLOT (gf, scm_si_used_by, SCM_BOOL_F); |
80662eda MD |
1575 | } |
1576 | ||
398d8ee1 KN |
1577 | SCM_DEFINE (scm_sys_invalidate_method_cache_x, "%invalidate-method-cache!", 1, 0, 0, |
1578 | (SCM gf), | |
1579 | "") | |
1580 | #define FUNC_NAME s_scm_sys_invalidate_method_cache_x | |
80662eda MD |
1581 | { |
1582 | SCM used_by; | |
25ba37df | 1583 | SCM_ASSERT (SCM_PUREGENERICP (gf), gf, SCM_ARG1, FUNC_NAME); |
80662eda | 1584 | used_by = SCM_SLOT (gf, scm_si_used_by); |
6b80d352 | 1585 | if (!SCM_FALSEP (used_by)) |
80662eda MD |
1586 | { |
1587 | SCM methods = SCM_SLOT (gf, scm_si_methods); | |
c312aca7 | 1588 | for (; SCM_CONSP (used_by); used_by = SCM_CDR (used_by)) |
80662eda MD |
1589 | scm_sys_invalidate_method_cache_x (SCM_CAR (used_by)); |
1590 | clear_method_cache (gf); | |
c312aca7 | 1591 | for (; SCM_CONSP (methods); methods = SCM_CDR (methods)) |
dcb410ec | 1592 | SCM_SET_SLOT (SCM_CAR (methods), scm_si_code_table, SCM_EOL); |
80662eda MD |
1593 | } |
1594 | { | |
55c4a132 | 1595 | SCM n = SCM_SLOT (gf, scm_si_n_specialized); |
80662eda | 1596 | /* The sign of n is a flag indicating rest args. */ |
55c4a132 | 1597 | SCM_SET_MCACHE_N_SPECIALIZED (SCM_ENTITY_PROCEDURE (gf), n); |
80662eda MD |
1598 | } |
1599 | return SCM_UNSPECIFIED; | |
1600 | } | |
398d8ee1 | 1601 | #undef FUNC_NAME |
80662eda | 1602 | |
398d8ee1 KN |
1603 | SCM_DEFINE (scm_generic_capability_p, "generic-capability?", 1, 0, 0, |
1604 | (SCM proc), | |
1605 | "") | |
1606 | #define FUNC_NAME s_scm_generic_capability_p | |
80662eda | 1607 | { |
6b80d352 | 1608 | SCM_ASSERT (!SCM_FALSEP (scm_procedure_p (proc)), |
398d8ee1 | 1609 | proc, SCM_ARG1, FUNC_NAME); |
80662eda MD |
1610 | return (scm_subr_p (proc) && SCM_SUBR_GENERIC (proc) |
1611 | ? SCM_BOOL_T | |
1612 | : SCM_BOOL_F); | |
1613 | } | |
398d8ee1 | 1614 | #undef FUNC_NAME |
80662eda | 1615 | |
398d8ee1 KN |
1616 | SCM_DEFINE (scm_enable_primitive_generic_x, "enable-primitive-generic!", 0, 0, 1, |
1617 | (SCM subrs), | |
1618 | "") | |
1619 | #define FUNC_NAME s_scm_enable_primitive_generic_x | |
80662eda | 1620 | { |
6b80d352 DH |
1621 | SCM_VALIDATE_REST_ARGUMENT (subrs); |
1622 | while (!SCM_NULLP (subrs)) | |
80662eda MD |
1623 | { |
1624 | SCM subr = SCM_CAR (subrs); | |
1625 | SCM_ASSERT (scm_subr_p (subr) && SCM_SUBR_GENERIC (subr), | |
398d8ee1 | 1626 | subr, SCM_ARGn, FUNC_NAME); |
80662eda | 1627 | *SCM_SUBR_GENERIC (subr) |
1afff620 KN |
1628 | = scm_make (scm_list_3 (scm_class_generic, |
1629 | k_name, | |
1630 | SCM_SNAME (subr))); | |
80662eda MD |
1631 | subrs = SCM_CDR (subrs); |
1632 | } | |
1633 | return SCM_UNSPECIFIED; | |
1634 | } | |
398d8ee1 | 1635 | #undef FUNC_NAME |
80662eda | 1636 | |
398d8ee1 KN |
1637 | SCM_DEFINE (scm_primitive_generic_generic, "primitive-generic-generic", 1, 0, 0, |
1638 | (SCM subr), | |
1639 | "") | |
1640 | #define FUNC_NAME s_scm_primitive_generic_generic | |
80662eda MD |
1641 | { |
1642 | if (scm_subr_p (subr) && SCM_SUBR_GENERIC (subr)) | |
1643 | { | |
1644 | SCM gf = *SCM_SUBR_GENERIC (subr); | |
1645 | if (gf) | |
1646 | return gf; | |
1647 | } | |
db4b4ca6 | 1648 | SCM_WRONG_TYPE_ARG (SCM_ARG1, subr); |
80662eda | 1649 | } |
398d8ee1 | 1650 | #undef FUNC_NAME |
80662eda MD |
1651 | |
1652 | /****************************************************************************** | |
6d77c894 | 1653 | * |
80662eda | 1654 | * Protocol for calling a generic fumction |
6d77c894 | 1655 | * This protocol is roughly equivalent to (parameter are a little bit different |
80662eda MD |
1656 | * for efficiency reasons): |
1657 | * | |
1658 | * + apply-generic (gf args) | |
1659 | * + compute-applicable-methods (gf args ...) | |
1660 | * + sort-applicable-methods (methods args) | |
1661 | * + apply-methods (gf methods args) | |
6d77c894 TTN |
1662 | * |
1663 | * apply-methods calls make-next-method to build the "continuation" of a a | |
80662eda MD |
1664 | * method. Applying a next-method will call apply-next-method which in |
1665 | * turn will call apply again to call effectively the following method. | |
1666 | * | |
1667 | ******************************************************************************/ | |
1668 | ||
1669 | static int | |
1670 | applicablep (SCM actual, SCM formal) | |
1671 | { | |
79a3dafe DH |
1672 | /* We already know that the cpl is well formed. */ |
1673 | return !SCM_FALSEP (scm_c_memq (formal, SCM_SLOT (actual, scm_si_cpl))); | |
80662eda MD |
1674 | } |
1675 | ||
1676 | static int | |
34d19ef6 | 1677 | more_specificp (SCM m1, SCM m2, SCM const *targs) |
80662eda MD |
1678 | { |
1679 | register SCM s1, s2; | |
c014a02e | 1680 | register long i; |
6d77c894 TTN |
1681 | /* |
1682 | * Note: | |
1683 | * m1 and m2 can have != length (i.e. one can be one element longer than the | |
80662eda MD |
1684 | * other when we have a dotted parameter list). For instance, with the call |
1685 | * (M 1) | |
1686 | * with | |
1687 | * (define-method M (a . l) ....) | |
6d77c894 | 1688 | * (define-method M (a) ....) |
80662eda MD |
1689 | * |
1690 | * we consider that the second method is more specific. | |
1691 | * | |
1692 | * BTW, targs is an array of types. We don't need it's size since | |
1693 | * we already know that m1 and m2 are applicable (no risk to go past | |
1694 | * the end of this array). | |
1695 | * | |
1696 | */ | |
34d19ef6 | 1697 | for (i=0, s1=SPEC_OF(m1), s2=SPEC_OF(m2); ; i++, s1=SCM_CDR(s1), s2=SCM_CDR(s2)) { |
80662eda MD |
1698 | if (SCM_NULLP(s1)) return 1; |
1699 | if (SCM_NULLP(s2)) return 0; | |
1700 | if (SCM_CAR(s1) != SCM_CAR(s2)) { | |
1701 | register SCM l, cs1 = SCM_CAR(s1), cs2 = SCM_CAR(s2); | |
6d77c894 | 1702 | |
dcb410ec | 1703 | for (l = SCM_SLOT (targs[i], scm_si_cpl); ; l = SCM_CDR(l)) { |
80662eda MD |
1704 | if (cs1 == SCM_CAR(l)) |
1705 | return 1; | |
1706 | if (cs2 == SCM_CAR(l)) | |
1707 | return 0; | |
1708 | } | |
1709 | return 0;/* should not occur! */ | |
1710 | } | |
1711 | } | |
1712 | return 0; /* should not occur! */ | |
1713 | } | |
1714 | ||
1715 | #define BUFFSIZE 32 /* big enough for most uses */ | |
1716 | ||
1717 | static SCM | |
c014a02e | 1718 | scm_i_vector2list (SCM l, long len) |
80662eda | 1719 | { |
c014a02e | 1720 | long j; |
00ffa0e7 | 1721 | SCM z = scm_c_make_vector (len, SCM_UNDEFINED); |
6d77c894 | 1722 | |
80662eda | 1723 | for (j = 0; j < len; j++, l = SCM_CDR (l)) { |
34d19ef6 | 1724 | SCM_VECTOR_SET (z, j, SCM_CAR (l)); |
80662eda MD |
1725 | } |
1726 | return z; | |
1727 | } | |
1728 | ||
1729 | static SCM | |
34d19ef6 | 1730 | sort_applicable_methods (SCM method_list, long size, SCM const *targs) |
80662eda | 1731 | { |
c014a02e | 1732 | long i, j, incr; |
80662eda MD |
1733 | SCM *v, vector = SCM_EOL; |
1734 | SCM buffer[BUFFSIZE]; | |
1735 | SCM save = method_list; | |
1736 | ||
1737 | /* For reasonably sized method_lists we can try to avoid all the | |
1738 | * consing and reorder the list in place... | |
1739 | * This idea is due to David McClain <Dave_McClain@msn.com> | |
1740 | */ | |
1741 | if (size <= BUFFSIZE) | |
1742 | { | |
1743 | for (i = 0; i < size; i++) | |
1744 | { | |
1745 | buffer[i] = SCM_CAR (method_list); | |
1746 | method_list = SCM_CDR (method_list); | |
1747 | } | |
1748 | v = buffer; | |
6d77c894 | 1749 | } |
80662eda MD |
1750 | else |
1751 | { | |
1752 | /* Too many elements in method_list to keep everything locally */ | |
1753 | vector = scm_i_vector2list (save, size); | |
34d19ef6 HWN |
1754 | |
1755 | /* | |
1756 | This is a new vector. Don't worry about the write barrier. | |
1757 | We're not allocating elements in this routine, so this should | |
1758 | pose no problem. | |
1759 | */ | |
1760 | v = SCM_WRITABLE_VELTS (vector); | |
80662eda MD |
1761 | } |
1762 | ||
6d77c894 | 1763 | /* Use a simple shell sort since it is generally faster than qsort on |
80662eda MD |
1764 | * small vectors (which is probably mostly the case when we have to |
1765 | * sort a list of applicable methods). | |
1766 | */ | |
1767 | for (incr = size / 2; incr; incr /= 2) | |
1768 | { | |
1769 | for (i = incr; i < size; i++) | |
1770 | { | |
1771 | for (j = i - incr; j >= 0; j -= incr) | |
1772 | { | |
1773 | if (more_specificp (v[j], v[j+incr], targs)) | |
1774 | break; | |
1775 | else | |
1776 | { | |
1777 | SCM tmp = v[j + incr]; | |
1778 | v[j + incr] = v[j]; | |
1779 | v[j] = tmp; | |
1780 | } | |
1781 | } | |
1782 | } | |
1783 | } | |
1784 | ||
1785 | if (size <= BUFFSIZE) | |
1786 | { | |
1787 | /* We did it in locally, so restore the original list (reordered) in-place */ | |
1788 | for (i = 0, method_list = save; i < size; i++, v++) | |
1789 | { | |
1790 | SCM_SETCAR (method_list, *v); | |
1791 | method_list = SCM_CDR (method_list); | |
1792 | } | |
1793 | return save; | |
1794 | } | |
6d77c894 | 1795 | /* If we are here, that's that we did it the hard way... */ |
80662eda MD |
1796 | return scm_vector_to_list (vector); |
1797 | } | |
1798 | ||
1799 | SCM | |
c014a02e | 1800 | scm_compute_applicable_methods (SCM gf, SCM args, long len, int find_method_p) |
80662eda | 1801 | { |
c014a02e ML |
1802 | register long i; |
1803 | long count = 0; | |
80662eda MD |
1804 | SCM l, fl, applicable = SCM_EOL; |
1805 | SCM save = args; | |
34d19ef6 HWN |
1806 | SCM buffer[BUFFSIZE]; |
1807 | SCM const *types; | |
1808 | SCM *p; | |
1809 | SCM tmp = SCM_EOL; | |
6d77c894 | 1810 | |
80662eda MD |
1811 | /* Build the list of arguments types */ |
1812 | if (len >= BUFFSIZE) { | |
00ffa0e7 | 1813 | tmp = scm_c_make_vector (len, SCM_UNDEFINED); |
80662eda MD |
1814 | /* NOTE: Using pointers to malloced memory won't work if we |
1815 | 1. have preemtive threading, and, | |
1816 | 2. have a GC which moves objects. */ | |
34d19ef6 HWN |
1817 | types = p = SCM_WRITABLE_VELTS(tmp); |
1818 | ||
1819 | /* | |
1820 | note that we don't have to work to reset the generation | |
1821 | count. TMP is a new vector anyway, and it is found | |
1822 | conservatively. | |
1823 | */ | |
80662eda MD |
1824 | } |
1825 | else | |
1826 | types = p = buffer; | |
6d77c894 TTN |
1827 | |
1828 | for ( ; !SCM_NULLP (args); args = SCM_CDR (args)) | |
80662eda | 1829 | *p++ = scm_class_of (SCM_CAR (args)); |
34d19ef6 | 1830 | |
80662eda | 1831 | /* Build a list of all applicable methods */ |
6b80d352 | 1832 | for (l = SCM_SLOT (gf, scm_si_methods); !SCM_NULLP (l); l = SCM_CDR (l)) |
80662eda MD |
1833 | { |
1834 | fl = SPEC_OF (SCM_CAR (l)); | |
1835 | /* Only accept accessors which match exactly in first arg. */ | |
1836 | if (SCM_ACCESSORP (SCM_CAR (l)) | |
6b80d352 | 1837 | && (SCM_NULLP (fl) || types[0] != SCM_CAR (fl))) |
80662eda MD |
1838 | continue; |
1839 | for (i = 0; ; i++, fl = SCM_CDR (fl)) | |
1840 | { | |
c312aca7 | 1841 | if (SCM_INSTANCEP (fl) |
80662eda MD |
1842 | /* We have a dotted argument list */ |
1843 | || (i >= len && SCM_NULLP (fl))) | |
1844 | { /* both list exhausted */ | |
1845 | applicable = scm_cons (SCM_CAR (l), applicable); | |
1846 | count += 1; | |
1847 | break; | |
1848 | } | |
1849 | if (i >= len | |
1850 | || SCM_NULLP (fl) | |
1851 | || !applicablep (types[i], SCM_CAR (fl))) | |
1852 | break; | |
1853 | } | |
1854 | } | |
1855 | ||
1856 | if (count == 0) | |
1857 | { | |
1858 | if (find_method_p) | |
1859 | return SCM_BOOL_F; | |
1860 | CALL_GF2 ("no-applicable-method", gf, save); | |
1861 | /* if we are here, it's because no-applicable-method hasn't signaled an error */ | |
1862 | return SCM_BOOL_F; | |
1863 | } | |
34d19ef6 | 1864 | |
afc8e572 | 1865 | scm_remember_upto_here_1 (tmp); |
80662eda MD |
1866 | return (count == 1 |
1867 | ? applicable | |
1868 | : sort_applicable_methods (applicable, count, types)); | |
1869 | } | |
1870 | ||
1871 | #if 0 | |
1872 | SCM_PROC (s_sys_compute_applicable_methods, "%compute-applicable-methods", 2, 0, 0, scm_sys_compute_applicable_methods); | |
1873 | #endif | |
1874 | ||
1875 | static const char s_sys_compute_applicable_methods[] = "%compute-applicable-methods"; | |
1876 | ||
1877 | SCM | |
1878 | scm_sys_compute_applicable_methods (SCM gf, SCM args) | |
398d8ee1 | 1879 | #define FUNC_NAME s_sys_compute_applicable_methods |
80662eda | 1880 | { |
c014a02e | 1881 | long n; |
398d8ee1 | 1882 | SCM_VALIDATE_GENERIC (1, gf); |
80662eda | 1883 | n = scm_ilength (args); |
398d8ee1 | 1884 | SCM_ASSERT (n >= 0, args, SCM_ARG2, FUNC_NAME); |
80662eda MD |
1885 | return scm_compute_applicable_methods (gf, args, n, 1); |
1886 | } | |
398d8ee1 | 1887 | #undef FUNC_NAME |
80662eda | 1888 | |
86d31dfe | 1889 | SCM_SYMBOL (sym_compute_applicable_methods, "compute-applicable-methods"); |
9a441ddb | 1890 | SCM_VARIABLE_INIT (var_compute_applicable_methods, "compute-applicable-methods", scm_c_define_gsubr (s_sys_compute_applicable_methods, 2, 0, 0, scm_sys_compute_applicable_methods)); |
80662eda MD |
1891 | |
1892 | SCM_SYNTAX (s_atslot_ref, "@slot-ref", scm_makmmacro, scm_m_atslot_ref); | |
1893 | ||
1894 | SCM | |
e81d98ec | 1895 | scm_m_atslot_ref (SCM xorig, SCM env SCM_UNUSED) |
e11208ca | 1896 | #define FUNC_NAME s_atslot_ref |
80662eda MD |
1897 | { |
1898 | SCM x = SCM_CDR (xorig); | |
160bb34a | 1899 | SCM_ASSYNT (scm_ilength (x) == 2, scm_s_expression, FUNC_NAME); |
e11208ca | 1900 | SCM_VALIDATE_INUM (SCM_ARG2, SCM_CADR (x)); |
80662eda MD |
1901 | return scm_cons (SCM_IM_SLOT_REF, x); |
1902 | } | |
e11208ca DH |
1903 | #undef FUNC_NAME |
1904 | ||
80662eda MD |
1905 | |
1906 | SCM_SYNTAX (s_atslot_set_x, "@slot-set!", scm_makmmacro, scm_m_atslot_set_x); | |
1907 | ||
1908 | SCM | |
e81d98ec | 1909 | scm_m_atslot_set_x (SCM xorig, SCM env SCM_UNUSED) |
e11208ca | 1910 | #define FUNC_NAME s_atslot_set_x |
80662eda MD |
1911 | { |
1912 | SCM x = SCM_CDR (xorig); | |
160bb34a | 1913 | SCM_ASSYNT (scm_ilength (x) == 3, scm_s_expression, FUNC_NAME); |
e11208ca | 1914 | SCM_VALIDATE_INUM (SCM_ARG2, SCM_CADR (x)); |
80662eda MD |
1915 | return scm_cons (SCM_IM_SLOT_SET_X, x); |
1916 | } | |
e11208ca DH |
1917 | #undef FUNC_NAME |
1918 | ||
80662eda MD |
1919 | |
1920 | SCM_SYNTAX (s_atdispatch, "@dispatch", scm_makmmacro, scm_m_atdispatch); | |
1921 | ||
1922 | SCM_SYMBOL (sym_atdispatch, s_atdispatch); | |
1923 | ||
1924 | SCM | |
1925 | scm_m_atdispatch (SCM xorig, SCM env) | |
ca83b028 | 1926 | #define FUNC_NAME s_atdispatch |
80662eda MD |
1927 | { |
1928 | SCM args, n, v, gf, x = SCM_CDR (xorig); | |
160bb34a | 1929 | SCM_ASSYNT (scm_ilength (x) == 4, scm_s_expression, FUNC_NAME); |
80662eda | 1930 | args = SCM_CAR (x); |
e11208ca DH |
1931 | if (!SCM_CONSP (args) && !SCM_SYMBOLP (args)) |
1932 | SCM_WRONG_TYPE_ARG (SCM_ARG1, args); | |
80662eda MD |
1933 | x = SCM_CDR (x); |
1934 | n = SCM_XEVALCAR (x, env); | |
e11208ca | 1935 | SCM_VALIDATE_INUM (SCM_ARG2, n); |
ca83b028 | 1936 | SCM_ASSERT_RANGE (0, n, SCM_INUM (n) >= 1); |
80662eda MD |
1937 | x = SCM_CDR (x); |
1938 | v = SCM_XEVALCAR (x, env); | |
e11208ca | 1939 | SCM_VALIDATE_VECTOR (SCM_ARG3, v); |
80662eda MD |
1940 | x = SCM_CDR (x); |
1941 | gf = SCM_XEVALCAR (x, env); | |
e11208ca | 1942 | SCM_VALIDATE_PUREGENERIC (SCM_ARG4, gf); |
1afff620 | 1943 | return scm_list_5 (SCM_IM_DISPATCH, args, n, v, gf); |
80662eda | 1944 | } |
ca83b028 DH |
1945 | #undef FUNC_NAME |
1946 | ||
80662eda | 1947 | |
80662eda MD |
1948 | static void |
1949 | lock_cache_mutex (void *m) | |
1950 | { | |
6b80d352 | 1951 | SCM mutex = SCM_PACK ((scm_t_bits) m); |
80662eda MD |
1952 | scm_lock_mutex (mutex); |
1953 | } | |
1954 | ||
1955 | static void | |
1956 | unlock_cache_mutex (void *m) | |
1957 | { | |
6b80d352 | 1958 | SCM mutex = SCM_PACK ((scm_t_bits) m); |
80662eda MD |
1959 | scm_unlock_mutex (mutex); |
1960 | } | |
80662eda MD |
1961 | |
1962 | static SCM | |
1963 | call_memoize_method (void *a) | |
1964 | { | |
6b80d352 | 1965 | SCM args = SCM_PACK ((scm_t_bits) a); |
80662eda MD |
1966 | SCM gf = SCM_CAR (args); |
1967 | SCM x = SCM_CADR (args); | |
1968 | /* First check if another thread has inserted a method between | |
1969 | * the cache miss and locking the mutex. | |
1970 | */ | |
1971 | SCM cmethod = scm_mcache_lookup_cmethod (x, SCM_CDDR (args)); | |
6b80d352 | 1972 | if (!SCM_FALSEP (cmethod)) |
80662eda MD |
1973 | return cmethod; |
1974 | /*fixme* Use scm_apply */ | |
1975 | return CALL_GF3 ("memoize-method!", gf, SCM_CDDR (args), x); | |
1976 | } | |
1977 | ||
1978 | SCM | |
1979 | scm_memoize_method (SCM x, SCM args) | |
1980 | { | |
1981 | SCM gf = SCM_CAR (scm_last_pair (x)); | |
6b80d352 DH |
1982 | return scm_internal_dynamic_wind ( |
1983 | lock_cache_mutex, | |
1984 | call_memoize_method, | |
1985 | unlock_cache_mutex, | |
1986 | (void *) SCM_UNPACK (scm_cons2 (gf, x, args)), | |
1987 | (void *) SCM_UNPACK (SCM_SLOT (gf, scm_si_cache_mutex))); | |
80662eda MD |
1988 | } |
1989 | ||
1990 | /****************************************************************************** | |
1991 | * | |
1992 | * A simple make (which will be redefined later in Scheme) | |
1993 | * This version handles only creation of gf, methods and classes (no instances) | |
1994 | * | |
6d77c894 | 1995 | * Since this code will disappear when Goops will be fully booted, |
80662eda MD |
1996 | * no precaution is taken to be efficient. |
1997 | * | |
1998 | ******************************************************************************/ | |
1999 | ||
2000 | SCM_KEYWORD (k_setter, "setter"); | |
2001 | SCM_KEYWORD (k_specializers, "specializers"); | |
2002 | SCM_KEYWORD (k_procedure, "procedure"); | |
2003 | SCM_KEYWORD (k_dsupers, "dsupers"); | |
2004 | SCM_KEYWORD (k_slots, "slots"); | |
2005 | SCM_KEYWORD (k_gf, "generic-function"); | |
2006 | ||
398d8ee1 KN |
2007 | SCM_DEFINE (scm_make, "make", 0, 0, 1, |
2008 | (SCM args), | |
27c37006 | 2009 | "Make a new object. @var{args} must contain the class and\n" |
6bcefd15 | 2010 | "all necessary initialization information.") |
398d8ee1 | 2011 | #define FUNC_NAME s_scm_make |
80662eda MD |
2012 | { |
2013 | SCM class, z; | |
c014a02e | 2014 | long len = scm_ilength (args); |
80662eda MD |
2015 | |
2016 | if (len <= 0 || (len & 1) == 0) | |
398d8ee1 | 2017 | SCM_WRONG_NUM_ARGS (); |
80662eda MD |
2018 | |
2019 | class = SCM_CAR(args); | |
2020 | args = SCM_CDR(args); | |
2021 | ||
2022 | if (class == scm_class_generic || class == scm_class_generic_with_setter) | |
2023 | { | |
80662eda | 2024 | z = scm_make_struct (class, SCM_INUM0, |
1afff620 KN |
2025 | scm_list_4 (SCM_EOL, |
2026 | SCM_INUM0, | |
2027 | SCM_BOOL_F, | |
2028 | scm_make_mutex ())); | |
80662eda MD |
2029 | scm_set_procedure_property_x (z, scm_sym_name, |
2030 | scm_get_keyword (k_name, | |
2031 | args, | |
2032 | SCM_BOOL_F)); | |
2033 | clear_method_cache (z); | |
2034 | if (class == scm_class_generic_with_setter) | |
2035 | { | |
2036 | SCM setter = scm_get_keyword (k_setter, args, SCM_BOOL_F); | |
6b80d352 | 2037 | if (!SCM_FALSEP (setter)) |
80662eda MD |
2038 | scm_sys_set_object_setter_x (z, setter); |
2039 | } | |
2040 | } | |
2041 | else | |
2042 | { | |
2043 | z = scm_sys_allocate_instance (class, args); | |
2044 | ||
2045 | if (class == scm_class_method | |
2046 | || class == scm_class_simple_method | |
2047 | || class == scm_class_accessor) | |
2048 | { | |
6d77c894 | 2049 | SCM_SET_SLOT (z, scm_si_generic_function, |
80662eda MD |
2050 | scm_i_get_keyword (k_gf, |
2051 | args, | |
2052 | len - 1, | |
2053 | SCM_BOOL_F, | |
dcb410ec | 2054 | FUNC_NAME)); |
6d77c894 | 2055 | SCM_SET_SLOT (z, scm_si_specializers, |
80662eda MD |
2056 | scm_i_get_keyword (k_specializers, |
2057 | args, | |
2058 | len - 1, | |
2059 | SCM_EOL, | |
dcb410ec | 2060 | FUNC_NAME)); |
6d77c894 | 2061 | SCM_SET_SLOT (z, scm_si_procedure, |
80662eda MD |
2062 | scm_i_get_keyword (k_procedure, |
2063 | args, | |
2064 | len - 1, | |
2065 | SCM_EOL, | |
dcb410ec DH |
2066 | FUNC_NAME)); |
2067 | SCM_SET_SLOT (z, scm_si_code_table, SCM_EOL); | |
80662eda MD |
2068 | } |
2069 | else | |
2070 | { | |
2071 | /* In all the others case, make a new class .... No instance here */ | |
6d77c894 | 2072 | SCM_SET_SLOT (z, scm_si_name, |
80662eda MD |
2073 | scm_i_get_keyword (k_name, |
2074 | args, | |
2075 | len - 1, | |
38ae064c | 2076 | scm_str2symbol ("???"), |
dcb410ec | 2077 | FUNC_NAME)); |
6d77c894 | 2078 | SCM_SET_SLOT (z, scm_si_direct_supers, |
80662eda MD |
2079 | scm_i_get_keyword (k_dsupers, |
2080 | args, | |
2081 | len - 1, | |
2082 | SCM_EOL, | |
dcb410ec | 2083 | FUNC_NAME)); |
6d77c894 | 2084 | SCM_SET_SLOT (z, scm_si_direct_slots, |
80662eda MD |
2085 | scm_i_get_keyword (k_slots, |
2086 | args, | |
2087 | len - 1, | |
2088 | SCM_EOL, | |
dcb410ec | 2089 | FUNC_NAME)); |
80662eda MD |
2090 | } |
2091 | } | |
2092 | return z; | |
2093 | } | |
398d8ee1 | 2094 | #undef FUNC_NAME |
80662eda | 2095 | |
398d8ee1 KN |
2096 | SCM_DEFINE (scm_find_method, "find-method", 0, 0, 1, |
2097 | (SCM l), | |
2098 | "") | |
2099 | #define FUNC_NAME s_scm_find_method | |
80662eda MD |
2100 | { |
2101 | SCM gf; | |
c014a02e | 2102 | long len = scm_ilength (l); |
80662eda MD |
2103 | |
2104 | if (len == 0) | |
398d8ee1 | 2105 | SCM_WRONG_NUM_ARGS (); |
80662eda MD |
2106 | |
2107 | gf = SCM_CAR(l); l = SCM_CDR(l); | |
398d8ee1 | 2108 | SCM_VALIDATE_GENERIC (1, gf); |
80662eda | 2109 | if (SCM_NULLP (SCM_SLOT (gf, scm_si_methods))) |
1afff620 | 2110 | SCM_MISC_ERROR ("no methods for generic ~S", scm_list_1 (gf)); |
80662eda MD |
2111 | |
2112 | return scm_compute_applicable_methods (gf, l, len - 1, 1); | |
2113 | } | |
398d8ee1 | 2114 | #undef FUNC_NAME |
80662eda | 2115 | |
398d8ee1 KN |
2116 | SCM_DEFINE (scm_sys_method_more_specific_p, "%method-more-specific?", 3, 0, 0, |
2117 | (SCM m1, SCM m2, SCM targs), | |
2118 | "") | |
2119 | #define FUNC_NAME s_scm_sys_method_more_specific_p | |
80662eda MD |
2120 | { |
2121 | SCM l, v; | |
c014a02e | 2122 | long i, len; |
80662eda | 2123 | |
398d8ee1 KN |
2124 | SCM_VALIDATE_METHOD (1, m1); |
2125 | SCM_VALIDATE_METHOD (2, m2); | |
2126 | SCM_ASSERT ((len = scm_ilength (targs)) != -1, targs, SCM_ARG3, FUNC_NAME); | |
80662eda MD |
2127 | |
2128 | /* Verify that all the arguments of targs are classes and place them in a vector*/ | |
00ffa0e7 | 2129 | v = scm_c_make_vector (len, SCM_EOL); |
80662eda | 2130 | |
6b80d352 | 2131 | for (i = 0, l = targs; !SCM_NULLP (l); i++, l = SCM_CDR (l)) { |
398d8ee1 | 2132 | SCM_ASSERT (SCM_CLASSP (SCM_CAR (l)), targs, SCM_ARG3, FUNC_NAME); |
34d19ef6 | 2133 | SCM_VECTOR_SET (v, i, SCM_CAR(l)); |
80662eda MD |
2134 | } |
2135 | return more_specificp (m1, m2, SCM_VELTS(v)) ? SCM_BOOL_T: SCM_BOOL_F; | |
2136 | } | |
398d8ee1 | 2137 | #undef FUNC_NAME |
6d77c894 TTN |
2138 | |
2139 | ||
80662eda MD |
2140 | |
2141 | /****************************************************************************** | |
2142 | * | |
6d77c894 | 2143 | * Initializations |
80662eda MD |
2144 | * |
2145 | ******************************************************************************/ | |
2146 | ||
2147 | ||
2148 | static void | |
2149 | make_stdcls (SCM *var, char *name, SCM meta, SCM super, SCM slots) | |
2150 | { | |
38ae064c | 2151 | SCM tmp = scm_str2symbol (name); |
6d77c894 | 2152 | |
80662eda MD |
2153 | *var = scm_permanent_object (scm_basic_make_class (meta, |
2154 | tmp, | |
2155 | SCM_CONSP (super) | |
2156 | ? super | |
1afff620 | 2157 | : scm_list_1 (super), |
80662eda MD |
2158 | slots)); |
2159 | DEFVAR(tmp, *var); | |
2160 | } | |
2161 | ||
2162 | ||
2163 | SCM_KEYWORD (k_slot_definition, "slot-definition"); | |
2164 | ||
2165 | static void | |
2166 | create_standard_classes (void) | |
2167 | { | |
2168 | SCM slots; | |
6d77c894 TTN |
2169 | SCM method_slots = scm_list_4 (scm_str2symbol ("generic-function"), |
2170 | scm_str2symbol ("specializers"), | |
6b80d352 | 2171 | sym_procedure, |
1afff620 KN |
2172 | scm_str2symbol ("code-table")); |
2173 | SCM amethod_slots = scm_list_1 (scm_list_3 (scm_str2symbol ("slot-definition"), | |
2174 | k_init_keyword, | |
2175 | k_slot_definition)); | |
1afff620 | 2176 | SCM mutex_slot = scm_list_1 (scm_str2symbol ("make-mutex")); |
1afff620 KN |
2177 | SCM gf_slots = scm_list_4 (scm_str2symbol ("methods"), |
2178 | scm_list_3 (scm_str2symbol ("n-specialized"), | |
2179 | k_init_value, | |
2180 | SCM_INUM0), | |
2181 | scm_list_3 (scm_str2symbol ("used-by"), | |
2182 | k_init_value, | |
2183 | SCM_BOOL_F), | |
2184 | scm_list_3 (scm_str2symbol ("cache-mutex"), | |
2185 | k_init_thunk, | |
2186 | scm_closure (scm_list_2 (SCM_EOL, | |
2187 | mutex_slot), | |
2188 | SCM_EOL))); | |
80662eda MD |
2189 | |
2190 | /* Foreign class slot classes */ | |
2191 | make_stdcls (&scm_class_foreign_slot, "<foreign-slot>", | |
2192 | scm_class_class, scm_class_top, SCM_EOL); | |
2193 | make_stdcls (&scm_class_protected, "<protected-slot>", | |
2194 | scm_class_class, scm_class_foreign_slot, SCM_EOL); | |
2195 | make_stdcls (&scm_class_opaque, "<opaque-slot>", | |
2196 | scm_class_class, scm_class_foreign_slot, SCM_EOL); | |
2197 | make_stdcls (&scm_class_read_only, "<read-only-slot>", | |
2198 | scm_class_class, scm_class_foreign_slot, SCM_EOL); | |
2199 | make_stdcls (&scm_class_self, "<self-slot>", | |
2200 | scm_class_class, | |
1afff620 | 2201 | scm_list_2 (scm_class_foreign_slot, scm_class_read_only), |
80662eda MD |
2202 | SCM_EOL); |
2203 | make_stdcls (&scm_class_protected_opaque, "<protected-opaque-slot>", | |
2204 | scm_class_class, | |
1afff620 | 2205 | scm_list_2 (scm_class_protected, scm_class_opaque), |
80662eda MD |
2206 | SCM_EOL); |
2207 | make_stdcls (&scm_class_protected_read_only, "<protected-read-only-slot>", | |
2208 | scm_class_class, | |
1afff620 | 2209 | scm_list_2 (scm_class_protected, scm_class_read_only), |
80662eda MD |
2210 | SCM_EOL); |
2211 | make_stdcls (&scm_class_scm, "<scm-slot>", | |
2212 | scm_class_class, scm_class_protected, SCM_EOL); | |
2213 | make_stdcls (&scm_class_int, "<int-slot>", | |
2214 | scm_class_class, scm_class_foreign_slot, SCM_EOL); | |
2215 | make_stdcls (&scm_class_float, "<float-slot>", | |
2216 | scm_class_class, scm_class_foreign_slot, SCM_EOL); | |
2217 | make_stdcls (&scm_class_double, "<double-slot>", | |
2218 | scm_class_class, scm_class_foreign_slot, SCM_EOL); | |
2219 | ||
2220 | /* Continue initialization of class <class> */ | |
6d77c894 | 2221 | |
80662eda | 2222 | slots = build_class_class_slots (); |
dcb410ec DH |
2223 | SCM_SET_SLOT (scm_class_class, scm_si_direct_slots, slots); |
2224 | SCM_SET_SLOT (scm_class_class, scm_si_slots, slots); | |
2225 | SCM_SET_SLOT (scm_class_class, scm_si_getters_n_setters, | |
2226 | compute_getters_n_setters (slots)); | |
6d77c894 | 2227 | |
80662eda MD |
2228 | make_stdcls (&scm_class_foreign_class, "<foreign-class>", |
2229 | scm_class_class, scm_class_class, | |
1afff620 KN |
2230 | scm_list_2 (scm_list_3 (scm_str2symbol ("constructor"), |
2231 | k_class, | |
2232 | scm_class_opaque), | |
2233 | scm_list_3 (scm_str2symbol ("destructor"), | |
2234 | k_class, | |
2235 | scm_class_opaque))); | |
80662eda MD |
2236 | make_stdcls (&scm_class_foreign_object, "<foreign-object>", |
2237 | scm_class_foreign_class, scm_class_object, SCM_EOL); | |
2238 | SCM_SET_CLASS_FLAGS (scm_class_foreign_object, SCM_CLASSF_FOREIGN); | |
2239 | ||
2240 | /* scm_class_generic functions classes */ | |
2241 | make_stdcls (&scm_class_procedure_class, "<procedure-class>", | |
2242 | scm_class_class, scm_class_class, SCM_EOL); | |
2243 | make_stdcls (&scm_class_entity_class, "<entity-class>", | |
2244 | scm_class_class, scm_class_procedure_class, SCM_EOL); | |
2245 | make_stdcls (&scm_class_operator_class, "<operator-class>", | |
2246 | scm_class_class, scm_class_procedure_class, SCM_EOL); | |
2247 | make_stdcls (&scm_class_operator_with_setter_class, | |
2248 | "<operator-with-setter-class>", | |
2249 | scm_class_class, scm_class_operator_class, SCM_EOL); | |
2250 | make_stdcls (&scm_class_method, "<method>", | |
2251 | scm_class_class, scm_class_object, method_slots); | |
2252 | make_stdcls (&scm_class_simple_method, "<simple-method>", | |
2253 | scm_class_class, scm_class_method, SCM_EOL); | |
2254 | SCM_SET_CLASS_FLAGS (scm_class_simple_method, SCM_CLASSF_SIMPLE_METHOD); | |
2255 | make_stdcls (&scm_class_accessor, "<accessor-method>", | |
2256 | scm_class_class, scm_class_simple_method, amethod_slots); | |
2257 | SCM_SET_CLASS_FLAGS (scm_class_accessor, SCM_CLASSF_ACCESSOR_METHOD); | |
2258 | make_stdcls (&scm_class_entity, "<entity>", | |
2259 | scm_class_entity_class, scm_class_object, SCM_EOL); | |
2260 | make_stdcls (&scm_class_entity_with_setter, "<entity-with-setter>", | |
2261 | scm_class_entity_class, scm_class_entity, SCM_EOL); | |
2262 | make_stdcls (&scm_class_generic, "<generic>", | |
2263 | scm_class_entity_class, scm_class_entity, gf_slots); | |
2264 | SCM_SET_CLASS_FLAGS (scm_class_generic, SCM_CLASSF_PURE_GENERIC); | |
2265 | make_stdcls (&scm_class_generic_with_setter, "<generic-with-setter>", | |
2266 | scm_class_entity_class, | |
1afff620 | 2267 | scm_list_2 (scm_class_generic, scm_class_entity_with_setter), |
80662eda MD |
2268 | SCM_EOL); |
2269 | #if 0 | |
2270 | /* Patch cpl since compute_cpl doesn't support multiple inheritance. */ | |
6d77c894 | 2271 | SCM_SET_SLOT (scm_class_generic_with_setter, scm_si_cpl, |
1afff620 KN |
2272 | scm_append (scm_list_3 (scm_list_2 (scm_class_generic_with_setter, |
2273 | scm_class_generic), | |
2274 | SCM_SLOT (scm_class_entity_with_setter, | |
2275 | scm_si_cpl), | |
2276 | SCM_EOL))); | |
80662eda MD |
2277 | #endif |
2278 | SCM_SET_CLASS_FLAGS (scm_class_generic_with_setter, SCM_CLASSF_PURE_GENERIC); | |
2279 | ||
2280 | /* Primitive types classes */ | |
2281 | make_stdcls (&scm_class_boolean, "<boolean>", | |
2282 | scm_class_class, scm_class_top, SCM_EOL); | |
2283 | make_stdcls (&scm_class_char, "<char>", | |
2284 | scm_class_class, scm_class_top, SCM_EOL); | |
2285 | make_stdcls (&scm_class_list, "<list>", | |
2286 | scm_class_class, scm_class_top, SCM_EOL); | |
2287 | make_stdcls (&scm_class_pair, "<pair>", | |
2288 | scm_class_class, scm_class_list, SCM_EOL); | |
2289 | make_stdcls (&scm_class_null, "<null>", | |
2290 | scm_class_class, scm_class_list, SCM_EOL); | |
2291 | make_stdcls (&scm_class_string, "<string>", | |
2292 | scm_class_class, scm_class_top, SCM_EOL); | |
2293 | make_stdcls (&scm_class_symbol, "<symbol>", | |
2294 | scm_class_class, scm_class_top, SCM_EOL); | |
2295 | make_stdcls (&scm_class_vector, "<vector>", | |
2296 | scm_class_class, scm_class_top, SCM_EOL); | |
2297 | make_stdcls (&scm_class_number, "<number>", | |
2298 | scm_class_class, scm_class_top, SCM_EOL); | |
2299 | make_stdcls (&scm_class_complex, "<complex>", | |
2300 | scm_class_class, scm_class_number, SCM_EOL); | |
2301 | make_stdcls (&scm_class_real, "<real>", | |
2302 | scm_class_class, scm_class_complex, SCM_EOL); | |
2303 | make_stdcls (&scm_class_integer, "<integer>", | |
2304 | scm_class_class, scm_class_real, SCM_EOL); | |
2305 | make_stdcls (&scm_class_keyword, "<keyword>", | |
2306 | scm_class_class, scm_class_top, SCM_EOL); | |
2307 | make_stdcls (&scm_class_unknown, "<unknown>", | |
2308 | scm_class_class, scm_class_top, SCM_EOL); | |
2309 | make_stdcls (&scm_class_procedure, "<procedure>", | |
2310 | scm_class_procedure_class, scm_class_top, SCM_EOL); | |
2311 | make_stdcls (&scm_class_procedure_with_setter, "<procedure-with-setter>", | |
2312 | scm_class_procedure_class, scm_class_procedure, SCM_EOL); | |
2313 | make_stdcls (&scm_class_primitive_generic, "<primitive-generic>", | |
2314 | scm_class_procedure_class, scm_class_procedure, SCM_EOL); | |
2315 | make_stdcls (&scm_class_port, "<port>", | |
2316 | scm_class_class, scm_class_top, SCM_EOL); | |
2317 | make_stdcls (&scm_class_input_port, "<input-port>", | |
2318 | scm_class_class, scm_class_port, SCM_EOL); | |
2319 | make_stdcls (&scm_class_output_port, "<output-port>", | |
2320 | scm_class_class, scm_class_port, SCM_EOL); | |
2321 | make_stdcls (&scm_class_input_output_port, "<input-output-port>", | |
2322 | scm_class_class, | |
1afff620 | 2323 | scm_list_2 (scm_class_input_port, scm_class_output_port), |
80662eda MD |
2324 | SCM_EOL); |
2325 | } | |
2326 | ||
2327 | /********************************************************************** | |
2328 | * | |
2329 | * Smob classes | |
2330 | * | |
2331 | **********************************************************************/ | |
2332 | ||
2333 | static SCM | |
2334 | make_class_from_template (char *template, char *type_name, SCM supers) | |
2335 | { | |
2336 | SCM class, name; | |
2337 | if (type_name) | |
2338 | { | |
2339 | char buffer[100]; | |
2340 | sprintf (buffer, template, type_name); | |
38ae064c | 2341 | name = scm_str2symbol (buffer); |
80662eda MD |
2342 | } |
2343 | else | |
2344 | name = SCM_GOOPS_UNBOUND; | |
2345 | ||
2346 | class = scm_permanent_object (scm_basic_make_class (scm_class_class, | |
2347 | name, | |
2348 | supers, | |
2349 | SCM_EOL)); | |
2350 | ||
2351 | /* Only define name if doesn't already exist. */ | |
2352 | if (!SCM_GOOPS_UNBOUNDP (name) | |
fdc28395 | 2353 | && SCM_FALSEP (scm_call_2 (scm_goops_lookup_closure, name, SCM_BOOL_F))) |
0ba8a0a5 | 2354 | DEFVAR (name, class); |
80662eda MD |
2355 | return class; |
2356 | } | |
2357 | ||
2358 | SCM | |
2359 | scm_make_extended_class (char *type_name) | |
2360 | { | |
2361 | return make_class_from_template ("<%s>", | |
2362 | type_name, | |
1afff620 | 2363 | scm_list_1 (scm_class_top)); |
80662eda MD |
2364 | } |
2365 | ||
2366 | static void | |
2367 | create_smob_classes (void) | |
2368 | { | |
c014a02e | 2369 | long i; |
80662eda | 2370 | |
67329a9e | 2371 | scm_smob_class = (SCM *) scm_malloc (255 * sizeof (SCM)); |
80662eda MD |
2372 | for (i = 0; i < 255; ++i) |
2373 | scm_smob_class[i] = 0; | |
2374 | ||
2375 | scm_smob_class[SCM_TC2SMOBNUM (scm_tc16_big)] = scm_class_integer; | |
2376 | scm_smob_class[SCM_TC2SMOBNUM (scm_tc16_real)] = scm_class_real; | |
2377 | scm_smob_class[SCM_TC2SMOBNUM (scm_tc16_complex)] = scm_class_complex; | |
2378 | scm_smob_class[SCM_TC2SMOBNUM (scm_tc16_keyword)] = scm_class_keyword; | |
6d77c894 | 2379 | |
80662eda MD |
2380 | for (i = 0; i < scm_numsmob; ++i) |
2381 | if (!scm_smob_class[i]) | |
2382 | scm_smob_class[i] = scm_make_extended_class (SCM_SMOBNAME (i)); | |
2383 | } | |
2384 | ||
2385 | void | |
c014a02e | 2386 | scm_make_port_classes (long ptobnum, char *type_name) |
80662eda MD |
2387 | { |
2388 | SCM c, class = make_class_from_template ("<%s-port>", | |
2389 | type_name, | |
1afff620 | 2390 | scm_list_1 (scm_class_port)); |
80662eda MD |
2391 | scm_port_class[SCM_IN_PCLASS_INDEX + ptobnum] |
2392 | = make_class_from_template ("<%s-input-port>", | |
2393 | type_name, | |
1afff620 | 2394 | scm_list_2 (class, scm_class_input_port)); |
80662eda MD |
2395 | scm_port_class[SCM_OUT_PCLASS_INDEX + ptobnum] |
2396 | = make_class_from_template ("<%s-output-port>", | |
2397 | type_name, | |
1afff620 | 2398 | scm_list_2 (class, scm_class_output_port)); |
80662eda MD |
2399 | scm_port_class[SCM_INOUT_PCLASS_INDEX + ptobnum] |
2400 | = c | |
2401 | = make_class_from_template ("<%s-input-output-port>", | |
2402 | type_name, | |
1afff620 | 2403 | scm_list_2 (class, scm_class_input_output_port)); |
80662eda | 2404 | /* Patch cpl (since this tree is too complex for the C level compute-cpl) */ |
dcb410ec DH |
2405 | SCM_SET_SLOT (c, scm_si_cpl, |
2406 | scm_cons2 (c, class, SCM_SLOT (scm_class_input_output_port, scm_si_cpl))); | |
80662eda MD |
2407 | } |
2408 | ||
2409 | static void | |
2410 | create_port_classes (void) | |
2411 | { | |
c014a02e | 2412 | long i; |
80662eda | 2413 | |
67329a9e | 2414 | scm_port_class = (SCM *) scm_malloc (3 * 256 * sizeof (SCM)); |
80662eda MD |
2415 | for (i = 0; i < 3 * 256; ++i) |
2416 | scm_port_class[i] = 0; | |
2417 | ||
2418 | for (i = 0; i < scm_numptob; ++i) | |
2419 | scm_make_port_classes (i, SCM_PTOBNAME (i)); | |
2420 | } | |
2421 | ||
2422 | static SCM | |
6d77c894 | 2423 | make_struct_class (void *closure SCM_UNUSED, SCM key SCM_UNUSED, |
e81d98ec | 2424 | SCM data, SCM prev SCM_UNUSED) |
80662eda | 2425 | { |
6b80d352 | 2426 | if (!SCM_FALSEP (SCM_STRUCT_TABLE_NAME (data))) |
80662eda MD |
2427 | SCM_SET_STRUCT_TABLE_CLASS (data, |
2428 | scm_make_extended_class | |
b24b5e13 | 2429 | (SCM_SYMBOL_CHARS (SCM_STRUCT_TABLE_NAME (data)))); |
80662eda MD |
2430 | return SCM_UNSPECIFIED; |
2431 | } | |
2432 | ||
2433 | static void | |
2434 | create_struct_classes (void) | |
2435 | { | |
2436 | scm_internal_hash_fold (make_struct_class, 0, SCM_BOOL_F, scm_struct_table); | |
2437 | } | |
2438 | ||
2439 | /********************************************************************** | |
2440 | * | |
2441 | * C interface | |
2442 | * | |
2443 | **********************************************************************/ | |
2444 | ||
2445 | void | |
2446 | scm_load_goops () | |
2447 | { | |
2448 | if (!goops_loaded_p) | |
abd28220 | 2449 | scm_c_resolve_module ("oop goops"); |
80662eda MD |
2450 | } |
2451 | ||
e11208ca | 2452 | |
80662eda MD |
2453 | SCM |
2454 | scm_make_foreign_object (SCM class, SCM initargs) | |
e11208ca | 2455 | #define FUNC_NAME s_scm_make |
80662eda MD |
2456 | { |
2457 | void * (*constructor) (SCM) | |
2458 | = (void * (*) (SCM)) SCM_SLOT (class, scm_si_constructor); | |
e11208ca | 2459 | if (constructor == 0) |
1afff620 | 2460 | SCM_MISC_ERROR ("Can't make instances of class ~S", scm_list_1 (class)); |
80662eda MD |
2461 | return scm_wrap_object (class, constructor (initargs)); |
2462 | } | |
e11208ca DH |
2463 | #undef FUNC_NAME |
2464 | ||
80662eda MD |
2465 | |
2466 | static size_t | |
2467 | scm_free_foreign_object (SCM *class, SCM *data) | |
2468 | { | |
2469 | size_t (*destructor) (void *) | |
2470 | = (size_t (*) (void *)) class[scm_si_destructor]; | |
2471 | return destructor (data); | |
2472 | } | |
2473 | ||
2474 | SCM | |
2475 | scm_make_class (SCM meta, char *s_name, SCM supers, size_t size, | |
2476 | void * (*constructor) (SCM initargs), | |
2477 | size_t (*destructor) (void *)) | |
2478 | { | |
2479 | SCM name, class; | |
38ae064c | 2480 | name = scm_str2symbol (s_name); |
6b80d352 | 2481 | if (SCM_NULLP (supers)) |
1afff620 | 2482 | supers = scm_list_1 (scm_class_foreign_object); |
80662eda MD |
2483 | class = scm_basic_basic_make_class (meta, name, supers, SCM_EOL); |
2484 | scm_sys_inherit_magic_x (class, supers); | |
2485 | ||
2486 | if (destructor != 0) | |
2487 | { | |
dcb410ec | 2488 | SCM_SET_SLOT (class, scm_si_destructor, (SCM) destructor); |
80662eda MD |
2489 | SCM_SET_CLASS_DESTRUCTOR (class, scm_free_foreign_object); |
2490 | } | |
2491 | else if (size > 0) | |
2492 | { | |
2493 | SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_light); | |
2494 | SCM_SET_CLASS_INSTANCE_SIZE (class, size); | |
2495 | } | |
6d77c894 | 2496 | |
dcb410ec DH |
2497 | SCM_SET_SLOT (class, scm_si_layout, scm_str2symbol ("")); |
2498 | SCM_SET_SLOT (class, scm_si_constructor, (SCM) constructor); | |
80662eda MD |
2499 | |
2500 | return class; | |
2501 | } | |
2502 | ||
2503 | SCM_SYMBOL (sym_o, "o"); | |
2504 | SCM_SYMBOL (sym_x, "x"); | |
2505 | ||
2506 | SCM_KEYWORD (k_accessor, "accessor"); | |
2507 | SCM_KEYWORD (k_getter, "getter"); | |
2508 | ||
2509 | static SCM | |
e81d98ec | 2510 | default_setter (SCM obj SCM_UNUSED, SCM c SCM_UNUSED) |
80662eda MD |
2511 | { |
2512 | scm_misc_error ("slot-set!", "read-only slot", SCM_EOL); | |
2513 | return 0; | |
2514 | } | |
2515 | ||
2516 | void | |
2517 | scm_add_slot (SCM class, char *slot_name, SCM slot_class, | |
2518 | SCM (*getter) (SCM obj), | |
2519 | SCM (*setter) (SCM obj, SCM x), | |
2520 | char *accessor_name) | |
2521 | { | |
2522 | { | |
9a441ddb MV |
2523 | SCM get = scm_c_make_subr ("goops:get", scm_tc7_subr_1, getter); |
2524 | SCM set = scm_c_make_subr ("goops:set", scm_tc7_subr_2, | |
2525 | setter ? setter : default_setter); | |
1afff620 KN |
2526 | SCM getm = scm_closure (scm_list_2 (scm_list_1 (sym_o), |
2527 | scm_list_2 (get, sym_o)), | |
80662eda | 2528 | SCM_EOL); |
1afff620 KN |
2529 | SCM setm = scm_closure (scm_list_2 (scm_list_2 (sym_o, sym_x), |
2530 | scm_list_3 (set, sym_o, sym_x)), | |
80662eda MD |
2531 | SCM_EOL); |
2532 | { | |
38ae064c DH |
2533 | SCM name = scm_str2symbol (slot_name); |
2534 | SCM aname = scm_str2symbol (accessor_name); | |
80662eda | 2535 | SCM gf = scm_ensure_accessor (aname); |
1afff620 KN |
2536 | SCM slot = scm_list_5 (name, |
2537 | k_class, | |
2538 | slot_class, | |
2539 | setter ? k_accessor : k_getter, | |
2540 | gf); | |
2541 | SCM gns = scm_list_4 (name, SCM_BOOL_F, get, set); | |
2542 | ||
2543 | scm_add_method (gf, scm_make (scm_list_5 (scm_class_accessor, | |
2544 | k_specializers, | |
2545 | scm_list_1 (class), | |
2546 | k_procedure, | |
2547 | getm))); | |
80662eda | 2548 | scm_add_method (scm_setter (gf), |
1afff620 KN |
2549 | scm_make (scm_list_5 (scm_class_accessor, |
2550 | k_specializers, | |
2551 | scm_list_2 (class, scm_class_top), | |
2552 | k_procedure, | |
2553 | setm))); | |
80662eda | 2554 | DEFVAR (aname, gf); |
6d77c894 | 2555 | |
dcb410ec | 2556 | SCM_SET_SLOT (class, scm_si_slots, |
1afff620 KN |
2557 | scm_append_x (scm_list_2 (SCM_SLOT (class, scm_si_slots), |
2558 | scm_list_1 (slot)))); | |
dcb410ec | 2559 | SCM_SET_SLOT (class, scm_si_getters_n_setters, |
1afff620 KN |
2560 | scm_append_x (scm_list_2 (SCM_SLOT (class, scm_si_getters_n_setters), |
2561 | scm_list_1 (gns)))); | |
80662eda MD |
2562 | } |
2563 | } | |
6d77c894 | 2564 | { |
c014a02e | 2565 | long n = SCM_INUM (SCM_SLOT (class, scm_si_nfields)); |
80662eda | 2566 | |
dcb410ec | 2567 | SCM_SET_SLOT (class, scm_si_nfields, SCM_MAKINUM (n + 1)); |
80662eda MD |
2568 | } |
2569 | } | |
2570 | ||
2571 | SCM | |
2572 | scm_wrap_object (SCM class, void *data) | |
2573 | { | |
228a24ef DH |
2574 | return scm_double_cell (SCM_UNPACK (SCM_CDR (class)) | scm_tc3_struct, |
2575 | (scm_t_bits) data, | |
2576 | 0, 0); | |
80662eda MD |
2577 | } |
2578 | ||
2579 | SCM scm_components; | |
2580 | ||
2581 | SCM | |
2582 | scm_wrap_component (SCM class, SCM container, void *data) | |
2583 | { | |
2584 | SCM obj = scm_wrap_object (class, data); | |
2585 | SCM handle = scm_hash_fn_create_handle_x (scm_components, | |
2586 | obj, | |
2587 | SCM_BOOL_F, | |
2588 | scm_struct_ihashq, | |
2589 | scm_sloppy_assq, | |
2590 | 0); | |
2591 | SCM_SETCDR (handle, container); | |
2592 | return obj; | |
2593 | } | |
2594 | ||
2595 | SCM | |
2596 | scm_ensure_accessor (SCM name) | |
2597 | { | |
fdc28395 | 2598 | SCM gf = scm_call_2 (SCM_TOP_LEVEL_LOOKUP_CLOSURE, name, SCM_BOOL_F); |
80662eda MD |
2599 | if (!SCM_IS_A_P (gf, scm_class_generic_with_setter)) |
2600 | { | |
1afff620 KN |
2601 | gf = scm_make (scm_list_3 (scm_class_generic, k_name, name)); |
2602 | gf = scm_make (scm_list_5 (scm_class_generic_with_setter, | |
2603 | k_name, name, k_setter, gf)); | |
80662eda MD |
2604 | } |
2605 | return gf; | |
2606 | } | |
2607 | ||
2608 | SCM_SYMBOL (sym_internal_add_method_x, "internal-add-method!"); | |
2609 | ||
2610 | void | |
2611 | scm_add_method (SCM gf, SCM m) | |
2612 | { | |
1afff620 | 2613 | scm_eval (scm_list_3 (sym_internal_add_method_x, gf, m), scm_module_goops); |
80662eda MD |
2614 | } |
2615 | ||
2616 | #ifdef GUILE_DEBUG | |
2617 | /* | |
2618 | * Debugging utilities | |
2619 | */ | |
2620 | ||
398d8ee1 KN |
2621 | SCM_DEFINE (scm_pure_generic_p, "pure-generic?", 1, 0, 0, |
2622 | (SCM obj), | |
6bcefd15 | 2623 | "Return @code{#t} if @var{obj} is a pure generic.") |
398d8ee1 | 2624 | #define FUNC_NAME s_scm_pure_generic_p |
80662eda | 2625 | { |
25ba37df | 2626 | return SCM_BOOL (SCM_PUREGENERICP (obj)); |
80662eda | 2627 | } |
398d8ee1 | 2628 | #undef FUNC_NAME |
80662eda MD |
2629 | |
2630 | #endif /* GUILE_DEBUG */ | |
2631 | ||
2632 | /* | |
2633 | * Initialization | |
2634 | */ | |
2635 | ||
398d8ee1 KN |
2636 | SCM_DEFINE (scm_sys_goops_loaded, "%goops-loaded", 0, 0, 0, |
2637 | (), | |
6bcefd15 MG |
2638 | "Announce that GOOPS is loaded and perform initialization\n" |
2639 | "on the C level which depends on the loaded GOOPS modules.") | |
398d8ee1 | 2640 | #define FUNC_NAME s_scm_sys_goops_loaded |
80662eda MD |
2641 | { |
2642 | goops_loaded_p = 1; | |
86d31dfe MV |
2643 | var_compute_applicable_methods = |
2644 | scm_sym2var (sym_compute_applicable_methods, scm_goops_lookup_closure, | |
2645 | SCM_BOOL_F); | |
80662eda MD |
2646 | return SCM_UNSPECIFIED; |
2647 | } | |
398d8ee1 | 2648 | #undef FUNC_NAME |
80662eda MD |
2649 | |
2650 | SCM scm_module_goops; | |
2651 | ||
abd28220 MV |
2652 | SCM |
2653 | scm_init_goops_builtins (void) | |
80662eda | 2654 | { |
abd28220 | 2655 | scm_module_goops = scm_current_module (); |
80662eda MD |
2656 | scm_goops_lookup_closure = scm_module_lookup_closure (scm_module_goops); |
2657 | ||
6d77c894 | 2658 | /* Not really necessary right now, but who knows... |
0ba8a0a5 MV |
2659 | */ |
2660 | scm_permanent_object (scm_module_goops); | |
2661 | scm_permanent_object (scm_goops_lookup_closure); | |
2662 | ||
80662eda MD |
2663 | scm_components = scm_permanent_object (scm_make_weak_key_hash_table |
2664 | (SCM_MAKINUM (37))); | |
2665 | ||
2666 | goops_rstate = scm_c_make_rstate ("GOOPS", 5); | |
2667 | ||
2668 | #include "libguile/goops.x" | |
2669 | ||
1afff620 | 2670 | list_of_no_method = scm_permanent_object (scm_list_1 (sym_no_method)); |
80662eda | 2671 | |
4c9419ac | 2672 | hell = scm_malloc (hell_size); |
2132f0d2 | 2673 | hell_mutex = scm_permanent_object (scm_make_mutex ()); |
80662eda MD |
2674 | |
2675 | create_basic_classes (); | |
2676 | create_standard_classes (); | |
2677 | create_smob_classes (); | |
2678 | create_struct_classes (); | |
2679 | create_port_classes (); | |
2680 | ||
2681 | { | |
38ae064c | 2682 | SCM name = scm_str2symbol ("no-applicable-method"); |
80662eda | 2683 | scm_no_applicable_method |
1afff620 KN |
2684 | = scm_permanent_object (scm_make (scm_list_3 (scm_class_generic, |
2685 | k_name, | |
2686 | name))); | |
80662eda MD |
2687 | DEFVAR (name, scm_no_applicable_method); |
2688 | } | |
abd28220 MV |
2689 | |
2690 | return SCM_UNSPECIFIED; | |
80662eda MD |
2691 | } |
2692 | ||
2693 | void | |
abd28220 | 2694 | scm_init_goops () |
80662eda | 2695 | { |
9a441ddb MV |
2696 | scm_c_define_gsubr ("%init-goops-builtins", 0, 0, 0, |
2697 | scm_init_goops_builtins); | |
80662eda | 2698 | } |
23437298 DH |
2699 | |
2700 | /* | |
2701 | Local Variables: | |
2702 | c-file-style: "gnu" | |
2703 | End: | |
2704 | */ |