(Fx_create_frame): Move unwind_create_frame setup down.
[emacs.git] / src / eval.c
blob30df5f8ea360950a9ba2c612721acfc34cc30cda
1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 #include <config.h>
24 #include "lisp.h"
25 #include "blockinput.h"
26 #include "commands.h"
27 #include "keyboard.h"
28 #include "dispextern.h"
29 #include <setjmp.h>
31 /* This definition is duplicated in alloc.c and keyboard.c */
32 /* Putting it in lisp.h makes cc bomb out! */
34 struct backtrace
36 struct backtrace *next;
37 Lisp_Object *function;
38 Lisp_Object *args; /* Points to vector of args. */
39 int nargs; /* Length of vector.
40 If nargs is UNEVALLED, args points to slot holding
41 list of unevalled args */
42 char evalargs;
43 /* Nonzero means call value of debugger when done with this operation. */
44 char debug_on_exit;
47 struct backtrace *backtrace_list;
49 /* This structure helps implement the `catch' and `throw' control
50 structure. A struct catchtag contains all the information needed
51 to restore the state of the interpreter after a non-local jump.
53 Handlers for error conditions (represented by `struct handler'
54 structures) just point to a catch tag to do the cleanup required
55 for their jumps.
57 catchtag structures are chained together in the C calling stack;
58 the `next' member points to the next outer catchtag.
60 A call like (throw TAG VAL) searches for a catchtag whose `tag'
61 member is TAG, and then unbinds to it. The `val' member is used to
62 hold VAL while the stack is unwound; `val' is returned as the value
63 of the catch form.
65 All the other members are concerned with restoring the interpreter
66 state. */
68 struct catchtag
70 Lisp_Object tag;
71 Lisp_Object val;
72 struct catchtag *next;
73 struct gcpro *gcpro;
74 jmp_buf jmp;
75 struct backtrace *backlist;
76 struct handler *handlerlist;
77 int lisp_eval_depth;
78 int pdlcount;
79 int poll_suppress_count;
80 int interrupt_input_blocked;
81 struct byte_stack *byte_stack;
84 struct catchtag *catchlist;
86 #ifdef DEBUG_GCPRO
87 /* Count levels of GCPRO to detect failure to UNGCPRO. */
88 int gcpro_level;
89 #endif
91 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
92 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag;
93 Lisp_Object Qand_rest, Qand_optional;
94 Lisp_Object Qdebug_on_error;
95 Lisp_Object Qdeclare;
97 /* This holds either the symbol `run-hooks' or nil.
98 It is nil at an early stage of startup, and when Emacs
99 is shutting down. */
101 Lisp_Object Vrun_hooks;
103 /* Non-nil means record all fset's and provide's, to be undone
104 if the file being autoloaded is not fully loaded.
105 They are recorded by being consed onto the front of Vautoload_queue:
106 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
108 Lisp_Object Vautoload_queue;
110 /* Current number of specbindings allocated in specpdl. */
112 int specpdl_size;
114 /* Pointer to beginning of specpdl. */
116 struct specbinding *specpdl;
118 /* Pointer to first unused element in specpdl. */
120 struct specbinding *specpdl_ptr;
122 /* Maximum size allowed for specpdl allocation */
124 EMACS_INT max_specpdl_size;
126 /* Depth in Lisp evaluations and function calls. */
128 int lisp_eval_depth;
130 /* Maximum allowed depth in Lisp evaluations and function calls. */
132 EMACS_INT max_lisp_eval_depth;
134 /* Nonzero means enter debugger before next function call */
136 int debug_on_next_call;
138 /* Non-zero means debugger may continue. This is zero when the
139 debugger is called during redisplay, where it might not be safe to
140 continue the interrupted redisplay. */
142 int debugger_may_continue;
144 /* List of conditions (non-nil atom means all) which cause a backtrace
145 if an error is handled by the command loop's error handler. */
147 Lisp_Object Vstack_trace_on_error;
149 /* List of conditions (non-nil atom means all) which enter the debugger
150 if an error is handled by the command loop's error handler. */
152 Lisp_Object Vdebug_on_error;
154 /* List of conditions and regexps specifying error messages which
155 do not enter the debugger even if Vdebug_on_error says they should. */
157 Lisp_Object Vdebug_ignored_errors;
159 /* Non-nil means call the debugger even if the error will be handled. */
161 Lisp_Object Vdebug_on_signal;
163 /* Hook for edebug to use. */
165 Lisp_Object Vsignal_hook_function;
167 /* Nonzero means enter debugger if a quit signal
168 is handled by the command loop's error handler. */
170 int debug_on_quit;
172 /* The value of num_nonmacro_input_events as of the last time we
173 started to enter the debugger. If we decide to enter the debugger
174 again when this is still equal to num_nonmacro_input_events, then we
175 know that the debugger itself has an error, and we should just
176 signal the error instead of entering an infinite loop of debugger
177 invocations. */
179 int when_entered_debugger;
181 Lisp_Object Vdebugger;
183 /* The function from which the last `signal' was called. Set in
184 Fsignal. */
186 Lisp_Object Vsignaling_function;
188 /* Set to non-zero while processing X events. Checked in Feval to
189 make sure the Lisp interpreter isn't called from a signal handler,
190 which is unsafe because the interpreter isn't reentrant. */
192 int handling_signal;
194 /* Function to process declarations in defmacro forms. */
196 Lisp_Object Vmacro_declaration_function;
198 extern Lisp_Object Qrisky_local_variable;
200 static Lisp_Object funcall_lambda P_ ((Lisp_Object, int, Lisp_Object*));
202 void
203 init_eval_once ()
205 specpdl_size = 50;
206 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
207 specpdl_ptr = specpdl;
208 /* Don't forget to update docs (lispref node "Local Variables"). */
209 max_specpdl_size = 1000;
210 max_lisp_eval_depth = 300;
212 Vrun_hooks = Qnil;
215 void
216 init_eval ()
218 specpdl_ptr = specpdl;
219 catchlist = 0;
220 handlerlist = 0;
221 backtrace_list = 0;
222 Vquit_flag = Qnil;
223 debug_on_next_call = 0;
224 lisp_eval_depth = 0;
225 #ifdef DEBUG_GCPRO
226 gcpro_level = 0;
227 #endif
228 /* This is less than the initial value of num_nonmacro_input_events. */
229 when_entered_debugger = -1;
232 /* unwind-protect function used by call_debugger. */
234 static Lisp_Object
235 restore_stack_limits (data)
236 Lisp_Object data;
238 max_specpdl_size = XINT (XCAR (data));
239 max_lisp_eval_depth = XINT (XCDR (data));
240 return Qnil;
243 /* Call the Lisp debugger, giving it argument ARG. */
245 Lisp_Object
246 call_debugger (arg)
247 Lisp_Object arg;
249 int debug_while_redisplaying;
250 int count = SPECPDL_INDEX ();
251 Lisp_Object val;
252 int old_max = max_specpdl_size;
254 /* Temporarily bump up the stack limits,
255 so the debugger won't run out of stack. */
257 max_specpdl_size += 1;
258 record_unwind_protect (restore_stack_limits,
259 Fcons (make_number (old_max),
260 make_number (max_lisp_eval_depth)));
261 max_specpdl_size = old_max;
263 if (lisp_eval_depth + 40 > max_lisp_eval_depth)
264 max_lisp_eval_depth = lisp_eval_depth + 40;
266 if (SPECPDL_INDEX () + 100 > max_specpdl_size)
267 max_specpdl_size = SPECPDL_INDEX () + 100;
269 #ifdef HAVE_X_WINDOWS
270 if (display_hourglass_p)
271 cancel_hourglass ();
272 #endif
274 debug_on_next_call = 0;
275 when_entered_debugger = num_nonmacro_input_events;
277 /* Resetting redisplaying_p to 0 makes sure that debug output is
278 displayed if the debugger is invoked during redisplay. */
279 debug_while_redisplaying = redisplaying_p;
280 redisplaying_p = 0;
281 specbind (intern ("debugger-may-continue"),
282 debug_while_redisplaying ? Qnil : Qt);
283 specbind (Qinhibit_redisplay, Qnil);
284 specbind (Qdebug_on_error, Qnil);
286 #if 0 /* Binding this prevents execution of Lisp code during
287 redisplay, which necessarily leads to display problems. */
288 specbind (Qinhibit_eval_during_redisplay, Qt);
289 #endif
291 val = apply1 (Vdebugger, arg);
293 /* Interrupting redisplay and resuming it later is not safe under
294 all circumstances. So, when the debugger returns, abort the
295 interrupted redisplay by going back to the top-level. */
296 if (debug_while_redisplaying)
297 Ftop_level ();
299 return unbind_to (count, val);
302 void
303 do_debug_on_call (code)
304 Lisp_Object code;
306 debug_on_next_call = 0;
307 backtrace_list->debug_on_exit = 1;
308 call_debugger (Fcons (code, Qnil));
311 /* NOTE!!! Every function that can call EVAL must protect its args
312 and temporaries from garbage collection while it needs them.
313 The definition of `For' shows what you have to do. */
315 DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
316 doc: /* Eval args until one of them yields non-nil, then return that value.
317 The remaining args are not evalled at all.
318 If all args return nil, return nil.
319 usage: (or CONDITIONS ...) */)
320 (args)
321 Lisp_Object args;
323 register Lisp_Object val = Qnil;
324 struct gcpro gcpro1;
326 GCPRO1 (args);
328 while (CONSP (args))
330 val = Feval (XCAR (args));
331 if (!NILP (val))
332 break;
333 args = XCDR (args);
336 UNGCPRO;
337 return val;
340 DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
341 doc: /* Eval args until one of them yields nil, then return nil.
342 The remaining args are not evalled at all.
343 If no arg yields nil, return the last arg's value.
344 usage: (and CONDITIONS ...) */)
345 (args)
346 Lisp_Object args;
348 register Lisp_Object val = Qt;
349 struct gcpro gcpro1;
351 GCPRO1 (args);
353 while (CONSP (args))
355 val = Feval (XCAR (args));
356 if (NILP (val))
357 break;
358 args = XCDR (args);
361 UNGCPRO;
362 return val;
365 DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
366 doc: /* If COND yields non-nil, do THEN, else do ELSE...
367 Returns the value of THEN or the value of the last of the ELSE's.
368 THEN must be one expression, but ELSE... can be zero or more expressions.
369 If COND yields nil, and there are no ELSE's, the value is nil.
370 usage: (if COND THEN ELSE...) */)
371 (args)
372 Lisp_Object args;
374 register Lisp_Object cond;
375 struct gcpro gcpro1;
377 GCPRO1 (args);
378 cond = Feval (Fcar (args));
379 UNGCPRO;
381 if (!NILP (cond))
382 return Feval (Fcar (Fcdr (args)));
383 return Fprogn (Fcdr (Fcdr (args)));
386 DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
387 doc: /* Try each clause until one succeeds.
388 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
389 and, if the value is non-nil, this clause succeeds:
390 then the expressions in BODY are evaluated and the last one's
391 value is the value of the cond-form.
392 If no clause succeeds, cond returns nil.
393 If a clause has one element, as in (CONDITION),
394 CONDITION's value if non-nil is returned from the cond-form.
395 usage: (cond CLAUSES...) */)
396 (args)
397 Lisp_Object args;
399 register Lisp_Object clause, val;
400 struct gcpro gcpro1;
402 val = Qnil;
403 GCPRO1 (args);
404 while (!NILP (args))
406 clause = Fcar (args);
407 val = Feval (Fcar (clause));
408 if (!NILP (val))
410 if (!EQ (XCDR (clause), Qnil))
411 val = Fprogn (XCDR (clause));
412 break;
414 args = XCDR (args);
416 UNGCPRO;
418 return val;
421 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
422 doc: /* Eval BODY forms sequentially and return value of last one.
423 usage: (progn BODY ...) */)
424 (args)
425 Lisp_Object args;
427 register Lisp_Object val = Qnil;
428 struct gcpro gcpro1;
430 GCPRO1 (args);
432 while (CONSP (args))
434 val = Feval (XCAR (args));
435 args = XCDR (args);
438 UNGCPRO;
439 return val;
442 DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
443 doc: /* Eval FIRST and BODY sequentially; value from FIRST.
444 The value of FIRST is saved during the evaluation of the remaining args,
445 whose values are discarded.
446 usage: (prog1 FIRST BODY...) */)
447 (args)
448 Lisp_Object args;
450 Lisp_Object val;
451 register Lisp_Object args_left;
452 struct gcpro gcpro1, gcpro2;
453 register int argnum = 0;
455 if (NILP(args))
456 return Qnil;
458 args_left = args;
459 val = Qnil;
460 GCPRO2 (args, val);
464 if (!(argnum++))
465 val = Feval (Fcar (args_left));
466 else
467 Feval (Fcar (args_left));
468 args_left = Fcdr (args_left);
470 while (!NILP(args_left));
472 UNGCPRO;
473 return val;
476 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
477 doc: /* Eval FORM1, FORM2 and BODY sequentially; value from FORM2.
478 The value of FORM2 is saved during the evaluation of the
479 remaining args, whose values are discarded.
480 usage: (prog2 FORM1 FORM2 BODY...) */)
481 (args)
482 Lisp_Object args;
484 Lisp_Object val;
485 register Lisp_Object args_left;
486 struct gcpro gcpro1, gcpro2;
487 register int argnum = -1;
489 val = Qnil;
491 if (NILP (args))
492 return Qnil;
494 args_left = args;
495 val = Qnil;
496 GCPRO2 (args, val);
500 if (!(argnum++))
501 val = Feval (Fcar (args_left));
502 else
503 Feval (Fcar (args_left));
504 args_left = Fcdr (args_left);
506 while (!NILP (args_left));
508 UNGCPRO;
509 return val;
512 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
513 doc: /* Set each SYM to the value of its VAL.
514 The symbols SYM are variables; they are literal (not evaluated).
515 The values VAL are expressions; they are evaluated.
516 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
517 The second VAL is not computed until after the first SYM is set, and so on;
518 each VAL can use the new value of variables set earlier in the `setq'.
519 The return value of the `setq' form is the value of the last VAL.
520 usage: (setq SYM VAL SYM VAL ...) */)
521 (args)
522 Lisp_Object args;
524 register Lisp_Object args_left;
525 register Lisp_Object val, sym;
526 struct gcpro gcpro1;
528 if (NILP(args))
529 return Qnil;
531 args_left = args;
532 GCPRO1 (args);
536 val = Feval (Fcar (Fcdr (args_left)));
537 sym = Fcar (args_left);
538 Fset (sym, val);
539 args_left = Fcdr (Fcdr (args_left));
541 while (!NILP(args_left));
543 UNGCPRO;
544 return val;
547 DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
548 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
549 usage: (quote ARG) */)
550 (args)
551 Lisp_Object args;
553 return Fcar (args);
556 DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
557 doc: /* Like `quote', but preferred for objects which are functions.
558 In byte compilation, `function' causes its argument to be compiled.
559 `quote' cannot do that.
560 usage: (function ARG) */)
561 (args)
562 Lisp_Object args;
564 return Fcar (args);
568 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
569 doc: /* Return t if the function was run directly by user input.
570 This means that the function was called with `call-interactively'
571 \(which includes being called as the binding of a key)
572 and input is currently coming from the keyboard (not in keyboard macro),
573 and Emacs is not running in batch mode (`noninteractive' is nil).
575 The only known proper use of `interactive-p' is in deciding whether to
576 display a helpful message, or how to display it. If you're thinking
577 of using it for any other purpose, it is quite likely that you're
578 making a mistake. Think: what do you want to do when the command is
579 called from a keyboard macro?
581 If you want to test whether your function was called with
582 `call-interactively', the way to do that is by adding an extra
583 optional argument, and making the `interactive' spec specify non-nil
584 unconditionally for that argument. (`p' is a good way to do this.) */)
587 return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil;
591 DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 0, 0,
592 doc: /* Return t if the function using this was called with `call-interactively'.
593 This is used for implementing advice and other function-modifying
594 features of Emacs.
596 The cleanest way to test whether your function was called with
597 `call-interactively' is by adding an extra optional argument,
598 and making the `interactive' spec specify non-nil unconditionally
599 for that argument. (`p' is a good way to do this.) */)
602 return interactive_p (1) ? Qt : Qnil;
606 /* Return 1 if function in which this appears was called using
607 call-interactively.
609 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
610 called is a built-in. */
613 interactive_p (exclude_subrs_p)
614 int exclude_subrs_p;
616 struct backtrace *btp;
617 Lisp_Object fun;
619 btp = backtrace_list;
621 /* If this isn't a byte-compiled function, there may be a frame at
622 the top for Finteractive_p. If so, skip it. */
623 fun = Findirect_function (*btp->function, Qnil);
624 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
625 || XSUBR (fun) == &Scalled_interactively_p))
626 btp = btp->next;
628 /* If we're running an Emacs 18-style byte-compiled function, there
629 may be a frame for Fbytecode at the top level. In any version of
630 Emacs there can be Fbytecode frames for subexpressions evaluated
631 inside catch and condition-case. Skip past them.
633 If this isn't a byte-compiled function, then we may now be
634 looking at several frames for special forms. Skip past them. */
635 while (btp
636 && (EQ (*btp->function, Qbytecode)
637 || btp->nargs == UNEVALLED))
638 btp = btp->next;
640 /* btp now points at the frame of the innermost function that isn't
641 a special form, ignoring frames for Finteractive_p and/or
642 Fbytecode at the top. If this frame is for a built-in function
643 (such as load or eval-region) return nil. */
644 fun = Findirect_function (*btp->function, Qnil);
645 if (exclude_subrs_p && SUBRP (fun))
646 return 0;
648 /* btp points to the frame of a Lisp function that called interactive-p.
649 Return t if that function was called interactively. */
650 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
651 return 1;
652 return 0;
656 DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
657 doc: /* Define NAME as a function.
658 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
659 See also the function `interactive'.
660 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
661 (args)
662 Lisp_Object args;
664 register Lisp_Object fn_name;
665 register Lisp_Object defn;
667 fn_name = Fcar (args);
668 CHECK_SYMBOL (fn_name);
669 defn = Fcons (Qlambda, Fcdr (args));
670 if (!NILP (Vpurify_flag))
671 defn = Fpurecopy (defn);
672 if (CONSP (XSYMBOL (fn_name)->function)
673 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
674 LOADHIST_ATTACH (Fcons (Qt, fn_name));
675 Ffset (fn_name, defn);
676 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
677 return fn_name;
680 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
681 doc: /* Define NAME as a macro.
682 The actual definition looks like
683 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
684 When the macro is called, as in (NAME ARGS...),
685 the function (lambda ARGLIST BODY...) is applied to
686 the list ARGS... as it appears in the expression,
687 and the result should be a form to be evaluated instead of the original.
689 DECL is a declaration, optional, which can specify how to indent
690 calls to this macro and how Edebug should handle it. It looks like this:
691 (declare SPECS...)
692 The elements can look like this:
693 (indent INDENT)
694 Set NAME's `lisp-indent-function' property to INDENT.
696 (debug DEBUG)
697 Set NAME's `edebug-form-spec' property to DEBUG. (This is
698 equivalent to writing a `def-edebug-spec' for the macro.)
699 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
700 (args)
701 Lisp_Object args;
703 register Lisp_Object fn_name;
704 register Lisp_Object defn;
705 Lisp_Object lambda_list, doc, tail;
707 fn_name = Fcar (args);
708 CHECK_SYMBOL (fn_name);
709 lambda_list = Fcar (Fcdr (args));
710 tail = Fcdr (Fcdr (args));
712 doc = Qnil;
713 if (STRINGP (Fcar (tail)))
715 doc = XCAR (tail);
716 tail = XCDR (tail);
719 while (CONSP (Fcar (tail))
720 && EQ (Fcar (Fcar (tail)), Qdeclare))
722 if (!NILP (Vmacro_declaration_function))
724 struct gcpro gcpro1;
725 GCPRO1 (args);
726 call2 (Vmacro_declaration_function, fn_name, Fcar (tail));
727 UNGCPRO;
730 tail = Fcdr (tail);
733 if (NILP (doc))
734 tail = Fcons (lambda_list, tail);
735 else
736 tail = Fcons (lambda_list, Fcons (doc, tail));
737 defn = Fcons (Qmacro, Fcons (Qlambda, tail));
739 if (!NILP (Vpurify_flag))
740 defn = Fpurecopy (defn);
741 if (CONSP (XSYMBOL (fn_name)->function)
742 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
743 LOADHIST_ATTACH (Fcons (Qt, fn_name));
744 Ffset (fn_name, defn);
745 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
746 return fn_name;
750 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
751 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
752 Aliased variables always have the same value; setting one sets the other.
753 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
754 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
755 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
756 itself an alias.
757 The return value is BASE-VARIABLE. */)
758 (new_alias, base_variable, docstring)
759 Lisp_Object new_alias, base_variable, docstring;
761 struct Lisp_Symbol *sym;
763 CHECK_SYMBOL (new_alias);
764 CHECK_SYMBOL (base_variable);
766 if (SYMBOL_CONSTANT_P (new_alias))
767 error ("Cannot make a constant an alias");
769 sym = XSYMBOL (new_alias);
770 sym->indirect_variable = 1;
771 sym->value = base_variable;
772 sym->constant = SYMBOL_CONSTANT_P (base_variable);
773 LOADHIST_ATTACH (new_alias);
774 if (!NILP (docstring))
775 Fput (new_alias, Qvariable_documentation, docstring);
776 else
777 Fput (new_alias, Qvariable_documentation, Qnil);
779 return base_variable;
783 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
784 doc: /* Define SYMBOL as a variable, and return SYMBOL.
785 You are not required to define a variable in order to use it,
786 but the definition can supply documentation and an initial value
787 in a way that tags can recognize.
789 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
790 If SYMBOL is buffer-local, its default value is what is set;
791 buffer-local values are not affected.
792 INITVALUE and DOCSTRING are optional.
793 If DOCSTRING starts with *, this variable is identified as a user option.
794 This means that M-x set-variable recognizes it.
795 See also `user-variable-p'.
796 If INITVALUE is missing, SYMBOL's value is not set.
798 If SYMBOL has a local binding, then this form affects the local
799 binding. This is usually not what you want. Thus, if you need to
800 load a file defining variables, with this form or with `defconst' or
801 `defcustom', you should always load that file _outside_ any bindings
802 for these variables. \(`defconst' and `defcustom' behave similarly in
803 this respect.)
804 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
805 (args)
806 Lisp_Object args;
808 register Lisp_Object sym, tem, tail;
810 sym = Fcar (args);
811 tail = Fcdr (args);
812 if (!NILP (Fcdr (Fcdr (tail))))
813 error ("Too many arguments");
815 tem = Fdefault_boundp (sym);
816 if (!NILP (tail))
818 if (SYMBOL_CONSTANT_P (sym))
820 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
821 Lisp_Object tem = Fcar (tail);
822 if (! (CONSP (tem)
823 && EQ (XCAR (tem), Qquote)
824 && CONSP (XCDR (tem))
825 && EQ (XCAR (XCDR (tem)), sym)))
826 error ("Constant symbol `%s' specified in defvar",
827 SDATA (SYMBOL_NAME (sym)));
830 if (NILP (tem))
831 Fset_default (sym, Feval (Fcar (tail)));
832 else
833 { /* Check if there is really a global binding rather than just a let
834 binding that shadows the global unboundness of the var. */
835 volatile struct specbinding *pdl = specpdl_ptr;
836 while (--pdl >= specpdl)
838 if (EQ (pdl->symbol, sym) && !pdl->func
839 && EQ (pdl->old_value, Qunbound))
841 message_with_string ("Warning: defvar ignored because %s is let-bound",
842 SYMBOL_NAME (sym), 1);
843 break;
847 tail = Fcdr (tail);
848 tem = Fcar (tail);
849 if (!NILP (tem))
851 if (!NILP (Vpurify_flag))
852 tem = Fpurecopy (tem);
853 Fput (sym, Qvariable_documentation, tem);
855 LOADHIST_ATTACH (sym);
857 else
858 /* Simple (defvar <var>) should not count as a definition at all.
859 It could get in the way of other definitions, and unloading this
860 package could try to make the variable unbound. */
863 return sym;
866 DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
867 doc: /* Define SYMBOL as a constant variable.
868 The intent is that neither programs nor users should ever change this value.
869 Always sets the value of SYMBOL to the result of evalling INITVALUE.
870 If SYMBOL is buffer-local, its default value is what is set;
871 buffer-local values are not affected.
872 DOCSTRING is optional.
874 If SYMBOL has a local binding, then this form sets the local binding's
875 value. However, you should normally not make local bindings for
876 variables defined with this form.
877 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
878 (args)
879 Lisp_Object args;
881 register Lisp_Object sym, tem;
883 sym = Fcar (args);
884 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
885 error ("Too many arguments");
887 tem = Feval (Fcar (Fcdr (args)));
888 if (!NILP (Vpurify_flag))
889 tem = Fpurecopy (tem);
890 Fset_default (sym, tem);
891 tem = Fcar (Fcdr (Fcdr (args)));
892 if (!NILP (tem))
894 if (!NILP (Vpurify_flag))
895 tem = Fpurecopy (tem);
896 Fput (sym, Qvariable_documentation, tem);
898 Fput (sym, Qrisky_local_variable, Qt);
899 LOADHIST_ATTACH (sym);
900 return sym;
903 /* Error handler used in Fuser_variable_p. */
904 static Lisp_Object
905 user_variable_p_eh (ignore)
906 Lisp_Object ignore;
908 return Qnil;
911 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
912 doc: /* Return t if VARIABLE is intended to be set and modified by users.
913 \(The alternative is a variable used internally in a Lisp program.)
914 A variable is a user variable if
915 \(1) the first character of its documentation is `*', or
916 \(2) it is customizable (its property list contains a non-nil value
917 of `standard-value' or `custom-autoload'), or
918 \(3) it is an alias for another user variable.
919 Return nil if VARIABLE is an alias and there is a loop in the
920 chain of symbols. */)
921 (variable)
922 Lisp_Object variable;
924 Lisp_Object documentation;
926 if (!SYMBOLP (variable))
927 return Qnil;
929 /* If indirect and there's an alias loop, don't check anything else. */
930 if (XSYMBOL (variable)->indirect_variable
931 && NILP (internal_condition_case_1 (indirect_variable, variable,
932 Qt, user_variable_p_eh)))
933 return Qnil;
935 while (1)
937 documentation = Fget (variable, Qvariable_documentation);
938 if (INTEGERP (documentation) && XINT (documentation) < 0)
939 return Qt;
940 if (STRINGP (documentation)
941 && ((unsigned char) SREF (documentation, 0) == '*'))
942 return Qt;
943 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
944 if (CONSP (documentation)
945 && STRINGP (XCAR (documentation))
946 && INTEGERP (XCDR (documentation))
947 && XINT (XCDR (documentation)) < 0)
948 return Qt;
949 /* Customizable? See `custom-variable-p'. */
950 if ((!NILP (Fget (variable, intern ("standard-value"))))
951 || (!NILP (Fget (variable, intern ("custom-autoload")))))
952 return Qt;
954 if (!XSYMBOL (variable)->indirect_variable)
955 return Qnil;
957 /* An indirect variable? Let's follow the chain. */
958 variable = XSYMBOL (variable)->value;
962 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
963 doc: /* Bind variables according to VARLIST then eval BODY.
964 The value of the last form in BODY is returned.
965 Each element of VARLIST is a symbol (which is bound to nil)
966 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
967 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
968 usage: (let* VARLIST BODY...) */)
969 (args)
970 Lisp_Object args;
972 Lisp_Object varlist, val, elt;
973 int count = SPECPDL_INDEX ();
974 struct gcpro gcpro1, gcpro2, gcpro3;
976 GCPRO3 (args, elt, varlist);
978 varlist = Fcar (args);
979 while (!NILP (varlist))
981 QUIT;
982 elt = Fcar (varlist);
983 if (SYMBOLP (elt))
984 specbind (elt, Qnil);
985 else if (! NILP (Fcdr (Fcdr (elt))))
986 Fsignal (Qerror,
987 Fcons (build_string ("`let' bindings can have only one value-form"),
988 elt));
989 else
991 val = Feval (Fcar (Fcdr (elt)));
992 specbind (Fcar (elt), val);
994 varlist = Fcdr (varlist);
996 UNGCPRO;
997 val = Fprogn (Fcdr (args));
998 return unbind_to (count, val);
1001 DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
1002 doc: /* Bind variables according to VARLIST then eval BODY.
1003 The value of the last form in BODY is returned.
1004 Each element of VARLIST is a symbol (which is bound to nil)
1005 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1006 All the VALUEFORMs are evalled before any symbols are bound.
1007 usage: (let VARLIST BODY...) */)
1008 (args)
1009 Lisp_Object args;
1011 Lisp_Object *temps, tem;
1012 register Lisp_Object elt, varlist;
1013 int count = SPECPDL_INDEX ();
1014 register int argnum;
1015 struct gcpro gcpro1, gcpro2;
1017 varlist = Fcar (args);
1019 /* Make space to hold the values to give the bound variables */
1020 elt = Flength (varlist);
1021 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object));
1023 /* Compute the values and store them in `temps' */
1025 GCPRO2 (args, *temps);
1026 gcpro2.nvars = 0;
1028 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
1030 QUIT;
1031 elt = Fcar (varlist);
1032 if (SYMBOLP (elt))
1033 temps [argnum++] = Qnil;
1034 else if (! NILP (Fcdr (Fcdr (elt))))
1035 Fsignal (Qerror,
1036 Fcons (build_string ("`let' bindings can have only one value-form"),
1037 elt));
1038 else
1039 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
1040 gcpro2.nvars = argnum;
1042 UNGCPRO;
1044 varlist = Fcar (args);
1045 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
1047 elt = Fcar (varlist);
1048 tem = temps[argnum++];
1049 if (SYMBOLP (elt))
1050 specbind (elt, tem);
1051 else
1052 specbind (Fcar (elt), tem);
1055 elt = Fprogn (Fcdr (args));
1056 return unbind_to (count, elt);
1059 DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
1060 doc: /* If TEST yields non-nil, eval BODY... and repeat.
1061 The order of execution is thus TEST, BODY, TEST, BODY and so on
1062 until TEST returns nil.
1063 usage: (while TEST BODY...) */)
1064 (args)
1065 Lisp_Object args;
1067 Lisp_Object test, body;
1068 struct gcpro gcpro1, gcpro2;
1070 GCPRO2 (test, body);
1072 test = Fcar (args);
1073 body = Fcdr (args);
1074 while (!NILP (Feval (test)))
1076 QUIT;
1077 Fprogn (body);
1080 UNGCPRO;
1081 return Qnil;
1084 DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
1085 doc: /* Return result of expanding macros at top level of FORM.
1086 If FORM is not a macro call, it is returned unchanged.
1087 Otherwise, the macro is expanded and the expansion is considered
1088 in place of FORM. When a non-macro-call results, it is returned.
1090 The second optional arg ENVIRONMENT specifies an environment of macro
1091 definitions to shadow the loaded ones for use in file byte-compilation. */)
1092 (form, environment)
1093 Lisp_Object form;
1094 Lisp_Object environment;
1096 /* With cleanups from Hallvard Furuseth. */
1097 register Lisp_Object expander, sym, def, tem;
1099 while (1)
1101 /* Come back here each time we expand a macro call,
1102 in case it expands into another macro call. */
1103 if (!CONSP (form))
1104 break;
1105 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1106 def = sym = XCAR (form);
1107 tem = Qnil;
1108 /* Trace symbols aliases to other symbols
1109 until we get a symbol that is not an alias. */
1110 while (SYMBOLP (def))
1112 QUIT;
1113 sym = def;
1114 tem = Fassq (sym, environment);
1115 if (NILP (tem))
1117 def = XSYMBOL (sym)->function;
1118 if (!EQ (def, Qunbound))
1119 continue;
1121 break;
1123 /* Right now TEM is the result from SYM in ENVIRONMENT,
1124 and if TEM is nil then DEF is SYM's function definition. */
1125 if (NILP (tem))
1127 /* SYM is not mentioned in ENVIRONMENT.
1128 Look at its function definition. */
1129 if (EQ (def, Qunbound) || !CONSP (def))
1130 /* Not defined or definition not suitable */
1131 break;
1132 if (EQ (XCAR (def), Qautoload))
1134 /* Autoloading function: will it be a macro when loaded? */
1135 tem = Fnth (make_number (4), def);
1136 if (EQ (tem, Qt) || EQ (tem, Qmacro))
1137 /* Yes, load it and try again. */
1139 struct gcpro gcpro1;
1140 GCPRO1 (form);
1141 do_autoload (def, sym);
1142 UNGCPRO;
1143 continue;
1145 else
1146 break;
1148 else if (!EQ (XCAR (def), Qmacro))
1149 break;
1150 else expander = XCDR (def);
1152 else
1154 expander = XCDR (tem);
1155 if (NILP (expander))
1156 break;
1158 form = apply1 (expander, XCDR (form));
1160 return form;
1163 DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
1164 doc: /* Eval BODY allowing nonlocal exits using `throw'.
1165 TAG is evalled to get the tag to use; it must not be nil.
1167 Then the BODY is executed.
1168 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1169 If no throw happens, `catch' returns the value of the last BODY form.
1170 If a throw happens, it specifies the value to return from `catch'.
1171 usage: (catch TAG BODY...) */)
1172 (args)
1173 Lisp_Object args;
1175 register Lisp_Object tag;
1176 struct gcpro gcpro1;
1178 GCPRO1 (args);
1179 tag = Feval (Fcar (args));
1180 UNGCPRO;
1181 return internal_catch (tag, Fprogn, Fcdr (args));
1184 /* Set up a catch, then call C function FUNC on argument ARG.
1185 FUNC should return a Lisp_Object.
1186 This is how catches are done from within C code. */
1188 Lisp_Object
1189 internal_catch (tag, func, arg)
1190 Lisp_Object tag;
1191 Lisp_Object (*func) ();
1192 Lisp_Object arg;
1194 /* This structure is made part of the chain `catchlist'. */
1195 struct catchtag c;
1197 /* Fill in the components of c, and put it on the list. */
1198 c.next = catchlist;
1199 c.tag = tag;
1200 c.val = Qnil;
1201 c.backlist = backtrace_list;
1202 c.handlerlist = handlerlist;
1203 c.lisp_eval_depth = lisp_eval_depth;
1204 c.pdlcount = SPECPDL_INDEX ();
1205 c.poll_suppress_count = poll_suppress_count;
1206 c.interrupt_input_blocked = interrupt_input_blocked;
1207 c.gcpro = gcprolist;
1208 c.byte_stack = byte_stack_list;
1209 catchlist = &c;
1211 /* Call FUNC. */
1212 if (! _setjmp (c.jmp))
1213 c.val = (*func) (arg);
1215 /* Throw works by a longjmp that comes right here. */
1216 catchlist = c.next;
1217 return c.val;
1220 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1221 jump to that CATCH, returning VALUE as the value of that catch.
1223 This is the guts Fthrow and Fsignal; they differ only in the way
1224 they choose the catch tag to throw to. A catch tag for a
1225 condition-case form has a TAG of Qnil.
1227 Before each catch is discarded, unbind all special bindings and
1228 execute all unwind-protect clauses made above that catch. Unwind
1229 the handler stack as we go, so that the proper handlers are in
1230 effect for each unwind-protect clause we run. At the end, restore
1231 some static info saved in CATCH, and longjmp to the location
1232 specified in the
1234 This is used for correct unwinding in Fthrow and Fsignal. */
1236 static void
1237 unwind_to_catch (catch, value)
1238 struct catchtag *catch;
1239 Lisp_Object value;
1241 register int last_time;
1243 /* Save the value in the tag. */
1244 catch->val = value;
1246 /* Restore certain special C variables. */
1247 set_poll_suppress_count (catch->poll_suppress_count);
1248 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked);
1249 handling_signal = 0;
1250 immediate_quit = 0;
1254 last_time = catchlist == catch;
1256 /* Unwind the specpdl stack, and then restore the proper set of
1257 handlers. */
1258 unbind_to (catchlist->pdlcount, Qnil);
1259 handlerlist = catchlist->handlerlist;
1260 catchlist = catchlist->next;
1262 while (! last_time);
1264 #if HAVE_X_WINDOWS
1265 /* If x_catch_errors was done, turn it off now.
1266 (First we give unbind_to a chance to do that.) */
1267 x_fully_uncatch_errors ();
1268 #endif
1270 byte_stack_list = catch->byte_stack;
1271 gcprolist = catch->gcpro;
1272 #ifdef DEBUG_GCPRO
1273 if (gcprolist != 0)
1274 gcpro_level = gcprolist->level + 1;
1275 else
1276 gcpro_level = 0;
1277 #endif
1278 backtrace_list = catch->backlist;
1279 lisp_eval_depth = catch->lisp_eval_depth;
1281 _longjmp (catch->jmp, 1);
1284 DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
1285 doc: /* Throw to the catch for TAG and return VALUE from it.
1286 Both TAG and VALUE are evalled. */)
1287 (tag, value)
1288 register Lisp_Object tag, value;
1290 register struct catchtag *c;
1292 while (1)
1294 if (!NILP (tag))
1295 for (c = catchlist; c; c = c->next)
1297 if (EQ (c->tag, tag))
1298 unwind_to_catch (c, value);
1300 tag = Fsignal (Qno_catch, Fcons (tag, Fcons (value, Qnil)));
1305 DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
1306 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
1307 If BODYFORM completes normally, its value is returned
1308 after executing the UNWINDFORMS.
1309 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1310 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1311 (args)
1312 Lisp_Object args;
1314 Lisp_Object val;
1315 int count = SPECPDL_INDEX ();
1317 record_unwind_protect (Fprogn, Fcdr (args));
1318 val = Feval (Fcar (args));
1319 return unbind_to (count, val);
1322 /* Chain of condition handlers currently in effect.
1323 The elements of this chain are contained in the stack frames
1324 of Fcondition_case and internal_condition_case.
1325 When an error is signaled (by calling Fsignal, below),
1326 this chain is searched for an element that applies. */
1328 struct handler *handlerlist;
1330 DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
1331 doc: /* Regain control when an error is signaled.
1332 Executes BODYFORM and returns its value if no error happens.
1333 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1334 where the BODY is made of Lisp expressions.
1336 A handler is applicable to an error
1337 if CONDITION-NAME is one of the error's condition names.
1338 If an error happens, the first applicable handler is run.
1340 The car of a handler may be a list of condition names
1341 instead of a single condition name.
1343 When a handler handles an error,
1344 control returns to the condition-case and the handler BODY... is executed
1345 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1346 VAR may be nil; then you do not get access to the signal information.
1348 The value of the last BODY form is returned from the condition-case.
1349 See also the function `signal' for more info.
1350 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1351 (args)
1352 Lisp_Object args;
1354 register Lisp_Object bodyform, handlers;
1355 volatile Lisp_Object var;
1357 var = Fcar (args);
1358 bodyform = Fcar (Fcdr (args));
1359 handlers = Fcdr (Fcdr (args));
1361 return internal_lisp_condition_case (var, bodyform, handlers);
1364 /* Like Fcondition_case, but the args are separate
1365 rather than passed in a list. Used by Fbyte_code. */
1367 Lisp_Object
1368 internal_lisp_condition_case (var, bodyform, handlers)
1369 volatile Lisp_Object var;
1370 Lisp_Object bodyform, handlers;
1372 Lisp_Object val;
1373 struct catchtag c;
1374 struct handler h;
1376 CHECK_SYMBOL (var);
1378 for (val = handlers; CONSP (val); val = XCDR (val))
1380 Lisp_Object tem;
1381 tem = XCAR (val);
1382 if (! (NILP (tem)
1383 || (CONSP (tem)
1384 && (SYMBOLP (XCAR (tem))
1385 || CONSP (XCAR (tem))))))
1386 error ("Invalid condition handler", tem);
1389 c.tag = Qnil;
1390 c.val = Qnil;
1391 c.backlist = backtrace_list;
1392 c.handlerlist = handlerlist;
1393 c.lisp_eval_depth = lisp_eval_depth;
1394 c.pdlcount = SPECPDL_INDEX ();
1395 c.poll_suppress_count = poll_suppress_count;
1396 c.interrupt_input_blocked = interrupt_input_blocked;
1397 c.gcpro = gcprolist;
1398 c.byte_stack = byte_stack_list;
1399 if (_setjmp (c.jmp))
1401 if (!NILP (h.var))
1402 specbind (h.var, c.val);
1403 val = Fprogn (Fcdr (h.chosen_clause));
1405 /* Note that this just undoes the binding of h.var; whoever
1406 longjumped to us unwound the stack to c.pdlcount before
1407 throwing. */
1408 unbind_to (c.pdlcount, Qnil);
1409 return val;
1411 c.next = catchlist;
1412 catchlist = &c;
1414 h.var = var;
1415 h.handler = handlers;
1416 h.next = handlerlist;
1417 h.tag = &c;
1418 handlerlist = &h;
1420 val = Feval (bodyform);
1421 catchlist = c.next;
1422 handlerlist = h.next;
1423 return val;
1426 /* Call the function BFUN with no arguments, catching errors within it
1427 according to HANDLERS. If there is an error, call HFUN with
1428 one argument which is the data that describes the error:
1429 (SIGNALNAME . DATA)
1431 HANDLERS can be a list of conditions to catch.
1432 If HANDLERS is Qt, catch all errors.
1433 If HANDLERS is Qerror, catch all errors
1434 but allow the debugger to run if that is enabled. */
1436 Lisp_Object
1437 internal_condition_case (bfun, handlers, hfun)
1438 Lisp_Object (*bfun) ();
1439 Lisp_Object handlers;
1440 Lisp_Object (*hfun) ();
1442 Lisp_Object val;
1443 struct catchtag c;
1444 struct handler h;
1446 /* Since Fsignal will close off all calls to x_catch_errors,
1447 we will get the wrong results if some are not closed now. */
1448 #if HAVE_X_WINDOWS
1449 if (x_catching_errors ())
1450 abort ();
1451 #endif
1453 c.tag = Qnil;
1454 c.val = Qnil;
1455 c.backlist = backtrace_list;
1456 c.handlerlist = handlerlist;
1457 c.lisp_eval_depth = lisp_eval_depth;
1458 c.pdlcount = SPECPDL_INDEX ();
1459 c.poll_suppress_count = poll_suppress_count;
1460 c.interrupt_input_blocked = interrupt_input_blocked;
1461 c.gcpro = gcprolist;
1462 c.byte_stack = byte_stack_list;
1463 if (_setjmp (c.jmp))
1465 return (*hfun) (c.val);
1467 c.next = catchlist;
1468 catchlist = &c;
1469 h.handler = handlers;
1470 h.var = Qnil;
1471 h.next = handlerlist;
1472 h.tag = &c;
1473 handlerlist = &h;
1475 val = (*bfun) ();
1476 catchlist = c.next;
1477 handlerlist = h.next;
1478 return val;
1481 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1483 Lisp_Object
1484 internal_condition_case_1 (bfun, arg, handlers, hfun)
1485 Lisp_Object (*bfun) ();
1486 Lisp_Object arg;
1487 Lisp_Object handlers;
1488 Lisp_Object (*hfun) ();
1490 Lisp_Object val;
1491 struct catchtag c;
1492 struct handler h;
1494 /* Since Fsignal will close off all calls to x_catch_errors,
1495 we will get the wrong results if some are not closed now. */
1496 #if HAVE_X_WINDOWS
1497 if (x_catching_errors ())
1498 abort ();
1499 #endif
1501 c.tag = Qnil;
1502 c.val = Qnil;
1503 c.backlist = backtrace_list;
1504 c.handlerlist = handlerlist;
1505 c.lisp_eval_depth = lisp_eval_depth;
1506 c.pdlcount = SPECPDL_INDEX ();
1507 c.poll_suppress_count = poll_suppress_count;
1508 c.interrupt_input_blocked = interrupt_input_blocked;
1509 c.gcpro = gcprolist;
1510 c.byte_stack = byte_stack_list;
1511 if (_setjmp (c.jmp))
1513 return (*hfun) (c.val);
1515 c.next = catchlist;
1516 catchlist = &c;
1517 h.handler = handlers;
1518 h.var = Qnil;
1519 h.next = handlerlist;
1520 h.tag = &c;
1521 handlerlist = &h;
1523 val = (*bfun) (arg);
1524 catchlist = c.next;
1525 handlerlist = h.next;
1526 return val;
1530 /* Like internal_condition_case but call BFUN with NARGS as first,
1531 and ARGS as second argument. */
1533 Lisp_Object
1534 internal_condition_case_2 (bfun, nargs, args, handlers, hfun)
1535 Lisp_Object (*bfun) ();
1536 int nargs;
1537 Lisp_Object *args;
1538 Lisp_Object handlers;
1539 Lisp_Object (*hfun) ();
1541 Lisp_Object val;
1542 struct catchtag c;
1543 struct handler h;
1545 /* Since Fsignal will close off all calls to x_catch_errors,
1546 we will get the wrong results if some are not closed now. */
1547 #if HAVE_X_WINDOWS
1548 if (x_catching_errors ())
1549 abort ();
1550 #endif
1552 c.tag = Qnil;
1553 c.val = Qnil;
1554 c.backlist = backtrace_list;
1555 c.handlerlist = handlerlist;
1556 c.lisp_eval_depth = lisp_eval_depth;
1557 c.pdlcount = SPECPDL_INDEX ();
1558 c.poll_suppress_count = poll_suppress_count;
1559 c.interrupt_input_blocked = interrupt_input_blocked;
1560 c.gcpro = gcprolist;
1561 c.byte_stack = byte_stack_list;
1562 if (_setjmp (c.jmp))
1564 return (*hfun) (c.val);
1566 c.next = catchlist;
1567 catchlist = &c;
1568 h.handler = handlers;
1569 h.var = Qnil;
1570 h.next = handlerlist;
1571 h.tag = &c;
1572 handlerlist = &h;
1574 val = (*bfun) (nargs, args);
1575 catchlist = c.next;
1576 handlerlist = h.next;
1577 return val;
1581 static Lisp_Object find_handler_clause P_ ((Lisp_Object, Lisp_Object,
1582 Lisp_Object, Lisp_Object,
1583 Lisp_Object *));
1585 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
1586 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1587 This function does not return.
1589 An error symbol is a symbol with an `error-conditions' property
1590 that is a list of condition names.
1591 A handler for any of those names will get to handle this signal.
1592 The symbol `error' should normally be one of them.
1594 DATA should be a list. Its elements are printed as part of the error message.
1595 See Info anchor `(elisp)Definition of signal' for some details on how this
1596 error message is constructed.
1597 If the signal is handled, DATA is made available to the handler.
1598 See also the function `condition-case'. */)
1599 (error_symbol, data)
1600 Lisp_Object error_symbol, data;
1602 /* When memory is full, ERROR-SYMBOL is nil,
1603 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1604 That is a special case--don't do this in other situations. */
1605 register struct handler *allhandlers = handlerlist;
1606 Lisp_Object conditions;
1607 extern int gc_in_progress;
1608 extern int waiting_for_input;
1609 Lisp_Object debugger_value;
1610 Lisp_Object string;
1611 Lisp_Object real_error_symbol;
1612 struct backtrace *bp;
1614 immediate_quit = handling_signal = 0;
1615 abort_on_gc = 0;
1616 if (gc_in_progress || waiting_for_input)
1617 abort ();
1619 if (NILP (error_symbol))
1620 real_error_symbol = Fcar (data);
1621 else
1622 real_error_symbol = error_symbol;
1624 #if 0 /* rms: I don't know why this was here,
1625 but it is surely wrong for an error that is handled. */
1626 #ifdef HAVE_X_WINDOWS
1627 if (display_hourglass_p)
1628 cancel_hourglass ();
1629 #endif
1630 #endif
1632 /* This hook is used by edebug. */
1633 if (! NILP (Vsignal_hook_function)
1634 && ! NILP (error_symbol))
1636 /* Edebug takes care of restoring these variables when it exits. */
1637 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
1638 max_lisp_eval_depth = lisp_eval_depth + 20;
1640 if (SPECPDL_INDEX () + 40 > max_specpdl_size)
1641 max_specpdl_size = SPECPDL_INDEX () + 40;
1643 call2 (Vsignal_hook_function, error_symbol, data);
1646 conditions = Fget (real_error_symbol, Qerror_conditions);
1648 /* Remember from where signal was called. Skip over the frame for
1649 `signal' itself. If a frame for `error' follows, skip that,
1650 too. Don't do this when ERROR_SYMBOL is nil, because that
1651 is a memory-full error. */
1652 Vsignaling_function = Qnil;
1653 if (backtrace_list && !NILP (error_symbol))
1655 bp = backtrace_list->next;
1656 if (bp && bp->function && EQ (*bp->function, Qerror))
1657 bp = bp->next;
1658 if (bp && bp->function)
1659 Vsignaling_function = *bp->function;
1662 for (; handlerlist; handlerlist = handlerlist->next)
1664 register Lisp_Object clause;
1666 clause = find_handler_clause (handlerlist->handler, conditions,
1667 error_symbol, data, &debugger_value);
1669 if (EQ (clause, Qlambda))
1671 /* We can't return values to code which signaled an error, but we
1672 can continue code which has signaled a quit. */
1673 if (EQ (real_error_symbol, Qquit))
1674 return Qnil;
1675 else
1676 error ("Cannot return from the debugger in an error");
1679 if (!NILP (clause))
1681 Lisp_Object unwind_data;
1682 struct handler *h = handlerlist;
1684 handlerlist = allhandlers;
1686 if (NILP (error_symbol))
1687 unwind_data = data;
1688 else
1689 unwind_data = Fcons (error_symbol, data);
1690 h->chosen_clause = clause;
1691 unwind_to_catch (h->tag, unwind_data);
1695 handlerlist = allhandlers;
1696 /* If no handler is present now, try to run the debugger,
1697 and if that fails, throw to top level. */
1698 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value);
1699 if (catchlist != 0)
1700 Fthrow (Qtop_level, Qt);
1702 if (! NILP (error_symbol))
1703 data = Fcons (error_symbol, data);
1705 string = Ferror_message_string (data);
1706 fatal ("%s", SDATA (string), 0);
1709 /* Return nonzero iff LIST is a non-nil atom or
1710 a list containing one of CONDITIONS. */
1712 static int
1713 wants_debugger (list, conditions)
1714 Lisp_Object list, conditions;
1716 if (NILP (list))
1717 return 0;
1718 if (! CONSP (list))
1719 return 1;
1721 while (CONSP (conditions))
1723 Lisp_Object this, tail;
1724 this = XCAR (conditions);
1725 for (tail = list; CONSP (tail); tail = XCDR (tail))
1726 if (EQ (XCAR (tail), this))
1727 return 1;
1728 conditions = XCDR (conditions);
1730 return 0;
1733 /* Return 1 if an error with condition-symbols CONDITIONS,
1734 and described by SIGNAL-DATA, should skip the debugger
1735 according to debugger-ignored-errors. */
1737 static int
1738 skip_debugger (conditions, data)
1739 Lisp_Object conditions, data;
1741 Lisp_Object tail;
1742 int first_string = 1;
1743 Lisp_Object error_message;
1745 error_message = Qnil;
1746 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
1748 if (STRINGP (XCAR (tail)))
1750 if (first_string)
1752 error_message = Ferror_message_string (data);
1753 first_string = 0;
1756 if (fast_string_match (XCAR (tail), error_message) >= 0)
1757 return 1;
1759 else
1761 Lisp_Object contail;
1763 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
1764 if (EQ (XCAR (tail), XCAR (contail)))
1765 return 1;
1769 return 0;
1772 /* Value of Qlambda means we have called debugger and user has continued.
1773 There are two ways to pass SIG and DATA:
1774 = SIG is the error symbol, and DATA is the rest of the data.
1775 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1776 This is for memory-full errors only.
1778 Store value returned from debugger into *DEBUGGER_VALUE_PTR.
1780 We need to increase max_specpdl_size temporarily around
1781 anything we do that can push on the specpdl, so as not to get
1782 a second error here in case we're handling specpdl overflow. */
1784 static Lisp_Object
1785 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr)
1786 Lisp_Object handlers, conditions, sig, data;
1787 Lisp_Object *debugger_value_ptr;
1789 register Lisp_Object h;
1790 register Lisp_Object tem;
1792 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */
1793 return Qt;
1794 /* error is used similarly, but means print an error message
1795 and run the debugger if that is enabled. */
1796 if (EQ (handlers, Qerror)
1797 || !NILP (Vdebug_on_signal)) /* This says call debugger even if
1798 there is a handler. */
1800 int debugger_called = 0;
1801 Lisp_Object sig_symbol, combined_data;
1802 /* This is set to 1 if we are handling a memory-full error,
1803 because these must not run the debugger.
1804 (There is no room in memory to do that!) */
1805 int no_debugger = 0;
1807 if (NILP (sig))
1809 combined_data = data;
1810 sig_symbol = Fcar (data);
1811 no_debugger = 1;
1813 else
1815 combined_data = Fcons (sig, data);
1816 sig_symbol = sig;
1819 if (wants_debugger (Vstack_trace_on_error, conditions))
1821 max_specpdl_size++;
1822 #ifdef PROTOTYPES
1823 internal_with_output_to_temp_buffer ("*Backtrace*",
1824 (Lisp_Object (*) (Lisp_Object)) Fbacktrace,
1825 Qnil);
1826 #else
1827 internal_with_output_to_temp_buffer ("*Backtrace*",
1828 Fbacktrace, Qnil);
1829 #endif
1830 max_specpdl_size--;
1832 if (! no_debugger
1833 && (EQ (sig_symbol, Qquit)
1834 ? debug_on_quit
1835 : wants_debugger (Vdebug_on_error, conditions))
1836 && ! skip_debugger (conditions, combined_data)
1837 && when_entered_debugger < num_nonmacro_input_events)
1839 *debugger_value_ptr
1840 = call_debugger (Fcons (Qerror,
1841 Fcons (combined_data, Qnil)));
1842 debugger_called = 1;
1844 /* If there is no handler, return saying whether we ran the debugger. */
1845 if (EQ (handlers, Qerror))
1847 if (debugger_called)
1848 return Qlambda;
1849 return Qt;
1852 for (h = handlers; CONSP (h); h = Fcdr (h))
1854 Lisp_Object handler, condit;
1856 handler = Fcar (h);
1857 if (!CONSP (handler))
1858 continue;
1859 condit = Fcar (handler);
1860 /* Handle a single condition name in handler HANDLER. */
1861 if (SYMBOLP (condit))
1863 tem = Fmemq (Fcar (handler), conditions);
1864 if (!NILP (tem))
1865 return handler;
1867 /* Handle a list of condition names in handler HANDLER. */
1868 else if (CONSP (condit))
1870 while (CONSP (condit))
1872 tem = Fmemq (Fcar (condit), conditions);
1873 if (!NILP (tem))
1874 return handler;
1875 condit = XCDR (condit);
1879 return Qnil;
1882 /* dump an error message; called like printf */
1884 /* VARARGS 1 */
1885 void
1886 error (m, a1, a2, a3)
1887 char *m;
1888 char *a1, *a2, *a3;
1890 char buf[200];
1891 int size = 200;
1892 int mlen;
1893 char *buffer = buf;
1894 char *args[3];
1895 int allocated = 0;
1896 Lisp_Object string;
1898 args[0] = a1;
1899 args[1] = a2;
1900 args[2] = a3;
1902 mlen = strlen (m);
1904 while (1)
1906 int used = doprnt (buffer, size, m, m + mlen, 3, args);
1907 if (used < size)
1908 break;
1909 size *= 2;
1910 if (allocated)
1911 buffer = (char *) xrealloc (buffer, size);
1912 else
1914 buffer = (char *) xmalloc (size);
1915 allocated = 1;
1919 string = build_string (buffer);
1920 if (allocated)
1921 xfree (buffer);
1923 Fsignal (Qerror, Fcons (string, Qnil));
1924 abort ();
1927 DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
1928 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
1929 This means it contains a description for how to read arguments to give it.
1930 The value is nil for an invalid function or a symbol with no function
1931 definition.
1933 Interactively callable functions include strings and vectors (treated
1934 as keyboard macros), lambda-expressions that contain a top-level call
1935 to `interactive', autoload definitions made by `autoload' with non-nil
1936 fourth argument, and some of the built-in functions of Lisp.
1938 Also, a symbol satisfies `commandp' if its function definition does so.
1940 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1941 then strings and vectors are not accepted. */)
1942 (function, for_call_interactively)
1943 Lisp_Object function, for_call_interactively;
1945 register Lisp_Object fun;
1946 register Lisp_Object funcar;
1948 fun = function;
1950 fun = indirect_function (fun);
1951 if (EQ (fun, Qunbound))
1952 return Qnil;
1954 /* Emacs primitives are interactive if their DEFUN specifies an
1955 interactive spec. */
1956 if (SUBRP (fun))
1958 if (XSUBR (fun)->prompt)
1959 return Qt;
1960 else
1961 return Qnil;
1964 /* Bytecode objects are interactive if they are long enough to
1965 have an element whose index is COMPILED_INTERACTIVE, which is
1966 where the interactive spec is stored. */
1967 else if (COMPILEDP (fun))
1968 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
1969 ? Qt : Qnil);
1971 /* Strings and vectors are keyboard macros. */
1972 if (NILP (for_call_interactively) && (STRINGP (fun) || VECTORP (fun)))
1973 return Qt;
1975 /* Lists may represent commands. */
1976 if (!CONSP (fun))
1977 return Qnil;
1978 funcar = XCAR (fun);
1979 if (EQ (funcar, Qlambda))
1980 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
1981 if (EQ (funcar, Qautoload))
1982 return Fcar (Fcdr (Fcdr (XCDR (fun))));
1983 else
1984 return Qnil;
1987 /* ARGSUSED */
1988 DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
1989 doc: /* Define FUNCTION to autoload from FILE.
1990 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1991 Third arg DOCSTRING is documentation for the function.
1992 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1993 Fifth arg TYPE indicates the type of the object:
1994 nil or omitted says FUNCTION is a function,
1995 `keymap' says FUNCTION is really a keymap, and
1996 `macro' or t says FUNCTION is really a macro.
1997 Third through fifth args give info about the real definition.
1998 They default to nil.
1999 If FUNCTION is already defined other than as an autoload,
2000 this does nothing and returns nil. */)
2001 (function, file, docstring, interactive, type)
2002 Lisp_Object function, file, docstring, interactive, type;
2004 #ifdef NO_ARG_ARRAY
2005 Lisp_Object args[4];
2006 #endif
2008 CHECK_SYMBOL (function);
2009 CHECK_STRING (file);
2011 /* If function is defined and not as an autoload, don't override */
2012 if (!EQ (XSYMBOL (function)->function, Qunbound)
2013 && !(CONSP (XSYMBOL (function)->function)
2014 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
2015 return Qnil;
2017 if (NILP (Vpurify_flag))
2018 /* Only add entries after dumping, because the ones before are
2019 not useful and else we get loads of them from the loaddefs.el. */
2020 LOADHIST_ATTACH (Fcons (Qautoload, function));
2022 #ifdef NO_ARG_ARRAY
2023 args[0] = file;
2024 args[1] = docstring;
2025 args[2] = interactive;
2026 args[3] = type;
2028 return Ffset (function, Fcons (Qautoload, Flist (4, &args[0])));
2029 #else /* NO_ARG_ARRAY */
2030 return Ffset (function, Fcons (Qautoload, Flist (4, &file)));
2031 #endif /* not NO_ARG_ARRAY */
2034 Lisp_Object
2035 un_autoload (oldqueue)
2036 Lisp_Object oldqueue;
2038 register Lisp_Object queue, first, second;
2040 /* Queue to unwind is current value of Vautoload_queue.
2041 oldqueue is the shadowed value to leave in Vautoload_queue. */
2042 queue = Vautoload_queue;
2043 Vautoload_queue = oldqueue;
2044 while (CONSP (queue))
2046 first = XCAR (queue);
2047 second = Fcdr (first);
2048 first = Fcar (first);
2049 if (EQ (first, make_number (0)))
2050 Vfeatures = second;
2051 else
2052 Ffset (first, second);
2053 queue = XCDR (queue);
2055 return Qnil;
2058 /* Load an autoloaded function.
2059 FUNNAME is the symbol which is the function's name.
2060 FUNDEF is the autoload definition (a list). */
2062 void
2063 do_autoload (fundef, funname)
2064 Lisp_Object fundef, funname;
2066 int count = SPECPDL_INDEX ();
2067 Lisp_Object fun, queue, first, second;
2068 struct gcpro gcpro1, gcpro2, gcpro3;
2070 /* This is to make sure that loadup.el gives a clear picture
2071 of what files are preloaded and when. */
2072 if (! NILP (Vpurify_flag))
2073 error ("Attempt to autoload %s while preparing to dump",
2074 SDATA (SYMBOL_NAME (funname)));
2076 fun = funname;
2077 CHECK_SYMBOL (funname);
2078 GCPRO3 (fun, funname, fundef);
2080 /* Preserve the match data. */
2081 record_unwind_save_match_data ();
2083 /* Value saved here is to be restored into Vautoload_queue. */
2084 record_unwind_protect (un_autoload, Vautoload_queue);
2085 Vautoload_queue = Qt;
2086 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil, Qt);
2088 /* Save the old autoloads, in case we ever do an unload. */
2089 queue = Vautoload_queue;
2090 while (CONSP (queue))
2092 first = XCAR (queue);
2093 second = Fcdr (first);
2094 first = Fcar (first);
2096 if (SYMBOLP (first) && CONSP (second) && EQ (XCAR (second), Qautoload))
2097 Fput (first, Qautoload, (XCDR (second)));
2099 queue = XCDR (queue);
2102 /* Once loading finishes, don't undo it. */
2103 Vautoload_queue = Qt;
2104 unbind_to (count, Qnil);
2106 fun = Findirect_function (fun, Qnil);
2108 if (!NILP (Fequal (fun, fundef)))
2109 error ("Autoloading failed to define function %s",
2110 SDATA (SYMBOL_NAME (funname)));
2111 UNGCPRO;
2115 DEFUN ("eval", Feval, Seval, 1, 1, 0,
2116 doc: /* Evaluate FORM and return its value. */)
2117 (form)
2118 Lisp_Object form;
2120 Lisp_Object fun, val, original_fun, original_args;
2121 Lisp_Object funcar;
2122 struct backtrace backtrace;
2123 struct gcpro gcpro1, gcpro2, gcpro3;
2125 if (handling_signal)
2126 abort ();
2128 if (SYMBOLP (form))
2129 return Fsymbol_value (form);
2130 if (!CONSP (form))
2131 return form;
2133 QUIT;
2134 if ((consing_since_gc > gc_cons_threshold
2135 && consing_since_gc > gc_relative_threshold)
2137 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2139 GCPRO1 (form);
2140 Fgarbage_collect ();
2141 UNGCPRO;
2144 if (++lisp_eval_depth > max_lisp_eval_depth)
2146 if (max_lisp_eval_depth < 100)
2147 max_lisp_eval_depth = 100;
2148 if (lisp_eval_depth > max_lisp_eval_depth)
2149 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2152 original_fun = Fcar (form);
2153 original_args = Fcdr (form);
2155 backtrace.next = backtrace_list;
2156 backtrace_list = &backtrace;
2157 backtrace.function = &original_fun; /* This also protects them from gc */
2158 backtrace.args = &original_args;
2159 backtrace.nargs = UNEVALLED;
2160 backtrace.evalargs = 1;
2161 backtrace.debug_on_exit = 0;
2163 if (debug_on_next_call)
2164 do_debug_on_call (Qt);
2166 /* At this point, only original_fun and original_args
2167 have values that will be used below */
2168 retry:
2169 fun = Findirect_function (original_fun, Qnil);
2171 if (SUBRP (fun))
2173 Lisp_Object numargs;
2174 Lisp_Object argvals[8];
2175 Lisp_Object args_left;
2176 register int i, maxargs;
2178 args_left = original_args;
2179 numargs = Flength (args_left);
2181 CHECK_CONS_LIST ();
2183 if (XINT (numargs) < XSUBR (fun)->min_args ||
2184 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
2185 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
2187 if (XSUBR (fun)->max_args == UNEVALLED)
2189 backtrace.evalargs = 0;
2190 val = (*XSUBR (fun)->function) (args_left);
2191 goto done;
2194 if (XSUBR (fun)->max_args == MANY)
2196 /* Pass a vector of evaluated arguments */
2197 Lisp_Object *vals;
2198 register int argnum = 0;
2200 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2202 GCPRO3 (args_left, fun, fun);
2203 gcpro3.var = vals;
2204 gcpro3.nvars = 0;
2206 while (!NILP (args_left))
2208 vals[argnum++] = Feval (Fcar (args_left));
2209 args_left = Fcdr (args_left);
2210 gcpro3.nvars = argnum;
2213 backtrace.args = vals;
2214 backtrace.nargs = XINT (numargs);
2216 val = (*XSUBR (fun)->function) (XINT (numargs), vals);
2217 UNGCPRO;
2218 goto done;
2221 GCPRO3 (args_left, fun, fun);
2222 gcpro3.var = argvals;
2223 gcpro3.nvars = 0;
2225 maxargs = XSUBR (fun)->max_args;
2226 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
2228 argvals[i] = Feval (Fcar (args_left));
2229 gcpro3.nvars = ++i;
2232 UNGCPRO;
2234 backtrace.args = argvals;
2235 backtrace.nargs = XINT (numargs);
2237 switch (i)
2239 case 0:
2240 val = (*XSUBR (fun)->function) ();
2241 goto done;
2242 case 1:
2243 val = (*XSUBR (fun)->function) (argvals[0]);
2244 goto done;
2245 case 2:
2246 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]);
2247 goto done;
2248 case 3:
2249 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2250 argvals[2]);
2251 goto done;
2252 case 4:
2253 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2254 argvals[2], argvals[3]);
2255 goto done;
2256 case 5:
2257 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2258 argvals[3], argvals[4]);
2259 goto done;
2260 case 6:
2261 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2262 argvals[3], argvals[4], argvals[5]);
2263 goto done;
2264 case 7:
2265 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2266 argvals[3], argvals[4], argvals[5],
2267 argvals[6]);
2268 goto done;
2270 case 8:
2271 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2272 argvals[3], argvals[4], argvals[5],
2273 argvals[6], argvals[7]);
2274 goto done;
2276 default:
2277 /* Someone has created a subr that takes more arguments than
2278 is supported by this code. We need to either rewrite the
2279 subr to use a different argument protocol, or add more
2280 cases to this switch. */
2281 abort ();
2284 if (COMPILEDP (fun))
2285 val = apply_lambda (fun, original_args, 1);
2286 else
2288 if (!CONSP (fun))
2289 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2290 funcar = Fcar (fun);
2291 if (!SYMBOLP (funcar))
2292 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2293 if (EQ (funcar, Qautoload))
2295 do_autoload (fun, original_fun);
2296 goto retry;
2298 if (EQ (funcar, Qmacro))
2299 val = Feval (apply1 (Fcdr (fun), original_args));
2300 else if (EQ (funcar, Qlambda))
2301 val = apply_lambda (fun, original_args, 1);
2302 else
2303 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2305 done:
2306 CHECK_CONS_LIST ();
2308 lisp_eval_depth--;
2309 if (backtrace.debug_on_exit)
2310 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2311 backtrace_list = backtrace.next;
2313 return val;
2316 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
2317 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2318 Then return the value FUNCTION returns.
2319 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2320 usage: (apply FUNCTION &rest ARGUMENTS) */)
2321 (nargs, args)
2322 int nargs;
2323 Lisp_Object *args;
2325 register int i, numargs;
2326 register Lisp_Object spread_arg;
2327 register Lisp_Object *funcall_args;
2328 Lisp_Object fun;
2329 struct gcpro gcpro1;
2331 fun = args [0];
2332 funcall_args = 0;
2333 spread_arg = args [nargs - 1];
2334 CHECK_LIST (spread_arg);
2336 numargs = XINT (Flength (spread_arg));
2338 if (numargs == 0)
2339 return Ffuncall (nargs - 1, args);
2340 else if (numargs == 1)
2342 args [nargs - 1] = XCAR (spread_arg);
2343 return Ffuncall (nargs, args);
2346 numargs += nargs - 2;
2348 fun = indirect_function (fun);
2349 if (EQ (fun, Qunbound))
2351 /* Let funcall get the error */
2352 fun = args[0];
2353 goto funcall;
2356 if (SUBRP (fun))
2358 if (numargs < XSUBR (fun)->min_args
2359 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2360 goto funcall; /* Let funcall get the error */
2361 else if (XSUBR (fun)->max_args > numargs)
2363 /* Avoid making funcall cons up a yet another new vector of arguments
2364 by explicitly supplying nil's for optional values */
2365 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
2366 * sizeof (Lisp_Object));
2367 for (i = numargs; i < XSUBR (fun)->max_args;)
2368 funcall_args[++i] = Qnil;
2369 GCPRO1 (*funcall_args);
2370 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
2373 funcall:
2374 /* We add 1 to numargs because funcall_args includes the
2375 function itself as well as its arguments. */
2376 if (!funcall_args)
2378 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
2379 * sizeof (Lisp_Object));
2380 GCPRO1 (*funcall_args);
2381 gcpro1.nvars = 1 + numargs;
2384 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
2385 /* Spread the last arg we got. Its first element goes in
2386 the slot that it used to occupy, hence this value of I. */
2387 i = nargs - 1;
2388 while (!NILP (spread_arg))
2390 funcall_args [i++] = XCAR (spread_arg);
2391 spread_arg = XCDR (spread_arg);
2394 /* By convention, the caller needs to gcpro Ffuncall's args. */
2395 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
2398 /* Run hook variables in various ways. */
2400 enum run_hooks_condition {to_completion, until_success, until_failure};
2401 static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *,
2402 enum run_hooks_condition));
2404 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
2405 doc: /* Run each hook in HOOKS.
2406 Each argument should be a symbol, a hook variable.
2407 These symbols are processed in the order specified.
2408 If a hook symbol has a non-nil value, that value may be a function
2409 or a list of functions to be called to run the hook.
2410 If the value is a function, it is called with no arguments.
2411 If it is a list, the elements are called, in order, with no arguments.
2413 Major modes should not use this function directly to run their mode
2414 hook; they should use `run-mode-hooks' instead.
2416 Do not use `make-local-variable' to make a hook variable buffer-local.
2417 Instead, use `add-hook' and specify t for the LOCAL argument.
2418 usage: (run-hooks &rest HOOKS) */)
2419 (nargs, args)
2420 int nargs;
2421 Lisp_Object *args;
2423 Lisp_Object hook[1];
2424 register int i;
2426 for (i = 0; i < nargs; i++)
2428 hook[0] = args[i];
2429 run_hook_with_args (1, hook, to_completion);
2432 return Qnil;
2435 DEFUN ("run-hook-with-args", Frun_hook_with_args,
2436 Srun_hook_with_args, 1, MANY, 0,
2437 doc: /* Run HOOK with the specified arguments ARGS.
2438 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2439 value, that value may be a function or a list of functions to be
2440 called to run the hook. If the value is a function, it is called with
2441 the given arguments and its return value is returned. If it is a list
2442 of functions, those functions are called, in order,
2443 with the given arguments ARGS.
2444 It is best not to depend on the value returned by `run-hook-with-args',
2445 as that may change.
2447 Do not use `make-local-variable' to make a hook variable buffer-local.
2448 Instead, use `add-hook' and specify t for the LOCAL argument.
2449 usage: (run-hook-with-args HOOK &rest ARGS) */)
2450 (nargs, args)
2451 int nargs;
2452 Lisp_Object *args;
2454 return run_hook_with_args (nargs, args, to_completion);
2457 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
2458 Srun_hook_with_args_until_success, 1, MANY, 0,
2459 doc: /* Run HOOK with the specified arguments ARGS.
2460 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2461 value, that value may be a function or a list of functions to be
2462 called to run the hook. If the value is a function, it is called with
2463 the given arguments and its return value is returned.
2464 If it is a list of functions, those functions are called, in order,
2465 with the given arguments ARGS, until one of them
2466 returns a non-nil value. Then we return that value.
2467 However, if they all return nil, we return nil.
2469 Do not use `make-local-variable' to make a hook variable buffer-local.
2470 Instead, use `add-hook' and specify t for the LOCAL argument.
2471 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2472 (nargs, args)
2473 int nargs;
2474 Lisp_Object *args;
2476 return run_hook_with_args (nargs, args, until_success);
2479 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
2480 Srun_hook_with_args_until_failure, 1, MANY, 0,
2481 doc: /* Run HOOK with the specified arguments ARGS.
2482 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2483 value, that value may be a function or a list of functions to be
2484 called to run the hook. If the value is a function, it is called with
2485 the given arguments and its return value is returned.
2486 If it is a list of functions, those functions are called, in order,
2487 with the given arguments ARGS, until one of them returns nil.
2488 Then we return nil. However, if they all return non-nil, we return non-nil.
2490 Do not use `make-local-variable' to make a hook variable buffer-local.
2491 Instead, use `add-hook' and specify t for the LOCAL argument.
2492 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2493 (nargs, args)
2494 int nargs;
2495 Lisp_Object *args;
2497 return run_hook_with_args (nargs, args, until_failure);
2500 /* ARGS[0] should be a hook symbol.
2501 Call each of the functions in the hook value, passing each of them
2502 as arguments all the rest of ARGS (all NARGS - 1 elements).
2503 COND specifies a condition to test after each call
2504 to decide whether to stop.
2505 The caller (or its caller, etc) must gcpro all of ARGS,
2506 except that it isn't necessary to gcpro ARGS[0]. */
2508 static Lisp_Object
2509 run_hook_with_args (nargs, args, cond)
2510 int nargs;
2511 Lisp_Object *args;
2512 enum run_hooks_condition cond;
2514 Lisp_Object sym, val, ret;
2515 Lisp_Object globals;
2516 struct gcpro gcpro1, gcpro2, gcpro3;
2518 /* If we are dying or still initializing,
2519 don't do anything--it would probably crash if we tried. */
2520 if (NILP (Vrun_hooks))
2521 return Qnil;
2523 sym = args[0];
2524 val = find_symbol_value (sym);
2525 ret = (cond == until_failure ? Qt : Qnil);
2527 if (EQ (val, Qunbound) || NILP (val))
2528 return ret;
2529 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
2531 args[0] = val;
2532 return Ffuncall (nargs, args);
2534 else
2536 globals = Qnil;
2537 GCPRO3 (sym, val, globals);
2539 for (;
2540 CONSP (val) && ((cond == to_completion)
2541 || (cond == until_success ? NILP (ret)
2542 : !NILP (ret)));
2543 val = XCDR (val))
2545 if (EQ (XCAR (val), Qt))
2547 /* t indicates this hook has a local binding;
2548 it means to run the global binding too. */
2550 for (globals = Fdefault_value (sym);
2551 CONSP (globals) && ((cond == to_completion)
2552 || (cond == until_success ? NILP (ret)
2553 : !NILP (ret)));
2554 globals = XCDR (globals))
2556 args[0] = XCAR (globals);
2557 /* In a global value, t should not occur. If it does, we
2558 must ignore it to avoid an endless loop. */
2559 if (!EQ (args[0], Qt))
2560 ret = Ffuncall (nargs, args);
2563 else
2565 args[0] = XCAR (val);
2566 ret = Ffuncall (nargs, args);
2570 UNGCPRO;
2571 return ret;
2575 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2576 present value of that symbol.
2577 Call each element of FUNLIST,
2578 passing each of them the rest of ARGS.
2579 The caller (or its caller, etc) must gcpro all of ARGS,
2580 except that it isn't necessary to gcpro ARGS[0]. */
2582 Lisp_Object
2583 run_hook_list_with_args (funlist, nargs, args)
2584 Lisp_Object funlist;
2585 int nargs;
2586 Lisp_Object *args;
2588 Lisp_Object sym;
2589 Lisp_Object val;
2590 Lisp_Object globals;
2591 struct gcpro gcpro1, gcpro2, gcpro3;
2593 sym = args[0];
2594 globals = Qnil;
2595 GCPRO3 (sym, val, globals);
2597 for (val = funlist; CONSP (val); val = XCDR (val))
2599 if (EQ (XCAR (val), Qt))
2601 /* t indicates this hook has a local binding;
2602 it means to run the global binding too. */
2604 for (globals = Fdefault_value (sym);
2605 CONSP (globals);
2606 globals = XCDR (globals))
2608 args[0] = XCAR (globals);
2609 /* In a global value, t should not occur. If it does, we
2610 must ignore it to avoid an endless loop. */
2611 if (!EQ (args[0], Qt))
2612 Ffuncall (nargs, args);
2615 else
2617 args[0] = XCAR (val);
2618 Ffuncall (nargs, args);
2621 UNGCPRO;
2622 return Qnil;
2625 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2627 void
2628 run_hook_with_args_2 (hook, arg1, arg2)
2629 Lisp_Object hook, arg1, arg2;
2631 Lisp_Object temp[3];
2632 temp[0] = hook;
2633 temp[1] = arg1;
2634 temp[2] = arg2;
2636 Frun_hook_with_args (3, temp);
2639 /* Apply fn to arg */
2640 Lisp_Object
2641 apply1 (fn, arg)
2642 Lisp_Object fn, arg;
2644 struct gcpro gcpro1;
2646 GCPRO1 (fn);
2647 if (NILP (arg))
2648 RETURN_UNGCPRO (Ffuncall (1, &fn));
2649 gcpro1.nvars = 2;
2650 #ifdef NO_ARG_ARRAY
2652 Lisp_Object args[2];
2653 args[0] = fn;
2654 args[1] = arg;
2655 gcpro1.var = args;
2656 RETURN_UNGCPRO (Fapply (2, args));
2658 #else /* not NO_ARG_ARRAY */
2659 RETURN_UNGCPRO (Fapply (2, &fn));
2660 #endif /* not NO_ARG_ARRAY */
2663 /* Call function fn on no arguments */
2664 Lisp_Object
2665 call0 (fn)
2666 Lisp_Object fn;
2668 struct gcpro gcpro1;
2670 GCPRO1 (fn);
2671 RETURN_UNGCPRO (Ffuncall (1, &fn));
2674 /* Call function fn with 1 argument arg1 */
2675 /* ARGSUSED */
2676 Lisp_Object
2677 call1 (fn, arg1)
2678 Lisp_Object fn, arg1;
2680 struct gcpro gcpro1;
2681 #ifdef NO_ARG_ARRAY
2682 Lisp_Object args[2];
2684 args[0] = fn;
2685 args[1] = arg1;
2686 GCPRO1 (args[0]);
2687 gcpro1.nvars = 2;
2688 RETURN_UNGCPRO (Ffuncall (2, args));
2689 #else /* not NO_ARG_ARRAY */
2690 GCPRO1 (fn);
2691 gcpro1.nvars = 2;
2692 RETURN_UNGCPRO (Ffuncall (2, &fn));
2693 #endif /* not NO_ARG_ARRAY */
2696 /* Call function fn with 2 arguments arg1, arg2 */
2697 /* ARGSUSED */
2698 Lisp_Object
2699 call2 (fn, arg1, arg2)
2700 Lisp_Object fn, arg1, arg2;
2702 struct gcpro gcpro1;
2703 #ifdef NO_ARG_ARRAY
2704 Lisp_Object args[3];
2705 args[0] = fn;
2706 args[1] = arg1;
2707 args[2] = arg2;
2708 GCPRO1 (args[0]);
2709 gcpro1.nvars = 3;
2710 RETURN_UNGCPRO (Ffuncall (3, args));
2711 #else /* not NO_ARG_ARRAY */
2712 GCPRO1 (fn);
2713 gcpro1.nvars = 3;
2714 RETURN_UNGCPRO (Ffuncall (3, &fn));
2715 #endif /* not NO_ARG_ARRAY */
2718 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2719 /* ARGSUSED */
2720 Lisp_Object
2721 call3 (fn, arg1, arg2, arg3)
2722 Lisp_Object fn, arg1, arg2, arg3;
2724 struct gcpro gcpro1;
2725 #ifdef NO_ARG_ARRAY
2726 Lisp_Object args[4];
2727 args[0] = fn;
2728 args[1] = arg1;
2729 args[2] = arg2;
2730 args[3] = arg3;
2731 GCPRO1 (args[0]);
2732 gcpro1.nvars = 4;
2733 RETURN_UNGCPRO (Ffuncall (4, args));
2734 #else /* not NO_ARG_ARRAY */
2735 GCPRO1 (fn);
2736 gcpro1.nvars = 4;
2737 RETURN_UNGCPRO (Ffuncall (4, &fn));
2738 #endif /* not NO_ARG_ARRAY */
2741 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2742 /* ARGSUSED */
2743 Lisp_Object
2744 call4 (fn, arg1, arg2, arg3, arg4)
2745 Lisp_Object fn, arg1, arg2, arg3, arg4;
2747 struct gcpro gcpro1;
2748 #ifdef NO_ARG_ARRAY
2749 Lisp_Object args[5];
2750 args[0] = fn;
2751 args[1] = arg1;
2752 args[2] = arg2;
2753 args[3] = arg3;
2754 args[4] = arg4;
2755 GCPRO1 (args[0]);
2756 gcpro1.nvars = 5;
2757 RETURN_UNGCPRO (Ffuncall (5, args));
2758 #else /* not NO_ARG_ARRAY */
2759 GCPRO1 (fn);
2760 gcpro1.nvars = 5;
2761 RETURN_UNGCPRO (Ffuncall (5, &fn));
2762 #endif /* not NO_ARG_ARRAY */
2765 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2766 /* ARGSUSED */
2767 Lisp_Object
2768 call5 (fn, arg1, arg2, arg3, arg4, arg5)
2769 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
2771 struct gcpro gcpro1;
2772 #ifdef NO_ARG_ARRAY
2773 Lisp_Object args[6];
2774 args[0] = fn;
2775 args[1] = arg1;
2776 args[2] = arg2;
2777 args[3] = arg3;
2778 args[4] = arg4;
2779 args[5] = arg5;
2780 GCPRO1 (args[0]);
2781 gcpro1.nvars = 6;
2782 RETURN_UNGCPRO (Ffuncall (6, args));
2783 #else /* not NO_ARG_ARRAY */
2784 GCPRO1 (fn);
2785 gcpro1.nvars = 6;
2786 RETURN_UNGCPRO (Ffuncall (6, &fn));
2787 #endif /* not NO_ARG_ARRAY */
2790 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2791 /* ARGSUSED */
2792 Lisp_Object
2793 call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
2794 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
2796 struct gcpro gcpro1;
2797 #ifdef NO_ARG_ARRAY
2798 Lisp_Object args[7];
2799 args[0] = fn;
2800 args[1] = arg1;
2801 args[2] = arg2;
2802 args[3] = arg3;
2803 args[4] = arg4;
2804 args[5] = arg5;
2805 args[6] = arg6;
2806 GCPRO1 (args[0]);
2807 gcpro1.nvars = 7;
2808 RETURN_UNGCPRO (Ffuncall (7, args));
2809 #else /* not NO_ARG_ARRAY */
2810 GCPRO1 (fn);
2811 gcpro1.nvars = 7;
2812 RETURN_UNGCPRO (Ffuncall (7, &fn));
2813 #endif /* not NO_ARG_ARRAY */
2816 /* The caller should GCPRO all the elements of ARGS. */
2818 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2819 doc: /* Call first argument as a function, passing remaining arguments to it.
2820 Return the value that function returns.
2821 Thus, (funcall 'cons 'x 'y) returns (x . y).
2822 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2823 (nargs, args)
2824 int nargs;
2825 Lisp_Object *args;
2827 Lisp_Object fun;
2828 Lisp_Object funcar;
2829 int numargs = nargs - 1;
2830 Lisp_Object lisp_numargs;
2831 Lisp_Object val;
2832 struct backtrace backtrace;
2833 register Lisp_Object *internal_args;
2834 register int i;
2836 QUIT;
2837 if ((consing_since_gc > gc_cons_threshold
2838 && consing_since_gc > gc_relative_threshold)
2840 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2841 Fgarbage_collect ();
2843 if (++lisp_eval_depth > max_lisp_eval_depth)
2845 if (max_lisp_eval_depth < 100)
2846 max_lisp_eval_depth = 100;
2847 if (lisp_eval_depth > max_lisp_eval_depth)
2848 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2851 backtrace.next = backtrace_list;
2852 backtrace_list = &backtrace;
2853 backtrace.function = &args[0];
2854 backtrace.args = &args[1];
2855 backtrace.nargs = nargs - 1;
2856 backtrace.evalargs = 0;
2857 backtrace.debug_on_exit = 0;
2859 if (debug_on_next_call)
2860 do_debug_on_call (Qlambda);
2862 CHECK_CONS_LIST ();
2864 retry:
2866 fun = args[0];
2868 fun = Findirect_function (fun, Qnil);
2870 if (SUBRP (fun))
2872 if (numargs < XSUBR (fun)->min_args
2873 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2875 XSETFASTINT (lisp_numargs, numargs);
2876 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
2879 if (XSUBR (fun)->max_args == UNEVALLED)
2880 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2882 if (XSUBR (fun)->max_args == MANY)
2884 val = (*XSUBR (fun)->function) (numargs, args + 1);
2885 goto done;
2888 if (XSUBR (fun)->max_args > numargs)
2890 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2891 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
2892 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2893 internal_args[i] = Qnil;
2895 else
2896 internal_args = args + 1;
2897 switch (XSUBR (fun)->max_args)
2899 case 0:
2900 val = (*XSUBR (fun)->function) ();
2901 goto done;
2902 case 1:
2903 val = (*XSUBR (fun)->function) (internal_args[0]);
2904 goto done;
2905 case 2:
2906 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1]);
2907 goto done;
2908 case 3:
2909 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2910 internal_args[2]);
2911 goto done;
2912 case 4:
2913 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2914 internal_args[2], internal_args[3]);
2915 goto done;
2916 case 5:
2917 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2918 internal_args[2], internal_args[3],
2919 internal_args[4]);
2920 goto done;
2921 case 6:
2922 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2923 internal_args[2], internal_args[3],
2924 internal_args[4], internal_args[5]);
2925 goto done;
2926 case 7:
2927 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2928 internal_args[2], internal_args[3],
2929 internal_args[4], internal_args[5],
2930 internal_args[6]);
2931 goto done;
2933 case 8:
2934 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2935 internal_args[2], internal_args[3],
2936 internal_args[4], internal_args[5],
2937 internal_args[6], internal_args[7]);
2938 goto done;
2940 default:
2942 /* If a subr takes more than 8 arguments without using MANY
2943 or UNEVALLED, we need to extend this function to support it.
2944 Until this is done, there is no way to call the function. */
2945 abort ();
2948 if (COMPILEDP (fun))
2949 val = funcall_lambda (fun, numargs, args + 1);
2950 else
2952 if (!CONSP (fun))
2953 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2954 funcar = Fcar (fun);
2955 if (!SYMBOLP (funcar))
2956 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2957 if (EQ (funcar, Qlambda))
2958 val = funcall_lambda (fun, numargs, args + 1);
2959 else if (EQ (funcar, Qautoload))
2961 do_autoload (fun, args[0]);
2962 CHECK_CONS_LIST ();
2963 goto retry;
2965 else
2966 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2968 done:
2969 CHECK_CONS_LIST ();
2970 lisp_eval_depth--;
2971 if (backtrace.debug_on_exit)
2972 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2973 backtrace_list = backtrace.next;
2974 return val;
2977 Lisp_Object
2978 apply_lambda (fun, args, eval_flag)
2979 Lisp_Object fun, args;
2980 int eval_flag;
2982 Lisp_Object args_left;
2983 Lisp_Object numargs;
2984 register Lisp_Object *arg_vector;
2985 struct gcpro gcpro1, gcpro2, gcpro3;
2986 register int i;
2987 register Lisp_Object tem;
2989 numargs = Flength (args);
2990 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2991 args_left = args;
2993 GCPRO3 (*arg_vector, args_left, fun);
2994 gcpro1.nvars = 0;
2996 for (i = 0; i < XINT (numargs);)
2998 tem = Fcar (args_left), args_left = Fcdr (args_left);
2999 if (eval_flag) tem = Feval (tem);
3000 arg_vector[i++] = tem;
3001 gcpro1.nvars = i;
3004 UNGCPRO;
3006 if (eval_flag)
3008 backtrace_list->args = arg_vector;
3009 backtrace_list->nargs = i;
3011 backtrace_list->evalargs = 0;
3012 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
3014 /* Do the debug-on-exit now, while arg_vector still exists. */
3015 if (backtrace_list->debug_on_exit)
3016 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
3017 /* Don't do it again when we return to eval. */
3018 backtrace_list->debug_on_exit = 0;
3019 return tem;
3022 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3023 and return the result of evaluation.
3024 FUN must be either a lambda-expression or a compiled-code object. */
3026 static Lisp_Object
3027 funcall_lambda (fun, nargs, arg_vector)
3028 Lisp_Object fun;
3029 int nargs;
3030 register Lisp_Object *arg_vector;
3032 Lisp_Object val, syms_left, next;
3033 int count = SPECPDL_INDEX ();
3034 int i, optional, rest;
3036 if (CONSP (fun))
3038 syms_left = XCDR (fun);
3039 if (CONSP (syms_left))
3040 syms_left = XCAR (syms_left);
3041 else
3042 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
3044 else if (COMPILEDP (fun))
3045 syms_left = AREF (fun, COMPILED_ARGLIST);
3046 else
3047 abort ();
3049 i = optional = rest = 0;
3050 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
3052 QUIT;
3054 next = XCAR (syms_left);
3055 while (!SYMBOLP (next))
3056 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
3058 if (EQ (next, Qand_rest))
3059 rest = 1;
3060 else if (EQ (next, Qand_optional))
3061 optional = 1;
3062 else if (rest)
3064 specbind (next, Flist (nargs - i, &arg_vector[i]));
3065 i = nargs;
3067 else if (i < nargs)
3068 specbind (next, arg_vector[i++]);
3069 else if (!optional)
3070 return Fsignal (Qwrong_number_of_arguments,
3071 Fcons (fun, Fcons (make_number (nargs), Qnil)));
3072 else
3073 specbind (next, Qnil);
3076 if (!NILP (syms_left))
3077 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
3078 else if (i < nargs)
3079 return Fsignal (Qwrong_number_of_arguments,
3080 Fcons (fun, Fcons (make_number (nargs), Qnil)));
3082 if (CONSP (fun))
3083 val = Fprogn (XCDR (XCDR (fun)));
3084 else
3086 /* If we have not actually read the bytecode string
3087 and constants vector yet, fetch them from the file. */
3088 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
3089 Ffetch_bytecode (fun);
3090 val = Fbyte_code (AREF (fun, COMPILED_BYTECODE),
3091 AREF (fun, COMPILED_CONSTANTS),
3092 AREF (fun, COMPILED_STACK_DEPTH));
3095 return unbind_to (count, val);
3098 DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
3099 1, 1, 0,
3100 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3101 (object)
3102 Lisp_Object object;
3104 Lisp_Object tem;
3106 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
3108 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
3109 if (!CONSP (tem))
3111 tem = AREF (object, COMPILED_BYTECODE);
3112 if (CONSP (tem) && STRINGP (XCAR (tem)))
3113 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
3114 else
3115 error ("Invalid byte code");
3117 AREF (object, COMPILED_BYTECODE) = XCAR (tem);
3118 AREF (object, COMPILED_CONSTANTS) = XCDR (tem);
3120 return object;
3123 void
3124 grow_specpdl ()
3126 register int count = SPECPDL_INDEX ();
3127 if (specpdl_size >= max_specpdl_size)
3129 if (max_specpdl_size < 400)
3130 max_specpdl_size = 400;
3131 if (specpdl_size >= max_specpdl_size)
3132 Fsignal (Qerror,
3133 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil));
3135 specpdl_size *= 2;
3136 if (specpdl_size > max_specpdl_size)
3137 specpdl_size = max_specpdl_size;
3138 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
3139 specpdl_ptr = specpdl + count;
3142 void
3143 specbind (symbol, value)
3144 Lisp_Object symbol, value;
3146 Lisp_Object ovalue;
3147 Lisp_Object valcontents;
3149 CHECK_SYMBOL (symbol);
3150 if (specpdl_ptr == specpdl + specpdl_size)
3151 grow_specpdl ();
3153 /* The most common case is that of a non-constant symbol with a
3154 trivial value. Make that as fast as we can. */
3155 valcontents = SYMBOL_VALUE (symbol);
3156 if (!MISCP (valcontents) && !SYMBOL_CONSTANT_P (symbol))
3158 specpdl_ptr->symbol = symbol;
3159 specpdl_ptr->old_value = valcontents;
3160 specpdl_ptr->func = NULL;
3161 ++specpdl_ptr;
3162 SET_SYMBOL_VALUE (symbol, value);
3164 else
3166 Lisp_Object valcontents;
3168 ovalue = find_symbol_value (symbol);
3169 specpdl_ptr->func = 0;
3170 specpdl_ptr->old_value = ovalue;
3172 valcontents = XSYMBOL (symbol)->value;
3174 if (BUFFER_LOCAL_VALUEP (valcontents)
3175 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
3176 || BUFFER_OBJFWDP (valcontents))
3178 Lisp_Object where, current_buffer;
3180 current_buffer = Fcurrent_buffer ();
3182 /* For a local variable, record both the symbol and which
3183 buffer's or frame's value we are saving. */
3184 if (!NILP (Flocal_variable_p (symbol, Qnil)))
3185 where = current_buffer;
3186 else if (!BUFFER_OBJFWDP (valcontents)
3187 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
3188 where = XBUFFER_LOCAL_VALUE (valcontents)->frame;
3189 else
3190 where = Qnil;
3192 /* We're not using the `unused' slot in the specbinding
3193 structure because this would mean we have to do more
3194 work for simple variables. */
3195 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, current_buffer));
3197 /* If SYMBOL is a per-buffer variable which doesn't have a
3198 buffer-local value here, make the `let' change the global
3199 value by changing the value of SYMBOL in all buffers not
3200 having their own value. This is consistent with what
3201 happens with other buffer-local variables. */
3202 if (NILP (where)
3203 && BUFFER_OBJFWDP (valcontents))
3205 ++specpdl_ptr;
3206 Fset_default (symbol, value);
3207 return;
3210 else
3211 specpdl_ptr->symbol = symbol;
3213 specpdl_ptr++;
3214 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
3215 store_symval_forwarding (symbol, ovalue, value, NULL);
3216 else
3217 set_internal (symbol, value, 0, 1);
3221 void
3222 record_unwind_protect (function, arg)
3223 Lisp_Object (*function) P_ ((Lisp_Object));
3224 Lisp_Object arg;
3226 eassert (!handling_signal);
3228 if (specpdl_ptr == specpdl + specpdl_size)
3229 grow_specpdl ();
3230 specpdl_ptr->func = function;
3231 specpdl_ptr->symbol = Qnil;
3232 specpdl_ptr->old_value = arg;
3233 specpdl_ptr++;
3236 Lisp_Object
3237 unbind_to (count, value)
3238 int count;
3239 Lisp_Object value;
3241 Lisp_Object quitf = Vquit_flag;
3242 struct gcpro gcpro1, gcpro2;
3244 GCPRO2 (value, quitf);
3245 Vquit_flag = Qnil;
3247 while (specpdl_ptr != specpdl + count)
3249 /* Copy the binding, and decrement specpdl_ptr, before we do
3250 the work to unbind it. We decrement first
3251 so that an error in unbinding won't try to unbind
3252 the same entry again, and we copy the binding first
3253 in case more bindings are made during some of the code we run. */
3255 struct specbinding this_binding;
3256 this_binding = *--specpdl_ptr;
3258 if (this_binding.func != 0)
3259 (*this_binding.func) (this_binding.old_value);
3260 /* If the symbol is a list, it is really (SYMBOL WHERE
3261 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3262 frame. If WHERE is a buffer or frame, this indicates we
3263 bound a variable that had a buffer-local or frame-local
3264 binding. WHERE nil means that the variable had the default
3265 value when it was bound. CURRENT-BUFFER is the buffer that
3266 was current when the variable was bound. */
3267 else if (CONSP (this_binding.symbol))
3269 Lisp_Object symbol, where;
3271 symbol = XCAR (this_binding.symbol);
3272 where = XCAR (XCDR (this_binding.symbol));
3274 if (NILP (where))
3275 Fset_default (symbol, this_binding.old_value);
3276 else if (BUFFERP (where))
3277 set_internal (symbol, this_binding.old_value, XBUFFER (where), 1);
3278 else
3279 set_internal (symbol, this_binding.old_value, NULL, 1);
3281 else
3283 /* If variable has a trivial value (no forwarding), we can
3284 just set it. No need to check for constant symbols here,
3285 since that was already done by specbind. */
3286 if (!MISCP (SYMBOL_VALUE (this_binding.symbol)))
3287 SET_SYMBOL_VALUE (this_binding.symbol, this_binding.old_value);
3288 else
3289 set_internal (this_binding.symbol, this_binding.old_value, 0, 1);
3293 if (NILP (Vquit_flag) && !NILP (quitf))
3294 Vquit_flag = quitf;
3296 UNGCPRO;
3297 return value;
3300 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
3301 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3302 The debugger is entered when that frame exits, if the flag is non-nil. */)
3303 (level, flag)
3304 Lisp_Object level, flag;
3306 register struct backtrace *backlist = backtrace_list;
3307 register int i;
3309 CHECK_NUMBER (level);
3311 for (i = 0; backlist && i < XINT (level); i++)
3313 backlist = backlist->next;
3316 if (backlist)
3317 backlist->debug_on_exit = !NILP (flag);
3319 return flag;
3322 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
3323 doc: /* Print a trace of Lisp function calls currently active.
3324 Output stream used is value of `standard-output'. */)
3327 register struct backtrace *backlist = backtrace_list;
3328 register int i;
3329 Lisp_Object tail;
3330 Lisp_Object tem;
3331 extern Lisp_Object Vprint_level;
3332 struct gcpro gcpro1;
3334 XSETFASTINT (Vprint_level, 3);
3336 tail = Qnil;
3337 GCPRO1 (tail);
3339 while (backlist)
3341 write_string (backlist->debug_on_exit ? "* " : " ", 2);
3342 if (backlist->nargs == UNEVALLED)
3344 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
3345 write_string ("\n", -1);
3347 else
3349 tem = *backlist->function;
3350 Fprin1 (tem, Qnil); /* This can QUIT */
3351 write_string ("(", -1);
3352 if (backlist->nargs == MANY)
3354 for (tail = *backlist->args, i = 0;
3355 !NILP (tail);
3356 tail = Fcdr (tail), i++)
3358 if (i) write_string (" ", -1);
3359 Fprin1 (Fcar (tail), Qnil);
3362 else
3364 for (i = 0; i < backlist->nargs; i++)
3366 if (i) write_string (" ", -1);
3367 Fprin1 (backlist->args[i], Qnil);
3370 write_string (")\n", -1);
3372 backlist = backlist->next;
3375 Vprint_level = Qnil;
3376 UNGCPRO;
3377 return Qnil;
3380 DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
3381 doc: /* Return the function and arguments NFRAMES up from current execution point.
3382 If that frame has not evaluated the arguments yet (or is a special form),
3383 the value is (nil FUNCTION ARG-FORMS...).
3384 If that frame has evaluated its arguments and called its function already,
3385 the value is (t FUNCTION ARG-VALUES...).
3386 A &rest arg is represented as the tail of the list ARG-VALUES.
3387 FUNCTION is whatever was supplied as car of evaluated list,
3388 or a lambda expression for macro calls.
3389 If NFRAMES is more than the number of frames, the value is nil. */)
3390 (nframes)
3391 Lisp_Object nframes;
3393 register struct backtrace *backlist = backtrace_list;
3394 register int i;
3395 Lisp_Object tem;
3397 CHECK_NATNUM (nframes);
3399 /* Find the frame requested. */
3400 for (i = 0; backlist && i < XFASTINT (nframes); i++)
3401 backlist = backlist->next;
3403 if (!backlist)
3404 return Qnil;
3405 if (backlist->nargs == UNEVALLED)
3406 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
3407 else
3409 if (backlist->nargs == MANY)
3410 tem = *backlist->args;
3411 else
3412 tem = Flist (backlist->nargs, backlist->args);
3414 return Fcons (Qt, Fcons (*backlist->function, tem));
3419 void
3420 mark_backtrace ()
3422 register struct backtrace *backlist;
3423 register int i;
3425 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3427 mark_object (*backlist->function);
3429 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
3430 i = 0;
3431 else
3432 i = backlist->nargs - 1;
3433 for (; i >= 0; i--)
3434 mark_object (backlist->args[i]);
3438 void
3439 syms_of_eval ()
3441 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
3442 doc: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
3443 If Lisp code tries to increase the total number past this amount,
3444 an error is signaled.
3445 You can safely use a value considerably larger than the default value,
3446 if that proves inconveniently small. However, if you increase it too far,
3447 Emacs could run out of memory trying to make the stack bigger. */);
3449 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
3450 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3452 This limit serves to catch infinite recursions for you before they cause
3453 actual stack overflow in C, which would be fatal for Emacs.
3454 You can safely make it considerably larger than its default value,
3455 if that proves inconveniently small. However, if you increase it too far,
3456 Emacs could overflow the real C stack, and crash. */);
3458 DEFVAR_LISP ("quit-flag", &Vquit_flag,
3459 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3460 If the value is t, that means do an ordinary quit.
3461 If the value equals `throw-on-input', that means quit by throwing
3462 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3463 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3464 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3465 Vquit_flag = Qnil;
3467 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
3468 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3469 Note that `quit-flag' will still be set by typing C-g,
3470 so a quit will be signaled as soon as `inhibit-quit' is nil.
3471 To prevent this happening, set `quit-flag' to nil
3472 before making `inhibit-quit' nil. */);
3473 Vinhibit_quit = Qnil;
3475 Qinhibit_quit = intern ("inhibit-quit");
3476 staticpro (&Qinhibit_quit);
3478 Qautoload = intern ("autoload");
3479 staticpro (&Qautoload);
3481 Qdebug_on_error = intern ("debug-on-error");
3482 staticpro (&Qdebug_on_error);
3484 Qmacro = intern ("macro");
3485 staticpro (&Qmacro);
3487 Qdeclare = intern ("declare");
3488 staticpro (&Qdeclare);
3490 /* Note that the process handling also uses Qexit, but we don't want
3491 to staticpro it twice, so we just do it here. */
3492 Qexit = intern ("exit");
3493 staticpro (&Qexit);
3495 Qinteractive = intern ("interactive");
3496 staticpro (&Qinteractive);
3498 Qcommandp = intern ("commandp");
3499 staticpro (&Qcommandp);
3501 Qdefun = intern ("defun");
3502 staticpro (&Qdefun);
3504 Qand_rest = intern ("&rest");
3505 staticpro (&Qand_rest);
3507 Qand_optional = intern ("&optional");
3508 staticpro (&Qand_optional);
3510 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
3511 doc: /* *Non-nil means errors display a backtrace buffer.
3512 More precisely, this happens for any error that is handled
3513 by the editor command loop.
3514 If the value is a list, an error only means to display a backtrace
3515 if one of its condition symbols appears in the list. */);
3516 Vstack_trace_on_error = Qnil;
3518 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
3519 doc: /* *Non-nil means enter debugger if an error is signaled.
3520 Does not apply to errors handled by `condition-case' or those
3521 matched by `debug-ignored-errors'.
3522 If the value is a list, an error only means to enter the debugger
3523 if one of its condition symbols appears in the list.
3524 When you evaluate an expression interactively, this variable
3525 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3526 See also variable `debug-on-quit'. */);
3527 Vdebug_on_error = Qnil;
3529 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors,
3530 doc: /* *List of errors for which the debugger should not be called.
3531 Each element may be a condition-name or a regexp that matches error messages.
3532 If any element applies to a given error, that error skips the debugger
3533 and just returns to top level.
3534 This overrides the variable `debug-on-error'.
3535 It does not apply to errors handled by `condition-case'. */);
3536 Vdebug_ignored_errors = Qnil;
3538 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
3539 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3540 Does not apply if quit is handled by a `condition-case'. */);
3541 debug_on_quit = 0;
3543 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
3544 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3546 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue,
3547 doc: /* Non-nil means debugger may continue execution.
3548 This is nil when the debugger is called under circumstances where it
3549 might not be safe to continue. */);
3550 debugger_may_continue = 1;
3552 DEFVAR_LISP ("debugger", &Vdebugger,
3553 doc: /* Function to call to invoke debugger.
3554 If due to frame exit, args are `exit' and the value being returned;
3555 this function's value will be returned instead of that.
3556 If due to error, args are `error' and a list of the args to `signal'.
3557 If due to `apply' or `funcall' entry, one arg, `lambda'.
3558 If due to `eval' entry, one arg, t. */);
3559 Vdebugger = Qnil;
3561 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function,
3562 doc: /* If non-nil, this is a function for `signal' to call.
3563 It receives the same arguments that `signal' was given.
3564 The Edebug package uses this to regain control. */);
3565 Vsignal_hook_function = Qnil;
3567 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal,
3568 doc: /* *Non-nil means call the debugger regardless of condition handlers.
3569 Note that `debug-on-error', `debug-on-quit' and friends
3570 still determine whether to handle the particular condition. */);
3571 Vdebug_on_signal = Qnil;
3573 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function,
3574 doc: /* Function to process declarations in a macro definition.
3575 The function will be called with two args MACRO and DECL.
3576 MACRO is the name of the macro being defined.
3577 DECL is a list `(declare ...)' containing the declarations.
3578 The value the function returns is not used. */);
3579 Vmacro_declaration_function = Qnil;
3581 Vrun_hooks = intern ("run-hooks");
3582 staticpro (&Vrun_hooks);
3584 staticpro (&Vautoload_queue);
3585 Vautoload_queue = Qnil;
3586 staticpro (&Vsignaling_function);
3587 Vsignaling_function = Qnil;
3589 defsubr (&Sor);
3590 defsubr (&Sand);
3591 defsubr (&Sif);
3592 defsubr (&Scond);
3593 defsubr (&Sprogn);
3594 defsubr (&Sprog1);
3595 defsubr (&Sprog2);
3596 defsubr (&Ssetq);
3597 defsubr (&Squote);
3598 defsubr (&Sfunction);
3599 defsubr (&Sdefun);
3600 defsubr (&Sdefmacro);
3601 defsubr (&Sdefvar);
3602 defsubr (&Sdefvaralias);
3603 defsubr (&Sdefconst);
3604 defsubr (&Suser_variable_p);
3605 defsubr (&Slet);
3606 defsubr (&SletX);
3607 defsubr (&Swhile);
3608 defsubr (&Smacroexpand);
3609 defsubr (&Scatch);
3610 defsubr (&Sthrow);
3611 defsubr (&Sunwind_protect);
3612 defsubr (&Scondition_case);
3613 defsubr (&Ssignal);
3614 defsubr (&Sinteractive_p);
3615 defsubr (&Scalled_interactively_p);
3616 defsubr (&Scommandp);
3617 defsubr (&Sautoload);
3618 defsubr (&Seval);
3619 defsubr (&Sapply);
3620 defsubr (&Sfuncall);
3621 defsubr (&Srun_hooks);
3622 defsubr (&Srun_hook_with_args);
3623 defsubr (&Srun_hook_with_args_until_success);
3624 defsubr (&Srun_hook_with_args_until_failure);
3625 defsubr (&Sfetch_bytecode);
3626 defsubr (&Sbacktrace_debug);
3627 defsubr (&Sbacktrace);
3628 defsubr (&Sbacktrace_frame);
3631 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3632 (do not change this comment) */