Commit | Line | Data |
---|---|---|
1d9ee7c7 MD |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef OBJECTSH | |
4 | #define OBJECTSH | |
5 | ||
6 | /* Copyright (C) 1996 Free Software Foundation, Inc. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2, or (at your option) | |
11 | * any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this software; see the file COPYING. If not, write to | |
20 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
21 | * Boston, MA 02111-1307 USA | |
22 | * | |
23 | * As a special exception, the Free Software Foundation gives permission | |
24 | * for additional uses of the text contained in its release of GUILE. | |
25 | * | |
26 | * The exception is that, if you link the GUILE library with other files | |
27 | * to produce an executable, this does not by itself cause the | |
28 | * resulting executable to be covered by the GNU General Public License. | |
29 | * Your use of that executable is in no way restricted on account of | |
30 | * linking the GUILE library code into it. | |
31 | * | |
32 | * This exception does not however invalidate any other reasons why | |
33 | * the executable file might be covered by the GNU General Public License. | |
34 | * | |
35 | * This exception applies only to the code released by the | |
36 | * Free Software Foundation under the name GUILE. If you copy | |
37 | * code from other Free Software Foundation releases into a copy of | |
38 | * GUILE, as the General Public License permits, the exception does | |
39 | * not apply to the code that you add in this way. To avoid misleading | |
40 | * anyone as to the status of such modified files, you must delete | |
41 | * this exception notice from them. | |
42 | * | |
43 | * If you write modifications of your own for GUILE, it is your choice | |
44 | * whether to permit this exception to apply to your modifications. | |
45 | * If you do not wish that, delete this exception notice. */ | |
46 | \f | |
47 | ||
da7f71d7 MD |
48 | /* This file and objects.c contains those minimal pieces of the Guile |
49 | * Object Oriented Programming System which need to be included in | |
50 | * libguile. | |
51 | * | |
52 | * {Objects and structs} | |
53 | * | |
54 | * Objects are currently based upon structs. Although the struct | |
55 | * implementation will change thoroughly in the future, objects will | |
56 | * still be based upon structs. | |
57 | */ | |
58 | ||
1d9ee7c7 MD |
59 | #include "libguile/__scm.h" |
60 | #include "libguile/struct.h" | |
61 | ||
62 | \f | |
63 | ||
da7f71d7 MD |
64 | /* {Class flags} |
65 | * | |
66 | * These are used for efficient identification of instances of a | |
67 | * certain class or its subclasses when traversal of the inheritance | |
68 | * graph would be too costly. | |
69 | */ | |
70 | #define SCM_CLASS_FLAGS(class) (SCM_STRUCT_DATA (class)[scm_struct_i_tag]) | |
71 | #define SCM_OBJ_CLASS_FLAGS(obj)\ | |
72 | (SCM_STRUCT_VTABLE_DATA (obj)[scm_struct_i_tag]) | |
73 | #define SCM_SET_CLASS_FLAGS(c, f) (SCM_CLASS_FLAGS (c) |= (f)) | |
74 | #define SCM_CLEAR_CLASS_FLAGS(c, f) (SCM_CLASS_FLAGS (c) &= ~(f)) | |
75 | #define SCM_CLASSF_MASK (0xFF << 24) | |
76 | ||
77 | /* Operator classes need to be identified in the evaluator. */ | |
78 | #define SCM_CLASSF_OPERATOR (1L << 30) | |
79 | /* Entities also have SCM_CLASSF_OPERATOR set in their vtable. */ | |
80 | #define SCM_CLASSF_ENTITY (1L << 29) | |
81 | ||
82 | #define SCM_I_OPERATORP(obj)\ | |
83 | ((SCM_OBJ_CLASS_FLAGS (obj) & SCM_CLASSF_OPERATOR) != 0) | |
84 | #define SCM_OPERATOR_CLASS(obj)\ | |
85 | ((struct scm_metaclass_operator *) SCM_STRUCT_DATA (obj)) | |
86 | #define SCM_OBJ_OPERATOR_CLASS(obj)\ | |
87 | ((struct scm_metaclass_operator *) SCM_STRUCT_VTABLE_DATA (obj)) | |
88 | #define SCM_OPERATOR_PROC_0(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->proc0) | |
89 | #define SCM_OPERATOR_PROC_1(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->proc1) | |
90 | #define SCM_OPERATOR_PROC_2(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->proc2) | |
91 | #define SCM_OPERATOR_PROC_3(obj) (SCM_OBJ_OPERATOR_CLASS (obj)->proc3) | |
92 | ||
93 | #define SCM_I_ENTITYP(obj)\ | |
94 | ((SCM_OBJ_CLASS_FLAGS (obj) & SCM_CLASSF_ENTITY) != 0) | |
95 | #define SCM_ENTITY(obj) ((scm_entity*) SCM_STRUCT_DATA (obj)) | |
96 | #define SCM_ENTITY_PROC_0(obj) (SCM_ENTITY (obj)->proc0) | |
97 | #define SCM_ENTITY_PROC_1(obj) (SCM_ENTITY (obj)->proc1) | |
98 | #define SCM_ENTITY_PROC_2(obj) (SCM_ENTITY (obj)->proc2) | |
99 | #define SCM_ENTITY_PROC_3(obj) (SCM_ENTITY (obj)->proc3) | |
1d9ee7c7 | 100 | |
da7f71d7 MD |
101 | /* {Operator classes} |
102 | * | |
103 | * Instances of operator classes can work as operators, i. e., they | |
104 | * can be applied to arguments just as if they were ordinary | |
105 | * procedures. | |
106 | * | |
107 | * For instances of operator classes, the procedures to be applied are | |
108 | * stored in four dedicated slots in the associated class object. | |
109 | * Which one is selected depends on the number of arguments in the | |
110 | * application. | |
111 | * | |
112 | * If zero arguments are passed, the first will be selected. | |
113 | * If one argument is passed, the second will be selected. | |
114 | * If two arguments are passed, the third will be selected. | |
115 | * If three or more arguments are passed, the fourth will be selected. | |
116 | * | |
117 | * This is complicated and may seem gratuitous but has to do with the | |
118 | * architecture of the evaluator. Using only one procedure would | |
119 | * result in a great deal less efficient application, loss of | |
120 | * tail-recursion and would be difficult to reconcile with the | |
121 | * debugging evaluator. | |
122 | * | |
123 | * Also, using this "forked" application in low-level code has the | |
124 | * advantage of speeding up some code. An example is method dispatch | |
125 | * for generic operators applied to few arguments. On the user level, | |
126 | * the "forked" application will be hidden by mechanisms in the GOOPS | |
127 | * package. | |
128 | * | |
129 | * Operator classes have the metaclass <operator-metaclass>. | |
130 | * | |
131 | * An example of an operator class is the class <tk-command>. | |
132 | */ | |
133 | #define SCM_METACLASS_STANDARD_LAYOUT "pwpw" | |
1d9ee7c7 MD |
134 | struct scm_metaclass_standard { |
135 | SCM layout; | |
136 | SCM vcell; | |
137 | SCM vtable; | |
138 | SCM print; | |
139 | SCM direct_supers; | |
140 | SCM direct_slots; | |
141 | }; | |
142 | ||
b6d850ad | 143 | #define SCM_METACLASS_OPERATOR_LAYOUT "pwpwpopopopo" |
da7f71d7 MD |
144 | struct scm_metaclass_operator { |
145 | SCM layout; | |
146 | SCM vcell; | |
147 | SCM vtable; | |
148 | SCM print; | |
149 | SCM direct_supers; | |
150 | SCM direct_slots; | |
151 | SCM proc0; | |
152 | SCM proc1; | |
153 | SCM proc2; | |
154 | SCM proc3; | |
155 | }; | |
156 | ||
157 | /* {Entity classes} | |
158 | * | |
159 | * For instances of entity classes (entities), the procedures to be | |
160 | * applied are stored in the instance itself rather than in the class | |
161 | * object as is the case for instances of operator classes (see above). | |
162 | * | |
163 | * An example of an entity class is the class of generic methods. | |
164 | */ | |
b6d850ad | 165 | #define SCM_ENTITY_LAYOUT "popopopo" |
1d9ee7c7 MD |
166 | typedef struct scm_entity { |
167 | SCM proc0; | |
168 | SCM proc1; | |
169 | SCM proc2; | |
170 | SCM proc3; | |
171 | } scm_entity; | |
172 | ||
173 | extern SCM scm_metaclass_standard; | |
da7f71d7 | 174 | extern SCM scm_metaclass_operator; |
1d9ee7c7 | 175 | |
2d5881d5 JB |
176 | extern SCM scm_set_object_procedure_x (SCM obj, SCM procs); |
177 | extern SCM scm_make_class_object (SCM metaclass, SCM layout); | |
178 | extern SCM scm_make_subclass_object (SCM class, SCM layout); | |
179 | ||
1d9ee7c7 MD |
180 | extern void scm_init_objects SCM_P ((void)); |
181 | ||
182 | #endif /* OBJECTSH */ |