428
|
1 /* Fundamental definitions for XEmacs Lisp interpreter -- union objects.
|
|
2 Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994
|
|
3 Free Software Foundation, Inc.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
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
|
|
10 later version.
|
|
11
|
|
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
|
|
15 for more details.
|
|
16
|
|
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. */
|
|
21
|
|
22 /* Divergent from FSF. */
|
|
23
|
|
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. */
|
|
28
|
|
29 typedef
|
|
30 union Lisp_Object
|
|
31 {
|
|
32 /* if non-valbits are at lower addresses */
|
442
|
33 #ifdef WORDS_BIGENDIAN
|
428
|
34 struct
|
|
35 {
|
|
36 EMACS_UINT val : VALBITS;
|
|
37 enum_field (Lisp_Type) type : GCTYPEBITS;
|
|
38 } gu;
|
|
39
|
|
40 struct
|
|
41 {
|
|
42 signed EMACS_INT val : INT_VALBITS;
|
|
43 unsigned int bits : INT_GCBITS;
|
|
44 } s;
|
|
45
|
|
46 struct
|
|
47 {
|
|
48 EMACS_UINT val : INT_VALBITS;
|
|
49 unsigned int bits : INT_GCBITS;
|
|
50 } u;
|
|
51 #else /* non-valbits are at higher addresses */
|
|
52 struct
|
|
53 {
|
|
54 enum_field (Lisp_Type) type : GCTYPEBITS;
|
|
55 EMACS_UINT val : VALBITS;
|
|
56 } gu;
|
|
57
|
|
58 struct
|
|
59 {
|
|
60 unsigned int bits : INT_GCBITS;
|
|
61 signed EMACS_INT val : INT_VALBITS;
|
|
62 } s;
|
|
63
|
|
64 struct
|
|
65 {
|
|
66 unsigned int bits : INT_GCBITS;
|
|
67 EMACS_UINT val : INT_VALBITS;
|
|
68 } u;
|
|
69
|
|
70 #endif /* non-valbits are at higher addresses */
|
|
71
|
|
72 EMACS_UINT ui;
|
|
73 signed EMACS_INT i;
|
|
74
|
|
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;
|
442
|
79 const struct nosuchstruct *cv;
|
428
|
80 }
|
|
81 Lisp_Object;
|
|
82
|
|
83 #define XCHARVAL(x) ((x).gu.val)
|
|
84
|
|
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; \
|
|
90 } while (0)
|
|
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; \
|
|
96 } while (0)
|
442
|
97 # define XSETOBJ(var, value) do { \
|
428
|
98 EMACS_UINT xset_value = (EMACS_UINT) (value); \
|
|
99 (var).ui = xset_value; \
|
|
100 } while (0)
|
|
101 # define XPNTRVAL(x) ((x).ui)
|
|
102
|
442
|
103 INLINE_HEADER Lisp_Object make_int (EMACS_INT val);
|
|
104 INLINE_HEADER Lisp_Object
|
428
|
105 make_int (EMACS_INT val)
|
|
106 {
|
|
107 Lisp_Object obj;
|
442
|
108 XSETINT (obj, val);
|
428
|
109 return obj;
|
|
110 }
|
|
111
|
442
|
112 INLINE_HEADER Lisp_Object make_char (Emchar val);
|
|
113 INLINE_HEADER Lisp_Object
|
428
|
114 make_char (Emchar val)
|
|
115 {
|
|
116 Lisp_Object obj;
|
442
|
117 XSETCHAR (obj, val);
|
|
118 return obj;
|
|
119 }
|
|
120
|
|
121 INLINE_HEADER Lisp_Object wrap_object (void *ptr);
|
|
122 INLINE_HEADER Lisp_Object
|
|
123 wrap_object (void *ptr)
|
|
124 {
|
|
125 Lisp_Object obj;
|
|
126 XSETOBJ (obj, ptr);
|
428
|
127 return obj;
|
|
128 }
|
|
129
|
|
130 extern Lisp_Object Qnull_pointer, Qzero;
|
|
131
|
|
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)
|
|
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
|
|
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) \
|
442
|
148 ((void) ((larg).cv = (const struct nosuchstruct *) (varg)))
|
428
|
149 #define LISP_TO_VOID(larg) ((void *) ((larg).v))
|
442
|
150 #define LISP_TO_CVOID(larg) ((const void *) ((larg).cv))
|
428
|
151
|
|
152 /* Convert a Lisp_Object into something that can't be used as an
|
|
153 lvalue. Useful for type-checking. */
|
|
154 #if (__GNUC__ > 1)
|
|
155 #define NON_LVALUE(larg) ({ (larg); })
|
|
156 #else
|
|
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)
|
|
161 #endif
|