XEmacs 21.2.28 "Hermes".
[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.
42
43      The object is obtained by masking off the type and mark 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.  By
46      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
54      by the implementation to be 00, just like the least
55      significant bits of word-aligned struct pointers on 32-bit
56      hardware.  Because of this, Lisp_Object pointers don't have
57      to be masked and are full-sized.
58
59  There are no mark bits.
60  Integers and characters don't need to be marked.  All other types
61  are lrecord-based, which means they get marked by incrementing
62  their ->implementation pointer.
63
64  Here is a brief description of the following macros:
65
66  XTYPE     The type bits of a Lisp_Object
67  XPNTRVAL  The value bits of a Lisp_Object storing a pointer
68  XCHARVAL  The value bits of a Lisp_Object storing a Emchar
69  XREALINT  The value bits of a Lisp_Object storing an integer, signed
70  XUINT     The value bits of a Lisp_Object storing an integer, unsigned
71  INTP      Non-zero if this Lisp_Object an integer?
72  Qzero     Lisp Integer 0
73  EQ        Non-zero if two Lisp_Objects are identical */
74
75
76 typedef EMACS_INT Lisp_Object;
77
78 #define Lisp_Type_Int_Bit (Lisp_Type_Int_Even & Lisp_Type_Int_Odd)
79 #define make_obj(vartype, x) ((Lisp_Object) (x))
80 #define make_int(x) ((Lisp_Object) (((x) << INT_GCBITS) | Lisp_Type_Int_Bit))
81 #define make_char(x) ((Lisp_Object) (((x) << GCBITS) | Lisp_Type_Char))
82 #define VALMASK (((1UL << VALBITS) - 1UL) << GCTYPEBITS)
83 #define XTYPE(x) ((enum Lisp_Type) (((EMACS_UINT)(x)) & ~VALMASK))
84 #define XPNTRVAL(x) (x) /* This depends on Lisp_Type_Record == 0 */
85 #define XCHARVAL(x) ((x) >> GCBITS)
86 #define XREALINT(x) ((x) >> INT_GCBITS)
87 #define XUINT(x) ((EMACS_UINT)(x) >> INT_GCBITS)
88 #define INTP(x) ((EMACS_UINT)(x) & Lisp_Type_Int_Bit)
89 #define INT_PLUS(x,y)  ((x)+(y)-Lisp_Type_Int_Bit)
90 #define INT_MINUS(x,y) ((x)-(y)+Lisp_Type_Int_Bit)
91 #define INT_PLUS1(x)   INT_PLUS  (x, make_int (1))
92 #define INT_MINUS1(x)  INT_MINUS (x, make_int (1))
93
94 #define Qzero make_int (0)
95 #define Qnull_pointer ((Lisp_Object) 0)
96 #define EQ(x,y) ((x) == (y))
97 #define XSETINT(var,  value) ((void) ((var) = make_int (value)))
98 #define XSETCHAR(var, value) ((void) ((var) = make_char (value)))
99 #define XSETOBJ(var, vartype, value) ((void) ((var) = make_obj (vartype, value)))
100
101 /* Convert between a (void *) and a Lisp_Object, as when the
102    Lisp_Object is passed to a toolkit callback function */
103 #define VOID_TO_LISP(larg,varg) ((void) ((larg) = ((Lisp_Object) (varg))))
104 #define CVOID_TO_LISP VOID_TO_LISP
105 #define LISP_TO_VOID(larg) ((void *) (larg))
106 #define LISP_TO_CVOID(varg) ((CONST void *) (larg))
107
108 /* Convert a Lisp_Object into something that can't be used as an
109    lvalue.  Useful for type-checking. */
110 #define NON_LVALUE(larg) ((larg) + 0)