Commit | Line | Data |
---|---|---|
0518d3e2 MD |
1 | /* classes: h_files */ |
2 | ||
729dbac3 DH |
3 | #ifndef SCM_GOOPS_H |
4 | #define SCM_GOOPS_H | |
a392ee15 | 5 | |
51fd1cd6 | 6 | /* Copyright (C) 1998,1999,2000,2001,2002,2003, 2006, 2008, 2009, 2011, 2015 Free Software Foundation, Inc. |
a392ee15 | 7 | * |
73be1d9e | 8 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
9 | * modify it under the terms of the GNU Lesser General Public License |
10 | * as published by the Free Software Foundation; either version 3 of | |
11 | * the License, or (at your option) any later version. | |
a392ee15 | 12 | * |
53befeb7 NJ |
13 | * This library is distributed in the hope that it will be useful, but |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
a392ee15 | 17 | * |
73be1d9e MV |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the Free Software | |
53befeb7 NJ |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | * 02110-1301 USA | |
73be1d9e | 22 | */ |
a392ee15 | 23 | |
0518d3e2 MD |
24 | \f |
25 | ||
26 | /* This software is a derivative work of other copyrighted softwares; the | |
27 | * copyright notices of these softwares are placed in the file COPYRIGHTS | |
28 | * | |
29 | * This file is based upon stklos.h from the STk distribution by | |
30 | * Erick Gallesio <eg@unice.fr>. | |
31 | */ | |
32 | ||
33 | #include "libguile/__scm.h" | |
34 | ||
398d8ee1 KN |
35 | #include "libguile/validate.h" |
36 | ||
b6cf4d02 AW |
37 | /* {Class flags} |
38 | * | |
39 | * These are used for efficient identification of instances of a | |
40 | * certain class or its subclasses when traversal of the inheritance | |
41 | * graph would be too costly. | |
42 | */ | |
43 | #define SCM_VTABLE_FLAG_GOOPS_CLASS SCM_VTABLE_FLAG_GOOPS_0 | |
44 | #define SCM_VTABLE_FLAG_GOOPS_VALID SCM_VTABLE_FLAG_GOOPS_1 | |
b6cf4d02 AW |
45 | |
46 | #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x) | |
47 | #define SCM_CLASS_FLAGS(class) (SCM_VTABLE_FLAGS (class)) | |
48 | #define SCM_OBJ_CLASS_FLAGS(obj) (SCM_STRUCT_VTABLE_FLAGS (obj)) | |
49 | #define SCM_SET_CLASS_FLAGS(c, f) (SCM_SET_VTABLE_FLAGS (c, f)) | |
50 | #define SCM_CLEAR_CLASS_FLAGS(c, f) (SCM_CLEAR_VTABLE_FLAGS (c, f)) | |
51 | ||
51f66c91 | 52 | #define SCM_CLASSF_METACLASS (SCM_VTABLE_FLAG_GOOPS_CLASS|SCM_VTABLE_FLAG_VTABLE) |
b6cf4d02 AW |
53 | #define SCM_CLASSF_GOOPS_VALID SCM_VTABLE_FLAG_GOOPS_VALID |
54 | #define SCM_CLASSF_GOOPS SCM_VTABLE_FLAG_GOOPS_CLASS | |
b6cf4d02 AW |
55 | #define SCM_CLASSF_GOOPS_OR_VALID (SCM_CLASSF_GOOPS | SCM_CLASSF_GOOPS_VALID) |
56 | ||
0518d3e2 | 57 | #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x) |
00d8d838 DH |
58 | |
59 | #define SCM_CLASSP(x) \ | |
60 | (SCM_STRUCTP (x) && SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_METACLASS) | |
6182ceac | 61 | #define SCM_VALIDATE_CLASS(pos, x) SCM_MAKE_VALIDATE_MSG (pos, x, CLASSP, "class") |
0518d3e2 | 62 | |
25ba37df | 63 | #define SCM_INSTANCEP(x) \ |
00d8d838 | 64 | (SCM_STRUCTP (x) && (SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_GOOPS)) |
6182ceac | 65 | #define SCM_VALIDATE_INSTANCE(pos, x) SCM_MAKE_VALIDATE_MSG (pos, x, INSTANCEP, "instance") |
0518d3e2 | 66 | |
b6cf4d02 AW |
67 | #define SCM_SLOT(x, i) (SCM_STRUCT_SLOT_REF (x, i)) |
68 | #define SCM_SET_SLOT(x, i, v) (SCM_STRUCT_SLOT_SET (x, i, v)) | |
00d8d838 | 69 | |
2025a027 AW |
70 | #define SCM_SUBCLASSP(c1, c2) \ |
71 | (scm_is_true (scm_c_memq (c2, scm_class_precedence_list (c1)))) | |
00d8d838 DH |
72 | #define SCM_IS_A_P(x, c) \ |
73 | (SCM_INSTANCEP (x) && SCM_SUBCLASSP (SCM_CLASS_OF (x), c)) | |
0518d3e2 | 74 | |
57898597 | 75 | #define SCM_GENERICP(x) (scm_is_generic (x)) |
6182ceac | 76 | #define SCM_VALIDATE_GENERIC(pos, x) SCM_MAKE_VALIDATE_MSG (pos, x, GENERICP, "generic function") |
00d8d838 | 77 | |
57898597 | 78 | #define SCM_METHODP(x) (scm_is_method (x)) |
6182ceac | 79 | #define SCM_VALIDATE_METHOD(pos, x) SCM_MAKE_VALIDATE_MSG (pos, x, METHODP, "method") |
398d8ee1 | 80 | |
efcebb5b | 81 | #define SCM_SET_CLASS_DESTRUCTOR(c, d) SCM_SET_VTABLE_DESTRUCTOR (c, d) |
efcebb5b | 82 | |
57898597 AW |
83 | SCM_INTERNAL SCM scm_i_port_class[]; |
84 | SCM_INTERNAL SCM scm_i_smob_class[]; | |
33b001fd MV |
85 | |
86 | SCM_API SCM scm_module_goops; | |
87 | ||
88 | SCM_API SCM scm_goops_version (void); | |
33b001fd | 89 | SCM_API void scm_load_goops (void); |
efcebb5b AW |
90 | SCM_API SCM scm_make_extended_class (char const *type_name, int applicablep); |
91 | SCM_API void scm_make_port_classes (long ptobnum, char *type_name); | |
33b001fd | 92 | SCM_API SCM scm_ensure_accessor (SCM name); |
539d5410 | 93 | SCM_API SCM scm_class_of (SCM obj); |
0518d3e2 MD |
94 | |
95 | /* Low level functions exported */ | |
33b001fd | 96 | SCM_API SCM scm_make_next_method (SCM methods, SCM args, SCM gf); |
28b818d3 AW |
97 | SCM_INTERNAL SCM scm_make_standard_class (SCM meta, SCM name, SCM dsupers, |
98 | SCM dslots); | |
0518d3e2 MD |
99 | |
100 | /* Primitives exported */ | |
33b001fd MV |
101 | SCM_API SCM scm_slot_ref (SCM obj, SCM slot_name); |
102 | SCM_API SCM scm_slot_set_x (SCM obj, SCM slot_name, SCM value); | |
103 | ||
efcebb5b | 104 | SCM_INTERNAL void scm_i_inherit_applicable (SCM c); |
0b607675 TTN |
105 | SCM_API SCM scm_sys_inherit_magic_x (SCM c, SCM dsupers); |
106 | SCM_API SCM scm_instance_p (SCM obj); | |
57898597 AW |
107 | SCM_API int scm_is_generic (SCM x); |
108 | SCM_API int scm_is_method (SCM x); | |
0b607675 TTN |
109 | SCM_API SCM scm_class_name (SCM obj); |
110 | SCM_API SCM scm_class_direct_supers (SCM obj); | |
111 | SCM_API SCM scm_class_direct_slots (SCM obj); | |
112 | SCM_API SCM scm_class_direct_subclasses (SCM obj); | |
113 | SCM_API SCM scm_class_direct_methods (SCM obj); | |
114 | SCM_API SCM scm_class_precedence_list (SCM obj); | |
115 | SCM_API SCM scm_class_slots (SCM obj); | |
0b607675 TTN |
116 | SCM_API SCM scm_generic_function_name (SCM obj); |
117 | SCM_API SCM scm_generic_function_methods (SCM obj); | |
118 | SCM_API SCM scm_method_generic_function (SCM obj); | |
119 | SCM_API SCM scm_method_specializers (SCM obj); | |
120 | SCM_API SCM scm_method_procedure (SCM obj); | |
0b607675 TTN |
121 | SCM_API SCM scm_slot_ref_using_class (SCM cls, SCM obj, SCM slot_name); |
122 | SCM_API SCM scm_slot_set_using_class_x (SCM cls, SCM obj, SCM slot_name, SCM value); | |
123 | SCM_API SCM scm_slot_bound_using_class_p (SCM cls, SCM obj, SCM slot_name); | |
124 | SCM_API SCM scm_slot_exists_using_class_p (SCM cls, SCM obj, SCM slot_name); | |
125 | SCM_API SCM scm_slot_bound_p (SCM obj, SCM slot_name); | |
126 | SCM_API SCM scm_slot_exists_p (SCM obj, SCM slot_name); | |
127 | SCM_API SCM scm_sys_modify_instance (SCM old, SCM newinst); | |
33b001fd MV |
128 | SCM_API SCM scm_sys_modify_class (SCM old, SCM newcls); |
129 | SCM_API SCM scm_sys_invalidate_class (SCM cls); | |
33b001fd MV |
130 | SCM_API SCM scm_sys_invalidate_method_cache_x (SCM gf); |
131 | SCM_API SCM scm_generic_capability_p (SCM proc); | |
132 | SCM_API SCM scm_enable_primitive_generic_x (SCM subrs); | |
9f63ce02 | 133 | SCM_INTERNAL SCM scm_set_primitive_generic_x (SCM subr, SCM generic); |
33b001fd | 134 | SCM_API SCM scm_primitive_generic_generic (SCM subr); |
0b607675 TTN |
135 | SCM_API SCM stklos_version (void); |
136 | SCM_API SCM scm_make (SCM args); | |
efcebb5b | 137 | SCM_API void scm_change_object_class (SCM, SCM, SCM); |
fa075d40 AW |
138 | |
139 | /* These procedures are for dispatching to a generic when a primitive | |
140 | fails to apply. They raise a wrong-type-arg error if the primitive's | |
141 | generic has not been initialized yet. */ | |
142 | SCM_API SCM scm_wta_dispatch_0 (SCM gf, const char *subr); | |
143 | SCM_API SCM scm_wta_dispatch_1 (SCM gf, SCM a1, int pos, const char *subr); | |
144 | SCM_API SCM scm_wta_dispatch_2 (SCM gf, SCM a1, SCM a2, int pos, const char *subr); | |
145 | SCM_API SCM scm_wta_dispatch_n (SCM gf, SCM args, int pos, const char *subr); | |
efcebb5b | 146 | |
f3c6a02c AW |
147 | SCM_INTERNAL SCM scm_i_define_class_for_vtable (SCM vtable); |
148 | ||
33b001fd | 149 | |
102dbb6f | 150 | SCM_INTERNAL void scm_init_goops (void); |
0518d3e2 | 151 | |
a392ee15 DH |
152 | #endif /* SCM_GOOPS_H */ |
153 | ||
154 | /* | |
155 | Local Variables: | |
156 | c-file-style: "gnu" | |
157 | End: | |
158 | */ |