1 /* Fundamental definitions for XEmacs Lisp interpreter -- non-union objects.
2 Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of XEmacs.
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
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
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. */
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 */
26 Format of a non-union-type Lisp Object
29 bit 10987654321098765432109876543210
30 --------------------------------
31 VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTT
33 Integers are treated specially, and look like this:
36 bit 10987654321098765432109876543210
37 --------------------------------
38 VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVT
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".
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.
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.
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
60 There are no mark bits in the Lisp_Object itself (there used to be).
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.
66 Here is a brief description of the following macros:
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
75 EQ Non-zero if two Lisp_Objects are identical, not merely equal. */
78 typedef EMACS_INT Lisp_Object;
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) (((x) << INT_GCBITS) | Lisp_Type_Int_Bit))
83 #define make_char(x) ((Lisp_Object) (((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 */
88 INLINE_HEADER int XCHARVAL (Emchar chr);
92 int code = (EMACS_UINT)(chr) >> GCBITS;
94 if (code & 0x20000000)
95 return code | 0x40000000;
100 #define XCHARVAL(x) ((EMACS_UINT)(x) >> GCBITS)
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))
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)))
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))
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)