* lisp/icomplete.el: Change separator; add ido-style commands.
[emacs.git] / src / eval.c
blob34b20f6fc8eac07a53aba051cecdd66784ad001e
1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985-1987, 1993-1995, 1999-2012 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include "lisp.h"
24 #include "blockinput.h"
25 #include "commands.h"
26 #include "keyboard.h"
27 #include "dispextern.h"
28 #include "frame.h" /* For XFRAME. */
30 #if HAVE_X_WINDOWS
31 #include "xterm.h"
32 #endif
34 struct backtrace *backtrace_list;
36 #if !BYTE_MARK_STACK
37 static
38 #endif
39 struct catchtag *catchlist;
41 /* Chain of condition handlers currently in effect.
42 The elements of this chain are contained in the stack frames
43 of Fcondition_case and internal_condition_case.
44 When an error is signaled (by calling Fsignal, below),
45 this chain is searched for an element that applies. */
47 #if !BYTE_MARK_STACK
48 static
49 #endif
50 struct handler *handlerlist;
52 #ifdef DEBUG_GCPRO
53 /* Count levels of GCPRO to detect failure to UNGCPRO. */
54 int gcpro_level;
55 #endif
57 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp;
58 Lisp_Object Qinhibit_quit;
59 Lisp_Object Qand_rest;
60 static Lisp_Object Qand_optional;
61 static Lisp_Object Qinhibit_debugger;
62 static Lisp_Object Qdeclare;
63 Lisp_Object Qinternal_interpreter_environment, Qclosure;
65 static Lisp_Object Qdebug;
67 /* This holds either the symbol `run-hooks' or nil.
68 It is nil at an early stage of startup, and when Emacs
69 is shutting down. */
71 Lisp_Object Vrun_hooks;
73 /* Non-nil means record all fset's and provide's, to be undone
74 if the file being autoloaded is not fully loaded.
75 They are recorded by being consed onto the front of Vautoload_queue:
76 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
78 Lisp_Object Vautoload_queue;
80 /* Current number of specbindings allocated in specpdl. */
82 ptrdiff_t specpdl_size;
84 /* Pointer to beginning of specpdl. */
86 struct specbinding *specpdl;
88 /* Pointer to first unused element in specpdl. */
90 struct specbinding *specpdl_ptr;
92 /* Depth in Lisp evaluations and function calls. */
94 static EMACS_INT lisp_eval_depth;
96 /* The value of num_nonmacro_input_events as of the last time we
97 started to enter the debugger. If we decide to enter the debugger
98 again when this is still equal to num_nonmacro_input_events, then we
99 know that the debugger itself has an error, and we should just
100 signal the error instead of entering an infinite loop of debugger
101 invocations. */
103 static EMACS_INT when_entered_debugger;
105 /* The function from which the last `signal' was called. Set in
106 Fsignal. */
108 Lisp_Object Vsignaling_function;
110 /* If non-nil, Lisp code must not be run since some part of Emacs is
111 in an inconsistent state. Currently, x-create-frame uses this to
112 avoid triggering window-configuration-change-hook while the new
113 frame is half-initialized. */
114 Lisp_Object inhibit_lisp_code;
116 static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
117 static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args);
119 /* Functions to set Lisp_Object slots of struct specbinding. */
121 static void
122 set_specpdl_symbol (Lisp_Object symbol)
124 specpdl_ptr->symbol = symbol;
127 static void
128 set_specpdl_old_value (Lisp_Object oldval)
130 specpdl_ptr->old_value = oldval;
133 void
134 init_eval_once (void)
136 enum { size = 50 };
137 specpdl = xmalloc (size * sizeof *specpdl);
138 specpdl_size = size;
139 specpdl_ptr = specpdl;
140 /* Don't forget to update docs (lispref node "Local Variables"). */
141 max_specpdl_size = 1300; /* 1000 is not enough for CEDET's c-by.el. */
142 max_lisp_eval_depth = 600;
144 Vrun_hooks = Qnil;
147 void
148 init_eval (void)
150 specpdl_ptr = specpdl;
151 catchlist = 0;
152 handlerlist = 0;
153 backtrace_list = 0;
154 Vquit_flag = Qnil;
155 debug_on_next_call = 0;
156 lisp_eval_depth = 0;
157 #ifdef DEBUG_GCPRO
158 gcpro_level = 0;
159 #endif
160 /* This is less than the initial value of num_nonmacro_input_events. */
161 when_entered_debugger = -1;
164 /* Unwind-protect function used by call_debugger. */
166 static Lisp_Object
167 restore_stack_limits (Lisp_Object data)
169 max_specpdl_size = XINT (XCAR (data));
170 max_lisp_eval_depth = XINT (XCDR (data));
171 return Qnil;
174 /* Call the Lisp debugger, giving it argument ARG. */
176 Lisp_Object
177 call_debugger (Lisp_Object arg)
179 bool debug_while_redisplaying;
180 ptrdiff_t count = SPECPDL_INDEX ();
181 Lisp_Object val;
182 EMACS_INT old_max = max_specpdl_size;
184 /* Temporarily bump up the stack limits,
185 so the debugger won't run out of stack. */
187 max_specpdl_size += 1;
188 record_unwind_protect (restore_stack_limits,
189 Fcons (make_number (old_max),
190 make_number (max_lisp_eval_depth)));
191 max_specpdl_size = old_max;
193 if (lisp_eval_depth + 40 > max_lisp_eval_depth)
194 max_lisp_eval_depth = lisp_eval_depth + 40;
196 if (max_specpdl_size - 100 < SPECPDL_INDEX ())
197 max_specpdl_size = SPECPDL_INDEX () + 100;
199 #ifdef HAVE_WINDOW_SYSTEM
200 if (display_hourglass_p)
201 cancel_hourglass ();
202 #endif
204 debug_on_next_call = 0;
205 when_entered_debugger = num_nonmacro_input_events;
207 /* Resetting redisplaying_p to 0 makes sure that debug output is
208 displayed if the debugger is invoked during redisplay. */
209 debug_while_redisplaying = redisplaying_p;
210 redisplaying_p = 0;
211 specbind (intern ("debugger-may-continue"),
212 debug_while_redisplaying ? Qnil : Qt);
213 specbind (Qinhibit_redisplay, Qnil);
214 specbind (Qinhibit_debugger, Qt);
216 #if 0 /* Binding this prevents execution of Lisp code during
217 redisplay, which necessarily leads to display problems. */
218 specbind (Qinhibit_eval_during_redisplay, Qt);
219 #endif
221 val = apply1 (Vdebugger, arg);
223 /* Interrupting redisplay and resuming it later is not safe under
224 all circumstances. So, when the debugger returns, abort the
225 interrupted redisplay by going back to the top-level. */
226 if (debug_while_redisplaying)
227 Ftop_level ();
229 return unbind_to (count, val);
232 static void
233 do_debug_on_call (Lisp_Object code)
235 debug_on_next_call = 0;
236 backtrace_list->debug_on_exit = 1;
237 call_debugger (Fcons (code, Qnil));
240 /* NOTE!!! Every function that can call EVAL must protect its args
241 and temporaries from garbage collection while it needs them.
242 The definition of `For' shows what you have to do. */
244 DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
245 doc: /* Eval args until one of them yields non-nil, then return that value.
246 The remaining args are not evalled at all.
247 If all args return nil, return nil.
248 usage: (or CONDITIONS...) */)
249 (Lisp_Object args)
251 register Lisp_Object val = Qnil;
252 struct gcpro gcpro1;
254 GCPRO1 (args);
256 while (CONSP (args))
258 val = eval_sub (XCAR (args));
259 if (!NILP (val))
260 break;
261 args = XCDR (args);
264 UNGCPRO;
265 return val;
268 DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
269 doc: /* Eval args until one of them yields nil, then return nil.
270 The remaining args are not evalled at all.
271 If no arg yields nil, return the last arg's value.
272 usage: (and CONDITIONS...) */)
273 (Lisp_Object args)
275 register Lisp_Object val = Qt;
276 struct gcpro gcpro1;
278 GCPRO1 (args);
280 while (CONSP (args))
282 val = eval_sub (XCAR (args));
283 if (NILP (val))
284 break;
285 args = XCDR (args);
288 UNGCPRO;
289 return val;
292 DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
293 doc: /* If COND yields non-nil, do THEN, else do ELSE...
294 Returns the value of THEN or the value of the last of the ELSE's.
295 THEN must be one expression, but ELSE... can be zero or more expressions.
296 If COND yields nil, and there are no ELSE's, the value is nil.
297 usage: (if COND THEN ELSE...) */)
298 (Lisp_Object args)
300 register Lisp_Object cond;
301 struct gcpro gcpro1;
303 GCPRO1 (args);
304 cond = eval_sub (Fcar (args));
305 UNGCPRO;
307 if (!NILP (cond))
308 return eval_sub (Fcar (Fcdr (args)));
309 return Fprogn (Fcdr (Fcdr (args)));
312 DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
313 doc: /* Try each clause until one succeeds.
314 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
315 and, if the value is non-nil, this clause succeeds:
316 then the expressions in BODY are evaluated and the last one's
317 value is the value of the cond-form.
318 If no clause succeeds, cond returns nil.
319 If a clause has one element, as in (CONDITION),
320 CONDITION's value if non-nil is returned from the cond-form.
321 usage: (cond CLAUSES...) */)
322 (Lisp_Object args)
324 register Lisp_Object clause, val;
325 struct gcpro gcpro1;
327 val = Qnil;
328 GCPRO1 (args);
329 while (!NILP (args))
331 clause = Fcar (args);
332 val = eval_sub (Fcar (clause));
333 if (!NILP (val))
335 if (!EQ (XCDR (clause), Qnil))
336 val = Fprogn (XCDR (clause));
337 break;
339 args = XCDR (args);
341 UNGCPRO;
343 return val;
346 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
347 doc: /* Eval BODY forms sequentially and return value of last one.
348 usage: (progn BODY...) */)
349 (Lisp_Object args)
351 register Lisp_Object val = Qnil;
352 struct gcpro gcpro1;
354 GCPRO1 (args);
356 while (CONSP (args))
358 val = eval_sub (XCAR (args));
359 args = XCDR (args);
362 UNGCPRO;
363 return val;
366 DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
367 doc: /* Eval FIRST and BODY sequentially; return value from FIRST.
368 The value of FIRST is saved during the evaluation of the remaining args,
369 whose values are discarded.
370 usage: (prog1 FIRST BODY...) */)
371 (Lisp_Object args)
373 Lisp_Object val;
374 register Lisp_Object args_left;
375 struct gcpro gcpro1, gcpro2;
377 args_left = args;
378 val = Qnil;
379 GCPRO2 (args, val);
381 val = eval_sub (XCAR (args_left));
382 while (CONSP (args_left = XCDR (args_left)))
383 eval_sub (XCAR (args_left));
385 UNGCPRO;
386 return val;
389 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
390 doc: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
391 The value of FORM2 is saved during the evaluation of the
392 remaining args, whose values are discarded.
393 usage: (prog2 FORM1 FORM2 BODY...) */)
394 (Lisp_Object args)
396 struct gcpro gcpro1;
398 GCPRO1 (args);
399 eval_sub (XCAR (args));
400 UNGCPRO;
401 return Fprog1 (XCDR (args));
404 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
405 doc: /* Set each SYM to the value of its VAL.
406 The symbols SYM are variables; they are literal (not evaluated).
407 The values VAL are expressions; they are evaluated.
408 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
409 The second VAL is not computed until after the first SYM is set, and so on;
410 each VAL can use the new value of variables set earlier in the `setq'.
411 The return value of the `setq' form is the value of the last VAL.
412 usage: (setq [SYM VAL]...) */)
413 (Lisp_Object args)
415 register Lisp_Object args_left;
416 register Lisp_Object val, sym, lex_binding;
417 struct gcpro gcpro1;
419 if (NILP (args))
420 return Qnil;
422 args_left = args;
423 GCPRO1 (args);
427 val = eval_sub (Fcar (Fcdr (args_left)));
428 sym = Fcar (args_left);
430 /* Like for eval_sub, we do not check declared_special here since
431 it's been done when let-binding. */
432 if (!NILP (Vinternal_interpreter_environment) /* Mere optimization! */
433 && SYMBOLP (sym)
434 && !NILP (lex_binding
435 = Fassq (sym, Vinternal_interpreter_environment)))
436 XSETCDR (lex_binding, val); /* SYM is lexically bound. */
437 else
438 Fset (sym, val); /* SYM is dynamically bound. */
440 args_left = Fcdr (Fcdr (args_left));
442 while (!NILP (args_left));
444 UNGCPRO;
445 return val;
448 DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
449 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
450 Warning: `quote' does not construct its return value, but just returns
451 the value that was pre-constructed by the Lisp reader (see info node
452 `(elisp)Printed Representation').
453 This means that '(a . b) is not identical to (cons 'a 'b): the former
454 does not cons. Quoting should be reserved for constants that will
455 never be modified by side-effects, unless you like self-modifying code.
456 See the common pitfall in info node `(elisp)Rearrangement' for an example
457 of unexpected results when a quoted object is modified.
458 usage: (quote ARG) */)
459 (Lisp_Object args)
461 if (!NILP (Fcdr (args)))
462 xsignal2 (Qwrong_number_of_arguments, Qquote, Flength (args));
463 return Fcar (args);
466 DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
467 doc: /* Like `quote', but preferred for objects which are functions.
468 In byte compilation, `function' causes its argument to be compiled.
469 `quote' cannot do that.
470 usage: (function ARG) */)
471 (Lisp_Object args)
473 Lisp_Object quoted = XCAR (args);
475 if (!NILP (Fcdr (args)))
476 xsignal2 (Qwrong_number_of_arguments, Qfunction, Flength (args));
478 if (!NILP (Vinternal_interpreter_environment)
479 && CONSP (quoted)
480 && EQ (XCAR (quoted), Qlambda))
481 /* This is a lambda expression within a lexical environment;
482 return an interpreted closure instead of a simple lambda. */
483 return Fcons (Qclosure, Fcons (Vinternal_interpreter_environment,
484 XCDR (quoted)));
485 else
486 /* Simply quote the argument. */
487 return quoted;
491 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
492 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
493 Aliased variables always have the same value; setting one sets the other.
494 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
495 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
496 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
497 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
498 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
499 The return value is BASE-VARIABLE. */)
500 (Lisp_Object new_alias, Lisp_Object base_variable, Lisp_Object docstring)
502 struct Lisp_Symbol *sym;
504 CHECK_SYMBOL (new_alias);
505 CHECK_SYMBOL (base_variable);
507 sym = XSYMBOL (new_alias);
509 if (sym->constant)
510 /* Not sure why, but why not? */
511 error ("Cannot make a constant an alias");
513 switch (sym->redirect)
515 case SYMBOL_FORWARDED:
516 error ("Cannot make an internal variable an alias");
517 case SYMBOL_LOCALIZED:
518 error ("Don't know how to make a localized variable an alias");
521 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
522 If n_a is bound, but b_v is not, set the value of b_v to n_a,
523 so that old-code that affects n_a before the aliasing is setup
524 still works. */
525 if (NILP (Fboundp (base_variable)))
526 set_internal (base_variable, find_symbol_value (new_alias), Qnil, 1);
529 struct specbinding *p;
531 for (p = specpdl_ptr; p > specpdl; )
532 if ((--p)->func == NULL
533 && (EQ (new_alias,
534 CONSP (p->symbol) ? XCAR (p->symbol) : p->symbol)))
535 error ("Don't know how to make a let-bound variable an alias");
538 sym->declared_special = 1;
539 XSYMBOL (base_variable)->declared_special = 1;
540 sym->redirect = SYMBOL_VARALIAS;
541 SET_SYMBOL_ALIAS (sym, XSYMBOL (base_variable));
542 sym->constant = SYMBOL_CONSTANT_P (base_variable);
543 LOADHIST_ATTACH (new_alias);
544 /* Even if docstring is nil: remove old docstring. */
545 Fput (new_alias, Qvariable_documentation, docstring);
547 return base_variable;
551 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
552 doc: /* Define SYMBOL as a variable, and return SYMBOL.
553 You are not required to define a variable in order to use it, but
554 defining it lets you supply an initial value and documentation, which
555 can be referred to by the Emacs help facilities and other programming
556 tools. The `defvar' form also declares the variable as \"special\",
557 so that it is always dynamically bound even if `lexical-binding' is t.
559 The optional argument INITVALUE is evaluated, and used to set SYMBOL,
560 only if SYMBOL's value is void. If SYMBOL is buffer-local, its
561 default value is what is set; buffer-local values are not affected.
562 If INITVALUE is missing, SYMBOL's value is not set.
564 If SYMBOL has a local binding, then this form affects the local
565 binding. This is usually not what you want. Thus, if you need to
566 load a file defining variables, with this form or with `defconst' or
567 `defcustom', you should always load that file _outside_ any bindings
568 for these variables. \(`defconst' and `defcustom' behave similarly in
569 this respect.)
571 The optional argument DOCSTRING is a documentation string for the
572 variable.
574 To define a user option, use `defcustom' instead of `defvar'.
575 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
576 (Lisp_Object args)
578 register Lisp_Object sym, tem, tail;
580 sym = Fcar (args);
581 tail = Fcdr (args);
582 if (!NILP (Fcdr (Fcdr (tail))))
583 error ("Too many arguments");
585 tem = Fdefault_boundp (sym);
586 if (!NILP (tail))
588 /* Do it before evaluating the initial value, for self-references. */
589 XSYMBOL (sym)->declared_special = 1;
591 if (NILP (tem))
592 Fset_default (sym, eval_sub (Fcar (tail)));
593 else
594 { /* Check if there is really a global binding rather than just a let
595 binding that shadows the global unboundness of the var. */
596 struct specbinding *pdl = specpdl_ptr;
597 while (pdl > specpdl)
599 if (EQ ((--pdl)->symbol, sym) && !pdl->func
600 && EQ (pdl->old_value, Qunbound))
602 message_with_string
603 ("Warning: defvar ignored because %s is let-bound",
604 SYMBOL_NAME (sym), 1);
605 break;
609 tail = Fcdr (tail);
610 tem = Fcar (tail);
611 if (!NILP (tem))
613 if (!NILP (Vpurify_flag))
614 tem = Fpurecopy (tem);
615 Fput (sym, Qvariable_documentation, tem);
617 LOADHIST_ATTACH (sym);
619 else if (!NILP (Vinternal_interpreter_environment)
620 && !XSYMBOL (sym)->declared_special)
621 /* A simple (defvar foo) with lexical scoping does "nothing" except
622 declare that var to be dynamically scoped *locally* (i.e. within
623 the current file or let-block). */
624 Vinternal_interpreter_environment
625 = Fcons (sym, Vinternal_interpreter_environment);
626 else
628 /* Simple (defvar <var>) should not count as a definition at all.
629 It could get in the way of other definitions, and unloading this
630 package could try to make the variable unbound. */
633 return sym;
636 DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
637 doc: /* Define SYMBOL as a constant variable.
638 This declares that neither programs nor users should ever change the
639 value. This constancy is not actually enforced by Emacs Lisp, but
640 SYMBOL is marked as a special variable so that it is never lexically
641 bound.
643 The `defconst' form always sets the value of SYMBOL to the result of
644 evalling INITVALUE. If SYMBOL is buffer-local, its default value is
645 what is set; buffer-local values are not affected. If SYMBOL has a
646 local binding, then this form sets the local binding's value.
647 However, you should normally not make local bindings for variables
648 defined with this form.
650 The optional DOCSTRING specifies the variable's documentation string.
651 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
652 (Lisp_Object args)
654 register Lisp_Object sym, tem;
656 sym = Fcar (args);
657 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
658 error ("Too many arguments");
660 tem = eval_sub (Fcar (Fcdr (args)));
661 if (!NILP (Vpurify_flag))
662 tem = Fpurecopy (tem);
663 Fset_default (sym, tem);
664 XSYMBOL (sym)->declared_special = 1;
665 tem = Fcar (Fcdr (Fcdr (args)));
666 if (!NILP (tem))
668 if (!NILP (Vpurify_flag))
669 tem = Fpurecopy (tem);
670 Fput (sym, Qvariable_documentation, tem);
672 Fput (sym, Qrisky_local_variable, Qt);
673 LOADHIST_ATTACH (sym);
674 return sym;
677 /* Make SYMBOL lexically scoped. */
678 DEFUN ("internal-make-var-non-special", Fmake_var_non_special,
679 Smake_var_non_special, 1, 1, 0,
680 doc: /* Internal function. */)
681 (Lisp_Object symbol)
683 CHECK_SYMBOL (symbol);
684 XSYMBOL (symbol)->declared_special = 0;
685 return Qnil;
689 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
690 doc: /* Bind variables according to VARLIST then eval BODY.
691 The value of the last form in BODY is returned.
692 Each element of VARLIST is a symbol (which is bound to nil)
693 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
694 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
695 usage: (let* VARLIST BODY...) */)
696 (Lisp_Object args)
698 Lisp_Object varlist, var, val, elt, lexenv;
699 ptrdiff_t count = SPECPDL_INDEX ();
700 struct gcpro gcpro1, gcpro2, gcpro3;
702 GCPRO3 (args, elt, varlist);
704 lexenv = Vinternal_interpreter_environment;
706 varlist = Fcar (args);
707 while (CONSP (varlist))
709 QUIT;
711 elt = XCAR (varlist);
712 if (SYMBOLP (elt))
714 var = elt;
715 val = Qnil;
717 else if (! NILP (Fcdr (Fcdr (elt))))
718 signal_error ("`let' bindings can have only one value-form", elt);
719 else
721 var = Fcar (elt);
722 val = eval_sub (Fcar (Fcdr (elt)));
725 if (!NILP (lexenv) && SYMBOLP (var)
726 && !XSYMBOL (var)->declared_special
727 && NILP (Fmemq (var, Vinternal_interpreter_environment)))
728 /* Lexically bind VAR by adding it to the interpreter's binding
729 alist. */
731 Lisp_Object newenv
732 = Fcons (Fcons (var, val), Vinternal_interpreter_environment);
733 if (EQ (Vinternal_interpreter_environment, lexenv))
734 /* Save the old lexical environment on the specpdl stack,
735 but only for the first lexical binding, since we'll never
736 need to revert to one of the intermediate ones. */
737 specbind (Qinternal_interpreter_environment, newenv);
738 else
739 Vinternal_interpreter_environment = newenv;
741 else
742 specbind (var, val);
744 varlist = XCDR (varlist);
746 UNGCPRO;
747 val = Fprogn (Fcdr (args));
748 return unbind_to (count, val);
751 DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
752 doc: /* Bind variables according to VARLIST then eval BODY.
753 The value of the last form in BODY is returned.
754 Each element of VARLIST is a symbol (which is bound to nil)
755 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
756 All the VALUEFORMs are evalled before any symbols are bound.
757 usage: (let VARLIST BODY...) */)
758 (Lisp_Object args)
760 Lisp_Object *temps, tem, lexenv;
761 register Lisp_Object elt, varlist;
762 ptrdiff_t count = SPECPDL_INDEX ();
763 ptrdiff_t argnum;
764 struct gcpro gcpro1, gcpro2;
765 USE_SAFE_ALLOCA;
767 varlist = Fcar (args);
769 /* Make space to hold the values to give the bound variables. */
770 elt = Flength (varlist);
771 SAFE_ALLOCA_LISP (temps, XFASTINT (elt));
773 /* Compute the values and store them in `temps'. */
775 GCPRO2 (args, *temps);
776 gcpro2.nvars = 0;
778 for (argnum = 0; CONSP (varlist); varlist = XCDR (varlist))
780 QUIT;
781 elt = XCAR (varlist);
782 if (SYMBOLP (elt))
783 temps [argnum++] = Qnil;
784 else if (! NILP (Fcdr (Fcdr (elt))))
785 signal_error ("`let' bindings can have only one value-form", elt);
786 else
787 temps [argnum++] = eval_sub (Fcar (Fcdr (elt)));
788 gcpro2.nvars = argnum;
790 UNGCPRO;
792 lexenv = Vinternal_interpreter_environment;
794 varlist = Fcar (args);
795 for (argnum = 0; CONSP (varlist); varlist = XCDR (varlist))
797 Lisp_Object var;
799 elt = XCAR (varlist);
800 var = SYMBOLP (elt) ? elt : Fcar (elt);
801 tem = temps[argnum++];
803 if (!NILP (lexenv) && SYMBOLP (var)
804 && !XSYMBOL (var)->declared_special
805 && NILP (Fmemq (var, Vinternal_interpreter_environment)))
806 /* Lexically bind VAR by adding it to the lexenv alist. */
807 lexenv = Fcons (Fcons (var, tem), lexenv);
808 else
809 /* Dynamically bind VAR. */
810 specbind (var, tem);
813 if (!EQ (lexenv, Vinternal_interpreter_environment))
814 /* Instantiate a new lexical environment. */
815 specbind (Qinternal_interpreter_environment, lexenv);
817 elt = Fprogn (Fcdr (args));
818 SAFE_FREE ();
819 return unbind_to (count, elt);
822 DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
823 doc: /* If TEST yields non-nil, eval BODY... and repeat.
824 The order of execution is thus TEST, BODY, TEST, BODY and so on
825 until TEST returns nil.
826 usage: (while TEST BODY...) */)
827 (Lisp_Object args)
829 Lisp_Object test, body;
830 struct gcpro gcpro1, gcpro2;
832 GCPRO2 (test, body);
834 test = Fcar (args);
835 body = Fcdr (args);
836 while (!NILP (eval_sub (test)))
838 QUIT;
839 Fprogn (body);
842 UNGCPRO;
843 return Qnil;
846 DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
847 doc: /* Return result of expanding macros at top level of FORM.
848 If FORM is not a macro call, it is returned unchanged.
849 Otherwise, the macro is expanded and the expansion is considered
850 in place of FORM. When a non-macro-call results, it is returned.
852 The second optional arg ENVIRONMENT specifies an environment of macro
853 definitions to shadow the loaded ones for use in file byte-compilation. */)
854 (Lisp_Object form, Lisp_Object environment)
856 /* With cleanups from Hallvard Furuseth. */
857 register Lisp_Object expander, sym, def, tem;
859 while (1)
861 /* Come back here each time we expand a macro call,
862 in case it expands into another macro call. */
863 if (!CONSP (form))
864 break;
865 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
866 def = sym = XCAR (form);
867 tem = Qnil;
868 /* Trace symbols aliases to other symbols
869 until we get a symbol that is not an alias. */
870 while (SYMBOLP (def))
872 QUIT;
873 sym = def;
874 tem = Fassq (sym, environment);
875 if (NILP (tem))
877 def = XSYMBOL (sym)->function;
878 if (!NILP (def))
879 continue;
881 break;
883 /* Right now TEM is the result from SYM in ENVIRONMENT,
884 and if TEM is nil then DEF is SYM's function definition. */
885 if (NILP (tem))
887 /* SYM is not mentioned in ENVIRONMENT.
888 Look at its function definition. */
889 struct gcpro gcpro1;
890 GCPRO1 (form);
891 def = Fautoload_do_load (def, sym, Qmacro);
892 UNGCPRO;
893 if (!CONSP (def))
894 /* Not defined or definition not suitable. */
895 break;
896 if (!EQ (XCAR (def), Qmacro))
897 break;
898 else expander = XCDR (def);
900 else
902 expander = XCDR (tem);
903 if (NILP (expander))
904 break;
907 Lisp_Object newform = apply1 (expander, XCDR (form));
908 if (EQ (form, newform))
909 break;
910 else
911 form = newform;
914 return form;
917 DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
918 doc: /* Eval BODY allowing nonlocal exits using `throw'.
919 TAG is evalled to get the tag to use; it must not be nil.
921 Then the BODY is executed.
922 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
923 If no throw happens, `catch' returns the value of the last BODY form.
924 If a throw happens, it specifies the value to return from `catch'.
925 usage: (catch TAG BODY...) */)
926 (Lisp_Object args)
928 register Lisp_Object tag;
929 struct gcpro gcpro1;
931 GCPRO1 (args);
932 tag = eval_sub (Fcar (args));
933 UNGCPRO;
934 return internal_catch (tag, Fprogn, Fcdr (args));
937 /* Set up a catch, then call C function FUNC on argument ARG.
938 FUNC should return a Lisp_Object.
939 This is how catches are done from within C code. */
941 Lisp_Object
942 internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object arg)
944 /* This structure is made part of the chain `catchlist'. */
945 struct catchtag c;
947 /* Fill in the components of c, and put it on the list. */
948 c.next = catchlist;
949 c.tag = tag;
950 c.val = Qnil;
951 c.backlist = backtrace_list;
952 c.handlerlist = handlerlist;
953 c.lisp_eval_depth = lisp_eval_depth;
954 c.pdlcount = SPECPDL_INDEX ();
955 c.poll_suppress_count = poll_suppress_count;
956 c.interrupt_input_blocked = interrupt_input_blocked;
957 c.gcpro = gcprolist;
958 c.byte_stack = byte_stack_list;
959 catchlist = &c;
961 /* Call FUNC. */
962 if (! sys_setjmp (c.jmp))
963 c.val = (*func) (arg);
965 /* Throw works by a longjmp that comes right here. */
966 catchlist = c.next;
967 return c.val;
970 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
971 jump to that CATCH, returning VALUE as the value of that catch.
973 This is the guts of Fthrow and Fsignal; they differ only in the way
974 they choose the catch tag to throw to. A catch tag for a
975 condition-case form has a TAG of Qnil.
977 Before each catch is discarded, unbind all special bindings and
978 execute all unwind-protect clauses made above that catch. Unwind
979 the handler stack as we go, so that the proper handlers are in
980 effect for each unwind-protect clause we run. At the end, restore
981 some static info saved in CATCH, and longjmp to the location
982 specified there.
984 This is used for correct unwinding in Fthrow and Fsignal. */
986 static _Noreturn void
987 unwind_to_catch (struct catchtag *catch, Lisp_Object value)
989 bool last_time;
991 /* Save the value in the tag. */
992 catch->val = value;
994 /* Restore certain special C variables. */
995 set_poll_suppress_count (catch->poll_suppress_count);
996 unblock_input_to (catch->interrupt_input_blocked);
997 immediate_quit = 0;
1001 last_time = catchlist == catch;
1003 /* Unwind the specpdl stack, and then restore the proper set of
1004 handlers. */
1005 unbind_to (catchlist->pdlcount, Qnil);
1006 handlerlist = catchlist->handlerlist;
1007 catchlist = catchlist->next;
1009 while (! last_time);
1011 byte_stack_list = catch->byte_stack;
1012 gcprolist = catch->gcpro;
1013 #ifdef DEBUG_GCPRO
1014 gcpro_level = gcprolist ? gcprolist->level + 1 : 0;
1015 #endif
1016 backtrace_list = catch->backlist;
1017 lisp_eval_depth = catch->lisp_eval_depth;
1019 sys_longjmp (catch->jmp, 1);
1022 DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
1023 doc: /* Throw to the catch for TAG and return VALUE from it.
1024 Both TAG and VALUE are evalled. */)
1025 (register Lisp_Object tag, Lisp_Object value)
1027 register struct catchtag *c;
1029 if (!NILP (tag))
1030 for (c = catchlist; c; c = c->next)
1032 if (EQ (c->tag, tag))
1033 unwind_to_catch (c, value);
1035 xsignal2 (Qno_catch, tag, value);
1039 DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
1040 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
1041 If BODYFORM completes normally, its value is returned
1042 after executing the UNWINDFORMS.
1043 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1044 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1045 (Lisp_Object args)
1047 Lisp_Object val;
1048 ptrdiff_t count = SPECPDL_INDEX ();
1050 record_unwind_protect (Fprogn, Fcdr (args));
1051 val = eval_sub (Fcar (args));
1052 return unbind_to (count, val);
1055 DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
1056 doc: /* Regain control when an error is signaled.
1057 Executes BODYFORM and returns its value if no error happens.
1058 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1059 where the BODY is made of Lisp expressions.
1061 A handler is applicable to an error
1062 if CONDITION-NAME is one of the error's condition names.
1063 If an error happens, the first applicable handler is run.
1065 The car of a handler may be a list of condition names instead of a
1066 single condition name; then it handles all of them. If the special
1067 condition name `debug' is present in this list, it allows another
1068 condition in the list to run the debugger if `debug-on-error' and the
1069 other usual mechanisms says it should (otherwise, `condition-case'
1070 suppresses the debugger).
1072 When a handler handles an error, control returns to the `condition-case'
1073 and it executes the handler's BODY...
1074 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1075 \(If VAR is nil, the handler can't access that information.)
1076 Then the value of the last BODY form is returned from the `condition-case'
1077 expression.
1079 See also the function `signal' for more info.
1080 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1081 (Lisp_Object args)
1083 Lisp_Object var = Fcar (args);
1084 Lisp_Object bodyform = Fcar (Fcdr (args));
1085 Lisp_Object handlers = Fcdr (Fcdr (args));
1087 return internal_lisp_condition_case (var, bodyform, handlers);
1090 /* Like Fcondition_case, but the args are separate
1091 rather than passed in a list. Used by Fbyte_code. */
1093 Lisp_Object
1094 internal_lisp_condition_case (volatile Lisp_Object var, Lisp_Object bodyform,
1095 Lisp_Object handlers)
1097 Lisp_Object val;
1098 struct catchtag c;
1099 struct handler h;
1101 CHECK_SYMBOL (var);
1103 for (val = handlers; CONSP (val); val = XCDR (val))
1105 Lisp_Object tem;
1106 tem = XCAR (val);
1107 if (! (NILP (tem)
1108 || (CONSP (tem)
1109 && (SYMBOLP (XCAR (tem))
1110 || CONSP (XCAR (tem))))))
1111 error ("Invalid condition handler: %s",
1112 SDATA (Fprin1_to_string (tem, Qt)));
1115 c.tag = Qnil;
1116 c.val = Qnil;
1117 c.backlist = backtrace_list;
1118 c.handlerlist = handlerlist;
1119 c.lisp_eval_depth = lisp_eval_depth;
1120 c.pdlcount = SPECPDL_INDEX ();
1121 c.poll_suppress_count = poll_suppress_count;
1122 c.interrupt_input_blocked = interrupt_input_blocked;
1123 c.gcpro = gcprolist;
1124 c.byte_stack = byte_stack_list;
1125 if (sys_setjmp (c.jmp))
1127 if (!NILP (h.var))
1128 specbind (h.var, c.val);
1129 val = Fprogn (Fcdr (h.chosen_clause));
1131 /* Note that this just undoes the binding of h.var; whoever
1132 longjumped to us unwound the stack to c.pdlcount before
1133 throwing. */
1134 unbind_to (c.pdlcount, Qnil);
1135 return val;
1137 c.next = catchlist;
1138 catchlist = &c;
1140 h.var = var;
1141 h.handler = handlers;
1142 h.next = handlerlist;
1143 h.tag = &c;
1144 handlerlist = &h;
1146 val = eval_sub (bodyform);
1147 catchlist = c.next;
1148 handlerlist = h.next;
1149 return val;
1152 /* Call the function BFUN with no arguments, catching errors within it
1153 according to HANDLERS. If there is an error, call HFUN with
1154 one argument which is the data that describes the error:
1155 (SIGNALNAME . DATA)
1157 HANDLERS can be a list of conditions to catch.
1158 If HANDLERS is Qt, catch all errors.
1159 If HANDLERS is Qerror, catch all errors
1160 but allow the debugger to run if that is enabled. */
1162 Lisp_Object
1163 internal_condition_case (Lisp_Object (*bfun) (void), Lisp_Object handlers,
1164 Lisp_Object (*hfun) (Lisp_Object))
1166 Lisp_Object val;
1167 struct catchtag c;
1168 struct handler h;
1170 c.tag = Qnil;
1171 c.val = Qnil;
1172 c.backlist = backtrace_list;
1173 c.handlerlist = handlerlist;
1174 c.lisp_eval_depth = lisp_eval_depth;
1175 c.pdlcount = SPECPDL_INDEX ();
1176 c.poll_suppress_count = poll_suppress_count;
1177 c.interrupt_input_blocked = interrupt_input_blocked;
1178 c.gcpro = gcprolist;
1179 c.byte_stack = byte_stack_list;
1180 if (sys_setjmp (c.jmp))
1182 return (*hfun) (c.val);
1184 c.next = catchlist;
1185 catchlist = &c;
1186 h.handler = handlers;
1187 h.var = Qnil;
1188 h.next = handlerlist;
1189 h.tag = &c;
1190 handlerlist = &h;
1192 val = (*bfun) ();
1193 catchlist = c.next;
1194 handlerlist = h.next;
1195 return val;
1198 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1200 Lisp_Object
1201 internal_condition_case_1 (Lisp_Object (*bfun) (Lisp_Object), Lisp_Object arg,
1202 Lisp_Object handlers, Lisp_Object (*hfun) (Lisp_Object))
1204 Lisp_Object val;
1205 struct catchtag c;
1206 struct handler h;
1208 c.tag = Qnil;
1209 c.val = Qnil;
1210 c.backlist = backtrace_list;
1211 c.handlerlist = handlerlist;
1212 c.lisp_eval_depth = lisp_eval_depth;
1213 c.pdlcount = SPECPDL_INDEX ();
1214 c.poll_suppress_count = poll_suppress_count;
1215 c.interrupt_input_blocked = interrupt_input_blocked;
1216 c.gcpro = gcprolist;
1217 c.byte_stack = byte_stack_list;
1218 if (sys_setjmp (c.jmp))
1220 return (*hfun) (c.val);
1222 c.next = catchlist;
1223 catchlist = &c;
1224 h.handler = handlers;
1225 h.var = Qnil;
1226 h.next = handlerlist;
1227 h.tag = &c;
1228 handlerlist = &h;
1230 val = (*bfun) (arg);
1231 catchlist = c.next;
1232 handlerlist = h.next;
1233 return val;
1236 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1237 its arguments. */
1239 Lisp_Object
1240 internal_condition_case_2 (Lisp_Object (*bfun) (Lisp_Object, Lisp_Object),
1241 Lisp_Object arg1,
1242 Lisp_Object arg2,
1243 Lisp_Object handlers,
1244 Lisp_Object (*hfun) (Lisp_Object))
1246 Lisp_Object val;
1247 struct catchtag c;
1248 struct handler h;
1250 c.tag = Qnil;
1251 c.val = Qnil;
1252 c.backlist = backtrace_list;
1253 c.handlerlist = handlerlist;
1254 c.lisp_eval_depth = lisp_eval_depth;
1255 c.pdlcount = SPECPDL_INDEX ();
1256 c.poll_suppress_count = poll_suppress_count;
1257 c.interrupt_input_blocked = interrupt_input_blocked;
1258 c.gcpro = gcprolist;
1259 c.byte_stack = byte_stack_list;
1260 if (sys_setjmp (c.jmp))
1262 return (*hfun) (c.val);
1264 c.next = catchlist;
1265 catchlist = &c;
1266 h.handler = handlers;
1267 h.var = Qnil;
1268 h.next = handlerlist;
1269 h.tag = &c;
1270 handlerlist = &h;
1272 val = (*bfun) (arg1, arg2);
1273 catchlist = c.next;
1274 handlerlist = h.next;
1275 return val;
1278 /* Like internal_condition_case but call BFUN with NARGS as first,
1279 and ARGS as second argument. */
1281 Lisp_Object
1282 internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1283 ptrdiff_t nargs,
1284 Lisp_Object *args,
1285 Lisp_Object handlers,
1286 Lisp_Object (*hfun) (Lisp_Object err,
1287 ptrdiff_t nargs,
1288 Lisp_Object *args))
1290 Lisp_Object val;
1291 struct catchtag c;
1292 struct handler h;
1294 c.tag = Qnil;
1295 c.val = Qnil;
1296 c.backlist = backtrace_list;
1297 c.handlerlist = handlerlist;
1298 c.lisp_eval_depth = lisp_eval_depth;
1299 c.pdlcount = SPECPDL_INDEX ();
1300 c.poll_suppress_count = poll_suppress_count;
1301 c.interrupt_input_blocked = interrupt_input_blocked;
1302 c.gcpro = gcprolist;
1303 c.byte_stack = byte_stack_list;
1304 if (sys_setjmp (c.jmp))
1306 return (*hfun) (c.val, nargs, args);
1308 c.next = catchlist;
1309 catchlist = &c;
1310 h.handler = handlers;
1311 h.var = Qnil;
1312 h.next = handlerlist;
1313 h.tag = &c;
1314 handlerlist = &h;
1316 val = (*bfun) (nargs, args);
1317 catchlist = c.next;
1318 handlerlist = h.next;
1319 return val;
1323 static Lisp_Object find_handler_clause (Lisp_Object, Lisp_Object);
1324 static bool maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig,
1325 Lisp_Object data);
1327 void
1328 process_quit_flag (void)
1330 Lisp_Object flag = Vquit_flag;
1331 Vquit_flag = Qnil;
1332 if (EQ (flag, Qkill_emacs))
1333 Fkill_emacs (Qnil);
1334 if (EQ (Vthrow_on_input, flag))
1335 Fthrow (Vthrow_on_input, Qt);
1336 Fsignal (Qquit, Qnil);
1339 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
1340 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1341 This function does not return.
1343 An error symbol is a symbol with an `error-conditions' property
1344 that is a list of condition names.
1345 A handler for any of those names will get to handle this signal.
1346 The symbol `error' should normally be one of them.
1348 DATA should be a list. Its elements are printed as part of the error message.
1349 See Info anchor `(elisp)Definition of signal' for some details on how this
1350 error message is constructed.
1351 If the signal is handled, DATA is made available to the handler.
1352 See also the function `condition-case'. */)
1353 (Lisp_Object error_symbol, Lisp_Object data)
1355 /* When memory is full, ERROR-SYMBOL is nil,
1356 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1357 That is a special case--don't do this in other situations. */
1358 Lisp_Object conditions;
1359 Lisp_Object string;
1360 Lisp_Object real_error_symbol
1361 = (NILP (error_symbol) ? Fcar (data) : error_symbol);
1362 register Lisp_Object clause = Qnil;
1363 struct handler *h;
1364 struct backtrace *bp;
1366 immediate_quit = 0;
1367 abort_on_gc = 0;
1368 if (gc_in_progress || waiting_for_input)
1369 emacs_abort ();
1371 #if 0 /* rms: I don't know why this was here,
1372 but it is surely wrong for an error that is handled. */
1373 #ifdef HAVE_WINDOW_SYSTEM
1374 if (display_hourglass_p)
1375 cancel_hourglass ();
1376 #endif
1377 #endif
1379 /* This hook is used by edebug. */
1380 if (! NILP (Vsignal_hook_function)
1381 && ! NILP (error_symbol))
1383 /* Edebug takes care of restoring these variables when it exits. */
1384 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
1385 max_lisp_eval_depth = lisp_eval_depth + 20;
1387 if (SPECPDL_INDEX () + 40 > max_specpdl_size)
1388 max_specpdl_size = SPECPDL_INDEX () + 40;
1390 call2 (Vsignal_hook_function, error_symbol, data);
1393 conditions = Fget (real_error_symbol, Qerror_conditions);
1395 /* Remember from where signal was called. Skip over the frame for
1396 `signal' itself. If a frame for `error' follows, skip that,
1397 too. Don't do this when ERROR_SYMBOL is nil, because that
1398 is a memory-full error. */
1399 Vsignaling_function = Qnil;
1400 if (backtrace_list && !NILP (error_symbol))
1402 bp = backtrace_list->next;
1403 if (bp && EQ (bp->function, Qerror))
1404 bp = bp->next;
1405 if (bp)
1406 Vsignaling_function = bp->function;
1409 for (h = handlerlist; h; h = h->next)
1411 clause = find_handler_clause (h->handler, conditions);
1412 if (!NILP (clause))
1413 break;
1416 if (/* Don't run the debugger for a memory-full error.
1417 (There is no room in memory to do that!) */
1418 !NILP (error_symbol)
1419 && (!NILP (Vdebug_on_signal)
1420 /* If no handler is present now, try to run the debugger. */
1421 || NILP (clause)
1422 /* A `debug' symbol in the handler list disables the normal
1423 suppression of the debugger. */
1424 || (CONSP (clause) && CONSP (XCAR (clause))
1425 && !NILP (Fmemq (Qdebug, XCAR (clause))))
1426 /* Special handler that means "print a message and run debugger
1427 if requested". */
1428 || EQ (h->handler, Qerror)))
1430 bool debugger_called
1431 = maybe_call_debugger (conditions, error_symbol, data);
1432 /* We can't return values to code which signaled an error, but we
1433 can continue code which has signaled a quit. */
1434 if (debugger_called && EQ (real_error_symbol, Qquit))
1435 return Qnil;
1438 if (!NILP (clause))
1440 Lisp_Object unwind_data
1441 = (NILP (error_symbol) ? data : Fcons (error_symbol, data));
1443 h->chosen_clause = clause;
1444 unwind_to_catch (h->tag, unwind_data);
1446 else
1448 if (catchlist != 0)
1449 Fthrow (Qtop_level, Qt);
1452 if (! NILP (error_symbol))
1453 data = Fcons (error_symbol, data);
1455 string = Ferror_message_string (data);
1456 fatal ("%s", SDATA (string));
1459 /* Internal version of Fsignal that never returns.
1460 Used for anything but Qquit (which can return from Fsignal). */
1462 void
1463 xsignal (Lisp_Object error_symbol, Lisp_Object data)
1465 Fsignal (error_symbol, data);
1466 emacs_abort ();
1469 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1471 void
1472 xsignal0 (Lisp_Object error_symbol)
1474 xsignal (error_symbol, Qnil);
1477 void
1478 xsignal1 (Lisp_Object error_symbol, Lisp_Object arg)
1480 xsignal (error_symbol, list1 (arg));
1483 void
1484 xsignal2 (Lisp_Object error_symbol, Lisp_Object arg1, Lisp_Object arg2)
1486 xsignal (error_symbol, list2 (arg1, arg2));
1489 void
1490 xsignal3 (Lisp_Object error_symbol, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
1492 xsignal (error_symbol, list3 (arg1, arg2, arg3));
1495 /* Signal `error' with message S, and additional arg ARG.
1496 If ARG is not a genuine list, make it a one-element list. */
1498 void
1499 signal_error (const char *s, Lisp_Object arg)
1501 Lisp_Object tortoise, hare;
1503 hare = tortoise = arg;
1504 while (CONSP (hare))
1506 hare = XCDR (hare);
1507 if (!CONSP (hare))
1508 break;
1510 hare = XCDR (hare);
1511 tortoise = XCDR (tortoise);
1513 if (EQ (hare, tortoise))
1514 break;
1517 if (!NILP (hare))
1518 arg = Fcons (arg, Qnil); /* Make it a list. */
1520 xsignal (Qerror, Fcons (build_string (s), arg));
1524 /* Return true if LIST is a non-nil atom or
1525 a list containing one of CONDITIONS. */
1527 static bool
1528 wants_debugger (Lisp_Object list, Lisp_Object conditions)
1530 if (NILP (list))
1531 return 0;
1532 if (! CONSP (list))
1533 return 1;
1535 while (CONSP (conditions))
1537 Lisp_Object this, tail;
1538 this = XCAR (conditions);
1539 for (tail = list; CONSP (tail); tail = XCDR (tail))
1540 if (EQ (XCAR (tail), this))
1541 return 1;
1542 conditions = XCDR (conditions);
1544 return 0;
1547 /* Return true if an error with condition-symbols CONDITIONS,
1548 and described by SIGNAL-DATA, should skip the debugger
1549 according to debugger-ignored-errors. */
1551 static bool
1552 skip_debugger (Lisp_Object conditions, Lisp_Object data)
1554 Lisp_Object tail;
1555 bool first_string = 1;
1556 Lisp_Object error_message;
1558 error_message = Qnil;
1559 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
1561 if (STRINGP (XCAR (tail)))
1563 if (first_string)
1565 error_message = Ferror_message_string (data);
1566 first_string = 0;
1569 if (fast_string_match (XCAR (tail), error_message) >= 0)
1570 return 1;
1572 else
1574 Lisp_Object contail;
1576 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
1577 if (EQ (XCAR (tail), XCAR (contail)))
1578 return 1;
1582 return 0;
1585 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1586 SIG and DATA describe the signal. There are two ways to pass them:
1587 = SIG is the error symbol, and DATA is the rest of the data.
1588 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1589 This is for memory-full errors only. */
1590 static bool
1591 maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, Lisp_Object data)
1593 Lisp_Object combined_data;
1595 combined_data = Fcons (sig, data);
1597 if (
1598 /* Don't try to run the debugger with interrupts blocked.
1599 The editing loop would return anyway. */
1600 ! input_blocked_p ()
1601 && NILP (Vinhibit_debugger)
1602 /* Does user want to enter debugger for this kind of error? */
1603 && (EQ (sig, Qquit)
1604 ? debug_on_quit
1605 : wants_debugger (Vdebug_on_error, conditions))
1606 && ! skip_debugger (conditions, combined_data)
1607 /* RMS: What's this for? */
1608 && when_entered_debugger < num_nonmacro_input_events)
1610 call_debugger (Fcons (Qerror, Fcons (combined_data, Qnil)));
1611 return 1;
1614 return 0;
1617 static Lisp_Object
1618 find_handler_clause (Lisp_Object handlers, Lisp_Object conditions)
1620 register Lisp_Object h;
1622 /* t is used by handlers for all conditions, set up by C code. */
1623 if (EQ (handlers, Qt))
1624 return Qt;
1626 /* error is used similarly, but means print an error message
1627 and run the debugger if that is enabled. */
1628 if (EQ (handlers, Qerror))
1629 return Qt;
1631 for (h = handlers; CONSP (h); h = XCDR (h))
1633 Lisp_Object handler = XCAR (h);
1634 Lisp_Object condit, tem;
1636 if (!CONSP (handler))
1637 continue;
1638 condit = XCAR (handler);
1639 /* Handle a single condition name in handler HANDLER. */
1640 if (SYMBOLP (condit))
1642 tem = Fmemq (Fcar (handler), conditions);
1643 if (!NILP (tem))
1644 return handler;
1646 /* Handle a list of condition names in handler HANDLER. */
1647 else if (CONSP (condit))
1649 Lisp_Object tail;
1650 for (tail = condit; CONSP (tail); tail = XCDR (tail))
1652 tem = Fmemq (XCAR (tail), conditions);
1653 if (!NILP (tem))
1654 return handler;
1659 return Qnil;
1663 /* Dump an error message; called like vprintf. */
1664 void
1665 verror (const char *m, va_list ap)
1667 char buf[4000];
1668 ptrdiff_t size = sizeof buf;
1669 ptrdiff_t size_max = STRING_BYTES_BOUND + 1;
1670 char *buffer = buf;
1671 ptrdiff_t used;
1672 Lisp_Object string;
1674 used = evxprintf (&buffer, &size, buf, size_max, m, ap);
1675 string = make_string (buffer, used);
1676 if (buffer != buf)
1677 xfree (buffer);
1679 xsignal1 (Qerror, string);
1683 /* Dump an error message; called like printf. */
1685 /* VARARGS 1 */
1686 void
1687 error (const char *m, ...)
1689 va_list ap;
1690 va_start (ap, m);
1691 verror (m, ap);
1692 va_end (ap);
1695 DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
1696 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
1697 This means it contains a description for how to read arguments to give it.
1698 The value is nil for an invalid function or a symbol with no function
1699 definition.
1701 Interactively callable functions include strings and vectors (treated
1702 as keyboard macros), lambda-expressions that contain a top-level call
1703 to `interactive', autoload definitions made by `autoload' with non-nil
1704 fourth argument, and some of the built-in functions of Lisp.
1706 Also, a symbol satisfies `commandp' if its function definition does so.
1708 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1709 then strings and vectors are not accepted. */)
1710 (Lisp_Object function, Lisp_Object for_call_interactively)
1712 register Lisp_Object fun;
1713 register Lisp_Object funcar;
1714 Lisp_Object if_prop = Qnil;
1716 fun = function;
1718 fun = indirect_function (fun); /* Check cycles. */
1719 if (NILP (fun))
1720 return Qnil;
1722 /* Check an `interactive-form' property if present, analogous to the
1723 function-documentation property. */
1724 fun = function;
1725 while (SYMBOLP (fun))
1727 Lisp_Object tmp = Fget (fun, Qinteractive_form);
1728 if (!NILP (tmp))
1729 if_prop = Qt;
1730 fun = Fsymbol_function (fun);
1733 /* Emacs primitives are interactive if their DEFUN specifies an
1734 interactive spec. */
1735 if (SUBRP (fun))
1736 return XSUBR (fun)->intspec ? Qt : if_prop;
1738 /* Bytecode objects are interactive if they are long enough to
1739 have an element whose index is COMPILED_INTERACTIVE, which is
1740 where the interactive spec is stored. */
1741 else if (COMPILEDP (fun))
1742 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
1743 ? Qt : if_prop);
1745 /* Strings and vectors are keyboard macros. */
1746 if (STRINGP (fun) || VECTORP (fun))
1747 return (NILP (for_call_interactively) ? Qt : Qnil);
1749 /* Lists may represent commands. */
1750 if (!CONSP (fun))
1751 return Qnil;
1752 funcar = XCAR (fun);
1753 if (EQ (funcar, Qclosure))
1754 return (!NILP (Fassq (Qinteractive, Fcdr (Fcdr (XCDR (fun)))))
1755 ? Qt : if_prop);
1756 else if (EQ (funcar, Qlambda))
1757 return !NILP (Fassq (Qinteractive, Fcdr (XCDR (fun)))) ? Qt : if_prop;
1758 else if (EQ (funcar, Qautoload))
1759 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun))))) ? Qt : if_prop;
1760 else
1761 return Qnil;
1764 DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
1765 doc: /* Define FUNCTION to autoload from FILE.
1766 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1767 Third arg DOCSTRING is documentation for the function.
1768 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1769 Fifth arg TYPE indicates the type of the object:
1770 nil or omitted says FUNCTION is a function,
1771 `keymap' says FUNCTION is really a keymap, and
1772 `macro' or t says FUNCTION is really a macro.
1773 Third through fifth args give info about the real definition.
1774 They default to nil.
1775 If FUNCTION is already defined other than as an autoload,
1776 this does nothing and returns nil. */)
1777 (Lisp_Object function, Lisp_Object file, Lisp_Object docstring, Lisp_Object interactive, Lisp_Object type)
1779 CHECK_SYMBOL (function);
1780 CHECK_STRING (file);
1782 /* If function is defined and not as an autoload, don't override. */
1783 if (!NILP (XSYMBOL (function)->function)
1784 && !AUTOLOADP (XSYMBOL (function)->function))
1785 return Qnil;
1787 if (!NILP (Vpurify_flag) && EQ (docstring, make_number (0)))
1788 /* `read1' in lread.c has found the docstring starting with "\
1789 and assumed the docstring will be provided by Snarf-documentation, so it
1790 passed us 0 instead. But that leads to accidental sharing in purecopy's
1791 hash-consing, so we use a (hopefully) unique integer instead. */
1792 docstring = make_number (XHASH (function));
1793 return Fdefalias (function,
1794 list5 (Qautoload, file, docstring, interactive, type),
1795 Qnil);
1798 Lisp_Object
1799 un_autoload (Lisp_Object oldqueue)
1801 register Lisp_Object queue, first, second;
1803 /* Queue to unwind is current value of Vautoload_queue.
1804 oldqueue is the shadowed value to leave in Vautoload_queue. */
1805 queue = Vautoload_queue;
1806 Vautoload_queue = oldqueue;
1807 while (CONSP (queue))
1809 first = XCAR (queue);
1810 second = Fcdr (first);
1811 first = Fcar (first);
1812 if (EQ (first, make_number (0)))
1813 Vfeatures = second;
1814 else
1815 Ffset (first, second);
1816 queue = XCDR (queue);
1818 return Qnil;
1821 /* Load an autoloaded function.
1822 FUNNAME is the symbol which is the function's name.
1823 FUNDEF is the autoload definition (a list). */
1825 DEFUN ("autoload-do-load", Fautoload_do_load, Sautoload_do_load, 1, 3, 0,
1826 doc: /* Load FUNDEF which should be an autoload.
1827 If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1828 in which case the function returns the new autoloaded function value.
1829 If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1830 it is defines a macro. */)
1831 (Lisp_Object fundef, Lisp_Object funname, Lisp_Object macro_only)
1833 ptrdiff_t count = SPECPDL_INDEX ();
1834 struct gcpro gcpro1, gcpro2, gcpro3;
1836 if (!CONSP (fundef) || !EQ (Qautoload, XCAR (fundef)))
1837 return fundef;
1839 if (EQ (macro_only, Qmacro))
1841 Lisp_Object kind = Fnth (make_number (4), fundef);
1842 if (! (EQ (kind, Qt) || EQ (kind, Qmacro)))
1843 return fundef;
1846 /* This is to make sure that loadup.el gives a clear picture
1847 of what files are preloaded and when. */
1848 if (! NILP (Vpurify_flag))
1849 error ("Attempt to autoload %s while preparing to dump",
1850 SDATA (SYMBOL_NAME (funname)));
1852 CHECK_SYMBOL (funname);
1853 GCPRO3 (funname, fundef, macro_only);
1855 /* Preserve the match data. */
1856 record_unwind_save_match_data ();
1858 /* If autoloading gets an error (which includes the error of failing
1859 to define the function being called), we use Vautoload_queue
1860 to undo function definitions and `provide' calls made by
1861 the function. We do this in the specific case of autoloading
1862 because autoloading is not an explicit request "load this file",
1863 but rather a request to "call this function".
1865 The value saved here is to be restored into Vautoload_queue. */
1866 record_unwind_protect (un_autoload, Vautoload_queue);
1867 Vautoload_queue = Qt;
1868 /* If `macro_only', assume this autoload to be a "best-effort",
1869 so don't signal an error if autoloading fails. */
1870 Fload (Fcar (Fcdr (fundef)), macro_only, Qt, Qnil, Qt);
1872 /* Once loading finishes, don't undo it. */
1873 Vautoload_queue = Qt;
1874 unbind_to (count, Qnil);
1876 UNGCPRO;
1878 if (NILP (funname))
1879 return Qnil;
1880 else
1882 Lisp_Object fun = Findirect_function (funname, Qnil);
1884 if (!NILP (Fequal (fun, fundef)))
1885 error ("Autoloading failed to define function %s",
1886 SDATA (SYMBOL_NAME (funname)));
1887 else
1888 return fun;
1893 DEFUN ("eval", Feval, Seval, 1, 2, 0,
1894 doc: /* Evaluate FORM and return its value.
1895 If LEXICAL is t, evaluate using lexical scoping. */)
1896 (Lisp_Object form, Lisp_Object lexical)
1898 ptrdiff_t count = SPECPDL_INDEX ();
1899 specbind (Qinternal_interpreter_environment,
1900 NILP (lexical) ? Qnil : Fcons (Qt, Qnil));
1901 return unbind_to (count, eval_sub (form));
1904 /* Eval a sub-expression of the current expression (i.e. in the same
1905 lexical scope). */
1906 Lisp_Object
1907 eval_sub (Lisp_Object form)
1909 Lisp_Object fun, val, original_fun, original_args;
1910 Lisp_Object funcar;
1911 struct backtrace backtrace;
1912 struct gcpro gcpro1, gcpro2, gcpro3;
1914 if (SYMBOLP (form))
1916 /* Look up its binding in the lexical environment.
1917 We do not pay attention to the declared_special flag here, since we
1918 already did that when let-binding the variable. */
1919 Lisp_Object lex_binding
1920 = !NILP (Vinternal_interpreter_environment) /* Mere optimization! */
1921 ? Fassq (form, Vinternal_interpreter_environment)
1922 : Qnil;
1923 if (CONSP (lex_binding))
1924 return XCDR (lex_binding);
1925 else
1926 return Fsymbol_value (form);
1929 if (!CONSP (form))
1930 return form;
1932 QUIT;
1933 maybe_gc ();
1935 if (++lisp_eval_depth > max_lisp_eval_depth)
1937 if (max_lisp_eval_depth < 100)
1938 max_lisp_eval_depth = 100;
1939 if (lisp_eval_depth > max_lisp_eval_depth)
1940 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
1943 original_fun = XCAR (form);
1944 original_args = XCDR (form);
1946 backtrace.next = backtrace_list;
1947 backtrace.function = original_fun; /* This also protects them from gc. */
1948 backtrace.args = &original_args;
1949 backtrace.nargs = UNEVALLED;
1950 backtrace.debug_on_exit = 0;
1951 backtrace_list = &backtrace;
1953 if (debug_on_next_call)
1954 do_debug_on_call (Qt);
1956 /* At this point, only original_fun and original_args
1957 have values that will be used below. */
1958 retry:
1960 /* Optimize for no indirection. */
1961 fun = original_fun;
1962 if (SYMBOLP (fun) && !NILP (fun)
1963 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
1964 fun = indirect_function (fun);
1966 if (SUBRP (fun))
1968 Lisp_Object numargs;
1969 Lisp_Object argvals[8];
1970 Lisp_Object args_left;
1971 register int i, maxargs;
1973 args_left = original_args;
1974 numargs = Flength (args_left);
1976 check_cons_list ();
1978 if (XINT (numargs) < XSUBR (fun)->min_args
1979 || (XSUBR (fun)->max_args >= 0
1980 && XSUBR (fun)->max_args < XINT (numargs)))
1981 xsignal2 (Qwrong_number_of_arguments, original_fun, numargs);
1983 else if (XSUBR (fun)->max_args == UNEVALLED)
1984 val = (XSUBR (fun)->function.aUNEVALLED) (args_left);
1985 else if (XSUBR (fun)->max_args == MANY)
1987 /* Pass a vector of evaluated arguments. */
1988 Lisp_Object *vals;
1989 ptrdiff_t argnum = 0;
1990 USE_SAFE_ALLOCA;
1992 SAFE_ALLOCA_LISP (vals, XINT (numargs));
1994 GCPRO3 (args_left, fun, fun);
1995 gcpro3.var = vals;
1996 gcpro3.nvars = 0;
1998 while (!NILP (args_left))
2000 vals[argnum++] = eval_sub (Fcar (args_left));
2001 args_left = Fcdr (args_left);
2002 gcpro3.nvars = argnum;
2005 backtrace.args = vals;
2006 backtrace.nargs = XINT (numargs);
2008 val = (XSUBR (fun)->function.aMANY) (XINT (numargs), vals);
2009 UNGCPRO;
2010 SAFE_FREE ();
2012 else
2014 GCPRO3 (args_left, fun, fun);
2015 gcpro3.var = argvals;
2016 gcpro3.nvars = 0;
2018 maxargs = XSUBR (fun)->max_args;
2019 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
2021 argvals[i] = eval_sub (Fcar (args_left));
2022 gcpro3.nvars = ++i;
2025 UNGCPRO;
2027 backtrace.args = argvals;
2028 backtrace.nargs = XINT (numargs);
2030 switch (i)
2032 case 0:
2033 val = (XSUBR (fun)->function.a0 ());
2034 break;
2035 case 1:
2036 val = (XSUBR (fun)->function.a1 (argvals[0]));
2037 break;
2038 case 2:
2039 val = (XSUBR (fun)->function.a2 (argvals[0], argvals[1]));
2040 break;
2041 case 3:
2042 val = (XSUBR (fun)->function.a3
2043 (argvals[0], argvals[1], argvals[2]));
2044 break;
2045 case 4:
2046 val = (XSUBR (fun)->function.a4
2047 (argvals[0], argvals[1], argvals[2], argvals[3]));
2048 break;
2049 case 5:
2050 val = (XSUBR (fun)->function.a5
2051 (argvals[0], argvals[1], argvals[2], argvals[3],
2052 argvals[4]));
2053 break;
2054 case 6:
2055 val = (XSUBR (fun)->function.a6
2056 (argvals[0], argvals[1], argvals[2], argvals[3],
2057 argvals[4], argvals[5]));
2058 break;
2059 case 7:
2060 val = (XSUBR (fun)->function.a7
2061 (argvals[0], argvals[1], argvals[2], argvals[3],
2062 argvals[4], argvals[5], argvals[6]));
2063 break;
2065 case 8:
2066 val = (XSUBR (fun)->function.a8
2067 (argvals[0], argvals[1], argvals[2], argvals[3],
2068 argvals[4], argvals[5], argvals[6], argvals[7]));
2069 break;
2071 default:
2072 /* Someone has created a subr that takes more arguments than
2073 is supported by this code. We need to either rewrite the
2074 subr to use a different argument protocol, or add more
2075 cases to this switch. */
2076 emacs_abort ();
2080 else if (COMPILEDP (fun))
2081 val = apply_lambda (fun, original_args);
2082 else
2084 if (NILP (fun))
2085 xsignal1 (Qvoid_function, original_fun);
2086 if (!CONSP (fun))
2087 xsignal1 (Qinvalid_function, original_fun);
2088 funcar = XCAR (fun);
2089 if (!SYMBOLP (funcar))
2090 xsignal1 (Qinvalid_function, original_fun);
2091 if (EQ (funcar, Qautoload))
2093 Fautoload_do_load (fun, original_fun, Qnil);
2094 goto retry;
2096 if (EQ (funcar, Qmacro))
2098 ptrdiff_t count = SPECPDL_INDEX ();
2099 Lisp_Object exp;
2100 /* Bind lexical-binding during expansion of the macro, so the
2101 macro can know reliably if the code it outputs will be
2102 interpreted using lexical-binding or not. */
2103 specbind (Qlexical_binding,
2104 NILP (Vinternal_interpreter_environment) ? Qnil : Qt);
2105 exp = apply1 (Fcdr (fun), original_args);
2106 unbind_to (count, Qnil);
2107 val = eval_sub (exp);
2109 else if (EQ (funcar, Qlambda)
2110 || EQ (funcar, Qclosure))
2111 val = apply_lambda (fun, original_args);
2112 else
2113 xsignal1 (Qinvalid_function, original_fun);
2115 check_cons_list ();
2117 lisp_eval_depth--;
2118 if (backtrace.debug_on_exit)
2119 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2120 backtrace_list = backtrace.next;
2122 return val;
2125 DEFUN ("apply", Fapply, Sapply, 1, MANY, 0,
2126 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2127 Then return the value FUNCTION returns.
2128 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2129 usage: (apply FUNCTION &rest ARGUMENTS) */)
2130 (ptrdiff_t nargs, Lisp_Object *args)
2132 ptrdiff_t i;
2133 EMACS_INT numargs;
2134 register Lisp_Object spread_arg;
2135 register Lisp_Object *funcall_args;
2136 Lisp_Object fun, retval;
2137 struct gcpro gcpro1;
2138 USE_SAFE_ALLOCA;
2140 fun = args [0];
2141 funcall_args = 0;
2142 spread_arg = args [nargs - 1];
2143 CHECK_LIST (spread_arg);
2145 numargs = XINT (Flength (spread_arg));
2147 if (numargs == 0)
2148 return Ffuncall (nargs - 1, args);
2149 else if (numargs == 1)
2151 args [nargs - 1] = XCAR (spread_arg);
2152 return Ffuncall (nargs, args);
2155 numargs += nargs - 2;
2157 /* Optimize for no indirection. */
2158 if (SYMBOLP (fun) && !NILP (fun)
2159 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2160 fun = indirect_function (fun);
2161 if (NILP (fun))
2163 /* Let funcall get the error. */
2164 fun = args[0];
2165 goto funcall;
2168 if (SUBRP (fun))
2170 if (numargs < XSUBR (fun)->min_args
2171 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2172 goto funcall; /* Let funcall get the error. */
2173 else if (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args > numargs)
2175 /* Avoid making funcall cons up a yet another new vector of arguments
2176 by explicitly supplying nil's for optional values. */
2177 SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args);
2178 for (i = numargs; i < XSUBR (fun)->max_args;)
2179 funcall_args[++i] = Qnil;
2180 GCPRO1 (*funcall_args);
2181 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
2184 funcall:
2185 /* We add 1 to numargs because funcall_args includes the
2186 function itself as well as its arguments. */
2187 if (!funcall_args)
2189 SAFE_ALLOCA_LISP (funcall_args, 1 + numargs);
2190 GCPRO1 (*funcall_args);
2191 gcpro1.nvars = 1 + numargs;
2194 memcpy (funcall_args, args, nargs * word_size);
2195 /* Spread the last arg we got. Its first element goes in
2196 the slot that it used to occupy, hence this value of I. */
2197 i = nargs - 1;
2198 while (!NILP (spread_arg))
2200 funcall_args [i++] = XCAR (spread_arg);
2201 spread_arg = XCDR (spread_arg);
2204 /* By convention, the caller needs to gcpro Ffuncall's args. */
2205 retval = Ffuncall (gcpro1.nvars, funcall_args);
2206 UNGCPRO;
2207 SAFE_FREE ();
2209 return retval;
2212 /* Run hook variables in various ways. */
2214 static Lisp_Object
2215 funcall_nil (ptrdiff_t nargs, Lisp_Object *args)
2217 Ffuncall (nargs, args);
2218 return Qnil;
2221 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
2222 doc: /* Run each hook in HOOKS.
2223 Each argument should be a symbol, a hook variable.
2224 These symbols are processed in the order specified.
2225 If a hook symbol has a non-nil value, that value may be a function
2226 or a list of functions to be called to run the hook.
2227 If the value is a function, it is called with no arguments.
2228 If it is a list, the elements are called, in order, with no arguments.
2230 Major modes should not use this function directly to run their mode
2231 hook; they should use `run-mode-hooks' instead.
2233 Do not use `make-local-variable' to make a hook variable buffer-local.
2234 Instead, use `add-hook' and specify t for the LOCAL argument.
2235 usage: (run-hooks &rest HOOKS) */)
2236 (ptrdiff_t nargs, Lisp_Object *args)
2238 Lisp_Object hook[1];
2239 ptrdiff_t i;
2241 for (i = 0; i < nargs; i++)
2243 hook[0] = args[i];
2244 run_hook_with_args (1, hook, funcall_nil);
2247 return Qnil;
2250 DEFUN ("run-hook-with-args", Frun_hook_with_args,
2251 Srun_hook_with_args, 1, MANY, 0,
2252 doc: /* Run HOOK with the specified arguments ARGS.
2253 HOOK should be a symbol, a hook variable. The value of HOOK
2254 may be nil, a function, or a list of functions. Call each
2255 function in order with arguments ARGS. The final return value
2256 is unspecified.
2258 Do not use `make-local-variable' to make a hook variable buffer-local.
2259 Instead, use `add-hook' and specify t for the LOCAL argument.
2260 usage: (run-hook-with-args HOOK &rest ARGS) */)
2261 (ptrdiff_t nargs, Lisp_Object *args)
2263 return run_hook_with_args (nargs, args, funcall_nil);
2266 /* NB this one still documents a specific non-nil return value.
2267 (As did run-hook-with-args and run-hook-with-args-until-failure
2268 until they were changed in 24.1.) */
2269 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
2270 Srun_hook_with_args_until_success, 1, MANY, 0,
2271 doc: /* Run HOOK with the specified arguments ARGS.
2272 HOOK should be a symbol, a hook variable. The value of HOOK
2273 may be nil, a function, or a list of functions. Call each
2274 function in order with arguments ARGS, stopping at the first
2275 one that returns non-nil, and return that value. Otherwise (if
2276 all functions return nil, or if there are no functions to call),
2277 return nil.
2279 Do not use `make-local-variable' to make a hook variable buffer-local.
2280 Instead, use `add-hook' and specify t for the LOCAL argument.
2281 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2282 (ptrdiff_t nargs, Lisp_Object *args)
2284 return run_hook_with_args (nargs, args, Ffuncall);
2287 static Lisp_Object
2288 funcall_not (ptrdiff_t nargs, Lisp_Object *args)
2290 return NILP (Ffuncall (nargs, args)) ? Qt : Qnil;
2293 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
2294 Srun_hook_with_args_until_failure, 1, MANY, 0,
2295 doc: /* Run HOOK with the specified arguments ARGS.
2296 HOOK should be a symbol, a hook variable. The value of HOOK
2297 may be nil, a function, or a list of functions. Call each
2298 function in order with arguments ARGS, stopping at the first
2299 one that returns nil, and return nil. Otherwise (if all functions
2300 return non-nil, or if there are no functions to call), return non-nil
2301 \(do not rely on the precise return value in this case).
2303 Do not use `make-local-variable' to make a hook variable buffer-local.
2304 Instead, use `add-hook' and specify t for the LOCAL argument.
2305 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2306 (ptrdiff_t nargs, Lisp_Object *args)
2308 return NILP (run_hook_with_args (nargs, args, funcall_not)) ? Qt : Qnil;
2311 static Lisp_Object
2312 run_hook_wrapped_funcall (ptrdiff_t nargs, Lisp_Object *args)
2314 Lisp_Object tmp = args[0], ret;
2315 args[0] = args[1];
2316 args[1] = tmp;
2317 ret = Ffuncall (nargs, args);
2318 args[1] = args[0];
2319 args[0] = tmp;
2320 return ret;
2323 DEFUN ("run-hook-wrapped", Frun_hook_wrapped, Srun_hook_wrapped, 2, MANY, 0,
2324 doc: /* Run HOOK, passing each function through WRAP-FUNCTION.
2325 I.e. instead of calling each function FUN directly with arguments ARGS,
2326 it calls WRAP-FUNCTION with arguments FUN and ARGS.
2327 As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2328 aborts and returns that value.
2329 usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2330 (ptrdiff_t nargs, Lisp_Object *args)
2332 return run_hook_with_args (nargs, args, run_hook_wrapped_funcall);
2335 /* ARGS[0] should be a hook symbol.
2336 Call each of the functions in the hook value, passing each of them
2337 as arguments all the rest of ARGS (all NARGS - 1 elements).
2338 FUNCALL specifies how to call each function on the hook.
2339 The caller (or its caller, etc) must gcpro all of ARGS,
2340 except that it isn't necessary to gcpro ARGS[0]. */
2342 Lisp_Object
2343 run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2344 Lisp_Object (*funcall) (ptrdiff_t nargs, Lisp_Object *args))
2346 Lisp_Object sym, val, ret = Qnil;
2347 struct gcpro gcpro1, gcpro2, gcpro3;
2349 /* If we are dying or still initializing,
2350 don't do anything--it would probably crash if we tried. */
2351 if (NILP (Vrun_hooks))
2352 return Qnil;
2354 sym = args[0];
2355 val = find_symbol_value (sym);
2357 if (EQ (val, Qunbound) || NILP (val))
2358 return ret;
2359 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
2361 args[0] = val;
2362 return funcall (nargs, args);
2364 else
2366 Lisp_Object global_vals = Qnil;
2367 GCPRO3 (sym, val, global_vals);
2369 for (;
2370 CONSP (val) && NILP (ret);
2371 val = XCDR (val))
2373 if (EQ (XCAR (val), Qt))
2375 /* t indicates this hook has a local binding;
2376 it means to run the global binding too. */
2377 global_vals = Fdefault_value (sym);
2378 if (NILP (global_vals)) continue;
2380 if (!CONSP (global_vals) || EQ (XCAR (global_vals), Qlambda))
2382 args[0] = global_vals;
2383 ret = funcall (nargs, args);
2385 else
2387 for (;
2388 CONSP (global_vals) && NILP (ret);
2389 global_vals = XCDR (global_vals))
2391 args[0] = XCAR (global_vals);
2392 /* In a global value, t should not occur. If it does, we
2393 must ignore it to avoid an endless loop. */
2394 if (!EQ (args[0], Qt))
2395 ret = funcall (nargs, args);
2399 else
2401 args[0] = XCAR (val);
2402 ret = funcall (nargs, args);
2406 UNGCPRO;
2407 return ret;
2411 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2413 void
2414 run_hook_with_args_2 (Lisp_Object hook, Lisp_Object arg1, Lisp_Object arg2)
2416 Lisp_Object temp[3];
2417 temp[0] = hook;
2418 temp[1] = arg1;
2419 temp[2] = arg2;
2421 Frun_hook_with_args (3, temp);
2424 /* Apply fn to arg. */
2425 Lisp_Object
2426 apply1 (Lisp_Object fn, Lisp_Object arg)
2428 struct gcpro gcpro1;
2430 GCPRO1 (fn);
2431 if (NILP (arg))
2432 RETURN_UNGCPRO (Ffuncall (1, &fn));
2433 gcpro1.nvars = 2;
2435 Lisp_Object args[2];
2436 args[0] = fn;
2437 args[1] = arg;
2438 gcpro1.var = args;
2439 RETURN_UNGCPRO (Fapply (2, args));
2443 /* Call function fn on no arguments. */
2444 Lisp_Object
2445 call0 (Lisp_Object fn)
2447 struct gcpro gcpro1;
2449 GCPRO1 (fn);
2450 RETURN_UNGCPRO (Ffuncall (1, &fn));
2453 /* Call function fn with 1 argument arg1. */
2454 /* ARGSUSED */
2455 Lisp_Object
2456 call1 (Lisp_Object fn, Lisp_Object arg1)
2458 struct gcpro gcpro1;
2459 Lisp_Object args[2];
2461 args[0] = fn;
2462 args[1] = arg1;
2463 GCPRO1 (args[0]);
2464 gcpro1.nvars = 2;
2465 RETURN_UNGCPRO (Ffuncall (2, args));
2468 /* Call function fn with 2 arguments arg1, arg2. */
2469 /* ARGSUSED */
2470 Lisp_Object
2471 call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2)
2473 struct gcpro gcpro1;
2474 Lisp_Object args[3];
2475 args[0] = fn;
2476 args[1] = arg1;
2477 args[2] = arg2;
2478 GCPRO1 (args[0]);
2479 gcpro1.nvars = 3;
2480 RETURN_UNGCPRO (Ffuncall (3, args));
2483 /* Call function fn with 3 arguments arg1, arg2, arg3. */
2484 /* ARGSUSED */
2485 Lisp_Object
2486 call3 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
2488 struct gcpro gcpro1;
2489 Lisp_Object args[4];
2490 args[0] = fn;
2491 args[1] = arg1;
2492 args[2] = arg2;
2493 args[3] = arg3;
2494 GCPRO1 (args[0]);
2495 gcpro1.nvars = 4;
2496 RETURN_UNGCPRO (Ffuncall (4, args));
2499 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
2500 /* ARGSUSED */
2501 Lisp_Object
2502 call4 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2503 Lisp_Object arg4)
2505 struct gcpro gcpro1;
2506 Lisp_Object args[5];
2507 args[0] = fn;
2508 args[1] = arg1;
2509 args[2] = arg2;
2510 args[3] = arg3;
2511 args[4] = arg4;
2512 GCPRO1 (args[0]);
2513 gcpro1.nvars = 5;
2514 RETURN_UNGCPRO (Ffuncall (5, args));
2517 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
2518 /* ARGSUSED */
2519 Lisp_Object
2520 call5 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2521 Lisp_Object arg4, Lisp_Object arg5)
2523 struct gcpro gcpro1;
2524 Lisp_Object args[6];
2525 args[0] = fn;
2526 args[1] = arg1;
2527 args[2] = arg2;
2528 args[3] = arg3;
2529 args[4] = arg4;
2530 args[5] = arg5;
2531 GCPRO1 (args[0]);
2532 gcpro1.nvars = 6;
2533 RETURN_UNGCPRO (Ffuncall (6, args));
2536 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
2537 /* ARGSUSED */
2538 Lisp_Object
2539 call6 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2540 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6)
2542 struct gcpro gcpro1;
2543 Lisp_Object args[7];
2544 args[0] = fn;
2545 args[1] = arg1;
2546 args[2] = arg2;
2547 args[3] = arg3;
2548 args[4] = arg4;
2549 args[5] = arg5;
2550 args[6] = arg6;
2551 GCPRO1 (args[0]);
2552 gcpro1.nvars = 7;
2553 RETURN_UNGCPRO (Ffuncall (7, args));
2556 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
2557 /* ARGSUSED */
2558 Lisp_Object
2559 call7 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2560 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7)
2562 struct gcpro gcpro1;
2563 Lisp_Object args[8];
2564 args[0] = fn;
2565 args[1] = arg1;
2566 args[2] = arg2;
2567 args[3] = arg3;
2568 args[4] = arg4;
2569 args[5] = arg5;
2570 args[6] = arg6;
2571 args[7] = arg7;
2572 GCPRO1 (args[0]);
2573 gcpro1.nvars = 8;
2574 RETURN_UNGCPRO (Ffuncall (8, args));
2577 /* The caller should GCPRO all the elements of ARGS. */
2579 DEFUN ("functionp", Ffunctionp, Sfunctionp, 1, 1, 0,
2580 doc: /* Non-nil if OBJECT is a function. */)
2581 (Lisp_Object object)
2583 if (FUNCTIONP (object))
2584 return Qt;
2585 return Qnil;
2588 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2589 doc: /* Call first argument as a function, passing remaining arguments to it.
2590 Return the value that function returns.
2591 Thus, (funcall 'cons 'x 'y) returns (x . y).
2592 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2593 (ptrdiff_t nargs, Lisp_Object *args)
2595 Lisp_Object fun, original_fun;
2596 Lisp_Object funcar;
2597 ptrdiff_t numargs = nargs - 1;
2598 Lisp_Object lisp_numargs;
2599 Lisp_Object val;
2600 struct backtrace backtrace;
2601 register Lisp_Object *internal_args;
2602 ptrdiff_t i;
2604 QUIT;
2606 if (++lisp_eval_depth > max_lisp_eval_depth)
2608 if (max_lisp_eval_depth < 100)
2609 max_lisp_eval_depth = 100;
2610 if (lisp_eval_depth > max_lisp_eval_depth)
2611 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2614 backtrace.next = backtrace_list;
2615 backtrace.function = args[0];
2616 backtrace.args = &args[1]; /* This also GCPROs them. */
2617 backtrace.nargs = nargs - 1;
2618 backtrace.debug_on_exit = 0;
2619 backtrace_list = &backtrace;
2621 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2622 maybe_gc ();
2624 if (debug_on_next_call)
2625 do_debug_on_call (Qlambda);
2627 check_cons_list ();
2629 original_fun = args[0];
2631 retry:
2633 /* Optimize for no indirection. */
2634 fun = original_fun;
2635 if (SYMBOLP (fun) && !NILP (fun)
2636 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2637 fun = indirect_function (fun);
2639 if (SUBRP (fun))
2641 if (numargs < XSUBR (fun)->min_args
2642 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2644 XSETFASTINT (lisp_numargs, numargs);
2645 xsignal2 (Qwrong_number_of_arguments, original_fun, lisp_numargs);
2648 else if (XSUBR (fun)->max_args == UNEVALLED)
2649 xsignal1 (Qinvalid_function, original_fun);
2651 else if (XSUBR (fun)->max_args == MANY)
2652 val = (XSUBR (fun)->function.aMANY) (numargs, args + 1);
2653 else
2655 if (XSUBR (fun)->max_args > numargs)
2657 internal_args = alloca (XSUBR (fun)->max_args
2658 * sizeof *internal_args);
2659 memcpy (internal_args, args + 1, numargs * word_size);
2660 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2661 internal_args[i] = Qnil;
2663 else
2664 internal_args = args + 1;
2665 switch (XSUBR (fun)->max_args)
2667 case 0:
2668 val = (XSUBR (fun)->function.a0 ());
2669 break;
2670 case 1:
2671 val = (XSUBR (fun)->function.a1 (internal_args[0]));
2672 break;
2673 case 2:
2674 val = (XSUBR (fun)->function.a2
2675 (internal_args[0], internal_args[1]));
2676 break;
2677 case 3:
2678 val = (XSUBR (fun)->function.a3
2679 (internal_args[0], internal_args[1], internal_args[2]));
2680 break;
2681 case 4:
2682 val = (XSUBR (fun)->function.a4
2683 (internal_args[0], internal_args[1], internal_args[2],
2684 internal_args[3]));
2685 break;
2686 case 5:
2687 val = (XSUBR (fun)->function.a5
2688 (internal_args[0], internal_args[1], internal_args[2],
2689 internal_args[3], internal_args[4]));
2690 break;
2691 case 6:
2692 val = (XSUBR (fun)->function.a6
2693 (internal_args[0], internal_args[1], internal_args[2],
2694 internal_args[3], internal_args[4], internal_args[5]));
2695 break;
2696 case 7:
2697 val = (XSUBR (fun)->function.a7
2698 (internal_args[0], internal_args[1], internal_args[2],
2699 internal_args[3], internal_args[4], internal_args[5],
2700 internal_args[6]));
2701 break;
2703 case 8:
2704 val = (XSUBR (fun)->function.a8
2705 (internal_args[0], internal_args[1], internal_args[2],
2706 internal_args[3], internal_args[4], internal_args[5],
2707 internal_args[6], internal_args[7]));
2708 break;
2710 default:
2712 /* If a subr takes more than 8 arguments without using MANY
2713 or UNEVALLED, we need to extend this function to support it.
2714 Until this is done, there is no way to call the function. */
2715 emacs_abort ();
2719 else if (COMPILEDP (fun))
2720 val = funcall_lambda (fun, numargs, args + 1);
2721 else
2723 if (NILP (fun))
2724 xsignal1 (Qvoid_function, original_fun);
2725 if (!CONSP (fun))
2726 xsignal1 (Qinvalid_function, original_fun);
2727 funcar = XCAR (fun);
2728 if (!SYMBOLP (funcar))
2729 xsignal1 (Qinvalid_function, original_fun);
2730 if (EQ (funcar, Qlambda)
2731 || EQ (funcar, Qclosure))
2732 val = funcall_lambda (fun, numargs, args + 1);
2733 else if (EQ (funcar, Qautoload))
2735 Fautoload_do_load (fun, original_fun, Qnil);
2736 check_cons_list ();
2737 goto retry;
2739 else
2740 xsignal1 (Qinvalid_function, original_fun);
2742 check_cons_list ();
2743 lisp_eval_depth--;
2744 if (backtrace.debug_on_exit)
2745 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2746 backtrace_list = backtrace.next;
2747 return val;
2750 static Lisp_Object
2751 apply_lambda (Lisp_Object fun, Lisp_Object args)
2753 Lisp_Object args_left;
2754 ptrdiff_t i;
2755 EMACS_INT numargs;
2756 register Lisp_Object *arg_vector;
2757 struct gcpro gcpro1, gcpro2, gcpro3;
2758 register Lisp_Object tem;
2759 USE_SAFE_ALLOCA;
2761 numargs = XFASTINT (Flength (args));
2762 SAFE_ALLOCA_LISP (arg_vector, numargs);
2763 args_left = args;
2765 GCPRO3 (*arg_vector, args_left, fun);
2766 gcpro1.nvars = 0;
2768 for (i = 0; i < numargs; )
2770 tem = Fcar (args_left), args_left = Fcdr (args_left);
2771 tem = eval_sub (tem);
2772 arg_vector[i++] = tem;
2773 gcpro1.nvars = i;
2776 UNGCPRO;
2778 backtrace_list->args = arg_vector;
2779 backtrace_list->nargs = i;
2780 tem = funcall_lambda (fun, numargs, arg_vector);
2782 /* Do the debug-on-exit now, while arg_vector still exists. */
2783 if (backtrace_list->debug_on_exit)
2784 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
2785 /* Don't do it again when we return to eval. */
2786 backtrace_list->debug_on_exit = 0;
2787 SAFE_FREE ();
2788 return tem;
2791 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2792 and return the result of evaluation.
2793 FUN must be either a lambda-expression or a compiled-code object. */
2795 static Lisp_Object
2796 funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
2797 register Lisp_Object *arg_vector)
2799 Lisp_Object val, syms_left, next, lexenv;
2800 ptrdiff_t count = SPECPDL_INDEX ();
2801 ptrdiff_t i;
2802 bool optional, rest;
2804 if (CONSP (fun))
2806 if (EQ (XCAR (fun), Qclosure))
2808 fun = XCDR (fun); /* Drop `closure'. */
2809 lexenv = XCAR (fun);
2810 CHECK_LIST_CONS (fun, fun);
2812 else
2813 lexenv = Qnil;
2814 syms_left = XCDR (fun);
2815 if (CONSP (syms_left))
2816 syms_left = XCAR (syms_left);
2817 else
2818 xsignal1 (Qinvalid_function, fun);
2820 else if (COMPILEDP (fun))
2822 syms_left = AREF (fun, COMPILED_ARGLIST);
2823 if (INTEGERP (syms_left))
2824 /* A byte-code object with a non-nil `push args' slot means we
2825 shouldn't bind any arguments, instead just call the byte-code
2826 interpreter directly; it will push arguments as necessary.
2828 Byte-code objects with either a non-existent, or a nil value for
2829 the `push args' slot (the default), have dynamically-bound
2830 arguments, and use the argument-binding code below instead (as do
2831 all interpreted functions, even lexically bound ones). */
2833 /* If we have not actually read the bytecode string
2834 and constants vector yet, fetch them from the file. */
2835 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
2836 Ffetch_bytecode (fun);
2837 return exec_byte_code (AREF (fun, COMPILED_BYTECODE),
2838 AREF (fun, COMPILED_CONSTANTS),
2839 AREF (fun, COMPILED_STACK_DEPTH),
2840 syms_left,
2841 nargs, arg_vector);
2843 lexenv = Qnil;
2845 else
2846 emacs_abort ();
2848 i = optional = rest = 0;
2849 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
2851 QUIT;
2853 next = XCAR (syms_left);
2854 if (!SYMBOLP (next))
2855 xsignal1 (Qinvalid_function, fun);
2857 if (EQ (next, Qand_rest))
2858 rest = 1;
2859 else if (EQ (next, Qand_optional))
2860 optional = 1;
2861 else
2863 Lisp_Object arg;
2864 if (rest)
2866 arg = Flist (nargs - i, &arg_vector[i]);
2867 i = nargs;
2869 else if (i < nargs)
2870 arg = arg_vector[i++];
2871 else if (!optional)
2872 xsignal2 (Qwrong_number_of_arguments, fun, make_number (nargs));
2873 else
2874 arg = Qnil;
2876 /* Bind the argument. */
2877 if (!NILP (lexenv) && SYMBOLP (next))
2878 /* Lexically bind NEXT by adding it to the lexenv alist. */
2879 lexenv = Fcons (Fcons (next, arg), lexenv);
2880 else
2881 /* Dynamically bind NEXT. */
2882 specbind (next, arg);
2886 if (!NILP (syms_left))
2887 xsignal1 (Qinvalid_function, fun);
2888 else if (i < nargs)
2889 xsignal2 (Qwrong_number_of_arguments, fun, make_number (nargs));
2891 if (!EQ (lexenv, Vinternal_interpreter_environment))
2892 /* Instantiate a new lexical environment. */
2893 specbind (Qinternal_interpreter_environment, lexenv);
2895 if (CONSP (fun))
2896 val = Fprogn (XCDR (XCDR (fun)));
2897 else
2899 /* If we have not actually read the bytecode string
2900 and constants vector yet, fetch them from the file. */
2901 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
2902 Ffetch_bytecode (fun);
2903 val = exec_byte_code (AREF (fun, COMPILED_BYTECODE),
2904 AREF (fun, COMPILED_CONSTANTS),
2905 AREF (fun, COMPILED_STACK_DEPTH),
2906 Qnil, 0, 0);
2909 return unbind_to (count, val);
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 (Lisp_Object object)
2917 Lisp_Object tem;
2919 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
2921 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
2922 if (!CONSP (tem))
2924 tem = AREF (object, COMPILED_BYTECODE);
2925 if (CONSP (tem) && STRINGP (XCAR (tem)))
2926 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
2927 else
2928 error ("Invalid byte code");
2930 ASET (object, COMPILED_BYTECODE, XCAR (tem));
2931 ASET (object, COMPILED_CONSTANTS, XCDR (tem));
2933 return object;
2936 static void
2937 grow_specpdl (void)
2939 register ptrdiff_t count = SPECPDL_INDEX ();
2940 ptrdiff_t max_size = min (max_specpdl_size, PTRDIFF_MAX);
2941 if (max_size <= specpdl_size)
2943 if (max_specpdl_size < 400)
2944 max_size = max_specpdl_size = 400;
2945 if (max_size <= specpdl_size)
2946 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil);
2948 specpdl = xpalloc (specpdl, &specpdl_size, 1, max_size, sizeof *specpdl);
2949 specpdl_ptr = specpdl + count;
2952 /* `specpdl_ptr->symbol' is a field which describes which variable is
2953 let-bound, so it can be properly undone when we unbind_to.
2954 It can have the following two shapes:
2955 - SYMBOL : if it's a plain symbol, it means that we have let-bound
2956 a symbol that is not buffer-local (at least at the time
2957 the let binding started). Note also that it should not be
2958 aliased (i.e. when let-binding V1 that's aliased to V2, we want
2959 to record V2 here).
2960 - (SYMBOL WHERE . BUFFER) : this means that it is a let-binding for
2961 variable SYMBOL which can be buffer-local. WHERE tells us
2962 which buffer is affected (or nil if the let-binding affects the
2963 global value of the variable) and BUFFER tells us which buffer was
2964 current (i.e. if WHERE is non-nil, then BUFFER==WHERE, otherwise
2965 BUFFER did not yet have a buffer-local value). */
2967 void
2968 specbind (Lisp_Object symbol, Lisp_Object value)
2970 struct Lisp_Symbol *sym;
2972 CHECK_SYMBOL (symbol);
2973 sym = XSYMBOL (symbol);
2974 if (specpdl_ptr == specpdl + specpdl_size)
2975 grow_specpdl ();
2977 start:
2978 switch (sym->redirect)
2980 case SYMBOL_VARALIAS:
2981 sym = indirect_variable (sym); XSETSYMBOL (symbol, sym); goto start;
2982 case SYMBOL_PLAINVAL:
2983 /* The most common case is that of a non-constant symbol with a
2984 trivial value. Make that as fast as we can. */
2985 set_specpdl_symbol (symbol);
2986 set_specpdl_old_value (SYMBOL_VAL (sym));
2987 specpdl_ptr->func = NULL;
2988 ++specpdl_ptr;
2989 if (!sym->constant)
2990 SET_SYMBOL_VAL (sym, value);
2991 else
2992 set_internal (symbol, value, Qnil, 1);
2993 break;
2994 case SYMBOL_LOCALIZED:
2995 if (SYMBOL_BLV (sym)->frame_local)
2996 error ("Frame-local vars cannot be let-bound");
2997 case SYMBOL_FORWARDED:
2999 Lisp_Object ovalue = find_symbol_value (symbol);
3000 specpdl_ptr->func = 0;
3001 set_specpdl_old_value (ovalue);
3003 eassert (sym->redirect != SYMBOL_LOCALIZED
3004 || (EQ (SYMBOL_BLV (sym)->where,
3005 SYMBOL_BLV (sym)->frame_local ?
3006 Fselected_frame () : Fcurrent_buffer ())));
3008 if (sym->redirect == SYMBOL_LOCALIZED
3009 || BUFFER_OBJFWDP (SYMBOL_FWD (sym)))
3011 Lisp_Object where, cur_buf = Fcurrent_buffer ();
3013 /* For a local variable, record both the symbol and which
3014 buffer's or frame's value we are saving. */
3015 if (!NILP (Flocal_variable_p (symbol, Qnil)))
3017 eassert (sym->redirect != SYMBOL_LOCALIZED
3018 || (blv_found (SYMBOL_BLV (sym))
3019 && EQ (cur_buf, SYMBOL_BLV (sym)->where)));
3020 where = cur_buf;
3022 else if (sym->redirect == SYMBOL_LOCALIZED
3023 && blv_found (SYMBOL_BLV (sym)))
3024 where = SYMBOL_BLV (sym)->where;
3025 else
3026 where = Qnil;
3028 /* We're not using the `unused' slot in the specbinding
3029 structure because this would mean we have to do more
3030 work for simple variables. */
3031 /* FIXME: The third value `current_buffer' is only used in
3032 let_shadows_buffer_binding_p which is itself only used
3033 in set_internal for local_if_set. */
3034 eassert (NILP (where) || EQ (where, cur_buf));
3035 set_specpdl_symbol (Fcons (symbol, Fcons (where, cur_buf)));
3037 /* If SYMBOL is a per-buffer variable which doesn't have a
3038 buffer-local value here, make the `let' change the global
3039 value by changing the value of SYMBOL in all buffers not
3040 having their own value. This is consistent with what
3041 happens with other buffer-local variables. */
3042 if (NILP (where)
3043 && sym->redirect == SYMBOL_FORWARDED)
3045 eassert (BUFFER_OBJFWDP (SYMBOL_FWD (sym)));
3046 ++specpdl_ptr;
3047 Fset_default (symbol, value);
3048 return;
3051 else
3052 set_specpdl_symbol (symbol);
3054 specpdl_ptr++;
3055 set_internal (symbol, value, Qnil, 1);
3056 break;
3058 default: emacs_abort ();
3062 void
3063 record_unwind_protect (Lisp_Object (*function) (Lisp_Object), Lisp_Object arg)
3065 if (specpdl_ptr == specpdl + specpdl_size)
3066 grow_specpdl ();
3067 specpdl_ptr->func = function;
3068 set_specpdl_symbol (Qnil);
3069 set_specpdl_old_value (arg);
3070 specpdl_ptr++;
3073 Lisp_Object
3074 unbind_to (ptrdiff_t count, Lisp_Object value)
3076 Lisp_Object quitf = Vquit_flag;
3077 struct gcpro gcpro1, gcpro2;
3079 GCPRO2 (value, quitf);
3080 Vquit_flag = Qnil;
3082 while (specpdl_ptr != specpdl + count)
3084 /* Copy the binding, and decrement specpdl_ptr, before we do
3085 the work to unbind it. We decrement first
3086 so that an error in unbinding won't try to unbind
3087 the same entry again, and we copy the binding first
3088 in case more bindings are made during some of the code we run. */
3090 struct specbinding this_binding;
3091 this_binding = *--specpdl_ptr;
3093 if (this_binding.func != 0)
3094 (*this_binding.func) (this_binding.old_value);
3095 /* If the symbol is a list, it is really (SYMBOL WHERE
3096 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3097 frame. If WHERE is a buffer or frame, this indicates we
3098 bound a variable that had a buffer-local or frame-local
3099 binding. WHERE nil means that the variable had the default
3100 value when it was bound. CURRENT-BUFFER is the buffer that
3101 was current when the variable was bound. */
3102 else if (CONSP (this_binding.symbol))
3104 Lisp_Object symbol, where;
3106 symbol = XCAR (this_binding.symbol);
3107 where = XCAR (XCDR (this_binding.symbol));
3109 if (NILP (where))
3110 Fset_default (symbol, this_binding.old_value);
3111 /* If `where' is non-nil, reset the value in the appropriate
3112 local binding, but only if that binding still exists. */
3113 else if (BUFFERP (where)
3114 ? !NILP (Flocal_variable_p (symbol, where))
3115 : !NILP (Fassq (symbol, XFRAME (where)->param_alist)))
3116 set_internal (symbol, this_binding.old_value, where, 1);
3118 /* If variable has a trivial value (no forwarding), we can
3119 just set it. No need to check for constant symbols here,
3120 since that was already done by specbind. */
3121 else if (XSYMBOL (this_binding.symbol)->redirect == SYMBOL_PLAINVAL)
3122 SET_SYMBOL_VAL (XSYMBOL (this_binding.symbol),
3123 this_binding.old_value);
3124 else
3125 /* NOTE: we only ever come here if make_local_foo was used for
3126 the first time on this var within this let. */
3127 Fset_default (this_binding.symbol, this_binding.old_value);
3130 if (NILP (Vquit_flag) && !NILP (quitf))
3131 Vquit_flag = quitf;
3133 UNGCPRO;
3134 return value;
3137 DEFUN ("special-variable-p", Fspecial_variable_p, Sspecial_variable_p, 1, 1, 0,
3138 doc: /* Return non-nil if SYMBOL's global binding has been declared special.
3139 A special variable is one that will be bound dynamically, even in a
3140 context where binding is lexical by default. */)
3141 (Lisp_Object symbol)
3143 CHECK_SYMBOL (symbol);
3144 return XSYMBOL (symbol)->declared_special ? Qt : Qnil;
3148 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
3149 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3150 The debugger is entered when that frame exits, if the flag is non-nil. */)
3151 (Lisp_Object level, Lisp_Object flag)
3153 register struct backtrace *backlist = backtrace_list;
3154 register EMACS_INT i;
3156 CHECK_NUMBER (level);
3158 for (i = 0; backlist && i < XINT (level); i++)
3160 backlist = backlist->next;
3163 if (backlist)
3164 backlist->debug_on_exit = !NILP (flag);
3166 return flag;
3169 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
3170 doc: /* Print a trace of Lisp function calls currently active.
3171 Output stream used is value of `standard-output'. */)
3172 (void)
3174 register struct backtrace *backlist = backtrace_list;
3175 Lisp_Object tail;
3176 Lisp_Object tem;
3177 struct gcpro gcpro1;
3178 Lisp_Object old_print_level = Vprint_level;
3180 if (NILP (Vprint_level))
3181 XSETFASTINT (Vprint_level, 8);
3183 tail = Qnil;
3184 GCPRO1 (tail);
3186 while (backlist)
3188 write_string (backlist->debug_on_exit ? "* " : " ", 2);
3189 if (backlist->nargs == UNEVALLED)
3191 Fprin1 (Fcons (backlist->function, *backlist->args), Qnil);
3192 write_string ("\n", -1);
3194 else
3196 tem = backlist->function;
3197 Fprin1 (tem, Qnil); /* This can QUIT. */
3198 write_string ("(", -1);
3199 if (backlist->nargs == MANY)
3200 { /* FIXME: Can this happen? */
3201 bool later_arg = 0;
3202 for (tail = *backlist->args; !NILP (tail); tail = Fcdr (tail))
3204 if (later_arg)
3205 write_string (" ", -1);
3206 Fprin1 (Fcar (tail), Qnil);
3207 later_arg = 1;
3210 else
3212 ptrdiff_t i;
3213 for (i = 0; i < backlist->nargs; i++)
3215 if (i) write_string (" ", -1);
3216 Fprin1 (backlist->args[i], Qnil);
3219 write_string (")\n", -1);
3221 backlist = backlist->next;
3224 Vprint_level = old_print_level;
3225 UNGCPRO;
3226 return Qnil;
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 (Lisp_Object nframes)
3241 register struct backtrace *backlist = backtrace_list;
3242 register EMACS_INT i;
3243 Lisp_Object tem;
3245 CHECK_NATNUM (nframes);
3247 /* Find the frame requested. */
3248 for (i = 0; backlist && i < XFASTINT (nframes); i++)
3249 backlist = backlist->next;
3251 if (!backlist)
3252 return Qnil;
3253 if (backlist->nargs == UNEVALLED)
3254 return Fcons (Qnil, Fcons (backlist->function, *backlist->args));
3255 else
3257 if (backlist->nargs == MANY) /* FIXME: Can this happen? */
3258 tem = *backlist->args;
3259 else
3260 tem = Flist (backlist->nargs, backlist->args);
3262 return Fcons (Qt, Fcons (backlist->function, tem));
3267 #if BYTE_MARK_STACK
3268 void
3269 mark_backtrace (void)
3271 register struct backtrace *backlist;
3272 ptrdiff_t i;
3274 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3276 mark_object (backlist->function);
3278 if (backlist->nargs == UNEVALLED
3279 || backlist->nargs == MANY) /* FIXME: Can this happen? */
3280 i = 1;
3281 else
3282 i = backlist->nargs;
3283 while (i--)
3284 mark_object (backlist->args[i]);
3287 #endif
3289 void
3290 syms_of_eval (void)
3292 DEFVAR_INT ("max-specpdl-size", max_specpdl_size,
3293 doc: /* Limit on number of Lisp variable bindings and `unwind-protect's.
3294 If Lisp code tries to increase the total number past this amount,
3295 an error is signaled.
3296 You can safely use a value considerably larger than the default value,
3297 if that proves inconveniently small. However, if you increase it too far,
3298 Emacs could run out of memory trying to make the stack bigger. */);
3300 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth,
3301 doc: /* Limit on depth in `eval', `apply' and `funcall' before error.
3303 This limit serves to catch infinite recursions for you before they cause
3304 actual stack overflow in C, which would be fatal for Emacs.
3305 You can safely make it considerably larger than its default value,
3306 if that proves inconveniently small. However, if you increase it too far,
3307 Emacs could overflow the real C stack, and crash. */);
3309 DEFVAR_LISP ("quit-flag", Vquit_flag,
3310 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3311 If the value is t, that means do an ordinary quit.
3312 If the value equals `throw-on-input', that means quit by throwing
3313 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3314 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3315 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3316 Vquit_flag = Qnil;
3318 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit,
3319 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3320 Note that `quit-flag' will still be set by typing C-g,
3321 so a quit will be signaled as soon as `inhibit-quit' is nil.
3322 To prevent this happening, set `quit-flag' to nil
3323 before making `inhibit-quit' nil. */);
3324 Vinhibit_quit = Qnil;
3326 DEFSYM (Qinhibit_quit, "inhibit-quit");
3327 DEFSYM (Qautoload, "autoload");
3328 DEFSYM (Qinhibit_debugger, "inhibit-debugger");
3329 DEFSYM (Qmacro, "macro");
3330 DEFSYM (Qdeclare, "declare");
3332 /* Note that the process handling also uses Qexit, but we don't want
3333 to staticpro it twice, so we just do it here. */
3334 DEFSYM (Qexit, "exit");
3336 DEFSYM (Qinteractive, "interactive");
3337 DEFSYM (Qcommandp, "commandp");
3338 DEFSYM (Qand_rest, "&rest");
3339 DEFSYM (Qand_optional, "&optional");
3340 DEFSYM (Qclosure, "closure");
3341 DEFSYM (Qdebug, "debug");
3343 DEFVAR_LISP ("inhibit-debugger", Vinhibit_debugger,
3344 doc: /* Non-nil means never enter the debugger.
3345 Normally set while the debugger is already active, to avoid recursive
3346 invocations. */);
3347 Vinhibit_debugger = Qnil;
3349 DEFVAR_LISP ("debug-on-error", Vdebug_on_error,
3350 doc: /* Non-nil means enter debugger if an error is signaled.
3351 Does not apply to errors handled by `condition-case' or those
3352 matched by `debug-ignored-errors'.
3353 If the value is a list, an error only means to enter the debugger
3354 if one of its condition symbols appears in the list.
3355 When you evaluate an expression interactively, this variable
3356 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3357 The command `toggle-debug-on-error' toggles this.
3358 See also the variable `debug-on-quit' and `inhibit-debugger'. */);
3359 Vdebug_on_error = Qnil;
3361 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors,
3362 doc: /* List of errors for which the debugger should not be called.
3363 Each element may be a condition-name or a regexp that matches error messages.
3364 If any element applies to a given error, that error skips the debugger
3365 and just returns to top level.
3366 This overrides the variable `debug-on-error'.
3367 It does not apply to errors handled by `condition-case'. */);
3368 Vdebug_ignored_errors = Qnil;
3370 DEFVAR_BOOL ("debug-on-quit", debug_on_quit,
3371 doc: /* Non-nil means enter debugger if quit is signaled (C-g, for example).
3372 Does not apply if quit is handled by a `condition-case'. */);
3373 debug_on_quit = 0;
3375 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call,
3376 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3378 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue,
3379 doc: /* Non-nil means debugger may continue execution.
3380 This is nil when the debugger is called under circumstances where it
3381 might not be safe to continue. */);
3382 debugger_may_continue = 1;
3384 DEFVAR_LISP ("debugger", Vdebugger,
3385 doc: /* Function to call to invoke debugger.
3386 If due to frame exit, args are `exit' and the value being returned;
3387 this function's value will be returned instead of that.
3388 If due to error, args are `error' and a list of the args to `signal'.
3389 If due to `apply' or `funcall' entry, one arg, `lambda'.
3390 If due to `eval' entry, one arg, t. */);
3391 Vdebugger = Qnil;
3393 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function,
3394 doc: /* If non-nil, this is a function for `signal' to call.
3395 It receives the same arguments that `signal' was given.
3396 The Edebug package uses this to regain control. */);
3397 Vsignal_hook_function = Qnil;
3399 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal,
3400 doc: /* Non-nil means call the debugger regardless of condition handlers.
3401 Note that `debug-on-error', `debug-on-quit' and friends
3402 still determine whether to handle the particular condition. */);
3403 Vdebug_on_signal = Qnil;
3405 /* When lexical binding is being used,
3406 Vinternal_interpreter_environment is non-nil, and contains an alist
3407 of lexically-bound variable, or (t), indicating an empty
3408 environment. The lisp name of this variable would be
3409 `internal-interpreter-environment' if it weren't hidden.
3410 Every element of this list can be either a cons (VAR . VAL)
3411 specifying a lexical binding, or a single symbol VAR indicating
3412 that this variable should use dynamic scoping. */
3413 DEFSYM (Qinternal_interpreter_environment,
3414 "internal-interpreter-environment");
3415 DEFVAR_LISP ("internal-interpreter-environment",
3416 Vinternal_interpreter_environment,
3417 doc: /* If non-nil, the current lexical environment of the lisp interpreter.
3418 When lexical binding is not being used, this variable is nil.
3419 A value of `(t)' indicates an empty environment, otherwise it is an
3420 alist of active lexical bindings. */);
3421 Vinternal_interpreter_environment = Qnil;
3422 /* Don't export this variable to Elisp, so no one can mess with it
3423 (Just imagine if someone makes it buffer-local). */
3424 Funintern (Qinternal_interpreter_environment, Qnil);
3426 DEFSYM (Vrun_hooks, "run-hooks");
3428 staticpro (&Vautoload_queue);
3429 Vautoload_queue = Qnil;
3430 staticpro (&Vsignaling_function);
3431 Vsignaling_function = Qnil;
3433 inhibit_lisp_code = Qnil;
3435 defsubr (&Sor);
3436 defsubr (&Sand);
3437 defsubr (&Sif);
3438 defsubr (&Scond);
3439 defsubr (&Sprogn);
3440 defsubr (&Sprog1);
3441 defsubr (&Sprog2);
3442 defsubr (&Ssetq);
3443 defsubr (&Squote);
3444 defsubr (&Sfunction);
3445 defsubr (&Sdefvar);
3446 defsubr (&Sdefvaralias);
3447 defsubr (&Sdefconst);
3448 defsubr (&Smake_var_non_special);
3449 defsubr (&Slet);
3450 defsubr (&SletX);
3451 defsubr (&Swhile);
3452 defsubr (&Smacroexpand);
3453 defsubr (&Scatch);
3454 defsubr (&Sthrow);
3455 defsubr (&Sunwind_protect);
3456 defsubr (&Scondition_case);
3457 defsubr (&Ssignal);
3458 defsubr (&Scommandp);
3459 defsubr (&Sautoload);
3460 defsubr (&Sautoload_do_load);
3461 defsubr (&Seval);
3462 defsubr (&Sapply);
3463 defsubr (&Sfuncall);
3464 defsubr (&Srun_hooks);
3465 defsubr (&Srun_hook_with_args);
3466 defsubr (&Srun_hook_with_args_until_success);
3467 defsubr (&Srun_hook_with_args_until_failure);
3468 defsubr (&Srun_hook_wrapped);
3469 defsubr (&Sfetch_bytecode);
3470 defsubr (&Sbacktrace_debug);
3471 defsubr (&Sbacktrace);
3472 defsubr (&Sbacktrace_frame);
3473 defsubr (&Sspecial_variable_p);
3474 defsubr (&Sfunctionp);