Undo last change. Consistency doesn't seem to be desired.
[bpt/emacs.git] / src / eval.c
1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000, 2001
3 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; 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
23 #include <config.h>
24 #include "lisp.h"
25 #include "blockinput.h"
26 #include "commands.h"
27 #include "keyboard.h"
28 #include "dispextern.h"
29 #include <setjmp.h>
30
31 /* This definition is duplicated in alloc.c and keyboard.c */
32 /* Putting it in lisp.h makes cc bomb out! */
33
34 struct backtrace
35 {
36 struct backtrace *next;
37 Lisp_Object *function;
38 Lisp_Object *args; /* Points to vector of args. */
39 int nargs; /* Length of vector.
40 If nargs is UNEVALLED, args points to slot holding
41 list of unevalled args */
42 char evalargs;
43 /* Nonzero means call value of debugger when done with this operation. */
44 char debug_on_exit;
45 };
46
47 struct backtrace *backtrace_list;
48
49 /* This structure helps implement the `catch' and `throw' control
50 structure. A struct catchtag contains all the information needed
51 to restore the state of the interpreter after a non-local jump.
52
53 Handlers for error conditions (represented by `struct handler'
54 structures) just point to a catch tag to do the cleanup required
55 for their jumps.
56
57 catchtag structures are chained together in the C calling stack;
58 the `next' member points to the next outer catchtag.
59
60 A call like (throw TAG VAL) searches for a catchtag whose `tag'
61 member is TAG, and then unbinds to it. The `val' member is used to
62 hold VAL while the stack is unwound; `val' is returned as the value
63 of the catch form.
64
65 All the other members are concerned with restoring the interpreter
66 state. */
67
68 struct catchtag
69 {
70 Lisp_Object tag;
71 Lisp_Object val;
72 struct catchtag *next;
73 struct gcpro *gcpro;
74 jmp_buf jmp;
75 struct backtrace *backlist;
76 struct handler *handlerlist;
77 int lisp_eval_depth;
78 int pdlcount;
79 int poll_suppress_count;
80 struct byte_stack *byte_stack;
81 };
82
83 struct catchtag *catchlist;
84
85 #ifdef DEBUG_GCPRO
86 /* Count levels of GCPRO to detect failure to UNGCPRO. */
87 int gcpro_level;
88 #endif
89
90 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
91 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag;
92 Lisp_Object Qmocklisp_arguments, Vmocklisp_arguments, Qmocklisp;
93 Lisp_Object Qand_rest, Qand_optional;
94 Lisp_Object Qdebug_on_error;
95
96 /* This holds either the symbol `run-hooks' or nil.
97 It is nil at an early stage of startup, and when Emacs
98 is shutting down. */
99
100 Lisp_Object Vrun_hooks;
101
102 /* Non-nil means record all fset's and provide's, to be undone
103 if the file being autoloaded is not fully loaded.
104 They are recorded by being consed onto the front of Vautoload_queue:
105 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
106
107 Lisp_Object Vautoload_queue;
108
109 /* Current number of specbindings allocated in specpdl. */
110
111 int specpdl_size;
112
113 /* Pointer to beginning of specpdl. */
114
115 struct specbinding *specpdl;
116
117 /* Pointer to first unused element in specpdl. */
118
119 struct specbinding *specpdl_ptr;
120
121 /* Maximum size allowed for specpdl allocation */
122
123 EMACS_INT max_specpdl_size;
124
125 /* Depth in Lisp evaluations and function calls. */
126
127 int lisp_eval_depth;
128
129 /* Maximum allowed depth in Lisp evaluations and function calls. */
130
131 EMACS_INT max_lisp_eval_depth;
132
133 /* Nonzero means enter debugger before next function call */
134
135 int debug_on_next_call;
136
137 /* Non-zero means debugger may continue. This is zero when the
138 debugger is called during redisplay, where it might not be safe to
139 continue the interrupted redisplay. */
140
141 int debugger_may_continue;
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
146 Lisp_Object Vstack_trace_on_error;
147
148 /* List of conditions (non-nil atom means all) which enter the debugger
149 if an error is handled by the command loop's error handler. */
150
151 Lisp_Object Vdebug_on_error;
152
153 /* List of conditions and regexps specifying error messages which
154 do not enter the debugger even if Vdebug_on_error says they should. */
155
156 Lisp_Object Vdebug_ignored_errors;
157
158 /* Non-nil means call the debugger even if the error will be handled. */
159
160 Lisp_Object Vdebug_on_signal;
161
162 /* Hook for edebug to use. */
163
164 Lisp_Object Vsignal_hook_function;
165
166 /* Nonzero means enter debugger if a quit signal
167 is handled by the command loop's error handler. */
168
169 int debug_on_quit;
170
171 /* The value of num_nonmacro_input_events as of the last time we
172 started to enter the debugger. If we decide to enter the debugger
173 again when this is still equal to num_nonmacro_input_events, then we
174 know that the debugger itself has an error, and we should just
175 signal the error instead of entering an infinite loop of debugger
176 invocations. */
177
178 int when_entered_debugger;
179
180 Lisp_Object Vdebugger;
181
182 /* The function from which the last `signal' was called. Set in
183 Fsignal. */
184
185 Lisp_Object Vsignaling_function;
186
187 /* Set to non-zero while processing X events. Checked in Feval to
188 make sure the Lisp interpreter isn't called from a signal handler,
189 which is unsafe because the interpreter isn't reentrant. */
190
191 int handling_signal;
192
193 static Lisp_Object funcall_lambda P_ ((Lisp_Object, int, Lisp_Object*));
194 /* Apply a mocklisp function to unevaluated argument list. */
195 extern Lisp_Object ml_apply P_ ((Lisp_Object, Lisp_Object));
196
197 void
198 init_eval_once ()
199 {
200 specpdl_size = 50;
201 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
202 specpdl_ptr = specpdl;
203 max_specpdl_size = 600;
204 max_lisp_eval_depth = 300;
205
206 Vrun_hooks = Qnil;
207 }
208
209 void
210 init_eval ()
211 {
212 specpdl_ptr = specpdl;
213 catchlist = 0;
214 handlerlist = 0;
215 backtrace_list = 0;
216 Vquit_flag = Qnil;
217 debug_on_next_call = 0;
218 lisp_eval_depth = 0;
219 #ifdef DEBUG_GCPRO
220 gcpro_level = 0;
221 #endif
222 /* This is less than the initial value of num_nonmacro_input_events. */
223 when_entered_debugger = -1;
224 }
225
226 Lisp_Object
227 call_debugger (arg)
228 Lisp_Object arg;
229 {
230 int debug_while_redisplaying;
231 int count = specpdl_ptr - specpdl;
232 Lisp_Object val;
233
234 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
235 max_lisp_eval_depth = lisp_eval_depth + 20;
236
237 if (specpdl_size + 40 > max_specpdl_size)
238 max_specpdl_size = specpdl_size + 40;
239
240 #ifdef HAVE_X_WINDOWS
241 if (display_hourglass_p)
242 cancel_hourglass ();
243 #endif
244
245 debug_on_next_call = 0;
246 when_entered_debugger = num_nonmacro_input_events;
247
248 /* Resetting redisplaying_p to 0 makes sure that debug output is
249 displayed if the debugger is invoked during redisplay. */
250 debug_while_redisplaying = redisplaying_p;
251 redisplaying_p = 0;
252 specbind (intern ("debugger-may-continue"),
253 debug_while_redisplaying ? Qnil : Qt);
254 specbind (Qinhibit_redisplay, Qnil);
255
256 #if 0 /* Binding this prevents execution of Lisp code during
257 redisplay, which necessarily leads to display problems. */
258 specbind (Qinhibit_eval_during_redisplay, Qt);
259 #endif
260
261 val = apply1 (Vdebugger, arg);
262
263 /* Interrupting redisplay and resuming it later is not safe under
264 all circumstances. So, when the debugger returns, abort the
265 interrupted redisplay by going back to the top-level. */
266 if (debug_while_redisplaying)
267 Ftop_level ();
268
269 return unbind_to (count, val);
270 }
271
272 void
273 do_debug_on_call (code)
274 Lisp_Object code;
275 {
276 debug_on_next_call = 0;
277 backtrace_list->debug_on_exit = 1;
278 call_debugger (Fcons (code, Qnil));
279 }
280 \f
281 /* NOTE!!! Every function that can call EVAL must protect its args
282 and temporaries from garbage collection while it needs them.
283 The definition of `For' shows what you have to do. */
284
285 DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
286 doc: /* Eval args until one of them yields non-nil, then return that value.
287 The remaining args are not evalled at all.
288 If all args return nil, return nil.
289 usage: (or CONDITIONS ...) */)
290 (args)
291 Lisp_Object args;
292 {
293 register Lisp_Object val;
294 Lisp_Object args_left;
295 struct gcpro gcpro1;
296
297 if (NILP(args))
298 return Qnil;
299
300 args_left = args;
301 GCPRO1 (args_left);
302
303 do
304 {
305 val = Feval (Fcar (args_left));
306 if (!NILP (val))
307 break;
308 args_left = Fcdr (args_left);
309 }
310 while (!NILP(args_left));
311
312 UNGCPRO;
313 return val;
314 }
315
316 DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
317 doc: /* Eval args until one of them yields nil, then return nil.
318 The remaining args are not evalled at all.
319 If no arg yields nil, return the last arg's value.
320 usage: (and CONDITIONS ...) */)
321 (args)
322 Lisp_Object args;
323 {
324 register Lisp_Object val;
325 Lisp_Object args_left;
326 struct gcpro gcpro1;
327
328 if (NILP(args))
329 return Qt;
330
331 args_left = args;
332 GCPRO1 (args_left);
333
334 do
335 {
336 val = Feval (Fcar (args_left));
337 if (NILP (val))
338 break;
339 args_left = Fcdr (args_left);
340 }
341 while (!NILP(args_left));
342
343 UNGCPRO;
344 return val;
345 }
346
347 DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
348 doc: /* If COND yields non-nil, do THEN, else do ELSE...
349 Returns the value of THEN or the value of the last of the ELSE's.
350 THEN must be one expression, but ELSE... can be zero or more expressions.
351 If COND yields nil, and there are no ELSE's, the value is nil.
352 usage: (if COND THEN ELSE...) */)
353 (args)
354 Lisp_Object args;
355 {
356 register Lisp_Object cond;
357 struct gcpro gcpro1;
358
359 GCPRO1 (args);
360 cond = Feval (Fcar (args));
361 UNGCPRO;
362
363 if (!NILP (cond))
364 return Feval (Fcar (Fcdr (args)));
365 return Fprogn (Fcdr (Fcdr (args)));
366 }
367
368 DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
369 doc: /* Try each clause until one succeeds.
370 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
371 and, if the value is non-nil, this clause succeeds:
372 then the expressions in BODY are evaluated and the last one's
373 value is the value of the cond-form.
374 If no clause succeeds, cond returns nil.
375 If a clause has one element, as in (CONDITION),
376 CONDITION's value if non-nil is returned from the cond-form.
377 usage: (cond CLAUSES...) */)
378 (args)
379 Lisp_Object args;
380 {
381 register Lisp_Object clause, val;
382 struct gcpro gcpro1;
383
384 val = Qnil;
385 GCPRO1 (args);
386 while (!NILP (args))
387 {
388 clause = Fcar (args);
389 val = Feval (Fcar (clause));
390 if (!NILP (val))
391 {
392 if (!EQ (XCDR (clause), Qnil))
393 val = Fprogn (XCDR (clause));
394 break;
395 }
396 args = XCDR (args);
397 }
398 UNGCPRO;
399
400 return val;
401 }
402
403 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
404 doc: /* Eval BODY forms sequentially and return value of last one.
405 usage: (progn BODY ...) */)
406 (args)
407 Lisp_Object args;
408 {
409 register Lisp_Object val, tem;
410 Lisp_Object args_left;
411 struct gcpro gcpro1;
412
413 /* In Mocklisp code, symbols at the front of the progn arglist
414 are to be bound to zero. */
415 if (!EQ (Vmocklisp_arguments, Qt))
416 {
417 val = make_number (0);
418 while (!NILP (args) && (tem = Fcar (args), SYMBOLP (tem)))
419 {
420 QUIT;
421 specbind (tem, val), args = Fcdr (args);
422 }
423 }
424
425 if (NILP(args))
426 return Qnil;
427
428 args_left = args;
429 GCPRO1 (args_left);
430
431 do
432 {
433 val = Feval (Fcar (args_left));
434 args_left = Fcdr (args_left);
435 }
436 while (!NILP(args_left));
437
438 UNGCPRO;
439 return val;
440 }
441
442 DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
443 doc: /* Eval FIRST and BODY sequentially; value from FIRST.
444 The value of FIRST is saved during the evaluation of the remaining args,
445 whose values are discarded.
446 usage: (prog1 FIRST BODY...) */)
447 (args)
448 Lisp_Object args;
449 {
450 Lisp_Object val;
451 register Lisp_Object args_left;
452 struct gcpro gcpro1, gcpro2;
453 register int argnum = 0;
454
455 if (NILP(args))
456 return Qnil;
457
458 args_left = args;
459 val = Qnil;
460 GCPRO2 (args, val);
461
462 do
463 {
464 if (!(argnum++))
465 val = Feval (Fcar (args_left));
466 else
467 Feval (Fcar (args_left));
468 args_left = Fcdr (args_left);
469 }
470 while (!NILP(args_left));
471
472 UNGCPRO;
473 return val;
474 }
475
476 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
477 doc: /* Eval X, Y and BODY sequentially; value from Y.
478 The value of Y is saved during the evaluation of the remaining args,
479 whose values are discarded.
480 usage: (prog2 X Y BODY...) */)
481 (args)
482 Lisp_Object args;
483 {
484 Lisp_Object val;
485 register Lisp_Object args_left;
486 struct gcpro gcpro1, gcpro2;
487 register int argnum = -1;
488
489 val = Qnil;
490
491 if (NILP (args))
492 return Qnil;
493
494 args_left = args;
495 val = Qnil;
496 GCPRO2 (args, val);
497
498 do
499 {
500 if (!(argnum++))
501 val = Feval (Fcar (args_left));
502 else
503 Feval (Fcar (args_left));
504 args_left = Fcdr (args_left);
505 }
506 while (!NILP (args_left));
507
508 UNGCPRO;
509 return val;
510 }
511
512 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
513 doc: /* Set each SYM to the value of its VAL.
514 The symbols SYM are variables; they are literal (not evaluated).
515 The values VAL are expressions; they are evaluated.
516 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
517 The second VAL is not computed until after the first SYM is set, and so on;
518 each VAL can use the new value of variables set earlier in the `setq'.
519 The return value of the `setq' form is the value of the last VAL.
520 usage: (setq SYM VAL SYM VAL ...) */)
521 (args)
522 Lisp_Object args;
523 {
524 register Lisp_Object args_left;
525 register Lisp_Object val, sym;
526 struct gcpro gcpro1;
527
528 if (NILP(args))
529 return Qnil;
530
531 args_left = args;
532 GCPRO1 (args);
533
534 do
535 {
536 val = Feval (Fcar (Fcdr (args_left)));
537 sym = Fcar (args_left);
538 Fset (sym, val);
539 args_left = Fcdr (Fcdr (args_left));
540 }
541 while (!NILP(args_left));
542
543 UNGCPRO;
544 return val;
545 }
546
547 DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
548 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
549 usage: (quote ARG) */)
550 (args)
551 Lisp_Object args;
552 {
553 return Fcar (args);
554 }
555
556 DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
557 doc: /* Like `quote', but preferred for objects which are functions.
558 In byte compilation, `function' causes its argument to be compiled.
559 `quote' cannot do that.
560 usage: (function ARG) */)
561 (args)
562 Lisp_Object args;
563 {
564 return Fcar (args);
565 }
566
567
568 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
569 doc: /* Return t if function in which this appears was called interactively.
570 This means that the function was called with call-interactively (which
571 includes being called as the binding of a key)
572 and input is currently coming from the keyboard (not in keyboard macro). */)
573 ()
574 {
575 return interactive_p (1) ? Qt : Qnil;
576 }
577
578
579 /* Return 1 if function in which this appears was called
580 interactively. This means that the function was called with
581 call-interactively (which includes being called as the binding of
582 a key) and input is currently coming from the keyboard (not in
583 keyboard macro).
584
585 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
586 called is a built-in. */
587
588 int
589 interactive_p (exclude_subrs_p)
590 int exclude_subrs_p;
591 {
592 struct backtrace *btp;
593 Lisp_Object fun;
594
595 if (!INTERACTIVE)
596 return 0;
597
598 btp = backtrace_list;
599
600 /* If this isn't a byte-compiled function, there may be a frame at
601 the top for Finteractive_p. If so, skip it. */
602 fun = Findirect_function (*btp->function);
603 if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p)
604 btp = btp->next;
605
606 /* If we're running an Emacs 18-style byte-compiled function, there
607 may be a frame for Fbytecode. Now, given the strictest
608 definition, this function isn't really being called
609 interactively, but because that's the way Emacs 18 always builds
610 byte-compiled functions, we'll accept it for now. */
611 if (EQ (*btp->function, Qbytecode))
612 btp = btp->next;
613
614 /* If this isn't a byte-compiled function, then we may now be
615 looking at several frames for special forms. Skip past them. */
616 while (btp &&
617 btp->nargs == UNEVALLED)
618 btp = btp->next;
619
620 /* btp now points at the frame of the innermost function that isn't
621 a special form, ignoring frames for Finteractive_p and/or
622 Fbytecode at the top. If this frame is for a built-in function
623 (such as load or eval-region) return nil. */
624 fun = Findirect_function (*btp->function);
625 if (exclude_subrs_p && SUBRP (fun))
626 return 0;
627
628 /* btp points to the frame of a Lisp function that called interactive-p.
629 Return t if that function was called interactively. */
630 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
631 return 1;
632 return 0;
633 }
634
635
636 DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
637 doc: /* Define NAME as a function.
638 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
639 See also the function `interactive'.
640 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
641 (args)
642 Lisp_Object args;
643 {
644 register Lisp_Object fn_name;
645 register Lisp_Object defn;
646
647 fn_name = Fcar (args);
648 defn = Fcons (Qlambda, Fcdr (args));
649 if (!NILP (Vpurify_flag))
650 defn = Fpurecopy (defn);
651 Ffset (fn_name, defn);
652 LOADHIST_ATTACH (fn_name);
653 return fn_name;
654 }
655
656 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
657 doc: /* Define NAME as a macro.
658 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).
659 When the macro is called, as in (NAME ARGS...),
660 the function (lambda ARGLIST BODY...) is applied to
661 the list ARGS... as it appears in the expression,
662 and the result should be a form to be evaluated instead of the original.
663 usage: (defmacro NAME ARGLIST [DOCSTRING] BODY...) */)
664 (args)
665 Lisp_Object args;
666 {
667 register Lisp_Object fn_name;
668 register Lisp_Object defn;
669
670 fn_name = Fcar (args);
671 defn = Fcons (Qmacro, Fcons (Qlambda, Fcdr (args)));
672 if (!NILP (Vpurify_flag))
673 defn = Fpurecopy (defn);
674 Ffset (fn_name, defn);
675 LOADHIST_ATTACH (fn_name);
676 return fn_name;
677 }
678
679
680 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 2, 0,
681 doc: /* Make SYMBOL a variable alias for symbol ALIASED.
682 Setting the value of SYMBOL will subsequently set the value of ALIASED,
683 and getting the value of SYMBOL will return the value ALIASED has.
684 ALIASED nil means remove the alias; SYMBOL is unbound after that. */)
685 (symbol, aliased)
686 Lisp_Object symbol, aliased;
687 {
688 struct Lisp_Symbol *sym;
689
690 CHECK_SYMBOL (symbol);
691 CHECK_SYMBOL (aliased);
692
693 if (SYMBOL_CONSTANT_P (symbol))
694 error ("Cannot make a constant an alias");
695
696 sym = XSYMBOL (symbol);
697 sym->indirect_variable = 1;
698 sym->value = aliased;
699 sym->constant = SYMBOL_CONSTANT_P (aliased);
700 LOADHIST_ATTACH (symbol);
701
702 return aliased;
703 }
704
705
706 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
707 doc: /* Define SYMBOL as a variable.
708 You are not required to define a variable in order to use it,
709 but the definition can supply documentation and an initial value
710 in a way that tags can recognize.
711
712 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
713 If SYMBOL is buffer-local, its default value is what is set;
714 buffer-local values are not affected.
715 INITVALUE and DOCSTRING are optional.
716 If DOCSTRING starts with *, this variable is identified as a user option.
717 This means that M-x set-variable recognizes it.
718 See also `user-variable-p'.
719 If INITVALUE is missing, SYMBOL's value is not set.
720 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
721 (args)
722 Lisp_Object args;
723 {
724 register Lisp_Object sym, tem, tail;
725
726 sym = Fcar (args);
727 tail = Fcdr (args);
728 if (!NILP (Fcdr (Fcdr (tail))))
729 error ("too many arguments");
730
731 tem = Fdefault_boundp (sym);
732 if (!NILP (tail))
733 {
734 if (NILP (tem))
735 Fset_default (sym, Feval (Fcar (tail)));
736 tail = Fcdr (tail);
737 if (!NILP (Fcar (tail)))
738 {
739 tem = Fcar (tail);
740 if (!NILP (Vpurify_flag))
741 tem = Fpurecopy (tem);
742 Fput (sym, Qvariable_documentation, tem);
743 }
744 LOADHIST_ATTACH (sym);
745 }
746 else
747 /* A (defvar <var>) should not take precedence in the load-history over
748 an earlier (defvar <var> <val>), so only add to history if the default
749 value is still unbound. */
750 if (NILP (tem))
751 LOADHIST_ATTACH (sym);
752
753 return sym;
754 }
755
756 DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
757 doc: /* Define SYMBOL as a constant variable.
758 The intent is that neither programs nor users should ever change this value.
759 Always sets the value of SYMBOL to the result of evalling INITVALUE.
760 If SYMBOL is buffer-local, its default value is what is set;
761 buffer-local values are not affected.
762 DOCSTRING is optional.
763 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
764 (args)
765 Lisp_Object args;
766 {
767 register Lisp_Object sym, tem;
768
769 sym = Fcar (args);
770 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
771 error ("too many arguments");
772
773 tem = Feval (Fcar (Fcdr (args)));
774 if (!NILP (Vpurify_flag))
775 tem = Fpurecopy (tem);
776 Fset_default (sym, tem);
777 tem = Fcar (Fcdr (Fcdr (args)));
778 if (!NILP (tem))
779 {
780 if (!NILP (Vpurify_flag))
781 tem = Fpurecopy (tem);
782 Fput (sym, Qvariable_documentation, tem);
783 }
784 LOADHIST_ATTACH (sym);
785 return sym;
786 }
787
788 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
789 doc: /* Returns t if VARIABLE is intended to be set and modified by users.
790 \(The alternative is a variable used internally in a Lisp program.)
791 Determined by whether the first character of the documentation
792 for the variable is `*' or if the variable is customizable (has a non-nil
793 value of any of `custom-type', `custom-loads' or `standard-value'
794 on its property list). */)
795 (variable)
796 Lisp_Object variable;
797 {
798 Lisp_Object documentation;
799
800 if (!SYMBOLP (variable))
801 return Qnil;
802
803 documentation = Fget (variable, Qvariable_documentation);
804 if (INTEGERP (documentation) && XINT (documentation) < 0)
805 return Qt;
806 if (STRINGP (documentation)
807 && ((unsigned char) XSTRING (documentation)->data[0] == '*'))
808 return Qt;
809 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
810 if (CONSP (documentation)
811 && STRINGP (XCAR (documentation))
812 && INTEGERP (XCDR (documentation))
813 && XINT (XCDR (documentation)) < 0)
814 return Qt;
815 /* Customizable? */
816 if ((!NILP (Fget (variable, intern ("custom-type"))))
817 || (!NILP (Fget (variable, intern ("custom-loads"))))
818 || (!NILP (Fget (variable, intern ("standard-value")))))
819 return Qt;
820 return Qnil;
821 }
822 \f
823 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
824 doc: /* Bind variables according to VARLIST then eval BODY.
825 The value of the last form in BODY is returned.
826 Each element of VARLIST is a symbol (which is bound to nil)
827 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
828 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
829 usage: (let* VARLIST BODY...) */)
830 (args)
831 Lisp_Object args;
832 {
833 Lisp_Object varlist, val, elt;
834 int count = specpdl_ptr - specpdl;
835 struct gcpro gcpro1, gcpro2, gcpro3;
836
837 GCPRO3 (args, elt, varlist);
838
839 varlist = Fcar (args);
840 while (!NILP (varlist))
841 {
842 QUIT;
843 elt = Fcar (varlist);
844 if (SYMBOLP (elt))
845 specbind (elt, Qnil);
846 else if (! NILP (Fcdr (Fcdr (elt))))
847 Fsignal (Qerror,
848 Fcons (build_string ("`let' bindings can have only one value-form"),
849 elt));
850 else
851 {
852 val = Feval (Fcar (Fcdr (elt)));
853 specbind (Fcar (elt), val);
854 }
855 varlist = Fcdr (varlist);
856 }
857 UNGCPRO;
858 val = Fprogn (Fcdr (args));
859 return unbind_to (count, val);
860 }
861
862 DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
863 doc: /* Bind variables according to VARLIST then eval BODY.
864 The value of the last form in BODY is returned.
865 Each element of VARLIST is a symbol (which is bound to nil)
866 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
867 All the VALUEFORMs are evalled before any symbols are bound.
868 usage: (let VARLIST BODY...) */)
869 (args)
870 Lisp_Object args;
871 {
872 Lisp_Object *temps, tem;
873 register Lisp_Object elt, varlist;
874 int count = specpdl_ptr - specpdl;
875 register int argnum;
876 struct gcpro gcpro1, gcpro2;
877
878 varlist = Fcar (args);
879
880 /* Make space to hold the values to give the bound variables */
881 elt = Flength (varlist);
882 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object));
883
884 /* Compute the values and store them in `temps' */
885
886 GCPRO2 (args, *temps);
887 gcpro2.nvars = 0;
888
889 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
890 {
891 QUIT;
892 elt = Fcar (varlist);
893 if (SYMBOLP (elt))
894 temps [argnum++] = Qnil;
895 else if (! NILP (Fcdr (Fcdr (elt))))
896 Fsignal (Qerror,
897 Fcons (build_string ("`let' bindings can have only one value-form"),
898 elt));
899 else
900 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
901 gcpro2.nvars = argnum;
902 }
903 UNGCPRO;
904
905 varlist = Fcar (args);
906 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
907 {
908 elt = Fcar (varlist);
909 tem = temps[argnum++];
910 if (SYMBOLP (elt))
911 specbind (elt, tem);
912 else
913 specbind (Fcar (elt), tem);
914 }
915
916 elt = Fprogn (Fcdr (args));
917 return unbind_to (count, elt);
918 }
919
920 DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
921 doc: /* If TEST yields non-nil, eval BODY... and repeat.
922 The order of execution is thus TEST, BODY, TEST, BODY and so on
923 until TEST returns nil.
924 usage: (while TEST BODY...) */)
925 (args)
926 Lisp_Object args;
927 {
928 Lisp_Object test, body, tem;
929 struct gcpro gcpro1, gcpro2;
930
931 GCPRO2 (test, body);
932
933 test = Fcar (args);
934 body = Fcdr (args);
935 while (tem = Feval (test),
936 (!EQ (Vmocklisp_arguments, Qt) ? XINT (tem) : !NILP (tem)))
937 {
938 QUIT;
939 Fprogn (body);
940 }
941
942 UNGCPRO;
943 return Qnil;
944 }
945
946 DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
947 doc: /* Return result of expanding macros at top level of FORM.
948 If FORM is not a macro call, it is returned unchanged.
949 Otherwise, the macro is expanded and the expansion is considered
950 in place of FORM. When a non-macro-call results, it is returned.
951
952 The second optional arg ENVIRONMENT specifies an environment of macro
953 definitions to shadow the loaded ones for use in file byte-compilation. */)
954 (form, environment)
955 Lisp_Object form;
956 Lisp_Object environment;
957 {
958 /* With cleanups from Hallvard Furuseth. */
959 register Lisp_Object expander, sym, def, tem;
960
961 while (1)
962 {
963 /* Come back here each time we expand a macro call,
964 in case it expands into another macro call. */
965 if (!CONSP (form))
966 break;
967 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
968 def = sym = XCAR (form);
969 tem = Qnil;
970 /* Trace symbols aliases to other symbols
971 until we get a symbol that is not an alias. */
972 while (SYMBOLP (def))
973 {
974 QUIT;
975 sym = def;
976 tem = Fassq (sym, environment);
977 if (NILP (tem))
978 {
979 def = XSYMBOL (sym)->function;
980 if (!EQ (def, Qunbound))
981 continue;
982 }
983 break;
984 }
985 /* Right now TEM is the result from SYM in ENVIRONMENT,
986 and if TEM is nil then DEF is SYM's function definition. */
987 if (NILP (tem))
988 {
989 /* SYM is not mentioned in ENVIRONMENT.
990 Look at its function definition. */
991 if (EQ (def, Qunbound) || !CONSP (def))
992 /* Not defined or definition not suitable */
993 break;
994 if (EQ (XCAR (def), Qautoload))
995 {
996 /* Autoloading function: will it be a macro when loaded? */
997 tem = Fnth (make_number (4), def);
998 if (EQ (tem, Qt) || EQ (tem, Qmacro))
999 /* Yes, load it and try again. */
1000 {
1001 struct gcpro gcpro1;
1002 GCPRO1 (form);
1003 do_autoload (def, sym);
1004 UNGCPRO;
1005 continue;
1006 }
1007 else
1008 break;
1009 }
1010 else if (!EQ (XCAR (def), Qmacro))
1011 break;
1012 else expander = XCDR (def);
1013 }
1014 else
1015 {
1016 expander = XCDR (tem);
1017 if (NILP (expander))
1018 break;
1019 }
1020 form = apply1 (expander, XCDR (form));
1021 }
1022 return form;
1023 }
1024 \f
1025 DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
1026 doc: /* Eval BODY allowing nonlocal exits using `throw'.
1027 TAG is evalled to get the tag to use; it must not be nil.
1028
1029 Then the BODY is executed.
1030 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1031 If no throw happens, `catch' returns the value of the last BODY form.
1032 If a throw happens, it specifies the value to return from `catch'.
1033 usage: (catch TAG BODY...) */)
1034 (args)
1035 Lisp_Object args;
1036 {
1037 register Lisp_Object tag;
1038 struct gcpro gcpro1;
1039
1040 GCPRO1 (args);
1041 tag = Feval (Fcar (args));
1042 UNGCPRO;
1043 return internal_catch (tag, Fprogn, Fcdr (args));
1044 }
1045
1046 /* Set up a catch, then call C function FUNC on argument ARG.
1047 FUNC should return a Lisp_Object.
1048 This is how catches are done from within C code. */
1049
1050 Lisp_Object
1051 internal_catch (tag, func, arg)
1052 Lisp_Object tag;
1053 Lisp_Object (*func) ();
1054 Lisp_Object arg;
1055 {
1056 /* This structure is made part of the chain `catchlist'. */
1057 struct catchtag c;
1058
1059 /* Fill in the components of c, and put it on the list. */
1060 c.next = catchlist;
1061 c.tag = tag;
1062 c.val = Qnil;
1063 c.backlist = backtrace_list;
1064 c.handlerlist = handlerlist;
1065 c.lisp_eval_depth = lisp_eval_depth;
1066 c.pdlcount = specpdl_ptr - specpdl;
1067 c.poll_suppress_count = poll_suppress_count;
1068 c.gcpro = gcprolist;
1069 c.byte_stack = byte_stack_list;
1070 catchlist = &c;
1071
1072 /* Call FUNC. */
1073 if (! _setjmp (c.jmp))
1074 c.val = (*func) (arg);
1075
1076 /* Throw works by a longjmp that comes right here. */
1077 catchlist = c.next;
1078 return c.val;
1079 }
1080
1081 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1082 jump to that CATCH, returning VALUE as the value of that catch.
1083
1084 This is the guts Fthrow and Fsignal; they differ only in the way
1085 they choose the catch tag to throw to. A catch tag for a
1086 condition-case form has a TAG of Qnil.
1087
1088 Before each catch is discarded, unbind all special bindings and
1089 execute all unwind-protect clauses made above that catch. Unwind
1090 the handler stack as we go, so that the proper handlers are in
1091 effect for each unwind-protect clause we run. At the end, restore
1092 some static info saved in CATCH, and longjmp to the location
1093 specified in the
1094
1095 This is used for correct unwinding in Fthrow and Fsignal. */
1096
1097 static void
1098 unwind_to_catch (catch, value)
1099 struct catchtag *catch;
1100 Lisp_Object value;
1101 {
1102 register int last_time;
1103
1104 /* Save the value in the tag. */
1105 catch->val = value;
1106
1107 /* Restore the polling-suppression count. */
1108 set_poll_suppress_count (catch->poll_suppress_count);
1109
1110 do
1111 {
1112 last_time = catchlist == catch;
1113
1114 /* Unwind the specpdl stack, and then restore the proper set of
1115 handlers. */
1116 unbind_to (catchlist->pdlcount, Qnil);
1117 handlerlist = catchlist->handlerlist;
1118 catchlist = catchlist->next;
1119 }
1120 while (! last_time);
1121
1122 byte_stack_list = catch->byte_stack;
1123 gcprolist = catch->gcpro;
1124 #ifdef DEBUG_GCPRO
1125 if (gcprolist != 0)
1126 gcpro_level = gcprolist->level + 1;
1127 else
1128 gcpro_level = 0;
1129 #endif
1130 backtrace_list = catch->backlist;
1131 lisp_eval_depth = catch->lisp_eval_depth;
1132
1133 _longjmp (catch->jmp, 1);
1134 }
1135
1136 DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
1137 doc: /* Throw to the catch for TAG and return VALUE from it.
1138 Both TAG and VALUE are evalled. */)
1139 (tag, value)
1140 register Lisp_Object tag, value;
1141 {
1142 register struct catchtag *c;
1143
1144 while (1)
1145 {
1146 if (!NILP (tag))
1147 for (c = catchlist; c; c = c->next)
1148 {
1149 if (EQ (c->tag, tag))
1150 unwind_to_catch (c, value);
1151 }
1152 tag = Fsignal (Qno_catch, Fcons (tag, Fcons (value, Qnil)));
1153 }
1154 }
1155
1156
1157 DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
1158 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
1159 If BODYFORM completes normally, its value is returned
1160 after executing the UNWINDFORMS.
1161 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1162 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1163 (args)
1164 Lisp_Object args;
1165 {
1166 Lisp_Object val;
1167 int count = specpdl_ptr - specpdl;
1168
1169 record_unwind_protect (0, Fcdr (args));
1170 val = Feval (Fcar (args));
1171 return unbind_to (count, val);
1172 }
1173 \f
1174 /* Chain of condition handlers currently in effect.
1175 The elements of this chain are contained in the stack frames
1176 of Fcondition_case and internal_condition_case.
1177 When an error is signaled (by calling Fsignal, below),
1178 this chain is searched for an element that applies. */
1179
1180 struct handler *handlerlist;
1181
1182 DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
1183 doc: /* Regain control when an error is signaled.
1184 Executes BODYFORM and returns its value if no error happens.
1185 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1186 where the BODY is made of Lisp expressions.
1187
1188 A handler is applicable to an error
1189 if CONDITION-NAME is one of the error's condition names.
1190 If an error happens, the first applicable handler is run.
1191
1192 The car of a handler may be a list of condition names
1193 instead of a single condition name.
1194
1195 When a handler handles an error,
1196 control returns to the condition-case and the handler BODY... is executed
1197 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1198 VAR may be nil; then you do not get access to the signal information.
1199
1200 The value of the last BODY form is returned from the condition-case.
1201 See also the function `signal' for more info.
1202 usage: (condition-case VAR BODYFORM HANDLERS...) */)
1203 (args)
1204 Lisp_Object args;
1205 {
1206 Lisp_Object val;
1207 struct catchtag c;
1208 struct handler h;
1209 register Lisp_Object bodyform, handlers;
1210 volatile Lisp_Object var;
1211
1212 var = Fcar (args);
1213 bodyform = Fcar (Fcdr (args));
1214 handlers = Fcdr (Fcdr (args));
1215 CHECK_SYMBOL (var);
1216
1217 for (val = handlers; ! NILP (val); val = Fcdr (val))
1218 {
1219 Lisp_Object tem;
1220 tem = Fcar (val);
1221 if (! (NILP (tem)
1222 || (CONSP (tem)
1223 && (SYMBOLP (XCAR (tem))
1224 || CONSP (XCAR (tem))))))
1225 error ("Invalid condition handler", tem);
1226 }
1227
1228 c.tag = Qnil;
1229 c.val = Qnil;
1230 c.backlist = backtrace_list;
1231 c.handlerlist = handlerlist;
1232 c.lisp_eval_depth = lisp_eval_depth;
1233 c.pdlcount = specpdl_ptr - specpdl;
1234 c.poll_suppress_count = poll_suppress_count;
1235 c.gcpro = gcprolist;
1236 c.byte_stack = byte_stack_list;
1237 if (_setjmp (c.jmp))
1238 {
1239 if (!NILP (h.var))
1240 specbind (h.var, c.val);
1241 val = Fprogn (Fcdr (h.chosen_clause));
1242
1243 /* Note that this just undoes the binding of h.var; whoever
1244 longjumped to us unwound the stack to c.pdlcount before
1245 throwing. */
1246 unbind_to (c.pdlcount, Qnil);
1247 return val;
1248 }
1249 c.next = catchlist;
1250 catchlist = &c;
1251
1252 h.var = var;
1253 h.handler = handlers;
1254 h.next = handlerlist;
1255 h.tag = &c;
1256 handlerlist = &h;
1257
1258 val = Feval (bodyform);
1259 catchlist = c.next;
1260 handlerlist = h.next;
1261 return val;
1262 }
1263
1264 /* Call the function BFUN with no arguments, catching errors within it
1265 according to HANDLERS. If there is an error, call HFUN with
1266 one argument which is the data that describes the error:
1267 (SIGNALNAME . DATA)
1268
1269 HANDLERS can be a list of conditions to catch.
1270 If HANDLERS is Qt, catch all errors.
1271 If HANDLERS is Qerror, catch all errors
1272 but allow the debugger to run if that is enabled. */
1273
1274 Lisp_Object
1275 internal_condition_case (bfun, handlers, hfun)
1276 Lisp_Object (*bfun) ();
1277 Lisp_Object handlers;
1278 Lisp_Object (*hfun) ();
1279 {
1280 Lisp_Object val;
1281 struct catchtag c;
1282 struct handler h;
1283
1284 #if 0 /* Can't do this check anymore because realize_basic_faces has
1285 to BLOCK_INPUT, and can call Lisp. What's really needed is a
1286 flag indicating that we're currently handling a signal. */
1287 /* Since Fsignal resets this to 0, it had better be 0 now
1288 or else we have a potential bug. */
1289 if (interrupt_input_blocked != 0)
1290 abort ();
1291 #endif
1292
1293 c.tag = Qnil;
1294 c.val = Qnil;
1295 c.backlist = backtrace_list;
1296 c.handlerlist = handlerlist;
1297 c.lisp_eval_depth = lisp_eval_depth;
1298 c.pdlcount = specpdl_ptr - specpdl;
1299 c.poll_suppress_count = poll_suppress_count;
1300 c.gcpro = gcprolist;
1301 c.byte_stack = byte_stack_list;
1302 if (_setjmp (c.jmp))
1303 {
1304 return (*hfun) (c.val);
1305 }
1306 c.next = catchlist;
1307 catchlist = &c;
1308 h.handler = handlers;
1309 h.var = Qnil;
1310 h.next = handlerlist;
1311 h.tag = &c;
1312 handlerlist = &h;
1313
1314 val = (*bfun) ();
1315 catchlist = c.next;
1316 handlerlist = h.next;
1317 return val;
1318 }
1319
1320 /* Like internal_condition_case but call HFUN with ARG as its argument. */
1321
1322 Lisp_Object
1323 internal_condition_case_1 (bfun, arg, handlers, hfun)
1324 Lisp_Object (*bfun) ();
1325 Lisp_Object arg;
1326 Lisp_Object handlers;
1327 Lisp_Object (*hfun) ();
1328 {
1329 Lisp_Object val;
1330 struct catchtag c;
1331 struct handler h;
1332
1333 c.tag = Qnil;
1334 c.val = Qnil;
1335 c.backlist = backtrace_list;
1336 c.handlerlist = handlerlist;
1337 c.lisp_eval_depth = lisp_eval_depth;
1338 c.pdlcount = specpdl_ptr - specpdl;
1339 c.poll_suppress_count = poll_suppress_count;
1340 c.gcpro = gcprolist;
1341 c.byte_stack = byte_stack_list;
1342 if (_setjmp (c.jmp))
1343 {
1344 return (*hfun) (c.val);
1345 }
1346 c.next = catchlist;
1347 catchlist = &c;
1348 h.handler = handlers;
1349 h.var = Qnil;
1350 h.next = handlerlist;
1351 h.tag = &c;
1352 handlerlist = &h;
1353
1354 val = (*bfun) (arg);
1355 catchlist = c.next;
1356 handlerlist = h.next;
1357 return val;
1358 }
1359
1360
1361 /* Like internal_condition_case but call HFUN with NARGS as first,
1362 and ARGS as second argument. */
1363
1364 Lisp_Object
1365 internal_condition_case_2 (bfun, nargs, args, handlers, hfun)
1366 Lisp_Object (*bfun) ();
1367 int nargs;
1368 Lisp_Object *args;
1369 Lisp_Object handlers;
1370 Lisp_Object (*hfun) ();
1371 {
1372 Lisp_Object val;
1373 struct catchtag c;
1374 struct handler h;
1375
1376 c.tag = Qnil;
1377 c.val = Qnil;
1378 c.backlist = backtrace_list;
1379 c.handlerlist = handlerlist;
1380 c.lisp_eval_depth = lisp_eval_depth;
1381 c.pdlcount = specpdl_ptr - specpdl;
1382 c.poll_suppress_count = poll_suppress_count;
1383 c.gcpro = gcprolist;
1384 c.byte_stack = byte_stack_list;
1385 if (_setjmp (c.jmp))
1386 {
1387 return (*hfun) (c.val);
1388 }
1389 c.next = catchlist;
1390 catchlist = &c;
1391 h.handler = handlers;
1392 h.var = Qnil;
1393 h.next = handlerlist;
1394 h.tag = &c;
1395 handlerlist = &h;
1396
1397 val = (*bfun) (nargs, args);
1398 catchlist = c.next;
1399 handlerlist = h.next;
1400 return val;
1401 }
1402
1403 \f
1404 static Lisp_Object find_handler_clause P_ ((Lisp_Object, Lisp_Object,
1405 Lisp_Object, Lisp_Object,
1406 Lisp_Object *));
1407
1408 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
1409 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1410 This function does not return.
1411
1412 An error symbol is a symbol with an `error-conditions' property
1413 that is a list of condition names.
1414 A handler for any of those names will get to handle this signal.
1415 The symbol `error' should normally be one of them.
1416
1417 DATA should be a list. Its elements are printed as part of the error message.
1418 If the signal is handled, DATA is made available to the handler.
1419 See also the function `condition-case'. */)
1420 (error_symbol, data)
1421 Lisp_Object error_symbol, data;
1422 {
1423 /* When memory is full, ERROR-SYMBOL is nil,
1424 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA). */
1425 register struct handler *allhandlers = handlerlist;
1426 Lisp_Object conditions;
1427 extern int gc_in_progress;
1428 extern int waiting_for_input;
1429 Lisp_Object debugger_value;
1430 Lisp_Object string;
1431 Lisp_Object real_error_symbol;
1432 extern int display_hourglass_p;
1433 struct backtrace *bp;
1434
1435 immediate_quit = handling_signal = 0;
1436 if (gc_in_progress || waiting_for_input)
1437 abort ();
1438
1439 TOTALLY_UNBLOCK_INPUT;
1440
1441 if (NILP (error_symbol))
1442 real_error_symbol = Fcar (data);
1443 else
1444 real_error_symbol = error_symbol;
1445
1446 #ifdef HAVE_X_WINDOWS
1447 if (display_hourglass_p)
1448 cancel_hourglass ();
1449 #endif
1450
1451 /* This hook is used by edebug. */
1452 if (! NILP (Vsignal_hook_function))
1453 call2 (Vsignal_hook_function, error_symbol, data);
1454
1455 conditions = Fget (real_error_symbol, Qerror_conditions);
1456
1457 /* Remember from where signal was called. Skip over the frame for
1458 `signal' itself. If a frame for `error' follows, skip that,
1459 too. */
1460 Vsignaling_function = Qnil;
1461 if (backtrace_list)
1462 {
1463 bp = backtrace_list->next;
1464 if (bp && bp->function && EQ (*bp->function, Qerror))
1465 bp = bp->next;
1466 if (bp && bp->function)
1467 Vsignaling_function = *bp->function;
1468 }
1469
1470 for (; handlerlist; handlerlist = handlerlist->next)
1471 {
1472 register Lisp_Object clause;
1473
1474 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
1475 max_lisp_eval_depth = lisp_eval_depth + 20;
1476
1477 if (specpdl_size + 40 > max_specpdl_size)
1478 max_specpdl_size = specpdl_size + 40;
1479
1480 clause = find_handler_clause (handlerlist->handler, conditions,
1481 error_symbol, data, &debugger_value);
1482
1483 #if 0 /* Most callers are not prepared to handle gc if this returns.
1484 So, since this feature is not very useful, take it out. */
1485 /* If have called debugger and user wants to continue,
1486 just return nil. */
1487 if (EQ (clause, Qlambda))
1488 return debugger_value;
1489 #else
1490 if (EQ (clause, Qlambda))
1491 {
1492 /* We can't return values to code which signaled an error, but we
1493 can continue code which has signaled a quit. */
1494 if (EQ (real_error_symbol, Qquit))
1495 return Qnil;
1496 else
1497 error ("Cannot return from the debugger in an error");
1498 }
1499 #endif
1500
1501 if (!NILP (clause))
1502 {
1503 Lisp_Object unwind_data;
1504 struct handler *h = handlerlist;
1505
1506 handlerlist = allhandlers;
1507
1508 if (NILP (error_symbol))
1509 unwind_data = data;
1510 else
1511 unwind_data = Fcons (error_symbol, data);
1512 h->chosen_clause = clause;
1513 unwind_to_catch (h->tag, unwind_data);
1514 }
1515 }
1516
1517 handlerlist = allhandlers;
1518 /* If no handler is present now, try to run the debugger,
1519 and if that fails, throw to top level. */
1520 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value);
1521 if (catchlist != 0)
1522 Fthrow (Qtop_level, Qt);
1523
1524 if (! NILP (error_symbol))
1525 data = Fcons (error_symbol, data);
1526
1527 string = Ferror_message_string (data);
1528 fatal ("%s", XSTRING (string)->data, 0);
1529 }
1530
1531 /* Return nonzero iff LIST is a non-nil atom or
1532 a list containing one of CONDITIONS. */
1533
1534 static int
1535 wants_debugger (list, conditions)
1536 Lisp_Object list, conditions;
1537 {
1538 if (NILP (list))
1539 return 0;
1540 if (! CONSP (list))
1541 return 1;
1542
1543 while (CONSP (conditions))
1544 {
1545 Lisp_Object this, tail;
1546 this = XCAR (conditions);
1547 for (tail = list; CONSP (tail); tail = XCDR (tail))
1548 if (EQ (XCAR (tail), this))
1549 return 1;
1550 conditions = XCDR (conditions);
1551 }
1552 return 0;
1553 }
1554
1555 /* Return 1 if an error with condition-symbols CONDITIONS,
1556 and described by SIGNAL-DATA, should skip the debugger
1557 according to debugger-ignored-errors. */
1558
1559 static int
1560 skip_debugger (conditions, data)
1561 Lisp_Object conditions, data;
1562 {
1563 Lisp_Object tail;
1564 int first_string = 1;
1565 Lisp_Object error_message;
1566
1567 error_message = Qnil;
1568 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
1569 {
1570 if (STRINGP (XCAR (tail)))
1571 {
1572 if (first_string)
1573 {
1574 error_message = Ferror_message_string (data);
1575 first_string = 0;
1576 }
1577
1578 if (fast_string_match (XCAR (tail), error_message) >= 0)
1579 return 1;
1580 }
1581 else
1582 {
1583 Lisp_Object contail;
1584
1585 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
1586 if (EQ (XCAR (tail), XCAR (contail)))
1587 return 1;
1588 }
1589 }
1590
1591 return 0;
1592 }
1593
1594 /* Value of Qlambda means we have called debugger and user has continued.
1595 There are two ways to pass SIG and DATA:
1596 = SIG is the error symbol, and DATA is the rest of the data.
1597 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1598 This is for memory-full errors only.
1599
1600 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
1601
1602 static Lisp_Object
1603 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr)
1604 Lisp_Object handlers, conditions, sig, data;
1605 Lisp_Object *debugger_value_ptr;
1606 {
1607 register Lisp_Object h;
1608 register Lisp_Object tem;
1609
1610 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */
1611 return Qt;
1612 /* error is used similarly, but means print an error message
1613 and run the debugger if that is enabled. */
1614 if (EQ (handlers, Qerror)
1615 || !NILP (Vdebug_on_signal)) /* This says call debugger even if
1616 there is a handler. */
1617 {
1618 int count = specpdl_ptr - specpdl;
1619 int debugger_called = 0;
1620 Lisp_Object sig_symbol, combined_data;
1621 /* This is set to 1 if we are handling a memory-full error,
1622 because these must not run the debugger.
1623 (There is no room in memory to do that!) */
1624 int no_debugger = 0;
1625
1626 if (NILP (sig))
1627 {
1628 combined_data = data;
1629 sig_symbol = Fcar (data);
1630 no_debugger = 1;
1631 }
1632 else
1633 {
1634 combined_data = Fcons (sig, data);
1635 sig_symbol = sig;
1636 }
1637
1638 if (wants_debugger (Vstack_trace_on_error, conditions))
1639 {
1640 #ifdef PROTOTYPES
1641 internal_with_output_to_temp_buffer ("*Backtrace*",
1642 (Lisp_Object (*) (Lisp_Object)) Fbacktrace,
1643 Qnil);
1644 #else
1645 internal_with_output_to_temp_buffer ("*Backtrace*",
1646 Fbacktrace, Qnil);
1647 #endif
1648 }
1649 if (! no_debugger
1650 && (EQ (sig_symbol, Qquit)
1651 ? debug_on_quit
1652 : wants_debugger (Vdebug_on_error, conditions))
1653 && ! skip_debugger (conditions, combined_data)
1654 && when_entered_debugger < num_nonmacro_input_events)
1655 {
1656 specbind (Qdebug_on_error, Qnil);
1657 *debugger_value_ptr
1658 = call_debugger (Fcons (Qerror,
1659 Fcons (combined_data, Qnil)));
1660 debugger_called = 1;
1661 }
1662 /* If there is no handler, return saying whether we ran the debugger. */
1663 if (EQ (handlers, Qerror))
1664 {
1665 if (debugger_called)
1666 return unbind_to (count, Qlambda);
1667 return Qt;
1668 }
1669 }
1670 for (h = handlers; CONSP (h); h = Fcdr (h))
1671 {
1672 Lisp_Object handler, condit;
1673
1674 handler = Fcar (h);
1675 if (!CONSP (handler))
1676 continue;
1677 condit = Fcar (handler);
1678 /* Handle a single condition name in handler HANDLER. */
1679 if (SYMBOLP (condit))
1680 {
1681 tem = Fmemq (Fcar (handler), conditions);
1682 if (!NILP (tem))
1683 return handler;
1684 }
1685 /* Handle a list of condition names in handler HANDLER. */
1686 else if (CONSP (condit))
1687 {
1688 while (CONSP (condit))
1689 {
1690 tem = Fmemq (Fcar (condit), conditions);
1691 if (!NILP (tem))
1692 return handler;
1693 condit = XCDR (condit);
1694 }
1695 }
1696 }
1697 return Qnil;
1698 }
1699
1700 /* dump an error message; called like printf */
1701
1702 /* VARARGS 1 */
1703 void
1704 error (m, a1, a2, a3)
1705 char *m;
1706 char *a1, *a2, *a3;
1707 {
1708 char buf[200];
1709 int size = 200;
1710 int mlen;
1711 char *buffer = buf;
1712 char *args[3];
1713 int allocated = 0;
1714 Lisp_Object string;
1715
1716 args[0] = a1;
1717 args[1] = a2;
1718 args[2] = a3;
1719
1720 mlen = strlen (m);
1721
1722 while (1)
1723 {
1724 int used = doprnt (buffer, size, m, m + mlen, 3, args);
1725 if (used < size)
1726 break;
1727 size *= 2;
1728 if (allocated)
1729 buffer = (char *) xrealloc (buffer, size);
1730 else
1731 {
1732 buffer = (char *) xmalloc (size);
1733 allocated = 1;
1734 }
1735 }
1736
1737 string = build_string (buffer);
1738 if (allocated)
1739 xfree (buffer);
1740
1741 Fsignal (Qerror, Fcons (string, Qnil));
1742 abort ();
1743 }
1744 \f
1745 DEFUN ("commandp", Fcommandp, Scommandp, 1, 1, 0,
1746 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
1747 This means it contains a description for how to read arguments to give it.
1748 The value is nil for an invalid function or a symbol with no function
1749 definition.
1750
1751 Interactively callable functions include strings and vectors (treated
1752 as keyboard macros), lambda-expressions that contain a top-level call
1753 to `interactive', autoload definitions made by `autoload' with non-nil
1754 fourth argument, and some of the built-in functions of Lisp.
1755
1756 Also, a symbol satisfies `commandp' if its function definition does so. */)
1757 (function)
1758 Lisp_Object function;
1759 {
1760 register Lisp_Object fun;
1761 register Lisp_Object funcar;
1762
1763 fun = function;
1764
1765 fun = indirect_function (fun);
1766 if (EQ (fun, Qunbound))
1767 return Qnil;
1768
1769 /* Emacs primitives are interactive if their DEFUN specifies an
1770 interactive spec. */
1771 if (SUBRP (fun))
1772 {
1773 if (XSUBR (fun)->prompt)
1774 return Qt;
1775 else
1776 return Qnil;
1777 }
1778
1779 /* Bytecode objects are interactive if they are long enough to
1780 have an element whose index is COMPILED_INTERACTIVE, which is
1781 where the interactive spec is stored. */
1782 else if (COMPILEDP (fun))
1783 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
1784 ? Qt : Qnil);
1785
1786 /* Strings and vectors are keyboard macros. */
1787 if (STRINGP (fun) || VECTORP (fun))
1788 return Qt;
1789
1790 /* Lists may represent commands. */
1791 if (!CONSP (fun))
1792 return Qnil;
1793 funcar = Fcar (fun);
1794 if (!SYMBOLP (funcar))
1795 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1796 if (EQ (funcar, Qlambda))
1797 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
1798 if (EQ (funcar, Qmocklisp))
1799 return Qt; /* All mocklisp functions can be called interactively */
1800 if (EQ (funcar, Qautoload))
1801 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
1802 else
1803 return Qnil;
1804 }
1805
1806 /* ARGSUSED */
1807 DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
1808 doc: /* Define FUNCTION to autoload from FILE.
1809 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1810 Third arg DOCSTRING is documentation for the function.
1811 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1812 Fifth arg TYPE indicates the type of the object:
1813 nil or omitted says FUNCTION is a function,
1814 `keymap' says FUNCTION is really a keymap, and
1815 `macro' or t says FUNCTION is really a macro.
1816 Third through fifth args give info about the real definition.
1817 They default to nil.
1818 If FUNCTION is already defined other than as an autoload,
1819 this does nothing and returns nil. */)
1820 (function, file, docstring, interactive, type)
1821 Lisp_Object function, file, docstring, interactive, type;
1822 {
1823 #ifdef NO_ARG_ARRAY
1824 Lisp_Object args[4];
1825 #endif
1826
1827 CHECK_SYMBOL (function);
1828 CHECK_STRING (file);
1829
1830 /* If function is defined and not as an autoload, don't override */
1831 if (!EQ (XSYMBOL (function)->function, Qunbound)
1832 && !(CONSP (XSYMBOL (function)->function)
1833 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
1834 return Qnil;
1835
1836 if (NILP (Vpurify_flag))
1837 /* Only add entries after dumping, because the ones before are
1838 not useful and else we get loads of them from the loaddefs.el. */
1839 LOADHIST_ATTACH (Fcons (Qautoload, function));
1840
1841 #ifdef NO_ARG_ARRAY
1842 args[0] = file;
1843 args[1] = docstring;
1844 args[2] = interactive;
1845 args[3] = type;
1846
1847 return Ffset (function, Fcons (Qautoload, Flist (4, &args[0])));
1848 #else /* NO_ARG_ARRAY */
1849 return Ffset (function, Fcons (Qautoload, Flist (4, &file)));
1850 #endif /* not NO_ARG_ARRAY */
1851 }
1852
1853 Lisp_Object
1854 un_autoload (oldqueue)
1855 Lisp_Object oldqueue;
1856 {
1857 register Lisp_Object queue, first, second;
1858
1859 /* Queue to unwind is current value of Vautoload_queue.
1860 oldqueue is the shadowed value to leave in Vautoload_queue. */
1861 queue = Vautoload_queue;
1862 Vautoload_queue = oldqueue;
1863 while (CONSP (queue))
1864 {
1865 first = Fcar (queue);
1866 second = Fcdr (first);
1867 first = Fcar (first);
1868 if (EQ (second, Qnil))
1869 Vfeatures = first;
1870 else
1871 Ffset (first, second);
1872 queue = Fcdr (queue);
1873 }
1874 return Qnil;
1875 }
1876
1877 /* Load an autoloaded function.
1878 FUNNAME is the symbol which is the function's name.
1879 FUNDEF is the autoload definition (a list). */
1880
1881 void
1882 do_autoload (fundef, funname)
1883 Lisp_Object fundef, funname;
1884 {
1885 int count = specpdl_ptr - specpdl;
1886 Lisp_Object fun, queue, first, second;
1887 struct gcpro gcpro1, gcpro2, gcpro3;
1888
1889 fun = funname;
1890 CHECK_SYMBOL (funname);
1891 GCPRO3 (fun, funname, fundef);
1892
1893 /* Preserve the match data. */
1894 record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil));
1895
1896 /* Value saved here is to be restored into Vautoload_queue. */
1897 record_unwind_protect (un_autoload, Vautoload_queue);
1898 Vautoload_queue = Qt;
1899 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil, Qt);
1900
1901 /* Save the old autoloads, in case we ever do an unload. */
1902 queue = Vautoload_queue;
1903 while (CONSP (queue))
1904 {
1905 first = Fcar (queue);
1906 second = Fcdr (first);
1907 first = Fcar (first);
1908
1909 /* Note: This test is subtle. The cdr of an autoload-queue entry
1910 may be an atom if the autoload entry was generated by a defalias
1911 or fset. */
1912 if (CONSP (second))
1913 Fput (first, Qautoload, (Fcdr (second)));
1914
1915 queue = Fcdr (queue);
1916 }
1917
1918 /* Once loading finishes, don't undo it. */
1919 Vautoload_queue = Qt;
1920 unbind_to (count, Qnil);
1921
1922 fun = Findirect_function (fun);
1923
1924 if (!NILP (Fequal (fun, fundef)))
1925 error ("Autoloading failed to define function %s",
1926 XSYMBOL (funname)->name->data);
1927 UNGCPRO;
1928 }
1929
1930 \f
1931 DEFUN ("eval", Feval, Seval, 1, 1, 0,
1932 doc: /* Evaluate FORM and return its value. */)
1933 (form)
1934 Lisp_Object form;
1935 {
1936 Lisp_Object fun, val, original_fun, original_args;
1937 Lisp_Object funcar;
1938 struct backtrace backtrace;
1939 struct gcpro gcpro1, gcpro2, gcpro3;
1940
1941 if (handling_signal)
1942 abort ();
1943
1944 if (SYMBOLP (form))
1945 {
1946 if (EQ (Vmocklisp_arguments, Qt))
1947 return Fsymbol_value (form);
1948 val = Fsymbol_value (form);
1949 if (NILP (val))
1950 XSETFASTINT (val, 0);
1951 else if (EQ (val, Qt))
1952 XSETFASTINT (val, 1);
1953 return val;
1954 }
1955 if (!CONSP (form))
1956 return form;
1957
1958 QUIT;
1959 if (consing_since_gc > gc_cons_threshold)
1960 {
1961 GCPRO1 (form);
1962 Fgarbage_collect ();
1963 UNGCPRO;
1964 }
1965
1966 if (++lisp_eval_depth > max_lisp_eval_depth)
1967 {
1968 if (max_lisp_eval_depth < 100)
1969 max_lisp_eval_depth = 100;
1970 if (lisp_eval_depth > max_lisp_eval_depth)
1971 error ("Lisp nesting exceeds max-lisp-eval-depth");
1972 }
1973
1974 original_fun = Fcar (form);
1975 original_args = Fcdr (form);
1976
1977 backtrace.next = backtrace_list;
1978 backtrace_list = &backtrace;
1979 backtrace.function = &original_fun; /* This also protects them from gc */
1980 backtrace.args = &original_args;
1981 backtrace.nargs = UNEVALLED;
1982 backtrace.evalargs = 1;
1983 backtrace.debug_on_exit = 0;
1984
1985 if (debug_on_next_call)
1986 do_debug_on_call (Qt);
1987
1988 /* At this point, only original_fun and original_args
1989 have values that will be used below */
1990 retry:
1991 fun = Findirect_function (original_fun);
1992
1993 if (SUBRP (fun))
1994 {
1995 Lisp_Object numargs;
1996 Lisp_Object argvals[8];
1997 Lisp_Object args_left;
1998 register int i, maxargs;
1999
2000 args_left = original_args;
2001 numargs = Flength (args_left);
2002
2003 if (XINT (numargs) < XSUBR (fun)->min_args ||
2004 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
2005 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
2006
2007 if (XSUBR (fun)->max_args == UNEVALLED)
2008 {
2009 backtrace.evalargs = 0;
2010 val = (*XSUBR (fun)->function) (args_left);
2011 goto done;
2012 }
2013
2014 if (XSUBR (fun)->max_args == MANY)
2015 {
2016 /* Pass a vector of evaluated arguments */
2017 Lisp_Object *vals;
2018 register int argnum = 0;
2019
2020 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2021
2022 GCPRO3 (args_left, fun, fun);
2023 gcpro3.var = vals;
2024 gcpro3.nvars = 0;
2025
2026 while (!NILP (args_left))
2027 {
2028 vals[argnum++] = Feval (Fcar (args_left));
2029 args_left = Fcdr (args_left);
2030 gcpro3.nvars = argnum;
2031 }
2032
2033 backtrace.args = vals;
2034 backtrace.nargs = XINT (numargs);
2035
2036 val = (*XSUBR (fun)->function) (XINT (numargs), vals);
2037 UNGCPRO;
2038 goto done;
2039 }
2040
2041 GCPRO3 (args_left, fun, fun);
2042 gcpro3.var = argvals;
2043 gcpro3.nvars = 0;
2044
2045 maxargs = XSUBR (fun)->max_args;
2046 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
2047 {
2048 argvals[i] = Feval (Fcar (args_left));
2049 gcpro3.nvars = ++i;
2050 }
2051
2052 UNGCPRO;
2053
2054 backtrace.args = argvals;
2055 backtrace.nargs = XINT (numargs);
2056
2057 switch (i)
2058 {
2059 case 0:
2060 val = (*XSUBR (fun)->function) ();
2061 goto done;
2062 case 1:
2063 val = (*XSUBR (fun)->function) (argvals[0]);
2064 goto done;
2065 case 2:
2066 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]);
2067 goto done;
2068 case 3:
2069 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2070 argvals[2]);
2071 goto done;
2072 case 4:
2073 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2074 argvals[2], argvals[3]);
2075 goto done;
2076 case 5:
2077 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2078 argvals[3], argvals[4]);
2079 goto done;
2080 case 6:
2081 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2082 argvals[3], argvals[4], argvals[5]);
2083 goto done;
2084 case 7:
2085 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2086 argvals[3], argvals[4], argvals[5],
2087 argvals[6]);
2088 goto done;
2089
2090 case 8:
2091 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2092 argvals[3], argvals[4], argvals[5],
2093 argvals[6], argvals[7]);
2094 goto done;
2095
2096 default:
2097 /* Someone has created a subr that takes more arguments than
2098 is supported by this code. We need to either rewrite the
2099 subr to use a different argument protocol, or add more
2100 cases to this switch. */
2101 abort ();
2102 }
2103 }
2104 if (COMPILEDP (fun))
2105 val = apply_lambda (fun, original_args, 1);
2106 else
2107 {
2108 if (!CONSP (fun))
2109 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2110 funcar = Fcar (fun);
2111 if (!SYMBOLP (funcar))
2112 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2113 if (EQ (funcar, Qautoload))
2114 {
2115 do_autoload (fun, original_fun);
2116 goto retry;
2117 }
2118 if (EQ (funcar, Qmacro))
2119 val = Feval (apply1 (Fcdr (fun), original_args));
2120 else if (EQ (funcar, Qlambda))
2121 val = apply_lambda (fun, original_args, 1);
2122 else if (EQ (funcar, Qmocklisp))
2123 val = ml_apply (fun, original_args);
2124 else
2125 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2126 }
2127 done:
2128 if (!EQ (Vmocklisp_arguments, Qt))
2129 {
2130 if (NILP (val))
2131 XSETFASTINT (val, 0);
2132 else if (EQ (val, Qt))
2133 XSETFASTINT (val, 1);
2134 }
2135 lisp_eval_depth--;
2136 if (backtrace.debug_on_exit)
2137 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2138 backtrace_list = backtrace.next;
2139 return val;
2140 }
2141 \f
2142 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
2143 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2144 Then return the value FUNCTION returns.
2145 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2146 usage: (apply FUNCTION &rest ARGUMENTS) */)
2147 (nargs, args)
2148 int nargs;
2149 Lisp_Object *args;
2150 {
2151 register int i, numargs;
2152 register Lisp_Object spread_arg;
2153 register Lisp_Object *funcall_args;
2154 Lisp_Object fun;
2155 struct gcpro gcpro1;
2156
2157 fun = args [0];
2158 funcall_args = 0;
2159 spread_arg = args [nargs - 1];
2160 CHECK_LIST (spread_arg);
2161
2162 numargs = XINT (Flength (spread_arg));
2163
2164 if (numargs == 0)
2165 return Ffuncall (nargs - 1, args);
2166 else if (numargs == 1)
2167 {
2168 args [nargs - 1] = XCAR (spread_arg);
2169 return Ffuncall (nargs, args);
2170 }
2171
2172 numargs += nargs - 2;
2173
2174 fun = indirect_function (fun);
2175 if (EQ (fun, Qunbound))
2176 {
2177 /* Let funcall get the error */
2178 fun = args[0];
2179 goto funcall;
2180 }
2181
2182 if (SUBRP (fun))
2183 {
2184 if (numargs < XSUBR (fun)->min_args
2185 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2186 goto funcall; /* Let funcall get the error */
2187 else if (XSUBR (fun)->max_args > numargs)
2188 {
2189 /* Avoid making funcall cons up a yet another new vector of arguments
2190 by explicitly supplying nil's for optional values */
2191 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
2192 * sizeof (Lisp_Object));
2193 for (i = numargs; i < XSUBR (fun)->max_args;)
2194 funcall_args[++i] = Qnil;
2195 GCPRO1 (*funcall_args);
2196 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
2197 }
2198 }
2199 funcall:
2200 /* We add 1 to numargs because funcall_args includes the
2201 function itself as well as its arguments. */
2202 if (!funcall_args)
2203 {
2204 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
2205 * sizeof (Lisp_Object));
2206 GCPRO1 (*funcall_args);
2207 gcpro1.nvars = 1 + numargs;
2208 }
2209
2210 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
2211 /* Spread the last arg we got. Its first element goes in
2212 the slot that it used to occupy, hence this value of I. */
2213 i = nargs - 1;
2214 while (!NILP (spread_arg))
2215 {
2216 funcall_args [i++] = XCAR (spread_arg);
2217 spread_arg = XCDR (spread_arg);
2218 }
2219
2220 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
2221 }
2222 \f
2223 /* Run hook variables in various ways. */
2224
2225 enum run_hooks_condition {to_completion, until_success, until_failure};
2226 static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *,
2227 enum run_hooks_condition));
2228
2229 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
2230 doc: /* Run each hook in HOOKS. Major mode functions use this.
2231 Each argument should be a symbol, a hook variable.
2232 These symbols are processed in the order specified.
2233 If a hook symbol has a non-nil value, that value may be a function
2234 or a list of functions to be called to run the hook.
2235 If the value is a function, it is called with no arguments.
2236 If it is a list, the elements are called, in order, with no arguments.
2237
2238 Do not use `make-local-variable' to make a hook variable buffer-local.
2239 Instead, use `add-hook' and specify t for the LOCAL argument.
2240 usage: (run-hooks &rest HOOKS) */)
2241 (nargs, args)
2242 int nargs;
2243 Lisp_Object *args;
2244 {
2245 Lisp_Object hook[1];
2246 register int i;
2247
2248 for (i = 0; i < nargs; i++)
2249 {
2250 hook[0] = args[i];
2251 run_hook_with_args (1, hook, to_completion);
2252 }
2253
2254 return Qnil;
2255 }
2256
2257 DEFUN ("run-hook-with-args", Frun_hook_with_args,
2258 Srun_hook_with_args, 1, MANY, 0,
2259 doc: /* Run HOOK with the specified arguments ARGS.
2260 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2261 value, that value may be a function or a list of functions to be
2262 called to run the hook. If the value is a function, it is called with
2263 the given arguments and its return value is returned. If it is a list
2264 of functions, those functions are called, in order,
2265 with the given arguments ARGS.
2266 It is best not to depend on the value return by `run-hook-with-args',
2267 as that may change.
2268
2269 Do not use `make-local-variable' to make a hook variable buffer-local.
2270 Instead, use `add-hook' and specify t for the LOCAL argument.
2271 usage: (run-hook-with-args HOOK &rest ARGS) */)
2272 (nargs, args)
2273 int nargs;
2274 Lisp_Object *args;
2275 {
2276 return run_hook_with_args (nargs, args, to_completion);
2277 }
2278
2279 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
2280 Srun_hook_with_args_until_success, 1, MANY, 0,
2281 doc: /* Run HOOK with the specified arguments ARGS.
2282 HOOK should be a symbol, a hook variable. Its value should
2283 be a list of functions. We call those functions, one by one,
2284 passing arguments ARGS to each of them, until one of them
2285 returns a non-nil value. Then we return that value.
2286 If all the functions return nil, we return nil.
2287
2288 Do not use `make-local-variable' to make a hook variable buffer-local.
2289 Instead, use `add-hook' and specify t for the LOCAL argument.
2290 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2291 (nargs, args)
2292 int nargs;
2293 Lisp_Object *args;
2294 {
2295 return run_hook_with_args (nargs, args, until_success);
2296 }
2297
2298 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
2299 Srun_hook_with_args_until_failure, 1, MANY, 0,
2300 doc: /* Run HOOK with the specified arguments ARGS.
2301 HOOK should be a symbol, a hook variable. Its value should
2302 be a list of functions. We call those functions, one by one,
2303 passing arguments ARGS to each of them, until one of them
2304 returns nil. Then we return nil.
2305 If all the functions return non-nil, we return non-nil.
2306
2307 Do not use `make-local-variable' to make a hook variable buffer-local.
2308 Instead, use `add-hook' and specify t for the LOCAL argument.
2309 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2310 (nargs, args)
2311 int nargs;
2312 Lisp_Object *args;
2313 {
2314 return run_hook_with_args (nargs, args, until_failure);
2315 }
2316
2317 /* ARGS[0] should be a hook symbol.
2318 Call each of the functions in the hook value, passing each of them
2319 as arguments all the rest of ARGS (all NARGS - 1 elements).
2320 COND specifies a condition to test after each call
2321 to decide whether to stop.
2322 The caller (or its caller, etc) must gcpro all of ARGS,
2323 except that it isn't necessary to gcpro ARGS[0]. */
2324
2325 static Lisp_Object
2326 run_hook_with_args (nargs, args, cond)
2327 int nargs;
2328 Lisp_Object *args;
2329 enum run_hooks_condition cond;
2330 {
2331 Lisp_Object sym, val, ret;
2332 Lisp_Object globals;
2333 struct gcpro gcpro1, gcpro2, gcpro3;
2334
2335 /* If we are dying or still initializing,
2336 don't do anything--it would probably crash if we tried. */
2337 if (NILP (Vrun_hooks))
2338 return Qnil;
2339
2340 sym = args[0];
2341 val = find_symbol_value (sym);
2342 ret = (cond == until_failure ? Qt : Qnil);
2343
2344 if (EQ (val, Qunbound) || NILP (val))
2345 return ret;
2346 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
2347 {
2348 args[0] = val;
2349 return Ffuncall (nargs, args);
2350 }
2351 else
2352 {
2353 globals = Qnil;
2354 GCPRO3 (sym, val, globals);
2355
2356 for (;
2357 CONSP (val) && ((cond == to_completion)
2358 || (cond == until_success ? NILP (ret)
2359 : !NILP (ret)));
2360 val = XCDR (val))
2361 {
2362 if (EQ (XCAR (val), Qt))
2363 {
2364 /* t indicates this hook has a local binding;
2365 it means to run the global binding too. */
2366
2367 for (globals = Fdefault_value (sym);
2368 CONSP (globals) && ((cond == to_completion)
2369 || (cond == until_success ? NILP (ret)
2370 : !NILP (ret)));
2371 globals = XCDR (globals))
2372 {
2373 args[0] = XCAR (globals);
2374 /* In a global value, t should not occur. If it does, we
2375 must ignore it to avoid an endless loop. */
2376 if (!EQ (args[0], Qt))
2377 ret = Ffuncall (nargs, args);
2378 }
2379 }
2380 else
2381 {
2382 args[0] = XCAR (val);
2383 ret = Ffuncall (nargs, args);
2384 }
2385 }
2386
2387 UNGCPRO;
2388 return ret;
2389 }
2390 }
2391
2392 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2393 present value of that symbol.
2394 Call each element of FUNLIST,
2395 passing each of them the rest of ARGS.
2396 The caller (or its caller, etc) must gcpro all of ARGS,
2397 except that it isn't necessary to gcpro ARGS[0]. */
2398
2399 Lisp_Object
2400 run_hook_list_with_args (funlist, nargs, args)
2401 Lisp_Object funlist;
2402 int nargs;
2403 Lisp_Object *args;
2404 {
2405 Lisp_Object sym;
2406 Lisp_Object val;
2407 Lisp_Object globals;
2408 struct gcpro gcpro1, gcpro2, gcpro3;
2409
2410 sym = args[0];
2411 globals = Qnil;
2412 GCPRO3 (sym, val, globals);
2413
2414 for (val = funlist; CONSP (val); val = XCDR (val))
2415 {
2416 if (EQ (XCAR (val), Qt))
2417 {
2418 /* t indicates this hook has a local binding;
2419 it means to run the global binding too. */
2420
2421 for (globals = Fdefault_value (sym);
2422 CONSP (globals);
2423 globals = XCDR (globals))
2424 {
2425 args[0] = XCAR (globals);
2426 /* In a global value, t should not occur. If it does, we
2427 must ignore it to avoid an endless loop. */
2428 if (!EQ (args[0], Qt))
2429 Ffuncall (nargs, args);
2430 }
2431 }
2432 else
2433 {
2434 args[0] = XCAR (val);
2435 Ffuncall (nargs, args);
2436 }
2437 }
2438 UNGCPRO;
2439 return Qnil;
2440 }
2441
2442 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2443
2444 void
2445 run_hook_with_args_2 (hook, arg1, arg2)
2446 Lisp_Object hook, arg1, arg2;
2447 {
2448 Lisp_Object temp[3];
2449 temp[0] = hook;
2450 temp[1] = arg1;
2451 temp[2] = arg2;
2452
2453 Frun_hook_with_args (3, temp);
2454 }
2455 \f
2456 /* Apply fn to arg */
2457 Lisp_Object
2458 apply1 (fn, arg)
2459 Lisp_Object fn, arg;
2460 {
2461 struct gcpro gcpro1;
2462
2463 GCPRO1 (fn);
2464 if (NILP (arg))
2465 RETURN_UNGCPRO (Ffuncall (1, &fn));
2466 gcpro1.nvars = 2;
2467 #ifdef NO_ARG_ARRAY
2468 {
2469 Lisp_Object args[2];
2470 args[0] = fn;
2471 args[1] = arg;
2472 gcpro1.var = args;
2473 RETURN_UNGCPRO (Fapply (2, args));
2474 }
2475 #else /* not NO_ARG_ARRAY */
2476 RETURN_UNGCPRO (Fapply (2, &fn));
2477 #endif /* not NO_ARG_ARRAY */
2478 }
2479
2480 /* Call function fn on no arguments */
2481 Lisp_Object
2482 call0 (fn)
2483 Lisp_Object fn;
2484 {
2485 struct gcpro gcpro1;
2486
2487 GCPRO1 (fn);
2488 RETURN_UNGCPRO (Ffuncall (1, &fn));
2489 }
2490
2491 /* Call function fn with 1 argument arg1 */
2492 /* ARGSUSED */
2493 Lisp_Object
2494 call1 (fn, arg1)
2495 Lisp_Object fn, arg1;
2496 {
2497 struct gcpro gcpro1;
2498 #ifdef NO_ARG_ARRAY
2499 Lisp_Object args[2];
2500
2501 args[0] = fn;
2502 args[1] = arg1;
2503 GCPRO1 (args[0]);
2504 gcpro1.nvars = 2;
2505 RETURN_UNGCPRO (Ffuncall (2, args));
2506 #else /* not NO_ARG_ARRAY */
2507 GCPRO1 (fn);
2508 gcpro1.nvars = 2;
2509 RETURN_UNGCPRO (Ffuncall (2, &fn));
2510 #endif /* not NO_ARG_ARRAY */
2511 }
2512
2513 /* Call function fn with 2 arguments arg1, arg2 */
2514 /* ARGSUSED */
2515 Lisp_Object
2516 call2 (fn, arg1, arg2)
2517 Lisp_Object fn, arg1, arg2;
2518 {
2519 struct gcpro gcpro1;
2520 #ifdef NO_ARG_ARRAY
2521 Lisp_Object args[3];
2522 args[0] = fn;
2523 args[1] = arg1;
2524 args[2] = arg2;
2525 GCPRO1 (args[0]);
2526 gcpro1.nvars = 3;
2527 RETURN_UNGCPRO (Ffuncall (3, args));
2528 #else /* not NO_ARG_ARRAY */
2529 GCPRO1 (fn);
2530 gcpro1.nvars = 3;
2531 RETURN_UNGCPRO (Ffuncall (3, &fn));
2532 #endif /* not NO_ARG_ARRAY */
2533 }
2534
2535 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2536 /* ARGSUSED */
2537 Lisp_Object
2538 call3 (fn, arg1, arg2, arg3)
2539 Lisp_Object fn, arg1, arg2, arg3;
2540 {
2541 struct gcpro gcpro1;
2542 #ifdef NO_ARG_ARRAY
2543 Lisp_Object args[4];
2544 args[0] = fn;
2545 args[1] = arg1;
2546 args[2] = arg2;
2547 args[3] = arg3;
2548 GCPRO1 (args[0]);
2549 gcpro1.nvars = 4;
2550 RETURN_UNGCPRO (Ffuncall (4, args));
2551 #else /* not NO_ARG_ARRAY */
2552 GCPRO1 (fn);
2553 gcpro1.nvars = 4;
2554 RETURN_UNGCPRO (Ffuncall (4, &fn));
2555 #endif /* not NO_ARG_ARRAY */
2556 }
2557
2558 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2559 /* ARGSUSED */
2560 Lisp_Object
2561 call4 (fn, arg1, arg2, arg3, arg4)
2562 Lisp_Object fn, arg1, arg2, arg3, arg4;
2563 {
2564 struct gcpro gcpro1;
2565 #ifdef NO_ARG_ARRAY
2566 Lisp_Object args[5];
2567 args[0] = fn;
2568 args[1] = arg1;
2569 args[2] = arg2;
2570 args[3] = arg3;
2571 args[4] = arg4;
2572 GCPRO1 (args[0]);
2573 gcpro1.nvars = 5;
2574 RETURN_UNGCPRO (Ffuncall (5, args));
2575 #else /* not NO_ARG_ARRAY */
2576 GCPRO1 (fn);
2577 gcpro1.nvars = 5;
2578 RETURN_UNGCPRO (Ffuncall (5, &fn));
2579 #endif /* not NO_ARG_ARRAY */
2580 }
2581
2582 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2583 /* ARGSUSED */
2584 Lisp_Object
2585 call5 (fn, arg1, arg2, arg3, arg4, arg5)
2586 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
2587 {
2588 struct gcpro gcpro1;
2589 #ifdef NO_ARG_ARRAY
2590 Lisp_Object args[6];
2591 args[0] = fn;
2592 args[1] = arg1;
2593 args[2] = arg2;
2594 args[3] = arg3;
2595 args[4] = arg4;
2596 args[5] = arg5;
2597 GCPRO1 (args[0]);
2598 gcpro1.nvars = 6;
2599 RETURN_UNGCPRO (Ffuncall (6, args));
2600 #else /* not NO_ARG_ARRAY */
2601 GCPRO1 (fn);
2602 gcpro1.nvars = 6;
2603 RETURN_UNGCPRO (Ffuncall (6, &fn));
2604 #endif /* not NO_ARG_ARRAY */
2605 }
2606
2607 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2608 /* ARGSUSED */
2609 Lisp_Object
2610 call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
2611 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
2612 {
2613 struct gcpro gcpro1;
2614 #ifdef NO_ARG_ARRAY
2615 Lisp_Object args[7];
2616 args[0] = fn;
2617 args[1] = arg1;
2618 args[2] = arg2;
2619 args[3] = arg3;
2620 args[4] = arg4;
2621 args[5] = arg5;
2622 args[6] = arg6;
2623 GCPRO1 (args[0]);
2624 gcpro1.nvars = 7;
2625 RETURN_UNGCPRO (Ffuncall (7, args));
2626 #else /* not NO_ARG_ARRAY */
2627 GCPRO1 (fn);
2628 gcpro1.nvars = 7;
2629 RETURN_UNGCPRO (Ffuncall (7, &fn));
2630 #endif /* not NO_ARG_ARRAY */
2631 }
2632
2633 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2634 doc: /* Call first argument as a function, passing remaining arguments to it.
2635 Return the value that function returns.
2636 Thus, (funcall 'cons 'x 'y) returns (x . y).
2637 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2638 (nargs, args)
2639 int nargs;
2640 Lisp_Object *args;
2641 {
2642 Lisp_Object fun;
2643 Lisp_Object funcar;
2644 int numargs = nargs - 1;
2645 Lisp_Object lisp_numargs;
2646 Lisp_Object val;
2647 struct backtrace backtrace;
2648 register Lisp_Object *internal_args;
2649 register int i;
2650
2651 QUIT;
2652 if (consing_since_gc > gc_cons_threshold)
2653 Fgarbage_collect ();
2654
2655 if (++lisp_eval_depth > max_lisp_eval_depth)
2656 {
2657 if (max_lisp_eval_depth < 100)
2658 max_lisp_eval_depth = 100;
2659 if (lisp_eval_depth > max_lisp_eval_depth)
2660 error ("Lisp nesting exceeds max-lisp-eval-depth");
2661 }
2662
2663 backtrace.next = backtrace_list;
2664 backtrace_list = &backtrace;
2665 backtrace.function = &args[0];
2666 backtrace.args = &args[1];
2667 backtrace.nargs = nargs - 1;
2668 backtrace.evalargs = 0;
2669 backtrace.debug_on_exit = 0;
2670
2671 if (debug_on_next_call)
2672 do_debug_on_call (Qlambda);
2673
2674 retry:
2675
2676 fun = args[0];
2677
2678 fun = Findirect_function (fun);
2679
2680 if (SUBRP (fun))
2681 {
2682 if (numargs < XSUBR (fun)->min_args
2683 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2684 {
2685 XSETFASTINT (lisp_numargs, numargs);
2686 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
2687 }
2688
2689 if (XSUBR (fun)->max_args == UNEVALLED)
2690 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2691
2692 if (XSUBR (fun)->max_args == MANY)
2693 {
2694 val = (*XSUBR (fun)->function) (numargs, args + 1);
2695 goto done;
2696 }
2697
2698 if (XSUBR (fun)->max_args > numargs)
2699 {
2700 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2701 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
2702 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2703 internal_args[i] = Qnil;
2704 }
2705 else
2706 internal_args = args + 1;
2707 switch (XSUBR (fun)->max_args)
2708 {
2709 case 0:
2710 val = (*XSUBR (fun)->function) ();
2711 goto done;
2712 case 1:
2713 val = (*XSUBR (fun)->function) (internal_args[0]);
2714 goto done;
2715 case 2:
2716 val = (*XSUBR (fun)->function) (internal_args[0],
2717 internal_args[1]);
2718 goto done;
2719 case 3:
2720 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2721 internal_args[2]);
2722 goto done;
2723 case 4:
2724 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2725 internal_args[2],
2726 internal_args[3]);
2727 goto done;
2728 case 5:
2729 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2730 internal_args[2], internal_args[3],
2731 internal_args[4]);
2732 goto done;
2733 case 6:
2734 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2735 internal_args[2], internal_args[3],
2736 internal_args[4], internal_args[5]);
2737 goto done;
2738 case 7:
2739 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2740 internal_args[2], internal_args[3],
2741 internal_args[4], internal_args[5],
2742 internal_args[6]);
2743 goto done;
2744
2745 case 8:
2746 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2747 internal_args[2], internal_args[3],
2748 internal_args[4], internal_args[5],
2749 internal_args[6], internal_args[7]);
2750 goto done;
2751
2752 default:
2753
2754 /* If a subr takes more than 8 arguments without using MANY
2755 or UNEVALLED, we need to extend this function to support it.
2756 Until this is done, there is no way to call the function. */
2757 abort ();
2758 }
2759 }
2760 if (COMPILEDP (fun))
2761 val = funcall_lambda (fun, numargs, args + 1);
2762 else
2763 {
2764 if (!CONSP (fun))
2765 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2766 funcar = Fcar (fun);
2767 if (!SYMBOLP (funcar))
2768 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2769 if (EQ (funcar, Qlambda))
2770 val = funcall_lambda (fun, numargs, args + 1);
2771 else if (EQ (funcar, Qmocklisp))
2772 val = ml_apply (fun, Flist (numargs, args + 1));
2773 else if (EQ (funcar, Qautoload))
2774 {
2775 do_autoload (fun, args[0]);
2776 goto retry;
2777 }
2778 else
2779 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2780 }
2781 done:
2782 lisp_eval_depth--;
2783 if (backtrace.debug_on_exit)
2784 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2785 backtrace_list = backtrace.next;
2786 return val;
2787 }
2788 \f
2789 Lisp_Object
2790 apply_lambda (fun, args, eval_flag)
2791 Lisp_Object fun, args;
2792 int eval_flag;
2793 {
2794 Lisp_Object args_left;
2795 Lisp_Object numargs;
2796 register Lisp_Object *arg_vector;
2797 struct gcpro gcpro1, gcpro2, gcpro3;
2798 register int i;
2799 register Lisp_Object tem;
2800
2801 numargs = Flength (args);
2802 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2803 args_left = args;
2804
2805 GCPRO3 (*arg_vector, args_left, fun);
2806 gcpro1.nvars = 0;
2807
2808 for (i = 0; i < XINT (numargs);)
2809 {
2810 tem = Fcar (args_left), args_left = Fcdr (args_left);
2811 if (eval_flag) tem = Feval (tem);
2812 arg_vector[i++] = tem;
2813 gcpro1.nvars = i;
2814 }
2815
2816 UNGCPRO;
2817
2818 if (eval_flag)
2819 {
2820 backtrace_list->args = arg_vector;
2821 backtrace_list->nargs = i;
2822 }
2823 backtrace_list->evalargs = 0;
2824 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
2825
2826 /* Do the debug-on-exit now, while arg_vector still exists. */
2827 if (backtrace_list->debug_on_exit)
2828 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
2829 /* Don't do it again when we return to eval. */
2830 backtrace_list->debug_on_exit = 0;
2831 return tem;
2832 }
2833
2834 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2835 and return the result of evaluation.
2836 FUN must be either a lambda-expression or a compiled-code object. */
2837
2838 static Lisp_Object
2839 funcall_lambda (fun, nargs, arg_vector)
2840 Lisp_Object fun;
2841 int nargs;
2842 register Lisp_Object *arg_vector;
2843 {
2844 Lisp_Object val, syms_left, next;
2845 int count = specpdl_ptr - specpdl;
2846 int i, optional, rest;
2847
2848 if (NILP (Vmocklisp_arguments))
2849 specbind (Qmocklisp_arguments, Qt); /* t means NOT mocklisp! */
2850
2851 if (CONSP (fun))
2852 {
2853 syms_left = XCDR (fun);
2854 if (CONSP (syms_left))
2855 syms_left = XCAR (syms_left);
2856 else
2857 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2858 }
2859 else if (COMPILEDP (fun))
2860 syms_left = AREF (fun, COMPILED_ARGLIST);
2861 else
2862 abort ();
2863
2864 i = optional = rest = 0;
2865 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
2866 {
2867 QUIT;
2868
2869 next = XCAR (syms_left);
2870 while (!SYMBOLP (next))
2871 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2872
2873 if (EQ (next, Qand_rest))
2874 rest = 1;
2875 else if (EQ (next, Qand_optional))
2876 optional = 1;
2877 else if (rest)
2878 {
2879 specbind (next, Flist (nargs - i, &arg_vector[i]));
2880 i = nargs;
2881 }
2882 else if (i < nargs)
2883 specbind (next, arg_vector[i++]);
2884 else if (!optional)
2885 return Fsignal (Qwrong_number_of_arguments,
2886 Fcons (fun, Fcons (make_number (nargs), Qnil)));
2887 else
2888 specbind (next, Qnil);
2889 }
2890
2891 if (!NILP (syms_left))
2892 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2893 else if (i < nargs)
2894 return Fsignal (Qwrong_number_of_arguments,
2895 Fcons (fun, Fcons (make_number (nargs), Qnil)));
2896
2897 if (CONSP (fun))
2898 val = Fprogn (XCDR (XCDR (fun)));
2899 else
2900 {
2901 /* If we have not actually read the bytecode string
2902 and constants vector yet, fetch them from the file. */
2903 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
2904 Ffetch_bytecode (fun);
2905 val = Fbyte_code (AREF (fun, COMPILED_BYTECODE),
2906 AREF (fun, COMPILED_CONSTANTS),
2907 AREF (fun, COMPILED_STACK_DEPTH));
2908 }
2909
2910 return unbind_to (count, val);
2911 }
2912
2913 DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
2914 1, 1, 0,
2915 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2916 (object)
2917 Lisp_Object object;
2918 {
2919 Lisp_Object tem;
2920
2921 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
2922 {
2923 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
2924 if (!CONSP (tem))
2925 {
2926 tem = AREF (object, COMPILED_BYTECODE);
2927 if (CONSP (tem) && STRINGP (XCAR (tem)))
2928 error ("Invalid byte code in %s", XSTRING (XCAR (tem))->data);
2929 else
2930 error ("Invalid byte code");
2931 }
2932 AREF (object, COMPILED_BYTECODE) = XCAR (tem);
2933 AREF (object, COMPILED_CONSTANTS) = XCDR (tem);
2934 }
2935 return object;
2936 }
2937 \f
2938 void
2939 grow_specpdl ()
2940 {
2941 register int count = specpdl_ptr - specpdl;
2942 if (specpdl_size >= max_specpdl_size)
2943 {
2944 if (max_specpdl_size < 400)
2945 max_specpdl_size = 400;
2946 if (specpdl_size >= max_specpdl_size)
2947 {
2948 if (!NILP (Vdebug_on_error))
2949 /* Leave room for some specpdl in the debugger. */
2950 max_specpdl_size = specpdl_size + 100;
2951 Fsignal (Qerror,
2952 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil));
2953 }
2954 }
2955 specpdl_size *= 2;
2956 if (specpdl_size > max_specpdl_size)
2957 specpdl_size = max_specpdl_size;
2958 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
2959 specpdl_ptr = specpdl + count;
2960 }
2961
2962 void
2963 specbind (symbol, value)
2964 Lisp_Object symbol, value;
2965 {
2966 Lisp_Object ovalue;
2967 Lisp_Object valcontents;
2968
2969 CHECK_SYMBOL (symbol);
2970 if (specpdl_ptr == specpdl + specpdl_size)
2971 grow_specpdl ();
2972
2973 /* The most common case is that of a non-constant symbol with a
2974 trivial value. Make that as fast as we can. */
2975 valcontents = SYMBOL_VALUE (symbol);
2976 if (!MISCP (valcontents) && !SYMBOL_CONSTANT_P (symbol))
2977 {
2978 specpdl_ptr->symbol = symbol;
2979 specpdl_ptr->old_value = valcontents;
2980 specpdl_ptr->func = NULL;
2981 ++specpdl_ptr;
2982 SET_SYMBOL_VALUE (symbol, value);
2983 }
2984 else
2985 {
2986 Lisp_Object valcontents;
2987
2988 ovalue = find_symbol_value (symbol);
2989 specpdl_ptr->func = 0;
2990 specpdl_ptr->old_value = ovalue;
2991
2992 valcontents = XSYMBOL (symbol)->value;
2993
2994 if (BUFFER_LOCAL_VALUEP (valcontents)
2995 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
2996 || BUFFER_OBJFWDP (valcontents))
2997 {
2998 Lisp_Object where, current_buffer;
2999
3000 current_buffer = Fcurrent_buffer ();
3001
3002 /* For a local variable, record both the symbol and which
3003 buffer's or frame's value we are saving. */
3004 if (!NILP (Flocal_variable_p (symbol, Qnil)))
3005 where = current_buffer;
3006 else if (!BUFFER_OBJFWDP (valcontents)
3007 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
3008 where = XBUFFER_LOCAL_VALUE (valcontents)->frame;
3009 else
3010 where = Qnil;
3011
3012 /* We're not using the `unused' slot in the specbinding
3013 structure because this would mean we have to do more
3014 work for simple variables. */
3015 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, current_buffer));
3016
3017 /* If SYMBOL is a per-buffer variable which doesn't have a
3018 buffer-local value here, make the `let' change the global
3019 value by changing the value of SYMBOL in all buffers not
3020 having their own value. This is consistent with what
3021 happens with other buffer-local variables. */
3022 if (NILP (where)
3023 && BUFFER_OBJFWDP (valcontents))
3024 {
3025 ++specpdl_ptr;
3026 Fset_default (symbol, value);
3027 return;
3028 }
3029 }
3030 else
3031 specpdl_ptr->symbol = symbol;
3032
3033 specpdl_ptr++;
3034 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
3035 store_symval_forwarding (symbol, ovalue, value, NULL);
3036 else
3037 set_internal (symbol, value, 0, 1);
3038 }
3039 }
3040
3041 void
3042 record_unwind_protect (function, arg)
3043 Lisp_Object (*function) P_ ((Lisp_Object));
3044 Lisp_Object arg;
3045 {
3046 if (specpdl_ptr == specpdl + specpdl_size)
3047 grow_specpdl ();
3048 specpdl_ptr->func = function;
3049 specpdl_ptr->symbol = Qnil;
3050 specpdl_ptr->old_value = arg;
3051 specpdl_ptr++;
3052 }
3053
3054 Lisp_Object
3055 unbind_to (count, value)
3056 int count;
3057 Lisp_Object value;
3058 {
3059 int quitf = !NILP (Vquit_flag);
3060 struct gcpro gcpro1;
3061
3062 GCPRO1 (value);
3063 Vquit_flag = Qnil;
3064
3065 while (specpdl_ptr != specpdl + count)
3066 {
3067 --specpdl_ptr;
3068
3069 if (specpdl_ptr->func != 0)
3070 (*specpdl_ptr->func) (specpdl_ptr->old_value);
3071 /* Note that a "binding" of nil is really an unwind protect,
3072 so in that case the "old value" is a list of forms to evaluate. */
3073 else if (NILP (specpdl_ptr->symbol))
3074 Fprogn (specpdl_ptr->old_value);
3075 /* If the symbol is a list, it is really (SYMBOL WHERE
3076 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3077 frame. If WHERE is a buffer or frame, this indicates we
3078 bound a variable that had a buffer-local or frame-local
3079 binding. WHERE nil means that the variable had the default
3080 value when it was bound. CURRENT-BUFFER is the buffer that
3081 was current when the variable was bound. */
3082 else if (CONSP (specpdl_ptr->symbol))
3083 {
3084 Lisp_Object symbol, where;
3085
3086 symbol = XCAR (specpdl_ptr->symbol);
3087 where = XCAR (XCDR (specpdl_ptr->symbol));
3088
3089 if (NILP (where))
3090 Fset_default (symbol, specpdl_ptr->old_value);
3091 else if (BUFFERP (where))
3092 set_internal (symbol, specpdl_ptr->old_value, XBUFFER (where), 1);
3093 else
3094 set_internal (symbol, specpdl_ptr->old_value, NULL, 1);
3095 }
3096 else
3097 {
3098 /* If variable has a trivial value (no forwarding), we can
3099 just set it. No need to check for constant symbols here,
3100 since that was already done by specbind. */
3101 if (!MISCP (SYMBOL_VALUE (specpdl_ptr->symbol)))
3102 SET_SYMBOL_VALUE (specpdl_ptr->symbol, specpdl_ptr->old_value);
3103 else
3104 set_internal (specpdl_ptr->symbol, specpdl_ptr->old_value, 0, 1);
3105 }
3106 }
3107
3108 if (NILP (Vquit_flag) && quitf)
3109 Vquit_flag = Qt;
3110
3111 UNGCPRO;
3112 return value;
3113 }
3114 \f
3115 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
3116 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3117 The debugger is entered when that frame exits, if the flag is non-nil. */)
3118 (level, flag)
3119 Lisp_Object level, flag;
3120 {
3121 register struct backtrace *backlist = backtrace_list;
3122 register int i;
3123
3124 CHECK_NUMBER (level);
3125
3126 for (i = 0; backlist && i < XINT (level); i++)
3127 {
3128 backlist = backlist->next;
3129 }
3130
3131 if (backlist)
3132 backlist->debug_on_exit = !NILP (flag);
3133
3134 return flag;
3135 }
3136
3137 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
3138 doc: /* Print a trace of Lisp function calls currently active.
3139 Output stream used is value of `standard-output'. */)
3140 ()
3141 {
3142 register struct backtrace *backlist = backtrace_list;
3143 register int i;
3144 Lisp_Object tail;
3145 Lisp_Object tem;
3146 extern Lisp_Object Vprint_level;
3147 struct gcpro gcpro1;
3148
3149 XSETFASTINT (Vprint_level, 3);
3150
3151 tail = Qnil;
3152 GCPRO1 (tail);
3153
3154 while (backlist)
3155 {
3156 write_string (backlist->debug_on_exit ? "* " : " ", 2);
3157 if (backlist->nargs == UNEVALLED)
3158 {
3159 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
3160 write_string ("\n", -1);
3161 }
3162 else
3163 {
3164 tem = *backlist->function;
3165 Fprin1 (tem, Qnil); /* This can QUIT */
3166 write_string ("(", -1);
3167 if (backlist->nargs == MANY)
3168 {
3169 for (tail = *backlist->args, i = 0;
3170 !NILP (tail);
3171 tail = Fcdr (tail), i++)
3172 {
3173 if (i) write_string (" ", -1);
3174 Fprin1 (Fcar (tail), Qnil);
3175 }
3176 }
3177 else
3178 {
3179 for (i = 0; i < backlist->nargs; i++)
3180 {
3181 if (i) write_string (" ", -1);
3182 Fprin1 (backlist->args[i], Qnil);
3183 }
3184 }
3185 write_string (")\n", -1);
3186 }
3187 backlist = backlist->next;
3188 }
3189
3190 Vprint_level = Qnil;
3191 UNGCPRO;
3192 return Qnil;
3193 }
3194
3195 DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
3196 doc: /* Return the function and arguments NFRAMES up from current execution point.
3197 If that frame has not evaluated the arguments yet (or is a special form),
3198 the value is (nil FUNCTION ARG-FORMS...).
3199 If that frame has evaluated its arguments and called its function already,
3200 the value is (t FUNCTION ARG-VALUES...).
3201 A &rest arg is represented as the tail of the list ARG-VALUES.
3202 FUNCTION is whatever was supplied as car of evaluated list,
3203 or a lambda expression for macro calls.
3204 If NFRAMES is more than the number of frames, the value is nil. */)
3205 (nframes)
3206 Lisp_Object nframes;
3207 {
3208 register struct backtrace *backlist = backtrace_list;
3209 register int i;
3210 Lisp_Object tem;
3211
3212 CHECK_NATNUM (nframes);
3213
3214 /* Find the frame requested. */
3215 for (i = 0; backlist && i < XFASTINT (nframes); i++)
3216 backlist = backlist->next;
3217
3218 if (!backlist)
3219 return Qnil;
3220 if (backlist->nargs == UNEVALLED)
3221 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
3222 else
3223 {
3224 if (backlist->nargs == MANY)
3225 tem = *backlist->args;
3226 else
3227 tem = Flist (backlist->nargs, backlist->args);
3228
3229 return Fcons (Qt, Fcons (*backlist->function, tem));
3230 }
3231 }
3232
3233 \f
3234 void
3235 syms_of_eval ()
3236 {
3237 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
3238 doc: /* *Limit on number of Lisp variable bindings & unwind-protects.
3239 If Lisp code tries to make more than this many at once,
3240 an error is signaled. */);
3241
3242 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
3243 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3244 This limit is to catch infinite recursions for you before they cause
3245 actual stack overflow in C, which would be fatal for Emacs.
3246 You can safely make it considerably larger than its default value,
3247 if that proves inconveniently small. */);
3248
3249 DEFVAR_LISP ("quit-flag", &Vquit_flag,
3250 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3251 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'. */);
3252 Vquit_flag = Qnil;
3253
3254 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
3255 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3256 Note that `quit-flag' will still be set by typing C-g,
3257 so a quit will be signaled as soon as `inhibit-quit' is nil.
3258 To prevent this happening, set `quit-flag' to nil
3259 before making `inhibit-quit' nil. */);
3260 Vinhibit_quit = Qnil;
3261
3262 Qinhibit_quit = intern ("inhibit-quit");
3263 staticpro (&Qinhibit_quit);
3264
3265 Qautoload = intern ("autoload");
3266 staticpro (&Qautoload);
3267
3268 Qdebug_on_error = intern ("debug-on-error");
3269 staticpro (&Qdebug_on_error);
3270
3271 Qmacro = intern ("macro");
3272 staticpro (&Qmacro);
3273
3274 /* Note that the process handling also uses Qexit, but we don't want
3275 to staticpro it twice, so we just do it here. */
3276 Qexit = intern ("exit");
3277 staticpro (&Qexit);
3278
3279 Qinteractive = intern ("interactive");
3280 staticpro (&Qinteractive);
3281
3282 Qcommandp = intern ("commandp");
3283 staticpro (&Qcommandp);
3284
3285 Qdefun = intern ("defun");
3286 staticpro (&Qdefun);
3287
3288 Qand_rest = intern ("&rest");
3289 staticpro (&Qand_rest);
3290
3291 Qand_optional = intern ("&optional");
3292 staticpro (&Qand_optional);
3293
3294 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
3295 doc: /* *Non-nil means errors display a backtrace buffer.
3296 More precisely, this happens for any error that is handled
3297 by the editor command loop.
3298 If the value is a list, an error only means to display a backtrace
3299 if one of its condition symbols appears in the list. */);
3300 Vstack_trace_on_error = Qnil;
3301
3302 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
3303 doc: /* *Non-nil means enter debugger if an error is signaled.
3304 Does not apply to errors handled by `condition-case' or those
3305 matched by `debug-ignored-errors'.
3306 If the value is a list, an error only means to enter the debugger
3307 if one of its condition symbols appears in the list.
3308 When you evaluate an expression interactively, this variable
3309 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3310 See also variable `debug-on-quit'. */);
3311 Vdebug_on_error = Qnil;
3312
3313 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors,
3314 doc: /* *List of errors for which the debugger should not be called.
3315 Each element may be a condition-name or a regexp that matches error messages.
3316 If any element applies to a given error, that error skips the debugger
3317 and just returns to top level.
3318 This overrides the variable `debug-on-error'.
3319 It does not apply to errors handled by `condition-case'. */);
3320 Vdebug_ignored_errors = Qnil;
3321
3322 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
3323 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3324 Does not apply if quit is handled by a `condition-case'.
3325 When you evaluate an expression interactively, this variable
3326 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
3327 debug_on_quit = 0;
3328
3329 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
3330 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3331
3332 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue,
3333 doc: /* Non-nil means debugger may continue execution.
3334 This is nil when the debugger is called under circumstances where it
3335 might not be safe to continue. */);
3336 debugger_may_continue = 1;
3337
3338 DEFVAR_LISP ("debugger", &Vdebugger,
3339 doc: /* Function to call to invoke debugger.
3340 If due to frame exit, args are `exit' and the value being returned;
3341 this function's value will be returned instead of that.
3342 If due to error, args are `error' and a list of the args to `signal'.
3343 If due to `apply' or `funcall' entry, one arg, `lambda'.
3344 If due to `eval' entry, one arg, t. */);
3345 Vdebugger = Qnil;
3346
3347 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function,
3348 doc: /* If non-nil, this is a function for `signal' to call.
3349 It receives the same arguments that `signal' was given.
3350 The Edebug package uses this to regain control. */);
3351 Vsignal_hook_function = Qnil;
3352
3353 Qmocklisp_arguments = intern ("mocklisp-arguments");
3354 staticpro (&Qmocklisp_arguments);
3355 DEFVAR_LISP ("mocklisp-arguments", &Vmocklisp_arguments,
3356 doc: /* While in a mocklisp function, the list of its unevaluated args. */);
3357 Vmocklisp_arguments = Qt;
3358
3359 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal,
3360 doc: /* *Non-nil means call the debugger regardless of condition handlers.
3361 Note that `debug-on-error', `debug-on-quit' and friends
3362 still determine whether to handle the particular condition. */);
3363 Vdebug_on_signal = Qnil;
3364
3365 Vrun_hooks = intern ("run-hooks");
3366 staticpro (&Vrun_hooks);
3367
3368 staticpro (&Vautoload_queue);
3369 Vautoload_queue = Qnil;
3370 staticpro (&Vsignaling_function);
3371 Vsignaling_function = Qnil;
3372
3373 defsubr (&Sor);
3374 defsubr (&Sand);
3375 defsubr (&Sif);
3376 defsubr (&Scond);
3377 defsubr (&Sprogn);
3378 defsubr (&Sprog1);
3379 defsubr (&Sprog2);
3380 defsubr (&Ssetq);
3381 defsubr (&Squote);
3382 defsubr (&Sfunction);
3383 defsubr (&Sdefun);
3384 defsubr (&Sdefmacro);
3385 defsubr (&Sdefvar);
3386 defsubr (&Sdefvaralias);
3387 defsubr (&Sdefconst);
3388 defsubr (&Suser_variable_p);
3389 defsubr (&Slet);
3390 defsubr (&SletX);
3391 defsubr (&Swhile);
3392 defsubr (&Smacroexpand);
3393 defsubr (&Scatch);
3394 defsubr (&Sthrow);
3395 defsubr (&Sunwind_protect);
3396 defsubr (&Scondition_case);
3397 defsubr (&Ssignal);
3398 defsubr (&Sinteractive_p);
3399 defsubr (&Scommandp);
3400 defsubr (&Sautoload);
3401 defsubr (&Seval);
3402 defsubr (&Sapply);
3403 defsubr (&Sfuncall);
3404 defsubr (&Srun_hooks);
3405 defsubr (&Srun_hook_with_args);
3406 defsubr (&Srun_hook_with_args_until_success);
3407 defsubr (&Srun_hook_with_args_until_failure);
3408 defsubr (&Sfetch_bytecode);
3409 defsubr (&Sbacktrace_debug);
3410 defsubr (&Sbacktrace);
3411 defsubr (&Sbacktrace_frame);
3412 }