0
|
1 /* Evaluator for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985-1987, 1992-1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, 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 /* Synched up with: FSF 19.30 (except for Fsignal), Mule 2.0. */
|
|
23
|
|
24 /* Debugging hack */
|
|
25 int always_gc;
|
|
26
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #ifndef standalone
|
|
32 #include "commands.h"
|
|
33 #endif
|
|
34
|
|
35 #include "symeval.h"
|
|
36 #include "backtrace.h"
|
|
37 #include "bytecode.h"
|
|
38 #include "buffer.h"
|
|
39 #include "console.h"
|
|
40 #include "opaque.h"
|
|
41
|
|
42 struct backtrace *backtrace_list;
|
|
43
|
116
|
44 /* Note you must always fill all of the fields in a backtrace structure
|
|
45 before pushing them on the backtrace_list. The profiling code depends
|
|
46 on this. */
|
|
47
|
|
48 #define PUSH_BACKTRACE(bt) \
|
|
49 do { (bt).next = backtrace_list; backtrace_list = &(bt); } while (0)
|
|
50
|
|
51 #define POP_BACKTRACE(bt) \
|
|
52 do { backtrace_list = (bt).next; } while (0)
|
|
53
|
0
|
54 /* This is the list of current catches (and also condition-cases).
|
|
55 This is a stack: the most recent catch is at the head of the
|
|
56 list. Catches are created by declaring a 'struct catchtag'
|
|
57 locally, filling the .TAG field in with the tag, and doing
|
|
58 a setjmp() on .JMP. Fthrow() will store the value passed
|
|
59 to it in .VAL and longjmp() back to .JMP, back to the function
|
|
60 that established the catch. This will always be either
|
|
61 internal_catch() (catches established internally or through
|
|
62 `catch') or condition_case_1 (condition-cases established
|
|
63 internally or through `condition-case').
|
|
64
|
|
65 The catchtag also records the current position in the
|
|
66 call stack (stored in BACKTRACE_LIST), the current position
|
|
67 in the specpdl stack (used for variable bindings and
|
|
68 unwind-protects), the value of LISP_EVAL_DEPTH, and the
|
|
69 current position in the GCPRO stack. All of these are
|
|
70 restored by Fthrow().
|
|
71 */
|
|
72
|
|
73 struct catchtag *catchlist;
|
|
74
|
|
75 Lisp_Object Qautoload, Qmacro, Qexit;
|
|
76 Lisp_Object Qinteractive, Qcommandp, Qdefun, Qprogn, Qvalues;
|
|
77 Lisp_Object Vquit_flag, Vinhibit_quit;
|
|
78 Lisp_Object Qand_rest, Qand_optional;
|
|
79 Lisp_Object Qdebug_on_error;
|
|
80 Lisp_Object Qstack_trace_on_error;
|
|
81 Lisp_Object Qdebug_on_signal;
|
|
82 Lisp_Object Qstack_trace_on_signal;
|
|
83 Lisp_Object Qdebugger;
|
|
84 Lisp_Object Qinhibit_quit;
|
|
85 Lisp_Object Qrun_hooks;
|
|
86
|
|
87 Lisp_Object Qsetq;
|
|
88
|
|
89 Lisp_Object Qdisplay_warning;
|
|
90 Lisp_Object Vpending_warnings, Vpending_warnings_tail;
|
|
91
|
|
92 /* Records whether we want errors to occur. This will be a boolean,
|
|
93 nil (errors OK) or t (no errors). If t, an error will cause a
|
|
94 throw to Qunbound_suspended_errors_tag.
|
|
95
|
|
96 See call_with_suspended_errors(). */
|
|
97 Lisp_Object Vcurrent_error_state;
|
|
98
|
|
99 /* Current warning class when warnings occur, or nil for no warnings.
|
|
100 Only meaningful when Vcurrent_error_state is non-nil.
|
|
101 See call_with_suspended_errors(). */
|
|
102 Lisp_Object Vcurrent_warning_class;
|
|
103
|
|
104 /* Special catch tag used in call_with_suspended_errors(). */
|
|
105 Lisp_Object Qunbound_suspended_errors_tag;
|
|
106
|
|
107 /* Non-nil means we're going down, so we better not run any hooks
|
|
108 or do other non-essential stuff. */
|
|
109 int preparing_for_armageddon;
|
|
110
|
|
111 /* Non-nil means record all fset's and provide's, to be undone
|
|
112 if the file being autoloaded is not fully loaded.
|
|
113 They are recorded by being consed onto the front of Vautoload_queue:
|
|
114 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
|
|
115
|
|
116 Lisp_Object Vautoload_queue;
|
|
117
|
|
118 /* Current number of specbindings allocated in specpdl. */
|
|
119 static int specpdl_size;
|
|
120
|
|
121 /* Pointer to beginning of specpdl. */
|
|
122 struct specbinding *specpdl;
|
|
123
|
|
124 /* Pointer to first unused element in specpdl. */
|
|
125 struct specbinding *specpdl_ptr;
|
|
126
|
2
|
127 /* specpdl_ptr - specpdl. Callers outside this file should use
|
0
|
128 * specpdl_depth () function-call */
|
|
129 static int specpdl_depth_counter;
|
|
130
|
|
131 /* Maximum size allowed for specpdl allocation */
|
|
132 int max_specpdl_size;
|
|
133
|
|
134 /* Depth in Lisp evaluations and function calls. */
|
|
135 int lisp_eval_depth;
|
|
136
|
|
137 /* Maximum allowed depth in Lisp evaluations and function calls. */
|
|
138 int max_lisp_eval_depth;
|
|
139
|
|
140 /* Nonzero means enter debugger before next function call */
|
|
141 static int debug_on_next_call;
|
|
142
|
|
143 /* List of conditions (non-nil atom means all) which cause a backtrace
|
|
144 if an error is handled by the command loop's error handler. */
|
|
145 Lisp_Object Vstack_trace_on_error;
|
|
146
|
|
147 /* List of conditions (non-nil atom means all) which enter the debugger
|
|
148 if an error is handled by the command loop's error handler. */
|
|
149 Lisp_Object Vdebug_on_error;
|
|
150
|
|
151 /* List of conditions (non-nil atom means all) which cause a backtrace
|
|
152 if any error is signalled. */
|
|
153 Lisp_Object Vstack_trace_on_signal;
|
|
154
|
|
155 /* List of conditions (non-nil atom means all) which enter the debugger
|
|
156 if any error is signalled. */
|
|
157 Lisp_Object Vdebug_on_signal;
|
|
158
|
|
159 /* Nonzero means enter debugger if a quit signal
|
|
160 is handled by the command loop's error handler.
|
|
161
|
|
162 From lisp, this is a boolean variable and may have the values 0 and 1.
|
|
163 But, eval.c temporarily uses the second bit of this variable to indicate
|
|
164 that a critical_quit is in progress. The second bit is reset immediately
|
|
165 after it is processed in signal_call_debugger(). */
|
|
166 int debug_on_quit;
|
|
167
|
|
168 #if 0 /* FSFmacs */
|
|
169 /* entering_debugger is basically equivalent */
|
|
170 /* The value of num_nonmacro_input_chars as of the last time we
|
|
171 started to enter the debugger. If we decide to enter the debugger
|
|
172 again when this is still equal to num_nonmacro_input_chars, then we
|
|
173 know that the debugger itself has an error, and we should just
|
|
174 signal the error instead of entering an infinite loop of debugger
|
|
175 invocations. */
|
|
176 int when_entered_debugger;
|
|
177 #endif
|
|
178
|
|
179 /* Nonzero means we are trying to enter the debugger.
|
|
180 This is to prevent recursive attempts.
|
|
181 Cleared by the debugger calling Fbacktrace */
|
|
182 static int entering_debugger;
|
|
183
|
|
184 /* Function to call to invoke the debugger */
|
|
185 Lisp_Object Vdebugger;
|
|
186
|
|
187 /* Chain of condition handlers currently in effect.
|
|
188 The elements of this chain are contained in the stack frames
|
|
189 of Fcondition_case and internal_condition_case.
|
|
190 When an error is signaled (by calling Fsignal, below),
|
|
191 this chain is searched for an element that applies.
|
|
192
|
|
193 Each element of this list is one of the following:
|
|
194
|
|
195 A list of a handler function and possibly args to pass to
|
|
196 the function. This is a handler established with
|
|
197 `call-with-condition-handler' (q.v.).
|
|
198
|
|
199 A list whose car is Qunbound and whose cdr is Qt.
|
|
200 This is a special condition-case handler established
|
|
201 by C code with condition_case_1(). All errors are
|
|
202 trapped; the debugger is not invoked even if
|
|
203 `debug-on-error' was set.
|
|
204
|
|
205 A list whose car is Qunbound and whose cdr is Qerror.
|
|
206 This is a special condition-case handler established
|
|
207 by C code with condition_case_1(). It is like Qt
|
|
208 except that the debugger is invoked normally if it is
|
|
209 called for.
|
|
210
|
|
211 A list whose car is Qunbound and whose cdr is a list
|
|
212 of lists (CONDITION-NAME BODY ...) exactly as in
|
|
213 `condition-case'. This is a normal `condition-case'
|
|
214 handler.
|
|
215
|
|
216 Note that in all cases *except* the first, there is a
|
|
217 corresponding catch, whose TAG is the value of
|
|
218 Vcondition_handlers just after the handler data just
|
|
219 described is pushed onto it. The reason is that
|
|
220 `condition-case' handlers need to throw back to the
|
|
221 place where the handler was installed before invoking
|
|
222 it, while `call-with-condition-handler' handlers are
|
|
223 invoked in the environment that `signal' was invoked
|
|
224 in.
|
|
225 */
|
|
226 static Lisp_Object Vcondition_handlers;
|
|
227
|
|
228 /* Used for error catching purposes by throw_or_bomb_out */
|
|
229 static int throw_level;
|
|
230
|
74
|
231 static Lisp_Object primitive_funcall (lisp_fn_t fn, int nargs,
|
0
|
232 Lisp_Object args[]);
|
|
233
|
|
234
|
|
235 /**********************************************************************/
|
|
236 /* The subr and compiled-function types */
|
|
237 /**********************************************************************/
|
|
238
|
|
239 static void print_subr (Lisp_Object, Lisp_Object, int);
|
|
240 DEFINE_LRECORD_IMPLEMENTATION ("subr", subr,
|
|
241 this_one_is_unmarkable, print_subr, 0, 0, 0,
|
|
242 struct Lisp_Subr);
|
|
243
|
|
244 static void
|
|
245 print_subr (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
246 {
|
|
247 struct Lisp_Subr *subr = XSUBR (obj);
|
|
248
|
|
249 if (print_readably)
|
|
250 error ("printing unreadable object #<subr %s>",
|
|
251 subr_name (subr));
|
|
252
|
|
253 write_c_string (((subr->max_args == UNEVALLED)
|
|
254 ? "#<special-form "
|
|
255 : "#<subr "),
|
|
256 printcharfun);
|
|
257
|
|
258 write_c_string (subr_name (subr), printcharfun);
|
|
259 write_c_string (((subr->prompt) ? " (interactive)>" : ">"),
|
|
260 printcharfun);
|
|
261 }
|
|
262
|
|
263
|
|
264 static Lisp_Object mark_compiled_function (Lisp_Object,
|
|
265 void (*) (Lisp_Object));
|
|
266 extern void print_compiled_function (Lisp_Object, Lisp_Object, int);
|
|
267 static int compiled_function_equal (Lisp_Object, Lisp_Object, int);
|
|
268 static unsigned long compiled_function_hash (Lisp_Object obj, int depth);
|
|
269 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("compiled-function", compiled_function,
|
|
270 mark_compiled_function,
|
|
271 print_compiled_function, 0,
|
|
272 compiled_function_equal,
|
|
273 compiled_function_hash,
|
|
274 struct Lisp_Compiled_Function);
|
|
275
|
|
276 static Lisp_Object
|
|
277 mark_compiled_function (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
278 {
|
|
279 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (obj);
|
|
280
|
|
281 ((markobj) (b->bytecodes));
|
|
282 ((markobj) (b->arglist));
|
|
283 ((markobj) (b->doc_and_interactive));
|
|
284 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
285 ((markobj) (b->annotated));
|
|
286 #endif
|
|
287 /* tail-recurse on constants */
|
|
288 return (b->constants);
|
|
289 }
|
|
290
|
|
291 static int
|
|
292 compiled_function_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
293 {
|
|
294 struct Lisp_Compiled_Function *b1 = XCOMPILED_FUNCTION (o1);
|
|
295 struct Lisp_Compiled_Function *b2 = XCOMPILED_FUNCTION (o2);
|
|
296 return (b1->flags.documentationp == b2->flags.documentationp
|
|
297 && b1->flags.interactivep == b2->flags.interactivep
|
|
298 && b1->flags.domainp == b2->flags.domainp /* I18N3 */
|
|
299 && internal_equal (b1->bytecodes, b2->bytecodes, depth + 1)
|
|
300 && internal_equal (b1->constants, b2->constants, depth + 1)
|
|
301 && internal_equal (b1->arglist, b2->arglist, depth + 1)
|
|
302 && internal_equal (b1->doc_and_interactive,
|
|
303 b2->doc_and_interactive, depth + 1));
|
|
304 }
|
|
305
|
|
306 static unsigned long
|
|
307 compiled_function_hash (Lisp_Object obj, int depth)
|
|
308 {
|
|
309 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (obj);
|
|
310 return HASH3 ((b->flags.documentationp << 2) +
|
|
311 (b->flags.interactivep << 1) +
|
|
312 b->flags.domainp,
|
|
313 internal_hash (b->bytecodes, depth + 1),
|
|
314 internal_hash (b->constants, depth + 1));
|
|
315 }
|
|
316
|
|
317
|
|
318 /**********************************************************************/
|
|
319 /* Entering the debugger */
|
|
320 /**********************************************************************/
|
|
321
|
|
322 /* unwind-protect used by call_debugger() to restore the value of
|
|
323 enterring_debugger. (We cannot use specbind() because the
|
|
324 variable is not Lisp-accessible.) */
|
|
325
|
|
326 static Lisp_Object
|
|
327 restore_entering_debugger (Lisp_Object arg)
|
|
328 {
|
|
329 entering_debugger = ((NILP (arg)) ? 0 : 1);
|
|
330 return arg;
|
|
331 }
|
|
332
|
|
333 /* Actually call the debugger. ARG is a list of args that will be
|
|
334 passed to the debugger function, as follows;
|
|
335
|
|
336 If due to frame exit, args are `exit' and the value being returned;
|
|
337 this function's value will be returned instead of that.
|
|
338 If due to error, args are `error' and a list of the args to `signal'.
|
|
339 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
340 If due to `eval' entry, one arg, t.
|
|
341
|
|
342 */
|
|
343
|
|
344 static Lisp_Object
|
|
345 call_debugger_259 (Lisp_Object arg)
|
|
346 {
|
|
347 return apply1 (Vdebugger, arg);
|
|
348 }
|
|
349
|
|
350 /* Call the debugger, doing some encapsulation. We make sure we have
|
|
351 some room on the eval and specpdl stacks, and bind enterring_debugger
|
|
352 to 1 during this call. This is used to trap errors that may occur
|
|
353 when enterring the debugger (e.g. the value of `debugger' is invalid),
|
|
354 so that the debugger will not be recursively entered if debug-on-error
|
|
355 is set. (Otherwise, XEmacs would infinitely recurse, attempting to
|
|
356 enter the debugger.) enterring_debugger gets reset to 0 as soon
|
|
357 as a backtrace is displayed, so that further errors can indeed be
|
|
358 handled normally.
|
|
359
|
|
360 We also establish a catch for 'debugger. If the debugger function
|
|
361 throws to this instead of returning a value, it means that the user
|
|
362 pressed 'c' (pretend like the debugger was never entered). The
|
|
363 function then returns Qunbound. (If the user pressed 'r', for
|
|
364 return a value, then the debugger function returns normally with
|
|
365 this value.)
|
|
366
|
|
367 The difference between 'c' and 'r' is as follows:
|
|
368
|
|
369 debug-on-call:
|
|
370 No difference. The call proceeds as normal.
|
|
371 debug-on-exit:
|
|
372 With 'r', the specified value is returned as the function's
|
|
373 return value. With 'c', the value that would normally be
|
|
374 returned is returned.
|
|
375 signal:
|
|
376 With 'r', the specified value is returned as the return
|
|
377 value of `signal'. (This is the only time that `signal'
|
|
378 can return, instead of making a non-local exit.) With `c',
|
|
379 `signal' will continue looking for handlers as if the
|
|
380 debugger was never entered, and will probably end up
|
|
381 throwing to a handler or to top-level.
|
|
382 */
|
|
383
|
|
384 static Lisp_Object
|
|
385 call_debugger (Lisp_Object arg)
|
|
386 {
|
|
387 int threw;
|
|
388 Lisp_Object val;
|
|
389 int speccount;
|
|
390
|
|
391 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
|
|
392 max_lisp_eval_depth = lisp_eval_depth + 20;
|
|
393 if (specpdl_size + 40 > max_specpdl_size)
|
|
394 max_specpdl_size = specpdl_size + 40;
|
|
395 debug_on_next_call = 0;
|
|
396
|
|
397 speccount = specpdl_depth_counter;
|
|
398 record_unwind_protect (restore_entering_debugger,
|
|
399 (entering_debugger ? Qt : Qnil));
|
|
400 entering_debugger = 1;
|
|
401 val = internal_catch (Qdebugger, call_debugger_259, arg, &threw);
|
|
402
|
|
403 return (unbind_to (speccount, ((threw)
|
|
404 ? Qunbound /* Not returning a value */
|
|
405 : val)));
|
|
406 }
|
|
407
|
|
408 /* Called when debug-on-exit behavior is called for. Enter the debugger
|
|
409 with the appropriate args for this. VAL is the exit value that is
|
|
410 about to be returned. */
|
|
411
|
|
412 static Lisp_Object
|
|
413 do_debug_on_exit (Lisp_Object val)
|
|
414 {
|
|
415 /* This is falsified by call_debugger */
|
|
416 Lisp_Object v = call_debugger (list2 (Qexit, val));
|
94
|
417
|
0
|
418 return ((!UNBOUNDP (v)) ? v : val);
|
|
419 }
|
|
420
|
|
421 /* Called when debug-on-call behavior is called for. Enter the debugger
|
|
422 with the appropriate args for this. VAL is either t for a call
|
|
423 through `eval' or 'lambda for a call through `funcall'.
|
|
424
|
|
425 #### The differentiation here between EVAL and FUNCALL is bogus.
|
|
426 FUNCALL can be defined as
|
|
427
|
|
428 (defmacro func (fun &rest args)
|
|
429 (cons (eval fun) args))
|
|
430
|
|
431 and should be treated as such.
|
|
432 */
|
|
433
|
|
434 static void
|
|
435 do_debug_on_call (Lisp_Object code)
|
|
436 {
|
|
437 debug_on_next_call = 0;
|
|
438 backtrace_list->debug_on_exit = 1;
|
|
439 call_debugger (list1 (code));
|
|
440 }
|
|
441
|
|
442 /* LIST is the value of one of the variables `debug-on-error',
|
|
443 `debug-on-signal', `stack-trace-on-error', or `stack-trace-on-signal',
|
|
444 and CONDITIONS is the list of error conditions associated with
|
|
445 the error being signalled. This returns non-nil if LIST
|
|
446 matches CONDITIONS. (A nil value for LIST does not match
|
|
447 CONDITIONS. A non-list value for LIST does match CONDITIONS.
|
|
448 A list matches CONDITIONS when one of the symbols in LIST is the
|
|
449 same as one of the symbols in CONDITIONS.) */
|
|
450
|
|
451 static int
|
|
452 wants_debugger (Lisp_Object list, Lisp_Object conditions)
|
|
453 {
|
|
454 if (NILP (list))
|
|
455 return 0;
|
|
456 if (! CONSP (list))
|
|
457 return 1;
|
|
458
|
|
459 while (CONSP (conditions))
|
|
460 {
|
|
461 Lisp_Object this, tail;
|
|
462 this = XCAR (conditions);
|
|
463 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
464 if (EQ (XCAR (tail), this))
|
|
465 return 1;
|
|
466 conditions = XCDR (conditions);
|
|
467 }
|
|
468 return 0;
|
|
469 }
|
|
470
|
|
471 /* Actually generate a backtrace on STREAM. */
|
|
472
|
|
473 static Lisp_Object
|
|
474 backtrace_259 (Lisp_Object stream)
|
|
475 {
|
|
476 return (Fbacktrace (stream, Qt));
|
|
477 }
|
|
478
|
|
479 /* An error was signalled. Maybe call the debugger, if the `debug-on-error'
|
|
480 etc. variables call for this. CONDITIONS is the list of conditions
|
|
481 associated with the error being signalled. SIG is the actual error
|
|
482 being signalled, and DATA is the associated data (these are exactly
|
|
483 the same as the arguments to `signal'). ACTIVE_HANDLERS is the
|
|
484 list of error handlers that are to be put in place while the debugger
|
|
485 is called. This is generally the remaining handlers that are
|
|
486 outside of the innermost handler trapping this error. This way,
|
|
487 if the same error occurs inside of the debugger, you usually don't get
|
|
488 the debugger entered recursively.
|
|
489
|
|
490 This function returns Qunbound if it didn't call the debugger or if
|
|
491 the user asked (through 'c') that XEmacs should pretend like the
|
|
492 debugger was never entered. Otherwise, it returns the value
|
|
493 that the user specified with `r'. (Note that much of the time,
|
|
494 the user will abort with C-], and we will never have a chance to
|
|
495 return anything at all.)
|
|
496
|
|
497 SIGNAL_VARS_ONLY means we should only look at debug-on-signal
|
|
498 and stack-trace-on-signal to control whether we do anything.
|
|
499 This is so that debug-on-error doesn't make handled errors
|
|
500 cause the debugger to get invoked.
|
|
501
|
|
502 STACK_TRACE_DISPLAYED and DEBUGGER_ENTERED are used so that
|
|
503 those functions aren't done more than once in a single `signal'
|
|
504 session. */
|
|
505
|
|
506 static Lisp_Object
|
|
507 signal_call_debugger (Lisp_Object conditions,
|
|
508 Lisp_Object sig, Lisp_Object data,
|
|
509 Lisp_Object active_handlers,
|
|
510 int signal_vars_only,
|
|
511 int *stack_trace_displayed,
|
|
512 int *debugger_entered)
|
|
513 {
|
|
514 /* This function can GC */
|
|
515 Lisp_Object val = Qunbound;
|
|
516 Lisp_Object all_handlers = Vcondition_handlers;
|
|
517 int speccount = specpdl_depth_counter;
|
|
518 struct gcpro gcpro1;
|
|
519 GCPRO1 (all_handlers);
|
|
520
|
|
521 Vcondition_handlers = active_handlers;
|
|
522
|
|
523 if (!entering_debugger && !*stack_trace_displayed && !signal_vars_only
|
|
524 && wants_debugger (Vstack_trace_on_error, conditions))
|
|
525 {
|
|
526 specbind (Qdebug_on_error, Qnil);
|
|
527 specbind (Qstack_trace_on_error, Qnil);
|
|
528 specbind (Qdebug_on_signal, Qnil);
|
|
529 specbind (Qstack_trace_on_signal, Qnil);
|
|
530
|
|
531 internal_with_output_to_temp_buffer ("*Backtrace*",
|
|
532 backtrace_259,
|
|
533 Qnil,
|
|
534 Qnil);
|
|
535 unbind_to (speccount, Qnil);
|
|
536 *stack_trace_displayed = 1;
|
|
537 }
|
|
538
|
|
539 if (!entering_debugger && !*debugger_entered && !signal_vars_only
|
|
540 && (EQ (sig, Qquit)
|
|
541 ? debug_on_quit
|
|
542 : wants_debugger (Vdebug_on_error, conditions)))
|
|
543 {
|
|
544 debug_on_quit &= ~2; /* reset critical bit */
|
|
545 specbind (Qdebug_on_error, Qnil);
|
|
546 specbind (Qstack_trace_on_error, Qnil);
|
|
547 specbind (Qdebug_on_signal, Qnil);
|
|
548 specbind (Qstack_trace_on_signal, Qnil);
|
|
549
|
|
550 val = call_debugger (list2 (Qerror, (Fcons (sig, data))));
|
|
551 *debugger_entered = 1;
|
|
552 }
|
|
553
|
|
554 if (!entering_debugger && !*stack_trace_displayed
|
|
555 && wants_debugger (Vstack_trace_on_signal, conditions))
|
|
556 {
|
|
557 specbind (Qdebug_on_error, Qnil);
|
|
558 specbind (Qstack_trace_on_error, Qnil);
|
|
559 specbind (Qdebug_on_signal, Qnil);
|
|
560 specbind (Qstack_trace_on_signal, Qnil);
|
|
561
|
|
562 internal_with_output_to_temp_buffer ("*Backtrace*",
|
|
563 backtrace_259,
|
|
564 Qnil,
|
|
565 Qnil);
|
|
566 unbind_to (speccount, Qnil);
|
|
567 *stack_trace_displayed = 1;
|
|
568 }
|
|
569
|
|
570 if (!entering_debugger && !*debugger_entered
|
|
571 && (EQ (sig, Qquit)
|
|
572 ? debug_on_quit
|
|
573 : wants_debugger (Vdebug_on_signal, conditions)))
|
|
574 {
|
|
575 debug_on_quit &= ~2; /* reset critical bit */
|
|
576 specbind (Qdebug_on_error, Qnil);
|
|
577 specbind (Qstack_trace_on_error, Qnil);
|
|
578 specbind (Qdebug_on_signal, Qnil);
|
|
579 specbind (Qstack_trace_on_signal, Qnil);
|
|
580
|
|
581 val = call_debugger (list2 (Qerror, (Fcons (sig, data))));
|
|
582 *debugger_entered = 1;
|
|
583 }
|
|
584
|
|
585 UNGCPRO;
|
|
586 Vcondition_handlers = all_handlers;
|
|
587 return (unbind_to (speccount, val));
|
|
588 }
|
|
589
|
|
590
|
|
591 /**********************************************************************/
|
|
592 /* The basic special forms */
|
|
593 /**********************************************************************/
|
|
594
|
|
595 /* NOTE!!! Every function that can call EVAL must protect its args
|
|
596 and temporaries from garbage collection while it needs them.
|
|
597 The definition of `For' shows what you have to do. */
|
|
598
|
20
|
599 DEFUN ("or", For, 0, UNEVALLED, 0, /*
|
0
|
600 Eval args until one of them yields non-nil, then return that value.
|
|
601 The remaining args are not evalled at all.
|
|
602 If all args return nil, return nil.
|
20
|
603 */
|
|
604 (args))
|
0
|
605 {
|
|
606 /* This function can GC */
|
|
607 REGISTER Lisp_Object val;
|
|
608 Lisp_Object args_left;
|
|
609 struct gcpro gcpro1;
|
|
610
|
|
611 if (NILP (args))
|
|
612 return Qnil;
|
|
613
|
|
614 args_left = args;
|
|
615 GCPRO1 (args_left);
|
|
616
|
|
617 do
|
|
618 {
|
|
619 val = Feval (Fcar (args_left));
|
|
620 if (!NILP (val))
|
|
621 break;
|
|
622 args_left = Fcdr (args_left);
|
|
623 }
|
|
624 while (!NILP (args_left));
|
|
625
|
|
626 UNGCPRO;
|
|
627 return val;
|
|
628 }
|
|
629
|
20
|
630 DEFUN ("and", Fand, 0, UNEVALLED, 0, /*
|
0
|
631 Eval args until one of them yields nil, then return nil.
|
|
632 The remaining args are not evalled at all.
|
|
633 If no arg yields nil, return the last arg's value.
|
20
|
634 */
|
|
635 (args))
|
0
|
636 {
|
|
637 /* This function can GC */
|
|
638 REGISTER Lisp_Object val;
|
|
639 Lisp_Object args_left;
|
|
640 struct gcpro gcpro1;
|
|
641
|
|
642 if (NILP (args))
|
|
643 return Qt;
|
|
644
|
|
645 args_left = args;
|
|
646 GCPRO1 (args_left);
|
|
647
|
|
648 do
|
|
649 {
|
|
650 val = Feval (Fcar (args_left));
|
|
651 if (NILP (val))
|
|
652 break;
|
|
653 args_left = Fcdr (args_left);
|
|
654 }
|
|
655 while (!NILP (args_left));
|
|
656
|
|
657 UNGCPRO;
|
|
658 return val;
|
|
659 }
|
|
660
|
20
|
661 DEFUN ("if", Fif, 2, UNEVALLED, 0, /*
|
0
|
662 (if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE...
|
|
663 Returns the value of THEN or the value of the last of the ELSE's.
|
|
664 THEN must be one expression, but ELSE... can be zero or more expressions.
|
|
665 If COND yields nil, and there are no ELSE's, the value is nil.
|
20
|
666 */
|
70
|
667 (args))
|
0
|
668 {
|
|
669 /* This function can GC */
|
|
670 Lisp_Object cond;
|
|
671 struct gcpro gcpro1;
|
|
672
|
|
673 GCPRO1 (args);
|
|
674 cond = Feval (Fcar (args));
|
|
675 UNGCPRO;
|
|
676
|
|
677 if (!NILP (cond))
|
|
678 return Feval (Fcar (Fcdr (args)));
|
|
679 return Fprogn (Fcdr (Fcdr (args)));
|
|
680 }
|
|
681
|
20
|
682 DEFUN ("cond", Fcond, 0, UNEVALLED, 0, /*
|
0
|
683 (cond CLAUSES...): try each clause until one succeeds.
|
|
684 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
|
|
685 and, if the value is non-nil, this clause succeeds:
|
|
686 then the expressions in BODY are evaluated and the last one's
|
|
687 value is the value of the cond-form.
|
|
688 If no clause succeeds, cond returns nil.
|
|
689 If a clause has one element, as in (CONDITION),
|
|
690 CONDITION's value if non-nil is returned from the cond-form.
|
20
|
691 */
|
|
692 (args))
|
0
|
693 {
|
|
694 /* This function can GC */
|
|
695 REGISTER Lisp_Object clause, val;
|
|
696 struct gcpro gcpro1;
|
|
697
|
|
698 val = Qnil;
|
|
699 GCPRO1 (args);
|
|
700 while (!NILP (args))
|
|
701 {
|
|
702 clause = Fcar (args);
|
|
703 val = Feval (Fcar (clause));
|
|
704 if (!NILP (val))
|
|
705 {
|
|
706 if (!EQ (XCDR (clause), Qnil))
|
|
707 val = Fprogn (XCDR (clause));
|
|
708 break;
|
|
709 }
|
|
710 args = XCDR (args);
|
|
711 }
|
|
712 UNGCPRO;
|
|
713
|
|
714 return val;
|
|
715 }
|
|
716
|
20
|
717 DEFUN ("progn", Fprogn, 0, UNEVALLED, 0, /*
|
0
|
718 (progn BODY...): eval BODY forms sequentially and return value of last one.
|
20
|
719 */
|
|
720 (args))
|
0
|
721 {
|
|
722 /* This function can GC */
|
|
723 REGISTER Lisp_Object val;
|
|
724 Lisp_Object args_left;
|
|
725 struct gcpro gcpro1;
|
|
726
|
|
727 if (NILP (args))
|
|
728 return Qnil;
|
|
729
|
|
730 args_left = args;
|
|
731 GCPRO1 (args_left);
|
|
732
|
|
733 do
|
|
734 {
|
|
735 val = Feval (Fcar (args_left));
|
|
736 args_left = Fcdr (args_left);
|
|
737 }
|
|
738 while (!NILP (args_left));
|
|
739
|
|
740 UNGCPRO;
|
|
741 return val;
|
|
742 }
|
|
743
|
20
|
744 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /*
|
0
|
745 (prog1 FIRST BODY...): eval FIRST and BODY sequentially; value from FIRST.
|
|
746 The value of FIRST is saved during the evaluation of the remaining args,
|
|
747 whose values are discarded.
|
20
|
748 */
|
|
749 (args))
|
0
|
750 {
|
|
751 /* This function can GC */
|
|
752 Lisp_Object val;
|
|
753 REGISTER Lisp_Object args_left;
|
|
754 struct gcpro gcpro1, gcpro2;
|
|
755 REGISTER int argnum = 0;
|
|
756
|
|
757 if (NILP (args))
|
|
758 return Qnil;
|
|
759
|
|
760 args_left = args;
|
|
761 val = Qnil;
|
|
762 GCPRO2 (args, val);
|
|
763
|
|
764 do
|
|
765 {
|
|
766 if (!(argnum++))
|
|
767 val = Feval (Fcar (args_left));
|
|
768 else
|
|
769 Feval (Fcar (args_left));
|
|
770 args_left = Fcdr (args_left);
|
|
771 }
|
|
772 while (!NILP (args_left));
|
|
773
|
|
774 UNGCPRO;
|
|
775 return val;
|
|
776 }
|
|
777
|
20
|
778 DEFUN ("prog2", Fprog2, 2, UNEVALLED, 0, /*
|
0
|
779 (prog2 X Y BODY...): eval X, Y and BODY sequentially; value from Y.
|
|
780 The value of Y is saved during the evaluation of the remaining args,
|
|
781 whose values are discarded.
|
20
|
782 */
|
|
783 (args))
|
0
|
784 {
|
|
785 /* This function can GC */
|
|
786 Lisp_Object val;
|
|
787 REGISTER Lisp_Object args_left;
|
|
788 struct gcpro gcpro1, gcpro2;
|
|
789 REGISTER int argnum = -1;
|
|
790
|
|
791 val = Qnil;
|
|
792
|
|
793 if (NILP (args))
|
|
794 return Qnil;
|
|
795
|
|
796 args_left = args;
|
|
797 val = Qnil;
|
|
798 GCPRO2 (args, val);
|
|
799
|
|
800 do
|
|
801 {
|
|
802 if (!(argnum++))
|
|
803 val = Feval (Fcar (args_left));
|
|
804 else
|
|
805 Feval (Fcar (args_left));
|
|
806 args_left = Fcdr (args_left);
|
|
807 }
|
|
808 while (!NILP (args_left));
|
|
809
|
|
810 UNGCPRO;
|
|
811 return val;
|
|
812 }
|
|
813
|
20
|
814 DEFUN ("let*", FletX, 1, UNEVALLED, 0, /*
|
0
|
815 (let* VARLIST BODY...): bind variables according to VARLIST then eval BODY.
|
|
816 The value of the last form in BODY is returned.
|
|
817 Each element of VARLIST is a symbol (which is bound to nil)
|
|
818 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
|
|
819 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
|
20
|
820 */
|
|
821 (args))
|
0
|
822 {
|
|
823 /* This function can GC */
|
|
824 Lisp_Object varlist, val, elt;
|
|
825 int speccount = specpdl_depth_counter;
|
|
826 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
827
|
|
828 GCPRO3 (args, elt, varlist);
|
|
829
|
|
830 varlist = Fcar (args);
|
|
831 while (!NILP (varlist))
|
|
832 {
|
|
833 QUIT;
|
|
834 elt = Fcar (varlist);
|
|
835 if (SYMBOLP (elt))
|
|
836 specbind (elt, Qnil);
|
|
837 else if (! NILP (Fcdr (Fcdr (elt))))
|
|
838 signal_simple_error ("`let' bindings can have only one value-form",
|
|
839 elt);
|
|
840 else
|
|
841 {
|
|
842 val = Feval (Fcar (Fcdr (elt)));
|
|
843 specbind (Fcar (elt), val);
|
|
844 }
|
|
845 varlist = Fcdr (varlist);
|
|
846 }
|
|
847 UNGCPRO;
|
|
848 val = Fprogn (Fcdr (args));
|
|
849 return unbind_to (speccount, val);
|
|
850 }
|
|
851
|
20
|
852 DEFUN ("let", Flet, 1, UNEVALLED, 0, /*
|
0
|
853 (let VARLIST BODY...): bind variables according to VARLIST then eval BODY.
|
|
854 The value of the last form in BODY is returned.
|
|
855 Each element of VARLIST is a symbol (which is bound to nil)
|
|
856 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
|
|
857 All the VALUEFORMs are evalled before any symbols are bound.
|
20
|
858 */
|
|
859 (args))
|
0
|
860 {
|
|
861 /* This function can GC */
|
|
862 Lisp_Object *temps, tem;
|
|
863 REGISTER Lisp_Object elt, varlist;
|
|
864 int speccount = specpdl_depth_counter;
|
|
865 REGISTER int argnum;
|
|
866 struct gcpro gcpro1, gcpro2;
|
|
867
|
|
868 varlist = Fcar (args);
|
|
869
|
|
870 /* Make space to hold the values to give the bound variables */
|
|
871 elt = Flength (varlist);
|
|
872 temps = (Lisp_Object *) alloca (XINT (elt) * sizeof (Lisp_Object));
|
|
873
|
|
874 /* Compute the values and store them in `temps' */
|
|
875
|
|
876 GCPRO2 (args, *temps);
|
|
877 gcpro2.nvars = 0;
|
|
878
|
|
879 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
|
|
880 {
|
|
881 QUIT;
|
|
882 elt = Fcar (varlist);
|
|
883 if (SYMBOLP (elt))
|
|
884 temps [argnum++] = Qnil;
|
|
885 else if (! NILP (Fcdr (Fcdr (elt))))
|
|
886 signal_simple_error ("`let' bindings can have only one value-form",
|
|
887 elt);
|
|
888 else
|
|
889 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
|
|
890 gcpro2.nvars = argnum;
|
|
891 }
|
|
892 UNGCPRO;
|
|
893
|
|
894 varlist = Fcar (args);
|
|
895 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
|
|
896 {
|
|
897 elt = Fcar (varlist);
|
|
898 tem = temps[argnum++];
|
|
899 if (SYMBOLP (elt))
|
|
900 specbind (elt, tem);
|
|
901 else
|
|
902 specbind (Fcar (elt), tem);
|
|
903 }
|
|
904
|
|
905 elt = Fprogn (Fcdr (args));
|
|
906 return unbind_to (speccount, elt);
|
|
907 }
|
|
908
|
20
|
909 DEFUN ("while", Fwhile, 1, UNEVALLED, 0, /*
|
0
|
910 (while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat.
|
|
911 The order of execution is thus TEST, BODY, TEST, BODY and so on
|
|
912 until TEST returns nil.
|
20
|
913 */
|
70
|
914 (args))
|
0
|
915 {
|
|
916 /* This function can GC */
|
|
917 Lisp_Object test, body, tem;
|
|
918 struct gcpro gcpro1, gcpro2;
|
|
919
|
|
920 GCPRO2 (test, body);
|
|
921
|
|
922 test = Fcar (args);
|
|
923 body = Fcdr (args);
|
|
924 while (tem = Feval (test), !NILP (tem))
|
|
925 {
|
|
926 QUIT;
|
|
927 Fprogn (body);
|
|
928 }
|
|
929
|
|
930 UNGCPRO;
|
|
931 return Qnil;
|
|
932 }
|
|
933
|
|
934 Lisp_Object Qsetq;
|
|
935
|
20
|
936 DEFUN ("setq", Fsetq, 0, UNEVALLED, 0, /*
|
0
|
937 (setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL.
|
|
938 The symbols SYM are variables; they are literal (not evaluated).
|
|
939 The values VAL are expressions; they are evaluated.
|
|
940 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
|
|
941 The second VAL is not computed until after the first SYM is set, and so on;
|
|
942 each VAL can use the new value of variables set earlier in the `setq'.
|
|
943 The return value of the `setq' form is the value of the last VAL.
|
20
|
944 */
|
|
945 (args))
|
0
|
946 {
|
|
947 /* This function can GC */
|
|
948 REGISTER Lisp_Object args_left;
|
|
949 REGISTER Lisp_Object val, sym;
|
|
950 struct gcpro gcpro1;
|
|
951
|
|
952 if (NILP (args))
|
|
953 return Qnil;
|
|
954
|
|
955 val = Flength (args);
|
|
956 if (XINT (val) & 1) /* Odd number of arguments? */
|
|
957 Fsignal (Qwrong_number_of_arguments, list2 (Qsetq, val));
|
|
958
|
|
959 args_left = args;
|
|
960 GCPRO1 (args);
|
|
961
|
|
962 do
|
|
963 {
|
|
964 val = Feval (Fcar (Fcdr (args_left)));
|
|
965 sym = Fcar (args_left);
|
|
966 Fset (sym, val);
|
|
967 args_left = Fcdr (Fcdr (args_left));
|
|
968 }
|
|
969 while (!NILP (args_left));
|
|
970
|
|
971 UNGCPRO;
|
|
972 return val;
|
|
973 }
|
|
974
|
20
|
975 DEFUN ("quote", Fquote, 1, UNEVALLED, 0, /*
|
0
|
976 Return the argument, without evaluating it. `(quote x)' yields `x'.
|
20
|
977 */
|
|
978 (args))
|
0
|
979 {
|
|
980 return Fcar (args);
|
|
981 }
|
|
982
|
20
|
983 DEFUN ("function", Ffunction, 1, UNEVALLED, 0, /*
|
0
|
984 Like `quote', but preferred for objects which are functions.
|
|
985 In byte compilation, `function' causes its argument to be compiled.
|
|
986 `quote' cannot do that.
|
20
|
987 */
|
|
988 (args))
|
0
|
989 {
|
|
990 return Fcar (args);
|
|
991 }
|
|
992
|
|
993
|
|
994 /**********************************************************************/
|
|
995 /* Defining functions/variables */
|
|
996 /**********************************************************************/
|
|
997
|
20
|
998 DEFUN ("defun", Fdefun, 2, UNEVALLED, 0, /*
|
0
|
999 (defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
|
|
1000 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
|
|
1001 See also the function `interactive'.
|
20
|
1002 */
|
|
1003 (args))
|
0
|
1004 {
|
|
1005 /* This function can GC */
|
|
1006 Lisp_Object fn_name;
|
|
1007 Lisp_Object defn;
|
|
1008
|
|
1009 fn_name = Fcar (args);
|
|
1010 defn = Fcons (Qlambda, Fcdr (args));
|
|
1011 if (purify_flag)
|
|
1012 defn = Fpurecopy (defn);
|
|
1013 Ffset (fn_name, defn);
|
|
1014 LOADHIST_ATTACH (fn_name);
|
|
1015 return fn_name;
|
|
1016 }
|
|
1017
|
20
|
1018 DEFUN ("defmacro", Fdefmacro, 2, UNEVALLED, 0, /*
|
0
|
1019 (defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.
|
|
1020 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).
|
|
1021 When the macro is called, as in (NAME ARGS...),
|
|
1022 the function (lambda ARGLIST BODY...) is applied to
|
|
1023 the list ARGS... as it appears in the expression,
|
|
1024 and the result should be a form to be evaluated instead of the original.
|
20
|
1025 */
|
|
1026 (args))
|
0
|
1027 {
|
|
1028 /* This function can GC */
|
|
1029 Lisp_Object fn_name;
|
|
1030 Lisp_Object defn;
|
|
1031
|
|
1032 fn_name = Fcar (args);
|
|
1033 defn = Fcons (Qmacro, Fcons (Qlambda, Fcdr (args)));
|
|
1034 if (purify_flag)
|
|
1035 defn = Fpurecopy (defn);
|
|
1036 Ffset (fn_name, defn);
|
|
1037 LOADHIST_ATTACH (fn_name);
|
|
1038 return fn_name;
|
|
1039 }
|
|
1040
|
20
|
1041 DEFUN ("defvar", Fdefvar, 1, UNEVALLED, 0, /*
|
0
|
1042 (defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable.
|
|
1043 You are not required to define a variable in order to use it,
|
|
1044 but the definition can supply documentation and an initial value
|
|
1045 in a way that tags can recognize.
|
|
1046
|
|
1047 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is
|
|
1048 void. (However, when you evaluate a defvar interactively, it acts like a
|
|
1049 defconst: SYMBOL's value is always set regardless of whether it's currently
|
|
1050 void.)
|
|
1051 If SYMBOL is buffer-local, its default value is what is set;
|
|
1052 buffer-local values are not affected.
|
|
1053 INITVALUE and DOCSTRING are optional.
|
|
1054 If DOCSTRING starts with *, this variable is identified as a user option.
|
|
1055 This means that M-x set-variable and M-x edit-options recognize it.
|
|
1056 If INITVALUE is missing, SYMBOL's value is not set.
|
|
1057
|
|
1058 In lisp-interaction-mode defvar is treated as defconst.
|
20
|
1059 */
|
|
1060 (args))
|
0
|
1061 {
|
|
1062 /* This function can GC */
|
|
1063 REGISTER Lisp_Object sym, tem, tail;
|
|
1064
|
|
1065 sym = Fcar (args);
|
|
1066 tail = Fcdr (args);
|
|
1067 if (!NILP (Fcdr (Fcdr (tail))))
|
|
1068 error ("too many arguments");
|
|
1069
|
|
1070 if (!NILP (tail))
|
|
1071 {
|
|
1072 tem = Fdefault_boundp (sym);
|
|
1073 if (NILP (tem))
|
|
1074 Fset_default (sym, Feval (Fcar (Fcdr (args))));
|
|
1075 }
|
|
1076
|
|
1077 #ifdef I18N3
|
|
1078 if (!NILP (Vfile_domain))
|
|
1079 pure_put (sym, Qvariable_domain, Vfile_domain);
|
|
1080 #endif
|
|
1081
|
|
1082 tail = Fcdr (Fcdr (args));
|
|
1083 if (!NILP (Fcar (tail)))
|
|
1084 {
|
|
1085 tem = Fcar (tail);
|
|
1086 #if 0 /* FSFmacs */
|
|
1087 /* #### We should probably do this but it might be dangerous */
|
|
1088 if (purify_flag)
|
|
1089 tem = Fpurecopy (tem);
|
|
1090 Fput (sym, Qvariable_documentation, tem);
|
|
1091 #else
|
|
1092 pure_put (sym, Qvariable_documentation, tem);
|
|
1093 #endif
|
|
1094 }
|
|
1095
|
|
1096 LOADHIST_ATTACH (sym);
|
|
1097 return sym;
|
|
1098 }
|
|
1099
|
20
|
1100 DEFUN ("defconst", Fdefconst, 2, UNEVALLED, 0, /*
|
0
|
1101 (defconst SYMBOL INITVALUE DOCSTRING): define SYMBOL as a constant
|
|
1102 variable.
|
|
1103 The intent is that programs do not change this value, but users may.
|
|
1104 Always sets the value of SYMBOL to the result of evalling INITVALUE.
|
|
1105 If SYMBOL is buffer-local, its default value is what is set;
|
|
1106 buffer-local values are not affected.
|
|
1107 DOCSTRING is optional.
|
|
1108 If DOCSTRING starts with *, this variable is identified as a user option.
|
|
1109 This means that M-x set-variable and M-x edit-options recognize it.
|
|
1110
|
|
1111 Note: do not use `defconst' for user options in libraries that are not
|
|
1112 normally loaded, since it is useful for users to be able to specify
|
|
1113 their own values for such variables before loading the library.
|
|
1114 Since `defconst' unconditionally assigns the variable,
|
|
1115 it would override the user's choice.
|
20
|
1116 */
|
|
1117 (args))
|
0
|
1118 {
|
|
1119 /* This function can GC */
|
|
1120 REGISTER Lisp_Object sym, tem;
|
|
1121
|
|
1122 sym = Fcar (args);
|
|
1123 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
|
|
1124 error ("too many arguments");
|
|
1125
|
|
1126 Fset_default (sym, Feval (Fcar (Fcdr (args))));
|
|
1127
|
|
1128 #ifdef I18N3
|
|
1129 if (!NILP (Vfile_domain))
|
|
1130 pure_put (sym, Qvariable_domain, Vfile_domain);
|
|
1131 #endif
|
|
1132
|
|
1133 tem = Fcar (Fcdr (Fcdr (args)));
|
|
1134
|
|
1135 if (!NILP (tem))
|
|
1136 #if 0 /* FSFmacs */
|
|
1137 /* #### We should probably do this but it might be dangerous */
|
|
1138 {
|
|
1139 if (purify_flag)
|
|
1140 tem = Fpurecopy (tem);
|
|
1141 Fput (sym, Qvariable_documentation, tem);
|
|
1142 }
|
|
1143 #else
|
|
1144 pure_put (sym, Qvariable_documentation, tem);
|
|
1145 #endif
|
|
1146
|
|
1147 LOADHIST_ATTACH (sym);
|
|
1148 return sym;
|
|
1149 }
|
|
1150
|
20
|
1151 DEFUN ("user-variable-p", Fuser_variable_p, 1, 1, 0, /*
|
0
|
1152 Return t if VARIABLE is intended to be set and modified by users.
|
|
1153 \(The alternative is a variable used internally in a Lisp program.)
|
|
1154 Determined by whether the first character of the documentation
|
|
1155 for the variable is `*'.
|
20
|
1156 */
|
|
1157 (variable))
|
0
|
1158 {
|
|
1159 Lisp_Object documentation;
|
|
1160
|
|
1161 documentation = Fget (variable, Qvariable_documentation, Qnil);
|
|
1162 if (INTP (documentation) && XINT (documentation) < 0)
|
|
1163 return Qt;
|
|
1164 if ((STRINGP (documentation)) &&
|
|
1165 (string_byte (XSTRING (documentation), 0) == '*'))
|
|
1166 return Qt;
|
|
1167 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
|
|
1168 if (CONSP (documentation)
|
|
1169 && STRINGP (XCAR (documentation))
|
|
1170 && INTP (XCDR (documentation))
|
|
1171 && XINT (XCDR (documentation)) < 0)
|
|
1172 return Qt;
|
|
1173 return Qnil;
|
|
1174 }
|
|
1175
|
20
|
1176 DEFUN ("macroexpand-internal", Fmacroexpand_internal, 1, 2, 0, /*
|
0
|
1177 Return result of expanding macros at top level of FORM.
|
|
1178 If FORM is not a macro call, it is returned unchanged.
|
|
1179 Otherwise, the macro is expanded and the expansion is considered
|
|
1180 in place of FORM. When a non-macro-call results, it is returned.
|
|
1181
|
|
1182 The second optional arg ENVIRONMENT species an environment of macro
|
|
1183 definitions to shadow the loaded ones for use in file byte-compilation.
|
20
|
1184 */
|
|
1185 (form, env))
|
0
|
1186 {
|
|
1187 /* This function can GC */
|
|
1188 /* With cleanups from Hallvard Furuseth. */
|
|
1189 REGISTER Lisp_Object expander, sym, def, tem;
|
|
1190
|
|
1191 while (1)
|
|
1192 {
|
|
1193 /* Come back here each time we expand a macro call,
|
|
1194 in case it expands into another macro call. */
|
|
1195 if (!CONSP (form))
|
|
1196 break;
|
|
1197 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
|
|
1198 def = sym = XCAR (form);
|
|
1199 tem = Qnil;
|
|
1200 /* Trace symbols aliases to other symbols
|
|
1201 until we get a symbol that is not an alias. */
|
|
1202 while (SYMBOLP (def))
|
|
1203 {
|
|
1204 QUIT;
|
|
1205 sym = def;
|
|
1206 tem = Fassq (sym, env);
|
|
1207 if (NILP (tem))
|
|
1208 {
|
|
1209 def = XSYMBOL (sym)->function;
|
|
1210 if (!UNBOUNDP (def))
|
|
1211 continue;
|
|
1212 }
|
|
1213 break;
|
|
1214 }
|
|
1215 /* Right now TEM is the result from SYM in ENV,
|
|
1216 and if TEM is nil then DEF is SYM's function definition. */
|
|
1217 if (NILP (tem))
|
|
1218 {
|
|
1219 /* SYM is not mentioned in ENV.
|
|
1220 Look at its function definition. */
|
|
1221 if (UNBOUNDP (def)
|
|
1222 || !CONSP (def))
|
|
1223 /* Not defined or definition not suitable */
|
|
1224 break;
|
|
1225 if (EQ (XCAR (def), Qautoload))
|
|
1226 {
|
|
1227 /* Autoloading function: will it be a macro when loaded? */
|
|
1228 tem = Felt (def, make_int (4));
|
|
1229 if (EQ (tem, Qt) || EQ (tem, Qmacro))
|
|
1230 {
|
|
1231 /* Yes, load it and try again. */
|
|
1232 do_autoload (def, sym);
|
|
1233 continue;
|
|
1234 }
|
|
1235 else
|
|
1236 break;
|
|
1237 }
|
|
1238 else if (!EQ (XCAR (def), Qmacro))
|
|
1239 break;
|
|
1240 else expander = XCDR (def);
|
|
1241 }
|
|
1242 else
|
|
1243 {
|
|
1244 expander = XCDR (tem);
|
|
1245 if (NILP (expander))
|
|
1246 break;
|
|
1247 }
|
|
1248 form = apply1 (expander, XCDR (form));
|
|
1249 }
|
|
1250 return form;
|
|
1251 }
|
|
1252
|
|
1253
|
|
1254 /**********************************************************************/
|
|
1255 /* Non-local exits */
|
|
1256 /**********************************************************************/
|
|
1257
|
20
|
1258 DEFUN ("catch", Fcatch, 1, UNEVALLED, 0, /*
|
0
|
1259 (catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'.
|
|
1260 TAG is evalled to get the tag to use. Then the BODY is executed.
|
|
1261 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
|
|
1262 If no throw happens, `catch' returns the value of the last BODY form.
|
|
1263 If a throw happens, it specifies the value to return from `catch'.
|
20
|
1264 */
|
|
1265 (args))
|
0
|
1266 {
|
|
1267 /* This function can GC */
|
|
1268 Lisp_Object tag;
|
|
1269 struct gcpro gcpro1;
|
|
1270
|
|
1271 GCPRO1 (args);
|
|
1272 tag = Feval (Fcar (args));
|
|
1273 UNGCPRO;
|
|
1274 return internal_catch (tag, Fprogn, Fcdr (args), 0);
|
|
1275 }
|
|
1276
|
|
1277 /* Set up a catch, then call C function FUNC on argument ARG.
|
|
1278 FUNC should return a Lisp_Object.
|
|
1279 This is how catches are done from within C code. */
|
|
1280
|
|
1281 Lisp_Object
|
|
1282 internal_catch (Lisp_Object tag,
|
|
1283 Lisp_Object (*func) (Lisp_Object arg),
|
|
1284 Lisp_Object arg,
|
|
1285 int *threw)
|
|
1286 {
|
|
1287 /* This structure is made part of the chain `catchlist'. */
|
|
1288 struct catchtag c;
|
|
1289
|
|
1290 /* Fill in the components of c, and put it on the list. */
|
|
1291 c.next = catchlist;
|
|
1292 c.tag = tag;
|
|
1293 c.val = Qnil;
|
|
1294 c.backlist = backtrace_list;
|
|
1295 #if 0 /* FSFmacs */
|
|
1296 /* #### */
|
|
1297 c.handlerlist = handlerlist;
|
|
1298 #endif
|
|
1299 c.lisp_eval_depth = lisp_eval_depth;
|
|
1300 c.pdlcount = specpdl_depth_counter;
|
|
1301 #if 0 /* FSFmacs */
|
|
1302 c.poll_suppress_count = async_timer_suppress_count;
|
|
1303 #endif
|
|
1304 c.gcpro = gcprolist;
|
|
1305 catchlist = &c;
|
|
1306
|
|
1307 /* Call FUNC. */
|
|
1308 if (SETJMP (c.jmp))
|
|
1309 {
|
|
1310 /* Throw works by a longjmp that comes right here. */
|
|
1311 if (threw) *threw = 1;
|
|
1312 return (c.val);
|
|
1313 }
|
|
1314 c.val = (*func) (arg);
|
|
1315 if (threw) *threw = 0;
|
|
1316 catchlist = c.next;
|
|
1317 return (c.val);
|
|
1318 }
|
|
1319
|
|
1320
|
|
1321 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
|
|
1322 jump to that CATCH, returning VALUE as the value of that catch.
|
|
1323
|
|
1324 This is the guts Fthrow and Fsignal; they differ only in the way
|
|
1325 they choose the catch tag to throw to. A catch tag for a
|
|
1326 condition-case form has a TAG of Qnil.
|
|
1327
|
|
1328 Before each catch is discarded, unbind all special bindings and
|
|
1329 execute all unwind-protect clauses made above that catch. Unwind
|
|
1330 the handler stack as we go, so that the proper handlers are in
|
|
1331 effect for each unwind-protect clause we run. At the end, restore
|
|
1332 some static info saved in CATCH, and longjmp to the location
|
|
1333 specified in the
|
|
1334
|
|
1335 This is used for correct unwinding in Fthrow and Fsignal. */
|
|
1336
|
|
1337 static void
|
|
1338 unwind_to_catch (struct catchtag *c, Lisp_Object val)
|
|
1339 {
|
|
1340 #if 0 /* FSFmacs */
|
|
1341 /* #### */
|
|
1342 register int last_time;
|
|
1343 #endif
|
|
1344
|
|
1345 /* Unwind the specbind, catch, and handler stacks back to CATCH
|
|
1346 Before each catch is discarded, unbind all special bindings
|
|
1347 and execute all unwind-protect clauses made above that catch.
|
|
1348 At the end, restore some static info saved in CATCH,
|
|
1349 and longjmp to the location specified.
|
|
1350 */
|
|
1351
|
|
1352 /* Save the value somewhere it will be GC'ed.
|
|
1353 (Can't overwrite tag slot because an unwind-protect may
|
|
1354 want to throw to this same tag, which isn't yet invalid.) */
|
|
1355 c->val = val;
|
|
1356
|
|
1357 #if 0 /* FSFmacs */
|
|
1358 /* Restore the polling-suppression count. */
|
|
1359 set_poll_suppress_count (catch->poll_suppress_count);
|
|
1360 #endif
|
|
1361
|
|
1362 #if 0 /* FSFmacs */
|
|
1363 /* #### FSFmacs has the following loop. Is it more correct? */
|
|
1364 do
|
|
1365 {
|
|
1366 last_time = catchlist == c;
|
|
1367
|
|
1368 /* Unwind the specpdl stack, and then restore the proper set of
|
|
1369 handlers. */
|
|
1370 unbind_to (catchlist->pdlcount, Qnil);
|
|
1371 handlerlist = catchlist->handlerlist;
|
|
1372 catchlist = catchlist->next;
|
|
1373 }
|
|
1374 while (! last_time);
|
|
1375 #else /* Actual XEmacs code */
|
|
1376 /* Unwind the specpdl stack */
|
|
1377 unbind_to (c->pdlcount, Qnil);
|
|
1378 catchlist = c->next;
|
|
1379 #endif
|
|
1380
|
|
1381 gcprolist = c->gcpro;
|
|
1382 backtrace_list = c->backlist;
|
|
1383 lisp_eval_depth = c->lisp_eval_depth;
|
|
1384
|
|
1385 throw_level = 0;
|
|
1386 LONGJMP (c->jmp, 1);
|
|
1387 }
|
|
1388
|
|
1389 static DOESNT_RETURN
|
|
1390 throw_or_bomb_out (Lisp_Object tag, Lisp_Object val, int bomb_out_p,
|
|
1391 Lisp_Object sig, Lisp_Object data)
|
|
1392 {
|
|
1393 /* die if we recurse more than is reasonable */
|
|
1394 if (++throw_level > 20)
|
|
1395 abort();
|
|
1396
|
|
1397 /* If bomb_out_p is t, this is being called from Fsignal as a
|
|
1398 "last resort" when there is no handler for this error and
|
|
1399 the debugger couldn't be invoked, so we are throwing to
|
|
1400 'top-level. If this tag doesn't exist (happens during the
|
|
1401 initialization stages) we would get in an infinite recursive
|
|
1402 Fsignal/Fthrow loop, so instead we bomb out to the
|
|
1403 really-early-error-handler.
|
|
1404
|
|
1405 Note that in fact the only time that the "last resort"
|
|
1406 occurs is when there's no catch for 'top-level -- the
|
|
1407 'top-level catch and the catch-all error handler are
|
|
1408 established at the same time, in initial_command_loop/
|
|
1409 top_level_1.
|
|
1410
|
|
1411 #### Fix this horrifitude!
|
|
1412 */
|
|
1413
|
|
1414 while (1)
|
|
1415 {
|
|
1416 REGISTER struct catchtag *c;
|
|
1417
|
|
1418 #if 0 /* FSFmacs */
|
|
1419 if (!NILP (tag)) /* #### */
|
|
1420 #endif
|
|
1421 for (c = catchlist; c; c = c->next)
|
|
1422 {
|
|
1423 if (EQ (c->tag, tag))
|
|
1424 unwind_to_catch (c, val);
|
|
1425 }
|
|
1426 if (!bomb_out_p)
|
|
1427 tag = Fsignal (Qno_catch, list2 (tag, val));
|
|
1428 else
|
|
1429 call1 (Qreally_early_error_handler, Fcons (sig, data));
|
|
1430 }
|
|
1431
|
|
1432 /* can't happen. who cares? - (Sun's compiler does) */
|
|
1433 /* throw_level--; */
|
|
1434 /* getting tired of compilation warnings */
|
|
1435 /* return Qnil; */
|
|
1436 }
|
|
1437
|
|
1438 /* See above, where CATCHLIST is defined, for a description of how
|
|
1439 Fthrow() works.
|
|
1440
|
|
1441 Fthrow() is also called by Fsignal(), to do a non-local jump
|
|
1442 back to the appropriate condition-case handler after (maybe)
|
|
1443 the debugger is entered. In that case, TAG is the value
|
|
1444 of Vcondition_handlers that was in place just after the
|
|
1445 condition-case handler was set up. The car of this will be
|
|
1446 some data referring to the handler: Its car will be Qunbound
|
|
1447 (thus, this tag can never be generated by Lisp code), and
|
|
1448 its CDR will be the HANDLERS argument to condition_case_1()
|
|
1449 (either Qerror, Qt, or a list of handlers as in `condition-case').
|
|
1450 This works fine because Fthrow() does not care what TAG was
|
|
1451 passed to it: it just looks up the catch list for something
|
|
1452 that is EQ() to TAG. When it finds it, it will longjmp()
|
|
1453 back to the place that established the catch (in this case,
|
|
1454 condition_case_1). See below for more info.
|
|
1455 */
|
|
1456
|
20
|
1457 DEFUN ("throw", Fthrow, 2, 2, 0, /*
|
0
|
1458 (throw TAG VALUE): throw to the catch for TAG and return VALUE from it.
|
|
1459 Both TAG and VALUE are evalled.
|
20
|
1460 */
|
|
1461 (tag, val))
|
0
|
1462 {
|
|
1463 throw_or_bomb_out (tag, val, 0, Qnil, Qnil); /* Doesn't return */
|
|
1464 return Qnil;
|
|
1465 }
|
|
1466
|
20
|
1467 DEFUN ("unwind-protect", Funwind_protect, 1, UNEVALLED, 0, /*
|
0
|
1468 Do BODYFORM, protecting with UNWINDFORMS.
|
|
1469 Usage looks like (unwind-protect BODYFORM UNWINDFORMS...).
|
|
1470 If BODYFORM completes normally, its value is returned
|
|
1471 after executing the UNWINDFORMS.
|
|
1472 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
|
20
|
1473 */
|
|
1474 (args))
|
0
|
1475 {
|
|
1476 /* This function can GC */
|
|
1477 Lisp_Object val;
|
|
1478 int speccount = specpdl_depth_counter;
|
|
1479
|
|
1480 record_unwind_protect (Fprogn, Fcdr (args));
|
|
1481 val = Feval (Fcar (args));
|
|
1482 return unbind_to (speccount, val);
|
|
1483 }
|
|
1484
|
|
1485
|
|
1486 /**********************************************************************/
|
|
1487 /* Signalling and trapping errors */
|
|
1488 /**********************************************************************/
|
|
1489
|
|
1490 static Lisp_Object
|
|
1491 condition_bind_unwind (Lisp_Object loser)
|
|
1492 {
|
|
1493 struct Lisp_Cons *victim;
|
|
1494 /* ((handler-fun . handler-args) ... other handlers) */
|
|
1495 Lisp_Object tem = XCAR (loser);
|
|
1496
|
|
1497 while (CONSP (tem))
|
|
1498 {
|
|
1499 victim = XCONS (tem);
|
|
1500 tem = victim->cdr;
|
|
1501 free_cons (victim);
|
|
1502 }
|
|
1503 victim = XCONS (loser);
|
|
1504
|
|
1505 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */
|
|
1506 Vcondition_handlers = victim->cdr;
|
|
1507
|
|
1508 free_cons (victim);
|
|
1509 return (Qnil);
|
|
1510 }
|
|
1511
|
|
1512 static Lisp_Object
|
|
1513 condition_case_unwind (Lisp_Object loser)
|
|
1514 {
|
|
1515 struct Lisp_Cons *victim;
|
|
1516
|
|
1517 /* ((<unbound> . clauses) ... other handlers */
|
|
1518 victim = XCONS (XCAR (loser));
|
|
1519 free_cons (victim);
|
|
1520
|
|
1521 victim = XCONS (loser);
|
|
1522 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */
|
|
1523 Vcondition_handlers = victim->cdr;
|
|
1524
|
|
1525 free_cons (victim);
|
|
1526 return (Qnil);
|
|
1527 }
|
|
1528
|
|
1529 /* Split out from condition_case_3 so that primitive C callers
|
|
1530 don't have to cons up a lisp handler form to be evaluated. */
|
|
1531
|
|
1532 /* Call a function BFUN of one argument BARG, trapping errors as
|
|
1533 specified by HANDLERS. If no error occurs that is indicated by
|
|
1534 HANDLERS as something to be caught, the return value of this
|
|
1535 function is the return value from BFUN. If such an error does
|
|
1536 occur, HFUN is called, and its return value becomes the
|
|
1537 return value of condition_case_1(). The second argument passed
|
|
1538 to HFUN will always be HARG. The first argument depends on
|
|
1539 HANDLERS:
|
|
1540
|
|
1541 If HANDLERS is Qt, all errors (this includes QUIT, but not
|
|
1542 non-local exits with `throw') cause HFUN to be invoked, and VAL
|
|
1543 (the first argument to HFUN) is a cons (SIG . DATA) of the
|
|
1544 arguments passed to `signal'. The debugger is not invoked even if
|
|
1545 `debug-on-error' was set.
|
|
1546
|
|
1547 A HANDLERS value of Qerror is the same as Qt except that the
|
|
1548 debugger is invoked if `debug-on-error' was set.
|
|
1549
|
|
1550 Otherwise, HANDLERS should be a list of lists (CONDITION-NAME BODY ...)
|
|
1551 exactly as in `condition-case', and errors will be trapped
|
|
1552 as indicated in HANDLERS. VAL (the first argument to HFUN) will
|
|
1553 be a cons whose car is the cons (SIG . DATA) and whose CDR is the
|
|
1554 list (BODY ...) from the appropriate slot in HANDLERS.
|
|
1555
|
|
1556 This function pushes HANDLERS onto the front of Vcondition_handlers
|
|
1557 (actually with a Qunbound marker as well -- see Fthrow() above
|
|
1558 for why), establishes a catch whose tag is this new value of
|
|
1559 Vcondition_handlers, and calls BFUN. When Fsignal() is called,
|
|
1560 it calls Fthrow(), setting TAG to this same new value of
|
|
1561 Vcondition_handlers and setting VAL to the same thing that will
|
|
1562 be passed to HFUN, as above. Fthrow() longjmp()s back to the
|
|
1563 jump point we just established, and we in turn just call the
|
|
1564 HFUN and return its value.
|
|
1565
|
|
1566 For a real condition-case, HFUN will always be
|
|
1567 run_condition_case_handlers() and HARG is the argument VAR
|
|
1568 to condition-case. That function just binds VAR to the cons
|
|
1569 (SIG . DATA) that is the CAR of VAL, and calls the handler
|
|
1570 (BODY ...) that is the CDR of VAL. Note that before calling
|
|
1571 Fthrow(), Fsignal() restored Vcondition_handlers to the value
|
|
1572 it had *before* condition_case_1() was called. This maintains
|
|
1573 consistency (so that the state of things at exit of
|
|
1574 condition_case_1() is the same as at entry), and implies
|
|
1575 that the handler can signal the same error again (possibly
|
|
1576 after processing of its own), without getting in an infinite
|
|
1577 loop. */
|
|
1578
|
|
1579 Lisp_Object
|
|
1580 condition_case_1 (Lisp_Object handlers,
|
|
1581 Lisp_Object (*bfun) (Lisp_Object barg),
|
|
1582 Lisp_Object barg,
|
|
1583 Lisp_Object (*hfun) (Lisp_Object val, Lisp_Object harg),
|
|
1584 Lisp_Object harg)
|
|
1585 {
|
|
1586 int speccount = specpdl_depth_counter;
|
|
1587 struct catchtag c;
|
|
1588 struct gcpro gcpro1;
|
|
1589
|
|
1590 #if 0 /* FSFmacs */
|
|
1591 c.tag = Qnil;
|
|
1592 #else
|
|
1593 /* Do consing now so out-of-memory error happens up front */
|
|
1594 /* (unbound . stuff) is a special condition-case kludge marker
|
|
1595 which is known specially by Fsignal.
|
|
1596 This is an abomination, but to fix it would require either
|
|
1597 making condition_case cons (a union of the conditions of the clauses)
|
|
1598 or changing the byte-compiler output (no thanks). */
|
|
1599 c.tag = noseeum_cons (noseeum_cons (Qunbound, handlers),
|
|
1600 Vcondition_handlers);
|
|
1601 #endif
|
|
1602 c.val = Qnil;
|
|
1603 c.backlist = backtrace_list;
|
|
1604 #if 0 /* FSFmacs */
|
|
1605 /* #### */
|
|
1606 c.handlerlist = handlerlist;
|
|
1607 #endif
|
|
1608 c.lisp_eval_depth = lisp_eval_depth;
|
|
1609 c.pdlcount = specpdl_depth_counter;
|
|
1610 #if 0 /* FSFmacs */
|
|
1611 c.poll_suppress_count = async_timer_suppress_count;
|
|
1612 #endif
|
|
1613 c.gcpro = gcprolist;
|
|
1614 /* #### FSFmacs does the following statement *after* the setjmp(). */
|
|
1615 c.next = catchlist;
|
|
1616
|
|
1617 if (SETJMP (c.jmp))
|
|
1618 {
|
|
1619 /* throw does ungcpro, etc */
|
|
1620 return ((*hfun) (c.val, harg));
|
|
1621 }
|
|
1622
|
|
1623 record_unwind_protect (condition_case_unwind, c.tag);
|
|
1624
|
|
1625 catchlist = &c;
|
|
1626 #if 0 /* FSFmacs */
|
|
1627 h.handler = handlers;
|
|
1628 h.var = Qnil;
|
|
1629 h.next = handlerlist;
|
|
1630 h.tag = &c;
|
|
1631 handlerlist = &h;
|
|
1632 #else
|
|
1633 Vcondition_handlers = c.tag;
|
|
1634 #endif
|
|
1635 GCPRO1 (harg); /* Somebody has to gc-protect */
|
|
1636
|
|
1637 c.val = ((*bfun) (barg));
|
|
1638
|
|
1639 /* The following is *not* true: (ben)
|
|
1640
|
|
1641 ungcpro, restoring catchlist and condition_handlers are actually
|
|
1642 redundant since unbind_to now restores them. But it looks funny not to
|
|
1643 have this code here, and it doesn't cost anything, so I'm leaving it.*/
|
|
1644 UNGCPRO;
|
|
1645 catchlist = c.next;
|
|
1646 Vcondition_handlers = XCDR (c.tag);
|
|
1647
|
|
1648 return (unbind_to (speccount, c.val));
|
|
1649 }
|
|
1650
|
|
1651 static Lisp_Object
|
|
1652 run_condition_case_handlers (Lisp_Object val, Lisp_Object var)
|
|
1653 {
|
|
1654 /* This function can GC */
|
|
1655 #if 0 /* FSFmacs */
|
|
1656 if (!NILP (h.var))
|
|
1657 specbind (h.var, c.val);
|
|
1658 val = Fprogn (Fcdr (h.chosen_clause));
|
|
1659
|
|
1660 /* Note that this just undoes the binding of h.var; whoever
|
|
1661 longjumped to us unwound the stack to c.pdlcount before
|
|
1662 throwing. */
|
|
1663 unbind_to (c.pdlcount, Qnil);
|
|
1664 return val;
|
|
1665 #else
|
|
1666 int speccount;
|
|
1667
|
|
1668 if (NILP (var))
|
|
1669 return (Fprogn (Fcdr (val))); /* tailcall */
|
|
1670
|
|
1671 speccount = specpdl_depth_counter;
|
|
1672 specbind (var, Fcar (val));
|
|
1673 val = Fprogn (Fcdr (val));
|
|
1674 return unbind_to (speccount, val);
|
|
1675 #endif
|
|
1676 }
|
|
1677
|
|
1678 /* Here for bytecode to call non-consfully. This is exactly like
|
|
1679 condition-case except that it takes three arguments rather
|
|
1680 than a single list of arguments. */
|
|
1681 Lisp_Object
|
|
1682 Fcondition_case_3 (Lisp_Object bodyform,
|
|
1683 Lisp_Object var, Lisp_Object handlers)
|
|
1684 {
|
|
1685 /* This function can GC */
|
|
1686 Lisp_Object val;
|
|
1687
|
|
1688 CHECK_SYMBOL (var);
|
|
1689
|
|
1690 for (val = handlers; ! NILP (val); val = Fcdr (val))
|
|
1691 {
|
|
1692 Lisp_Object tem;
|
|
1693 tem = Fcar (val);
|
|
1694 if ((!NILP (tem))
|
|
1695 && (!CONSP (tem)
|
|
1696 || (!SYMBOLP (XCAR (tem)) && !CONSP (XCAR (tem)))))
|
|
1697 signal_simple_error ("Invalid condition handler", tem);
|
|
1698 }
|
|
1699
|
|
1700 return condition_case_1 (handlers,
|
|
1701 Feval, bodyform,
|
|
1702 run_condition_case_handlers,
|
|
1703 var);
|
|
1704 }
|
|
1705
|
20
|
1706 DEFUN ("condition-case", Fcondition_case, 2, UNEVALLED, 0, /*
|
0
|
1707 Regain control when an error is signalled.
|
|
1708 Usage looks like (condition-case VAR BODYFORM HANDLERS...).
|
|
1709 executes BODYFORM and returns its value if no error happens.
|
|
1710 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
|
|
1711 where the BODY is made of Lisp expressions.
|
|
1712
|
|
1713 A handler is applicable to an error if CONDITION-NAME is one of the
|
|
1714 error's condition names. If an error happens, the first applicable
|
|
1715 handler is run. As a special case, a CONDITION-NAME of t matches
|
|
1716 all errors, even those without the `error' condition name on them
|
|
1717 (e.g. `quit').
|
|
1718
|
|
1719 The car of a handler may be a list of condition names
|
|
1720 instead of a single condition name.
|
|
1721
|
|
1722 When a handler handles an error,
|
|
1723 control returns to the condition-case and the handler BODY... is executed
|
|
1724 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
|
|
1725 VAR may be nil; then you do not get access to the signal information.
|
|
1726
|
|
1727 The value of the last BODY form is returned from the condition-case.
|
|
1728 See also the function `signal' for more info.
|
|
1729
|
|
1730 Note that at the time the condition handler is invoked, the Lisp stack
|
|
1731 and the current catches, condition-cases, and bindings have all been
|
|
1732 popped back to the state they were in just before the call to
|
|
1733 `condition-case'. This means that resignalling the error from
|
|
1734 within the handler will not result in an infinite loop.
|
|
1735
|
|
1736 If you want to establish an error handler that is called with the
|
|
1737 Lisp stack, bindings, etc. as they were when `signal' was called,
|
|
1738 rather than when the handler was set, use `call-with-condition-handler'.
|
20
|
1739 */
|
70
|
1740 (args))
|
0
|
1741 {
|
|
1742 /* This function can GC */
|
|
1743 return Fcondition_case_3 (Fcar (Fcdr (args)),
|
|
1744 Fcar (args),
|
|
1745 Fcdr (Fcdr (args)));
|
|
1746 }
|
|
1747
|
20
|
1748 DEFUN ("call-with-condition-handler", Fcall_with_condition_handler, 2, MANY, 0, /*
|
0
|
1749 Regain control when an error is signalled, without popping the stack.
|
|
1750 Usage looks like (call-with-condition-handler HANDLER FUNCTION &rest ARGS).
|
|
1751 This function is similar to `condition-case', but the handler is invoked
|
|
1752 with the same environment (Lisp stack, bindings, catches, condition-cases)
|
|
1753 that was current when `signal' was called, rather than when the handler
|
|
1754 was established.
|
|
1755
|
|
1756 HANDLER should be a function of one argument, which is a cons of the args
|
|
1757 (SIG . DATA) that were passed to `signal'. It is invoked whenever
|
|
1758 `signal' is called (this differs from `condition-case', which allows
|
|
1759 you to specify which errors are trapped). If the handler function
|
|
1760 returns, `signal' continues as if the handler were never invoked.
|
|
1761 (It continues to look for handlers established earlier than this one,
|
|
1762 and invokes the standard error-handler if none is found.)
|
20
|
1763 */
|
70
|
1764 (int nargs, Lisp_Object *args)) /* Note! Args side-effected! */
|
0
|
1765 {
|
|
1766 /* This function can GC */
|
|
1767 int speccount = specpdl_depth_counter;
|
|
1768 Lisp_Object tem;
|
|
1769
|
|
1770 /* #### If there were a way to check that args[0] were a function
|
|
1771 which accepted one arg, that should be done here ... */
|
|
1772
|
|
1773 /* (handler-fun . handler-args) */
|
|
1774 tem = noseeum_cons (list1 (args[0]), Vcondition_handlers);
|
|
1775 record_unwind_protect (condition_bind_unwind, tem);
|
|
1776 Vcondition_handlers = tem;
|
|
1777
|
|
1778 /* Caller should have GC-protected args */
|
|
1779 tem = Ffuncall (nargs - 1, args + 1);
|
|
1780 return (unbind_to (speccount, tem));
|
|
1781 }
|
|
1782
|
|
1783 static int
|
|
1784 condition_type_p (Lisp_Object type, Lisp_Object conditions)
|
|
1785 {
|
|
1786 if (EQ (type, Qt))
|
|
1787 /* (condition-case c # (t c)) catches -all- signals
|
|
1788 * Use with caution! */
|
|
1789 return (1);
|
|
1790 else
|
|
1791 {
|
|
1792 if (SYMBOLP (type))
|
|
1793 {
|
|
1794 return (!NILP (Fmemq (type, conditions)));
|
|
1795 }
|
|
1796 else if (CONSP (type))
|
|
1797 {
|
|
1798 while (CONSP (type))
|
|
1799 {
|
|
1800 if (!NILP (Fmemq (Fcar (type), conditions)))
|
|
1801 return 1;
|
|
1802 type = XCDR (type);
|
|
1803 }
|
|
1804 return 0;
|
|
1805 }
|
|
1806 else
|
|
1807 return 0;
|
|
1808 }
|
|
1809 }
|
|
1810
|
|
1811 static Lisp_Object
|
|
1812 return_from_signal (Lisp_Object value)
|
|
1813 {
|
|
1814 #if 1 /* RMS Claims: */
|
|
1815 /* Most callers are not prepared to handle gc if this
|
|
1816 returns. So, since this feature is not very useful,
|
|
1817 take it out. */
|
|
1818 /* Have called debugger; return value to signaller */
|
|
1819 return (value);
|
|
1820 #else /* But the reality is that that stinks, because: */
|
|
1821 /* GACK!!! Really want some way for debug-on-quit errors
|
|
1822 to be continuable!! */
|
|
1823 error ("Returning a value from an error is no longer supported");
|
|
1824 #endif
|
|
1825 }
|
|
1826
|
|
1827 extern int in_display;
|
|
1828 extern int gc_in_progress;
|
|
1829
|
|
1830
|
|
1831 /****************** the workhorse error-signaling function ******************/
|
|
1832
|
|
1833 /* #### This function has not been synched with FSF. It diverges
|
|
1834 significantly. */
|
|
1835
|
|
1836 static Lisp_Object
|
|
1837 signal_1 (Lisp_Object sig, Lisp_Object data)
|
|
1838 {
|
|
1839 /* This function can GC */
|
|
1840 struct gcpro gcpro1, gcpro2;
|
|
1841 Lisp_Object conditions;
|
|
1842 Lisp_Object handlers;
|
|
1843 /* signal_call_debugger() could get called more than once
|
|
1844 (once when a call-with-condition-handler is about to
|
|
1845 be dealt with, and another when a condition-case handler
|
|
1846 is about to be invoked). So make sure the debugger and/or
|
|
1847 stack trace aren't done more than once. */
|
|
1848 int stack_trace_displayed = 0;
|
|
1849 int debugger_entered = 0;
|
|
1850 GCPRO2 (conditions, handlers);
|
|
1851
|
|
1852 if (!initialized)
|
|
1853 {
|
|
1854 /* who knows how much has been initialized? Safest bet is
|
|
1855 just to bomb out immediately. */
|
|
1856 fprintf (stderr, "Error before initialization is complete!\n");
|
|
1857 abort ();
|
|
1858 }
|
|
1859
|
|
1860 if (gc_in_progress || in_display)
|
|
1861 /* This is one of many reasons why you can't run lisp code from redisplay.
|
|
1862 There is no sensible way to handle errors there. */
|
|
1863 abort ();
|
|
1864
|
|
1865 conditions = Fget (sig, Qerror_conditions, Qnil);
|
|
1866
|
|
1867 for (handlers = Vcondition_handlers;
|
|
1868 CONSP (handlers);
|
|
1869 handlers = XCDR (handlers))
|
|
1870 {
|
|
1871 Lisp_Object handler_fun = XCAR (XCAR (handlers));
|
|
1872 Lisp_Object handler_data = XCDR (XCAR (handlers));
|
|
1873 Lisp_Object outer_handlers = XCDR (handlers);
|
|
1874
|
|
1875 if (!UNBOUNDP (handler_fun))
|
|
1876 {
|
|
1877 /* call-with-condition-handler */
|
|
1878 Lisp_Object tem;
|
|
1879 Lisp_Object all_handlers = Vcondition_handlers;
|
|
1880 struct gcpro ngcpro1;
|
|
1881 NGCPRO1 (all_handlers);
|
|
1882 Vcondition_handlers = outer_handlers;
|
|
1883
|
|
1884 tem = signal_call_debugger (conditions, sig, data,
|
|
1885 outer_handlers, 1,
|
|
1886 &stack_trace_displayed,
|
|
1887 &debugger_entered);
|
|
1888 if (!UNBOUNDP (tem))
|
|
1889 RETURN_NUNGCPRO (return_from_signal (tem));
|
|
1890
|
|
1891 tem = Fcons (sig, data);
|
|
1892 if (NILP (handler_data))
|
|
1893 tem = call1 (handler_fun, tem);
|
|
1894 else
|
|
1895 {
|
|
1896 /* (This code won't be used (for now?).) */
|
|
1897 struct gcpro nngcpro1;
|
|
1898 Lisp_Object args[3];
|
|
1899 NNGCPRO1 (args[0]);
|
|
1900 nngcpro1.nvars = 3;
|
|
1901 args[0] = handler_fun;
|
|
1902 args[1] = tem;
|
|
1903 args[2] = handler_data;
|
|
1904 nngcpro1.var = args;
|
|
1905 tem = Fapply (3, args);
|
|
1906 NNUNGCPRO;
|
|
1907 }
|
|
1908 NUNGCPRO;
|
|
1909 #if 0
|
|
1910 if (!EQ (tem, Qsignal))
|
|
1911 return (return_from_signal (tem));
|
|
1912 #endif
|
|
1913 /* If handler didn't throw, try another handler */
|
|
1914 Vcondition_handlers = all_handlers;
|
|
1915 }
|
|
1916
|
|
1917 /* It's a condition-case handler */
|
|
1918
|
|
1919 /* t is used by handlers for all conditions, set up by C code.
|
|
1920 * debugger is not called even if debug_on_error */
|
|
1921 else if (EQ (handler_data, Qt))
|
|
1922 {
|
|
1923 UNGCPRO;
|
|
1924 return (Fthrow (handlers, Fcons (sig, data)));
|
|
1925 }
|
|
1926 /* `error' is used similarly to the way `t' is used, but in
|
|
1927 addition it invokes the debugger if debug_on_error.
|
|
1928 This is normally used for the outer command-loop error
|
|
1929 handler. */
|
|
1930 else if (EQ (handler_data, Qerror))
|
|
1931 {
|
|
1932 Lisp_Object tem = signal_call_debugger (conditions, sig, data,
|
|
1933 outer_handlers, 0,
|
|
1934 &stack_trace_displayed,
|
|
1935 &debugger_entered);
|
|
1936
|
|
1937 UNGCPRO;
|
|
1938 if (!UNBOUNDP (tem))
|
|
1939 return (return_from_signal (tem));
|
|
1940
|
|
1941 tem = Fcons (sig, data);
|
|
1942 return (Fthrow (handlers, tem));
|
|
1943 }
|
|
1944 else
|
|
1945 {
|
|
1946 /* handler established by real (Lisp) condition-case */
|
|
1947 Lisp_Object h;
|
|
1948
|
|
1949 for (h = handler_data; CONSP (h); h = Fcdr (h))
|
|
1950 {
|
|
1951 Lisp_Object clause = Fcar (h);
|
|
1952 Lisp_Object tem = Fcar (clause);
|
|
1953
|
|
1954 if (condition_type_p (tem, conditions))
|
|
1955 {
|
|
1956 tem = signal_call_debugger (conditions, sig, data,
|
|
1957 outer_handlers, 1,
|
|
1958 &stack_trace_displayed,
|
|
1959 &debugger_entered);
|
|
1960 UNGCPRO;
|
|
1961 if (!UNBOUNDP (tem))
|
|
1962 return (return_from_signal (tem));
|
|
1963
|
|
1964 /* Doesn't return */
|
|
1965 tem = Fcons (Fcons (sig, data), Fcdr (clause));
|
|
1966 return (Fthrow (handlers, tem));
|
|
1967 }
|
|
1968 }
|
|
1969 }
|
|
1970 }
|
|
1971
|
|
1972 /* If no handler is present now, try to run the debugger,
|
|
1973 and if that fails, throw to top level.
|
|
1974
|
|
1975 #### The only time that no handler is present is during
|
|
1976 temacs or perhaps very early in XEmacs. In both cases,
|
|
1977 there is no 'top-level catch. (That's why the
|
|
1978 "bomb-out" hack was added.)
|
|
1979
|
|
1980 #### Fix this horrifitude!
|
|
1981 */
|
|
1982 signal_call_debugger (conditions, sig, data, Qnil, 0,
|
|
1983 &stack_trace_displayed,
|
|
1984 &debugger_entered);
|
|
1985 UNGCPRO;
|
|
1986 throw_or_bomb_out (Qtop_level, Qt, 1, sig, data); /* Doesn't return */
|
|
1987 return Qnil;
|
|
1988 }
|
|
1989
|
|
1990
|
|
1991 /****************** Error functions class 1 ******************/
|
|
1992
|
|
1993 /* Class 1: General functions that signal an error.
|
|
1994 These functions take an error type and a list of associated error
|
|
1995 data. */
|
|
1996
|
|
1997 /* The simplest external error function: it would be called
|
|
1998 signal_continuable_error() in the terminology below, but it's
|
|
1999 Lisp-callable. */
|
|
2000
|
20
|
2001 DEFUN ("signal", Fsignal, 2, 2, 0, /*
|
0
|
2002 Signal a continuable error. Args are ERROR-SYMBOL, and associated DATA.
|
|
2003 An error symbol is a symbol defined using `define-error'.
|
|
2004 DATA should be a list. Its elements are printed as part of the error message.
|
|
2005 If the signal is handled, DATA is made available to the handler.
|
|
2006 See also the function `signal-error', and the functions to handle errors:
|
|
2007 `condition-case' and `call-with-condition-handler'.
|
|
2008
|
|
2009 Note that this function can return, if the debugger is invoked and the
|
|
2010 user invokes the "return from signal" option.
|
20
|
2011 */
|
|
2012 (error_symbol, data))
|
0
|
2013 {
|
|
2014 /* Fsignal() is one of these functions that's called all the time
|
|
2015 with newly-created Lisp objects. We allow this; but we must GC-
|
|
2016 protect the objects because all sorts of weird stuff could
|
|
2017 happen. */
|
|
2018
|
|
2019 struct gcpro gcpro1;
|
|
2020
|
|
2021 GCPRO1 (data);
|
|
2022 if (!NILP (Vcurrent_error_state))
|
|
2023 {
|
|
2024 if (!NILP (Vcurrent_warning_class))
|
|
2025 warn_when_safe_lispobj (Vcurrent_warning_class, Qwarning,
|
|
2026 Fcons (error_symbol, data));
|
|
2027 Fthrow (Qunbound_suspended_errors_tag, Qnil);
|
|
2028 abort (); /* Better not get here! */
|
|
2029 }
|
|
2030 RETURN_UNGCPRO (signal_1 (error_symbol, data));
|
|
2031 }
|
|
2032
|
|
2033 /* Signal a non-continuable error. */
|
|
2034
|
|
2035 DOESNT_RETURN
|
|
2036 signal_error (Lisp_Object sig, Lisp_Object data)
|
|
2037 {
|
|
2038 for (;;)
|
|
2039 Fsignal (sig, data);
|
|
2040 }
|
|
2041
|
|
2042 static Lisp_Object
|
|
2043 call_with_suspended_errors_1 (Lisp_Object opaque_arg)
|
|
2044 {
|
|
2045 Lisp_Object *kludgy_args = (Lisp_Object *) get_opaque_ptr (opaque_arg);
|
74
|
2046 return (primitive_funcall ((lisp_fn_t) get_opaque_ptr (kludgy_args[0]),
|
|
2047 XINT (kludgy_args[1]), kludgy_args + 2));
|
0
|
2048 }
|
|
2049
|
|
2050 static Lisp_Object
|
|
2051 restore_current_warning_class (Lisp_Object warning_class)
|
|
2052 {
|
|
2053 Vcurrent_warning_class = warning_class;
|
|
2054 return Qnil;
|
|
2055 }
|
|
2056
|
|
2057 static Lisp_Object
|
|
2058 restore_current_error_state (Lisp_Object error_state)
|
|
2059 {
|
|
2060 Vcurrent_error_state = error_state;
|
|
2061 return Qnil;
|
|
2062 }
|
|
2063
|
|
2064 /* Many functions would like to do one of three things if an error
|
|
2065 occurs:
|
|
2066
|
|
2067 (1) signal the error, as usual.
|
|
2068 (2) silently fail and return some error value.
|
|
2069 (3) do as (2) but issue a warning in the process.
|
|
2070
|
|
2071 Currently there's lots of stuff that passes an Error_behavior
|
|
2072 value and calls maybe_signal_error() and other such functions.
|
|
2073 This approach is inherently error-prone and broken. A much
|
|
2074 more robust and easier approach is to use call_with_suspended_errors().
|
|
2075 Wrap this around any function in which you might want errors
|
|
2076 to not be errors.
|
|
2077 */
|
|
2078
|
|
2079 Lisp_Object
|
74
|
2080 call_with_suspended_errors (lisp_fn_t fun, Lisp_Object retval,
|
0
|
2081 Lisp_Object class, Error_behavior errb,
|
|
2082 int nargs, ...)
|
|
2083 {
|
|
2084 va_list vargs;
|
|
2085 int speccount;
|
|
2086 Lisp_Object kludgy_args[22];
|
|
2087 Lisp_Object *args = kludgy_args + 2;
|
|
2088 int i;
|
|
2089 Lisp_Object no_error;
|
|
2090
|
|
2091 assert (SYMBOLP (class)); /* sanity-check */
|
|
2092 assert (!NILP (class));
|
|
2093 assert (nargs >= 0 && nargs < 20);
|
|
2094
|
|
2095 /* ERROR_ME means don't trap errors. (However, if errors are
|
|
2096 already trapped, we leave them trapped.)
|
|
2097
|
|
2098 Otherwise, we trap errors, and trap warnings if ERROR_ME_WARN.
|
|
2099
|
|
2100 If ERROR_ME_NOT, it causes no warnings even if warnings
|
|
2101 were previously enabled. However, we never change the
|
|
2102 warning class from one to another. */
|
|
2103 if (!ERRB_EQ (errb, ERROR_ME))
|
|
2104 {
|
|
2105 if (ERRB_EQ (errb, ERROR_ME_NOT)) /* person wants no warnings */
|
|
2106 class = Qnil;
|
|
2107 errb = ERROR_ME_NOT;
|
|
2108 no_error = Qt;
|
|
2109 }
|
|
2110 else
|
|
2111 no_error = Qnil;
|
|
2112
|
|
2113 va_start (vargs, nargs);
|
|
2114 for (i = 0; i < nargs; i++)
|
|
2115 args[i] = va_arg (vargs, Lisp_Object);
|
|
2116 va_end (vargs);
|
|
2117
|
|
2118 /* If error-checking is not disabled, just call the function.
|
|
2119 It's important not to override disabled error-checking with
|
|
2120 enabled error-checking. */
|
|
2121
|
|
2122 if (ERRB_EQ (errb, ERROR_ME))
|
|
2123 return primitive_funcall (fun, nargs, args);
|
|
2124
|
|
2125 speccount = specpdl_depth ();
|
|
2126 if (NILP (class) || NILP (Vcurrent_warning_class))
|
|
2127 {
|
|
2128 /* If we're currently calling for no warnings, then make it so.
|
|
2129 If we're currently calling for warnings and we weren't
|
|
2130 previously, then set our warning class; otherwise, leave
|
|
2131 the existing one alone. */
|
|
2132 record_unwind_protect (restore_current_warning_class,
|
|
2133 Vcurrent_warning_class);
|
|
2134 Vcurrent_warning_class = class;
|
|
2135 }
|
|
2136 if (!EQ (Vcurrent_error_state, no_error))
|
|
2137 {
|
|
2138 record_unwind_protect (restore_current_error_state,
|
|
2139 Vcurrent_error_state);
|
|
2140 Vcurrent_error_state = no_error;
|
|
2141 }
|
|
2142
|
|
2143 {
|
|
2144 int threw;
|
|
2145 Lisp_Object the_retval;
|
|
2146 Lisp_Object opaque1 = make_opaque_ptr (kludgy_args);
|
|
2147 Lisp_Object opaque2 = make_opaque_ptr ((void *) fun);
|
|
2148 struct gcpro gcpro1, gcpro2;
|
|
2149
|
|
2150 GCPRO2 (opaque1, opaque2);
|
|
2151 kludgy_args[0] = opaque2;
|
|
2152 kludgy_args[1] = make_int (nargs);
|
|
2153 the_retval = internal_catch (Qunbound_suspended_errors_tag,
|
|
2154 call_with_suspended_errors_1,
|
|
2155 opaque1, &threw);
|
|
2156 free_opaque_ptr (opaque1);
|
|
2157 free_opaque_ptr (opaque2);
|
|
2158 UNGCPRO;
|
|
2159 /* Use the returned value except in non-local exit, when
|
|
2160 RETVAL applies. */
|
|
2161 if (!threw)
|
|
2162 retval = the_retval;
|
|
2163 return unbind_to (speccount, retval);
|
|
2164 }
|
|
2165 }
|
|
2166
|
|
2167 /* Signal a non-continuable error or display a warning or do nothing,
|
|
2168 according to ERRB. CLASS is the class of warning and should
|
|
2169 refer to what sort of operation is being done (e.g. Qtoolbar,
|
|
2170 Qresource, etc.). */
|
|
2171
|
|
2172 void
|
|
2173 maybe_signal_error (Lisp_Object sig, Lisp_Object data, Lisp_Object class,
|
|
2174 Error_behavior errb)
|
|
2175 {
|
|
2176 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2177 return;
|
|
2178 else if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2179 warn_when_safe_lispobj (class, Qwarning, Fcons (sig, data));
|
|
2180 else
|
|
2181 for (;;)
|
|
2182 Fsignal (sig, data);
|
|
2183 }
|
|
2184
|
|
2185 /* Signal a continuable error or display a warning or do nothing,
|
|
2186 according to ERRB. */
|
|
2187
|
|
2188 Lisp_Object
|
|
2189 maybe_signal_continuable_error (Lisp_Object sig, Lisp_Object data,
|
|
2190 Lisp_Object class, Error_behavior errb)
|
|
2191 {
|
|
2192 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2193 return Qnil;
|
|
2194 else if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2195 {
|
|
2196 warn_when_safe_lispobj (class, Qwarning, Fcons (sig, data));
|
|
2197 return Qnil;
|
|
2198 }
|
|
2199 else
|
|
2200 return Fsignal (sig, data);
|
|
2201 }
|
|
2202
|
|
2203
|
|
2204 /****************** Error functions class 2 ******************/
|
|
2205
|
|
2206 /* Class 2: Printf-like functions that signal an error.
|
|
2207 These functions signal an error of type Qerror, whose data
|
|
2208 is a single string, created using the arguments. */
|
|
2209
|
|
2210 /* dump an error message; called like printf */
|
|
2211
|
|
2212 DOESNT_RETURN
|
|
2213 error (CONST char *fmt, ...)
|
|
2214 {
|
|
2215 Lisp_Object obj;
|
|
2216 va_list args;
|
|
2217
|
|
2218 va_start (args, fmt);
|
|
2219 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2220 args);
|
|
2221 va_end (args);
|
|
2222
|
|
2223 /* Fsignal GC-protects its args */
|
|
2224 signal_error (Qerror, list1 (obj));
|
|
2225 }
|
|
2226
|
|
2227 void
|
|
2228 maybe_error (Lisp_Object class, Error_behavior errb, CONST char *fmt, ...)
|
|
2229 {
|
|
2230 Lisp_Object obj;
|
|
2231 va_list args;
|
|
2232
|
|
2233 /* Optimization: */
|
|
2234 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2235 return;
|
|
2236
|
|
2237 va_start (args, fmt);
|
|
2238 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2239 args);
|
|
2240 va_end (args);
|
|
2241
|
|
2242 /* Fsignal GC-protects its args */
|
|
2243 maybe_signal_error (Qerror, list1 (obj), class, errb);
|
|
2244 }
|
|
2245
|
|
2246 Lisp_Object
|
|
2247 continuable_error (CONST char *fmt, ...)
|
|
2248 {
|
|
2249 Lisp_Object obj;
|
|
2250 va_list args;
|
|
2251
|
|
2252 va_start (args, fmt);
|
|
2253 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2254 args);
|
|
2255 va_end (args);
|
|
2256
|
|
2257 /* Fsignal GC-protects its args */
|
|
2258 return Fsignal (Qerror, list1 (obj));
|
|
2259 }
|
|
2260
|
|
2261 Lisp_Object
|
|
2262 maybe_continuable_error (Lisp_Object class, Error_behavior errb,
|
|
2263 CONST char *fmt, ...)
|
|
2264 {
|
|
2265 Lisp_Object obj;
|
|
2266 va_list args;
|
|
2267
|
|
2268 /* Optimization: */
|
|
2269 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2270 return Qnil;
|
|
2271
|
|
2272 va_start (args, fmt);
|
|
2273 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2274 args);
|
|
2275 va_end (args);
|
|
2276
|
|
2277 /* Fsignal GC-protects its args */
|
|
2278 return maybe_signal_continuable_error (Qerror, list1 (obj), class, errb);
|
|
2279 }
|
|
2280
|
|
2281
|
|
2282 /****************** Error functions class 3 ******************/
|
|
2283
|
|
2284 /* Class 3: Signal an error with a string and an associated object.
|
|
2285 These functions signal an error of type Qerror, whose data
|
|
2286 is two objects, a string and a related Lisp object (usually the object
|
|
2287 where the error is occurring). */
|
|
2288
|
|
2289 DOESNT_RETURN
|
|
2290 signal_simple_error (CONST char *reason, Lisp_Object frob)
|
|
2291 {
|
|
2292 signal_error (Qerror, list2 (build_translated_string (reason), frob));
|
|
2293 }
|
|
2294
|
|
2295 void
|
|
2296 maybe_signal_simple_error (CONST char *reason, Lisp_Object frob,
|
|
2297 Lisp_Object class, Error_behavior errb)
|
|
2298 {
|
|
2299 /* Optimization: */
|
|
2300 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2301 return;
|
|
2302 maybe_signal_error (Qerror, list2 (build_translated_string (reason), frob),
|
|
2303 class, errb);
|
|
2304 }
|
|
2305
|
|
2306 Lisp_Object
|
|
2307 signal_simple_continuable_error (CONST char *reason, Lisp_Object frob)
|
|
2308 {
|
|
2309 return Fsignal (Qerror, list2 (build_translated_string (reason), frob));
|
|
2310 }
|
|
2311
|
|
2312 Lisp_Object
|
|
2313 maybe_signal_simple_continuable_error (CONST char *reason, Lisp_Object frob,
|
|
2314 Lisp_Object class, Error_behavior errb)
|
|
2315 {
|
|
2316 /* Optimization: */
|
|
2317 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2318 return Qnil;
|
|
2319 return maybe_signal_continuable_error
|
|
2320 (Qerror, list2 (build_translated_string (reason),
|
|
2321 frob), class, errb);
|
|
2322 }
|
|
2323
|
|
2324
|
|
2325 /****************** Error functions class 4 ******************/
|
|
2326
|
|
2327 /* Class 4: Printf-like functions that signal an error.
|
|
2328 These functions signal an error of type Qerror, whose data
|
|
2329 is a two objects, a string (created using the arguments) and a
|
|
2330 Lisp object.
|
|
2331 */
|
|
2332
|
|
2333 DOESNT_RETURN
|
|
2334 error_with_frob (Lisp_Object frob, CONST char *fmt, ...)
|
|
2335 {
|
|
2336 Lisp_Object obj;
|
|
2337 va_list args;
|
|
2338
|
|
2339 va_start (args, fmt);
|
|
2340 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2341 args);
|
|
2342 va_end (args);
|
|
2343
|
|
2344 /* Fsignal GC-protects its args */
|
|
2345 signal_error (Qerror, list2 (obj, frob));
|
|
2346 }
|
|
2347
|
|
2348 void
|
|
2349 maybe_error_with_frob (Lisp_Object frob, Lisp_Object class,
|
|
2350 Error_behavior errb, CONST char *fmt, ...)
|
|
2351 {
|
|
2352 Lisp_Object obj;
|
|
2353 va_list args;
|
|
2354
|
|
2355 /* Optimization: */
|
|
2356 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2357 return;
|
|
2358
|
|
2359 va_start (args, fmt);
|
|
2360 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2361 args);
|
|
2362 va_end (args);
|
|
2363
|
|
2364 /* Fsignal GC-protects its args */
|
|
2365 maybe_signal_error (Qerror, list2 (obj, frob), class, errb);
|
|
2366 }
|
|
2367
|
|
2368 Lisp_Object
|
|
2369 continuable_error_with_frob (Lisp_Object frob, CONST char *fmt, ...)
|
|
2370 {
|
|
2371 Lisp_Object obj;
|
|
2372 va_list args;
|
|
2373
|
|
2374 va_start (args, fmt);
|
|
2375 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2376 args);
|
|
2377 va_end (args);
|
|
2378
|
|
2379 /* Fsignal GC-protects its args */
|
|
2380 return Fsignal (Qerror, list2 (obj, frob));
|
|
2381 }
|
|
2382
|
|
2383 Lisp_Object
|
|
2384 maybe_continuable_error_with_frob (Lisp_Object frob, Lisp_Object class,
|
|
2385 Error_behavior errb, CONST char *fmt, ...)
|
|
2386 {
|
|
2387 Lisp_Object obj;
|
|
2388 va_list args;
|
|
2389
|
|
2390 /* Optimization: */
|
|
2391 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2392 return Qnil;
|
|
2393
|
|
2394 va_start (args, fmt);
|
|
2395 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2396 args);
|
|
2397 va_end (args);
|
|
2398
|
|
2399 /* Fsignal GC-protects its args */
|
|
2400 return maybe_signal_continuable_error (Qerror, list2 (obj, frob),
|
|
2401 class, errb);
|
|
2402 }
|
|
2403
|
|
2404
|
|
2405 /****************** Error functions class 5 ******************/
|
|
2406
|
|
2407 /* Class 5: Signal an error with a string and two associated objects.
|
|
2408 These functions signal an error of type Qerror, whose data
|
|
2409 is three objects, a string and two related Lisp objects. */
|
|
2410
|
|
2411 DOESNT_RETURN
|
|
2412 signal_simple_error_2 (CONST char *reason,
|
|
2413 Lisp_Object frob0, Lisp_Object frob1)
|
|
2414 {
|
|
2415 signal_error (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2416 frob1));
|
|
2417 }
|
|
2418
|
|
2419 void
|
|
2420 maybe_signal_simple_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2421 Lisp_Object frob1, Lisp_Object class,
|
|
2422 Error_behavior errb)
|
|
2423 {
|
|
2424 /* Optimization: */
|
|
2425 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2426 return;
|
|
2427 maybe_signal_error (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2428 frob1), class, errb);
|
|
2429 }
|
|
2430
|
|
2431
|
|
2432 Lisp_Object
|
|
2433 signal_simple_continuable_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2434 Lisp_Object frob1)
|
|
2435 {
|
|
2436 return Fsignal (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2437 frob1));
|
|
2438 }
|
|
2439
|
|
2440 Lisp_Object
|
|
2441 maybe_signal_simple_continuable_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2442 Lisp_Object frob1, Lisp_Object class,
|
|
2443 Error_behavior errb)
|
|
2444 {
|
|
2445 /* Optimization: */
|
|
2446 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2447 return Qnil;
|
|
2448 return maybe_signal_continuable_error
|
|
2449 (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2450 frob1),
|
|
2451 class, errb);
|
|
2452 }
|
|
2453
|
|
2454
|
|
2455 /* This is what the QUIT macro calls to signal a quit */
|
|
2456 void
|
|
2457 signal_quit (void)
|
|
2458 {
|
|
2459 /* This function can GC */
|
|
2460 if (EQ (Vquit_flag, Qcritical))
|
|
2461 debug_on_quit |= 2; /* set critical bit. */
|
|
2462 Vquit_flag = Qnil;
|
|
2463 /* note that this is continuable. */
|
|
2464 Fsignal (Qquit, Qnil);
|
|
2465 }
|
|
2466
|
|
2467
|
149
|
2468 DEFUN ("strerror", Fstrerror, 1, 1, 0, /*
|
|
2469 Return the error string associated with integer ERRNUM.
|
|
2470 This function is an interface to strerror(3).
|
|
2471 The returned string may or may not be translated.
|
|
2472 */
|
|
2473 (errnum))
|
|
2474 {
|
|
2475 CHECK_INT (errnum);
|
|
2476 return build_ext_string (strerror (XINT (errnum)), FORMAT_NATIVE);
|
|
2477 }
|
|
2478
|
|
2479
|
0
|
2480 /**********************************************************************/
|
|
2481 /* User commands */
|
|
2482 /**********************************************************************/
|
|
2483
|
20
|
2484 DEFUN ("commandp", Fcommandp, 1, 1, 0, /*
|
0
|
2485 T if FUNCTION makes provisions for interactive calling.
|
|
2486 This means it contains a description for how to read arguments to give it.
|
|
2487 The value is nil for an invalid function or a symbol with no function
|
|
2488 definition.
|
|
2489
|
|
2490 Interactively callable functions include
|
|
2491
|
|
2492 -- strings and vectors (treated as keyboard macros)
|
|
2493 -- lambda-expressions that contain a top-level call to `interactive'
|
|
2494 -- autoload definitions made by `autoload' with non-nil fourth argument
|
|
2495 (i.e. the interactive flag)
|
|
2496 -- compiled-function objects with a non-nil `compiled-function-interactive'
|
|
2497 value
|
|
2498 -- subrs (built-in functions) that are interactively callable
|
|
2499
|
|
2500 Also, a symbol satisfies `commandp' if its function definition does so.
|
20
|
2501 */
|
|
2502 (function))
|
0
|
2503 {
|
|
2504 REGISTER Lisp_Object fun;
|
|
2505 REGISTER Lisp_Object funcar;
|
|
2506
|
|
2507 fun = function;
|
|
2508
|
|
2509 fun = indirect_function (fun, 0);
|
|
2510 if (UNBOUNDP (fun))
|
|
2511 return Qnil;
|
|
2512
|
|
2513 /* Emacs primitives are interactive if their DEFUN specifies an
|
|
2514 interactive spec. */
|
|
2515 if (SUBRP (fun))
|
149
|
2516 return XSUBR (fun)->prompt ? Qt : Qnil;
|
|
2517
|
|
2518 if (COMPILED_FUNCTIONP (fun))
|
|
2519 return XCOMPILED_FUNCTION (fun)->flags.interactivep ? Qt : Qnil;
|
0
|
2520
|
|
2521 /* Strings and vectors are keyboard macros. */
|
|
2522 if (VECTORP (fun) || STRINGP (fun))
|
|
2523 return Qt;
|
|
2524
|
|
2525 /* Lists may represent commands. */
|
|
2526 if (!CONSP (fun))
|
|
2527 return Qnil;
|
|
2528 funcar = Fcar (fun);
|
|
2529 if (!SYMBOLP (funcar))
|
|
2530 return Fsignal (Qinvalid_function, list1 (fun));
|
|
2531 if (EQ (funcar, Qlambda))
|
|
2532 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
|
|
2533 if (EQ (funcar, Qautoload))
|
|
2534 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
|
|
2535 else
|
|
2536 return Qnil;
|
|
2537 }
|
|
2538
|
20
|
2539 DEFUN ("command-execute", Fcommand_execute, 1, 3, 0, /*
|
0
|
2540 Execute CMD as an editor command.
|
|
2541 CMD must be an object that satisfies the `commandp' predicate.
|
|
2542 Optional second arg RECORD-FLAG is as in `call-interactively'.
|
|
2543 The argument KEYS specifies the value to use instead of (this-command-keys)
|
|
2544 when reading the arguments.
|
20
|
2545 */
|
|
2546 (cmd, record, keys))
|
0
|
2547 {
|
|
2548 /* This function can GC */
|
|
2549 Lisp_Object prefixarg;
|
|
2550 Lisp_Object final = cmd;
|
|
2551 struct backtrace backtrace;
|
|
2552 struct console *con = XCONSOLE (Vselected_console);
|
|
2553
|
|
2554 prefixarg = con->prefix_arg;
|
|
2555 con->prefix_arg = Qnil;
|
|
2556 Vcurrent_prefix_arg = prefixarg;
|
|
2557 debug_on_next_call = 0; /* #### from FSFmacs; correct? */
|
|
2558
|
|
2559 if (SYMBOLP (cmd) && !NILP (Fget (cmd, Qdisabled, Qnil)))
|
|
2560 return run_hook (Vdisabled_command_hook);
|
|
2561
|
|
2562 for (;;)
|
|
2563 {
|
|
2564 final = indirect_function (cmd, 1);
|
|
2565 if (CONSP (final) && EQ (Fcar (final), Qautoload))
|
|
2566 do_autoload (final, cmd);
|
|
2567 else
|
|
2568 break;
|
|
2569 }
|
|
2570
|
|
2571 if (CONSP (final) || SUBRP (final) || COMPILED_FUNCTIONP (final))
|
|
2572 {
|
|
2573 #ifdef EMACS_BTL
|
|
2574 backtrace.id_number = 0;
|
|
2575 #endif
|
|
2576 backtrace.function = &Qcall_interactively;
|
|
2577 backtrace.args = &cmd;
|
|
2578 backtrace.nargs = 1;
|
|
2579 backtrace.evalargs = 0;
|
|
2580 backtrace.pdlcount = specpdl_depth ();
|
|
2581 backtrace.debug_on_exit = 0;
|
116
|
2582 PUSH_BACKTRACE (backtrace);
|
0
|
2583
|
|
2584 final = Fcall_interactively (cmd, record, keys);
|
|
2585
|
116
|
2586 POP_BACKTRACE (backtrace);
|
0
|
2587 return (final);
|
|
2588 }
|
|
2589 else if (STRINGP (final) || VECTORP (final))
|
|
2590 {
|
|
2591 return Fexecute_kbd_macro (final, prefixarg);
|
|
2592 }
|
|
2593 else
|
|
2594 {
|
|
2595 Fsignal (Qwrong_type_argument,
|
|
2596 Fcons (Qcommandp,
|
|
2597 ((EQ (cmd, final))
|
|
2598 ? list1 (cmd)
|
|
2599 : list2 (cmd, final))));
|
|
2600 return Qnil;
|
|
2601 }
|
|
2602 }
|
|
2603
|
20
|
2604 DEFUN ("interactive-p", Finteractive_p, 0, 0, 0, /*
|
0
|
2605 Return t if function in which this appears was called interactively.
|
|
2606 This means that the function was called with call-interactively (which
|
|
2607 includes being called as the binding of a key)
|
|
2608 and input is currently coming from the keyboard (not in keyboard macro).
|
20
|
2609 */
|
|
2610 ())
|
0
|
2611 {
|
|
2612 REGISTER struct backtrace *btp;
|
|
2613 REGISTER Lisp_Object fun;
|
|
2614
|
|
2615 if (!INTERACTIVE)
|
|
2616 return Qnil;
|
|
2617
|
|
2618 /* Unless the object was compiled, skip the frame of interactive-p itself
|
|
2619 (if interpreted) or the frame of byte-code (if called from a compiled
|
|
2620 function). Note that *btp->function may be a symbol pointing at a
|
|
2621 compiled function. */
|
|
2622 btp = backtrace_list;
|
|
2623
|
|
2624 #if 0 /* FSFmacs */
|
|
2625
|
|
2626 /* #### FSFmacs does the following instead. I can't figure
|
|
2627 out which one is more correct. */
|
|
2628 /* If this isn't a byte-compiled function, there may be a frame at
|
|
2629 the top for Finteractive_p itself. If so, skip it. */
|
|
2630 fun = Findirect_function (*btp->function);
|
|
2631 if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p)
|
|
2632 btp = btp->next;
|
|
2633
|
|
2634 /* If we're running an Emacs 18-style byte-compiled function, there
|
|
2635 may be a frame for Fbyte_code. Now, given the strictest
|
|
2636 definition, this function isn't really being called
|
|
2637 interactively, but because that's the way Emacs 18 always builds
|
|
2638 byte-compiled functions, we'll accept it for now. */
|
|
2639 if (EQ (*btp->function, Qbyte_code))
|
|
2640 btp = btp->next;
|
|
2641
|
|
2642 /* If this isn't a byte-compiled function, then we may now be
|
|
2643 looking at several frames for special forms. Skip past them. */
|
|
2644 while (btp &&
|
|
2645 btp->nargs == UNEVALLED)
|
|
2646 btp = btp->next;
|
|
2647
|
|
2648 #else
|
|
2649
|
|
2650 if (! (COMPILED_FUNCTIONP (Findirect_function (*btp->function))))
|
|
2651 btp = btp->next;
|
|
2652 for (;
|
|
2653 btp && (btp->nargs == UNEVALLED
|
|
2654 || EQ (*btp->function, Qbyte_code));
|
|
2655 btp = btp->next)
|
|
2656 {}
|
|
2657 /* btp now points at the frame of the innermost function
|
|
2658 that DOES eval its args.
|
|
2659 If it is a built-in function (such as load or eval-region)
|
|
2660 return nil. */
|
|
2661 /* Beats me why this is necessary, but it is */
|
|
2662 if (btp && EQ (*btp->function, Qcall_interactively))
|
|
2663 return Qt;
|
|
2664
|
|
2665 #endif
|
|
2666
|
|
2667 fun = Findirect_function (*btp->function);
|
|
2668 if (SUBRP (fun))
|
|
2669 return Qnil;
|
|
2670 /* btp points to the frame of a Lisp function that called interactive-p.
|
|
2671 Return t if that function was called interactively. */
|
|
2672 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
|
|
2673 return Qt;
|
|
2674 return Qnil;
|
|
2675 }
|
|
2676
|
|
2677
|
|
2678 /**********************************************************************/
|
|
2679 /* Autoloading */
|
|
2680 /**********************************************************************/
|
|
2681
|
20
|
2682 DEFUN ("autoload", Fautoload, 2, 5, 0, /*
|
0
|
2683 Define FUNCTION to autoload from FILE.
|
|
2684 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
|
|
2685 Third arg DOCSTRING is documentation for the function.
|
|
2686 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
|
|
2687 Fifth arg TYPE indicates the type of the object:
|
|
2688 nil or omitted says FUNCTION is a function,
|
|
2689 `keymap' says FUNCTION is really a keymap, and
|
|
2690 `macro' or t says FUNCTION is really a macro.
|
|
2691 Third through fifth args give info about the real definition.
|
|
2692 They default to nil.
|
|
2693 If FUNCTION is already defined other than as an autoload,
|
|
2694 this does nothing and returns nil.
|
20
|
2695 */
|
|
2696 (function, file, docstring, interactive, type))
|
0
|
2697 {
|
|
2698 /* This function can GC */
|
|
2699 CHECK_SYMBOL (function);
|
|
2700 CHECK_STRING (file);
|
|
2701
|
|
2702 /* If function is defined and not as an autoload, don't override */
|
|
2703 if (!UNBOUNDP (XSYMBOL (function)->function)
|
|
2704 && !(CONSP (XSYMBOL (function)->function)
|
|
2705 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
|
|
2706 return Qnil;
|
|
2707
|
|
2708 if (purify_flag)
|
|
2709 {
|
|
2710 /* Attempt to avoid consing identical (string=) pure strings. */
|
|
2711 file = Fsymbol_name (Fintern (file, Qnil));
|
|
2712 }
|
|
2713
|
|
2714 return Ffset (function,
|
|
2715 Fpurecopy (Fcons (Qautoload, list4 (file,
|
|
2716 docstring,
|
|
2717 interactive,
|
|
2718 type))));
|
|
2719 }
|
|
2720
|
|
2721 Lisp_Object
|
|
2722 un_autoload (Lisp_Object oldqueue)
|
|
2723 {
|
|
2724 /* This function can GC */
|
|
2725 REGISTER Lisp_Object queue, first, second;
|
|
2726
|
|
2727 /* Queue to unwind is current value of Vautoload_queue.
|
|
2728 oldqueue is the shadowed value to leave in Vautoload_queue. */
|
|
2729 queue = Vautoload_queue;
|
|
2730 Vautoload_queue = oldqueue;
|
|
2731 while (CONSP (queue))
|
|
2732 {
|
|
2733 first = Fcar (queue);
|
|
2734 second = Fcdr (first);
|
|
2735 first = Fcar (first);
|
|
2736 if (NILP (second))
|
|
2737 Vfeatures = first;
|
|
2738 else
|
|
2739 Ffset (first, second);
|
|
2740 queue = Fcdr (queue);
|
|
2741 }
|
|
2742 return Qnil;
|
|
2743 }
|
|
2744
|
|
2745 void
|
|
2746 do_autoload (Lisp_Object fundef,
|
|
2747 Lisp_Object funname)
|
|
2748 {
|
|
2749 /* This function can GC */
|
|
2750 int speccount = specpdl_depth_counter;
|
|
2751 Lisp_Object fun = funname;
|
|
2752 struct gcpro gcpro1, gcpro2;
|
|
2753
|
|
2754 CHECK_SYMBOL (funname);
|
|
2755 GCPRO2 (fun, funname);
|
|
2756
|
|
2757 /* Value saved here is to be restored into Vautoload_queue */
|
|
2758 record_unwind_protect (un_autoload, Vautoload_queue);
|
|
2759 Vautoload_queue = Qt;
|
|
2760 call4 (Qload, Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil,
|
|
2761 Qnil);
|
|
2762
|
|
2763 {
|
|
2764 Lisp_Object queue = Vautoload_queue;
|
|
2765
|
|
2766 /* Save the old autoloads, in case we ever do an unload. */
|
|
2767 queue = Vautoload_queue;
|
|
2768 while (CONSP (queue))
|
|
2769 {
|
|
2770 Lisp_Object first = Fcar (queue);
|
|
2771 Lisp_Object second = Fcdr (first);
|
|
2772
|
|
2773 first = Fcar (first);
|
|
2774
|
|
2775 /* Note: This test is subtle. The cdr of an autoload-queue entry
|
|
2776 may be an atom if the autoload entry was generated by a defalias
|
|
2777 or fset. */
|
|
2778 if (CONSP (second))
|
|
2779 Fput (first, Qautoload, (Fcdr (second)));
|
|
2780
|
|
2781 queue = Fcdr (queue);
|
|
2782 }
|
|
2783 }
|
|
2784
|
|
2785 /* Once loading finishes, don't undo it. */
|
|
2786 Vautoload_queue = Qt;
|
|
2787 unbind_to (speccount, Qnil);
|
|
2788
|
|
2789 fun = indirect_function (fun, 0);
|
|
2790
|
|
2791 #if 0 /* FSFmacs */
|
|
2792 if (!NILP (Fequal (fun, fundef)))
|
|
2793 #else
|
|
2794 if (UNBOUNDP (fun)
|
|
2795 || (CONSP (fun)
|
|
2796 && EQ (XCAR (fun), Qautoload)))
|
|
2797 #endif
|
|
2798 error ("Autoloading failed to define function %s",
|
|
2799 string_data (XSYMBOL (funname)->name));
|
|
2800 UNGCPRO;
|
|
2801 }
|
|
2802
|
|
2803
|
|
2804 /**********************************************************************/
|
|
2805 /* eval, funcall, apply */
|
|
2806 /**********************************************************************/
|
|
2807
|
|
2808 static Lisp_Object funcall_lambda (Lisp_Object fun,
|
|
2809 int nargs, Lisp_Object args[]);
|
|
2810 static Lisp_Object apply_lambda (Lisp_Object fun,
|
|
2811 int nargs, Lisp_Object args);
|
|
2812 static Lisp_Object funcall_subr (struct Lisp_Subr *sub, Lisp_Object args[]);
|
|
2813
|
|
2814 static int in_warnings;
|
|
2815
|
|
2816 static Lisp_Object
|
|
2817 in_warnings_restore (Lisp_Object minimus)
|
|
2818 {
|
|
2819 in_warnings = 0;
|
|
2820 return Qnil;
|
|
2821 }
|
|
2822
|
|
2823
|
20
|
2824 DEFUN ("eval", Feval, 1, 1, 0, /*
|
0
|
2825 Evaluate FORM and return its value.
|
20
|
2826 */
|
|
2827 (form))
|
0
|
2828 {
|
|
2829 /* This function can GC */
|
|
2830 Lisp_Object fun, val, original_fun, original_args;
|
|
2831 int nargs;
|
|
2832 struct backtrace backtrace;
|
|
2833
|
|
2834 /* I think this is a pretty safe place to call Lisp code, don't you? */
|
|
2835 while (!in_warnings && !NILP (Vpending_warnings))
|
|
2836 {
|
|
2837 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
2838 int speccount = specpdl_depth ();
|
|
2839 Lisp_Object this_warning_cons, this_warning, class, level, messij;
|
|
2840
|
|
2841 record_unwind_protect (in_warnings_restore, Qnil);
|
|
2842 in_warnings = 1;
|
|
2843 this_warning_cons = Vpending_warnings;
|
|
2844 this_warning = XCAR (this_warning_cons);
|
|
2845 /* in case an error occurs in the warn function, at least
|
|
2846 it won't happen infinitely */
|
|
2847 Vpending_warnings = XCDR (Vpending_warnings);
|
|
2848 free_cons (XCONS (this_warning_cons));
|
|
2849 class = XCAR (this_warning);
|
|
2850 level = XCAR (XCDR (this_warning));
|
|
2851 messij = XCAR (XCDR (XCDR (this_warning)));
|
|
2852 free_list (this_warning);
|
|
2853
|
|
2854 if (NILP (Vpending_warnings))
|
|
2855 Vpending_warnings_tail = Qnil; /* perhaps not strictly necessary,
|
|
2856 but safer */
|
|
2857
|
|
2858 GCPRO4 (form, class, level, messij);
|
|
2859 if (!STRINGP (messij))
|
|
2860 messij = Fprin1_to_string (messij, Qnil);
|
|
2861 call3 (Qdisplay_warning, class, messij, level);
|
|
2862 UNGCPRO;
|
|
2863 unbind_to (speccount, Qnil);
|
|
2864 }
|
|
2865
|
|
2866 if (!CONSP (form))
|
|
2867 {
|
|
2868 if (!SYMBOLP (form))
|
|
2869 return form;
|
|
2870
|
|
2871 val = Fsymbol_value (form);
|
|
2872
|
|
2873 return val;
|
|
2874 }
|
|
2875
|
|
2876 QUIT;
|
|
2877 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
2878 {
|
|
2879 struct gcpro gcpro1;
|
|
2880 GCPRO1 (form);
|
|
2881 garbage_collect_1 ();
|
|
2882 UNGCPRO;
|
|
2883 }
|
|
2884
|
|
2885 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
2886 {
|
|
2887 if (max_lisp_eval_depth < 100)
|
|
2888 max_lisp_eval_depth = 100;
|
|
2889 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
2890 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
|
|
2891 }
|
|
2892
|
|
2893 original_fun = Fcar (form);
|
|
2894 original_args = Fcdr (form);
|
|
2895 nargs = XINT (Flength (original_args));
|
|
2896
|
|
2897 #ifdef EMACS_BTL
|
|
2898 backtrace.id_number = 0;
|
|
2899 #endif
|
|
2900 backtrace.pdlcount = specpdl_depth_counter;
|
|
2901 backtrace.function = &original_fun; /* This also protects them from gc */
|
|
2902 backtrace.args = &original_args;
|
|
2903 backtrace.nargs = UNEVALLED;
|
|
2904 backtrace.evalargs = 1;
|
|
2905 backtrace.debug_on_exit = 0;
|
116
|
2906 PUSH_BACKTRACE (backtrace);
|
0
|
2907
|
|
2908 if (debug_on_next_call)
|
|
2909 do_debug_on_call (Qt);
|
|
2910
|
|
2911 /* At this point, only original_fun and original_args
|
|
2912 have values that will be used below */
|
|
2913 retry:
|
|
2914 fun = indirect_function (original_fun, 1);
|
|
2915
|
|
2916 if (SUBRP (fun))
|
|
2917 {
|
|
2918 struct Lisp_Subr *subr = XSUBR (fun);
|
|
2919 int max_args = subr->max_args;
|
|
2920 Lisp_Object argvals[SUBR_MAX_ARGS];
|
|
2921 Lisp_Object args_left;
|
|
2922 REGISTER int i;
|
|
2923
|
|
2924 args_left = original_args;
|
|
2925
|
|
2926 if (nargs < subr->min_args
|
|
2927 || (max_args >= 0 && max_args < nargs))
|
|
2928 {
|
|
2929 return Fsignal (Qwrong_number_of_arguments,
|
|
2930 list2 (fun, make_int (nargs)));
|
|
2931 }
|
|
2932
|
|
2933 if (max_args == UNEVALLED)
|
|
2934 {
|
|
2935 backtrace.evalargs = 0;
|
|
2936 val = ((subr_function (subr)) (args_left));
|
|
2937 }
|
|
2938
|
|
2939 else if (max_args == MANY)
|
|
2940 {
|
|
2941 /* Pass a vector of evaluated arguments */
|
|
2942 Lisp_Object *vals;
|
|
2943 REGISTER int argnum;
|
|
2944 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2945
|
|
2946 vals = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
|
|
2947
|
|
2948 GCPRO3 (args_left, fun, vals[0]);
|
|
2949 gcpro3.nvars = 0;
|
|
2950
|
|
2951 argnum = 0;
|
|
2952 while (!NILP (args_left))
|
|
2953 {
|
|
2954 vals[argnum++] = Feval (Fcar (args_left));
|
|
2955 args_left = Fcdr (args_left);
|
|
2956 gcpro3.nvars = argnum;
|
|
2957 }
|
|
2958
|
|
2959 backtrace.args = vals;
|
|
2960 backtrace.nargs = nargs;
|
|
2961
|
74
|
2962 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr)))
|
|
2963 (nargs, vals);
|
0
|
2964
|
|
2965 /* Have to duplicate this code because if the
|
|
2966 * debugger is called it must be in a scope in
|
|
2967 * which the `alloca'-ed data in vals is still valid.
|
|
2968 * (And GC-protected.)
|
|
2969 */
|
|
2970 lisp_eval_depth--;
|
|
2971 if (backtrace.debug_on_exit)
|
|
2972 val = do_debug_on_exit (val);
|
116
|
2973 POP_BACKTRACE (backtrace);
|
0
|
2974 UNGCPRO;
|
|
2975 return (val);
|
|
2976 }
|
|
2977
|
|
2978 else
|
|
2979 {
|
|
2980 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2981
|
|
2982 GCPRO3 (args_left, fun, fun);
|
|
2983 gcpro3.var = argvals;
|
|
2984 gcpro3.nvars = 0;
|
|
2985
|
|
2986 for (i = 0; i < nargs; args_left = Fcdr (args_left))
|
|
2987 {
|
|
2988 argvals[i] = Feval (Fcar (args_left));
|
|
2989 gcpro3.nvars = ++i;
|
|
2990 }
|
|
2991
|
|
2992 UNGCPRO;
|
|
2993
|
|
2994 for (i = nargs; i < max_args; i++)
|
|
2995 argvals[i] = Qnil;
|
|
2996
|
|
2997 backtrace.args = argvals;
|
|
2998 backtrace.nargs = nargs;
|
|
2999
|
|
3000 val = funcall_subr (subr, argvals);
|
|
3001 }
|
|
3002 }
|
|
3003 else if (COMPILED_FUNCTIONP (fun))
|
|
3004 val = apply_lambda (fun, nargs, original_args);
|
|
3005 else
|
|
3006 {
|
|
3007 Lisp_Object funcar;
|
|
3008
|
|
3009 if (!CONSP (fun))
|
|
3010 goto invalid_function;
|
|
3011 funcar = Fcar (fun);
|
|
3012 if (!SYMBOLP (funcar))
|
|
3013 goto invalid_function;
|
|
3014 if (EQ (funcar, Qautoload))
|
|
3015 {
|
|
3016 do_autoload (fun, original_fun);
|
|
3017 goto retry;
|
|
3018 }
|
|
3019 if (EQ (funcar, Qmacro))
|
|
3020 val = Feval (apply1 (Fcdr (fun), original_args));
|
|
3021 else if (EQ (funcar, Qlambda))
|
|
3022 val = apply_lambda (fun, nargs, original_args);
|
|
3023 else
|
|
3024 {
|
|
3025 invalid_function:
|
|
3026 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3027 }
|
|
3028 }
|
|
3029
|
|
3030 lisp_eval_depth--;
|
|
3031 if (backtrace.debug_on_exit)
|
|
3032 val = do_debug_on_exit (val);
|
116
|
3033 POP_BACKTRACE (backtrace);
|
0
|
3034 return (val);
|
|
3035 }
|
|
3036
|
|
3037
|
|
3038 Lisp_Object
|
|
3039 funcall_recording_as (Lisp_Object recorded_as, int nargs,
|
|
3040 Lisp_Object *args)
|
|
3041 {
|
|
3042 /* This function can GC */
|
|
3043 Lisp_Object fun;
|
|
3044 Lisp_Object val;
|
|
3045 struct backtrace backtrace;
|
|
3046 REGISTER int i;
|
|
3047
|
|
3048 QUIT;
|
|
3049 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
3050 /* Callers should gcpro lexpr args */
|
|
3051 garbage_collect_1 ();
|
|
3052
|
|
3053 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
3054 {
|
|
3055 if (max_lisp_eval_depth < 100)
|
|
3056 max_lisp_eval_depth = 100;
|
|
3057 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
3058 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
|
|
3059 }
|
|
3060
|
|
3061 /* Count number of arguments to function */
|
|
3062 nargs = nargs - 1;
|
|
3063
|
|
3064 #ifdef EMACS_BTL
|
|
3065 backtrace.id_number = 0;
|
|
3066 #endif
|
|
3067 backtrace.pdlcount = specpdl_depth_counter;
|
|
3068 backtrace.function = &args[0];
|
|
3069 backtrace.args = &args[1];
|
|
3070 backtrace.nargs = nargs;
|
|
3071 backtrace.evalargs = 0;
|
|
3072 backtrace.debug_on_exit = 0;
|
116
|
3073 PUSH_BACKTRACE (backtrace);
|
0
|
3074
|
|
3075 if (debug_on_next_call)
|
|
3076 do_debug_on_call (Qlambda);
|
|
3077
|
|
3078 retry:
|
|
3079
|
|
3080 fun = args[0];
|
|
3081
|
|
3082 #ifdef EMACS_BTL
|
|
3083 {
|
|
3084 extern int emacs_btl_elisp_only_p;
|
|
3085 extern int btl_symbol_id_number ();
|
|
3086 if (emacs_btl_elisp_only_p)
|
|
3087 backtrace.id_number = btl_symbol_id_number (fun);
|
|
3088 }
|
|
3089 #endif
|
|
3090
|
|
3091 if (SYMBOLP (fun))
|
|
3092 fun = indirect_function (fun, 1);
|
|
3093
|
|
3094 if (SUBRP (fun))
|
|
3095 {
|
|
3096 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3097 int max_args = subr->max_args;
|
|
3098
|
|
3099 if (max_args == UNEVALLED)
|
|
3100 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3101
|
|
3102 if (nargs < subr->min_args
|
|
3103 || (max_args >= 0 && max_args < nargs))
|
|
3104 {
|
|
3105 return Fsignal (Qwrong_number_of_arguments,
|
|
3106 list2 (fun, make_int (nargs)));
|
|
3107 }
|
|
3108
|
|
3109 if (max_args == MANY)
|
|
3110 {
|
74
|
3111 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr)))
|
|
3112 (nargs, args + 1);
|
0
|
3113 }
|
|
3114
|
|
3115 else if (max_args > nargs)
|
|
3116 {
|
|
3117 Lisp_Object argvals[SUBR_MAX_ARGS];
|
|
3118
|
|
3119 /* Default optionals to nil */
|
|
3120 for (i = 0; i < nargs; i++)
|
|
3121 argvals[i] = args[i + 1];
|
|
3122 for (i = nargs; i < max_args; i++)
|
|
3123 argvals[i] = Qnil;
|
|
3124
|
|
3125 val = funcall_subr (subr, argvals);
|
|
3126 }
|
|
3127 else
|
|
3128 val = funcall_subr (subr, args + 1);
|
|
3129 }
|
|
3130 else if (COMPILED_FUNCTIONP (fun))
|
|
3131 val = funcall_lambda (fun, nargs, args + 1);
|
|
3132 else if (!CONSP (fun))
|
|
3133 {
|
|
3134 invalid_function:
|
|
3135 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3136 }
|
|
3137 else
|
|
3138 {
|
|
3139 Lisp_Object funcar = Fcar (fun);
|
|
3140
|
|
3141 if (!SYMBOLP (funcar))
|
|
3142 goto invalid_function;
|
|
3143 if (EQ (funcar, Qlambda))
|
|
3144 val = funcall_lambda (fun, nargs, args + 1);
|
|
3145 else if (EQ (funcar, Qautoload))
|
|
3146 {
|
|
3147 do_autoload (fun, args[0]);
|
|
3148 goto retry;
|
|
3149 }
|
|
3150 else
|
|
3151 {
|
|
3152 goto invalid_function;
|
|
3153 }
|
|
3154 }
|
|
3155 lisp_eval_depth--;
|
|
3156 if (backtrace.debug_on_exit)
|
|
3157 val = do_debug_on_exit (val);
|
116
|
3158 POP_BACKTRACE (backtrace);
|
0
|
3159 return val;
|
|
3160 }
|
|
3161
|
20
|
3162 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /*
|
0
|
3163 Call first argument as a function, passing remaining arguments to it.
|
|
3164 Thus, (funcall 'cons 'x 'y) returns (x . y).
|
20
|
3165 */
|
|
3166 (int nargs, Lisp_Object *args))
|
0
|
3167 {
|
|
3168 return funcall_recording_as (args[0], nargs, args);
|
|
3169 }
|
|
3170
|
20
|
3171 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /*
|
0
|
3172 Return the number of arguments a function may be called with. The
|
|
3173 function may be any form that can be passed to `funcall', any special
|
|
3174 form, or any macro.
|
20
|
3175 */
|
|
3176 (function))
|
0
|
3177 {
|
|
3178 Lisp_Object orig_function = function;
|
|
3179 Lisp_Object arglist;
|
|
3180 int argcount;
|
|
3181
|
|
3182 retry:
|
|
3183
|
|
3184 if (SYMBOLP (function))
|
|
3185 function = indirect_function (function, 1);
|
|
3186
|
|
3187 if (SUBRP (function))
|
|
3188 return Fsubr_min_args (function);
|
|
3189 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function))
|
|
3190 {
|
|
3191 invalid_function:
|
|
3192 return Fsignal (Qinvalid_function, list1 (function));
|
|
3193 }
|
|
3194
|
|
3195 if (CONSP (function))
|
|
3196 {
|
|
3197 Lisp_Object funcar = Fcar (function);
|
|
3198
|
|
3199 if (!SYMBOLP (funcar))
|
|
3200 goto invalid_function;
|
|
3201 if (EQ (funcar, Qmacro))
|
|
3202 {
|
|
3203 function = Fcdr (function);
|
|
3204 goto retry;
|
|
3205 }
|
|
3206 if (EQ (funcar, Qautoload))
|
|
3207 {
|
|
3208 do_autoload (function, orig_function);
|
|
3209 goto retry;
|
|
3210 }
|
|
3211 if (EQ (funcar, Qlambda))
|
|
3212 arglist = Fcar (Fcdr (function));
|
|
3213 else
|
|
3214 goto invalid_function;
|
|
3215 }
|
|
3216 else
|
|
3217 arglist = XCOMPILED_FUNCTION (function)->arglist;
|
|
3218
|
|
3219 argcount = 0;
|
|
3220 while (!NILP (arglist))
|
|
3221 {
|
|
3222 QUIT;
|
|
3223 if (EQ (Fcar (arglist), Qand_optional)
|
|
3224 || EQ (Fcar (arglist), Qand_rest))
|
|
3225 break;
|
|
3226 argcount++;
|
|
3227 arglist = Fcdr (arglist);
|
|
3228 }
|
|
3229
|
|
3230 return make_int (argcount);
|
|
3231 }
|
|
3232
|
20
|
3233 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /*
|
0
|
3234 Return the number of arguments a function may be called with. If the
|
|
3235 function takes an arbitrary number of arguments or is a built-in
|
|
3236 special form, nil is returned. The function may be any form that can
|
|
3237 be passed to `funcall', any special form, or any macro.
|
20
|
3238 */
|
|
3239 (function))
|
0
|
3240 {
|
|
3241 Lisp_Object orig_function = function;
|
|
3242 Lisp_Object arglist;
|
|
3243 int argcount;
|
|
3244
|
|
3245 retry:
|
|
3246
|
|
3247 if (SYMBOLP (function))
|
|
3248 function = indirect_function (function, 1);
|
|
3249
|
|
3250 if (SUBRP (function))
|
|
3251 return Fsubr_max_args (function);
|
|
3252 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function))
|
|
3253 {
|
|
3254 invalid_function:
|
|
3255 return Fsignal (Qinvalid_function, list1 (function));
|
|
3256 }
|
|
3257
|
|
3258 if (CONSP (function))
|
|
3259 {
|
|
3260 Lisp_Object funcar = Fcar (function);
|
|
3261
|
|
3262 if (!SYMBOLP (funcar))
|
|
3263 goto invalid_function;
|
|
3264 if (EQ (funcar, Qmacro))
|
|
3265 {
|
|
3266 function = Fcdr (function);
|
|
3267 goto retry;
|
|
3268 }
|
|
3269 if (EQ (funcar, Qautoload))
|
|
3270 {
|
|
3271 do_autoload (function, orig_function);
|
|
3272 goto retry;
|
|
3273 }
|
|
3274 if (EQ (funcar, Qlambda))
|
|
3275 arglist = Fcar (Fcdr (function));
|
|
3276 else
|
|
3277 goto invalid_function;
|
|
3278 }
|
|
3279 else
|
|
3280 arglist = XCOMPILED_FUNCTION (function)->arglist;
|
|
3281
|
|
3282 argcount = 0;
|
|
3283 while (!NILP (arglist))
|
|
3284 {
|
|
3285 QUIT;
|
|
3286 if (EQ (Fcar (arglist), Qand_optional))
|
|
3287 {
|
|
3288 arglist = Fcdr (arglist);
|
|
3289 continue;
|
|
3290 }
|
|
3291 if (EQ (Fcar (arglist), Qand_rest))
|
|
3292 return Qnil;
|
|
3293 argcount++;
|
|
3294 arglist = Fcdr (arglist);
|
|
3295 }
|
|
3296
|
|
3297 return make_int (argcount);
|
|
3298 }
|
|
3299
|
|
3300
|
20
|
3301 DEFUN ("apply", Fapply, 2, MANY, 0, /*
|
0
|
3302 Call FUNCTION with our remaining args, using our last arg as list of args.
|
|
3303 Thus, (apply '+ 1 2 '(3 4)) returns 10.
|
20
|
3304 */
|
|
3305 (int nargs, Lisp_Object *args))
|
0
|
3306 {
|
|
3307 /* This function can GC */
|
|
3308 Lisp_Object fun = args[0];
|
|
3309 Lisp_Object spread_arg = args [nargs - 1];
|
|
3310 int numargs;
|
|
3311 int funcall_nargs;
|
|
3312
|
|
3313 CHECK_LIST (spread_arg);
|
|
3314
|
|
3315 numargs = XINT (Flength (spread_arg));
|
|
3316
|
|
3317 if (numargs == 0)
|
|
3318 /* (apply foo 0 1 '()) */
|
|
3319 return Ffuncall (nargs - 1, args);
|
|
3320 else if (numargs == 1)
|
|
3321 {
|
|
3322 /* (apply foo 0 1 '(2)) */
|
|
3323 args [nargs - 1] = XCAR (spread_arg);
|
|
3324 return Ffuncall (nargs, args);
|
|
3325 }
|
|
3326
|
|
3327 /* -1 for function, -1 for spread arg */
|
|
3328 numargs = nargs - 2 + numargs;
|
|
3329 /* +1 for function */
|
|
3330 funcall_nargs = 1 + numargs;
|
|
3331
|
|
3332 if (SYMBOLP (fun))
|
|
3333 fun = indirect_function (fun, 0);
|
|
3334 if (UNBOUNDP (fun))
|
|
3335 {
|
|
3336 /* Let funcall get the error */
|
|
3337 fun = args[0];
|
|
3338 }
|
|
3339 else if (SUBRP (fun))
|
|
3340 {
|
|
3341 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3342 int max_args = subr->max_args;
|
|
3343
|
|
3344 if (numargs < subr->min_args
|
|
3345 || (max_args >= 0 && max_args < numargs))
|
|
3346 {
|
|
3347 /* Let funcall get the error */
|
|
3348 }
|
|
3349 else if (max_args > numargs)
|
|
3350 {
|
|
3351 /* Avoid having funcall cons up yet another new vector of arguments
|
|
3352 by explicitly supplying nil's for optional values */
|
|
3353 funcall_nargs += (max_args - numargs);
|
|
3354 }
|
|
3355 }
|
|
3356 {
|
|
3357 REGISTER int i;
|
|
3358 REGISTER Lisp_Object *funcall_args
|
|
3359 = (Lisp_Object *) alloca (funcall_nargs * sizeof (Lisp_Object));
|
|
3360 struct gcpro gcpro1;
|
|
3361
|
|
3362 GCPRO1 (*funcall_args);
|
|
3363 gcpro1.nvars = funcall_nargs;
|
|
3364
|
|
3365 /* Copy in the unspread args */
|
|
3366 memcpy (funcall_args, args, (nargs - 1) * sizeof (Lisp_Object));
|
|
3367 /* Spread the last arg we got. Its first element goes in
|
|
3368 the slot that it used to occupy, hence this value of I. */
|
|
3369 for (i = nargs - 1;
|
|
3370 !NILP (spread_arg); /* i < 1 + numargs */
|
|
3371 i++, spread_arg = XCDR (spread_arg))
|
|
3372 {
|
|
3373 funcall_args [i] = XCAR (spread_arg);
|
|
3374 }
|
|
3375 /* Supply nil for optional args (to subrs) */
|
|
3376 for (; i < funcall_nargs; i++)
|
|
3377 funcall_args[i] = Qnil;
|
|
3378
|
|
3379
|
|
3380 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args));
|
|
3381 }
|
|
3382 }
|
|
3383
|
|
3384
|
74
|
3385 /* Define proper types and argument lists simultaneously */
|
|
3386 #define PRIMITIVE_FUNCALL(n) ((Lisp_Object (*) (PRIMITIVE_FUNCALL_##n)
|
|
3387 #define PRIMITIVE_FUNCALL_0 void)) (fn)) (
|
|
3388 #define PRIMITIVE_FUNCALL_1 Lisp_Object)) (fn)) (args[0]
|
|
3389 #define PRIMITIVE_FUNCALL_2 Lisp_Object, PRIMITIVE_FUNCALL_1, args[1]
|
|
3390 #define PRIMITIVE_FUNCALL_3 Lisp_Object, PRIMITIVE_FUNCALL_2, args[2]
|
|
3391 #define PRIMITIVE_FUNCALL_4 Lisp_Object, PRIMITIVE_FUNCALL_3, args[3]
|
|
3392 #define PRIMITIVE_FUNCALL_5 Lisp_Object, PRIMITIVE_FUNCALL_4, args[4]
|
|
3393 #define PRIMITIVE_FUNCALL_6 Lisp_Object, PRIMITIVE_FUNCALL_5, args[5]
|
|
3394 #define PRIMITIVE_FUNCALL_7 Lisp_Object, PRIMITIVE_FUNCALL_6, args[6]
|
|
3395 #define PRIMITIVE_FUNCALL_8 Lisp_Object, PRIMITIVE_FUNCALL_7, args[7]
|
|
3396 #define PRIMITIVE_FUNCALL_9 Lisp_Object, PRIMITIVE_FUNCALL_8, args[8]
|
|
3397 #define PRIMITIVE_FUNCALL_10 Lisp_Object, PRIMITIVE_FUNCALL_9, args[9]
|
|
3398 #define PRIMITIVE_FUNCALL_11 Lisp_Object, PRIMITIVE_FUNCALL_10, args[10]
|
|
3399 #define PRIMITIVE_FUNCALL_12 Lisp_Object, PRIMITIVE_FUNCALL_11, args[11]
|
|
3400
|
0
|
3401 static Lisp_Object
|
74
|
3402 primitive_funcall (lisp_fn_t fn, int nargs, Lisp_Object args[])
|
0
|
3403 {
|
|
3404 switch (nargs)
|
|
3405 {
|
74
|
3406 case 0: return PRIMITIVE_FUNCALL(0);
|
|
3407 case 1: return PRIMITIVE_FUNCALL(1);
|
|
3408 case 2: return PRIMITIVE_FUNCALL(2);
|
|
3409 case 3: return PRIMITIVE_FUNCALL(3);
|
|
3410 case 4: return PRIMITIVE_FUNCALL(4);
|
|
3411 case 5: return PRIMITIVE_FUNCALL(5);
|
|
3412 case 6: return PRIMITIVE_FUNCALL(6);
|
|
3413 case 7: return PRIMITIVE_FUNCALL(7);
|
|
3414 case 8: return PRIMITIVE_FUNCALL(8);
|
|
3415 case 9: return PRIMITIVE_FUNCALL(9);
|
|
3416 case 10: return PRIMITIVE_FUNCALL(10);
|
|
3417 case 11: return PRIMITIVE_FUNCALL(11);
|
|
3418 case 12: return PRIMITIVE_FUNCALL(12);
|
0
|
3419 }
|
74
|
3420
|
|
3421 /* Someone has created a subr that takes more arguments than is
|
|
3422 supported by this code. We need to either rewrite the subr to
|
|
3423 use a different argument protocol, or add more cases to this
|
|
3424 switch. */
|
|
3425 abort ();
|
0
|
3426 return Qnil; /* suppress compiler warning */
|
|
3427 }
|
|
3428
|
|
3429 static Lisp_Object
|
|
3430 funcall_subr (struct Lisp_Subr *subr, Lisp_Object args[])
|
|
3431 {
|
|
3432 return primitive_funcall (subr_function (subr), subr->max_args, args);
|
|
3433 }
|
|
3434
|
|
3435 /* FSFmacs has an extra arg EVAL_FLAG. If false, some of
|
|
3436 the statements below are not done. But it's always true
|
|
3437 in all the calls to apply_lambda(). */
|
|
3438
|
|
3439 static Lisp_Object
|
|
3440 apply_lambda (Lisp_Object fun, int numargs, Lisp_Object unevalled_args)
|
|
3441 {
|
|
3442 /* This function can GC */
|
|
3443 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3444 REGISTER int i;
|
|
3445 REGISTER Lisp_Object tem;
|
|
3446 REGISTER Lisp_Object *arg_vector
|
|
3447 = (Lisp_Object *) alloca (numargs * sizeof (Lisp_Object));
|
|
3448
|
|
3449 GCPRO3 (*arg_vector, unevalled_args, fun);
|
|
3450 gcpro1.nvars = 0;
|
|
3451
|
|
3452 for (i = 0; i < numargs;)
|
|
3453 {
|
|
3454 tem = Fcar (unevalled_args), unevalled_args = Fcdr (unevalled_args);
|
|
3455 tem = Feval (tem);
|
|
3456 arg_vector[i++] = tem;
|
|
3457 gcpro1.nvars = i;
|
|
3458 }
|
|
3459
|
|
3460 UNGCPRO;
|
|
3461
|
|
3462 backtrace_list->args = arg_vector;
|
|
3463 backtrace_list->nargs = i;
|
|
3464 backtrace_list->evalargs = 0;
|
|
3465 tem = funcall_lambda (fun, numargs, arg_vector);
|
|
3466
|
|
3467 /* Do the debug-on-exit now, while arg_vector still exists. */
|
|
3468 if (backtrace_list->debug_on_exit)
|
|
3469 tem = do_debug_on_exit (tem);
|
|
3470 /* Don't do it again when we return to eval. */
|
|
3471 backtrace_list->debug_on_exit = 0;
|
|
3472 return (tem);
|
|
3473 }
|
|
3474
|
|
3475 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
|
|
3476 and return the result of evaluation.
|
|
3477 FUN must be either a lambda-expression or a compiled-code object. */
|
|
3478
|
|
3479 static Lisp_Object
|
|
3480 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object arg_vector[])
|
|
3481 {
|
|
3482 /* This function can GC */
|
|
3483 Lisp_Object val, tem;
|
|
3484 REGISTER Lisp_Object syms_left;
|
|
3485 REGISTER Lisp_Object next;
|
|
3486 int speccount = specpdl_depth_counter;
|
|
3487 REGISTER int i;
|
|
3488 int optional = 0, rest = 0;
|
|
3489
|
|
3490 if (CONSP (fun))
|
|
3491 syms_left = Fcar (Fcdr (fun));
|
|
3492 else if (COMPILED_FUNCTIONP (fun))
|
|
3493 syms_left = XCOMPILED_FUNCTION (fun)->arglist;
|
|
3494 else abort ();
|
|
3495
|
|
3496 i = 0;
|
|
3497 for (; !NILP (syms_left); syms_left = Fcdr (syms_left))
|
|
3498 {
|
|
3499 QUIT;
|
|
3500 next = Fcar (syms_left);
|
|
3501 if (!SYMBOLP (next))
|
|
3502 signal_error (Qinvalid_function, list1 (fun));
|
|
3503 if (EQ (next, Qand_rest))
|
|
3504 rest = 1;
|
|
3505 else if (EQ (next, Qand_optional))
|
|
3506 optional = 1;
|
|
3507 else if (rest)
|
|
3508 {
|
|
3509 specbind (next, Flist (nargs - i, &arg_vector[i]));
|
|
3510 i = nargs;
|
|
3511 }
|
|
3512 else if (i < nargs)
|
|
3513 {
|
|
3514 tem = arg_vector[i++];
|
|
3515 specbind (next, tem);
|
|
3516 }
|
|
3517 else if (!optional)
|
|
3518 return Fsignal (Qwrong_number_of_arguments,
|
|
3519 list2 (fun, make_int (nargs)));
|
|
3520 else
|
|
3521 specbind (next, Qnil);
|
|
3522 }
|
|
3523
|
|
3524 if (i < nargs)
|
|
3525 return Fsignal (Qwrong_number_of_arguments,
|
|
3526 list2 (fun, make_int (nargs)));
|
|
3527
|
|
3528 if (CONSP (fun))
|
|
3529 val = Fprogn (Fcdr (Fcdr (fun)));
|
|
3530 else
|
|
3531 {
|
|
3532 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun);
|
|
3533 /* If we have not actually read the bytecode string
|
|
3534 and constants vector yet, fetch them from the file. */
|
|
3535 if (CONSP (b->bytecodes))
|
|
3536 Ffetch_bytecode (fun);
|
|
3537 val = Fbyte_code (b->bytecodes,
|
|
3538 b->constants,
|
|
3539 make_int (b->maxdepth));
|
|
3540 }
|
|
3541 return unbind_to (speccount, val);
|
|
3542 }
|
|
3543
|
20
|
3544 DEFUN ("fetch-bytecode", Ffetch_bytecode, 1, 1, 0, /*
|
0
|
3545 If byte-compiled OBJECT is lazy-loaded, fetch it now.
|
20
|
3546 */
|
|
3547 (object))
|
0
|
3548 {
|
|
3549 Lisp_Object tem;
|
|
3550
|
|
3551 if (COMPILED_FUNCTIONP (object)
|
|
3552 && CONSP (XCOMPILED_FUNCTION (object)->bytecodes))
|
|
3553 {
|
|
3554 tem = read_doc_string (XCOMPILED_FUNCTION (object)->bytecodes);
|
|
3555 if (!CONSP (tem))
|
|
3556 signal_simple_error ("invalid lazy-loaded byte code", tem);
|
70
|
3557 /* v18 or v19 bytecode file. Need to Ebolify. */
|
|
3558 if (XCOMPILED_FUNCTION (object)->flags.ebolified
|
|
3559 && VECTORP (XCDR (tem)))
|
|
3560 ebolify_bytecode_constants (XCDR (tem));
|
0
|
3561 /* VERY IMPORTANT to purecopy here!!!!!
|
|
3562 See load_force_doc_string_unwind. */
|
|
3563 XCOMPILED_FUNCTION (object)->bytecodes = Fpurecopy (XCAR (tem));
|
|
3564 XCOMPILED_FUNCTION (object)->constants = Fpurecopy (XCDR (tem));
|
|
3565 }
|
|
3566 return object;
|
|
3567 }
|
|
3568
|
|
3569
|
|
3570 /**********************************************************************/
|
|
3571 /* Run hook variables in various ways. */
|
|
3572 /**********************************************************************/
|
|
3573
|
20
|
3574 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /*
|
0
|
3575 Run each hook in HOOKS. Major mode functions use this.
|
|
3576 Each argument should be a symbol, a hook variable.
|
|
3577 These symbols are processed in the order specified.
|
|
3578 If a hook symbol has a non-nil value, that value may be a function
|
|
3579 or a list of functions to be called to run the hook.
|
|
3580 If the value is a function, it is called with no arguments.
|
|
3581 If it is a list, the elements are called, in order, with no arguments.
|
|
3582
|
|
3583 To make a hook variable buffer-local, use `make-local-hook',
|
|
3584 not `make-local-variable'.
|
20
|
3585 */
|
|
3586 (int nargs, Lisp_Object *args))
|
0
|
3587 {
|
|
3588 Lisp_Object hook[1];
|
|
3589 REGISTER int i;
|
|
3590
|
|
3591 for (i = 0; i < nargs; i++)
|
|
3592 {
|
|
3593 hook[0] = args[i];
|
|
3594 run_hook_with_args (1, hook, RUN_HOOKS_TO_COMPLETION);
|
|
3595 }
|
|
3596
|
|
3597 return Qnil;
|
|
3598 }
|
|
3599
|
20
|
3600 DEFUN ("run-hook-with-args", Frun_hook_with_args, 1, MANY, 0, /*
|
0
|
3601 Run HOOK with the specified arguments ARGS.
|
|
3602 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
3603 value, that value may be a function or a list of functions to be
|
|
3604 called to run the hook. If the value is a function, it is called with
|
|
3605 the given arguments and its return value is returned. If it is a list
|
|
3606 of functions, those functions are called, in order,
|
|
3607 with the given arguments ARGS.
|
|
3608 It is best not to depend on the value return by `run-hook-with-args',
|
|
3609 as that may change.
|
|
3610
|
|
3611 To make a hook variable buffer-local, use `make-local-hook',
|
|
3612 not `make-local-variable'.
|
20
|
3613 */
|
|
3614 (int nargs, Lisp_Object *args))
|
0
|
3615 {
|
|
3616 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION);
|
|
3617 }
|
|
3618
|
20
|
3619 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, 1, MANY, 0, /*
|
0
|
3620 Run HOOK with the specified arguments ARGS.
|
|
3621 HOOK should be a symbol, a hook variable. Its value should
|
|
3622 be a list of functions. We call those functions, one by one,
|
|
3623 passing arguments ARGS to each of them, until one of them
|
|
3624 returns a non-nil value. Then we return that value.
|
|
3625 If all the functions return nil, we return nil.
|
|
3626
|
|
3627 To make a hook variable buffer-local, use `make-local-hook',
|
|
3628 not `make-local-variable'.
|
20
|
3629 */
|
|
3630 (int nargs, Lisp_Object *args))
|
0
|
3631 {
|
|
3632 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS);
|
|
3633 }
|
|
3634
|
20
|
3635 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, 1, MANY, 0, /*
|
0
|
3636 Run HOOK with the specified arguments ARGS.
|
|
3637 HOOK should be a symbol, a hook variable. Its value should
|
|
3638 be a list of functions. We call those functions, one by one,
|
|
3639 passing arguments ARGS to each of them, until one of them
|
|
3640 returns nil. Then we return nil.
|
|
3641 If all the functions return non-nil, we return non-nil.
|
|
3642
|
|
3643 To make a hook variable buffer-local, use `make-local-hook',
|
|
3644 not `make-local-variable'.
|
20
|
3645 */
|
|
3646 (int nargs, Lisp_Object *args))
|
0
|
3647 {
|
|
3648 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE);
|
|
3649 }
|
|
3650
|
|
3651 /* ARGS[0] should be a hook symbol.
|
|
3652 Call each of the functions in the hook value, passing each of them
|
|
3653 as arguments all the rest of ARGS (all NARGS - 1 elements).
|
|
3654 COND specifies a condition to test after each call
|
|
3655 to decide whether to stop.
|
|
3656 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3657 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3658
|
|
3659 Lisp_Object
|
|
3660 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args,
|
|
3661 enum run_hooks_condition cond)
|
|
3662 {
|
|
3663 Lisp_Object sym, val, ret;
|
|
3664 struct gcpro gcpro1, gcpro2;
|
|
3665
|
|
3666 if (!initialized || preparing_for_armageddon)
|
|
3667 /* We need to bail out of here pronto. */
|
|
3668 return Qnil;
|
|
3669
|
|
3670 /* Whenever gc_in_progress is true, preparing_for_armageddon
|
|
3671 will also be true unless something is really hosed. */
|
|
3672 assert (!gc_in_progress);
|
|
3673
|
|
3674 sym = args[0];
|
|
3675 val = symbol_value_in_buffer (sym, make_buffer (buf));
|
|
3676 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil);
|
|
3677
|
|
3678 if (UNBOUNDP (val) || NILP (val))
|
|
3679 return ret;
|
|
3680 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
|
|
3681 {
|
|
3682 args[0] = val;
|
|
3683 return Ffuncall (nargs, args);
|
|
3684 }
|
|
3685 else
|
|
3686 {
|
|
3687 GCPRO2 (sym, val);
|
|
3688
|
|
3689 for (;
|
|
3690 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3691 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret)
|
|
3692 : !NILP (ret)));
|
|
3693 val = XCDR (val))
|
|
3694 {
|
|
3695 if (EQ (XCAR (val), Qt))
|
|
3696 {
|
|
3697 /* t indicates this hook has a local binding;
|
|
3698 it means to run the global binding too. */
|
|
3699 Lisp_Object globals;
|
|
3700
|
|
3701 for (globals = Fdefault_value (sym);
|
|
3702 CONSP (globals) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3703 || (cond == RUN_HOOKS_UNTIL_SUCCESS
|
|
3704 ? NILP (ret)
|
|
3705 : !NILP (ret)));
|
|
3706 globals = XCDR (globals))
|
|
3707 {
|
|
3708 args[0] = XCAR (globals);
|
|
3709 /* In a global value, t should not occur. If it does, we
|
|
3710 must ignore it to avoid an endless loop. */
|
|
3711 if (!EQ (args[0], Qt))
|
|
3712 ret = Ffuncall (nargs, args);
|
|
3713 }
|
|
3714 }
|
|
3715 else
|
|
3716 {
|
|
3717 args[0] = XCAR (val);
|
|
3718 ret = Ffuncall (nargs, args);
|
|
3719 }
|
|
3720 }
|
|
3721
|
|
3722 UNGCPRO;
|
|
3723 return ret;
|
|
3724 }
|
|
3725 }
|
|
3726
|
|
3727 Lisp_Object
|
|
3728 run_hook_with_args (int nargs, Lisp_Object *args,
|
|
3729 enum run_hooks_condition cond)
|
|
3730 {
|
|
3731 return run_hook_with_args_in_buffer (current_buffer, nargs, args, cond);
|
|
3732 }
|
|
3733
|
|
3734 #if 0
|
|
3735
|
|
3736 /* From FSF 19.30, not currently used */
|
|
3737
|
|
3738 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
|
|
3739 present value of that symbol.
|
|
3740 Call each element of FUNLIST,
|
|
3741 passing each of them the rest of ARGS.
|
|
3742 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3743 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3744
|
|
3745 Lisp_Object
|
|
3746 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args)
|
|
3747 {
|
|
3748 Lisp_Object sym;
|
|
3749 Lisp_Object val;
|
|
3750 struct gcpro gcpro1, gcpro2;
|
|
3751
|
|
3752 sym = args[0];
|
|
3753 GCPRO2 (sym, val);
|
|
3754
|
|
3755 for (val = funlist; CONSP (val); val = XCDR (val))
|
|
3756 {
|
|
3757 if (EQ (XCAR (val), Qt))
|
|
3758 {
|
|
3759 /* t indicates this hook has a local binding;
|
|
3760 it means to run the global binding too. */
|
|
3761 Lisp_Object globals;
|
|
3762
|
|
3763 for (globals = Fdefault_value (sym);
|
|
3764 CONSP (globals);
|
|
3765 globals = XCDR (globals))
|
|
3766 {
|
|
3767 args[0] = XCAR (globals);
|
|
3768 /* In a global value, t should not occur. If it does, we
|
|
3769 must ignore it to avoid an endless loop. */
|
|
3770 if (!EQ (args[0], Qt))
|
|
3771 Ffuncall (nargs, args);
|
|
3772 }
|
|
3773 }
|
|
3774 else
|
|
3775 {
|
|
3776 args[0] = XCAR (val);
|
|
3777 Ffuncall (nargs, args);
|
|
3778 }
|
|
3779 }
|
|
3780 UNGCPRO;
|
|
3781 return Qnil;
|
|
3782 }
|
|
3783
|
|
3784 #endif /* 0 */
|
|
3785
|
|
3786 void
|
|
3787 va_run_hook_with_args (Lisp_Object hook_var, int nargs, ...)
|
|
3788 {
|
|
3789 /* This function can GC */
|
|
3790 struct gcpro gcpro1;
|
|
3791 int i;
|
|
3792 va_list vargs;
|
|
3793 Lisp_Object *funcall_args =
|
|
3794 (Lisp_Object *) alloca ((1 + nargs) * sizeof (Lisp_Object));
|
|
3795
|
|
3796 va_start (vargs, nargs);
|
|
3797 funcall_args[0] = hook_var;
|
|
3798 for (i = 0; i < nargs; i++)
|
|
3799 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
3800 va_end (vargs);
|
|
3801
|
|
3802 GCPRO1 (*funcall_args);
|
|
3803 gcpro1.nvars = nargs + 1;
|
|
3804 run_hook_with_args (nargs + 1, funcall_args, RUN_HOOKS_TO_COMPLETION);
|
|
3805 UNGCPRO;
|
|
3806 }
|
|
3807
|
|
3808 void
|
|
3809 va_run_hook_with_args_in_buffer (struct buffer *buf, Lisp_Object hook_var,
|
|
3810 int nargs, ...)
|
|
3811 {
|
|
3812 /* This function can GC */
|
|
3813 struct gcpro gcpro1;
|
|
3814 int i;
|
|
3815 va_list vargs;
|
|
3816 Lisp_Object *funcall_args =
|
|
3817 (Lisp_Object *) alloca ((1 + nargs) * sizeof (Lisp_Object));
|
|
3818
|
|
3819 va_start (vargs, nargs);
|
|
3820 funcall_args[0] = hook_var;
|
|
3821 for (i = 0; i < nargs; i++)
|
|
3822 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
3823 va_end (vargs);
|
|
3824
|
|
3825 GCPRO1 (*funcall_args);
|
|
3826 gcpro1.nvars = nargs + 1;
|
|
3827 run_hook_with_args_in_buffer (buf, nargs + 1, funcall_args,
|
|
3828 RUN_HOOKS_TO_COMPLETION);
|
|
3829 UNGCPRO;
|
|
3830 }
|
|
3831
|
|
3832 Lisp_Object
|
|
3833 run_hook (Lisp_Object hook)
|
|
3834 {
|
|
3835 Frun_hooks (1, &hook);
|
|
3836 return Qnil;
|
|
3837 }
|
|
3838
|
|
3839
|
|
3840 /**********************************************************************/
|
|
3841 /* Front-ends to eval, funcall, apply */
|
|
3842 /**********************************************************************/
|
|
3843
|
|
3844 /* Apply fn to arg */
|
|
3845 Lisp_Object
|
|
3846 apply1 (Lisp_Object fn, Lisp_Object arg)
|
|
3847 {
|
|
3848 /* This function can GC */
|
|
3849 struct gcpro gcpro1;
|
|
3850 Lisp_Object args[2];
|
|
3851
|
|
3852 if (NILP (arg))
|
|
3853 return (Ffuncall (1, &fn));
|
|
3854 GCPRO1 (args[0]);
|
|
3855 gcpro1.nvars = 2;
|
|
3856 args[0] = fn;
|
|
3857 args[1] = arg;
|
|
3858 RETURN_UNGCPRO (Fapply (2, args));
|
|
3859 }
|
|
3860
|
|
3861 /* Call function fn on no arguments */
|
|
3862 Lisp_Object
|
|
3863 call0 (Lisp_Object fn)
|
|
3864 {
|
|
3865 /* This function can GC */
|
|
3866 struct gcpro gcpro1;
|
|
3867
|
|
3868 GCPRO1 (fn);
|
|
3869 RETURN_UNGCPRO (Ffuncall (1, &fn));
|
|
3870 }
|
|
3871
|
|
3872 /* Call function fn with argument arg0 */
|
|
3873 Lisp_Object
|
|
3874 call1 (Lisp_Object fn,
|
|
3875 Lisp_Object arg0)
|
|
3876 {
|
|
3877 /* This function can GC */
|
|
3878 struct gcpro gcpro1;
|
|
3879 Lisp_Object args[2];
|
|
3880 args[0] = fn;
|
|
3881 args[1] = arg0;
|
|
3882 GCPRO1 (args[0]);
|
|
3883 gcpro1.nvars = 2;
|
|
3884 RETURN_UNGCPRO (Ffuncall (2, args));
|
|
3885 }
|
|
3886
|
|
3887 /* Call function fn with arguments arg0, arg1 */
|
|
3888 Lisp_Object
|
|
3889 call2 (Lisp_Object fn,
|
|
3890 Lisp_Object arg0, Lisp_Object arg1)
|
|
3891 {
|
|
3892 /* This function can GC */
|
|
3893 struct gcpro gcpro1;
|
|
3894 Lisp_Object args[3];
|
|
3895 args[0] = fn;
|
|
3896 args[1] = arg0;
|
|
3897 args[2] = arg1;
|
|
3898 GCPRO1 (args[0]);
|
|
3899 gcpro1.nvars = 3;
|
|
3900 RETURN_UNGCPRO (Ffuncall (3, args));
|
|
3901 }
|
|
3902
|
|
3903 /* Call function fn with arguments arg0, arg1, arg2 */
|
|
3904 Lisp_Object
|
|
3905 call3 (Lisp_Object fn,
|
|
3906 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
3907 {
|
|
3908 /* This function can GC */
|
|
3909 struct gcpro gcpro1;
|
|
3910 Lisp_Object args[4];
|
|
3911 args[0] = fn;
|
|
3912 args[1] = arg0;
|
|
3913 args[2] = arg1;
|
|
3914 args[3] = arg2;
|
|
3915 GCPRO1 (args[0]);
|
|
3916 gcpro1.nvars = 4;
|
|
3917 RETURN_UNGCPRO (Ffuncall (4, args));
|
|
3918 }
|
|
3919
|
|
3920 /* Call function fn with arguments arg0, arg1, arg2, arg3 */
|
|
3921 Lisp_Object
|
|
3922 call4 (Lisp_Object fn,
|
|
3923 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
3924 Lisp_Object arg3)
|
|
3925 {
|
|
3926 /* This function can GC */
|
|
3927 struct gcpro gcpro1;
|
|
3928 Lisp_Object args[5];
|
|
3929 args[0] = fn;
|
|
3930 args[1] = arg0;
|
|
3931 args[2] = arg1;
|
|
3932 args[3] = arg2;
|
|
3933 args[4] = arg3;
|
|
3934 GCPRO1 (args[0]);
|
|
3935 gcpro1.nvars = 5;
|
|
3936 RETURN_UNGCPRO (Ffuncall (5, args));
|
|
3937 }
|
|
3938
|
|
3939 /* Call function fn with arguments arg0, arg1, arg2, arg3, arg4 */
|
|
3940 Lisp_Object
|
|
3941 call5 (Lisp_Object fn,
|
|
3942 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
3943 Lisp_Object arg3, Lisp_Object arg4)
|
|
3944 {
|
|
3945 /* This function can GC */
|
|
3946 struct gcpro gcpro1;
|
|
3947 Lisp_Object args[6];
|
|
3948 args[0] = fn;
|
|
3949 args[1] = arg0;
|
|
3950 args[2] = arg1;
|
|
3951 args[3] = arg2;
|
|
3952 args[4] = arg3;
|
|
3953 args[5] = arg4;
|
|
3954 GCPRO1 (args[0]);
|
|
3955 gcpro1.nvars = 6;
|
|
3956 RETURN_UNGCPRO (Ffuncall (6, args));
|
|
3957 }
|
|
3958
|
|
3959 Lisp_Object
|
|
3960 call6 (Lisp_Object fn,
|
|
3961 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
3962 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
3963 {
|
|
3964 /* This function can GC */
|
|
3965 struct gcpro gcpro1;
|
|
3966 Lisp_Object args[7];
|
|
3967 args[0] = fn;
|
|
3968 args[1] = arg0;
|
|
3969 args[2] = arg1;
|
|
3970 args[3] = arg2;
|
|
3971 args[4] = arg3;
|
|
3972 args[5] = arg4;
|
|
3973 args[6] = arg5;
|
|
3974 GCPRO1 (args[0]);
|
|
3975 gcpro1.nvars = 7;
|
|
3976 RETURN_UNGCPRO (Ffuncall (7, args));
|
|
3977 }
|
|
3978
|
|
3979 Lisp_Object
|
|
3980 call7 (Lisp_Object fn,
|
|
3981 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
3982 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
3983 Lisp_Object arg6)
|
|
3984 {
|
|
3985 /* This function can GC */
|
|
3986 struct gcpro gcpro1;
|
|
3987 Lisp_Object args[8];
|
|
3988 args[0] = fn;
|
|
3989 args[1] = arg0;
|
|
3990 args[2] = arg1;
|
|
3991 args[3] = arg2;
|
|
3992 args[4] = arg3;
|
|
3993 args[5] = arg4;
|
|
3994 args[6] = arg5;
|
|
3995 args[7] = arg6;
|
|
3996 GCPRO1 (args[0]);
|
|
3997 gcpro1.nvars = 8;
|
|
3998 RETURN_UNGCPRO (Ffuncall (8, args));
|
|
3999 }
|
|
4000
|
|
4001 Lisp_Object
|
|
4002 call8 (Lisp_Object fn,
|
|
4003 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4004 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4005 Lisp_Object arg6, Lisp_Object arg7)
|
|
4006 {
|
|
4007 /* This function can GC */
|
|
4008 struct gcpro gcpro1;
|
|
4009 Lisp_Object args[9];
|
|
4010 args[0] = fn;
|
|
4011 args[1] = arg0;
|
|
4012 args[2] = arg1;
|
|
4013 args[3] = arg2;
|
|
4014 args[4] = arg3;
|
|
4015 args[5] = arg4;
|
|
4016 args[6] = arg5;
|
|
4017 args[7] = arg6;
|
|
4018 args[8] = arg7;
|
|
4019 GCPRO1 (args[0]);
|
|
4020 gcpro1.nvars = 9;
|
|
4021 RETURN_UNGCPRO (Ffuncall (9, args));
|
|
4022 }
|
|
4023
|
|
4024 Lisp_Object
|
|
4025 call0_in_buffer (struct buffer *buf, Lisp_Object fn)
|
|
4026 {
|
|
4027 int speccount = specpdl_depth ();
|
|
4028 Lisp_Object val;
|
|
4029
|
|
4030 if (current_buffer != buf)
|
|
4031 {
|
|
4032 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4033 set_buffer_internal (buf);
|
|
4034 }
|
|
4035 val = call0 (fn);
|
|
4036 unbind_to (speccount, Qnil);
|
|
4037 return val;
|
|
4038 }
|
|
4039
|
|
4040 Lisp_Object
|
|
4041 call1_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4042 Lisp_Object arg0)
|
|
4043 {
|
|
4044 int speccount = specpdl_depth ();
|
|
4045 Lisp_Object val;
|
|
4046
|
|
4047 if (current_buffer != buf)
|
|
4048 {
|
|
4049 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4050 set_buffer_internal (buf);
|
|
4051 }
|
|
4052 val = call1 (fn, arg0);
|
|
4053 unbind_to (speccount, Qnil);
|
|
4054 return val;
|
|
4055 }
|
|
4056
|
|
4057 Lisp_Object
|
|
4058 call2_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4059 Lisp_Object arg0, Lisp_Object arg1)
|
|
4060 {
|
|
4061 int speccount = specpdl_depth ();
|
|
4062 Lisp_Object val;
|
|
4063
|
|
4064 if (current_buffer != buf)
|
|
4065 {
|
|
4066 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4067 set_buffer_internal (buf);
|
|
4068 }
|
|
4069 val = call2 (fn, arg0, arg1);
|
|
4070 unbind_to (speccount, Qnil);
|
|
4071 return val;
|
|
4072 }
|
|
4073
|
|
4074 Lisp_Object
|
|
4075 call3_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4076 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4077 {
|
|
4078 int speccount = specpdl_depth ();
|
|
4079 Lisp_Object val;
|
|
4080
|
|
4081 if (current_buffer != buf)
|
|
4082 {
|
|
4083 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4084 set_buffer_internal (buf);
|
|
4085 }
|
|
4086 val = call3 (fn, arg0, arg1, arg2);
|
|
4087 unbind_to (speccount, Qnil);
|
|
4088 return val;
|
|
4089 }
|
|
4090
|
|
4091 Lisp_Object
|
|
4092 call4_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4093 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4094 Lisp_Object arg3)
|
|
4095 {
|
|
4096 int speccount = specpdl_depth ();
|
|
4097 Lisp_Object val;
|
|
4098
|
|
4099 if (current_buffer != buf)
|
|
4100 {
|
|
4101 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4102 set_buffer_internal (buf);
|
|
4103 }
|
|
4104 val = call4 (fn, arg0, arg1, arg2, arg3);
|
|
4105 unbind_to (speccount, Qnil);
|
|
4106 return val;
|
|
4107 }
|
|
4108
|
|
4109 Lisp_Object
|
|
4110 call5_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4111 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4112 Lisp_Object arg3, Lisp_Object arg4)
|
|
4113 {
|
|
4114 int speccount = specpdl_depth ();
|
|
4115 Lisp_Object val;
|
|
4116
|
|
4117 if (current_buffer != buf)
|
|
4118 {
|
|
4119 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4120 set_buffer_internal (buf);
|
|
4121 }
|
|
4122 val = call5 (fn, arg0, arg1, arg2, arg3, arg4);
|
|
4123 unbind_to (speccount, Qnil);
|
|
4124 return val;
|
|
4125 }
|
|
4126
|
|
4127 Lisp_Object
|
|
4128 call6_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4129 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4130 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4131 {
|
|
4132 int speccount = specpdl_depth ();
|
|
4133 Lisp_Object val;
|
|
4134
|
|
4135 if (current_buffer != buf)
|
|
4136 {
|
|
4137 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4138 set_buffer_internal (buf);
|
|
4139 }
|
|
4140 val = call6 (fn, arg0, arg1, arg2, arg3, arg4, arg5);
|
|
4141 unbind_to (speccount, Qnil);
|
|
4142 return val;
|
|
4143 }
|
|
4144
|
|
4145 Lisp_Object
|
|
4146 eval_in_buffer (struct buffer *buf, Lisp_Object form)
|
|
4147 {
|
|
4148 int speccount = specpdl_depth ();
|
|
4149 Lisp_Object val;
|
|
4150
|
|
4151 if (current_buffer != buf)
|
|
4152 {
|
|
4153 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4154 set_buffer_internal (buf);
|
|
4155 }
|
|
4156 val = Feval (form);
|
|
4157 unbind_to (speccount, Qnil);
|
|
4158 return val;
|
|
4159 }
|
|
4160
|
|
4161
|
|
4162 /***** Error-catching front-ends to eval, funcall, apply */
|
|
4163
|
|
4164 /* Call function fn on no arguments, with condition handler */
|
|
4165 Lisp_Object
|
|
4166 call0_with_handler (Lisp_Object handler, Lisp_Object fn)
|
|
4167 {
|
|
4168 /* This function can GC */
|
|
4169 struct gcpro gcpro1;
|
|
4170 Lisp_Object args[2];
|
|
4171 args[0] = handler;
|
|
4172 args[1] = fn;
|
|
4173 GCPRO1 (args[0]);
|
|
4174 gcpro1.nvars = 2;
|
|
4175 RETURN_UNGCPRO (Fcall_with_condition_handler (2, args));
|
|
4176 }
|
|
4177
|
|
4178 /* Call function fn with argument arg0, with condition handler */
|
|
4179 Lisp_Object
|
|
4180 call1_with_handler (Lisp_Object handler, Lisp_Object fn,
|
|
4181 Lisp_Object arg0)
|
|
4182 {
|
|
4183 /* This function can GC */
|
|
4184 struct gcpro gcpro1;
|
|
4185 Lisp_Object args[3];
|
|
4186 args[0] = handler;
|
|
4187 args[1] = fn;
|
|
4188 args[2] = arg0;
|
|
4189 GCPRO1 (args[0]);
|
|
4190 gcpro1.nvars = 3;
|
|
4191 RETURN_UNGCPRO (Fcall_with_condition_handler (3, args));
|
|
4192 }
|
|
4193
|
|
4194
|
|
4195 /* The following functions provide you with error-trapping versions
|
|
4196 of the various front-ends above. They take an additional
|
|
4197 "warning_string" argument; if non-zero, a warning with this
|
|
4198 string and the actual error that occurred will be displayed
|
|
4199 in the *Warnings* buffer if an error occurs. In all cases,
|
|
4200 QUIT is inhibited while these functions are running, and if
|
|
4201 an error occurs, Qunbound is returned instead of the normal
|
|
4202 return value.
|
|
4203 */
|
|
4204
|
|
4205 /* #### This stuff needs to catch throws as well. We need to
|
|
4206 improve internal_catch() so it can take a "catch anything"
|
|
4207 argument similar to Qt or Qerror for condition_case_1(). */
|
|
4208
|
|
4209 static Lisp_Object
|
|
4210 caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4211 {
|
|
4212 if (!NILP (errordata))
|
|
4213 {
|
|
4214 Lisp_Object args[2];
|
|
4215
|
|
4216 if (!NILP (arg))
|
|
4217 {
|
|
4218 char *str = (char *) get_opaque_ptr (arg);
|
|
4219 args[0] = build_string (str);
|
|
4220 }
|
|
4221 else
|
|
4222 args[0] = build_string ("error");
|
|
4223 /* #### This should call
|
|
4224 (with-output-to-string (display-error errordata))
|
|
4225 but that stuff is all in Lisp currently. */
|
|
4226 args[1] = errordata;
|
|
4227 warn_when_safe_lispobj
|
|
4228 (Qerror, Qwarning,
|
|
4229 emacs_doprnt_string_lisp ((CONST Bufbyte *) "%s: %s",
|
|
4230 Qnil, -1, 2, args));
|
|
4231 }
|
|
4232 return Qunbound;
|
|
4233 }
|
|
4234
|
|
4235 static Lisp_Object
|
|
4236 allow_quit_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4237 {
|
|
4238 if (CONSP (errordata) && EQ (XCAR (errordata), Qquit))
|
|
4239 return Fsignal (Qquit, XCDR (errordata));
|
|
4240 return caught_a_squirmer (errordata, arg);
|
|
4241 }
|
|
4242
|
|
4243 static Lisp_Object
|
|
4244 safe_run_hook_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4245 {
|
|
4246 Lisp_Object hook = Fcar (arg);
|
|
4247 arg = Fcdr (arg);
|
|
4248 /* Clear out the hook. */
|
|
4249 Fset (hook, Qnil);
|
|
4250 return caught_a_squirmer (errordata, arg);
|
|
4251 }
|
|
4252
|
|
4253 static Lisp_Object
|
|
4254 allow_quit_safe_run_hook_caught_a_squirmer (Lisp_Object errordata,
|
|
4255 Lisp_Object arg)
|
|
4256 {
|
|
4257 Lisp_Object hook = Fcar (arg);
|
|
4258 arg = Fcdr (arg);
|
|
4259 if (!CONSP (errordata) || !EQ (XCAR (errordata), Qquit))
|
|
4260 /* Clear out the hook. */
|
|
4261 Fset (hook, Qnil);
|
|
4262 return allow_quit_caught_a_squirmer (errordata, arg);
|
|
4263 }
|
|
4264
|
|
4265 static Lisp_Object
|
|
4266 catch_them_squirmers_eval_in_buffer (Lisp_Object cons)
|
|
4267 {
|
|
4268 return eval_in_buffer (XBUFFER (XCAR (cons)), XCDR (cons));
|
|
4269 }
|
|
4270
|
|
4271 Lisp_Object
|
|
4272 eval_in_buffer_trapping_errors (CONST char *warning_string,
|
|
4273 struct buffer *buf, Lisp_Object form)
|
|
4274 {
|
|
4275 int speccount = specpdl_depth ();
|
|
4276 Lisp_Object tem;
|
|
4277 Lisp_Object buffer = Qnil;
|
|
4278 Lisp_Object cons;
|
|
4279 Lisp_Object opaque;
|
|
4280 struct gcpro gcpro1, gcpro2;
|
|
4281
|
|
4282 XSETBUFFER (buffer, buf);
|
|
4283
|
|
4284 specbind (Qinhibit_quit, Qt);
|
|
4285 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4286
|
|
4287 cons = noseeum_cons (buffer, form);
|
|
4288 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4289 GCPRO2 (cons, opaque);
|
|
4290 /* Qerror not Qt, so you can get a backtrace */
|
|
4291 tem = condition_case_1 (Qerror,
|
|
4292 catch_them_squirmers_eval_in_buffer, cons,
|
|
4293 caught_a_squirmer, opaque);
|
|
4294 free_cons (XCONS (cons));
|
|
4295 if (OPAQUEP (opaque))
|
|
4296 free_opaque_ptr (opaque);
|
|
4297 UNGCPRO;
|
|
4298
|
|
4299 /* gc_currently_forbidden = 0; */
|
|
4300 return unbind_to (speccount, tem);
|
|
4301 }
|
|
4302
|
|
4303 static Lisp_Object
|
|
4304 catch_them_squirmers_run_hook (Lisp_Object hook_symbol)
|
|
4305 {
|
|
4306 /* This function can GC */
|
|
4307 run_hook (hook_symbol);
|
|
4308 return Qnil;
|
|
4309 }
|
|
4310
|
|
4311 Lisp_Object
|
|
4312 run_hook_trapping_errors (CONST char *warning_string, Lisp_Object hook_symbol)
|
|
4313 {
|
|
4314 int speccount = specpdl_depth ();
|
|
4315 Lisp_Object tem;
|
|
4316 Lisp_Object opaque;
|
|
4317 struct gcpro gcpro1;
|
|
4318
|
|
4319 if (!initialized || preparing_for_armageddon)
|
|
4320 return Qnil;
|
|
4321 tem = find_symbol_value (hook_symbol);
|
|
4322 if (NILP (tem) || UNBOUNDP (tem))
|
|
4323 return Qnil;
|
|
4324
|
|
4325 specbind (Qinhibit_quit, Qt);
|
|
4326
|
|
4327 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4328 GCPRO1 (opaque);
|
|
4329 /* Qerror not Qt, so you can get a backtrace */
|
|
4330 tem = condition_case_1 (Qerror,
|
|
4331 catch_them_squirmers_run_hook, hook_symbol,
|
|
4332 caught_a_squirmer, opaque);
|
|
4333 if (OPAQUEP (opaque))
|
|
4334 free_opaque_ptr (opaque);
|
|
4335 UNGCPRO;
|
|
4336
|
|
4337 return unbind_to (speccount, tem);
|
|
4338 }
|
|
4339
|
|
4340 /* Same as run_hook_trapping_errors() but also set the hook to nil
|
|
4341 if an error occurs. */
|
|
4342
|
|
4343 Lisp_Object
|
|
4344 safe_run_hook_trapping_errors (CONST char *warning_string,
|
|
4345 Lisp_Object hook_symbol,
|
|
4346 int allow_quit)
|
|
4347 {
|
|
4348 int speccount = specpdl_depth ();
|
|
4349 Lisp_Object tem;
|
|
4350 Lisp_Object cons = Qnil;
|
|
4351 struct gcpro gcpro1;
|
|
4352
|
|
4353 if (!initialized || preparing_for_armageddon)
|
|
4354 return Qnil;
|
|
4355 tem = find_symbol_value (hook_symbol);
|
|
4356 if (NILP (tem) || UNBOUNDP (tem))
|
|
4357 return Qnil;
|
|
4358
|
|
4359 if (!allow_quit)
|
|
4360 specbind (Qinhibit_quit, Qt);
|
|
4361
|
|
4362 cons = noseeum_cons (hook_symbol,
|
|
4363 warning_string ? make_opaque_ptr (warning_string)
|
|
4364 : Qnil);
|
|
4365 GCPRO1 (cons);
|
|
4366 /* Qerror not Qt, so you can get a backtrace */
|
|
4367 tem = condition_case_1 (Qerror,
|
|
4368 catch_them_squirmers_run_hook,
|
|
4369 hook_symbol,
|
|
4370 allow_quit ?
|
|
4371 allow_quit_safe_run_hook_caught_a_squirmer :
|
|
4372 safe_run_hook_caught_a_squirmer,
|
|
4373 cons);
|
|
4374 if (OPAQUEP (XCDR (cons)))
|
|
4375 free_opaque_ptr (XCDR (cons));
|
|
4376 free_cons (XCONS (cons));
|
|
4377 UNGCPRO;
|
|
4378
|
|
4379 return unbind_to (speccount, tem);
|
|
4380 }
|
|
4381
|
|
4382 static Lisp_Object
|
|
4383 catch_them_squirmers_call0 (Lisp_Object function)
|
|
4384 {
|
|
4385 /* This function can GC */
|
|
4386 return call0 (function);
|
|
4387 }
|
|
4388
|
|
4389 Lisp_Object
|
|
4390 call0_trapping_errors (CONST char *warning_string, Lisp_Object function)
|
|
4391 {
|
|
4392 int speccount = specpdl_depth ();
|
|
4393 Lisp_Object tem;
|
|
4394 Lisp_Object opaque = Qnil;
|
|
4395 struct gcpro gcpro1, gcpro2;
|
|
4396
|
|
4397 if (SYMBOLP (function))
|
|
4398 {
|
|
4399 tem = XSYMBOL (function)->function;
|
|
4400 if (NILP (tem) || UNBOUNDP (tem))
|
|
4401 return (Qnil);
|
|
4402 }
|
|
4403
|
|
4404 GCPRO2 (opaque, function);
|
|
4405 specbind (Qinhibit_quit, Qt);
|
|
4406 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4407
|
|
4408 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4409 /* Qerror not Qt, so you can get a backtrace */
|
|
4410 tem = condition_case_1 (Qerror,
|
|
4411 catch_them_squirmers_call0, function,
|
|
4412 caught_a_squirmer, opaque);
|
|
4413 if (OPAQUEP (opaque))
|
|
4414 free_opaque_ptr (opaque);
|
|
4415 UNGCPRO;
|
|
4416
|
|
4417 /* gc_currently_forbidden = 0; */
|
|
4418 return unbind_to (speccount, tem);
|
|
4419 }
|
|
4420
|
|
4421 static Lisp_Object
|
|
4422 catch_them_squirmers_call1 (Lisp_Object cons)
|
|
4423 {
|
|
4424 /* This function can GC */
|
|
4425 return call1 (XCAR (cons), XCDR (cons));
|
|
4426 }
|
|
4427
|
|
4428 static Lisp_Object
|
|
4429 catch_them_squirmers_call2 (Lisp_Object cons)
|
|
4430 {
|
|
4431 /* This function can GC */
|
|
4432 return call2 (XCAR (cons), XCAR (XCDR (cons)), XCAR (XCDR (XCDR (cons))));
|
|
4433 }
|
|
4434
|
|
4435 Lisp_Object
|
|
4436 call1_trapping_errors (CONST char *warning_string, Lisp_Object function,
|
|
4437 Lisp_Object object)
|
|
4438 {
|
|
4439 int speccount = specpdl_depth ();
|
|
4440 Lisp_Object tem;
|
|
4441 Lisp_Object cons = Qnil;
|
|
4442 Lisp_Object opaque = Qnil;
|
|
4443 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
4444
|
|
4445 if (SYMBOLP (function))
|
|
4446 {
|
|
4447 tem = XSYMBOL (function)->function;
|
|
4448 if (NILP (tem) || UNBOUNDP (tem))
|
|
4449 return (Qnil);
|
|
4450 }
|
|
4451
|
|
4452 GCPRO4 (cons, opaque, function, object);
|
|
4453
|
|
4454 specbind (Qinhibit_quit, Qt);
|
|
4455 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4456
|
|
4457 cons = noseeum_cons (function, object);
|
|
4458 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4459 /* Qerror not Qt, so you can get a backtrace */
|
|
4460 tem = condition_case_1 (Qerror,
|
|
4461 catch_them_squirmers_call1, cons,
|
|
4462 caught_a_squirmer, opaque);
|
|
4463 if (OPAQUEP (opaque))
|
|
4464 free_opaque_ptr (opaque);
|
|
4465 free_cons (XCONS (cons));
|
|
4466 UNGCPRO;
|
|
4467
|
|
4468 /* gc_currently_forbidden = 0; */
|
|
4469 return unbind_to (speccount, tem);
|
|
4470 }
|
|
4471
|
|
4472 Lisp_Object
|
|
4473 call2_trapping_errors (CONST char *warning_string, Lisp_Object function,
|
|
4474 Lisp_Object object1, Lisp_Object object2)
|
|
4475 {
|
|
4476 int speccount = specpdl_depth ();
|
|
4477 Lisp_Object tem;
|
|
4478 Lisp_Object cons = Qnil;
|
|
4479 Lisp_Object opaque = Qnil;
|
|
4480 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
4481
|
|
4482 if (SYMBOLP (function))
|
|
4483 {
|
|
4484 tem = XSYMBOL (function)->function;
|
|
4485 if (NILP (tem) || UNBOUNDP (tem))
|
|
4486 return (Qnil);
|
|
4487 }
|
|
4488
|
|
4489 GCPRO5 (cons, opaque, function, object1, object2);
|
|
4490 specbind (Qinhibit_quit, Qt);
|
|
4491 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4492
|
|
4493 cons = list3 (function, object1, object2);
|
|
4494 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4495 /* Qerror not Qt, so you can get a backtrace */
|
|
4496 tem = condition_case_1 (Qerror,
|
|
4497 catch_them_squirmers_call2, cons,
|
|
4498 caught_a_squirmer, opaque);
|
|
4499 if (OPAQUEP (opaque))
|
|
4500 free_opaque_ptr (opaque);
|
|
4501 free_list (cons);
|
|
4502 UNGCPRO;
|
|
4503
|
|
4504 /* gc_currently_forbidden = 0; */
|
|
4505 return unbind_to (speccount, tem);
|
|
4506 }
|
|
4507
|
|
4508
|
|
4509 /**********************************************************************/
|
|
4510 /* The special binding stack */
|
|
4511 /**********************************************************************/
|
|
4512
|
2
|
4513 #define min_max_specpdl_size 400
|
|
4514
|
0
|
4515 static void
|
|
4516 grow_specpdl (void)
|
|
4517 {
|
|
4518 if (specpdl_size >= max_specpdl_size)
|
|
4519 {
|
2
|
4520 if (max_specpdl_size < min_max_specpdl_size)
|
|
4521 max_specpdl_size = min_max_specpdl_size;
|
0
|
4522 if (specpdl_size >= max_specpdl_size)
|
|
4523 {
|
|
4524 if (!NILP (Vdebug_on_error) || !NILP (Vdebug_on_signal))
|
|
4525 /* Leave room for some specpdl in the debugger. */
|
|
4526 max_specpdl_size = specpdl_size + 100;
|
|
4527 continuable_error
|
|
4528 ("Variable binding depth exceeds max-specpdl-size");
|
|
4529 }
|
|
4530 }
|
|
4531 specpdl_size *= 2;
|
|
4532 if (specpdl_size > max_specpdl_size)
|
|
4533 specpdl_size = max_specpdl_size;
|
|
4534 specpdl = ((struct specbinding *)
|
|
4535 xrealloc (specpdl, specpdl_size * sizeof (struct specbinding)));
|
|
4536 specpdl_ptr = specpdl + specpdl_depth_counter;
|
|
4537 }
|
|
4538
|
|
4539
|
|
4540 /* Handle unbinding buffer-local variables */
|
|
4541 static Lisp_Object
|
|
4542 specbind_unwind_local (Lisp_Object ovalue)
|
|
4543 {
|
|
4544 Lisp_Object current = Fcurrent_buffer ();
|
|
4545 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4546 struct Lisp_Cons *victim = XCONS (ovalue);
|
|
4547 Lisp_Object buf = get_buffer (victim->car, 0);
|
|
4548 ovalue = victim->cdr;
|
|
4549
|
|
4550 free_cons (victim);
|
|
4551
|
|
4552 if (NILP (buf))
|
|
4553 {
|
|
4554 /* Deleted buffer -- do nothing */
|
|
4555 }
|
|
4556 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buf)) == 0)
|
|
4557 {
|
|
4558 /* Was buffer-local when binding was made, now no longer is.
|
|
4559 * (kill-local-variable can do this.)
|
|
4560 * Do nothing in this case.
|
|
4561 */
|
|
4562 }
|
|
4563 else if (EQ (buf, current))
|
|
4564 Fset (symbol, ovalue);
|
|
4565 else
|
|
4566 {
|
|
4567 /* Urk! Somebody switched buffers */
|
|
4568 struct gcpro gcpro1;
|
|
4569 GCPRO1 (current);
|
|
4570 Fset_buffer (buf);
|
|
4571 Fset (symbol, ovalue);
|
|
4572 Fset_buffer (current);
|
|
4573 UNGCPRO;
|
|
4574 }
|
|
4575 return (symbol);
|
|
4576 }
|
|
4577
|
|
4578 static Lisp_Object
|
|
4579 specbind_unwind_wasnt_local (Lisp_Object buffer)
|
|
4580 {
|
|
4581 Lisp_Object current = Fcurrent_buffer ();
|
|
4582 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4583
|
|
4584 buffer = get_buffer (buffer, 0);
|
|
4585 if (NILP (buffer))
|
|
4586 {
|
|
4587 /* Deleted buffer -- do nothing */
|
|
4588 }
|
|
4589 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buffer)) == 0)
|
|
4590 {
|
|
4591 /* Was buffer-local when binding was made, now no longer is.
|
|
4592 * (kill-local-variable can do this.)
|
|
4593 * Do nothing in this case.
|
|
4594 */
|
|
4595 }
|
|
4596 else if (EQ (buffer, current))
|
|
4597 Fkill_local_variable (symbol);
|
|
4598 else
|
|
4599 {
|
|
4600 /* Urk! Somebody switched buffers */
|
|
4601 struct gcpro gcpro1;
|
|
4602 GCPRO1 (current);
|
|
4603 Fset_buffer (buffer);
|
|
4604 Fkill_local_variable (symbol);
|
|
4605 Fset_buffer (current);
|
|
4606 UNGCPRO;
|
|
4607 }
|
|
4608 return (symbol);
|
|
4609 }
|
|
4610
|
|
4611
|
|
4612 /* Don't want to include buffer.h just for this */
|
|
4613 extern struct buffer *current_buffer;
|
|
4614
|
|
4615 void
|
|
4616 specbind (Lisp_Object symbol, Lisp_Object value)
|
|
4617 {
|
|
4618 int buffer_local;
|
|
4619
|
|
4620 CHECK_SYMBOL (symbol);
|
|
4621
|
|
4622 if (specpdl_depth_counter >= specpdl_size)
|
|
4623 grow_specpdl ();
|
|
4624
|
|
4625 buffer_local = symbol_value_buffer_local_info (symbol, current_buffer);
|
|
4626 if (buffer_local == 0)
|
|
4627 {
|
|
4628 specpdl_ptr->old_value = find_symbol_value (symbol);
|
|
4629 specpdl_ptr->func = 0; /* Handled specially by unbind_to */
|
|
4630 }
|
|
4631 else if (buffer_local > 0)
|
|
4632 {
|
|
4633 /* Already buffer-local */
|
|
4634 specpdl_ptr->old_value = noseeum_cons (Fcurrent_buffer (),
|
|
4635 find_symbol_value (symbol));
|
|
4636 specpdl_ptr->func = specbind_unwind_local;
|
|
4637 }
|
|
4638 else
|
|
4639 {
|
|
4640 /* About to become buffer-local */
|
|
4641 specpdl_ptr->old_value = Fcurrent_buffer ();
|
|
4642 specpdl_ptr->func = specbind_unwind_wasnt_local;
|
|
4643 }
|
|
4644
|
|
4645 specpdl_ptr->symbol = symbol;
|
|
4646 specpdl_ptr++;
|
|
4647 specpdl_depth_counter++;
|
|
4648
|
|
4649 Fset (symbol, value);
|
|
4650 }
|
|
4651
|
|
4652 void
|
|
4653 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg),
|
|
4654 Lisp_Object arg)
|
|
4655 {
|
|
4656 if (specpdl_depth_counter >= specpdl_size)
|
|
4657 grow_specpdl ();
|
|
4658 specpdl_ptr->func = function;
|
|
4659 specpdl_ptr->symbol = Qnil;
|
|
4660 specpdl_ptr->old_value = arg;
|
|
4661 specpdl_ptr++;
|
|
4662 specpdl_depth_counter++;
|
|
4663 }
|
|
4664
|
|
4665 extern int check_sigio (void);
|
|
4666
|
|
4667 Lisp_Object
|
|
4668 unbind_to (int count, Lisp_Object value)
|
|
4669 {
|
|
4670 int quitf;
|
|
4671 struct gcpro gcpro1;
|
|
4672
|
|
4673 GCPRO1 (value);
|
|
4674
|
|
4675 check_quit (); /* make Vquit_flag accurate */
|
|
4676 quitf = !NILP (Vquit_flag);
|
|
4677 Vquit_flag = Qnil;
|
|
4678
|
|
4679 while (specpdl_depth_counter != count)
|
|
4680 {
|
|
4681 Lisp_Object ovalue;
|
|
4682 --specpdl_ptr;
|
|
4683 --specpdl_depth_counter;
|
|
4684
|
|
4685 ovalue = specpdl_ptr->old_value;
|
|
4686 if (specpdl_ptr->func != 0)
|
|
4687 /* An unwind-protect */
|
|
4688 (*specpdl_ptr->func) (ovalue);
|
|
4689 else
|
|
4690 Fset (specpdl_ptr->symbol, ovalue);
|
|
4691
|
|
4692 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE
|
|
4693 /* There should never be anything here for us to remove.
|
|
4694 If so, it indicates a logic error in Emacs. Catches
|
|
4695 should get removed when a throw or signal occurs, or
|
|
4696 when a catch or condition-case exits normally. But
|
|
4697 it's too dangerous to just remove this code. --ben */
|
|
4698
|
|
4699 /* Furthermore, this code is not in FSFmacs!!!
|
|
4700 Braino on mly's part? */
|
|
4701 /* If we're unwound past the pdlcount of a catch frame,
|
|
4702 that catch can't possibly still be valid. */
|
|
4703 while (catchlist && catchlist->pdlcount > specpdl_depth_counter)
|
|
4704 {
|
|
4705 catchlist = catchlist->next;
|
|
4706 /* Don't mess with gcprolist, backtrace_list here */
|
|
4707 }
|
|
4708 #endif
|
|
4709 }
|
|
4710 if (quitf)
|
|
4711 Vquit_flag = Qt;
|
|
4712
|
|
4713 UNGCPRO;
|
|
4714
|
|
4715 return (value);
|
|
4716 }
|
|
4717
|
|
4718
|
|
4719 int
|
|
4720 specpdl_depth (void)
|
|
4721 {
|
|
4722 return (specpdl_depth_counter);
|
|
4723 }
|
|
4724
|
|
4725
|
|
4726 /* Get the value of symbol's global binding, even if that binding is
|
|
4727 not now dynamically visible. May return Qunbound or magic values. */
|
|
4728
|
|
4729 Lisp_Object
|
|
4730 top_level_value (Lisp_Object symbol)
|
|
4731 {
|
|
4732 REGISTER struct specbinding *ptr = specpdl;
|
|
4733
|
|
4734 CHECK_SYMBOL (symbol);
|
|
4735 for (; ptr != specpdl_ptr; ptr++)
|
|
4736 {
|
|
4737 if (EQ (ptr->symbol, symbol))
|
|
4738 return ptr->old_value;
|
|
4739 }
|
|
4740 return XSYMBOL (symbol)->value;
|
|
4741 }
|
|
4742
|
|
4743 #if 0
|
|
4744
|
|
4745 Lisp_Object
|
|
4746 top_level_set (Lisp_Object symbol, Lisp_Object newval)
|
|
4747 {
|
|
4748 REGISTER struct specbinding *ptr = specpdl;
|
|
4749
|
|
4750 CHECK_SYMBOL (symbol);
|
|
4751 for (; ptr != specpdl_ptr; ptr++)
|
|
4752 {
|
|
4753 if (EQ (ptr->symbol, symbol))
|
|
4754 {
|
|
4755 ptr->old_value = newval;
|
|
4756 return newval;
|
|
4757 }
|
|
4758 }
|
|
4759 return Fset (symbol, newval);
|
|
4760 }
|
|
4761
|
|
4762 #endif /* 0 */
|
|
4763
|
|
4764
|
|
4765 /**********************************************************************/
|
|
4766 /* Backtraces */
|
|
4767 /**********************************************************************/
|
|
4768
|
20
|
4769 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /*
|
0
|
4770 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
|
|
4771 The debugger is entered when that frame exits, if the flag is non-nil.
|
20
|
4772 */
|
|
4773 (level, flag))
|
0
|
4774 {
|
|
4775 REGISTER struct backtrace *backlist = backtrace_list;
|
|
4776 REGISTER int i;
|
|
4777
|
|
4778 CHECK_INT (level);
|
|
4779
|
|
4780 for (i = 0; backlist && i < XINT (level); i++)
|
|
4781 {
|
|
4782 backlist = backlist->next;
|
|
4783 }
|
|
4784
|
|
4785 if (backlist)
|
|
4786 backlist->debug_on_exit = !NILP (flag);
|
|
4787
|
|
4788 return flag;
|
|
4789 }
|
|
4790
|
|
4791 static void
|
|
4792 backtrace_specials (int speccount, int speclimit, Lisp_Object stream)
|
|
4793 {
|
|
4794 int printing_bindings = 0;
|
|
4795
|
|
4796 for (; speccount > speclimit; speccount--)
|
|
4797 {
|
|
4798 if (specpdl[speccount - 1].func == 0
|
|
4799 || specpdl[speccount - 1].func == specbind_unwind_local
|
|
4800 || specpdl[speccount - 1].func == specbind_unwind_wasnt_local)
|
|
4801 {
|
|
4802 write_c_string (((!printing_bindings) ? " # bind (" : " "),
|
|
4803 stream);
|
|
4804 Fprin1 (specpdl[speccount - 1].symbol, stream);
|
|
4805 printing_bindings = 1;
|
|
4806 }
|
|
4807 else
|
|
4808 {
|
|
4809 if (printing_bindings) write_c_string (")\n", stream);
|
|
4810 write_c_string (" # (unwind-protect ...)\n", stream);
|
|
4811 printing_bindings = 0;
|
|
4812 }
|
|
4813 }
|
|
4814 if (printing_bindings) write_c_string (")\n", stream);
|
|
4815 }
|
|
4816
|
20
|
4817 DEFUN ("backtrace", Fbacktrace, 0, 2, "", /*
|
0
|
4818 Print a trace of Lisp function calls currently active.
|
|
4819 Option arg STREAM specifies the output stream to send the backtrace to,
|
|
4820 and defaults to the value of `standard-output'. Optional second arg
|
|
4821 DETAILED means show places where currently active variable bindings,
|
|
4822 catches, condition-cases, and unwind-protects were made as well as
|
|
4823 function calls.
|
20
|
4824 */
|
|
4825 (stream, detailed))
|
0
|
4826 {
|
|
4827 struct backtrace *backlist = backtrace_list;
|
|
4828 struct catchtag *catches = catchlist;
|
|
4829 int speccount = specpdl_depth_counter;
|
|
4830
|
|
4831 int old_nl = print_escape_newlines;
|
|
4832 int old_pr = print_readably;
|
|
4833 Lisp_Object old_level = Vprint_level;
|
|
4834 Lisp_Object oiq = Vinhibit_quit;
|
|
4835 struct gcpro gcpro1, gcpro2;
|
|
4836
|
|
4837 /* We can't allow quits in here because that could cause the values
|
|
4838 of print_readably and print_escape_newlines to get screwed up.
|
|
4839 Normally we would use a record_unwind_protect but that would
|
|
4840 screw up the functioning of this function. */
|
|
4841 Vinhibit_quit = Qt;
|
|
4842
|
|
4843 entering_debugger = 0;
|
|
4844
|
|
4845 Vprint_level = make_int (3);
|
|
4846 print_readably = 0;
|
|
4847 print_escape_newlines = 1;
|
|
4848
|
|
4849 GCPRO2 (stream, old_level);
|
|
4850
|
|
4851 if (NILP (stream))
|
|
4852 stream = Vstandard_output;
|
|
4853 if (!noninteractive && (NILP (stream) || EQ (stream, Qt)))
|
|
4854 stream = Fselected_frame (Qnil);
|
|
4855
|
|
4856 for (;;)
|
|
4857 {
|
|
4858 if (!NILP (detailed) && catches && catches->backlist == backlist)
|
|
4859 {
|
|
4860 int catchpdl = catches->pdlcount;
|
|
4861 if (specpdl[catchpdl].func == condition_case_unwind
|
|
4862 && speccount > catchpdl)
|
|
4863 /* This is a condition-case catchpoint */
|
|
4864 catchpdl = catchpdl + 1;
|
|
4865
|
|
4866 backtrace_specials (speccount, catchpdl, stream);
|
|
4867
|
|
4868 speccount = catches->pdlcount;
|
|
4869 if (catchpdl == speccount)
|
|
4870 {
|
|
4871 write_c_string (" # (catch ", stream);
|
|
4872 Fprin1 (catches->tag, stream);
|
|
4873 write_c_string (" ...)\n", stream);
|
|
4874 }
|
|
4875 else
|
|
4876 {
|
|
4877 write_c_string (" # (condition-case ... . ", stream);
|
|
4878 Fprin1 (Fcdr (Fcar (catches->tag)), stream);
|
|
4879 write_c_string (")\n", stream);
|
|
4880 }
|
|
4881 catches = catches->next;
|
|
4882 }
|
|
4883 else if (!backlist)
|
|
4884 break;
|
|
4885 else
|
|
4886 {
|
|
4887 if (!NILP (detailed) && backlist->pdlcount < speccount)
|
|
4888 {
|
|
4889 backtrace_specials (speccount, backlist->pdlcount, stream);
|
|
4890 speccount = backlist->pdlcount;
|
|
4891 }
|
|
4892 write_c_string (((backlist->debug_on_exit) ? "* " : " "),
|
|
4893 stream);
|
|
4894 if (backlist->nargs == UNEVALLED)
|
|
4895 {
|
|
4896 Fprin1 (Fcons (*backlist->function, *backlist->args), stream);
|
|
4897 write_c_string ("\n", stream); /* from FSFmacs 19.30 */
|
|
4898 }
|
|
4899 else
|
|
4900 {
|
|
4901 Lisp_Object tem = *backlist->function;
|
|
4902 Fprin1 (tem, stream); /* This can QUIT */
|
|
4903 write_c_string ("(", stream);
|
|
4904 if (backlist->nargs == MANY)
|
|
4905 {
|
|
4906 int i;
|
|
4907 Lisp_Object tail = Qnil;
|
|
4908 struct gcpro ngcpro1;
|
|
4909
|
|
4910 NGCPRO1 (tail);
|
|
4911 for (tail = *backlist->args, i = 0;
|
|
4912 !NILP (tail);
|
|
4913 tail = Fcdr (tail), i++)
|
|
4914 {
|
|
4915 if (i != 0) write_c_string (" ", stream);
|
|
4916 Fprin1 (Fcar (tail), stream);
|
|
4917 }
|
|
4918 NUNGCPRO;
|
|
4919 }
|
|
4920 else
|
|
4921 {
|
|
4922 int i;
|
|
4923 for (i = 0; i < backlist->nargs; i++)
|
|
4924 {
|
|
4925 if (i != 0) write_c_string (" ", stream);
|
|
4926 Fprin1 (backlist->args[i], stream);
|
|
4927 }
|
|
4928 }
|
|
4929 }
|
|
4930 write_c_string (")\n", stream);
|
|
4931 backlist = backlist->next;
|
|
4932 }
|
|
4933 }
|
|
4934 Vprint_level = old_level;
|
|
4935 print_readably = old_pr;
|
|
4936 print_escape_newlines = old_nl;
|
|
4937 UNGCPRO;
|
|
4938 Vinhibit_quit = oiq;
|
|
4939 return Qnil;
|
|
4940 }
|
|
4941
|
|
4942
|
20
|
4943 DEFUN ("backtrace-frame", Fbacktrace_frame, 1, 1, "", /*
|
0
|
4944 Return the function and arguments N frames up from current execution point.
|
|
4945 If that frame has not evaluated the arguments yet (or is a special form),
|
|
4946 the value is (nil FUNCTION ARG-FORMS...).
|
|
4947 If that frame has evaluated its arguments and called its function already,
|
|
4948 the value is (t FUNCTION ARG-VALUES...).
|
|
4949 A &rest arg is represented as the tail of the list ARG-VALUES.
|
|
4950 FUNCTION is whatever was supplied as car of evaluated list,
|
|
4951 or a lambda expression for macro calls.
|
|
4952 If N is more than the number of frames, the value is nil.
|
20
|
4953 */
|
|
4954 (nframes))
|
0
|
4955 {
|
|
4956 REGISTER struct backtrace *backlist = backtrace_list;
|
|
4957 REGISTER int i;
|
|
4958 Lisp_Object tem;
|
|
4959
|
|
4960 CHECK_NATNUM (nframes);
|
|
4961
|
|
4962 /* Find the frame requested. */
|
|
4963 for (i = XINT (nframes); backlist && (i-- > 0);)
|
|
4964 backlist = backlist->next;
|
|
4965
|
|
4966 if (!backlist)
|
|
4967 return Qnil;
|
|
4968 if (backlist->nargs == UNEVALLED)
|
|
4969 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
|
|
4970 else
|
|
4971 {
|
|
4972 if (backlist->nargs == MANY)
|
|
4973 tem = *backlist->args;
|
|
4974 else
|
|
4975 tem = Flist (backlist->nargs, backlist->args);
|
|
4976
|
|
4977 return Fcons (Qt, Fcons (*backlist->function, tem));
|
|
4978 }
|
|
4979 }
|
|
4980
|
|
4981
|
|
4982 /**********************************************************************/
|
|
4983 /* Warnings */
|
|
4984 /**********************************************************************/
|
|
4985
|
|
4986 void
|
|
4987 warn_when_safe_lispobj (Lisp_Object class, Lisp_Object level,
|
|
4988 Lisp_Object obj)
|
|
4989 {
|
|
4990 obj = list1 (list3 (class, level, obj));
|
|
4991 if (NILP (Vpending_warnings))
|
|
4992 Vpending_warnings = Vpending_warnings_tail = obj;
|
|
4993 else
|
|
4994 {
|
|
4995 Fsetcdr (Vpending_warnings_tail, obj);
|
|
4996 Vpending_warnings_tail = obj;
|
|
4997 }
|
|
4998 }
|
|
4999
|
|
5000 /* #### This should probably accept Lisp objects; but then we have
|
|
5001 to make sure that Feval() isn't called, since it might not be safe.
|
|
5002
|
|
5003 An alternative approach is to just pass some non-string type of
|
|
5004 Lisp Object to warn_when_safe_lispobj(); `prin1-to-string' will
|
|
5005 automatically be called when it is safe to do so. */
|
|
5006
|
|
5007 void
|
|
5008 warn_when_safe (Lisp_Object class, Lisp_Object level, CONST char *fmt, ...)
|
|
5009 {
|
|
5010 Lisp_Object obj;
|
|
5011 va_list args;
|
|
5012
|
|
5013 va_start (args, fmt);
|
|
5014 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt),
|
|
5015 Qnil, -1, args);
|
|
5016 va_end (args);
|
|
5017
|
|
5018 warn_when_safe_lispobj (class, level, obj);
|
|
5019 }
|
|
5020
|
|
5021
|
|
5022
|
|
5023
|
|
5024 /**********************************************************************/
|
|
5025 /* Initialization */
|
|
5026 /**********************************************************************/
|
|
5027
|
|
5028 void
|
|
5029 syms_of_eval (void)
|
|
5030 {
|
|
5031 defsymbol (&Qinhibit_quit, "inhibit-quit");
|
|
5032 defsymbol (&Qautoload, "autoload");
|
|
5033 defsymbol (&Qdebug_on_error, "debug-on-error");
|
|
5034 defsymbol (&Qstack_trace_on_error, "stack-trace-on-error");
|
|
5035 defsymbol (&Qdebug_on_signal, "debug-on-signal");
|
|
5036 defsymbol (&Qstack_trace_on_signal, "stack-trace-on-signal");
|
|
5037 defsymbol (&Qdebugger, "debugger");
|
|
5038 defsymbol (&Qmacro, "macro");
|
|
5039 defsymbol (&Qand_rest, "&rest");
|
|
5040 defsymbol (&Qand_optional, "&optional");
|
|
5041 /* Note that the process code also uses Qexit */
|
|
5042 defsymbol (&Qexit, "exit");
|
|
5043 defsymbol (&Qsetq, "setq");
|
|
5044 defsymbol (&Qinteractive, "interactive");
|
|
5045 defsymbol (&Qcommandp, "commandp");
|
|
5046 defsymbol (&Qdefun, "defun");
|
|
5047 defsymbol (&Qprogn, "progn");
|
|
5048 defsymbol (&Qvalues, "values");
|
|
5049 defsymbol (&Qdisplay_warning, "display-warning");
|
|
5050 defsymbol (&Qrun_hooks, "run-hooks");
|
|
5051
|
20
|
5052 DEFSUBR (For);
|
|
5053 DEFSUBR (Fand);
|
|
5054 DEFSUBR (Fif);
|
|
5055 DEFSUBR (Fcond);
|
|
5056 DEFSUBR (Fprogn);
|
|
5057 DEFSUBR (Fprog1);
|
|
5058 DEFSUBR (Fprog2);
|
|
5059 DEFSUBR (Fsetq);
|
|
5060 DEFSUBR (Fquote);
|
|
5061 DEFSUBR (Ffunction);
|
|
5062 DEFSUBR (Fdefun);
|
|
5063 DEFSUBR (Fdefmacro);
|
|
5064 DEFSUBR (Fdefvar);
|
|
5065 DEFSUBR (Fdefconst);
|
|
5066 DEFSUBR (Fuser_variable_p);
|
|
5067 DEFSUBR (Flet);
|
|
5068 DEFSUBR (FletX);
|
|
5069 DEFSUBR (Fwhile);
|
|
5070 DEFSUBR (Fmacroexpand_internal);
|
|
5071 DEFSUBR (Fcatch);
|
|
5072 DEFSUBR (Fthrow);
|
|
5073 DEFSUBR (Funwind_protect);
|
|
5074 DEFSUBR (Fcondition_case);
|
|
5075 DEFSUBR (Fcall_with_condition_handler);
|
|
5076 DEFSUBR (Fsignal);
|
|
5077 DEFSUBR (Finteractive_p);
|
149
|
5078 DEFSUBR (Fstrerror);
|
20
|
5079 DEFSUBR (Fcommandp);
|
|
5080 DEFSUBR (Fcommand_execute);
|
|
5081 DEFSUBR (Fautoload);
|
|
5082 DEFSUBR (Feval);
|
|
5083 DEFSUBR (Fapply);
|
|
5084 DEFSUBR (Ffuncall);
|
|
5085 DEFSUBR (Ffunction_min_args);
|
|
5086 DEFSUBR (Ffunction_max_args);
|
|
5087 DEFSUBR (Frun_hooks);
|
|
5088 DEFSUBR (Frun_hook_with_args);
|
|
5089 DEFSUBR (Frun_hook_with_args_until_success);
|
|
5090 DEFSUBR (Frun_hook_with_args_until_failure);
|
|
5091 DEFSUBR (Ffetch_bytecode);
|
|
5092 DEFSUBR (Fbacktrace_debug);
|
|
5093 DEFSUBR (Fbacktrace);
|
|
5094 DEFSUBR (Fbacktrace_frame);
|
0
|
5095 }
|
|
5096
|
|
5097 void
|
|
5098 reinit_eval (void)
|
|
5099 {
|
|
5100 specpdl_ptr = specpdl;
|
|
5101 specpdl_depth_counter = 0;
|
|
5102 catchlist = 0;
|
|
5103 Vcondition_handlers = Qnil;
|
|
5104 backtrace_list = 0;
|
|
5105 Vquit_flag = Qnil;
|
|
5106 debug_on_next_call = 0;
|
|
5107 lisp_eval_depth = 0;
|
|
5108 entering_debugger = 0;
|
|
5109 }
|
|
5110
|
|
5111 void
|
|
5112 vars_of_eval (void)
|
|
5113 {
|
|
5114 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size /*
|
|
5115 Limit on number of Lisp variable bindings & unwind-protects before error.
|
|
5116 */ );
|
|
5117
|
|
5118 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth /*
|
|
5119 Limit on depth in `eval', `apply' and `funcall' before error.
|
|
5120 This limit is to catch infinite recursions for you before they cause
|
|
5121 actual stack overflow in C, which would be fatal for Emacs.
|
|
5122 You can safely make it considerably larger than its default value,
|
|
5123 if that proves inconveniently small.
|
|
5124 */ );
|
|
5125
|
|
5126 DEFVAR_LISP ("quit-flag", &Vquit_flag /*
|
|
5127 Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
|
|
5128 Typing C-G sets `quit-flag' non-nil, regardless of `inhibit-quit'.
|
|
5129 */ );
|
|
5130 Vquit_flag = Qnil;
|
|
5131
|
|
5132 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit /*
|
|
5133 Non-nil inhibits C-g quitting from happening immediately.
|
|
5134 Note that `quit-flag' will still be set by typing C-g,
|
|
5135 so a quit will be signalled as soon as `inhibit-quit' is nil.
|
|
5136 To prevent this happening, set `quit-flag' to nil
|
|
5137 before making `inhibit-quit' nil. The value of `inhibit-quit' is
|
|
5138 ignored if a critical quit is requested by typing control-shift-G in
|
|
5139 an X frame.
|
|
5140 */ );
|
|
5141 Vinhibit_quit = Qnil;
|
|
5142
|
|
5143 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error /*
|
|
5144 *Non-nil means automatically display a backtrace buffer
|
|
5145 after any error that is not handled by a `condition-case'.
|
|
5146 If the value is a list, an error only means to display a backtrace
|
|
5147 if one of its condition symbols appears in the list.
|
|
5148 See also variable `stack-trace-on-signal'.
|
|
5149 */ );
|
|
5150 Vstack_trace_on_error = Qnil;
|
|
5151
|
|
5152 DEFVAR_LISP ("stack-trace-on-signal", &Vstack_trace_on_signal /*
|
|
5153 *Non-nil means automatically display a backtrace buffer
|
|
5154 after any error that is signalled, whether or not it is handled by
|
|
5155 a `condition-case'.
|
|
5156 If the value is a list, an error only means to display a backtrace
|
|
5157 if one of its condition symbols appears in the list.
|
|
5158 See also variable `stack-trace-on-error'.
|
|
5159 */ );
|
|
5160 Vstack_trace_on_signal = Qnil;
|
|
5161
|
|
5162 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error /*
|
|
5163 *Non-nil means enter debugger if an unhandled error is signalled.
|
|
5164 The debugger will not be entered if the error is handled by
|
|
5165 a `condition-case'.
|
|
5166 If the value is a list, an error only means to enter the debugger
|
|
5167 if one of its condition symbols appears in the list.
|
|
5168 See also variables `debug-on-quit' and `debug-on-signal'.
|
|
5169 */ );
|
|
5170 Vdebug_on_error = Qnil;
|
|
5171
|
|
5172 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal /*
|
|
5173 *Non-nil means enter debugger if an error is signalled.
|
|
5174 The debugger will be entered whether or not the error is handled by
|
|
5175 a `condition-case'.
|
|
5176 If the value is a list, an error only means to enter the debugger
|
|
5177 if one of its condition symbols appears in the list.
|
|
5178 See also variable `debug-on-quit'.
|
|
5179 */ );
|
|
5180 Vdebug_on_signal = Qnil;
|
|
5181
|
|
5182 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit /*
|
|
5183 *Non-nil means enter debugger if quit is signalled (C-G, for example).
|
|
5184 Does not apply if quit is handled by a `condition-case'. Entering the
|
|
5185 debugger can also be achieved at any time (for X11 console) by typing
|
|
5186 control-shift-G to signal a critical quit.
|
|
5187 */ );
|
|
5188 debug_on_quit = 0;
|
|
5189
|
|
5190 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call /*
|
|
5191 Non-nil means enter debugger before next `eval', `apply' or `funcall'.
|
|
5192 */ );
|
|
5193
|
|
5194 DEFVAR_LISP ("debugger", &Vdebugger /*
|
|
5195 Function to call to invoke debugger.
|
|
5196 If due to frame exit, args are `exit' and the value being returned;
|
|
5197 this function's value will be returned instead of that.
|
|
5198 If due to error, args are `error' and a list of the args to `signal'.
|
|
5199 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
5200 If due to `eval' entry, one arg, t.
|
|
5201 */ );
|
|
5202 Vdebugger = Qnil;
|
|
5203
|
|
5204 preparing_for_armageddon = 0;
|
|
5205
|
|
5206 staticpro (&Vpending_warnings);
|
|
5207 Vpending_warnings = Qnil;
|
|
5208 Vpending_warnings_tail = Qnil; /* no need to protect this */
|
|
5209
|
|
5210 in_warnings = 0;
|
|
5211
|
|
5212 staticpro (&Vautoload_queue);
|
|
5213 Vautoload_queue = Qnil;
|
|
5214
|
|
5215 staticpro (&Vcondition_handlers);
|
|
5216
|
|
5217 staticpro (&Vcurrent_warning_class);
|
|
5218 Vcurrent_warning_class = Qnil;
|
|
5219
|
|
5220 staticpro (&Vcurrent_error_state);
|
|
5221 Vcurrent_error_state = Qnil; /* errors as normal */
|
|
5222
|
|
5223 Qunbound_suspended_errors_tag = make_opaque_long (0);
|
|
5224 staticpro (&Qunbound_suspended_errors_tag);
|
|
5225
|
|
5226 specpdl_size = 50;
|
|
5227 specpdl_depth_counter = 0;
|
|
5228 specpdl = (struct specbinding *)
|
|
5229 xmalloc (specpdl_size * sizeof (struct specbinding));
|
|
5230 /* XEmacs change: increase these values. */
|
|
5231 max_specpdl_size = 3000;
|
|
5232 max_lisp_eval_depth = 500;
|
|
5233 throw_level = 0;
|
|
5234
|
|
5235 reinit_eval ();
|
|
5236 }
|