428
|
1 /* Fundamental definitions for XEmacs Lisp interpreter -- union objects.
|
|
2 Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994
|
|
3 Free Software Foundation, Inc.
|
800
|
4 Copyright (C) 2002 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
|
|
76 /* This was formerly declared 'void *v' etc. but that causes
|
|
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;
|
442
|
80 const struct nosuchstruct *cv;
|
428
|
81 }
|
|
82 Lisp_Object;
|
|
83
|
|
84 #define XCHARVAL(x) ((x).gu.val)
|
|
85 # define XPNTRVAL(x) ((x).ui)
|
|
86
|
442
|
87 INLINE_HEADER Lisp_Object make_int (EMACS_INT val);
|
|
88 INLINE_HEADER Lisp_Object
|
428
|
89 make_int (EMACS_INT val)
|
|
90 {
|
|
91 Lisp_Object obj;
|
793
|
92 obj.s.bits = 1;
|
|
93 obj.s.val = val;
|
428
|
94 return obj;
|
|
95 }
|
|
96
|
801
|
97
|
|
98 #ifdef __cplusplus
|
|
99
|
|
100 #define volatile_make_int(val) make_int (val)
|
|
101
|
|
102 #else
|
|
103
|
800
|
104 /* Ugh, need different definition to avoid compiler complaint in
|
801
|
105 unix_send_process(). Furthermore, there's no way under C++, it seems,
|
|
106 to declare something volatile and then return it. Perhaps I'd have to
|
|
107 assign to something else instead? But in any case, the warnings about
|
|
108 volatile clobbering doesn't occur in C++. I bet the thing is that C++
|
|
109 already has a built-in system for dealing with non-local exits and such,
|
|
110 in a smart way that doesn't clobber registers, and incorporates
|
|
111 longjmp() into that. */
|
800
|
112 INLINE_HEADER Lisp_Object volatile_make_int (EMACS_INT val);
|
|
113 INLINE_HEADER Lisp_Object
|
|
114 volatile_make_int (EMACS_INT val)
|
|
115 {
|
|
116 volatile Lisp_Object obj;
|
|
117 obj.s.bits = 1;
|
|
118 obj.s.val = val;
|
|
119 return obj;
|
|
120 }
|
|
121
|
801
|
122 #endif /* __cplusplus */
|
|
123
|
|
124
|
442
|
125 INLINE_HEADER Lisp_Object make_char (Emchar val);
|
|
126 INLINE_HEADER Lisp_Object
|
428
|
127 make_char (Emchar val)
|
|
128 {
|
|
129 Lisp_Object obj;
|
793
|
130 obj.gu.type = Lisp_Type_Char;
|
|
131 obj.gu.val = val;
|
442
|
132 return obj;
|
|
133 }
|
|
134
|
800
|
135 INLINE_HEADER Lisp_Object wrap_pointer_1 (const void *ptr);
|
442
|
136 INLINE_HEADER Lisp_Object
|
800
|
137 wrap_pointer_1 (const void *ptr)
|
442
|
138 {
|
|
139 Lisp_Object obj;
|
793
|
140 obj.ui = (EMACS_UINT) ptr;
|
428
|
141 return obj;
|
|
142 }
|
|
143
|
|
144 extern Lisp_Object Qnull_pointer, Qzero;
|
|
145
|
|
146 #define XREALINT(x) ((x).s.val)
|
|
147 #define XUINT(x) ((x).u.val)
|
|
148 #define XTYPE(x) ((x).gu.type)
|
|
149 #define EQ(x,y) ((x).v == (y).v)
|
|
150
|
|
151 #define INTP(x) ((x).s.bits)
|
|
152 #define INT_PLUS(x,y) make_int (XINT (x) + XINT (y))
|
|
153 #define INT_MINUS(x,y) make_int (XINT (x) - XINT (y))
|
|
154 #define INT_PLUS1(x) make_int (XINT (x) + 1)
|
|
155 #define INT_MINUS1(x) make_int (XINT (x) - 1)
|
|
156
|
|
157 /* Convert between a (void *) and a Lisp_Object, as when the
|
|
158 Lisp_Object is passed to a toolkit callback function */
|
|
159 #define VOID_TO_LISP(larg,varg) \
|
|
160 ((void) ((larg).v = (struct nosuchstruct *) (varg)))
|
|
161 #define CVOID_TO_LISP(larg,varg) \
|
442
|
162 ((void) ((larg).cv = (const struct nosuchstruct *) (varg)))
|
428
|
163 #define LISP_TO_VOID(larg) ((void *) ((larg).v))
|
442
|
164 #define LISP_TO_CVOID(larg) ((const void *) ((larg).cv))
|
428
|
165
|
|
166 /* Convert a Lisp_Object into something that can't be used as an
|
|
167 lvalue. Useful for type-checking. */
|
|
168 #if (__GNUC__ > 1)
|
|
169 #define NON_LVALUE(larg) ({ (larg); })
|
|
170 #else
|
|
171 /* Well, you can't really do it without using a function call, and
|
|
172 there's no real point in that; no-union-type is the rule, and that
|
|
173 will catch errors. */
|
|
174 #define NON_LVALUE(larg) (larg)
|
|
175 #endif
|