comparison src/lisp.h @ 53654:8dc805af6250

[USE_LSB_TAG]: Add definitions for Lisp_Object value manipulation macros for when tags are in the lower bits. (struct Lisp_Free) [USE_LSB_TAG]: Add padding. (DECL_ALIGN): New macro. (DEFUN): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 21 Jan 2004 04:31:21 +0000
parents 6f2b0bb10619
children c6460069583e
comparison
equal deleted inserted replaced
53653:6f2b0bb10619 53654:8dc805af6250
287 }; 287 };
288 288
289 /* For convenience, we also store the number of elements in these bits. */ 289 /* For convenience, we also store the number of elements in these bits. */
290 #define PSEUDOVECTOR_SIZE_MASK 0x1ff 290 #define PSEUDOVECTOR_SIZE_MASK 0x1ff
291 291
292 /***** Select the tagging scheme. *****/
293
294 /* First, try and define DECL_ALIGN(type,var) which declares a static
295 variable VAR of type TYPE with the added requirement that it be
296 TYPEBITS-aligned. */
297 #ifndef DECL_ALIGN
298 /* What compiler directive should we use for non-gcc compilers? -stef */
299 #if defined (__GNUC__)
300 #define DECL_ALIGN(type, var) \
301 type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var
302 #endif
303 #endif
304
305 #ifndef DECL_ALIGN
306 /* Can't USE_LSB_TAG if we can't enforce alignment of statically allocated
307 objects like lisp_subr and the special buffers in buffer.c. */
308 #undef USE_LSB_TAG
309 #endif
310
311 #ifndef USE_LSB_TAG
312 /* Just remove the alignment annotation if we don't use it. */
313 #define DECL_ALIGN(type, var) type var
314 #endif
315
316
292 /* These macros extract various sorts of values from a Lisp_Object. 317 /* These macros extract various sorts of values from a Lisp_Object.
293 For example, if tem is a Lisp_Object whose type is Lisp_Cons, 318 For example, if tem is a Lisp_Object whose type is Lisp_Cons,
294 XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons. */ 319 XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons. */
295 320
296 #ifdef NO_UNION_TYPE 321 #ifdef NO_UNION_TYPE
322
323 #ifdef USE_LSB_TAG
324
325 #define TYPEMASK ((((EMACS_INT) 1) << GCTYPEBITS) - 1)
326 #define XTYPE(a) ((enum Lisp_Type) (((EMACS_UINT) (a)) & TYPEMASK))
327 #define XINT(a) (((EMACS_INT) (a)) >> GCTYPEBITS)
328 #define XUINT(a) (((EMACS_UINT) (a)) >> GCTYPEBITS)
329 #define XSET(var, type, ptr) \
330 (eassert (XTYPE (ptr) == 0), /* Check alignment. */ \
331 (var) = ((EMACS_INT) (type)) | ((EMACS_INT) (ptr)))
332 #define make_number(N) (((EMACS_INT) (N)) << GCTYPEBITS)
333
334 /* XFASTINT and XSETFASTINT are for use when the integer is known to be
335 positive, in which case the implementation can sometimes be faster
336 depending on the tagging scheme. With USE_LSB_TAG, there's no benefit. */
337 #define XFASTINT(a) XINT (a)
338 #define XSETFASTINT(a, b) ((a) = make_number (b))
339
340 #define XPNTR(a) ((EMACS_INT) ((a) & ~TYPEMASK))
341
342 #else /* not USE_LSB_TAG */
297 343
298 #define VALMASK ((((EMACS_INT) 1) << VALBITS) - 1) 344 #define VALMASK ((((EMACS_INT) 1) << VALBITS) - 1)
299 345
300 /* One need to override this if there must be high bits set in data space 346 /* One need to override this if there must be high bits set in data space
301 (doing the result of the below & ((1 << (GCTYPE + 1)) - 1) would work 347 (doing the result of the below & ((1 << (GCTYPE + 1)) - 1) would work
330 376
331 /* Convert a C integer into a Lisp_Object integer. */ 377 /* Convert a C integer into a Lisp_Object integer. */
332 378
333 #define make_number(N) \ 379 #define make_number(N) \
334 ((((EMACS_INT) (N)) & VALMASK) | ((EMACS_INT) Lisp_Int) << VALBITS) 380 ((((EMACS_INT) (N)) & VALMASK) | ((EMACS_INT) Lisp_Int) << VALBITS)
381
382 #endif /* not USE_LSB_TAG */
335 383
336 #define EQ(x, y) ((x) == (y)) 384 #define EQ(x, y) ((x) == (y))
337 385
338 #else /* not NO_UNION_TYPE */ 386 #else /* not NO_UNION_TYPE */
339 387
1144 { 1192 {
1145 int type : 16; /* = Lisp_Misc_Free */ 1193 int type : 16; /* = Lisp_Misc_Free */
1146 unsigned gcmarkbit : 1; 1194 unsigned gcmarkbit : 1;
1147 int spacer : 15; 1195 int spacer : 15;
1148 union Lisp_Misc *chain; 1196 union Lisp_Misc *chain;
1197 #ifdef USE_LSB_TAG
1198 /* Try to make sure that sizeof(Lisp_Misc) preserves TYPEBITS-alignment.
1199 This assumes that Lisp_Marker is the largest of the alternatives and
1200 that Lisp_Intfwd has the same size as "Lisp_Free w/o padding". */
1201 char padding[((((sizeof (struct Lisp_Marker) - 1) >> GCTYPEBITS) + 1)
1202 << GCTYPEBITS) - sizeof (struct Lisp_Intfwd)];
1203 #endif
1149 }; 1204 };
1150 1205
1151 /* To get the type field of a union Lisp_Misc, use XMISCTYPE. 1206 /* To get the type field of a union Lisp_Misc, use XMISCTYPE.
1152 It uses one of these struct subtypes to get the type field. */ 1207 It uses one of these struct subtypes to get the type field. */
1153 1208
1511 #if (!defined (__STDC__) && !defined (PROTOTYPES)) \ 1566 #if (!defined (__STDC__) && !defined (PROTOTYPES)) \
1512 || defined (USE_NONANSI_DEFUN) 1567 || defined (USE_NONANSI_DEFUN)
1513 1568
1514 #define DEFUN(lname, fnname, sname, minargs, maxargs, prompt, doc) \ 1569 #define DEFUN(lname, fnname, sname, minargs, maxargs, prompt, doc) \
1515 Lisp_Object fnname (); \ 1570 Lisp_Object fnname (); \
1516 struct Lisp_Subr sname = \ 1571 DECL_ALIGN (struct Lisp_Subr, sname) = \
1517 { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ 1572 { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \
1518 fnname, minargs, maxargs, lname, prompt, 0}; \ 1573 fnname, minargs, maxargs, lname, prompt, 0}; \
1519 Lisp_Object fnname 1574 Lisp_Object fnname
1520 1575
1521 #else 1576 #else
1522 1577
1523 /* This version of DEFUN declares a function prototype with the right 1578 /* This version of DEFUN declares a function prototype with the right
1524 arguments, so we can catch errors with maxargs at compile-time. */ 1579 arguments, so we can catch errors with maxargs at compile-time. */
1525 #define DEFUN(lname, fnname, sname, minargs, maxargs, prompt, doc) \ 1580 #define DEFUN(lname, fnname, sname, minargs, maxargs, prompt, doc) \
1526 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ 1581 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
1527 struct Lisp_Subr sname = \ 1582 DECL_ALIGN (struct Lisp_Subr, sname) = \
1528 { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ 1583 { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \
1529 fnname, minargs, maxargs, lname, prompt, 0}; \ 1584 fnname, minargs, maxargs, lname, prompt, 0}; \
1530 Lisp_Object fnname 1585 Lisp_Object fnname
1531 1586
1532 /* Note that the weird token-substitution semantics of ANSI C makes 1587 /* Note that the weird token-substitution semantics of ANSI C makes