Partially sync files.el from XEmacs 21.5 for wildcard support.
[sxemacs] / src / lisp-disunion.h
1 /* Fundamental definitions for XEmacs Lisp interpreter -- non-union objects.
2    Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
3
4 This file is part of SXEmacs
5
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
18
19
20 /* Synched up with: FSF 19.30.  Split out from lisp.h. */
21 /* This file has diverged greatly from FSF Emacs.  Syncing is no
22    longer desirable or possible */
23
24 /*
25  Format of a non-union-type Lisp Object
26
27              3         2         1         0
28        bit  10987654321098765432109876543210
29             --------------------------------
30             VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTT
31
32    Integers are treated specially, and look like this:
33
34              3         2         1         0
35        bit  10987654321098765432109876543210
36             --------------------------------
37             VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVT
38
39  For integral Lisp types, i.e. integers and characters, the value
40  bits are the Lisp object.  Some people call such Lisp_Objects "immediate".
41
42  The object is obtained by masking off the type bits.
43      Bit 1 is used as a value bit by splitting the Lisp integer type
44  into two subtypes, Lisp_Type_Int_Even and Lisp_Type_Int_Odd.
45  By this trickery we get 31 bits for integers instead of 30.
46
47  For non-integral types, the value bits of a Lisp_Object contain
48  a pointer to a structure containing the object.  The pointer is
49  obtained by masking off the type and mark bits.
50
51      All pointer-based types are coalesced under a single type called
52  Lisp_Type_Record.  The type bits for this type are required by the
53  implementation to be 00, just like the least significant bits of
54  word-aligned struct pointers on 32-bit hardware.  This requires that
55  all structs implementing Lisp_Objects have an alignment of at least 4
56  bytes.  Because of this, Lisp_Object pointers don't have to be masked
57  and are full-sized.
58
59  There are no mark bits in the Lisp_Object itself (there used to be).
60
61  Integers and characters don't need to be marked.  All other types are
62  lrecord-based, which means they get marked by setting the mark bit in
63  the struct lrecord_header.
64
65  Here is a brief description of the following macros:
66
67  XTYPE     The type bits of a Lisp_Object
68  XPNTRVAL  The value bits of a Lisp_Object storing a pointer
69  XCHARVAL  The value bits of a Lisp_Object storing a Emchar
70  XREALINT  The value bits of a Lisp_Object storing an integer, signed
71  XUINT     The value bits of a Lisp_Object storing an integer, unsigned
72  INTP      Non-zero if this Lisp_Object is an integer
73  Qzero     Lisp Integer 0
74  EQ        Non-zero if two Lisp_Objects are identical, not merely equal. */
75
76 typedef EMACS_INT Lisp_Object;
77
78 #define Lisp_Type_Int_Bit (Lisp_Type_Int_Even & Lisp_Type_Int_Odd)
79 extern_inline Lisp_Object
80 wrap_object(void *ptr)
81         __attribute__((always_inline));
82 extern_inline Lisp_Object
83 wrap_object(void *ptr)
84 {
85         return (Lisp_Object)ptr;
86 }
87 #define make_int(x) ((Lisp_Object) (((x) << INT_GCBITS) | Lisp_Type_Int_Bit))
88 #define make_char(x) ((Lisp_Object) (((x) << GCBITS) | Lisp_Type_Char))
89 #define VALMASK (((1UL << VALBITS) - 1UL) << GCTYPEBITS)
90 #define XTYPE(x) ((enum Lisp_Type) (((EMACS_UINT)(x)) & ~VALMASK))
91 #define XPNTRVAL(x) (x)         /* This depends on Lisp_Type_Record == 0 */
92 #define XCHARVAL(x) ((x) >> GCBITS)
93 #define XREALINT(x) ((x) >> INT_GCBITS)
94 #define XUINT(x) ((EMACS_UINT)(x) >> INT_GCBITS)
95 #define INTP(x) ((EMACS_UINT)(x) & Lisp_Type_Int_Bit)
96 #define INT_PLUS(x,y)  ((x)+(y)-Lisp_Type_Int_Bit)
97 #define INT_MINUS(x,y) ((x)-(y)+Lisp_Type_Int_Bit)
98 #define INT_PLUS1(x)   INT_PLUS  (x, make_int (1))
99 #define INT_MINUS1(x)  INT_MINUS (x, make_int (1))
100
101 #define Qnull_pointer ((Lisp_Object) 0)
102 #define EQ(x,y) ((x) == (y))
103 #define XSETINT(var, value) ((void) ((var) = make_int (value)))
104 #define XSETCHAR(var, value) ((void) ((var) = make_char (value)))
105 #define XSETOBJ(var, value) ((void) ((var) = wrap_object (value)))
106
107 /* Convert between a (void *) and a Lisp_Object, as when the
108    Lisp_Object is passed to a toolkit callback function */
109 #define VOID_TO_LISP(larg,varg) ((void) ((larg) = ((Lisp_Object) (varg))))
110 #define CVOID_TO_LISP VOID_TO_LISP
111 #define LISP_TO_VOID(larg) ((void *) (larg))
112 #define LISP_TO_CVOID(larg) ((const void *) (larg))
113
114 /* Convert a Lisp_Object into something that can't be used as an
115    lvalue.  Useful for type-checking. */
116 #define NON_LVALUE(larg) ((larg) + 0)