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