comparison src/lisp-union.h @ 428:3ecd8885ac67 r21-2-22

Import from CVS: tag r21-2-22
author cvs
date Mon, 13 Aug 2007 11:28:15 +0200
parents
children abe6d1db359e
comparison
equal deleted inserted replaced
427:0a0253eac470 428:3ecd8885ac67
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 */
33 #if defined(WORDS_BIGENDIAN)
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;
79 CONST struct nosuchstruct *cv;
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)
97 # define XSETOBJ(var, vartype, value) do { \
98 EMACS_UINT xset_value = (EMACS_UINT) (value); \
99 (var).ui = xset_value; \
100 } while (0)
101 # define XPNTRVAL(x) ((x).ui)
102
103 INLINE Lisp_Object make_int (EMACS_INT val);
104 INLINE Lisp_Object
105 make_int (EMACS_INT val)
106 {
107 Lisp_Object obj;
108 XSETINT(obj, val);
109 return obj;
110 }
111
112 INLINE Lisp_Object make_char (Emchar val);
113 INLINE Lisp_Object
114 make_char (Emchar val)
115 {
116 Lisp_Object obj;
117 XSETCHAR(obj, val);
118 return obj;
119 }
120
121 extern Lisp_Object Qnull_pointer, Qzero;
122
123 #define XREALINT(x) ((x).s.val)
124 #define XUINT(x) ((x).u.val)
125 #define XTYPE(x) ((x).gu.type)
126 #define EQ(x,y) ((x).v == (y).v)
127
128 #define INTP(x) ((x).s.bits)
129 #define INT_PLUS(x,y) make_int (XINT (x) + XINT (y))
130 #define INT_MINUS(x,y) make_int (XINT (x) - XINT (y))
131 #define INT_PLUS1(x) make_int (XINT (x) + 1)
132 #define INT_MINUS1(x) make_int (XINT (x) - 1)
133
134 /* Convert between a (void *) and a Lisp_Object, as when the
135 Lisp_Object is passed to a toolkit callback function */
136 #define VOID_TO_LISP(larg,varg) \
137 ((void) ((larg).v = (struct nosuchstruct *) (varg)))
138 #define CVOID_TO_LISP(larg,varg) \
139 ((void) ((larg).cv = (CONST struct nosuchstruct *) (varg)))
140 #define LISP_TO_VOID(larg) ((void *) ((larg).v))
141 #define LISP_TO_CVOID(larg) ((CONST void *) ((larg).cv))
142
143 /* Convert a Lisp_Object into something that can't be used as an
144 lvalue. Useful for type-checking. */
145 #if (__GNUC__ > 1)
146 #define NON_LVALUE(larg) ({ (larg); })
147 #else
148 /* Well, you can't really do it without using a function call, and
149 there's no real point in that; no-union-type is the rule, and that
150 will catch errors. */
151 #define NON_LVALUE(larg) (larg)
152 #endif