1 /* Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library 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 GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /* This software is a derivative work of other copyrighted softwares; the
20 * copyright notices of these softwares are placed in the file COPYRIGHTS
22 * This file is based upon stklos.c from the STk distribution by
23 * Erick Gallesio <eg@unice.fr>.
28 #include "libguile/_scm.h"
29 #include "libguile/alist.h"
30 #include "libguile/debug.h"
31 #include "libguile/dynl.h"
32 #include "libguile/dynwind.h"
33 #include "libguile/eval.h"
34 #include "libguile/hashtab.h"
35 #include "libguile/keywords.h"
36 #include "libguile/macros.h"
37 #include "libguile/modules.h"
38 #include "libguile/objects.h"
39 #include "libguile/ports.h"
40 #include "libguile/procprop.h"
41 #include "libguile/random.h"
42 #include "libguile/root.h"
43 #include "libguile/smob.h"
44 #include "libguile/strings.h"
45 #include "libguile/strports.h"
46 #include "libguile/vectors.h"
47 #include "libguile/weaks.h"
49 #include "libguile/validate.h"
50 #include "libguile/goops.h"
52 #define SPEC_OF(x) SCM_SLOT (x, scm_si_specializers)
54 #define DEFVAR(v, val) \
55 { scm_eval (scm_list_3 (scm_sym_define_public, (v), (val)), \
57 /* Temporary hack until we get the new module system */
58 /*fixme* Should optimize by keeping track of the variable object itself */
59 #define GETVAR(v) (SCM_VARIABLE_REF (scm_call_2 (scm_goops_lookup_closure, \
62 /* Fixme: Should use already interned symbols */
63 #define CALL_GF1(name, a) (scm_call_1 (GETVAR (scm_str2symbol (name)), \
65 #define CALL_GF2(name, a, b) (scm_call_2 (GETVAR (scm_str2symbol (name)), \
67 #define CALL_GF3(name, a, b, c) (scm_call_3 (GETVAR (scm_str2symbol (name)), \
69 #define CALL_GF4(name, a, b, c, d) (scm_call_4 (GETVAR (scm_str2symbol (name)), \
72 /* Class redefinition protocol:
74 A class is represented by a heap header h1 which points to a
75 malloc:ed memory block m1.
77 When a new version of a class is created, a new header h2 and
78 memory block m2 are allocated. The headers h1 and h2 then switch
79 pointers so that h1 refers to m2 and h2 to m1. In this way, names
80 bound to h1 will point to the new class at the same time as h2 will
81 be a handle which the GC will us to free m1.
83 The `redefined' slot of m1 will be set to point to h1. An old
84 instance will have it's class pointer (the CAR of the heap header)
85 pointing to m1. The non-immediate `redefined'-slot in m1 indicates
86 the class modification and the new class pointer can be found via
90 /* The following definition is located in libguile/objects.h:
91 #define SCM_OBJ_CLASS_REDEF(x) (SCM_STRUCT_VTABLE_DATA(x)[scm_si_redefined])
94 #define TEST_CHANGE_CLASS(obj, class) \
96 class = SCM_CLASS_OF (obj); \
97 if (!SCM_FALSEP (SCM_OBJ_CLASS_REDEF (obj))) \
99 scm_change_object_class (obj, class, SCM_OBJ_CLASS_REDEF (obj));\
100 class = SCM_CLASS_OF (obj); \
104 #define NXT_MTHD_METHODS(m) (SCM_VELTS (m)[1])
105 #define NXT_MTHD_ARGS(m) (SCM_VELTS (m)[2])
107 #define SCM_GOOPS_UNBOUND SCM_UNBOUND
108 #define SCM_GOOPS_UNBOUNDP(x) ((x) == SCM_GOOPS_UNBOUND)
110 static int goops_loaded_p
= 0;
111 static scm_t_rstate
*goops_rstate
;
113 static SCM scm_goops_lookup_closure
;
115 /* Some classes are defined in libguile/objects.c. */
116 SCM scm_class_top
, scm_class_object
, scm_class_class
;
117 SCM scm_class_applicable
;
118 SCM scm_class_entity
, scm_class_entity_with_setter
;
119 SCM scm_class_generic
, scm_class_generic_with_setter
;
120 SCM scm_class_accessor
;
121 SCM scm_class_extended_generic
, scm_class_extended_generic_with_setter
;
122 SCM scm_class_extended_accessor
;
123 SCM scm_class_method
;
124 SCM scm_class_simple_method
, scm_class_accessor_method
;
125 SCM scm_class_procedure_class
;
126 SCM scm_class_operator_class
, scm_class_operator_with_setter_class
;
127 SCM scm_class_entity_class
;
128 SCM scm_class_number
, scm_class_list
;
129 SCM scm_class_keyword
;
130 SCM scm_class_port
, scm_class_input_output_port
;
131 SCM scm_class_input_port
, scm_class_output_port
;
132 SCM scm_class_foreign_class
, scm_class_foreign_object
;
133 SCM scm_class_foreign_slot
;
134 SCM scm_class_self
, scm_class_protected
;
135 SCM scm_class_opaque
, scm_class_read_only
;
136 SCM scm_class_protected_opaque
, scm_class_protected_read_only
;
138 SCM scm_class_int
, scm_class_float
, scm_class_double
;
140 SCM_SYMBOL (scm_sym_define_public
, "define-public");
142 static SCM
scm_make_unbound (void);
143 static SCM
scm_unbound_p (SCM obj
);
144 static SCM
scm_assert_bound (SCM value
, SCM obj
);
145 static SCM
scm_at_assert_bound_ref (SCM obj
, SCM index
);
146 static SCM
scm_sys_goops_loaded (void);
148 /******************************************************************************
152 * This version doesn't fully handle multiple-inheritance. It serves
153 * only for booting classes and will be overloaded in Scheme
155 ******************************************************************************/
158 map (SCM (*proc
) (SCM
), SCM ls
)
164 SCM res
= scm_cons (proc (SCM_CAR (ls
)), SCM_EOL
);
167 while (!SCM_NULLP (ls
))
169 SCM_SETCDR (h
, scm_cons (proc (SCM_CAR (ls
)), SCM_EOL
));
181 while (!SCM_NULLP (ls
))
183 SCM el
= SCM_CAR (ls
);
184 if (SCM_FALSEP (scm_c_memq (el
, res
)))
185 res
= scm_cons (el
, res
);
192 compute_cpl (SCM
class)
195 return CALL_GF1 ("compute-cpl", class);
198 SCM supers
= SCM_SLOT (class, scm_si_direct_supers
);
199 SCM ls
= scm_append (scm_acons (class, supers
,
200 map (compute_cpl
, supers
)));
201 return scm_reverse_x (filter_cpl (ls
), SCM_EOL
);
205 /******************************************************************************
209 ******************************************************************************/
212 remove_duplicate_slots (SCM l
, SCM res
, SCM slots_already_seen
)
220 if (!SCM_SYMBOLP (tmp
))
221 scm_misc_error ("%compute-slots", "bad slot name ~S", scm_list_1 (tmp
));
223 if (SCM_FALSEP (scm_c_memq (tmp
, slots_already_seen
))) {
224 res
= scm_cons (SCM_CAR (l
), res
);
225 slots_already_seen
= scm_cons (tmp
, slots_already_seen
);
228 return remove_duplicate_slots (SCM_CDR (l
), res
, slots_already_seen
);
232 build_slots_list (SCM dslots
, SCM cpl
)
234 register SCM res
= dslots
;
236 for (cpl
= SCM_CDR (cpl
); !SCM_NULLP (cpl
); cpl
= SCM_CDR (cpl
))
237 res
= scm_append (scm_list_2 (SCM_SLOT (SCM_CAR (cpl
),
238 scm_si_direct_slots
),
241 /* res contains a list of slots. Remove slots which appears more than once */
242 return remove_duplicate_slots (scm_reverse (res
), SCM_EOL
, SCM_EOL
);
249 while (!SCM_NULLP (ls
))
251 if (!SCM_CONSP (SCM_CAR (ls
)))
252 SCM_SETCAR (ls
, scm_cons (SCM_CAR (ls
), SCM_EOL
));
259 SCM_DEFINE (scm_sys_compute_slots
, "%compute-slots", 1, 0, 0,
261 "Return a list consisting of the names of all slots belonging to\n"
262 "class @var{class}, i. e. the slots of @var{class} and of all of\n"
264 #define FUNC_NAME s_scm_sys_compute_slots
266 SCM_VALIDATE_CLASS (1, class);
267 return build_slots_list (SCM_SLOT (class, scm_si_direct_slots
),
268 SCM_SLOT (class, scm_si_cpl
));
273 /******************************************************************************
275 * compute-getters-n-setters
277 * This version doesn't handle slot options. It serves only for booting
278 * classes and will be overloaded in Scheme.
280 ******************************************************************************/
282 SCM_KEYWORD (k_init_value
, "init-value");
283 SCM_KEYWORD (k_init_thunk
, "init-thunk");
286 compute_getters_n_setters (SCM slots
)
292 for ( ; !SCM_NULLP (slots
); slots
= SCM_CDR (slots
))
294 SCM init
= SCM_BOOL_F
;
295 SCM options
= SCM_CDAR (slots
);
296 if (!SCM_NULLP (options
))
298 init
= scm_get_keyword (k_init_value
, options
, 0);
300 init
= scm_closure (scm_list_2 (SCM_EOL
,
301 scm_list_2 (scm_sym_quote
, init
)),
304 init
= scm_get_keyword (k_init_thunk
, options
, SCM_BOOL_F
);
306 *cdrloc
= scm_cons (scm_cons (SCM_CAAR (slots
),
310 cdrloc
= SCM_CDRLOC (*cdrloc
);
315 /******************************************************************************
319 ******************************************************************************/
321 /*fixme* Manufacture keywords in advance */
323 scm_i_get_keyword (SCM key
, SCM l
, long len
, SCM default_value
, const char *subr
)
327 for (i
= 0; i
!= len
; i
+= 2)
329 SCM obj
= SCM_CAR (l
);
331 if (!SCM_KEYWORDP (obj
))
332 scm_misc_error (subr
, "bad keyword: ~S", scm_list_1 (obj
));
333 else if (SCM_EQ_P (obj
, key
))
339 return default_value
;
343 SCM_DEFINE (scm_get_keyword
, "get-keyword", 3, 0, 0,
344 (SCM key
, SCM l
, SCM default_value
),
345 "Determine an associated value for the keyword @var{key} from\n"
346 "the list @var{l}. The list @var{l} has to consist of an even\n"
347 "number of elements, where, starting with the first, every\n"
348 "second element is a keyword, followed by its associated value.\n"
349 "If @var{l} does not hold a value for @var{key}, the value\n"
350 "@var{default_value} is returned.")
351 #define FUNC_NAME s_scm_get_keyword
355 SCM_ASSERT (SCM_KEYWORDP (key
), key
, SCM_ARG1
, FUNC_NAME
);
356 len
= scm_ilength (l
);
357 if (len
< 0 || len
% 2 == 1)
358 scm_misc_error (FUNC_NAME
, "Bad keyword-value list: ~S", scm_list_1 (l
));
360 return scm_i_get_keyword (key
, l
, len
, default_value
, FUNC_NAME
);
365 SCM_KEYWORD (k_init_keyword
, "init-keyword");
367 static SCM
get_slot_value (SCM
class, SCM obj
, SCM slotdef
);
368 static SCM
set_slot_value (SCM
class, SCM obj
, SCM slotdef
, SCM value
);
370 SCM_DEFINE (scm_sys_initialize_object
, "%initialize-object", 2, 0, 0,
371 (SCM obj
, SCM initargs
),
372 "Initialize the object @var{obj} with the given arguments\n"
374 #define FUNC_NAME s_scm_sys_initialize_object
376 SCM tmp
, get_n_set
, slots
;
377 SCM
class = SCM_CLASS_OF (obj
);
380 SCM_VALIDATE_INSTANCE (1, obj
);
381 n_initargs
= scm_ilength (initargs
);
382 SCM_ASSERT ((n_initargs
& 1) == 0, initargs
, SCM_ARG2
, FUNC_NAME
);
384 get_n_set
= SCM_SLOT (class, scm_si_getters_n_setters
);
385 slots
= SCM_SLOT (class, scm_si_slots
);
387 /* See for each slot how it must be initialized */
390 get_n_set
= SCM_CDR (get_n_set
), slots
= SCM_CDR (slots
))
392 SCM slot_name
= SCM_CAR (slots
);
395 if (!SCM_NULLP (SCM_CDR (slot_name
)))
397 /* This slot admits (perhaps) to be initialized at creation time */
398 long n
= scm_ilength (SCM_CDR (slot_name
));
399 if (n
& 1) /* odd or -1 */
400 SCM_MISC_ERROR ("class contains bogus slot definition: ~S",
401 scm_list_1 (slot_name
));
402 tmp
= scm_i_get_keyword (k_init_keyword
,
407 slot_name
= SCM_CAR (slot_name
);
410 /* an initarg was provided for this slot */
411 if (!SCM_KEYWORDP (tmp
))
412 SCM_MISC_ERROR ("initarg must be a keyword. It was ~S",
414 slot_value
= scm_i_get_keyword (tmp
,
423 /* set slot to provided value */
424 set_slot_value (class, obj
, SCM_CAR (get_n_set
), slot_value
);
427 /* set slot to its :init-form if it exists */
428 tmp
= SCM_CADAR (get_n_set
);
429 if (!SCM_FALSEP (tmp
))
431 slot_value
= get_slot_value (class, obj
, SCM_CAR (get_n_set
));
432 if (SCM_GOOPS_UNBOUNDP (slot_value
))
434 SCM env
= SCM_EXTEND_ENV (SCM_EOL
, SCM_EOL
, SCM_ENV (tmp
));
435 set_slot_value (class,
438 scm_eval_body (SCM_CLOSURE_BODY (tmp
), env
));
448 /* NOTE: The following macros are interdependent with code
449 * in goops.scm:compute-getters-n-setters
451 #define SCM_GNS_INSTANCE_ALLOCATED_P(gns) \
452 (SCM_INUMP (SCM_CDDR (gns)) \
453 || (SCM_CONSP (SCM_CDDR (gns)) \
454 && SCM_CONSP (SCM_CDDDR (gns)) \
455 && SCM_CONSP (SCM_CDDDDR (gns))))
456 #define SCM_GNS_INDEX(gns) \
457 (SCM_INUMP (SCM_CDDR (gns)) \
458 ? SCM_INUM (SCM_CDDR (gns)) \
459 : SCM_INUM (SCM_CAR (SCM_CDDDDR (gns))))
460 #define SCM_GNS_SIZE(gns) \
461 (SCM_INUMP (SCM_CDDR (gns)) \
463 : SCM_INUM (SCM_CADR (SCM_CDDDDR (gns))))
465 SCM_KEYWORD (k_class
, "class");
466 SCM_KEYWORD (k_allocation
, "allocation");
467 SCM_KEYWORD (k_instance
, "instance");
469 SCM_DEFINE (scm_sys_prep_layout_x
, "%prep-layout!", 1, 0, 0,
472 #define FUNC_NAME s_scm_sys_prep_layout_x
474 SCM slots
, getters_n_setters
, nfields
;
475 unsigned long int n
, i
;
478 SCM_VALIDATE_INSTANCE (1, class);
479 slots
= SCM_SLOT (class, scm_si_slots
);
480 getters_n_setters
= SCM_SLOT (class, scm_si_getters_n_setters
);
481 nfields
= SCM_SLOT (class, scm_si_nfields
);
482 if (!SCM_INUMP (nfields
) || SCM_INUM (nfields
) < 0)
483 SCM_MISC_ERROR ("bad value in nfields slot: ~S",
484 scm_list_1 (nfields
));
485 n
= 2 * SCM_INUM (nfields
);
486 if (n
< sizeof (SCM_CLASS_CLASS_LAYOUT
) - 1
487 && SCM_SUBCLASSP (class, scm_class_class
))
488 SCM_MISC_ERROR ("class object doesn't have enough fields: ~S",
489 scm_list_1 (nfields
));
491 s
= n
> 0 ? scm_malloc (n
) : 0;
493 while (SCM_CONSP (getters_n_setters
))
495 if (SCM_GNS_INSTANCE_ALLOCATED_P (SCM_CAR (getters_n_setters
)))
498 int len
, index
, size
;
501 if (i
>= n
|| !SCM_CONSP (slots
))
504 /* extract slot type */
505 len
= scm_ilength (SCM_CDAR (slots
));
506 type
= scm_i_get_keyword (k_class
, SCM_CDAR (slots
),
507 len
, SCM_BOOL_F
, FUNC_NAME
);
508 /* determine slot GC protection and access mode */
509 if (SCM_FALSEP (type
))
516 if (!SCM_CLASSP (type
))
520 SCM_MISC_ERROR ("bad slot class", SCM_EOL
);
522 else if (SCM_SUBCLASSP (type
, scm_class_foreign_slot
))
524 if (SCM_SUBCLASSP (type
, scm_class_self
))
526 else if (SCM_SUBCLASSP (type
, scm_class_protected
))
531 if (SCM_SUBCLASSP (type
, scm_class_opaque
))
533 else if (SCM_SUBCLASSP (type
, scm_class_read_only
))
545 index
= SCM_GNS_INDEX (SCM_CAR (getters_n_setters
));
546 if (index
!= (i
>> 1))
548 size
= SCM_GNS_SIZE (SCM_CAR (getters_n_setters
));
556 slots
= SCM_CDR (slots
);
557 getters_n_setters
= SCM_CDR (getters_n_setters
);
559 if (!SCM_NULLP (slots
))
564 SCM_MISC_ERROR ("inconsistent getters-n-setters", SCM_EOL
);
566 SCM_SET_SLOT (class, scm_si_layout
, scm_mem2symbol (s
, n
));
569 return SCM_UNSPECIFIED
;
573 static void prep_hashsets (SCM
);
575 SCM_DEFINE (scm_sys_inherit_magic_x
, "%inherit-magic!", 2, 0, 0,
576 (SCM
class, SCM dsupers
),
578 #define FUNC_NAME s_scm_sys_inherit_magic_x
582 SCM_VALIDATE_INSTANCE (1, class);
583 while (!SCM_NULLP (ls
))
585 SCM_ASSERT (SCM_CONSP (ls
)
586 && SCM_INSTANCEP (SCM_CAR (ls
)),
590 flags
|= SCM_CLASS_FLAGS (SCM_CAR (ls
));
593 flags
&= SCM_CLASSF_INHERIT
;
594 if (flags
& SCM_CLASSF_ENTITY
)
595 SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_entity
);
598 long n
= SCM_INUM (SCM_SLOT (class, scm_si_nfields
));
601 * We could avoid calling scm_gc_malloc in the allocation code
602 * (in which case the following two lines are needed). Instead
603 * we make 0-slot instances non-light, so that the light case
604 * can be handled without special cases.
607 SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_0
);
609 if (n
> 0 && !(flags
& SCM_CLASSF_METACLASS
))
611 /* NOTE: The following depends on scm_struct_i_size. */
612 flags
|= SCM_STRUCTF_LIGHT
+ n
* sizeof (SCM
); /* use light representation */
613 SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_light
);
616 SCM_SET_CLASS_FLAGS (class, flags
);
618 prep_hashsets (class);
620 return SCM_UNSPECIFIED
;
625 prep_hashsets (SCM
class)
629 for (i
= 0; i
< 7; ++i
)
630 SCM_SET_HASHSET (class, i
, scm_c_uniform32 (goops_rstate
));
633 /******************************************************************************/
636 scm_basic_basic_make_class (SCM
class, SCM name
, SCM dsupers
, SCM dslots
)
638 SCM z
, cpl
, slots
, nfields
, g_n_s
;
640 /* Allocate one instance */
641 z
= scm_make_struct (class, SCM_INUM0
, SCM_EOL
);
643 /* Initialize its slots */
644 SCM_SET_SLOT (z
, scm_si_direct_supers
, dsupers
);
645 cpl
= compute_cpl (z
);
646 slots
= build_slots_list (maplist (dslots
), cpl
);
647 nfields
= SCM_MAKINUM (scm_ilength (slots
));
648 g_n_s
= compute_getters_n_setters (slots
);
650 SCM_SET_SLOT (z
, scm_si_name
, name
);
651 SCM_SET_SLOT (z
, scm_si_direct_slots
, dslots
);
652 SCM_SET_SLOT (z
, scm_si_direct_subclasses
, SCM_EOL
);
653 SCM_SET_SLOT (z
, scm_si_direct_methods
, SCM_EOL
);
654 SCM_SET_SLOT (z
, scm_si_cpl
, cpl
);
655 SCM_SET_SLOT (z
, scm_si_slots
, slots
);
656 SCM_SET_SLOT (z
, scm_si_nfields
, nfields
);
657 SCM_SET_SLOT (z
, scm_si_getters_n_setters
, g_n_s
);
658 SCM_SET_SLOT (z
, scm_si_redefined
, SCM_BOOL_F
);
659 SCM_SET_SLOT (z
, scm_si_environment
,
660 scm_top_level_env (SCM_TOP_LEVEL_LOOKUP_CLOSURE
));
662 /* Add this class in the direct-subclasses slot of dsupers */
665 for (tmp
= dsupers
; !SCM_NULLP (tmp
); tmp
= SCM_CDR (tmp
))
666 SCM_SET_SLOT (SCM_CAR (tmp
), scm_si_direct_subclasses
,
667 scm_cons (z
, SCM_SLOT (SCM_CAR (tmp
),
668 scm_si_direct_subclasses
)));
671 /* Support for the underlying structs: */
672 SCM_SET_CLASS_FLAGS (z
, (class == scm_class_entity_class
673 ? (SCM_CLASSF_GOOPS_OR_VALID
674 | SCM_CLASSF_OPERATOR
676 : class == scm_class_operator_class
677 ? SCM_CLASSF_GOOPS_OR_VALID
| SCM_CLASSF_OPERATOR
678 : SCM_CLASSF_GOOPS_OR_VALID
));
683 scm_basic_make_class (SCM
class, SCM name
, SCM dsupers
, SCM dslots
)
685 SCM z
= scm_basic_basic_make_class (class, name
, dsupers
, dslots
);
686 scm_sys_inherit_magic_x (z
, dsupers
);
687 scm_sys_prep_layout_x (z
);
691 /******************************************************************************/
693 SCM_SYMBOL (sym_layout
, "layout");
694 SCM_SYMBOL (sym_vcell
, "vcell");
695 SCM_SYMBOL (sym_vtable
, "vtable");
696 SCM_SYMBOL (sym_print
, "print");
697 SCM_SYMBOL (sym_procedure
, "procedure");
698 SCM_SYMBOL (sym_setter
, "setter");
699 SCM_SYMBOL (sym_redefined
, "redefined");
700 SCM_SYMBOL (sym_h0
, "h0");
701 SCM_SYMBOL (sym_h1
, "h1");
702 SCM_SYMBOL (sym_h2
, "h2");
703 SCM_SYMBOL (sym_h3
, "h3");
704 SCM_SYMBOL (sym_h4
, "h4");
705 SCM_SYMBOL (sym_h5
, "h5");
706 SCM_SYMBOL (sym_h6
, "h6");
707 SCM_SYMBOL (sym_h7
, "h7");
708 SCM_SYMBOL (sym_name
, "name");
709 SCM_SYMBOL (sym_direct_supers
, "direct-supers");
710 SCM_SYMBOL (sym_direct_slots
, "direct-slots");
711 SCM_SYMBOL (sym_direct_subclasses
, "direct-subclasses");
712 SCM_SYMBOL (sym_direct_methods
, "direct-methods");
713 SCM_SYMBOL (sym_cpl
, "cpl");
714 SCM_SYMBOL (sym_default_slot_definition_class
, "default-slot-definition-class");
715 SCM_SYMBOL (sym_slots
, "slots");
716 SCM_SYMBOL (sym_getters_n_setters
, "getters-n-setters");
717 SCM_SYMBOL (sym_keyword_access
, "keyword-access");
718 SCM_SYMBOL (sym_nfields
, "nfields");
719 SCM_SYMBOL (sym_environment
, "environment");
723 build_class_class_slots ()
726 scm_list_3 (sym_layout
, k_class
, scm_class_protected_read_only
),
727 scm_list_3 (sym_vtable
, k_class
, scm_class_self
),
728 scm_list_1 (sym_print
),
729 scm_list_3 (sym_procedure
, k_class
, scm_class_protected_opaque
),
730 scm_list_3 (sym_setter
, k_class
, scm_class_protected_opaque
),
731 scm_list_1 (sym_redefined
),
732 scm_list_3 (sym_h0
, k_class
, scm_class_int
),
733 scm_list_3 (sym_h1
, k_class
, scm_class_int
),
734 scm_list_3 (sym_h2
, k_class
, scm_class_int
),
735 scm_list_3 (sym_h3
, k_class
, scm_class_int
),
736 scm_list_3 (sym_h4
, k_class
, scm_class_int
),
737 scm_list_3 (sym_h5
, k_class
, scm_class_int
),
738 scm_list_3 (sym_h6
, k_class
, scm_class_int
),
739 scm_list_3 (sym_h7
, k_class
, scm_class_int
),
740 scm_list_1 (sym_name
),
741 scm_list_1 (sym_direct_supers
),
742 scm_list_1 (sym_direct_slots
),
743 scm_list_1 (sym_direct_subclasses
),
744 scm_list_1 (sym_direct_methods
),
745 scm_list_1 (sym_cpl
),
746 scm_list_1 (sym_default_slot_definition_class
),
747 scm_list_1 (sym_slots
),
748 scm_list_1 (sym_getters_n_setters
),
749 scm_list_1 (sym_keyword_access
),
750 scm_list_1 (sym_nfields
),
751 scm_list_1 (sym_environment
),
756 create_basic_classes (void)
758 /* SCM slots_of_class = build_class_class_slots (); */
760 /**** <scm_class_class> ****/
761 SCM cs
= scm_makfrom0str (SCM_CLASS_CLASS_LAYOUT
762 + 2 * scm_vtable_offset_user
);
763 SCM name
= scm_str2symbol ("<class>");
764 scm_class_class
= scm_permanent_object (scm_make_vtable_vtable (cs
,
767 SCM_SET_CLASS_FLAGS (scm_class_class
, (SCM_CLASSF_GOOPS_OR_VALID
768 | SCM_CLASSF_METACLASS
));
770 SCM_SET_SLOT (scm_class_class
, scm_si_name
, name
);
771 SCM_SET_SLOT (scm_class_class
, scm_si_direct_supers
, SCM_EOL
); /* will be changed */
772 /* SCM_SET_SLOT (scm_class_class, scm_si_direct_slots, slots_of_class); */
773 SCM_SET_SLOT (scm_class_class
, scm_si_direct_subclasses
, SCM_EOL
);
774 SCM_SET_SLOT (scm_class_class
, scm_si_direct_methods
, SCM_EOL
);
775 SCM_SET_SLOT (scm_class_class
, scm_si_cpl
, SCM_EOL
); /* will be changed */
776 /* SCM_SET_SLOT (scm_class_class, scm_si_slots, slots_of_class); */
777 SCM_SET_SLOT (scm_class_class
, scm_si_nfields
, SCM_MAKINUM (SCM_N_CLASS_SLOTS
));
778 /* SCM_SET_SLOT (scm_class_class, scm_si_getters_n_setters,
779 compute_getters_n_setters (slots_of_class)); */
780 SCM_SET_SLOT (scm_class_class
, scm_si_redefined
, SCM_BOOL_F
);
781 SCM_SET_SLOT (scm_class_class
, scm_si_environment
,
782 scm_top_level_env (SCM_TOP_LEVEL_LOOKUP_CLOSURE
));
784 prep_hashsets (scm_class_class
);
786 DEFVAR(name
, scm_class_class
);
788 /**** <scm_class_top> ****/
789 name
= scm_str2symbol ("<top>");
790 scm_class_top
= scm_permanent_object (scm_basic_make_class (scm_class_class
,
795 DEFVAR(name
, scm_class_top
);
797 /**** <scm_class_object> ****/
798 name
= scm_str2symbol ("<object>");
799 scm_class_object
= scm_permanent_object (scm_basic_make_class (scm_class_class
,
801 scm_list_1 (scm_class_top
),
804 DEFVAR (name
, scm_class_object
);
806 /* <top> <object> and <class> were partially initialized. Correct them here */
807 SCM_SET_SLOT (scm_class_object
, scm_si_direct_subclasses
, scm_list_1 (scm_class_class
));
809 SCM_SET_SLOT (scm_class_class
, scm_si_direct_supers
, scm_list_1 (scm_class_object
));
810 SCM_SET_SLOT (scm_class_class
, scm_si_cpl
, scm_list_3 (scm_class_class
, scm_class_object
, scm_class_top
));
813 /******************************************************************************/
815 SCM_DEFINE (scm_instance_p
, "instance?", 1, 0, 0,
817 "Return @code{#t} if @var{obj} is an instance.")
818 #define FUNC_NAME s_scm_instance_p
820 return SCM_BOOL (SCM_INSTANCEP (obj
));
825 /******************************************************************************
827 * Meta object accessors
829 ******************************************************************************/
830 SCM_DEFINE (scm_class_name
, "class-name", 1, 0, 0,
832 "Return the class name of @var{obj}.")
833 #define FUNC_NAME s_scm_class_name
835 SCM_VALIDATE_CLASS (1, obj
);
836 return scm_slot_ref (obj
, sym_name
);
840 SCM_DEFINE (scm_class_direct_supers
, "class-direct-supers", 1, 0, 0,
842 "Return the direct superclasses of the class @var{obj}.")
843 #define FUNC_NAME s_scm_class_direct_supers
845 SCM_VALIDATE_CLASS (1, obj
);
846 return scm_slot_ref (obj
, sym_direct_supers
);
850 SCM_DEFINE (scm_class_direct_slots
, "class-direct-slots", 1, 0, 0,
852 "Return the direct slots of the class @var{obj}.")
853 #define FUNC_NAME s_scm_class_direct_slots
855 SCM_VALIDATE_CLASS (1, obj
);
856 return scm_slot_ref (obj
, sym_direct_slots
);
860 SCM_DEFINE (scm_class_direct_subclasses
, "class-direct-subclasses", 1, 0, 0,
862 "Return the direct subclasses of the class @var{obj}.")
863 #define FUNC_NAME s_scm_class_direct_subclasses
865 SCM_VALIDATE_CLASS (1, obj
);
866 return scm_slot_ref(obj
, sym_direct_subclasses
);
870 SCM_DEFINE (scm_class_direct_methods
, "class-direct-methods", 1, 0, 0,
872 "Return the direct methods of the class @var{obj}")
873 #define FUNC_NAME s_scm_class_direct_methods
875 SCM_VALIDATE_CLASS (1, obj
);
876 return scm_slot_ref (obj
, sym_direct_methods
);
880 SCM_DEFINE (scm_class_precedence_list
, "class-precedence-list", 1, 0, 0,
882 "Return the class precedence list of the class @var{obj}.")
883 #define FUNC_NAME s_scm_class_precedence_list
885 SCM_VALIDATE_CLASS (1, obj
);
886 return scm_slot_ref (obj
, sym_cpl
);
890 SCM_DEFINE (scm_class_slots
, "class-slots", 1, 0, 0,
892 "Return the slot list of the class @var{obj}.")
893 #define FUNC_NAME s_scm_class_slots
895 SCM_VALIDATE_CLASS (1, obj
);
896 return scm_slot_ref (obj
, sym_slots
);
900 SCM_DEFINE (scm_class_environment
, "class-environment", 1, 0, 0,
902 "Return the environment of the class @var{obj}.")
903 #define FUNC_NAME s_scm_class_environment
905 SCM_VALIDATE_CLASS (1, obj
);
906 return scm_slot_ref(obj
, sym_environment
);
911 SCM_DEFINE (scm_generic_function_name
, "generic-function-name", 1, 0, 0,
913 "Return the name of the generic function @var{obj}.")
914 #define FUNC_NAME s_scm_generic_function_name
916 SCM_VALIDATE_GENERIC (1, obj
);
917 return scm_procedure_property (obj
, scm_sym_name
);
921 SCM_SYMBOL (sym_methods
, "methods");
922 SCM_SYMBOL (sym_extended_by
, "extended-by");
923 SCM_SYMBOL (sym_extends
, "extends");
926 SCM
fold_downward_gf_methods (SCM method_lists
, SCM gf
)
928 SCM gfs
= scm_slot_ref (gf
, sym_extended_by
);
929 method_lists
= scm_cons (scm_slot_ref (gf
, sym_methods
), method_lists
);
930 while (!SCM_NULLP (gfs
))
932 method_lists
= fold_downward_gf_methods (method_lists
, SCM_CAR (gfs
));
939 SCM
fold_upward_gf_methods (SCM method_lists
, SCM gf
)
941 if (SCM_IS_A_P (gf
, scm_class_extended_generic
))
943 SCM gfs
= scm_slot_ref (gf
, sym_extends
);
944 while (!SCM_NULLP (gfs
))
946 SCM methods
= scm_slot_ref (SCM_CAR (gfs
), sym_methods
);
947 method_lists
= fold_upward_gf_methods (scm_cons (methods
,
956 SCM_DEFINE (scm_generic_function_methods
, "generic-function-methods", 1, 0, 0,
958 "Return the methods of the generic function @var{obj}.")
959 #define FUNC_NAME s_scm_generic_function_methods
962 SCM_VALIDATE_GENERIC (1, obj
);
963 methods
= fold_upward_gf_methods (SCM_EOL
, obj
);
964 methods
= fold_downward_gf_methods (methods
, obj
);
965 return scm_append (methods
);
969 SCM_DEFINE (scm_method_generic_function
, "method-generic-function", 1, 0, 0,
971 "Return the generic function for the method @var{obj}.")
972 #define FUNC_NAME s_scm_method_generic_function
974 SCM_VALIDATE_METHOD (1, obj
);
975 return scm_slot_ref (obj
, scm_str2symbol ("generic-function"));
979 SCM_DEFINE (scm_method_specializers
, "method-specializers", 1, 0, 0,
981 "Return specializers of the method @var{obj}.")
982 #define FUNC_NAME s_scm_method_specializers
984 SCM_VALIDATE_METHOD (1, obj
);
985 return scm_slot_ref (obj
, scm_str2symbol ("specializers"));
989 SCM_DEFINE (scm_method_procedure
, "method-procedure", 1, 0, 0,
991 "Return the procedure of the method @var{obj}.")
992 #define FUNC_NAME s_scm_method_procedure
994 SCM_VALIDATE_METHOD (1, obj
);
995 return scm_slot_ref (obj
, sym_procedure
);
999 SCM_DEFINE (scm_accessor_method_slot_definition
, "accessor-method-slot-definition", 1, 0, 0,
1001 "Return the slot definition of the accessor @var{obj}.")
1002 #define FUNC_NAME s_scm_accessor_method_slot_definition
1004 SCM_VALIDATE_ACCESSOR (1, obj
);
1005 return scm_slot_ref (obj
, scm_str2symbol ("slot-definition"));
1009 SCM_DEFINE (scm_sys_tag_body
, "%tag-body", 1, 0, 0,
1011 "Internal GOOPS magic---don't use this function!")
1012 #define FUNC_NAME s_scm_sys_tag_body
1014 return scm_cons (SCM_IM_LAMBDA
, body
);
1018 /******************************************************************************
1020 * S l o t a c c e s s
1022 ******************************************************************************/
1024 SCM_DEFINE (scm_make_unbound
, "make-unbound", 0, 0, 0,
1026 "Return the unbound value.")
1027 #define FUNC_NAME s_scm_make_unbound
1029 return SCM_GOOPS_UNBOUND
;
1033 SCM_DEFINE (scm_unbound_p
, "unbound?", 1, 0, 0,
1035 "Return @code{#t} if @var{obj} is unbound.")
1036 #define FUNC_NAME s_scm_unbound_p
1038 return SCM_GOOPS_UNBOUNDP (obj
) ? SCM_BOOL_T
: SCM_BOOL_F
;
1042 SCM_DEFINE (scm_assert_bound
, "assert-bound", 2, 0, 0,
1043 (SCM value
, SCM obj
),
1044 "Return @var{value} if it is bound, and invoke the\n"
1045 "@var{slot-unbound} method of @var{obj} if it is not.")
1046 #define FUNC_NAME s_scm_assert_bound
1048 if (SCM_GOOPS_UNBOUNDP (value
))
1049 return CALL_GF1 ("slot-unbound", obj
);
1054 SCM_DEFINE (scm_at_assert_bound_ref
, "@assert-bound-ref", 2, 0, 0,
1055 (SCM obj
, SCM index
),
1056 "Like @code{assert-bound}, but use @var{index} for accessing\n"
1057 "the value from @var{obj}.")
1058 #define FUNC_NAME s_scm_at_assert_bound_ref
1060 SCM value
= SCM_SLOT (obj
, SCM_INUM (index
));
1061 if (SCM_GOOPS_UNBOUNDP (value
))
1062 return CALL_GF1 ("slot-unbound", obj
);
1067 SCM_DEFINE (scm_sys_fast_slot_ref
, "%fast-slot-ref", 2, 0, 0,
1068 (SCM obj
, SCM index
),
1069 "Return the slot value with index @var{index} from @var{obj}.")
1070 #define FUNC_NAME s_scm_sys_fast_slot_ref
1072 unsigned long int i
;
1074 SCM_VALIDATE_INSTANCE (1, obj
);
1075 SCM_VALIDATE_INUM (2, index
);
1076 SCM_ASSERT_RANGE (2, index
, SCM_INUM (index
) >= 0);
1077 i
= SCM_INUM (index
);
1078 SCM_ASSERT_RANGE (2, index
, i
< SCM_NUMBER_OF_SLOTS (obj
));
1080 return SCM_SLOT (obj
, i
);
1084 SCM_DEFINE (scm_sys_fast_slot_set_x
, "%fast-slot-set!", 3, 0, 0,
1085 (SCM obj
, SCM index
, SCM value
),
1086 "Set the slot with index @var{index} in @var{obj} to\n"
1088 #define FUNC_NAME s_scm_sys_fast_slot_set_x
1090 unsigned long int i
;
1092 SCM_VALIDATE_INSTANCE (1, obj
);
1093 SCM_VALIDATE_INUM (2, index
);
1094 SCM_ASSERT_RANGE (2, index
, SCM_INUM (index
) >= 0);
1095 i
= SCM_INUM (index
);
1096 SCM_ASSERT_RANGE (2, index
, i
< SCM_NUMBER_OF_SLOTS (obj
));
1098 SCM_SET_SLOT (obj
, i
, value
);
1100 return SCM_UNSPECIFIED
;
1105 SCM_SYNTAX (s_atslot_ref
, "@slot-ref", scm_makmmacro
, scm_m_atslot_ref
);
1106 SCM_SYNTAX (s_atslot_set_x
, "@slot-set!", scm_makmmacro
, scm_m_atslot_set_x
);
1111 /* In the future, this function will return the effective slot
1112 * definition associated with SLOT_NAME. Now it just returns some of
1113 * the information which will be stored in the effective slot
1118 slot_definition_using_name (SCM
class, SCM slot_name
)
1120 register SCM slots
= SCM_SLOT (class, scm_si_getters_n_setters
);
1121 for (; !SCM_NULLP (slots
); slots
= SCM_CDR (slots
))
1122 if (SCM_CAAR (slots
) == slot_name
)
1123 return SCM_CAR (slots
);
1128 get_slot_value (SCM
class SCM_UNUSED
, SCM obj
, SCM slotdef
)
1130 SCM access
= SCM_CDDR (slotdef
);
1132 * - access is an integer (the offset of this slot in the slots vector)
1133 * - otherwise (car access) is the getter function to apply
1135 if (SCM_INUMP (access
))
1136 return SCM_SLOT (obj
, SCM_INUM (access
));
1139 /* We must evaluate (apply (car access) (list obj))
1140 * where (car access) is known to be a closure of arity 1 */
1141 register SCM code
, env
;
1143 code
= SCM_CAR (access
);
1144 if (!SCM_CLOSUREP (code
))
1145 return SCM_SUBRF (code
) (obj
);
1146 env
= SCM_EXTEND_ENV (SCM_CLOSURE_FORMALS (code
),
1149 /* Evaluate the closure body */
1150 return scm_eval_body (SCM_CLOSURE_BODY (code
), env
);
1155 get_slot_value_using_name (SCM
class, SCM obj
, SCM slot_name
)
1157 SCM slotdef
= slot_definition_using_name (class, slot_name
);
1158 if (!SCM_FALSEP (slotdef
))
1159 return get_slot_value (class, obj
, slotdef
);
1161 return CALL_GF3 ("slot-missing", class, obj
, slot_name
);
1165 set_slot_value (SCM
class SCM_UNUSED
, SCM obj
, SCM slotdef
, SCM value
)
1167 SCM access
= SCM_CDDR (slotdef
);
1169 * - access is an integer (the offset of this slot in the slots vector)
1170 * - otherwise (cadr access) is the setter function to apply
1172 if (SCM_INUMP (access
))
1173 SCM_SET_SLOT (obj
, SCM_INUM (access
), value
);
1176 /* We must evaluate (apply (cadr l) (list obj value))
1177 * where (cadr l) is known to be a closure of arity 2 */
1178 register SCM code
, env
;
1180 code
= SCM_CADR (access
);
1181 if (!SCM_CLOSUREP (code
))
1182 SCM_SUBRF (code
) (obj
, value
);
1185 env
= SCM_EXTEND_ENV (SCM_CLOSURE_FORMALS (code
),
1186 scm_list_2 (obj
, value
),
1188 /* Evaluate the closure body */
1189 scm_eval_body (SCM_CLOSURE_BODY (code
), env
);
1192 return SCM_UNSPECIFIED
;
1196 set_slot_value_using_name (SCM
class, SCM obj
, SCM slot_name
, SCM value
)
1198 SCM slotdef
= slot_definition_using_name (class, slot_name
);
1199 if (!SCM_FALSEP (slotdef
))
1200 return set_slot_value (class, obj
, slotdef
, value
);
1202 return CALL_GF4 ("slot-missing", class, obj
, slot_name
, value
);
1206 test_slot_existence (SCM
class SCM_UNUSED
, SCM obj
, SCM slot_name
)
1210 for (l
= SCM_ACCESSORS_OF (obj
); !SCM_NULLP (l
); l
= SCM_CDR (l
))
1211 if (SCM_EQ_P (SCM_CAAR (l
), slot_name
))
1217 /* ======================================== */
1219 SCM_DEFINE (scm_slot_ref_using_class
, "slot-ref-using-class", 3, 0, 0,
1220 (SCM
class, SCM obj
, SCM slot_name
),
1222 #define FUNC_NAME s_scm_slot_ref_using_class
1226 SCM_VALIDATE_CLASS (1, class);
1227 SCM_VALIDATE_INSTANCE (2, obj
);
1228 SCM_VALIDATE_SYMBOL (3, slot_name
);
1230 res
= get_slot_value_using_name (class, obj
, slot_name
);
1231 if (SCM_GOOPS_UNBOUNDP (res
))
1232 return CALL_GF3 ("slot-unbound", class, obj
, slot_name
);
1238 SCM_DEFINE (scm_slot_set_using_class_x
, "slot-set-using-class!", 4, 0, 0,
1239 (SCM
class, SCM obj
, SCM slot_name
, SCM value
),
1241 #define FUNC_NAME s_scm_slot_set_using_class_x
1243 SCM_VALIDATE_CLASS (1, class);
1244 SCM_VALIDATE_INSTANCE (2, obj
);
1245 SCM_VALIDATE_SYMBOL (3, slot_name
);
1247 return set_slot_value_using_name (class, obj
, slot_name
, value
);
1252 SCM_DEFINE (scm_slot_bound_using_class_p
, "slot-bound-using-class?", 3, 0, 0,
1253 (SCM
class, SCM obj
, SCM slot_name
),
1255 #define FUNC_NAME s_scm_slot_bound_using_class_p
1257 SCM_VALIDATE_CLASS (1, class);
1258 SCM_VALIDATE_INSTANCE (2, obj
);
1259 SCM_VALIDATE_SYMBOL (3, slot_name
);
1261 return (SCM_GOOPS_UNBOUNDP (get_slot_value_using_name (class, obj
, slot_name
))
1267 SCM_DEFINE (scm_slot_exists_using_class_p
, "slot-exists-using-class?", 3, 0, 0,
1268 (SCM
class, SCM obj
, SCM slot_name
),
1270 #define FUNC_NAME s_scm_slot_exists_using_class_p
1272 SCM_VALIDATE_CLASS (1, class);
1273 SCM_VALIDATE_INSTANCE (2, obj
);
1274 SCM_VALIDATE_SYMBOL (3, slot_name
);
1275 return test_slot_existence (class, obj
, slot_name
);
1280 /* ======================================== */
1282 SCM_DEFINE (scm_slot_ref
, "slot-ref", 2, 0, 0,
1283 (SCM obj
, SCM slot_name
),
1284 "Return the value from @var{obj}'s slot with the name\n"
1286 #define FUNC_NAME s_scm_slot_ref
1290 SCM_VALIDATE_INSTANCE (1, obj
);
1291 TEST_CHANGE_CLASS (obj
, class);
1293 res
= get_slot_value_using_name (class, obj
, slot_name
);
1294 if (SCM_GOOPS_UNBOUNDP (res
))
1295 return CALL_GF3 ("slot-unbound", class, obj
, slot_name
);
1300 SCM_DEFINE (scm_slot_set_x
, "slot-set!", 3, 0, 0,
1301 (SCM obj
, SCM slot_name
, SCM value
),
1302 "Set the slot named @var{slot_name} of @var{obj} to @var{value}.")
1303 #define FUNC_NAME s_scm_slot_set_x
1307 SCM_VALIDATE_INSTANCE (1, obj
);
1308 TEST_CHANGE_CLASS(obj
, class);
1310 return set_slot_value_using_name (class, obj
, slot_name
, value
);
1314 const char *scm_s_slot_set_x
= s_scm_slot_set_x
;
1316 SCM_DEFINE (scm_slot_bound_p
, "slot-bound?", 2, 0, 0,
1317 (SCM obj
, SCM slot_name
),
1318 "Return @code{#t} if the slot named @var{slot_name} of @var{obj}\n"
1320 #define FUNC_NAME s_scm_slot_bound_p
1324 SCM_VALIDATE_INSTANCE (1, obj
);
1325 TEST_CHANGE_CLASS(obj
, class);
1327 return (SCM_GOOPS_UNBOUNDP (get_slot_value_using_name (class,
1335 SCM_DEFINE (scm_slot_exists_p
, "slot-exists?", 2, 0, 0,
1336 (SCM obj
, SCM slot_name
),
1337 "Return @code{#t} if @var{obj} has a slot named @var{slot_name}.")
1338 #define FUNC_NAME s_scm_slot_exists_p
1342 SCM_VALIDATE_INSTANCE (1, obj
);
1343 SCM_VALIDATE_SYMBOL (2, slot_name
);
1344 TEST_CHANGE_CLASS (obj
, class);
1346 return test_slot_existence (class, obj
, slot_name
);
1351 /******************************************************************************
1353 * %allocate-instance (the low level instance allocation primitive)
1355 ******************************************************************************/
1357 static void clear_method_cache (SCM
);
1360 wrap_init (SCM
class, SCM
*m
, long n
)
1364 /* Set all slots to unbound */
1365 for (i
= 0; i
< n
; i
++)
1366 m
[i
] = SCM_GOOPS_UNBOUND
;
1368 return scm_double_cell ((((scm_t_bits
) SCM_STRUCT_DATA (class))
1370 (scm_t_bits
) m
, 0, 0);
1373 SCM_DEFINE (scm_sys_allocate_instance
, "%allocate-instance", 2, 0, 0,
1374 (SCM
class, SCM initargs
),
1375 "Create a new instance of class @var{class} and initialize it\n"
1376 "from the arguments @var{initargs}.")
1377 #define FUNC_NAME s_scm_sys_allocate_instance
1382 SCM_VALIDATE_CLASS (1, class);
1384 /* Most instances */
1385 if (SCM_CLASS_FLAGS (class) & SCM_STRUCTF_LIGHT
)
1387 n
= SCM_INUM (SCM_SLOT (class, scm_si_nfields
));
1388 m
= (SCM
*) scm_gc_malloc (n
* sizeof (SCM
), "struct");
1389 return wrap_init (class, m
, n
);
1392 /* Foreign objects */
1393 if (SCM_CLASS_FLAGS (class) & SCM_CLASSF_FOREIGN
)
1394 return scm_make_foreign_object (class, initargs
);
1396 n
= SCM_INUM (SCM_SLOT (class, scm_si_nfields
));
1399 if (SCM_CLASS_FLAGS (class) & SCM_CLASSF_ENTITY
)
1401 m
= (SCM
*) scm_alloc_struct (n
, scm_struct_entity_n_extra_words
,
1403 m
[scm_struct_i_setter
] = SCM_BOOL_F
;
1404 m
[scm_struct_i_procedure
] = SCM_BOOL_F
;
1405 /* Generic functions */
1406 if (SCM_CLASS_FLAGS (class) & SCM_CLASSF_PURE_GENERIC
)
1408 SCM gf
= wrap_init (class, m
, n
);
1409 clear_method_cache (gf
);
1413 return wrap_init (class, m
, n
);
1417 if (SCM_CLASS_FLAGS (class) & SCM_CLASSF_METACLASS
)
1421 /* allocate class object */
1422 SCM z
= scm_make_struct (class, SCM_INUM0
, SCM_EOL
);
1424 SCM_SET_SLOT (z
, scm_si_print
, SCM_GOOPS_UNBOUND
);
1425 for (i
= scm_si_goops_fields
; i
< n
; i
++)
1426 SCM_SET_SLOT (z
, i
, SCM_GOOPS_UNBOUND
);
1428 if (SCM_SUBCLASSP (class, scm_class_entity_class
))
1429 SCM_SET_CLASS_FLAGS (z
, SCM_CLASSF_OPERATOR
| SCM_CLASSF_ENTITY
);
1430 else if (SCM_SUBCLASSP (class, scm_class_operator_class
))
1431 SCM_SET_CLASS_FLAGS (z
, SCM_CLASSF_OPERATOR
);
1436 /* Non-light instances */
1438 m
= (SCM
*) scm_alloc_struct (n
, scm_struct_n_extra_words
, "heavy struct");
1439 return wrap_init (class, m
, n
);
1444 SCM_DEFINE (scm_sys_set_object_setter_x
, "%set-object-setter!", 2, 0, 0,
1445 (SCM obj
, SCM setter
),
1447 #define FUNC_NAME s_scm_sys_set_object_setter_x
1449 SCM_ASSERT (SCM_STRUCTP (obj
)
1450 && ((SCM_CLASS_FLAGS (obj
) & SCM_CLASSF_OPERATOR
)
1451 || SCM_I_ENTITYP (obj
)),
1455 if (SCM_I_ENTITYP (obj
))
1456 SCM_SET_ENTITY_SETTER (obj
, setter
);
1458 SCM_OPERATOR_CLASS (obj
)->setter
= setter
;
1459 return SCM_UNSPECIFIED
;
1463 /******************************************************************************
1465 * %modify-instance (used by change-class to modify in place)
1467 ******************************************************************************/
1469 SCM_DEFINE (scm_sys_modify_instance
, "%modify-instance", 2, 0, 0,
1472 #define FUNC_NAME s_scm_sys_modify_instance
1474 SCM_VALIDATE_INSTANCE (1, old
);
1475 SCM_VALIDATE_INSTANCE (2, new);
1477 /* Exchange the data contained in old and new. We exchange rather than
1478 * scratch the old value with new to be correct with GC.
1479 * See "Class redefinition protocol above".
1483 SCM car
= SCM_CAR (old
);
1484 SCM cdr
= SCM_CDR (old
);
1485 SCM_SETCAR (old
, SCM_CAR (new));
1486 SCM_SETCDR (old
, SCM_CDR (new));
1487 SCM_SETCAR (new, car
);
1488 SCM_SETCDR (new, cdr
);
1491 return SCM_UNSPECIFIED
;
1495 SCM_DEFINE (scm_sys_modify_class
, "%modify-class", 2, 0, 0,
1498 #define FUNC_NAME s_scm_sys_modify_class
1500 SCM_VALIDATE_CLASS (1, old
);
1501 SCM_VALIDATE_CLASS (2, new);
1505 SCM car
= SCM_CAR (old
);
1506 SCM cdr
= SCM_CDR (old
);
1507 SCM_SETCAR (old
, SCM_CAR (new));
1508 SCM_SETCDR (old
, SCM_CDR (new));
1509 SCM_STRUCT_DATA (old
)[scm_vtable_index_vtable
] = SCM_UNPACK (old
);
1510 SCM_SETCAR (new, car
);
1511 SCM_SETCDR (new, cdr
);
1512 SCM_STRUCT_DATA (new)[scm_vtable_index_vtable
] = SCM_UNPACK (new);
1515 return SCM_UNSPECIFIED
;
1519 SCM_DEFINE (scm_sys_invalidate_class
, "%invalidate-class", 1, 0, 0,
1522 #define FUNC_NAME s_scm_sys_invalidate_class
1524 SCM_VALIDATE_CLASS (1, class);
1525 SCM_CLEAR_CLASS_FLAGS (class, SCM_CLASSF_GOOPS_VALID
);
1526 return SCM_UNSPECIFIED
;
1530 /* When instances change class, they finally get a new body, but
1531 * before that, they go through purgatory in hell. Odd as it may
1532 * seem, this data structure saves us from eternal suffering in
1533 * infinite recursions.
1536 static scm_t_bits
**hell
;
1537 static long n_hell
= 1; /* one place for the evil one himself */
1538 static long hell_size
= 4;
1539 static SCM hell_mutex
;
1545 for (i
= 1; i
< n_hell
; ++i
)
1546 if (SCM_STRUCT_DATA (o
) == hell
[i
])
1552 go_to_hell (void *o
)
1554 SCM obj
= SCM_PACK ((scm_t_bits
) o
);
1555 scm_lock_mutex (hell_mutex
);
1556 if (n_hell
== hell_size
)
1558 long new_size
= 2 * hell_size
;
1559 hell
= scm_realloc (hell
, new_size
);
1560 hell_size
= new_size
;
1562 hell
[n_hell
++] = SCM_STRUCT_DATA (obj
);
1563 scm_unlock_mutex (hell_mutex
);
1567 go_to_heaven (void *o
)
1569 scm_lock_mutex (hell_mutex
);
1570 hell
[burnin (SCM_PACK ((scm_t_bits
) o
))] = hell
[--n_hell
];
1571 scm_unlock_mutex (hell_mutex
);
1575 SCM_SYMBOL (scm_sym_change_class
, "change-class");
1578 purgatory (void *args
)
1580 return scm_apply_0 (GETVAR (scm_sym_change_class
),
1581 SCM_PACK ((scm_t_bits
) args
));
1584 /* This function calls the generic function change-class for all
1585 * instances which aren't currently undergoing class change.
1589 scm_change_object_class (SCM obj
, SCM old_class SCM_UNUSED
, SCM new_class
)
1592 scm_internal_dynamic_wind (go_to_hell
, purgatory
, go_to_heaven
,
1593 (void *) SCM_UNPACK (scm_list_2 (obj
, new_class
)),
1594 (void *) SCM_UNPACK (obj
));
1597 /******************************************************************************
1603 * GGG E N E R I C F U N C T I O N S
1605 * This implementation provides
1606 * - generic functions (with class specializers)
1609 * - a hard-coded MOP for standard gf, which can be overloaded for non-std gf
1611 ******************************************************************************/
1613 SCM_KEYWORD (k_name
, "name");
1615 SCM_SYMBOL (sym_no_method
, "no-method");
1617 static SCM list_of_no_method
;
1619 SCM_GLOBAL_SYMBOL (scm_sym_args
, "args");
1622 SCM_SYNTAX (s_atdispatch
, "@dispatch", scm_makmmacro
, scm_m_atdispatch
);
1626 scm_make_method_cache (SCM gf
)
1628 return scm_list_5 (SCM_IM_DISPATCH
,
1631 scm_c_make_vector (SCM_INITIAL_MCACHE_SIZE
,
1637 clear_method_cache (SCM gf
)
1639 SCM cache
= scm_make_method_cache (gf
);
1640 SCM_SET_ENTITY_PROCEDURE (gf
, cache
);
1641 SCM_SET_SLOT (gf
, scm_si_used_by
, SCM_BOOL_F
);
1644 SCM_DEFINE (scm_sys_invalidate_method_cache_x
, "%invalidate-method-cache!", 1, 0, 0,
1647 #define FUNC_NAME s_scm_sys_invalidate_method_cache_x
1650 SCM_ASSERT (SCM_PUREGENERICP (gf
), gf
, SCM_ARG1
, FUNC_NAME
);
1651 used_by
= SCM_SLOT (gf
, scm_si_used_by
);
1652 if (!SCM_FALSEP (used_by
))
1654 SCM methods
= SCM_SLOT (gf
, scm_si_methods
);
1655 for (; SCM_CONSP (used_by
); used_by
= SCM_CDR (used_by
))
1656 scm_sys_invalidate_method_cache_x (SCM_CAR (used_by
));
1657 clear_method_cache (gf
);
1658 for (; SCM_CONSP (methods
); methods
= SCM_CDR (methods
))
1659 SCM_SET_SLOT (SCM_CAR (methods
), scm_si_code_table
, SCM_EOL
);
1662 SCM n
= SCM_SLOT (gf
, scm_si_n_specialized
);
1663 /* The sign of n is a flag indicating rest args. */
1664 SCM_SET_MCACHE_N_SPECIALIZED (SCM_ENTITY_PROCEDURE (gf
), n
);
1666 return SCM_UNSPECIFIED
;
1670 SCM_DEFINE (scm_generic_capability_p
, "generic-capability?", 1, 0, 0,
1673 #define FUNC_NAME s_scm_generic_capability_p
1675 SCM_ASSERT (!SCM_FALSEP (scm_procedure_p (proc
)),
1676 proc
, SCM_ARG1
, FUNC_NAME
);
1677 return (scm_subr_p (proc
) && SCM_SUBR_GENERIC (proc
)
1683 SCM_DEFINE (scm_enable_primitive_generic_x
, "enable-primitive-generic!", 0, 0, 1,
1686 #define FUNC_NAME s_scm_enable_primitive_generic_x
1688 SCM_VALIDATE_REST_ARGUMENT (subrs
);
1689 while (!SCM_NULLP (subrs
))
1691 SCM subr
= SCM_CAR (subrs
);
1692 SCM_ASSERT (scm_subr_p (subr
) && SCM_SUBR_GENERIC (subr
),
1693 subr
, SCM_ARGn
, FUNC_NAME
);
1694 *SCM_SUBR_GENERIC (subr
)
1695 = scm_make (scm_list_3 (scm_class_generic
,
1698 subrs
= SCM_CDR (subrs
);
1700 return SCM_UNSPECIFIED
;
1704 SCM_DEFINE (scm_primitive_generic_generic
, "primitive-generic-generic", 1, 0, 0,
1707 #define FUNC_NAME s_scm_primitive_generic_generic
1709 if (scm_subr_p (subr
) && SCM_SUBR_GENERIC (subr
))
1711 if (!*SCM_SUBR_GENERIC (subr
))
1712 scm_enable_primitive_generic_x (scm_list_1 (subr
));
1713 return *SCM_SUBR_GENERIC (subr
);
1715 SCM_WRONG_TYPE_ARG (SCM_ARG1
, subr
);
1719 typedef struct t_extension
{
1720 struct t_extension
*next
;
1725 static t_extension
*extensions
= 0;
1727 SCM_VARIABLE (scm_var_make_extended_generic
, "make-extended-generic");
1730 scm_c_extend_primitive_generic (SCM extended
, SCM extension
)
1735 if (!*SCM_SUBR_GENERIC (extended
))
1736 scm_enable_primitive_generic_x (scm_list_1 (extended
));
1737 gf
= *SCM_SUBR_GENERIC (extended
);
1738 gext
= scm_call_2 (SCM_VARIABLE_REF (scm_var_make_extended_generic
),
1740 SCM_SNAME (extension
));
1741 *SCM_SUBR_GENERIC (extension
) = gext
;
1745 t_extension
*e
= scm_malloc (sizeof (t_extension
));
1746 t_extension
**loc
= &extensions
;
1747 /* Make sure that extensions are placed before their own
1748 * extensions in the extensions list. O(N^2) algorithm, but
1749 * extensions of primitive generics are rare.
1751 while (*loc
&& extension
!= (*loc
)->extended
)
1752 loc
= &(*loc
)->next
;
1754 e
->extended
= extended
;
1755 e
->extension
= extension
;
1761 setup_extended_primitive_generics ()
1765 t_extension
*e
= extensions
;
1766 scm_c_extend_primitive_generic (e
->extended
, e
->extension
);
1767 extensions
= e
->next
;
1772 /******************************************************************************
1774 * Protocol for calling a generic fumction
1775 * This protocol is roughly equivalent to (parameter are a little bit different
1776 * for efficiency reasons):
1778 * + apply-generic (gf args)
1779 * + compute-applicable-methods (gf args ...)
1780 * + sort-applicable-methods (methods args)
1781 * + apply-methods (gf methods args)
1783 * apply-methods calls make-next-method to build the "continuation" of a a
1784 * method. Applying a next-method will call apply-next-method which in
1785 * turn will call apply again to call effectively the following method.
1787 ******************************************************************************/
1790 applicablep (SCM actual
, SCM formal
)
1792 /* We already know that the cpl is well formed. */
1793 return !SCM_FALSEP (scm_c_memq (formal
, SCM_SLOT (actual
, scm_si_cpl
)));
1797 more_specificp (SCM m1
, SCM m2
, SCM
const *targs
)
1799 register SCM s1
, s2
;
1803 * m1 and m2 can have != length (i.e. one can be one element longer than the
1804 * other when we have a dotted parameter list). For instance, with the call
1807 * (define-method M (a . l) ....)
1808 * (define-method M (a) ....)
1810 * we consider that the second method is more specific.
1812 * BTW, targs is an array of types. We don't need it's size since
1813 * we already know that m1 and m2 are applicable (no risk to go past
1814 * the end of this array).
1817 for (i
=0, s1
=SPEC_OF(m1
), s2
=SPEC_OF(m2
); ; i
++, s1
=SCM_CDR(s1
), s2
=SCM_CDR(s2
)) {
1818 if (SCM_NULLP(s1
)) return 1;
1819 if (SCM_NULLP(s2
)) return 0;
1820 if (SCM_CAR(s1
) != SCM_CAR(s2
)) {
1821 register SCM l
, cs1
= SCM_CAR(s1
), cs2
= SCM_CAR(s2
);
1823 for (l
= SCM_SLOT (targs
[i
], scm_si_cpl
); ; l
= SCM_CDR(l
)) {
1824 if (cs1
== SCM_CAR(l
))
1826 if (cs2
== SCM_CAR(l
))
1829 return 0;/* should not occur! */
1832 return 0; /* should not occur! */
1835 #define BUFFSIZE 32 /* big enough for most uses */
1838 scm_i_vector2list (SCM l
, long len
)
1841 SCM z
= scm_c_make_vector (len
, SCM_UNDEFINED
);
1843 for (j
= 0; j
< len
; j
++, l
= SCM_CDR (l
)) {
1844 SCM_VECTOR_SET (z
, j
, SCM_CAR (l
));
1850 sort_applicable_methods (SCM method_list
, long size
, SCM
const *targs
)
1853 SCM
*v
, vector
= SCM_EOL
;
1854 SCM buffer
[BUFFSIZE
];
1855 SCM save
= method_list
;
1857 /* For reasonably sized method_lists we can try to avoid all the
1858 * consing and reorder the list in place...
1859 * This idea is due to David McClain <Dave_McClain@msn.com>
1861 if (size
<= BUFFSIZE
)
1863 for (i
= 0; i
< size
; i
++)
1865 buffer
[i
] = SCM_CAR (method_list
);
1866 method_list
= SCM_CDR (method_list
);
1872 /* Too many elements in method_list to keep everything locally */
1873 vector
= scm_i_vector2list (save
, size
);
1876 This is a new vector. Don't worry about the write barrier.
1877 We're not allocating elements in this routine, so this should
1880 v
= SCM_WRITABLE_VELTS (vector
);
1883 /* Use a simple shell sort since it is generally faster than qsort on
1884 * small vectors (which is probably mostly the case when we have to
1885 * sort a list of applicable methods).
1887 for (incr
= size
/ 2; incr
; incr
/= 2)
1889 for (i
= incr
; i
< size
; i
++)
1891 for (j
= i
- incr
; j
>= 0; j
-= incr
)
1893 if (more_specificp (v
[j
], v
[j
+incr
], targs
))
1897 SCM tmp
= v
[j
+ incr
];
1905 if (size
<= BUFFSIZE
)
1907 /* We did it in locally, so restore the original list (reordered) in-place */
1908 for (i
= 0, method_list
= save
; i
< size
; i
++, v
++)
1910 SCM_SETCAR (method_list
, *v
);
1911 method_list
= SCM_CDR (method_list
);
1915 /* If we are here, that's that we did it the hard way... */
1916 return scm_vector_to_list (vector
);
1920 scm_compute_applicable_methods (SCM gf
, SCM args
, long len
, int find_method_p
)
1924 SCM l
, fl
, applicable
= SCM_EOL
;
1926 SCM buffer
[BUFFSIZE
];
1931 /* Build the list of arguments types */
1932 if (len
>= BUFFSIZE
) {
1933 tmp
= scm_c_make_vector (len
, SCM_UNDEFINED
);
1934 /* NOTE: Using pointers to malloced memory won't work if we
1935 1. have preemtive threading, and,
1936 2. have a GC which moves objects. */
1937 types
= p
= SCM_WRITABLE_VELTS(tmp
);
1940 note that we don't have to work to reset the generation
1941 count. TMP is a new vector anyway, and it is found
1948 for ( ; !SCM_NULLP (args
); args
= SCM_CDR (args
))
1949 *p
++ = scm_class_of (SCM_CAR (args
));
1951 /* Build a list of all applicable methods */
1952 for (l
= scm_generic_function_methods (gf
); !SCM_NULLP (l
); l
= SCM_CDR (l
))
1954 fl
= SPEC_OF (SCM_CAR (l
));
1955 /* Only accept accessors which match exactly in first arg. */
1956 if (SCM_ACCESSORP (SCM_CAR (l
))
1957 && (SCM_NULLP (fl
) || types
[0] != SCM_CAR (fl
)))
1959 for (i
= 0; ; i
++, fl
= SCM_CDR (fl
))
1961 if (SCM_INSTANCEP (fl
)
1962 /* We have a dotted argument list */
1963 || (i
>= len
&& SCM_NULLP (fl
)))
1964 { /* both list exhausted */
1965 applicable
= scm_cons (SCM_CAR (l
), applicable
);
1971 || !applicablep (types
[i
], SCM_CAR (fl
)))
1980 CALL_GF2 ("no-applicable-method", gf
, save
);
1981 /* if we are here, it's because no-applicable-method hasn't signaled an error */
1985 scm_remember_upto_here_1 (tmp
);
1988 : sort_applicable_methods (applicable
, count
, types
));
1992 SCM_PROC (s_sys_compute_applicable_methods
, "%compute-applicable-methods", 2, 0, 0, scm_sys_compute_applicable_methods
);
1995 static const char s_sys_compute_applicable_methods
[] = "%compute-applicable-methods";
1998 scm_sys_compute_applicable_methods (SCM gf
, SCM args
)
1999 #define FUNC_NAME s_sys_compute_applicable_methods
2002 SCM_VALIDATE_GENERIC (1, gf
);
2003 n
= scm_ilength (args
);
2004 SCM_ASSERT (n
>= 0, args
, SCM_ARG2
, FUNC_NAME
);
2005 return scm_compute_applicable_methods (gf
, args
, n
, 1);
2009 SCM_SYMBOL (sym_compute_applicable_methods
, "compute-applicable-methods");
2010 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
));
2013 lock_cache_mutex (void *m
)
2015 SCM mutex
= SCM_PACK ((scm_t_bits
) m
);
2016 scm_lock_mutex (mutex
);
2020 unlock_cache_mutex (void *m
)
2022 SCM mutex
= SCM_PACK ((scm_t_bits
) m
);
2023 scm_unlock_mutex (mutex
);
2027 call_memoize_method (void *a
)
2029 SCM args
= SCM_PACK ((scm_t_bits
) a
);
2030 SCM gf
= SCM_CAR (args
);
2031 SCM x
= SCM_CADR (args
);
2032 /* First check if another thread has inserted a method between
2033 * the cache miss and locking the mutex.
2035 SCM cmethod
= scm_mcache_lookup_cmethod (x
, SCM_CDDR (args
));
2036 if (!SCM_FALSEP (cmethod
))
2038 /*fixme* Use scm_apply */
2039 return CALL_GF3 ("memoize-method!", gf
, SCM_CDDR (args
), x
);
2043 scm_memoize_method (SCM x
, SCM args
)
2045 SCM gf
= SCM_CAR (scm_last_pair (x
));
2046 return scm_internal_dynamic_wind (
2048 call_memoize_method
,
2050 (void *) SCM_UNPACK (scm_cons2 (gf
, x
, args
)),
2051 (void *) SCM_UNPACK (SCM_SLOT (gf
, scm_si_cache_mutex
)));
2054 /******************************************************************************
2056 * A simple make (which will be redefined later in Scheme)
2057 * This version handles only creation of gf, methods and classes (no instances)
2059 * Since this code will disappear when Goops will be fully booted,
2060 * no precaution is taken to be efficient.
2062 ******************************************************************************/
2064 SCM_KEYWORD (k_setter
, "setter");
2065 SCM_KEYWORD (k_specializers
, "specializers");
2066 SCM_KEYWORD (k_procedure
, "procedure");
2067 SCM_KEYWORD (k_dsupers
, "dsupers");
2068 SCM_KEYWORD (k_slots
, "slots");
2069 SCM_KEYWORD (k_gf
, "generic-function");
2071 SCM_DEFINE (scm_make
, "make", 0, 0, 1,
2073 "Make a new object. @var{args} must contain the class and\n"
2074 "all necessary initialization information.")
2075 #define FUNC_NAME s_scm_make
2078 long len
= scm_ilength (args
);
2080 if (len
<= 0 || (len
& 1) == 0)
2081 SCM_WRONG_NUM_ARGS ();
2083 class = SCM_CAR(args
);
2084 args
= SCM_CDR(args
);
2086 if (class == scm_class_generic
|| class == scm_class_accessor
)
2088 z
= scm_make_struct (class, SCM_INUM0
,
2089 scm_list_5 (SCM_EOL
,
2094 scm_set_procedure_property_x (z
, scm_sym_name
,
2095 scm_get_keyword (k_name
,
2098 clear_method_cache (z
);
2099 if (class == scm_class_accessor
)
2101 SCM setter
= scm_get_keyword (k_setter
, args
, SCM_BOOL_F
);
2102 if (!SCM_FALSEP (setter
))
2103 scm_sys_set_object_setter_x (z
, setter
);
2108 z
= scm_sys_allocate_instance (class, args
);
2110 if (class == scm_class_method
2111 || class == scm_class_simple_method
2112 || class == scm_class_accessor_method
)
2114 SCM_SET_SLOT (z
, scm_si_generic_function
,
2115 scm_i_get_keyword (k_gf
,
2120 SCM_SET_SLOT (z
, scm_si_specializers
,
2121 scm_i_get_keyword (k_specializers
,
2126 SCM_SET_SLOT (z
, scm_si_procedure
,
2127 scm_i_get_keyword (k_procedure
,
2132 SCM_SET_SLOT (z
, scm_si_code_table
, SCM_EOL
);
2136 /* In all the others case, make a new class .... No instance here */
2137 SCM_SET_SLOT (z
, scm_si_name
,
2138 scm_i_get_keyword (k_name
,
2141 scm_str2symbol ("???"),
2143 SCM_SET_SLOT (z
, scm_si_direct_supers
,
2144 scm_i_get_keyword (k_dsupers
,
2149 SCM_SET_SLOT (z
, scm_si_direct_slots
,
2150 scm_i_get_keyword (k_slots
,
2161 SCM_DEFINE (scm_find_method
, "find-method", 0, 0, 1,
2164 #define FUNC_NAME s_scm_find_method
2167 long len
= scm_ilength (l
);
2170 SCM_WRONG_NUM_ARGS ();
2172 gf
= SCM_CAR(l
); l
= SCM_CDR(l
);
2173 SCM_VALIDATE_GENERIC (1, gf
);
2174 if (SCM_NULLP (SCM_SLOT (gf
, scm_si_methods
)))
2175 SCM_MISC_ERROR ("no methods for generic ~S", scm_list_1 (gf
));
2177 return scm_compute_applicable_methods (gf
, l
, len
- 1, 1);
2181 SCM_DEFINE (scm_sys_method_more_specific_p
, "%method-more-specific?", 3, 0, 0,
2182 (SCM m1
, SCM m2
, SCM targs
),
2184 #define FUNC_NAME s_scm_sys_method_more_specific_p
2189 SCM_VALIDATE_METHOD (1, m1
);
2190 SCM_VALIDATE_METHOD (2, m2
);
2191 SCM_ASSERT ((len
= scm_ilength (targs
)) != -1, targs
, SCM_ARG3
, FUNC_NAME
);
2193 /* Verify that all the arguments of targs are classes and place them in a vector*/
2194 v
= scm_c_make_vector (len
, SCM_EOL
);
2196 for (i
= 0, l
= targs
; !SCM_NULLP (l
); i
++, l
= SCM_CDR (l
)) {
2197 SCM_ASSERT (SCM_CLASSP (SCM_CAR (l
)), targs
, SCM_ARG3
, FUNC_NAME
);
2198 SCM_VECTOR_SET (v
, i
, SCM_CAR(l
));
2200 return more_specificp (m1
, m2
, SCM_VELTS(v
)) ? SCM_BOOL_T
: SCM_BOOL_F
;
2206 /******************************************************************************
2210 ******************************************************************************/
2213 fix_cpl (SCM c
, SCM before
, SCM after
)
2215 SCM cpl
= SCM_SLOT (c
, scm_si_cpl
);
2216 SCM ls
= scm_c_memq (after
, cpl
);
2217 SCM tail
= scm_delq1_x (before
, SCM_CDR (ls
));
2218 if (SCM_FALSEP (ls
))
2219 /* if this condition occurs, fix_cpl should not be applied this way */
2221 SCM_SETCAR (ls
, before
);
2222 SCM_SETCDR (ls
, scm_cons (after
, tail
));
2224 SCM dslots
= SCM_SLOT (c
, scm_si_direct_slots
);
2225 SCM slots
= build_slots_list (maplist (dslots
), cpl
);
2226 SCM g_n_s
= compute_getters_n_setters (slots
);
2227 SCM_SET_SLOT (c
, scm_si_slots
, slots
);
2228 SCM_SET_SLOT (c
, scm_si_getters_n_setters
, g_n_s
);
2234 make_stdcls (SCM
*var
, char *name
, SCM meta
, SCM super
, SCM slots
)
2236 SCM tmp
= scm_str2symbol (name
);
2238 *var
= scm_permanent_object (scm_basic_make_class (meta
,
2242 : scm_list_1 (super
),
2248 SCM_KEYWORD (k_slot_definition
, "slot-definition");
2251 create_standard_classes (void)
2254 SCM method_slots
= scm_list_4 (scm_str2symbol ("generic-function"),
2255 scm_str2symbol ("specializers"),
2257 scm_str2symbol ("code-table"));
2258 SCM amethod_slots
= scm_list_1 (scm_list_3 (scm_str2symbol ("slot-definition"),
2260 k_slot_definition
));
2261 SCM mutex_slot
= scm_list_1 (scm_str2symbol ("make-mutex"));
2262 SCM gf_slots
= scm_list_5 (scm_str2symbol ("methods"),
2263 scm_list_3 (scm_str2symbol ("n-specialized"),
2266 scm_list_3 (scm_str2symbol ("used-by"),
2269 scm_list_3 (scm_str2symbol ("cache-mutex"),
2271 scm_closure (scm_list_2 (SCM_EOL
,
2274 scm_list_3 (scm_str2symbol ("extended-by"),
2277 SCM egf_slots
= scm_list_1 (scm_list_3 (scm_str2symbol ("extends"),
2280 /* Foreign class slot classes */
2281 make_stdcls (&scm_class_foreign_slot
, "<foreign-slot>",
2282 scm_class_class
, scm_class_top
, SCM_EOL
);
2283 make_stdcls (&scm_class_protected
, "<protected-slot>",
2284 scm_class_class
, scm_class_foreign_slot
, SCM_EOL
);
2285 make_stdcls (&scm_class_opaque
, "<opaque-slot>",
2286 scm_class_class
, scm_class_foreign_slot
, SCM_EOL
);
2287 make_stdcls (&scm_class_read_only
, "<read-only-slot>",
2288 scm_class_class
, scm_class_foreign_slot
, SCM_EOL
);
2289 make_stdcls (&scm_class_self
, "<self-slot>",
2291 scm_class_read_only
,
2293 make_stdcls (&scm_class_protected_opaque
, "<protected-opaque-slot>",
2295 scm_list_2 (scm_class_protected
, scm_class_opaque
),
2297 make_stdcls (&scm_class_protected_read_only
, "<protected-read-only-slot>",
2299 scm_list_2 (scm_class_protected
, scm_class_read_only
),
2301 make_stdcls (&scm_class_scm
, "<scm-slot>",
2302 scm_class_class
, scm_class_protected
, SCM_EOL
);
2303 make_stdcls (&scm_class_int
, "<int-slot>",
2304 scm_class_class
, scm_class_foreign_slot
, SCM_EOL
);
2305 make_stdcls (&scm_class_float
, "<float-slot>",
2306 scm_class_class
, scm_class_foreign_slot
, SCM_EOL
);
2307 make_stdcls (&scm_class_double
, "<double-slot>",
2308 scm_class_class
, scm_class_foreign_slot
, SCM_EOL
);
2310 /* Continue initialization of class <class> */
2312 slots
= build_class_class_slots ();
2313 SCM_SET_SLOT (scm_class_class
, scm_si_direct_slots
, slots
);
2314 SCM_SET_SLOT (scm_class_class
, scm_si_slots
, slots
);
2315 SCM_SET_SLOT (scm_class_class
, scm_si_getters_n_setters
,
2316 compute_getters_n_setters (slots
));
2318 make_stdcls (&scm_class_foreign_class
, "<foreign-class>",
2319 scm_class_class
, scm_class_class
,
2320 scm_list_2 (scm_list_3 (scm_str2symbol ("constructor"),
2323 scm_list_3 (scm_str2symbol ("destructor"),
2325 scm_class_opaque
)));
2326 make_stdcls (&scm_class_foreign_object
, "<foreign-object>",
2327 scm_class_foreign_class
, scm_class_object
, SCM_EOL
);
2328 SCM_SET_CLASS_FLAGS (scm_class_foreign_object
, SCM_CLASSF_FOREIGN
);
2330 /* scm_class_generic functions classes */
2331 make_stdcls (&scm_class_procedure_class
, "<procedure-class>",
2332 scm_class_class
, scm_class_class
, SCM_EOL
);
2333 make_stdcls (&scm_class_entity_class
, "<entity-class>",
2334 scm_class_class
, scm_class_procedure_class
, SCM_EOL
);
2335 make_stdcls (&scm_class_operator_class
, "<operator-class>",
2336 scm_class_class
, scm_class_procedure_class
, SCM_EOL
);
2337 make_stdcls (&scm_class_operator_with_setter_class
,
2338 "<operator-with-setter-class>",
2339 scm_class_class
, scm_class_operator_class
, SCM_EOL
);
2340 make_stdcls (&scm_class_method
, "<method>",
2341 scm_class_class
, scm_class_object
, method_slots
);
2342 make_stdcls (&scm_class_simple_method
, "<simple-method>",
2343 scm_class_class
, scm_class_method
, SCM_EOL
);
2344 SCM_SET_CLASS_FLAGS (scm_class_simple_method
, SCM_CLASSF_SIMPLE_METHOD
);
2345 make_stdcls (&scm_class_accessor_method
, "<accessor-method>",
2346 scm_class_class
, scm_class_simple_method
, amethod_slots
);
2347 SCM_SET_CLASS_FLAGS (scm_class_accessor_method
, SCM_CLASSF_ACCESSOR_METHOD
);
2348 make_stdcls (&scm_class_applicable
, "<applicable>",
2349 scm_class_class
, scm_class_top
, SCM_EOL
);
2350 make_stdcls (&scm_class_entity
, "<entity>",
2351 scm_class_entity_class
,
2352 scm_list_2 (scm_class_object
, scm_class_applicable
),
2354 make_stdcls (&scm_class_entity_with_setter
, "<entity-with-setter>",
2355 scm_class_entity_class
, scm_class_entity
, SCM_EOL
);
2356 make_stdcls (&scm_class_generic
, "<generic>",
2357 scm_class_entity_class
, scm_class_entity
, gf_slots
);
2358 SCM_SET_CLASS_FLAGS (scm_class_generic
, SCM_CLASSF_PURE_GENERIC
);
2359 make_stdcls (&scm_class_extended_generic
, "<extended-generic>",
2360 scm_class_entity_class
, scm_class_generic
, egf_slots
);
2361 SCM_SET_CLASS_FLAGS (scm_class_extended_generic
, SCM_CLASSF_PURE_GENERIC
);
2362 make_stdcls (&scm_class_generic_with_setter
, "<generic-with-setter>",
2363 scm_class_entity_class
,
2364 scm_list_2 (scm_class_generic
, scm_class_entity_with_setter
),
2366 SCM_SET_CLASS_FLAGS (scm_class_generic_with_setter
, SCM_CLASSF_PURE_GENERIC
);
2367 make_stdcls (&scm_class_accessor
, "<accessor>",
2368 scm_class_entity_class
, scm_class_generic_with_setter
, SCM_EOL
);
2369 SCM_SET_CLASS_FLAGS (scm_class_accessor
, SCM_CLASSF_PURE_GENERIC
);
2370 make_stdcls (&scm_class_extended_generic_with_setter
,
2371 "<extended-generic-with-setter>",
2372 scm_class_entity_class
,
2373 scm_list_2 (scm_class_generic_with_setter
,
2374 scm_class_extended_generic
),
2376 SCM_SET_CLASS_FLAGS (scm_class_extended_generic_with_setter
,
2377 SCM_CLASSF_PURE_GENERIC
);
2378 make_stdcls (&scm_class_extended_accessor
, "<extended-accessor>",
2379 scm_class_entity_class
,
2380 scm_list_2 (scm_class_accessor
,
2381 scm_class_extended_generic_with_setter
),
2383 fix_cpl (scm_class_extended_accessor
,
2384 scm_class_extended_generic
, scm_class_generic
);
2385 SCM_SET_CLASS_FLAGS (scm_class_extended_accessor
, SCM_CLASSF_PURE_GENERIC
);
2387 /* Primitive types classes */
2388 make_stdcls (&scm_class_boolean
, "<boolean>",
2389 scm_class_class
, scm_class_top
, SCM_EOL
);
2390 make_stdcls (&scm_class_char
, "<char>",
2391 scm_class_class
, scm_class_top
, SCM_EOL
);
2392 make_stdcls (&scm_class_list
, "<list>",
2393 scm_class_class
, scm_class_top
, SCM_EOL
);
2394 make_stdcls (&scm_class_pair
, "<pair>",
2395 scm_class_class
, scm_class_list
, SCM_EOL
);
2396 make_stdcls (&scm_class_null
, "<null>",
2397 scm_class_class
, scm_class_list
, SCM_EOL
);
2398 make_stdcls (&scm_class_string
, "<string>",
2399 scm_class_class
, scm_class_top
, SCM_EOL
);
2400 make_stdcls (&scm_class_symbol
, "<symbol>",
2401 scm_class_class
, scm_class_top
, SCM_EOL
);
2402 make_stdcls (&scm_class_vector
, "<vector>",
2403 scm_class_class
, scm_class_top
, SCM_EOL
);
2404 make_stdcls (&scm_class_number
, "<number>",
2405 scm_class_class
, scm_class_top
, SCM_EOL
);
2406 make_stdcls (&scm_class_complex
, "<complex>",
2407 scm_class_class
, scm_class_number
, SCM_EOL
);
2408 make_stdcls (&scm_class_real
, "<real>",
2409 scm_class_class
, scm_class_complex
, SCM_EOL
);
2410 make_stdcls (&scm_class_integer
, "<integer>",
2411 scm_class_class
, scm_class_real
, SCM_EOL
);
2412 make_stdcls (&scm_class_keyword
, "<keyword>",
2413 scm_class_class
, scm_class_top
, SCM_EOL
);
2414 make_stdcls (&scm_class_unknown
, "<unknown>",
2415 scm_class_class
, scm_class_top
, SCM_EOL
);
2416 make_stdcls (&scm_class_procedure
, "<procedure>",
2417 scm_class_procedure_class
, scm_class_applicable
, SCM_EOL
);
2418 make_stdcls (&scm_class_procedure_with_setter
, "<procedure-with-setter>",
2419 scm_class_procedure_class
, scm_class_procedure
, SCM_EOL
);
2420 make_stdcls (&scm_class_primitive_generic
, "<primitive-generic>",
2421 scm_class_procedure_class
, scm_class_procedure
, SCM_EOL
);
2422 make_stdcls (&scm_class_port
, "<port>",
2423 scm_class_class
, scm_class_top
, SCM_EOL
);
2424 make_stdcls (&scm_class_input_port
, "<input-port>",
2425 scm_class_class
, scm_class_port
, SCM_EOL
);
2426 make_stdcls (&scm_class_output_port
, "<output-port>",
2427 scm_class_class
, scm_class_port
, SCM_EOL
);
2428 make_stdcls (&scm_class_input_output_port
, "<input-output-port>",
2430 scm_list_2 (scm_class_input_port
, scm_class_output_port
),
2434 /**********************************************************************
2438 **********************************************************************/
2441 make_class_from_template (char *template, char *type_name
, SCM supers
, int applicablep
)
2447 sprintf (buffer
, template, type_name
);
2448 name
= scm_str2symbol (buffer
);
2451 name
= SCM_GOOPS_UNBOUND
;
2453 class = scm_permanent_object (scm_basic_make_class (applicablep
2454 ? scm_class_procedure_class
2460 /* Only define name if doesn't already exist. */
2461 if (!SCM_GOOPS_UNBOUNDP (name
)
2462 && SCM_FALSEP (scm_call_2 (scm_goops_lookup_closure
, name
, SCM_BOOL_F
)))
2463 DEFVAR (name
, class);
2468 scm_make_extended_class (char *type_name
, int applicablep
)
2470 return make_class_from_template ("<%s>",
2472 scm_list_1 (applicablep
2473 ? scm_class_applicable
2479 scm_i_inherit_applicable (SCM c
)
2481 if (!SCM_SUBCLASSP (c
, scm_class_applicable
))
2483 SCM dsupers
= SCM_SLOT (c
, scm_si_direct_supers
);
2484 SCM cpl
= SCM_SLOT (c
, scm_si_cpl
);
2485 /* patch scm_class_applicable into direct-supers */
2486 SCM top
= scm_c_memq (scm_class_top
, dsupers
);
2487 if (SCM_FALSEP (top
))
2488 dsupers
= scm_append (scm_list_2 (dsupers
,
2489 scm_list_1 (scm_class_applicable
)));
2492 SCM_SETCAR (top
, scm_class_applicable
);
2493 SCM_SETCDR (top
, scm_cons (scm_class_top
, SCM_CDR (top
)));
2495 SCM_SET_SLOT (c
, scm_si_direct_supers
, dsupers
);
2496 /* patch scm_class_applicable into cpl */
2497 top
= scm_c_memq (scm_class_top
, cpl
);
2498 if (SCM_FALSEP (top
))
2502 SCM_SETCAR (top
, scm_class_applicable
);
2503 SCM_SETCDR (top
, scm_cons (scm_class_top
, SCM_CDR (top
)));
2505 /* add class to direct-subclasses of scm_class_applicable */
2506 SCM_SET_SLOT (scm_class_applicable
,
2507 scm_si_direct_subclasses
,
2508 scm_cons (c
, SCM_SLOT (scm_class_applicable
,
2509 scm_si_direct_subclasses
)));
2514 create_smob_classes (void)
2518 scm_smob_class
= (SCM
*) scm_malloc (255 * sizeof (SCM
));
2519 for (i
= 0; i
< 255; ++i
)
2520 scm_smob_class
[i
] = 0;
2522 scm_smob_class
[SCM_TC2SMOBNUM (scm_tc16_big
)] = scm_class_integer
;
2523 scm_smob_class
[SCM_TC2SMOBNUM (scm_tc16_real
)] = scm_class_real
;
2524 scm_smob_class
[SCM_TC2SMOBNUM (scm_tc16_complex
)] = scm_class_complex
;
2525 scm_smob_class
[SCM_TC2SMOBNUM (scm_tc16_keyword
)] = scm_class_keyword
;
2527 for (i
= 0; i
< scm_numsmob
; ++i
)
2528 if (!scm_smob_class
[i
])
2529 scm_smob_class
[i
] = scm_make_extended_class (SCM_SMOBNAME (i
),
2530 scm_smobs
[i
].apply
!= 0);
2534 scm_make_port_classes (long ptobnum
, char *type_name
)
2536 SCM c
, class = make_class_from_template ("<%s-port>",
2538 scm_list_1 (scm_class_port
),
2540 scm_port_class
[SCM_IN_PCLASS_INDEX
+ ptobnum
]
2541 = make_class_from_template ("<%s-input-port>",
2543 scm_list_2 (class, scm_class_input_port
),
2545 scm_port_class
[SCM_OUT_PCLASS_INDEX
+ ptobnum
]
2546 = make_class_from_template ("<%s-output-port>",
2548 scm_list_2 (class, scm_class_output_port
),
2550 scm_port_class
[SCM_INOUT_PCLASS_INDEX
+ ptobnum
]
2552 = make_class_from_template ("<%s-input-output-port>",
2554 scm_list_2 (class, scm_class_input_output_port
),
2556 /* Patch cpl (since this tree is too complex for the C level compute-cpl) */
2557 SCM_SET_SLOT (c
, scm_si_cpl
,
2558 scm_cons2 (c
, class, SCM_SLOT (scm_class_input_output_port
, scm_si_cpl
)));
2562 create_port_classes (void)
2566 scm_port_class
= (SCM
*) scm_malloc (3 * 256 * sizeof (SCM
));
2567 for (i
= 0; i
< 3 * 256; ++i
)
2568 scm_port_class
[i
] = 0;
2570 for (i
= 0; i
< scm_numptob
; ++i
)
2571 scm_make_port_classes (i
, SCM_PTOBNAME (i
));
2575 make_struct_class (void *closure SCM_UNUSED
,
2576 SCM vtable
, SCM data
, SCM prev SCM_UNUSED
)
2578 if (!SCM_FALSEP (SCM_STRUCT_TABLE_NAME (data
)))
2579 SCM_SET_STRUCT_TABLE_CLASS (data
,
2580 scm_make_extended_class
2581 (SCM_SYMBOL_CHARS (SCM_STRUCT_TABLE_NAME (data
)),
2582 SCM_CLASS_FLAGS (vtable
) & SCM_CLASSF_OPERATOR
));
2583 return SCM_UNSPECIFIED
;
2587 create_struct_classes (void)
2589 scm_internal_hash_fold (make_struct_class
, 0, SCM_BOOL_F
, scm_struct_table
);
2592 /**********************************************************************
2596 **********************************************************************/
2601 if (!goops_loaded_p
)
2602 scm_c_resolve_module ("oop goops");
2607 scm_make_foreign_object (SCM
class, SCM initargs
)
2608 #define FUNC_NAME s_scm_make
2610 void * (*constructor
) (SCM
)
2611 = (void * (*) (SCM
)) SCM_SLOT (class, scm_si_constructor
);
2612 if (constructor
== 0)
2613 SCM_MISC_ERROR ("Can't make instances of class ~S", scm_list_1 (class));
2614 return scm_wrap_object (class, constructor (initargs
));
2620 scm_free_foreign_object (SCM
*class, SCM
*data
)
2622 size_t (*destructor
) (void *)
2623 = (size_t (*) (void *)) class[scm_si_destructor
];
2624 return destructor (data
);
2628 scm_make_class (SCM meta
, char *s_name
, SCM supers
, size_t size
,
2629 void * (*constructor
) (SCM initargs
),
2630 size_t (*destructor
) (void *))
2633 name
= scm_str2symbol (s_name
);
2634 if (SCM_NULLP (supers
))
2635 supers
= scm_list_1 (scm_class_foreign_object
);
2636 class = scm_basic_basic_make_class (meta
, name
, supers
, SCM_EOL
);
2637 scm_sys_inherit_magic_x (class, supers
);
2639 if (destructor
!= 0)
2641 SCM_SET_SLOT (class, scm_si_destructor
, (SCM
) destructor
);
2642 SCM_SET_CLASS_DESTRUCTOR (class, scm_free_foreign_object
);
2646 SCM_SET_CLASS_DESTRUCTOR (class, scm_struct_free_light
);
2647 SCM_SET_CLASS_INSTANCE_SIZE (class, size
);
2650 SCM_SET_SLOT (class, scm_si_layout
, scm_str2symbol (""));
2651 SCM_SET_SLOT (class, scm_si_constructor
, (SCM
) constructor
);
2656 SCM_SYMBOL (sym_o
, "o");
2657 SCM_SYMBOL (sym_x
, "x");
2659 SCM_KEYWORD (k_accessor
, "accessor");
2660 SCM_KEYWORD (k_getter
, "getter");
2663 default_setter (SCM obj SCM_UNUSED
, SCM c SCM_UNUSED
)
2665 scm_misc_error ("slot-set!", "read-only slot", SCM_EOL
);
2670 scm_add_slot (SCM
class, char *slot_name
, SCM slot_class
,
2671 SCM (*getter
) (SCM obj
),
2672 SCM (*setter
) (SCM obj
, SCM x
),
2673 char *accessor_name
)
2676 SCM get
= scm_c_make_subr ("goops:get", scm_tc7_subr_1
, getter
);
2677 SCM set
= scm_c_make_subr ("goops:set", scm_tc7_subr_2
,
2678 setter
? setter
: default_setter
);
2679 SCM getm
= scm_closure (scm_list_2 (scm_list_1 (sym_o
),
2680 scm_list_2 (get
, sym_o
)),
2682 SCM setm
= scm_closure (scm_list_2 (scm_list_2 (sym_o
, sym_x
),
2683 scm_list_3 (set
, sym_o
, sym_x
)),
2686 SCM name
= scm_str2symbol (slot_name
);
2687 SCM aname
= scm_str2symbol (accessor_name
);
2688 SCM gf
= scm_ensure_accessor (aname
);
2689 SCM slot
= scm_list_5 (name
,
2692 setter
? k_accessor
: k_getter
,
2694 scm_add_method (gf
, scm_make (scm_list_5 (scm_class_accessor_method
,
2699 scm_add_method (scm_setter (gf
),
2700 scm_make (scm_list_5 (scm_class_accessor_method
,
2702 scm_list_2 (class, scm_class_top
),
2707 SCM_SET_SLOT (class, scm_si_slots
,
2708 scm_append_x (scm_list_2 (SCM_SLOT (class, scm_si_slots
),
2709 scm_list_1 (slot
))));
2711 SCM n
= SCM_SLOT (class, scm_si_nfields
);
2712 SCM gns
= scm_list_n (name
, SCM_BOOL_F
, get
, set
, n
, SCM_MAKINUM (1));
2713 SCM_SET_SLOT (class, scm_si_getters_n_setters
,
2714 scm_append_x (scm_list_2 (SCM_SLOT (class, scm_si_getters_n_setters
),
2715 scm_list_1 (gns
))));
2716 SCM_SET_SLOT (class, scm_si_nfields
, SCM_MAKINUM (SCM_INUM (n
) + 1));
2723 scm_wrap_object (SCM
class, void *data
)
2725 return scm_double_cell (SCM_UNPACK (SCM_CDR (class)) | scm_tc3_struct
,
2733 scm_wrap_component (SCM
class, SCM container
, void *data
)
2735 SCM obj
= scm_wrap_object (class, data
);
2736 SCM handle
= scm_hash_fn_create_handle_x (scm_components
,
2742 SCM_SETCDR (handle
, container
);
2747 scm_ensure_accessor (SCM name
)
2749 SCM gf
= scm_call_2 (SCM_TOP_LEVEL_LOOKUP_CLOSURE
, name
, SCM_BOOL_F
);
2750 if (!SCM_IS_A_P (gf
, scm_class_accessor
))
2752 gf
= scm_make (scm_list_3 (scm_class_generic
, k_name
, name
));
2753 gf
= scm_make (scm_list_5 (scm_class_accessor
,
2754 k_name
, name
, k_setter
, gf
));
2759 SCM_SYMBOL (sym_internal_add_method_x
, "internal-add-method!");
2762 scm_add_method (SCM gf
, SCM m
)
2764 scm_eval (scm_list_3 (sym_internal_add_method_x
, gf
, m
), scm_module_goops
);
2769 * Debugging utilities
2772 SCM_DEFINE (scm_pure_generic_p
, "pure-generic?", 1, 0, 0,
2774 "Return @code{#t} if @var{obj} is a pure generic.")
2775 #define FUNC_NAME s_scm_pure_generic_p
2777 return SCM_BOOL (SCM_PUREGENERICP (obj
));
2781 #endif /* GUILE_DEBUG */
2787 SCM_DEFINE (scm_sys_goops_loaded
, "%goops-loaded", 0, 0, 0,
2789 "Announce that GOOPS is loaded and perform initialization\n"
2790 "on the C level which depends on the loaded GOOPS modules.")
2791 #define FUNC_NAME s_scm_sys_goops_loaded
2794 var_compute_applicable_methods
=
2795 scm_sym2var (sym_compute_applicable_methods
, scm_goops_lookup_closure
,
2797 setup_extended_primitive_generics ();
2798 return SCM_UNSPECIFIED
;
2802 SCM scm_module_goops
;
2805 scm_init_goops_builtins (void)
2807 scm_module_goops
= scm_current_module ();
2808 scm_goops_lookup_closure
= scm_module_lookup_closure (scm_module_goops
);
2810 /* Not really necessary right now, but who knows...
2812 scm_permanent_object (scm_module_goops
);
2813 scm_permanent_object (scm_goops_lookup_closure
);
2815 scm_components
= scm_permanent_object (scm_make_weak_key_hash_table
2816 (SCM_MAKINUM (37)));
2818 goops_rstate
= scm_c_make_rstate ("GOOPS", 5);
2820 #include "libguile/goops.x"
2822 list_of_no_method
= scm_permanent_object (scm_list_1 (sym_no_method
));
2824 hell
= scm_malloc (hell_size
);
2825 hell_mutex
= scm_permanent_object (scm_make_mutex ());
2827 create_basic_classes ();
2828 create_standard_classes ();
2829 create_smob_classes ();
2830 create_struct_classes ();
2831 create_port_classes ();
2834 SCM name
= scm_str2symbol ("no-applicable-method");
2835 scm_no_applicable_method
2836 = scm_permanent_object (scm_make (scm_list_3 (scm_class_generic
,
2839 DEFVAR (name
, scm_no_applicable_method
);
2842 return SCM_UNSPECIFIED
;
2848 scm_c_define_gsubr ("%init-goops-builtins", 0, 0, 0,
2849 scm_init_goops_builtins
);