0
|
1 /* Definitions of symbol-value forwarding for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
|
23 /* Fsymbol_value checks whether XSYMBOL (sym)->value is one of these,
|
|
24 * and does weird magic stuff if so */
|
|
25
|
|
26 #ifndef _XEMACS_SYMEVAL_H_
|
|
27 #define _XEMACS_SYMEVAL_H_
|
|
28
|
|
29 struct symbol_value_magic
|
|
30 {
|
|
31 struct lcrecord_header lcheader;
|
|
32 enum
|
|
33 {
|
|
34 /* The following tags use the 'symbol_value_forward' structure
|
|
35 and are strictly for variables DEFVARed on the C level. */
|
|
36 SYMVAL_FIXNUM_FORWARD, /* Forward C "int" */
|
|
37 SYMVAL_CONST_FIXNUM_FORWARD, /* Same, but can't be set */
|
|
38 SYMVAL_BOOLEAN_FORWARD, /* Forward C boolean ("int") */
|
|
39 SYMVAL_CONST_BOOLEAN_FORWARD, /* Same, but can't be set */
|
|
40 SYMVAL_OBJECT_FORWARD, /* Forward C Lisp_Object */
|
|
41 SYMVAL_CONST_OBJECT_FORWARD, /* Same, but can't be set */
|
|
42 SYMVAL_CONST_SPECIFIER_FORWARD, /* Same, can't be set, but gives
|
|
43 a different message when attempting
|
|
44 to set that says "use set-specifier"
|
|
45 */
|
|
46 SYMVAL_DEFAULT_BUFFER_FORWARD, /* Forward Lisp_Object into
|
|
47 Vbuffer_defaults */
|
|
48 SYMVAL_CURRENT_BUFFER_FORWARD, /* Forward Lisp_Object into
|
|
49 current_buffer */
|
|
50 SYMVAL_CONST_CURRENT_BUFFER_FORWARD, /* Forward Lisp_Object into
|
|
51 current_buffer, can't
|
|
52 be set */
|
|
53 SYMVAL_DEFAULT_CONSOLE_FORWARD, /* Forward Lisp_Object into
|
|
54 Vconsole_defaults */
|
|
55 SYMVAL_SELECTED_CONSOLE_FORWARD, /* Forward Lisp_Object into
|
|
56 Vselected_console */
|
|
57 SYMVAL_CONST_SELECTED_CONSOLE_FORWARD, /* Forward Lisp_Object into
|
|
58 Vselected_console, can't
|
|
59 be set */
|
|
60 SYMVAL_UNBOUND_MARKER, /* Only Qunbound actually has this
|
|
61 tag */
|
|
62
|
|
63 /* The following tags use the 'symbol_value_buffer_local' structure */
|
|
64 SYMVAL_BUFFER_LOCAL, /* make-variable-buffer-local */
|
|
65 SYMVAL_SOME_BUFFER_LOCAL, /* make-local-variable */
|
|
66
|
|
67 /* The following tag uses the 'symbol_value_lisp_magic' structure */
|
|
68 SYMVAL_LISP_MAGIC, /* Forward to lisp callbacks */
|
|
69
|
|
70 /* The following tag uses the 'symbol_value_varalias' structure */
|
|
71 SYMVAL_VARALIAS /* defvaralias */
|
|
72
|
|
73 #if 0
|
|
74 /* NYI */
|
|
75 SYMVAL_CONSTANT_SYMBOL, /* Self-evaluating symbol */
|
|
76 /* NYI */
|
|
77 #endif
|
|
78 } type;
|
|
79 };
|
|
80 #define SYMBOL_VALUE_MAGIC_P(x) \
|
|
81 (LRECORDP (x) \
|
|
82 && (XRECORD_LHEADER (x)->implementation->printer \
|
|
83 == print_symbol_value_magic))
|
|
84 #define XSYMBOL_VALUE_MAGIC_TYPE(v) \
|
|
85 (((struct symbol_value_magic *) XPNTR (v))->type)
|
|
86 #define XSETSYMBOL_VALUE_MAGIC(s, p) XSETOBJ (s, Lisp_Record, p)
|
|
87 extern void print_symbol_value_magic (Lisp_Object, Lisp_Object, int);
|
|
88
|
|
89 /********** The various different symbol-value-magic types ***********/
|
|
90
|
|
91 /* 1. symbol-value-forward */
|
|
92
|
|
93 /* This type of symbol-value-magic is used for variables declared
|
|
94 DEFVAR_LISP, DEFVAR_INT, DEFVAR_BOOL, DEFVAR_BUFFER_LOCAL,
|
|
95 DEFVAR_BUFFER_DEFAULTS, DEFVAR_SPECIFIER, and for Qunbound.
|
|
96
|
|
97 Note that some of these types of variables can be made buffer-local.
|
|
98 Then, the symbol's value field contains a symbol-value-buffer-local,
|
|
99 whose CURRENT-VALUE field then contains a symbol-value-forward.
|
|
100 */
|
|
101
|
|
102 extern CONST_IF_NOT_DEBUG struct lrecord_implementation
|
|
103 lrecord_symbol_value_forward[];
|
|
104 struct symbol_value_forward
|
|
105 {
|
|
106 struct symbol_value_magic magic;
|
|
107 /* void *forward; -- use magic.lcheader.next instead */
|
|
108 /* Function controlling magic behavior of this forward variable.
|
|
109
|
|
110 SYM is the symbol being operated on (read, set, etc.);
|
|
111
|
|
112 VAL is either the value to set or the value to be returned.
|
|
113
|
|
114 IN_OBJECT is the buffer or console that the value is read in
|
|
115 or set in. A value of Qnil means that the current buffer
|
|
116 and possibly other buffers are being set. (This value will
|
|
117 never be passed for built-in buffer-local or console-local
|
|
118 variables such as `truncate-lines'.) (Currently, a value of
|
|
119 Qnil is always passed for DEFVAR_INT, DEFVAR_LISP, and
|
|
120 DEFVAR_BOOL variables; the code isn't smart enough to figure
|
|
121 out what buffers besides the current buffer are being
|
|
122 affected. Because the magic function is called
|
|
123 before the value is changed, it's not that easy
|
|
124 to determine which buffers are getting changed.
|
|
125 #### If this information is important, let me know
|
|
126 and I will look into providing it.) (Remember also
|
|
127 that the only console-local variables currently existing
|
|
128 are built-in ones, because others can't be created.)
|
|
129
|
|
130 FLAGS gives more information about the operation being
|
|
131 performed.
|
|
132
|
|
133 The return value indicates what the magic function actually
|
|
134 did.
|
|
135
|
|
136 Currently FLAGS and the return value are not used. This
|
|
137 function is only called when the value of a forward variable
|
|
138 is about to be changed. Note that this can occur explicitly
|
|
139 through a call to `set', `setq', `set-default', or `setq-default',
|
|
140 or implicitly by the current buffer being changed.
|
|
141
|
|
142 */
|
|
143
|
|
144 int (*magicfun) (Lisp_Object sym, Lisp_Object *val, Lisp_Object in_object,
|
|
145 int flags);
|
|
146 };
|
|
147 #define XSYMBOL_VALUE_FORWARD(v) \
|
|
148 ((CONST struct symbol_value_forward *) XPNTR(v))
|
|
149 #define symbol_value_forward_forward(m) ((void *)((m)->magic.lcheader.next))
|
|
150 #define symbol_value_forward_magicfun(m) ((m)->magicfun)
|
|
151
|
|
152 /* 2. symbol-value-buffer-local */
|
|
153
|
|
154 extern CONST_IF_NOT_DEBUG struct lrecord_implementation
|
|
155 lrecord_symbol_value_buffer_local[];
|
|
156 struct symbol_value_buffer_local
|
|
157 {
|
|
158 struct symbol_value_magic magic;
|
|
159 /* Used in a symbol value cell when the symbol's value is per-buffer.
|
|
160
|
|
161 The type of the symbol-value-magic will be either
|
|
162 SYMVAL_BUFFER_LOCAL (i.e. `make-variable-buffer-local' was called)
|
|
163 or SYMVAL_SOME_BUFFER_LOCAL (i.e. `make-local-variable' was called).
|
|
164 The only difference between the two is that when setting the
|
|
165 former kind of variable, an implicit `make-local-variable' is
|
|
166 called.
|
|
167
|
|
168 A buffer-local variable logically has
|
|
169
|
|
170 -- a default value
|
|
171 -- local values in some buffers
|
|
172
|
|
173 The primary place where the local values are stored is in each
|
|
174 buffer's local_var_alist slot.
|
|
175
|
|
176 In the simplest implementation, all that this structure needs to
|
|
177 keep track of is the default value; to retrieve the value in
|
|
178 a buffer, look in that buffer's local_var_alist, and use the
|
|
179 default value if there is no local value. To implement
|
|
180 `make-local-variable' in a buffer, look in the buffer's
|
|
181 local_var_alist, and if no element exists for this symbol,
|
|
182 add one, copying the value from the default value. When setting
|
|
183 the value in a buffer, look in the buffer's local_var_alist, and set
|
|
184 the value in that list if an element exists for this symbol;
|
|
185 otherwise, set the default. (Remember that SYMVAL_BUFFER_LOCAL
|
|
186 variables implicitly call `make-local-variable' first, so when
|
|
187 setting a value, there will always be an entry in the buffer's
|
|
188 local_var_alist to set.)
|
|
189
|
|
190 However, these operation is potentially slow. To speed it up,
|
|
191 we cache the value in one buffer in this structure.
|
|
192
|
|
193 NOTE: This is *not* a write-through cache. I.e. when setting
|
|
194 the value in the buffer that is cached, we *only* change the
|
|
195 cache and don't write the value through to either the buffer's
|
|
196 local_var_alist or the default value. Therefore, when retrieving
|
|
197 a value in a buffer, you must *always* look in the cache to see if
|
|
198 it refers to that buffer.
|
|
199
|
|
200 The cache consists of
|
|
201
|
|
202 -- a buffer, or nil if the cache has not been set up
|
|
203 -- the value in that buffer
|
|
204 -- the element (a cons) from the buffer's local_var_alist, or
|
|
205 nil if there is no local value in the buffer
|
|
206
|
|
207 These slots are called CURRENT-BUFFER, CURRENT-VALUE, and
|
|
208 CURRENT-ALIST-ELEMENT, respectively.
|
|
209
|
|
210 If we want to examine or set the value in BUFFER and CURRENT-BUFFER
|
|
211 equals BUFFER, we just examine or set CURRENT-VALUE. Otherwise,
|
|
212 we store CURRENT-VALUE value into CURRENT-ALIST-ELEMENT (or maybe
|
|
213 into DEFAULT-VALUE), then find the appropriate alist element for
|
|
214 BUFFER and set up CURRENT-ALIST-ELEMENT. Then we set CURRENT-VALUE
|
|
215 out of that element (or maybe out of DEFAULT-VALUE), and store
|
|
216 BUFFER into CURRENT-BUFFER.
|
|
217
|
|
218 If we are setting the variable and the current buffer does not have
|
|
219 an alist entry for this variable, an alist entry is created.
|
|
220
|
|
221 Note that CURRENT-BUFFER's local_var_alist value for this variable
|
|
222 might be out-of-date (the correct value is stored in CURRENT-VALUE).
|
|
223 Similarly, if CURRENT-BUFFER sees the default value, then
|
|
224 DEFAULT-VALUE might be out-of-date.
|
|
225
|
|
226 Note that CURRENT-VALUE (but not DEFAULT-VALUE) can be a
|
|
227 forwarding pointer. Each time it is examined or set,
|
|
228 forwarding must be done.
|
|
229 */
|
|
230 Lisp_Object default_value;
|
|
231 Lisp_Object current_value;
|
|
232 Lisp_Object current_buffer;
|
|
233 Lisp_Object current_alist_element;
|
|
234 };
|
|
235 #define XSYMBOL_VALUE_BUFFER_LOCAL(v) \
|
|
236 ((struct symbol_value_buffer_local *) XPNTR(v))
|
|
237 #define SYMBOL_VALUE_BUFFER_LOCAL_P(v) \
|
|
238 (SYMBOL_VALUE_MAGIC_P (v) && \
|
|
239 (XSYMBOL_VALUE_MAGIC_TYPE (v) == SYMVAL_BUFFER_LOCAL \
|
|
240 || XSYMBOL_VALUE_MAGIC_TYPE (v) == SYMVAL_SOME_BUFFER_LOCAL))
|
|
241
|
|
242 /* 3. symbol-value-lisp-magic */
|
|
243
|
|
244 extern CONST_IF_NOT_DEBUG struct lrecord_implementation
|
|
245 lrecord_symbol_value_lisp_magic[];
|
|
246 enum lisp_magic_handler
|
|
247 {
|
|
248 MAGIC_HANDLER_GET_VALUE,
|
|
249 MAGIC_HANDLER_SET_VALUE,
|
|
250 MAGIC_HANDLER_BOUND_PREDICATE,
|
|
251 MAGIC_HANDLER_MAKE_UNBOUND,
|
|
252 MAGIC_HANDLER_LOCAL_PREDICATE,
|
|
253 MAGIC_HANDLER_MAKE_LOCAL,
|
|
254 MAGIC_HANDLER_MAX
|
|
255 };
|
|
256
|
|
257 struct symbol_value_lisp_magic
|
|
258 {
|
|
259 struct symbol_value_magic magic;
|
|
260 Lisp_Object handler[MAGIC_HANDLER_MAX];
|
|
261 Lisp_Object harg[MAGIC_HANDLER_MAX];
|
|
262 Lisp_Object shadowed;
|
|
263 };
|
|
264 #define XSYMBOL_VALUE_LISP_MAGIC(v) \
|
|
265 ((struct symbol_value_lisp_magic *) XPNTR (v))
|
|
266 #define SYMBOL_VALUE_LISP_MAGIC_P(v) \
|
|
267 (SYMBOL_VALUE_MAGIC_P (v) && \
|
|
268 XSYMBOL_VALUE_MAGIC_TYPE (v) == SYMVAL_LISP_MAGIC)
|
|
269
|
|
270 /* 4. symbol-value-varalias */
|
|
271
|
|
272 extern CONST_IF_NOT_DEBUG struct lrecord_implementation
|
|
273 lrecord_symbol_value_varalias[];
|
|
274 struct symbol_value_varalias
|
|
275 {
|
|
276 struct symbol_value_magic magic;
|
|
277 Lisp_Object aliasee;
|
|
278 Lisp_Object shadowed;
|
|
279 };
|
|
280 #define XSYMBOL_VALUE_VARALIAS(v) \
|
|
281 ((struct symbol_value_varalias *) XPNTR (v))
|
|
282 #define SYMBOL_VALUE_VARALIAS_P(v) \
|
|
283 (SYMBOL_VALUE_MAGIC_P (v) && \
|
|
284 XSYMBOL_VALUE_MAGIC_TYPE (v) == SYMVAL_VARALIAS)
|
|
285 #define symbol_value_varalias_aliasee(m) ((m)->aliasee)
|
|
286 #define symbol_value_varalias_shadowed(m) ((m)->shadowed)
|
|
287
|
16
|
288 /* DEFSUBR (Fname);
|
|
289 is how we define the symbol for function `Fname' at start-up time. */
|
|
290 #define DEFSUBR(Fname) defsubr (&S##Fname)
|
0
|
291 extern void defsubr (struct Lisp_Subr *);
|
|
292
|
|
293 extern void defsymbol (Lisp_Object *location, CONST char *name);
|
|
294
|
|
295 extern void defkeyword (Lisp_Object *location, CONST char *name);
|
|
296
|
|
297 extern void deferror (Lisp_Object *symbol, CONST char *name,
|
|
298 CONST char *message, Lisp_Object inherits_from);
|
|
299
|
|
300 /* Macros we use to define forwarded Lisp variables.
|
|
301 These are used in the syms_of_FILENAME functions. */
|
|
302
|
|
303 extern void defvar_mumble (CONST char *names,
|
|
304 CONST void *magic, int sizeof_magic);
|
|
305
|
|
306 #define DEFVAR_HEADER(lname, c_location, forward_type) \
|
|
307 static CONST struct symbol_value_forward I_hate_C \
|
|
308 = { { { { lrecord_symbol_value_forward }, (void *) (c_location), 69 }, \
|
|
309 forward_type }, 0 }; \
|
|
310 defvar_mumble ((lname), &I_hate_C, sizeof (I_hate_C))
|
|
311
|
|
312 #define DEFVAR_MAGIC_HEADER(lname, c_location, forward_type, magicfun) \
|
|
313 static CONST struct symbol_value_forward I_hate_C \
|
|
314 = { { { { lrecord_symbol_value_forward }, (void *) (c_location), 69 }, \
|
|
315 forward_type }, magicfun }; \
|
|
316 defvar_mumble ((lname), &I_hate_C, sizeof (I_hate_C))
|
|
317
|
|
318 /* These discard their DOC arg because it is snarfed by make-docfile
|
|
319 * and stored in an external file. */
|
|
320
|
|
321 #define DEFVAR_LISP(lname, c_location) \
|
|
322 do { DEFVAR_HEADER (lname, c_location, SYMVAL_OBJECT_FORWARD); \
|
|
323 staticpro (c_location); \
|
|
324 } while (0)
|
|
325 #define DEFVAR_CONST_LISP(lname, c_location) \
|
|
326 do { DEFVAR_HEADER (lname, c_location, SYMVAL_CONST_OBJECT_FORWARD); \
|
|
327 staticpro (c_location); \
|
|
328 } while (0)
|
|
329 #define DEFVAR_SPECIFIER(lname, c_location) \
|
|
330 do { DEFVAR_HEADER (lname, c_location, SYMVAL_CONST_SPECIFIER_FORWARD); \
|
|
331 staticpro (c_location); \
|
|
332 } while (0)
|
|
333 #define DEFVAR_INT(lname, c_location) \
|
|
334 do { DEFVAR_HEADER (lname, c_location, SYMVAL_FIXNUM_FORWARD); \
|
|
335 } while (0)
|
|
336 #define DEFVAR_CONST_INT(lname, c_location) \
|
|
337 do { DEFVAR_HEADER (lname, c_location, SYMVAL_CONST_FIXNUM_FORWARD); \
|
|
338 } while (0)
|
|
339 #define DEFVAR_BOOL(lname, c_location) \
|
|
340 do { DEFVAR_HEADER (lname, c_location, SYMVAL_BOOLEAN_FORWARD);\
|
|
341 } while (0)
|
|
342 #define DEFVAR_CONST_BOOL(lname, c_location) \
|
|
343 do { DEFVAR_HEADER (lname, c_location, SYMVAL_CONST_BOOLEAN_FORWARD); \
|
|
344 } while (0)
|
|
345
|
|
346 #define DEFVAR_LISP_MAGIC(lname, c_location, magicfun) \
|
|
347 do { DEFVAR_MAGIC_HEADER (lname, c_location, \
|
|
348 SYMVAL_OBJECT_FORWARD, magicfun); \
|
|
349 staticpro (c_location); \
|
|
350 } while (0)
|
|
351 #define DEFVAR_INT_MAGIC(lname, c_location, magicfun) \
|
|
352 do { DEFVAR_MAGIC_HEADER (lname, c_location, \
|
|
353 SYMVAL_FIXNUM_FORWARD, magicfun); \
|
|
354 } while (0)
|
|
355 #define DEFVAR_BOOL_MAGIC(lname, c_location, magicfun) \
|
|
356 do { DEFVAR_MAGIC_HEADER (lname, c_location, \
|
|
357 SYMVAL_BOOLEAN_FORWARD, magicfun); \
|
|
358 } while (0)
|
|
359
|
|
360 #endif /* _XEMACS_SYMEVAL_H_ */
|