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