1 /* Fundamental definitions for XEmacs Lisp interpreter -- union objects.
2 Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of XEmacs.
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Divergent from FSF. */
24 /* Definition of Lisp_Object type as a union.
25 The declaration order of the objects within the struct members
26 of the union is dependent on ENDIAN-ness.
27 See lisp-disunion.h for more details. */
32 /* if non-valbits are at lower addresses */
33 #ifdef WORDS_BIGENDIAN
36 EMACS_UINT val : VALBITS;
37 enum_field (Lisp_Type) type : GCTYPEBITS;
42 signed EMACS_INT val : INT_VALBITS;
43 unsigned int bits : INT_GCBITS;
48 EMACS_UINT val : INT_VALBITS;
49 unsigned int bits : INT_GCBITS;
51 #else /* non-valbits are at higher addresses */
54 enum_field (Lisp_Type) type : GCTYPEBITS;
55 EMACS_UINT val : VALBITS;
60 unsigned int bits : INT_GCBITS;
61 signed EMACS_INT val : INT_VALBITS;
66 unsigned int bits : INT_GCBITS;
67 EMACS_UINT val : INT_VALBITS;
70 #endif /* non-valbits are at higher addresses */
75 /* This was formerly declared 'void *v' etc. but that causes
76 GCC to accept any (yes, any) pointer as the argument of
77 a function declared to accept a Lisp_Object. */
78 struct nosuchstruct *v;
79 const struct nosuchstruct *cv;
83 #define XCHARVAL(x) ((x).gu.val)
85 # define XSETINT(var, value) do { \
86 EMACS_INT xset_value = (value); \
87 Lisp_Object *xset_var = &(var); \
88 xset_var->s.bits = 1; \
89 xset_var->s.val = xset_value; \
91 # define XSETCHAR(var, value) do { \
92 Emchar xset_value = (value); \
93 Lisp_Object *xset_var = &(var); \
94 xset_var->gu.type = Lisp_Type_Char; \
95 xset_var->gu.val = xset_value; \
97 # define XSETOBJ(var, value) do { \
98 EMACS_UINT xset_value = (EMACS_UINT) (value); \
99 (var).ui = xset_value; \
101 # define XPNTRVAL(x) ((x).ui)
103 INLINE_HEADER Lisp_Object make_int (EMACS_INT val);
104 INLINE_HEADER Lisp_Object
105 make_int (EMACS_INT val)
112 INLINE_HEADER Lisp_Object make_char (Emchar val);
113 INLINE_HEADER Lisp_Object
114 make_char (Emchar val)
121 INLINE_HEADER Lisp_Object wrap_object (void *ptr);
122 INLINE_HEADER Lisp_Object
123 wrap_object (void *ptr)
130 extern Lisp_Object Qnull_pointer, Qzero;
132 #define XREALINT(x) ((x).s.val)
133 #define XUINT(x) ((x).u.val)
134 #define XTYPE(x) ((x).gu.type)
135 #define EQ(x,y) ((x).v == (y).v)
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)
143 /* Convert between a (void *) and a Lisp_Object, as when the
144 Lisp_Object is passed to a toolkit callback function */
145 #define VOID_TO_LISP(larg,varg) \
146 ((void) ((larg).v = (struct nosuchstruct *) (varg)))
147 #define CVOID_TO_LISP(larg,varg) \
148 ((void) ((larg).cv = (const struct nosuchstruct *) (varg)))
149 #define LISP_TO_VOID(larg) ((void *) ((larg).v))
150 #define LISP_TO_CVOID(larg) ((const void *) ((larg).cv))
152 /* Convert a Lisp_Object into something that can't be used as an
153 lvalue. Useful for type-checking. */
155 #define NON_LVALUE(larg) ({ (larg); })
157 /* Well, you can't really do it without using a function call, and
158 there's no real point in that; no-union-type is the rule, and that
159 will catch errors. */
160 #define NON_LVALUE(larg) (larg)