Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
22a52da1 DH |
3 | #ifndef SCM_TAGS_H |
4 | #define SCM_TAGS_H | |
8c494e99 | 5 | |
47dbd81e | 6 | /* Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc. |
8ce94504 | 7 | * |
73be1d9e MV |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
8ce94504 | 12 | * |
73be1d9e | 13 | * This library is distributed in the hope that it will be useful, |
0f2d19dd | 14 | * but 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. | |
8ce94504 | 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 | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | */ | |
1bbd0b84 | 22 | |
0f2d19dd JB |
23 | \f |
24 | ||
8ce94504 | 25 | /** This file defines the format of SCM values and cons pairs. |
0f2d19dd JB |
26 | ** It is here that tag bits are assigned for various purposes. |
27 | **/ | |
28 | ||
353d4770 RB |
29 | /* picks up scmconfig.h too */ |
30 | #include "libguile/__scm.h" | |
0f2d19dd | 31 | |
ee89863b KR |
32 | #if HAVE_INTTYPES_H |
33 | # include <inttypes.h> /* for INTPTR_MAX and friends */ | |
34 | #else | |
35 | # if HAVE_STDINT_H | |
36 | # include <stdint.h> /* for INTPTR_MAX and friends */ | |
37 | # endif | |
38 | #endif | |
39 | ||
7e3b25bf DH |
40 | \f |
41 | ||
0f2d19dd | 42 | /* In the beginning was the Word: |
7e3b25bf DH |
43 | * |
44 | * For the representation of scheme objects and their handling, Guile provides | |
45 | * two types: scm_t_bits and SCM. | |
46 | * | |
47 | * - scm_t_bits values can hold bit patterns of non-objects and objects: | |
48 | * | |
49 | * Non-objects -- in this case the value may not be changed into a SCM value | |
50 | * in any way. | |
51 | * | |
52 | * Objects -- in this case the value may be changed into a SCM value using | |
53 | * the SCM_PACK macro. | |
54 | * | |
55 | * - SCM values can hold proper scheme objects only. They can be changed into | |
56 | * a scm_t_bits value using the SCM_UNPACK macro. | |
57 | * | |
58 | * When working in the domain of scm_t_bits values, programmers must keep | |
59 | * track of any scm_t_bits value they create that is not a proper scheme | |
60 | * object. This makes sure that in the domain of SCM values developers can | |
61 | * rely on the fact that they are dealing with proper scheme objects only. | |
62 | * Thus, the distinction between scm_t_bits and SCM values helps to identify | |
63 | * those parts of the code where special care has to be taken not to create | |
64 | * bad SCM values. | |
65 | */ | |
66 | ||
67 | /* For dealing with the bit level representation of scheme objects we define | |
68 | * scm_t_bits: | |
0f2d19dd | 69 | */ |
23c96d9b KR |
70 | /* On Solaris 7 and 8, /usr/include/sys/int_limits.h defines |
71 | INTPTR_MAX and UINTPTR_MAX to empty, INTPTR_MIN is not defined. | |
72 | To avoid uintptr_t and intptr_t in this case we require | |
73 | UINTPTR_MAX-0 != 0 etc. */ | |
74 | #if SCM_SIZEOF_INTPTR_T != 0 && defined(INTPTR_MAX) && defined(INTPTR_MIN) \ | |
75 | && INTPTR_MAX-0 != 0 && INTPTR_MIN-0 != 0 \ | |
76 | && SCM_SIZEOF_UINTPTR_T != 0 && defined(UINTPTR_MAX) && UINTPTR_MAX-0 != 0 | |
77 | ||
f59195a1 | 78 | typedef intptr_t scm_t_signed_bits; |
004c0902 MV |
79 | #define SCM_T_SIGNED_BITS_MAX INTPTR_MAX |
80 | #define SCM_T_SIGNED_BITS_MIN INTPTR_MIN | |
353d4770 RB |
81 | typedef uintptr_t scm_t_bits; |
82 | #define SIZEOF_SCM_T_BITS SCM_SIZEOF_UINTPTR_T | |
83 | #define SCM_T_BITS_MAX UINTPTR_MAX | |
23c96d9b | 84 | |
353d4770 | 85 | #else |
23c96d9b KR |
86 | |
87 | typedef signed long scm_t_signed_bits; | |
88 | #define SCM_T_SIGNED_BITS_MAX LONG_MAX | |
89 | #define SCM_T_SIGNED_BITS_MIN LONG_MIN | |
353d4770 RB |
90 | typedef unsigned long scm_t_bits; |
91 | #define SIZEOF_SCM_T_BITS SCM_SIZEOF_UNSIGNED_LONG | |
92 | #define SCM_T_BITS_MAX ULONG_MAX | |
23c96d9b | 93 | |
353d4770 RB |
94 | #endif |
95 | ||
7e3b25bf DH |
96 | /* But as external interface, we define SCM, which may, according to the |
97 | * desired level of type checking, be defined in several ways: | |
8d3356e7 | 98 | */ |
729dbac3 | 99 | #if (SCM_DEBUG_TYPING_STRICTNESS == 2) |
92c2555f MV |
100 | typedef union { struct { scm_t_bits n; } n; } SCM; |
101 | static SCM scm_pack(scm_t_bits b) { SCM s; s.n.n = b; return s; } | |
076d6063 | 102 | # define SCM_UNPACK(x) ((x).n.n) |
92c2555f | 103 | # define SCM_PACK(x) (scm_pack ((scm_t_bits) (x))) |
729dbac3 | 104 | #elif (SCM_DEBUG_TYPING_STRICTNESS == 1) |
8d3356e7 DH |
105 | /* This is the default, which provides an intermediate level of compile time |
106 | * type checking while still resulting in very efficient code. | |
c209c88e | 107 | */ |
729dbac3 | 108 | typedef struct scm_unused_struct * SCM; |
702551e6 HWN |
109 | |
110 | /* | |
111 | The 0?: constructions makes sure that the code is never executed, | |
112 | and that there is no performance hit. However, the alternative is | |
113 | compiled, and does generate a warning when used with the wrong | |
114 | pointer type. | |
115 | */ | |
116 | # define SCM_UNPACK(x) ((scm_t_bits) (0? (*(SCM*)0=(x)): x)) | |
117 | ||
118 | /* | |
119 | There is no typechecking on SCM_PACK, since all kinds of types | |
120 | (unsigned long, void*) go in SCM_PACK | |
121 | */ | |
076d6063 | 122 | # define SCM_PACK(x) ((SCM) (x)) |
702551e6 | 123 | |
c209c88e | 124 | #else |
8d3356e7 DH |
125 | /* This should be used as a fall back solution for machines on which casting |
126 | * to a pointer may lead to loss of bit information, e. g. in the three least | |
127 | * significant bits. | |
128 | */ | |
92c2555f | 129 | typedef scm_t_bits SCM; |
076d6063 | 130 | # define SCM_UNPACK(x) (x) |
702551e6 | 131 | # define SCM_PACK(x) ((SCM) (x)) |
c209c88e | 132 | #endif |
0f2d19dd | 133 | |
8d3356e7 DH |
134 | |
135 | /* SCM values can not be compared by using the operator ==. Use the following | |
136 | * macro instead, which is the equivalent of the scheme predicate 'eq?'. | |
137 | */ | |
138 | #define SCM_EQ_P(x, y) (SCM_UNPACK (x) == SCM_UNPACK (y)) | |
139 | ||
0f2d19dd | 140 | \f |
2549a709 | 141 | |
7e3b25bf DH |
142 | /* Representation of scheme objects: |
143 | * | |
144 | * Guile's type system is designed to work on systems where scm_t_bits and SCM | |
145 | * variables consist of at least 32 bits. The objects that a SCM variable can | |
146 | * represent belong to one of the following two major categories: | |
147 | * | |
148 | * - Immediates -- meaning that the SCM variable contains an entire Scheme | |
149 | * object. That means, all the object's data (including the type tagging | |
150 | * information that is required to identify the object's type) must fit into | |
151 | * 32 bits. | |
152 | * | |
153 | * - Non-immediates -- meaning that the SCM variable holds a pointer into the | |
154 | * heap of cells (see below). On systems where a pointer needs more than 32 | |
155 | * bits this means that scm_t_bits and SCM variables need to be large enough | |
156 | * to hold such pointers. In contrast to immediates, the object's data of | |
157 | * a non-immediate can consume arbitrary amounts of memory: The heap cell | |
158 | * being pointed to consists of at least two scm_t_bits variables and thus | |
159 | * can be used to hold pointers to malloc'ed memory of any size. | |
160 | * | |
161 | * The 'heap' is the memory area that is under control of Guile's garbage | |
162 | * collector. It holds 'single-cells' or 'double-cells', which consist of | |
163 | * either two or four scm_t_bits variables, respectively. It is guaranteed | |
164 | * that the address of a cell on the heap is 8-byte aligned. That is, since | |
165 | * non-immediates hold a cell address, the three least significant bits of a | |
166 | * non-immediate can be used to store additional information. The bits are | |
167 | * used to store information about the object's type and thus are called | |
168 | * tc3-bits, where tc stands for type-code. | |
169 | * | |
170 | * For a given SCM value, the distinction whether it holds an immediate or | |
171 | * non-immediate object is based on the tc3-bits (see above) of its scm_t_bits | |
172 | * equivalent: If the tc3-bits equal #b000, then the SCM value holds a | |
173 | * non-immediate, and the scm_t_bits variable's value is just the pointer to | |
174 | * the heap cell. | |
175 | * | |
176 | * Summarized, the data of a scheme object that is represented by a SCM | |
177 | * variable consists of a) the SCM variable itself, b) in case of | |
178 | * non-immediates the data of the single-cell or double-cell the SCM object | |
179 | * points to, c) in case of non-immediates potentially additional data outside | |
180 | * of the heap (like for example malloc'ed data), and d) in case of | |
181 | * non-immediates potentially additional data inside of the heap, since data | |
182 | * stored in b) and c) may hold references to other cells. | |
183 | * | |
184 | * | |
185 | * Immediates | |
186 | * | |
187 | * Operations on immediate objects can typically be processed faster than on | |
188 | * non-immediates. The reason is that the object's data can be extracted | |
189 | * directly from the SCM variable (or rather a corresponding scm_t_bits | |
190 | * variable), instead of having to perform additional memory accesses to | |
191 | * obtain the object's data from the heap. In order to get the best possible | |
192 | * performance frequently used data types should be realized as immediates. | |
193 | * This is, as has been mentioned above, only possible if the objects can be | |
194 | * represented with 32 bits (including type tagging). | |
195 | * | |
196 | * In Guile, the following data types and special objects are realized as | |
197 | * immediates: booleans, characters, small integers (see below), the empty | |
198 | * list, the end of file object, the 'unspecified' object (which is delivered | |
199 | * as a return value by functions for which the return value is unspecified), | |
200 | * a 'nil' object used in the elisp-compatibility mode and certain other | |
201 | * 'special' objects which are only used internally in Guile. | |
202 | * | |
203 | * Integers in Guile can be arbitrarily large. On the other hand, integers | |
204 | * are one of the most frequently used data types. Especially integers with | |
205 | * less than 32 bits are commonly used. Thus, internally and transparently | |
206 | * for application code guile distinguishes between small and large integers. | |
207 | * Whether an integer is a large or a small integer depends on the number of | |
208 | * bits needed to represent its value. Small integers are those which can be | |
209 | * represented as immediates. Since they don't require more than a fixed | |
210 | * number of bits for their representation, they are also known as 'fixnums'. | |
211 | * | |
212 | * The tc3-combinations #b010 and #b110 are used to represent small integers, | |
213 | * which allows to use the most significant bit of the tc3-bits to be part of | |
214 | * the integer value being represented. This means that all integers with up | |
215 | * to 30 bits (including one bit for the sign) can be represented as | |
216 | * immediates. On systems where SCM and scm_t_bits variables hold more than | |
217 | * 32 bits, the amount of bits usable for small integers will even be larger. | |
218 | * The tc3-code #b100 is shared among booleans, characters and the other | |
219 | * special objects listed above. | |
220 | * | |
221 | * | |
222 | * Non-Immediates | |
223 | * | |
224 | * All object types not mentioned above in the list of immedate objects are | |
225 | * represented as non-immediates. Whether a non-immediate scheme object is | |
226 | * represented by a single-cell or a double-cell depends on the object's type, | |
227 | * namely on the set of attributes that have to be stored with objects of that | |
228 | * type. Every non-immediate type is allowed to define its own layout and | |
229 | * interpretation of the data stored in its cell (with some restrictions, see | |
230 | * below). | |
231 | * | |
232 | * One of the design goals of guile's type system is to make it possible to | |
233 | * store a scheme pair with as little memory usage as possible. The minimum | |
234 | * amount of memory that is required to store two scheme objects (car and cdr | |
235 | * of a pair) is the amount of memory required by two scm_t_bits or SCM | |
236 | * variables. Therefore pairs in guile are stored in single-cells. | |
237 | * | |
238 | * Another design goal for the type system is to store procedure objects | |
239 | * created by lambda expresssions (closures) and class instances (goops | |
240 | * objects) with as little memory usage as possible. Closures are represented | |
241 | * by a reference to the function code and a reference to the closure's | |
242 | * environment. Class instances are represented by a reference to the | |
243 | * instance's class definition and a reference to the instance's data. Thus, | |
244 | * closures as well as class instances also can be stored in single-cells. | |
245 | * | |
246 | * Certain other non-immediate types also store their data in single-cells. | |
247 | * By design decision, the heap is split into areas for single-cells and | |
248 | * double-cells, but not into areas for single-cells-holding-pairs and areas | |
249 | * for single-cells-holding-non-pairs. Any single-cell on the heap therefore | |
250 | * can hold pairs (consisting of two scm_t_bits variables representing two | |
251 | * scheme objects - the car and cdr of the pair) and non-pairs (consisting of | |
252 | * two scm_t_bits variables that hold bit patterns as defined by the layout of | |
253 | * the corresponding object's type). | |
254 | * | |
255 | * | |
256 | * Garbage collection | |
257 | * | |
258 | * During garbage collection, unreachable cells on the heap will be freed. | |
259 | * That is, the garbage collector will detect cells which have no SCM variable | |
260 | * pointing towards them. In order to properly release all memory belonging | |
261 | * to the object to which a cell belongs, the gc needs to be able to interpret | |
262 | * the cell contents in the correct way. That means that the gc needs to be | |
263 | * able to determine the object type associated with a cell only from the cell | |
264 | * itself. | |
265 | * | |
266 | * Consequently, if the gc detects an unreachable single-cell, those two | |
267 | * scm_t_bits variables must provide enough information to determine whether | |
268 | * they belong to a pair (i. e. both scm_t_bits variables represent valid | |
269 | * scheme objects), to a closure, a class instance or if they belong to any | |
270 | * other non-immediate. Guile's type system is designed to make it possible | |
271 | * to determine a the type to which a cell belongs in the majority of cases | |
272 | * from the cell's first scm_t_bits variable. (Given a SCM variable X holding | |
273 | * a non-immediate object, the macro SCM_CELL_TYPE(X) will deliver the | |
274 | * corresponding cell's first scm_t_bits variable.) | |
275 | * | |
276 | * If the cell holds a scheme pair, then we already know that the first | |
277 | * scm_t_bits variable of the cell will hold a scheme object with one of the | |
278 | * following tc3-codes: #b000 (non-immediate), #b010 (small integer), #b100 | |
279 | * (small integer), #b110 (non-integer immediate). All these tc3-codes have | |
280 | * in common, that their least significant bit is #b0. This fact is used by | |
281 | * the garbage collector to identify cells that hold pairs. The remaining | |
282 | * tc3-codes are assigned as follows: #b001 (class instance or, more | |
283 | * precisely, a struct, of which a class instance is a special case), #b011 | |
284 | * (closure), #b101/#b111 (all remaining non-immediate types). | |
285 | * | |
286 | * | |
287 | * Summary of type codes of scheme objects (SCM variables) | |
288 | * | |
289 | * Here is a summary of tagging bits as they might occur in a scheme object. | |
290 | * The notation is as follows: tc stands for type code as before, tc<n> with n | |
291 | * being a number indicates a type code formed by the n least significant bits | |
292 | * of the SCM variables corresponding scm_t_bits value. | |
293 | * | |
294 | * Note that (as has been explained above) tc1==1 can only occur in the first | |
295 | * scm_t_bits variable of a cell belonging to a non-immediate object that is | |
296 | * not a pair. For an explanation of the tc tags with tc1==1, see the next | |
297 | * section with the summary of the type codes on the heap. | |
298 | * | |
299 | * tc1: | |
300 | * 0: For scheme objects, tc1==0 must be fulfilled. | |
301 | * (1: This can never be the case for a scheme object.) | |
302 | * | |
303 | * tc2: | |
304 | * 00: Either a non-immediate or some non-integer immediate | |
305 | * (01: This can never be the case for a scheme object.) | |
306 | * 10: Small integer | |
307 | * (11: This can never be the case for a scheme object.) | |
308 | * | |
309 | * tc3: | |
310 | * 000: a non-immediate object (pair, closure, class instance etc.) | |
311 | * (001: This can never be the case for a scheme object.) | |
312 | * 010: an even small integer (least significant bit is 0). | |
313 | * (011: This can never be the case for a scheme object.) | |
314 | * 100: Non-integer immediate | |
315 | * (101: This can never be the case for a scheme object.) | |
316 | * 110: an odd small integer (least significant bit is 1). | |
317 | * (111: This can never be the case for a scheme object.) | |
318 | * | |
319 | * The remaining bits of the non-immediate objects form the pointer to the | |
320 | * heap cell. The remaining bits of the small integers form the integer's | |
321 | * value and sign. Thus, the only scheme objects for which a further | |
322 | * subdivision is of interest are the ones with tc3==100. | |
323 | * | |
324 | * tc7, tc8, tc9 (for objects with tc3==100): | |
22f2cf2d | 325 | * 00-0000-100: \ evaluator byte codes ('short instructions'). The byte |
7e3b25bf | 326 | * ... } code interpreter can dispatch on them in one step based |
22f2cf2d DH |
327 | * 00-1100-100: / on their tc7 value. |
328 | * 00-1101-100: evaluator byte codes ('long instructions'). The byte code | |
329 | * interpreter needs to dispatch on them in two steps: The | |
330 | * first dispatch is based on the tc7-code. The second | |
331 | * dispatch is based on the actual byte code that is extracted | |
332 | * from the upper bits. | |
e17d318f DH |
333 | * x1-1110-100: evaluator byte codes ('ilocs') |
334 | * x1-1111-100: characters with x as their least significant bit | |
335 | * 10-1111-100: various constants ('flags') | |
7e3b25bf DH |
336 | * |
337 | * | |
338 | * Summary of type codes on the heap | |
339 | * | |
340 | * Here is a summary of tagging in scm_t_bits values as they might occur in | |
341 | * the first scm_t_bits variable of a heap cell. | |
342 | * | |
343 | * tc1: | |
344 | * 0: the cell belongs to a pair. | |
345 | * 1: the cell belongs to a non-pair. | |
346 | * | |
347 | * tc2: | |
348 | * 00: the cell belongs to a pair with no short integer in its car. | |
349 | * 01: the cell belongs to a non-pair (struct or some other non-immediate). | |
350 | * 10: the cell belongs to a pair with a short integer in its car. | |
351 | * 11: the cell belongs to a non-pair (closure or some other non-immediate). | |
352 | * | |
353 | * tc3: | |
354 | * 000: the cell belongs to a pair with a non-immediate in its car. | |
355 | * 001: the cell belongs to a struct | |
356 | * 010: the cell belongs to a pair with an even short integer in its car. | |
357 | * 011: the cell belongs to a closure | |
358 | * 100: the cell belongs to a pair with a non-integer immediate in its car. | |
359 | * 101: the cell belongs to some other non-immediate. | |
360 | * 110: the cell belongs to a pair with an odd short integer in its car. | |
361 | * 111: the cell belongs to some other non-immediate. | |
362 | * | |
363 | * tc7 (for tc3==1x1): | |
364 | * See below for the list of types. Note the special case of scm_tc7_vector | |
365 | * and scm_tc7_wvect: vectors and weak vectors are treated the same in many | |
366 | * cases. Thus, their tc7-codes are chosen to only differ in one bit. This | |
367 | * makes it possible to check an object at the same time for being a vector | |
368 | * or a weak vector by comparing its tc7 code with that bit masked (using | |
534c55a9 DH |
369 | * the TYP7S macro). Three more special tc7-codes are of interest: |
370 | * numbers, ports and smobs in fact each represent collections of types, | |
371 | * which are subdivided using tc16-codes. | |
7e3b25bf DH |
372 | * |
373 | * tc16 (for tc7==scm_tc7_smob): | |
374 | * The largest part of the space of smob types is not subdivided in a | |
375 | * predefined way, since smobs can be added arbitrarily by user C code. | |
376 | * However, while Guile also defines a number of smob types throughout, | |
534c55a9 DH |
377 | * there is one smob type, namely scm_tc_free_cell, for which Guile assumes |
378 | * that it is declared first and thus gets a known-in-advance tc16-code. | |
379 | * The reason of requiring a fixed tc16-code for this type is performance. | |
7e3b25bf | 380 | */ |
0f2d19dd | 381 | |
7e3b25bf DH |
382 | \f |
383 | ||
384 | /* Checking if a SCM variable holds an immediate or a non-immediate object: | |
385 | * This check can either be performed by checking for tc3==000 or tc3==00x, | |
386 | * since for a SCM variable it is known that tc1==0. */ | |
f1267706 | 387 | #define SCM_IMP(x) (6 & SCM_UNPACK (x)) |
76189127 | 388 | #define SCM_NIMP(x) (!SCM_IMP (x)) |
0f2d19dd | 389 | |
7e3b25bf DH |
390 | /* Checking if a SCM variable holds an immediate integer: See numbers.h for |
391 | * the definition of the following macros: SCM_I_FIXNUM_BIT, | |
392 | * SCM_MOST_POSITIVE_FIXNUM, SCM_INUMP, SCM_MAKINUM, SCM_INUM. */ | |
0f2d19dd | 393 | |
7e3b25bf DH |
394 | /* Checking if a SCM variable holds a pair (for historical reasons, in Guile |
395 | * also known as a cons-cell): This is done by first checking that the SCM | |
396 | * variable holds a non-immediate, and second, by checking that tc1==0 holds | |
397 | * for the SCM_CELL_TYPE of the SCM variable. */ | |
22a52da1 | 398 | #define SCM_CONSP(x) (!SCM_IMP (x) && ((1 & SCM_CELL_TYPE (x)) == 0)) |
445f675c | 399 | #define SCM_NCONSP(x) (!SCM_CONSP (x)) |
0f2d19dd | 400 | |
0f2d19dd JB |
401 | \f |
402 | ||
7e3b25bf | 403 | /* Definitions for tc2: */ |
0f2d19dd | 404 | |
6375e040 DH |
405 | #define scm_tc2_int 2 |
406 | ||
7e3b25bf DH |
407 | |
408 | /* Definitions for tc3: */ | |
409 | ||
904a077d MV |
410 | #define SCM_ITAG3(x) (7 & SCM_UNPACK (x)) |
411 | #define SCM_TYP3(x) (7 & SCM_CELL_TYPE (x)) | |
7e3b25bf | 412 | |
904a077d MV |
413 | #define scm_tc3_cons 0 |
414 | #define scm_tc3_struct 1 | |
6375e040 | 415 | #define scm_tc3_int_1 (scm_tc2_int + 0) |
c209c88e GB |
416 | #define scm_tc3_closure 3 |
417 | #define scm_tc3_imm24 4 | |
418 | #define scm_tc3_tc7_1 5 | |
6375e040 | 419 | #define scm_tc3_int_2 (scm_tc2_int + 4) |
c209c88e | 420 | #define scm_tc3_tc7_2 7 |
0f2d19dd JB |
421 | |
422 | ||
7e3b25bf | 423 | /* Definitions for tc7: */ |
0f2d19dd | 424 | |
d1ca2c64 | 425 | #define SCM_ITAG7(x) (127 & SCM_UNPACK (x)) |
445f675c DH |
426 | #define SCM_TYP7(x) (0x7f & SCM_CELL_TYPE (x)) |
427 | #define SCM_TYP7S(x) ((0x7f & ~2) & SCM_CELL_TYPE (x)) | |
0f2d19dd | 428 | |
28b06554 | 429 | #define scm_tc7_symbol 5 |
e5aca4b5 | 430 | #define scm_tc7_variable 7 |
0f2d19dd JB |
431 | |
432 | /* couple */ | |
433 | #define scm_tc7_vector 13 | |
434 | #define scm_tc7_wvect 15 | |
435 | ||
0f2d19dd | 436 | #define scm_tc7_string 21 |
534c55a9 | 437 | #define scm_tc7_number 23 |
0f2d19dd JB |
438 | |
439 | /* Many of the following should be turned | |
440 | * into structs or smobs. We need back some | |
7e3b25bf DH |
441 | * of these 7 bit tags! */ |
442 | ||
37581b11 | 443 | #define scm_tc7_pws 31 |
afe5177e | 444 | |
f546be4d | 445 | #if SCM_HAVE_ARRAYS |
afe5177e GH |
446 | #define scm_tc7_llvect 29 |
447 | #define scm_tc7_uvect 37 | |
1660782e | 448 | /* free 39 */ |
0f2d19dd JB |
449 | #define scm_tc7_fvect 45 |
450 | #define scm_tc7_dvect 47 | |
451 | #define scm_tc7_cvect 53 | |
452 | #define scm_tc7_svect 55 | |
0f2d19dd JB |
453 | #define scm_tc7_bvect 71 |
454 | #define scm_tc7_byvect 77 | |
455 | #define scm_tc7_ivect 79 | |
afe5177e GH |
456 | #endif |
457 | ||
14b18ed6 | 458 | #define scm_tc7_dsubr 61 |
afe5177e GH |
459 | #define scm_tc7_cclo 63 |
460 | #define scm_tc7_rpsubr 69 | |
0f2d19dd JB |
461 | #define scm_tc7_subr_0 85 |
462 | #define scm_tc7_subr_1 87 | |
463 | #define scm_tc7_cxr 93 | |
464 | #define scm_tc7_subr_3 95 | |
465 | #define scm_tc7_subr_2 101 | |
466 | #define scm_tc7_asubr 103 | |
467 | #define scm_tc7_subr_1o 109 | |
468 | #define scm_tc7_subr_2o 111 | |
469 | #define scm_tc7_lsubr_2 117 | |
470 | #define scm_tc7_lsubr 119 | |
471 | ||
7e3b25bf | 472 | /* There are 256 port subtypes. */ |
0f2d19dd JB |
473 | #define scm_tc7_port 125 |
474 | ||
6375e040 DH |
475 | /* There are 256 smob subtypes. [**] If you change scm_tc7_smob, you must |
476 | * also change the places it is hard coded in this file and possibly others. | |
477 | * Dirk:FIXME:: Any hard coded reference to scm_tc7_smob must be replaced by a | |
7e3b25bf | 478 | * symbolic reference. */ |
0f2d19dd JB |
479 | #define scm_tc7_smob 127 /* DO NOT CHANGE [**] */ |
480 | ||
0f2d19dd | 481 | |
7e3b25bf DH |
482 | /* Definitions for tc16: */ |
483 | #define SCM_TYP16(x) (0xffff & SCM_CELL_TYPE (x)) | |
7e3b25bf DH |
484 | #define SCM_TYP16_PREDICATE(tag, x) (!SCM_IMP (x) && SCM_TYP16 (x) == (tag)) |
485 | ||
f03314f9 | 486 | |
534c55a9 | 487 | /* Here is the first smob subtype. */ |
0f2d19dd | 488 | |
6375e040 | 489 | /* scm_tc_free_cell is the 0th smob type. We place this in free cells to tell |
7e3b25bf | 490 | * the conservative marker not to trace it. */ |
8c921d5c | 491 | #define scm_tc_free_cell (scm_tc7_smob + 0 * 256L) |
0f2d19dd | 492 | |
0f2d19dd | 493 | \f |
8ce94504 | 494 | /* {Immediate Values} |
0f2d19dd JB |
495 | */ |
496 | ||
497 | enum scm_tags | |
498 | { | |
e17d318f DH |
499 | scm_tc8_iloc = 0xf4, |
500 | scm_tc8_char = 0xfc, | |
501 | scm_tc9_flag = 0x17c | |
0f2d19dd JB |
502 | }; |
503 | ||
f1267706 MD |
504 | #define SCM_ITAG8(X) (SCM_UNPACK (X) & 0xff) |
505 | #define SCM_MAKE_ITAG8(X, TAG) SCM_PACK (((X) << 8) + TAG) | |
506 | #define SCM_ITAG8_DATA(X) (SCM_UNPACK (X) >> 8) | |
0f2d19dd | 507 | |
e17d318f DH |
508 | #define SCM_ITAG9(X) (SCM_UNPACK (X) & 0x1ff) |
509 | #define SCM_MAKE_ITAG9(X, TAG) SCM_PACK (((X) << 9) + TAG) | |
510 | #define SCM_ITAG9_DATA(X) (SCM_UNPACK (X) >> 9) | |
511 | ||
0f2d19dd JB |
512 | |
513 | \f | |
e17d318f DH |
514 | /* Flags (various constants and special objects). The indices of the flags |
515 | * must agree with the declarations in print.c: iflagnames. */ | |
0f2d19dd | 516 | |
e17d318f DH |
517 | #define SCM_IFLAGP(n) (SCM_ITAG9 (n) == scm_tc9_flag) |
518 | #define SCM_MAKIFLAG(n) SCM_MAKE_ITAG9 ((n), scm_tc9_flag) | |
519 | #define SCM_IFLAGNUM(n) (SCM_ITAG9_DATA (n)) | |
520 | ||
521 | #define SCM_BOOL_F SCM_MAKIFLAG (0) | |
522 | #define SCM_BOOL_T SCM_MAKIFLAG (1) | |
523 | #define SCM_UNDEFINED SCM_MAKIFLAG (2) | |
524 | #define SCM_EOF_VAL SCM_MAKIFLAG (3) | |
525 | #define SCM_EOL SCM_MAKIFLAG (4) | |
526 | #define SCM_UNSPECIFIED SCM_MAKIFLAG (5) | |
527 | ||
528 | /* When a variable is unbound this is marked by the SCM_UNDEFINED | |
529 | * value. The following is an unbound value which can be handled on | |
530 | * the Scheme level, i.e., it can be stored in and retrieved from a | |
531 | * Scheme variable. This value is only intended to mark an unbound | |
532 | * slot in GOOPS. It is needed now, but we should probably rewrite | |
533 | * the code which handles this value in C so that SCM_UNDEFINED can be | |
534 | * used instead. It is not ideal to let this kind of unique and | |
535 | * strange values loose on the Scheme level. */ | |
536 | #define SCM_UNBOUND SCM_MAKIFLAG (6) | |
537 | ||
538 | /* The Elisp nil value. */ | |
539 | #define SCM_ELISP_NIL SCM_MAKIFLAG (7) | |
540 | ||
541 | ||
542 | #define SCM_UNBNDP(x) (SCM_EQ_P ((x), SCM_UNDEFINED)) | |
543 | ||
544 | ||
545 | /* Short instructions ('special symbols'), long instructions ('immediate | |
546 | * symbols'). The indices of the SCM_IM_ symbols must agree with the | |
547 | * declarations in print.c: scm_isymnames. */ | |
0f2d19dd | 548 | |
f1267706 | 549 | #define SCM_MAKSPCSYM(n) SCM_PACK (((n) << 9) + ((n) << 3) + 4L) |
22f2cf2d | 550 | #define SCM_MAKISYM(n) SCM_PACK (((n) << 9) + 0x6cL) |
0f2d19dd | 551 | |
e17d318f DH |
552 | /* SCM_ISYMP tests for ISPCSYM and ISYM */ |
553 | #define SCM_ISYMP(n) ((0x187 & SCM_UNPACK (n)) == 4) | |
554 | #define SCM_ISYMNUM(n) (SCM_UNPACK (n) >> 9) | |
33b001fd | 555 | SCM_API char *scm_isymnames[]; /* defined in print.c */ |
e17d318f | 556 | #define SCM_ISYMCHARS(n) (scm_isymnames[SCM_ISYMNUM (n)]) |
0f2d19dd | 557 | |
22f2cf2d DH |
558 | /* Evaluator bytecodes (short instructions): These are uniquely identified by |
559 | * their tc7 value. This makes it possible for the evaluator to dispatch on | |
560 | * them in one step. However, the type system allows for at most 13 short | |
561 | * instructions. Consequently, the most frequent instructions are chosen to | |
e17d318f DH |
562 | * be represented as short instructions. These constants are used only in |
563 | * eval but their values have to be allocated here. */ | |
22f2cf2d | 564 | |
76189127 MD |
565 | #define SCM_IM_AND SCM_MAKSPCSYM (0) |
566 | #define SCM_IM_BEGIN SCM_MAKSPCSYM (1) | |
567 | #define SCM_IM_CASE SCM_MAKSPCSYM (2) | |
568 | #define SCM_IM_COND SCM_MAKSPCSYM (3) | |
569 | #define SCM_IM_DO SCM_MAKSPCSYM (4) | |
570 | #define SCM_IM_IF SCM_MAKSPCSYM (5) | |
571 | #define SCM_IM_LAMBDA SCM_MAKSPCSYM (6) | |
572 | #define SCM_IM_LET SCM_MAKSPCSYM (7) | |
573 | #define SCM_IM_LETSTAR SCM_MAKSPCSYM (8) | |
574 | #define SCM_IM_LETREC SCM_MAKSPCSYM (9) | |
575 | #define SCM_IM_OR SCM_MAKSPCSYM (10) | |
576 | #define SCM_IM_QUOTE SCM_MAKSPCSYM (11) | |
577 | #define SCM_IM_SET_X SCM_MAKSPCSYM (12) | |
22f2cf2d | 578 | |
e17d318f | 579 | |
22f2cf2d | 580 | /* Evaluator bytecodes (long instructions): All these share a common tc7 |
e17d318f DH |
581 | * value. Thus, the evaluator needs to dispatch on them in two steps. These |
582 | * constants are used only in eval but their values have to be allocated | |
583 | * here. */ | |
22f2cf2d DH |
584 | |
585 | /* Evaluator bytecode for (define ...) statements. We make it a long | |
e17d318f | 586 | * instruction since the evaluator will see this bytecode only for a very |
22f2cf2d DH |
587 | * limited number of times, namely once for every top-level and internal |
588 | * definition: Top-level definitions are only executed once and internal | |
589 | * definitions are converted to letrec expressions. */ | |
590 | #define SCM_IM_DEFINE SCM_MAKISYM (13) | |
591 | ||
76189127 MD |
592 | #define SCM_IM_APPLY SCM_MAKISYM (14) |
593 | #define SCM_IM_CONT SCM_MAKISYM (15) | |
e17d318f DH |
594 | #define SCM_IM_DISPATCH SCM_MAKISYM (16) |
595 | #define SCM_IM_SLOT_REF SCM_MAKISYM (17) | |
596 | #define SCM_IM_SLOT_SET_X SCM_MAKISYM (18) | |
597 | #define SCM_IM_DELAY SCM_MAKISYM (19) | |
598 | #define SCM_IM_FUTURE SCM_MAKISYM (20) | |
599 | #define SCM_IM_CALL_WITH_VALUES SCM_MAKISYM (21) | |
2a6f7afe DH |
600 | #define SCM_IM_ELSE SCM_MAKISYM (22) |
601 | #define SCM_IM_ARROW SCM_MAKISYM (23) | |
0f2d19dd | 602 | |
159500fb MD |
603 | /* Multi-language support */ |
604 | ||
2a6f7afe DH |
605 | #define SCM_IM_NIL_COND SCM_MAKISYM (24) |
606 | #define SCM_IM_BIND SCM_MAKISYM (25) | |
c96d76b8 | 607 | |
0f2d19dd JB |
608 | \f |
609 | ||
904a077d | 610 | /* Dispatching aids: |
0f2d19dd | 611 | |
904a077d MV |
612 | When switching on SCM_TYP7 of a SCM value, use these fake case |
613 | labels to catch types that use fewer than 7 bits for tagging. */ | |
0f2d19dd | 614 | |
8ce94504 | 615 | /* For cons pairs with immediate values in the CAR |
0f2d19dd JB |
616 | */ |
617 | ||
6375e040 DH |
618 | #define scm_tcs_cons_imcar \ |
619 | scm_tc2_int + 0: case scm_tc2_int + 4: case scm_tc3_imm24 + 0:\ | |
620 | case scm_tc2_int + 8: case scm_tc2_int + 12: case scm_tc3_imm24 + 8:\ | |
621 | case scm_tc2_int + 16: case scm_tc2_int + 20: case scm_tc3_imm24 + 16:\ | |
622 | case scm_tc2_int + 24: case scm_tc2_int + 28: case scm_tc3_imm24 + 24:\ | |
623 | case scm_tc2_int + 32: case scm_tc2_int + 36: case scm_tc3_imm24 + 32:\ | |
624 | case scm_tc2_int + 40: case scm_tc2_int + 44: case scm_tc3_imm24 + 40:\ | |
625 | case scm_tc2_int + 48: case scm_tc2_int + 52: case scm_tc3_imm24 + 48:\ | |
626 | case scm_tc2_int + 56: case scm_tc2_int + 60: case scm_tc3_imm24 + 56:\ | |
627 | case scm_tc2_int + 64: case scm_tc2_int + 68: case scm_tc3_imm24 + 64:\ | |
628 | case scm_tc2_int + 72: case scm_tc2_int + 76: case scm_tc3_imm24 + 72:\ | |
629 | case scm_tc2_int + 80: case scm_tc2_int + 84: case scm_tc3_imm24 + 80:\ | |
630 | case scm_tc2_int + 88: case scm_tc2_int + 92: case scm_tc3_imm24 + 88:\ | |
631 | case scm_tc2_int + 96: case scm_tc2_int + 100: case scm_tc3_imm24 + 96:\ | |
632 | case scm_tc2_int + 104: case scm_tc2_int + 108: case scm_tc3_imm24 + 104:\ | |
633 | case scm_tc2_int + 112: case scm_tc2_int + 116: case scm_tc3_imm24 + 112:\ | |
634 | case scm_tc2_int + 120: case scm_tc2_int + 124: case scm_tc3_imm24 + 120 | |
0f2d19dd JB |
635 | |
636 | /* For cons pairs with non-immediate values in the SCM_CAR | |
637 | */ | |
6375e040 DH |
638 | #define scm_tcs_cons_nimcar \ |
639 | scm_tc3_cons + 0:\ | |
640 | case scm_tc3_cons + 8:\ | |
641 | case scm_tc3_cons + 16:\ | |
642 | case scm_tc3_cons + 24:\ | |
643 | case scm_tc3_cons + 32:\ | |
644 | case scm_tc3_cons + 40:\ | |
645 | case scm_tc3_cons + 48:\ | |
646 | case scm_tc3_cons + 56:\ | |
647 | case scm_tc3_cons + 64:\ | |
648 | case scm_tc3_cons + 72:\ | |
649 | case scm_tc3_cons + 80:\ | |
650 | case scm_tc3_cons + 88:\ | |
651 | case scm_tc3_cons + 96:\ | |
652 | case scm_tc3_cons + 104:\ | |
653 | case scm_tc3_cons + 112:\ | |
654 | case scm_tc3_cons + 120 | |
0f2d19dd | 655 | |
904a077d | 656 | /* For structs |
0f2d19dd | 657 | */ |
6375e040 DH |
658 | #define scm_tcs_struct \ |
659 | scm_tc3_struct + 0:\ | |
660 | case scm_tc3_struct + 8:\ | |
661 | case scm_tc3_struct + 16:\ | |
662 | case scm_tc3_struct + 24:\ | |
663 | case scm_tc3_struct + 32:\ | |
664 | case scm_tc3_struct + 40:\ | |
665 | case scm_tc3_struct + 48:\ | |
666 | case scm_tc3_struct + 56:\ | |
667 | case scm_tc3_struct + 64:\ | |
668 | case scm_tc3_struct + 72:\ | |
669 | case scm_tc3_struct + 80:\ | |
670 | case scm_tc3_struct + 88:\ | |
671 | case scm_tc3_struct + 96:\ | |
672 | case scm_tc3_struct + 104:\ | |
673 | case scm_tc3_struct + 112:\ | |
674 | case scm_tc3_struct + 120 | |
0f2d19dd | 675 | |
904a077d MV |
676 | /* For closures |
677 | */ | |
6375e040 DH |
678 | #define scm_tcs_closures \ |
679 | scm_tc3_closure + 0:\ | |
680 | case scm_tc3_closure + 8:\ | |
681 | case scm_tc3_closure + 16:\ | |
682 | case scm_tc3_closure + 24:\ | |
683 | case scm_tc3_closure + 32:\ | |
684 | case scm_tc3_closure + 40:\ | |
685 | case scm_tc3_closure + 48:\ | |
686 | case scm_tc3_closure + 56:\ | |
687 | case scm_tc3_closure + 64:\ | |
688 | case scm_tc3_closure + 72:\ | |
689 | case scm_tc3_closure + 80:\ | |
690 | case scm_tc3_closure + 88:\ | |
691 | case scm_tc3_closure + 96:\ | |
692 | case scm_tc3_closure + 104:\ | |
693 | case scm_tc3_closure + 112:\ | |
694 | case scm_tc3_closure + 120 | |
0f2d19dd | 695 | |
904a077d MV |
696 | /* For subrs |
697 | */ | |
14b18ed6 DH |
698 | #define scm_tcs_subrs \ |
699 | scm_tc7_asubr:\ | |
700 | case scm_tc7_subr_0:\ | |
701 | case scm_tc7_subr_1:\ | |
702 | case scm_tc7_dsubr:\ | |
703 | case scm_tc7_cxr:\ | |
704 | case scm_tc7_subr_3:\ | |
705 | case scm_tc7_subr_2:\ | |
706 | case scm_tc7_rpsubr:\ | |
707 | case scm_tc7_subr_1o:\ | |
708 | case scm_tc7_subr_2o:\ | |
709 | case scm_tc7_lsubr_2:\ | |
710 | case scm_tc7_lsubr | |
0f2d19dd | 711 | |
f5f2dcff DH |
712 | \f |
713 | ||
8c494e99 | 714 | #if (SCM_ENABLE_DEPRECATED == 1) |
22a52da1 | 715 | |
228a24ef | 716 | #define SCM_CELLP(x) (((sizeof (scm_t_cell) - 1) & SCM_UNPACK (x)) == 0) |
8c494e99 | 717 | #define SCM_NCELLP(x) (!SCM_CELLP (x)) |
28b06554 | 718 | |
8c494e99 | 719 | #endif |
f5f2dcff | 720 | |
22a52da1 | 721 | #endif /* SCM_TAGS_H */ |
89e00824 ML |
722 | |
723 | /* | |
724 | Local Variables: | |
725 | c-file-style: "gnu" | |
726 | End: | |
727 | */ |