Fix broken interaction between readline and Unicode
[bpt/guile.git] / libguile / objects.h
1 /* classes: h_files */
2
3 #ifndef SCM_OBJECTS_H
4 #define SCM_OBJECTS_H
5
6 /* Copyright (C) 1996,1999,2000,2001, 2003, 2006, 2008, 2009 Free Software Foundation, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
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.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
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
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 */
23
24 \f
25
26 /* This file and objects.c contains those minimal pieces of the Guile
27 * Object Oriented Programming System which need to be included in
28 * libguile.
29 *
30 * {Objects and structs}
31 *
32 * Objects are currently based upon structs. Although the struct
33 * implementation will change thoroughly in the future, objects will
34 * still be based upon structs.
35 */
36
37 #include "libguile/__scm.h"
38 #include "libguile/struct.h"
39
40 \f
41
42 /* {Class flags}
43 *
44 * These are used for efficient identification of instances of a
45 * certain class or its subclasses when traversal of the inheritance
46 * graph would be too costly.
47 */
48 #define SCM_CLASS_FLAGS(class) (SCM_STRUCT_DATA (class) [scm_struct_i_flags])
49 #define SCM_OBJ_CLASS_FLAGS(obj) (SCM_STRUCT_VTABLE_DATA (obj) [scm_struct_i_flags])
50 #define SCM_SET_CLASS_FLAGS(c, f) (SCM_CLASS_FLAGS (c) |= (f))
51 #define SCM_CLEAR_CLASS_FLAGS(c, f) (SCM_CLASS_FLAGS (c) &= ~(f))
52 #define SCM_CLASSF_MASK SCM_STRUCTF_MASK
53
54 #define SCM_CLASSF_ENTITY SCM_STRUCTF_ENTITY
55 /* Operator classes need to be identified in the evaluator.
56 (Entities also have SCM_CLASSF_OPERATOR set in their vtable.) */
57 #define SCM_CLASSF_OPERATOR (1L << 29)
58
59 #define SCM_I_OPERATORP(obj)\
60 ((SCM_OBJ_CLASS_FLAGS (obj) & SCM_CLASSF_OPERATOR) != 0)
61 #define SCM_OPERATOR_CLASS(obj)\
62 ((struct scm_metaclass_operator *) SCM_STRUCT_DATA (obj))
63 #define SCM_OBJ_OPERATOR_CLASS(obj)\
64 ((struct scm_metaclass_operator *) SCM_STRUCT_VTABLE_DATA (obj))
65 #define SCM_OPERATOR_PROCEDURE(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->procedure)
66 #define SCM_OPERATOR_SETTER(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->setter)
67
68 #define SCM_I_ENTITYP(obj)\
69 ((SCM_OBJ_CLASS_FLAGS (obj) & SCM_CLASSF_ENTITY) != 0)
70 #define SCM_ENTITY_PROCEDURE(obj) \
71 (SCM_PACK (SCM_STRUCT_DATA (obj) [scm_struct_i_procedure]))
72 #define SCM_SET_ENTITY_PROCEDURE(obj, v) \
73 (SCM_STRUCT_DATA (obj) [scm_struct_i_procedure] = SCM_UNPACK (v))
74 #define SCM_ENTITY_SETTER(obj) (SCM_PACK (SCM_STRUCT_DATA (obj)[scm_struct_i_setter]))
75 #define SCM_SET_ENTITY_SETTER(obj, v) \
76 (SCM_STRUCT_DATA (obj) [scm_struct_i_setter] = SCM_UNPACK (v))
77
78 #define SCM_SET_CLASS_DESTRUCTOR(c, d) SCM_SET_VTABLE_DESTRUCTOR (c, d)
79 #define SCM_SET_CLASS_INSTANCE_SIZE(c, s) \
80 (SCM_STRUCT_DATA (c)[scm_struct_i_size] \
81 = (SCM_STRUCT_DATA (c) [scm_struct_i_size] & SCM_STRUCTF_MASK) | s)
82
83 /* {Operator classes}
84 *
85 * Instances of operator classes can work as operators, i. e., they
86 * can be applied to arguments just as if they were ordinary
87 * procedures.
88 *
89 * For instances of operator classes, the procedures to be applied are
90 * stored in four dedicated slots in the associated class object.
91 * Which one is selected depends on the number of arguments in the
92 * application.
93 *
94 * If zero arguments are passed, the first will be selected.
95 * If one argument is passed, the second will be selected.
96 * If two arguments are passed, the third will be selected.
97 * If three or more arguments are passed, the fourth will be selected.
98 *
99 * This is complicated and may seem gratuitous but has to do with the
100 * architecture of the evaluator. Using only one procedure would
101 * result in a great deal less efficient application, loss of
102 * tail-recursion and would be difficult to reconcile with the
103 * debugging evaluator.
104 *
105 * Also, using this "forked" application in low-level code has the
106 * advantage of speeding up some code. An example is method dispatch
107 * for generic operators applied to few arguments. On the user level,
108 * the "forked" application will be hidden by mechanisms in the GOOPS
109 * package.
110 *
111 * Operator classes have the metaclass <operator-metaclass>.
112 *
113 * An example of an operator class is the class <tk-command>.
114 */
115 #define SCM_METACLASS_STANDARD_LAYOUT ""
116 struct scm_metaclass_standard {
117 SCM layout;
118 SCM vcell;
119 SCM vtable;
120 SCM print;
121 };
122
123 #define SCM_METACLASS_OPERATOR_LAYOUT "popo"
124 struct scm_metaclass_operator {
125 SCM layout;
126 SCM vcell;
127 SCM vtable;
128 SCM print;
129 SCM procedure;
130 SCM setter;
131 };
132
133 /* {Entity classes}
134 *
135 * For instances of entity classes (entities), the procedures to be
136 * applied are stored in the instance itself rather than in the class
137 * object as is the case for instances of operator classes (see above).
138 *
139 * An example of an entity class is the class of generic methods.
140 */
141 #define SCM_ENTITY_LAYOUT ""
142
143 /* {Interface to Goops}
144 *
145 * The evaluator contains a multi-method dispatch mechanism.
146 * This interface is used by that mechanism and during creation of
147 * smob and struct classes.
148 */
149
150 /* Internal representation of Goops objects. */
151 #define SCM_CLASSF_PURE_GENERIC (0x010 << 20)
152 #define SCM_CLASSF_GOOPS_VALID (0x080 << 20)
153 #define SCM_CLASSF_GOOPS (0x100 << 20)
154 #define scm_si_redefined 5
155 #define scm_si_hashsets 6
156 #define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x)
157 #define SCM_OBJ_CLASS_REDEF(x) (SCM_PACK (SCM_STRUCT_VTABLE_DATA (x) [scm_si_redefined]))
158
159 typedef struct scm_effective_slot_definition {
160 SCM name;
161 long location;
162 SCM init_value;
163 SCM (*get) (SCM obj, SCM slotdef);
164 SCM (*set) (SCM obj, SCM slotdef, SCM value);
165 } scm_effective_slot_definition;
166
167 #define SCM_ESLOTDEF(x) ((scm_effective_slot_definition *) SCM_CDR (x))
168
169 #define SCM_CMETHOD_CODE(cmethod) SCM_CDR (cmethod)
170 #define SCM_CMETHOD_FORMALS(cmethod) SCM_CAR (SCM_CMETHOD_CODE (cmethod))
171 #define SCM_CMETHOD_BODY(cmethod) SCM_CDR (SCM_CMETHOD_CODE (cmethod))
172 #define SCM_CMETHOD_ENV(cmethod) SCM_CAR (cmethod)
173
174 /* Port classes */
175 #define SCM_IN_PCLASS_INDEX 0
176 #define SCM_OUT_PCLASS_INDEX SCM_I_MAX_PORT_TYPE_COUNT
177 #define SCM_INOUT_PCLASS_INDEX (2 * SCM_I_MAX_PORT_TYPE_COUNT)
178
179 /* Plugin proxy classes for basic types. */
180 SCM_API SCM scm_metaclass_standard;
181 SCM_API SCM scm_metaclass_operator;
182
183 /* Goops functions. */
184 SCM_API SCM scm_make_extended_class (char const *type_name, int applicablep);
185 SCM_INTERNAL void scm_i_inherit_applicable (SCM c);
186 SCM_API void scm_make_port_classes (long ptobnum, char *type_name);
187 SCM_API void scm_change_object_class (SCM, SCM, SCM);
188 SCM_API SCM scm_memoize_method (SCM x, SCM args);
189
190 SCM_API SCM scm_mcache_lookup_cmethod (SCM cache, SCM args);
191 SCM_API SCM scm_mcache_compute_cmethod (SCM cache, SCM args);
192 /* The following are declared in __scm.h
193 SCM_API SCM scm_call_generic_0 (SCM gf);
194 SCM_API SCM scm_call_generic_1 (SCM gf, SCM a1);
195 SCM_API SCM scm_call_generic_2 (SCM gf, SCM a1, SCM a2);
196 SCM_API SCM scm_apply_generic (SCM gf, SCM args);
197 */
198 SCM_API SCM scm_call_generic_3 (SCM gf, SCM a1, SCM a2, SCM a3);
199 SCM_API SCM scm_entity_p (SCM obj);
200 SCM_API SCM scm_operator_p (SCM obj);
201 SCM_API SCM scm_valid_object_procedure_p (SCM proc);
202 SCM_API SCM scm_set_object_procedure_x (SCM obj, SCM proc);
203 #ifdef GUILE_DEBUG
204 SCM_API SCM scm_object_procedure (SCM obj);
205 #endif
206 SCM_API SCM scm_make_class_object (SCM metaclass, SCM layout);
207 SCM_API SCM scm_make_subclass_object (SCM c, SCM layout);
208
209 SCM_INTERNAL SCM scm_i_make_class_object (SCM metaclass, SCM layout_string,
210 unsigned long flags);
211 SCM_INTERNAL void scm_init_objects (void);
212
213 #endif /* SCM_OBJECTS_H */
214
215 /*
216 Local Variables:
217 c-file-style: "gnu"
218 End:
219 */