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