Mercurial > emacs
comparison src/lisp.h @ 84979:79d85dce25a5
(DECL_ALIGN, USE_LSB_TAG): Move logic to before definition of
Lisp elements such as tags.
(XHASH): New macro.
(EQ): Use it.
(SREF, SSET, STRING_COPYIN): Use SDATA.
(VOID_TO_LISP, CVOID_TO_LISP, LISP_TO_VOID, LISP_TO_CVOID): Remove.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 29 Sep 2007 20:55:05 +0000 |
parents | bc91e8a1fafc |
children | 1d35aa875508 |
comparison
equal
deleted
inserted
replaced
84978:33b7fe948502 | 84979:79d85dce25a5 |
---|---|
111 #define eassert(cond) CHECK(cond,"assertion failed: " #cond) | 111 #define eassert(cond) CHECK(cond,"assertion failed: " #cond) |
112 #else | 112 #else |
113 #define eassert(cond) CHECK(cond,"assertion failed") | 113 #define eassert(cond) CHECK(cond,"assertion failed") |
114 #endif | 114 #endif |
115 #endif /* ENABLE_CHECKING */ | 115 #endif /* ENABLE_CHECKING */ |
116 | |
117 /***** Select the tagging scheme. *****/ | |
118 /* There are basically two options that control the tagging scheme: | |
119 - NO_UNION_TYPE says that Lisp_Object should be an integer instead | |
120 of a union. | |
121 - USE_LSB_TAG means that we can assume the least 3 bits of pointers are | |
122 always 0, and we can thus use them to hold tag bits, without | |
123 restricting our addressing space. | |
124 | |
125 If USE_LSB_TAG is not set, then we use the top 3 bits for tagging, thus | |
126 restricting our possible address range. Currently USE_LSB_TAG is not | |
127 allowed together with a union. This is not due to any fundamental | |
128 technical (or political ;-) problem: nobody wrote the code to do it yet. | |
129 | |
130 USE_LSB_TAG not only requires the least 3 bits of pointers returned by | |
131 malloc to be 0 but also needs to be able to impose a mult-of-8 alignment | |
132 on the few static Lisp_Objects used: all the defsubr as well | |
133 as the two special buffers buffer_defaults and buffer_local_symbols. */ | |
134 | |
135 /* First, try and define DECL_ALIGN(type,var) which declares a static | |
136 variable VAR of type TYPE with the added requirement that it be | |
137 TYPEBITS-aligned. */ | |
138 #ifndef NO_DECL_ALIGN | |
139 # ifndef DECL_ALIGN | |
140 /* What compiler directive should we use for non-gcc compilers? -stef */ | |
141 # if defined (__GNUC__) | |
142 # define DECL_ALIGN(type, var) \ | |
143 type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var | |
144 # endif | |
145 # endif | |
146 #endif | |
147 | |
148 /* Let's USE_LSB_TAG on systems where we know malloc returns mult-of-8. */ | |
149 #if defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ || defined MAC_OSX | |
150 /* We also need to be able to specify mult-of-8 alignment on static vars. */ | |
151 # if defined DECL_ALIGN | |
152 /* We currently do not support USE_LSB_TAG with a union Lisp_Object. */ | |
153 # if defined NO_UNION_TYPE | |
154 # define USE_LSB_TAG | |
155 # endif | |
156 # endif | |
157 #endif | |
158 | |
159 /* If we cannot use 8-byte alignment, make DECL_ALIGN a no-op. */ | |
160 #ifndef DECL_ALIGN | |
161 # ifdef USE_LSB_TAG | |
162 # error "USE_LSB_TAG used without defining DECL_ALIGN" | |
163 # endif | |
164 # define DECL_ALIGN(type, var) type var | |
165 #endif | |
166 | |
116 | 167 |
117 /* Define the fundamental Lisp data structures. */ | 168 /* Define the fundamental Lisp data structures. */ |
118 | 169 |
119 /* This is the set of Lisp data types. */ | 170 /* This is the set of Lisp data types. */ |
120 | 171 |
192 typedef | 243 typedef |
193 union Lisp_Object | 244 union Lisp_Object |
194 { | 245 { |
195 /* Used for comparing two Lisp_Objects; | 246 /* Used for comparing two Lisp_Objects; |
196 also, positive integers can be accessed fast this way. */ | 247 also, positive integers can be accessed fast this way. */ |
197 EMACS_INT i; | 248 EMACS_UINT i; |
198 | 249 |
199 struct | 250 struct |
200 { | 251 { |
201 EMACS_INT val : VALBITS; | 252 EMACS_INT val : VALBITS; |
202 enum Lisp_Type type : GCTYPEBITS; | 253 enum Lisp_Type type : GCTYPEBITS; |
214 typedef | 265 typedef |
215 union Lisp_Object | 266 union Lisp_Object |
216 { | 267 { |
217 /* Used for comparing two Lisp_Objects; | 268 /* Used for comparing two Lisp_Objects; |
218 also, positive integers can be accessed fast this way. */ | 269 also, positive integers can be accessed fast this way. */ |
219 EMACS_INT i; | 270 EMACS_UINT i; |
220 | 271 |
221 struct | 272 struct |
222 { | 273 { |
223 enum Lisp_Type type : GCTYPEBITS; | 274 enum Lisp_Type type : GCTYPEBITS; |
224 EMACS_INT val : VALBITS; | 275 EMACS_INT val : VALBITS; |
245 modifying the location in question, but the casting could cover | 296 modifying the location in question, but the casting could cover |
246 other type-related bugs. */ | 297 other type-related bugs. */ |
247 #define LISP_MAKE_RVALUE(o) (o) | 298 #define LISP_MAKE_RVALUE(o) (o) |
248 #endif | 299 #endif |
249 | 300 |
250 #endif /* NO_UNION_TYPE */ | 301 #else /* NO_UNION_TYPE */ |
251 | |
252 | 302 |
253 /* If union type is not wanted, define Lisp_Object as just a number. */ | 303 /* If union type is not wanted, define Lisp_Object as just a number. */ |
254 | 304 |
255 #ifdef NO_UNION_TYPE | |
256 typedef EMACS_INT Lisp_Object; | 305 typedef EMACS_INT Lisp_Object; |
257 #define LISP_MAKE_RVALUE(o) (0+(o)) | 306 #define LISP_MAKE_RVALUE(o) (0+(o)) |
258 #endif /* NO_UNION_TYPE */ | 307 #endif /* NO_UNION_TYPE */ |
259 | 308 |
260 /* Two flags that are set during GC. On some machines, these flags | 309 /* Two flags that are set during GC. On some machines, these flags |
308 | 357 |
309 /* Number of bits to put in each character in the internal representation | 358 /* Number of bits to put in each character in the internal representation |
310 of bool vectors. This should not vary across implementations. */ | 359 of bool vectors. This should not vary across implementations. */ |
311 #define BOOL_VECTOR_BITS_PER_CHAR 8 | 360 #define BOOL_VECTOR_BITS_PER_CHAR 8 |
312 | 361 |
313 /***** Select the tagging scheme. *****/ | |
314 /* There are basically two options that control the tagging scheme: | |
315 - NO_UNION_TYPE says that Lisp_Object should be an integer instead | |
316 of a union. | |
317 - USE_LSB_TAG means that we can assume the least 3 bits of pointers are | |
318 always 0, and we can thus use them to hold tag bits, without | |
319 restricting our addressing space. | |
320 | |
321 If USE_LSB_TAG is not set, then we use the top 3 bits for tagging, thus | |
322 restricting our possible address range. Currently USE_LSB_TAG is not | |
323 allowed together with a union. This is not due to any fundamental | |
324 technical (or political ;-) problem: nobody wrote the code to do it yet. | |
325 | |
326 USE_LSB_TAG not only requires the least 3 bits of pointers returned by | |
327 malloc to be 0 but also needs to be able to impose a mult-of-8 alignment | |
328 on the few static Lisp_Objects used: all the defsubr as well | |
329 as the two special buffers buffer_defaults and buffer_local_symbols. */ | |
330 | |
331 /* First, try and define DECL_ALIGN(type,var) which declares a static | |
332 variable VAR of type TYPE with the added requirement that it be | |
333 TYPEBITS-aligned. */ | |
334 #ifndef NO_DECL_ALIGN | |
335 # ifndef DECL_ALIGN | |
336 /* What compiler directive should we use for non-gcc compilers? -stef */ | |
337 # if defined (__GNUC__) | |
338 # define DECL_ALIGN(type, var) \ | |
339 type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var | |
340 # endif | |
341 # endif | |
342 #endif | |
343 | |
344 /* Let's USE_LSB_TAG on systems where we know malloc returns mult-of-8. */ | |
345 #if defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ || defined MAC_OSX | |
346 /* We also need to be able to specify mult-of-8 alignment on static vars. */ | |
347 # if defined DECL_ALIGN | |
348 /* We currently do not support USE_LSB_TAG with a union Lisp_Object. */ | |
349 # if defined NO_UNION_TYPE | |
350 # define USE_LSB_TAG | |
351 # endif | |
352 # endif | |
353 #endif | |
354 | |
355 /* If we cannot use 8-byte alignment, make DECL_ALIGN a no-op. */ | |
356 #ifndef DECL_ALIGN | |
357 # ifdef USE_LSB_TAG | |
358 # error "USE_LSB_TAG used without defining DECL_ALIGN" | |
359 # endif | |
360 # define DECL_ALIGN(type, var) type var | |
361 #endif | |
362 | |
363 | |
364 /* These macros extract various sorts of values from a Lisp_Object. | 362 /* These macros extract various sorts of values from a Lisp_Object. |
365 For example, if tem is a Lisp_Object whose type is Lisp_Cons, | 363 For example, if tem is a Lisp_Object whose type is Lisp_Cons, |
366 XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons. */ | 364 XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons. */ |
367 | 365 |
368 #ifdef NO_UNION_TYPE | 366 #ifdef NO_UNION_TYPE |
367 | |
368 /* Return a perfect hash of the Lisp_Object representation. */ | |
369 #define XHASH(a) (a) | |
369 | 370 |
370 #ifdef USE_LSB_TAG | 371 #ifdef USE_LSB_TAG |
371 | 372 |
372 #define TYPEMASK ((((EMACS_INT) 1) << GCTYPEBITS) - 1) | 373 #define TYPEMASK ((((EMACS_INT) 1) << GCTYPEBITS) - 1) |
373 #define XTYPE(a) ((enum Lisp_Type) (((EMACS_UINT) (a)) & TYPEMASK)) | 374 #define XTYPE(a) ((enum Lisp_Type) (((EMACS_UINT) (a)) & TYPEMASK)) |
426 #define make_number(N) \ | 427 #define make_number(N) \ |
427 ((((EMACS_INT) (N)) & VALMASK) | ((EMACS_INT) Lisp_Int) << VALBITS) | 428 ((((EMACS_INT) (N)) & VALMASK) | ((EMACS_INT) Lisp_Int) << VALBITS) |
428 | 429 |
429 #endif /* not USE_LSB_TAG */ | 430 #endif /* not USE_LSB_TAG */ |
430 | 431 |
431 #define EQ(x, y) ((x) == (y)) | |
432 | |
433 #else /* not NO_UNION_TYPE */ | 432 #else /* not NO_UNION_TYPE */ |
433 | |
434 #define XHASH(a) ((a).i) | |
434 | 435 |
435 #define XTYPE(a) ((enum Lisp_Type) (a).u.type) | 436 #define XTYPE(a) ((enum Lisp_Type) (a).u.type) |
436 | 437 |
437 /* For integers known to be positive, XFASTINT provides fast retrieval | 438 /* For integers known to be positive, XFASTINT provides fast retrieval |
438 and XSETFASTINT provides fast storage. This takes advantage of the | 439 and XSETFASTINT provides fast storage. This takes advantage of the |
458 (__extension__ ({ Lisp_Object _l; _l.s.val = (N); _l.s.type = Lisp_Int; _l; })) | 459 (__extension__ ({ Lisp_Object _l; _l.s.val = (N); _l.s.type = Lisp_Int; _l; })) |
459 #else | 460 #else |
460 extern Lisp_Object make_number P_ ((EMACS_INT)); | 461 extern Lisp_Object make_number P_ ((EMACS_INT)); |
461 #endif | 462 #endif |
462 | 463 |
463 #define EQ(x, y) ((x).i == (y).i) | |
464 | |
465 #endif /* NO_UNION_TYPE */ | 464 #endif /* NO_UNION_TYPE */ |
465 | |
466 #define EQ(x, y) (XHASH (x) == XHASH (y)) | |
466 | 467 |
467 /* During garbage collection, XGCTYPE must be used for extracting types | 468 /* During garbage collection, XGCTYPE must be used for extracting types |
468 so that the mark bit is ignored. XMARKBIT accesses the markbit. | 469 so that the mark bit is ignored. XMARKBIT accesses the markbit. |
469 Markbits are used only in particular slots of particular structure types. | 470 Markbits are used only in particular slots of particular structure types. |
470 Other markbits are always zero. | 471 Other markbits are always zero. |
581 #define ASET(ARRAY, IDX, VAL) (AREF ((ARRAY), (IDX)) = (VAL)) | 582 #define ASET(ARRAY, IDX, VAL) (AREF ((ARRAY), (IDX)) = (VAL)) |
582 #define ASIZE(ARRAY) XVECTOR ((ARRAY))->size | 583 #define ASIZE(ARRAY) XVECTOR ((ARRAY))->size |
583 | 584 |
584 /* Convenience macros for dealing with Lisp strings. */ | 585 /* Convenience macros for dealing with Lisp strings. */ |
585 | 586 |
586 #define SREF(string, index) (XSTRING (string)->data[index] + 0) | |
587 #define SSET(string, index, new) (XSTRING (string)->data[index] = (new)) | |
588 #define SDATA(string) (XSTRING (string)->data + 0) | 587 #define SDATA(string) (XSTRING (string)->data + 0) |
588 #define SREF(string, index) (SDATA (string)[index] + 0) | |
589 #define SSET(string, index, new) (SDATA (string)[index] = (new)) | |
589 #define SCHARS(string) (XSTRING (string)->size + 0) | 590 #define SCHARS(string) (XSTRING (string)->size + 0) |
590 #define SBYTES(string) (STRING_BYTES (XSTRING (string)) + 0) | 591 #define SBYTES(string) (STRING_BYTES (XSTRING (string)) + 0) |
591 | 592 |
592 #define STRING_SET_CHARS(string, newsize) \ | 593 #define STRING_SET_CHARS(string, newsize) \ |
593 (XSTRING (string)->size = (newsize)) | 594 (XSTRING (string)->size = (newsize)) |
594 | 595 |
595 #define STRING_COPYIN(string, index, new, count) \ | 596 #define STRING_COPYIN(string, index, new, count) \ |
596 bcopy (new, XSTRING (string)->data + index, count) | 597 bcopy (new, SDATA (string) + index, count) |
597 | 598 |
598 /* Type checking. */ | 599 /* Type checking. */ |
599 | 600 |
600 #define CHECK_TYPE(ok, Qxxxp, x) \ | 601 #define CHECK_TYPE(ok, Qxxxp, x) \ |
601 do { if (!(ok)) wrong_type_argument (Qxxxp, (x)); } while (0) | 602 do { if (!(ok)) wrong_type_argument (Qxxxp, (x)); } while (0) |
1125 unsigned gcmarkbit : 1; | 1126 unsigned gcmarkbit : 1; |
1126 int spacer : 14; | 1127 int spacer : 14; |
1127 /* 1 means normal insertion at the marker's position | 1128 /* 1 means normal insertion at the marker's position |
1128 leaves the marker after the inserted text. */ | 1129 leaves the marker after the inserted text. */ |
1129 unsigned int insertion_type : 1; | 1130 unsigned int insertion_type : 1; |
1130 /* This is the buffer that the marker points into, | 1131 /* This is the buffer that the marker points into, or 0 if it points nowhere. |
1131 or 0 if it points nowhere. */ | 1132 Note: a chain of markers can contain markers pointing into different |
1133 buffers (the chain is per buffer_text rather than per buffer, so it's | |
1134 shared between indirect buffers). */ | |
1135 /* This is used for (other than NULL-checking): | |
1136 - Fmarker_buffer | |
1137 - Fset_marker: check eq(oldbuf, newbuf) to avoid unchain+rechain. | |
1138 - unchain_marker: to find the list from which to unchain. | |
1139 - Fkill_buffer: to unchain the markers of current indirect buffer. | |
1140 */ | |
1132 struct buffer *buffer; | 1141 struct buffer *buffer; |
1133 | 1142 |
1134 /* The remaining fields are meaningless in a marker that | 1143 /* The remaining fields are meaningless in a marker that |
1135 does not point anywhere. */ | 1144 does not point anywhere. */ |
1136 | 1145 |
1381 Thers are 6 modifiers, each consumes 2 chars. | 1390 Thers are 6 modifiers, each consumes 2 chars. |
1382 The octal form of a character code consumes | 1391 The octal form of a character code consumes |
1383 (1 + CHARACTERBITS / 3 + 1) chars (including backslash at the head). | 1392 (1 + CHARACTERBITS / 3 + 1) chars (including backslash at the head). |
1384 We need one more byte for string terminator `\0'. */ | 1393 We need one more byte for string terminator `\0'. */ |
1385 #define KEY_DESCRIPTION_SIZE ((2 * 6) + 1 + (CHARACTERBITS / 3) + 1 + 1) | 1394 #define KEY_DESCRIPTION_SIZE ((2 * 6) + 1 + (CHARACTERBITS / 3) + 1 + 1) |
1386 | |
1387 #ifdef USE_X_TOOLKIT | |
1388 #ifdef NO_UNION_TYPE | |
1389 /* Use this for turning a (void *) into a Lisp_Object, as when the | |
1390 Lisp_Object is passed into a toolkit callback function. */ | |
1391 #define VOID_TO_LISP(larg,varg) \ | |
1392 do { ((larg) = ((Lisp_Object) (varg))); } while (0) | |
1393 #define CVOID_TO_LISP VOID_TO_LISP | |
1394 | |
1395 /* Use this for turning a Lisp_Object into a (void *), as when the | |
1396 Lisp_Object is passed into a toolkit callback function. */ | |
1397 #define LISP_TO_VOID(larg) ((void *) (larg)) | |
1398 #define LISP_TO_CVOID(varg) ((const void *) (larg)) | |
1399 | |
1400 #else /* not NO_UNION_TYPE */ | |
1401 /* Use this for turning a (void *) into a Lisp_Object, as when the | |
1402 Lisp_Object is passed into a toolkit callback function. */ | |
1403 #define VOID_TO_LISP(larg,varg) \ | |
1404 do { ((larg).v = (void *) (varg)); } while (0) | |
1405 #define CVOID_TO_LISP(larg,varg) \ | |
1406 do { ((larg).cv = (const void *) (varg)); } while (0) | |
1407 | |
1408 /* Use this for turning a Lisp_Object into a (void *), as when the | |
1409 Lisp_Object is passed into a toolkit callback function. */ | |
1410 #define LISP_TO_VOID(larg) ((larg).v) | |
1411 #define LISP_TO_CVOID(larg) ((larg).cv) | |
1412 #endif /* not NO_UNION_TYPE */ | |
1413 #endif /* USE_X_TOOLKIT */ | |
1414 | 1395 |
1415 | 1396 |
1416 /* The glyph datatype, used to represent characters on the display. */ | 1397 /* The glyph datatype, used to represent characters on the display. */ |
1417 | 1398 |
1418 /* Glyph code to use as an index to the glyph table. If it is out of | 1399 /* Glyph code to use as an index to the glyph table. If it is out of |