428
+ − 1 /* Fundamental definitions for XEmacs Lisp interpreter -- union objects.
+ − 2 Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994
+ − 3 Free Software Foundation, Inc.
5013
+ − 4 Copyright (C) 2002, 2005, 2010 Ben Wing.
428
+ − 5
+ − 6 This file is part of XEmacs.
+ − 7
+ − 8 XEmacs is free software; you can redistribute it and/or modify it
+ − 9 under the terms of the GNU General Public License as published by the
+ − 10 Free Software Foundation; either version 2, or (at your option) any
+ − 11 later version.
+ − 12
+ − 13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
+ − 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ − 15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ − 16 for more details.
+ − 17
+ − 18 You should have received a copy of the GNU General Public License
+ − 19 along with XEmacs; see the file COPYING. If not, write to
+ − 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 21 Boston, MA 02111-1307, USA. */
+ − 22
+ − 23 /* Divergent from FSF. */
+ − 24
+ − 25 /* Definition of Lisp_Object type as a union.
+ − 26 The declaration order of the objects within the struct members
+ − 27 of the union is dependent on ENDIAN-ness.
+ − 28 See lisp-disunion.h for more details. */
+ − 29
+ − 30 typedef
+ − 31 union Lisp_Object
+ − 32 {
+ − 33 /* if non-valbits are at lower addresses */
442
+ − 34 #ifdef WORDS_BIGENDIAN
428
+ − 35 struct
+ − 36 {
+ − 37 EMACS_UINT val : VALBITS;
+ − 38 enum_field (Lisp_Type) type : GCTYPEBITS;
+ − 39 } gu;
+ − 40
+ − 41 struct
+ − 42 {
+ − 43 signed EMACS_INT val : INT_VALBITS;
+ − 44 unsigned int bits : INT_GCBITS;
+ − 45 } s;
+ − 46
+ − 47 struct
+ − 48 {
+ − 49 EMACS_UINT val : INT_VALBITS;
+ − 50 unsigned int bits : INT_GCBITS;
+ − 51 } u;
+ − 52 #else /* non-valbits are at higher addresses */
+ − 53 struct
+ − 54 {
+ − 55 enum_field (Lisp_Type) type : GCTYPEBITS;
+ − 56 EMACS_UINT val : VALBITS;
+ − 57 } gu;
+ − 58
+ − 59 struct
+ − 60 {
+ − 61 unsigned int bits : INT_GCBITS;
+ − 62 signed EMACS_INT val : INT_VALBITS;
+ − 63 } s;
+ − 64
+ − 65 struct
+ − 66 {
+ − 67 unsigned int bits : INT_GCBITS;
+ − 68 EMACS_UINT val : INT_VALBITS;
+ − 69 } u;
+ − 70
+ − 71 #endif /* non-valbits are at higher addresses */
+ − 72
+ − 73 EMACS_UINT ui;
+ − 74 signed EMACS_INT i;
+ − 75
3025
+ − 76 /* This was formerly declared `void *v' etc. but that causes
428
+ − 77 GCC to accept any (yes, any) pointer as the argument of
+ − 78 a function declared to accept a Lisp_Object. */
+ − 79 struct nosuchstruct *v;
+ − 80 }
+ − 81 Lisp_Object;
+ − 82
3455
+ − 83 #define XCHARVAL(x) ((EMACS_INT)(x).gu.val)
826
+ − 84 #define XPNTRVAL(x) ((x).ui)
+ − 85
3455
+ − 86 #define XREALINT(x) ((EMACS_INT)(x).s.val)
+ − 87 #define XUINT(x) ((EMACS_UINT)(x).u.val)
826
+ − 88 #define XTYPE(x) ((x).gu.type)
+ − 89 #define EQ(x,y) ((x).v == (y).v)
428
+ − 90
826
+ − 91 DECLARE_INLINE_HEADER (
+ − 92 Lisp_Object
+ − 93 make_int_verify (EMACS_INT val)
+ − 94 )
+ − 95 {
+ − 96 Lisp_Object obj;
+ − 97 obj.s.bits = 1;
+ − 98 obj.s.val = val;
+ − 99 type_checking_assert (XREALINT (obj) == val);
+ − 100 return obj;
+ − 101 }
+ − 102
+ − 103 DECLARE_INLINE_HEADER (
+ − 104 Lisp_Object
428
+ − 105 make_int (EMACS_INT val)
826
+ − 106 )
428
+ − 107 {
+ − 108 Lisp_Object obj;
793
+ − 109 obj.s.bits = 1;
+ − 110 obj.s.val = val;
428
+ − 111 return obj;
+ − 112 }
+ − 113
826
+ − 114 DECLARE_INLINE_HEADER (
+ − 115 Lisp_Object
867
+ − 116 make_char_1 (Ichar val)
826
+ − 117 )
428
+ − 118 {
+ − 119 Lisp_Object obj;
793
+ − 120 obj.gu.type = Lisp_Type_Char;
+ − 121 obj.gu.val = val;
442
+ − 122 return obj;
+ − 123 }
+ − 124
826
+ − 125 DECLARE_INLINE_HEADER (
+ − 126 Lisp_Object
800
+ − 127 wrap_pointer_1 (const void *ptr)
826
+ − 128 )
442
+ − 129 {
+ − 130 Lisp_Object obj;
793
+ − 131 obj.ui = (EMACS_UINT) ptr;
428
+ − 132 return obj;
+ − 133 }
+ − 134
1632
+ − 135 extern MODULE_API Lisp_Object Qnull_pointer, Qzero;
428
+ − 136
+ − 137 #define INTP(x) ((x).s.bits)
+ − 138 #define INT_PLUS(x,y) make_int (XINT (x) + XINT (y))
+ − 139 #define INT_MINUS(x,y) make_int (XINT (x) - XINT (y))
+ − 140 #define INT_PLUS1(x) make_int (XINT (x) + 1)
+ − 141 #define INT_MINUS1(x) make_int (XINT (x) - 1)
+ − 142
853
+ − 143 /* WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ − 144
5013
+ − 145 You can only GET_LISP_FROM_VOID something that had previously been
+ − 146 STORE_LISP_IN_VOID'd. If you want to go the other way, use
+ − 147 STORE_VOID_IN_LISP and GET_VOID_FROM_LISP, or use make_opaque_ptr(). */
853
+ − 148
5013
+ − 149 /* Convert a Lisp object to a void * pointer, as when it needs to be passed
+ − 150 to a toolkit callback function */
+ − 151 #define STORE_LISP_IN_VOID(larg) ((void *) ((larg).v))
+ − 152
+ − 153 /* Convert a void * pointer back into a Lisp object, assuming that the
+ − 154 pointer was generated by STORE_LISP_IN_VOID. */
826
+ − 155 DECLARE_INLINE_HEADER (
+ − 156 Lisp_Object
5013
+ − 157 GET_LISP_FROM_VOID (const void *arg)
826
+ − 158 )
+ − 159 {
+ − 160 Lisp_Object larg;
+ − 161 larg.v = (struct nosuchstruct *) arg;
+ − 162 return larg;
+ − 163 }
+ − 164
428
+ − 165 /* Convert a Lisp_Object into something that can't be used as an
+ − 166 lvalue. Useful for type-checking. */
+ − 167 #if (__GNUC__ > 1)
+ − 168 #define NON_LVALUE(larg) ({ (larg); })
+ − 169 #else
+ − 170 /* Well, you can't really do it without using a function call, and
+ − 171 there's no real point in that; no-union-type is the rule, and that
+ − 172 will catch errors. */
+ − 173 #define NON_LVALUE(larg) (larg)
+ − 174 #endif