(picture-mode-exit): Run picture-mode-exit-hook.
[emacs.git] / src / eval.c
blob86ee384896c2b1f74bff9c705c4902f697c2332c
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;
199 static Lisp_Object funcall_lambda P_ ((Lisp_Object, int, Lisp_Object*));
201 void
202 init_eval_once ()
204 specpdl_size = 50;
205 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
206 specpdl_ptr = specpdl;
207 max_specpdl_size = 1000;
208 max_lisp_eval_depth = 300;
210 Vrun_hooks = Qnil;
213 void
214 init_eval ()
216 specpdl_ptr = specpdl;
217 catchlist = 0;
218 handlerlist = 0;
219 backtrace_list = 0;
220 Vquit_flag = Qnil;
221 debug_on_next_call = 0;
222 lisp_eval_depth = 0;
223 #ifdef DEBUG_GCPRO
224 gcpro_level = 0;
225 #endif
226 /* This is less than the initial value of num_nonmacro_input_events. */
227 when_entered_debugger = -1;
230 /* unwind-protect function used by call_debugger. */
232 static Lisp_Object
233 restore_stack_limits (data)
234 Lisp_Object data;
236 max_specpdl_size = XINT (XCAR (data));
237 max_lisp_eval_depth = XINT (XCDR (data));
238 return Qnil;
241 /* Call the Lisp debugger, giving it argument ARG. */
243 Lisp_Object
244 call_debugger (arg)
245 Lisp_Object arg;
247 int debug_while_redisplaying;
248 int count = SPECPDL_INDEX ();
249 Lisp_Object val;
250 int old_max = max_specpdl_size;
252 /* Temporarily bump up the stack limits,
253 so the debugger won't run out of stack. */
255 max_specpdl_size += 1;
256 record_unwind_protect (restore_stack_limits,
257 Fcons (make_number (old_max),
258 make_number (max_lisp_eval_depth)));
259 max_specpdl_size = old_max;
261 if (lisp_eval_depth + 40 > max_lisp_eval_depth)
262 max_lisp_eval_depth = lisp_eval_depth + 40;
264 if (SPECPDL_INDEX () + 100 > max_specpdl_size)
265 max_specpdl_size = SPECPDL_INDEX () + 100;
267 #ifdef HAVE_X_WINDOWS
268 if (display_hourglass_p)
269 cancel_hourglass ();
270 #endif
272 debug_on_next_call = 0;
273 when_entered_debugger = num_nonmacro_input_events;
275 /* Resetting redisplaying_p to 0 makes sure that debug output is
276 displayed if the debugger is invoked during redisplay. */
277 debug_while_redisplaying = redisplaying_p;
278 redisplaying_p = 0;
279 specbind (intern ("debugger-may-continue"),
280 debug_while_redisplaying ? Qnil : Qt);
281 specbind (Qinhibit_redisplay, Qnil);
282 specbind (Qdebug_on_error, Qnil);
284 #if 0 /* Binding this prevents execution of Lisp code during
285 redisplay, which necessarily leads to display problems. */
286 specbind (Qinhibit_eval_during_redisplay, Qt);
287 #endif
289 val = apply1 (Vdebugger, arg);
291 /* Interrupting redisplay and resuming it later is not safe under
292 all circumstances. So, when the debugger returns, abort the
293 interrupted redisplay by going back to the top-level. */
294 if (debug_while_redisplaying)
295 Ftop_level ();
297 return unbind_to (count, val);
300 void
301 do_debug_on_call (code)
302 Lisp_Object code;
304 debug_on_next_call = 0;
305 backtrace_list->debug_on_exit = 1;
306 call_debugger (Fcons (code, Qnil));
309 /* NOTE!!! Every function that can call EVAL must protect its args
310 and temporaries from garbage collection while it needs them.
311 The definition of `For' shows what you have to do. */
313 DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
314 doc: /* Eval args until one of them yields non-nil, then return that value.
315 The remaining args are not evalled at all.
316 If all args return nil, return nil.
317 usage: (or CONDITIONS ...) */)
318 (args)
319 Lisp_Object args;
321 register Lisp_Object val = Qnil;
322 struct gcpro gcpro1;
324 GCPRO1 (args);
326 while (CONSP (args))
328 val = Feval (XCAR (args));
329 if (!NILP (val))
330 break;
331 args = XCDR (args);
334 UNGCPRO;
335 return val;
338 DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
339 doc: /* Eval args until one of them yields nil, then return nil.
340 The remaining args are not evalled at all.
341 If no arg yields nil, return the last arg's value.
342 usage: (and CONDITIONS ...) */)
343 (args)
344 Lisp_Object args;
346 register Lisp_Object val = Qt;
347 struct gcpro gcpro1;
349 GCPRO1 (args);
351 while (CONSP (args))
353 val = Feval (XCAR (args));
354 if (NILP (val))
355 break;
356 args = XCDR (args);
359 UNGCPRO;
360 return val;
363 DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
364 doc: /* If COND yields non-nil, do THEN, else do ELSE...
365 Returns the value of THEN or the value of the last of the ELSE's.
366 THEN must be one expression, but ELSE... can be zero or more expressions.
367 If COND yields nil, and there are no ELSE's, the value is nil.
368 usage: (if COND THEN ELSE...) */)
369 (args)
370 Lisp_Object args;
372 register Lisp_Object cond;
373 struct gcpro gcpro1;
375 GCPRO1 (args);
376 cond = Feval (Fcar (args));
377 UNGCPRO;
379 if (!NILP (cond))
380 return Feval (Fcar (Fcdr (args)));
381 return Fprogn (Fcdr (Fcdr (args)));
384 DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
385 doc: /* Try each clause until one succeeds.
386 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
387 and, if the value is non-nil, this clause succeeds:
388 then the expressions in BODY are evaluated and the last one's
389 value is the value of the cond-form.
390 If no clause succeeds, cond returns nil.
391 If a clause has one element, as in (CONDITION),
392 CONDITION's value if non-nil is returned from the cond-form.
393 usage: (cond CLAUSES...) */)
394 (args)
395 Lisp_Object args;
397 register Lisp_Object clause, val;
398 struct gcpro gcpro1;
400 val = Qnil;
401 GCPRO1 (args);
402 while (!NILP (args))
404 clause = Fcar (args);
405 val = Feval (Fcar (clause));
406 if (!NILP (val))
408 if (!EQ (XCDR (clause), Qnil))
409 val = Fprogn (XCDR (clause));
410 break;
412 args = XCDR (args);
414 UNGCPRO;
416 return val;
419 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
420 doc: /* Eval BODY forms sequentially and return value of last one.
421 usage: (progn BODY ...) */)
422 (args)
423 Lisp_Object args;
425 register Lisp_Object val = Qnil;
426 struct gcpro gcpro1;
428 GCPRO1 (args);
430 while (CONSP (args))
432 val = Feval (XCAR (args));
433 args = XCDR (args);
436 UNGCPRO;
437 return val;
440 DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
441 doc: /* Eval FIRST and BODY sequentially; value from FIRST.
442 The value of FIRST is saved during the evaluation of the remaining args,
443 whose values are discarded.
444 usage: (prog1 FIRST BODY...) */)
445 (args)
446 Lisp_Object args;
448 Lisp_Object val;
449 register Lisp_Object args_left;
450 struct gcpro gcpro1, gcpro2;
451 register int argnum = 0;
453 if (NILP(args))
454 return Qnil;
456 args_left = args;
457 val = Qnil;
458 GCPRO2 (args, val);
462 if (!(argnum++))
463 val = Feval (Fcar (args_left));
464 else
465 Feval (Fcar (args_left));
466 args_left = Fcdr (args_left);
468 while (!NILP(args_left));
470 UNGCPRO;
471 return val;
474 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
475 doc: /* Eval FORM1, FORM2 and BODY sequentially; value from FORM2.
476 The value of FORM2 is saved during the evaluation of the
477 remaining args, whose values are discarded.
478 usage: (prog2 FORM1 FORM2 BODY...) */)
479 (args)
480 Lisp_Object args;
482 Lisp_Object val;
483 register Lisp_Object args_left;
484 struct gcpro gcpro1, gcpro2;
485 register int argnum = -1;
487 val = Qnil;
489 if (NILP (args))
490 return Qnil;
492 args_left = args;
493 val = Qnil;
494 GCPRO2 (args, val);
498 if (!(argnum++))
499 val = Feval (Fcar (args_left));
500 else
501 Feval (Fcar (args_left));
502 args_left = Fcdr (args_left);
504 while (!NILP (args_left));
506 UNGCPRO;
507 return val;
510 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
511 doc: /* Set each SYM to the value of its VAL.
512 The symbols SYM are variables; they are literal (not evaluated).
513 The values VAL are expressions; they are evaluated.
514 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
515 The second VAL is not computed until after the first SYM is set, and so on;
516 each VAL can use the new value of variables set earlier in the `setq'.
517 The return value of the `setq' form is the value of the last VAL.
518 usage: (setq SYM VAL SYM VAL ...) */)
519 (args)
520 Lisp_Object args;
522 register Lisp_Object args_left;
523 register Lisp_Object val, sym;
524 struct gcpro gcpro1;
526 if (NILP(args))
527 return Qnil;
529 args_left = args;
530 GCPRO1 (args);
534 val = Feval (Fcar (Fcdr (args_left)));
535 sym = Fcar (args_left);
536 Fset (sym, val);
537 args_left = Fcdr (Fcdr (args_left));
539 while (!NILP(args_left));
541 UNGCPRO;
542 return val;
545 DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
546 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
547 usage: (quote ARG) */)
548 (args)
549 Lisp_Object args;
551 return Fcar (args);
554 DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
555 doc: /* Like `quote', but preferred for objects which are functions.
556 In byte compilation, `function' causes its argument to be compiled.
557 `quote' cannot do that.
558 usage: (function ARG) */)
559 (args)
560 Lisp_Object args;
562 return Fcar (args);
566 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
567 doc: /* Return t if the function was run directly by user input.
568 This means that the function was called with `call-interactively'
569 \(which includes being called as the binding of a key)
570 and input is currently coming from the keyboard (not in keyboard macro),
571 and Emacs is not running in batch mode (`noninteractive' is nil).
573 The only known proper use of `interactive-p' is in deciding whether to
574 display a helpful message, or how to display it. If you're thinking
575 of using it for any other purpose, it is quite likely that you're
576 making a mistake. Think: what do you want to do when the command is
577 called from a keyboard macro?
579 If you want to test whether your function was called with
580 `call-interactively', the way to do that is by adding an extra
581 optional argument, and making the `interactive' spec specify non-nil
582 unconditionally for that argument. (`p' is a good way to do this.) */)
585 return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil;
589 DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 0, 0,
590 doc: /* Return t if the function using this was called with `call-interactively'.
591 This is used for implementing advice and other function-modifying
592 features of Emacs.
594 The cleanest way to test whether your function was called with
595 `call-interactively' is by adding an extra optional argument,
596 and making the `interactive' spec specify non-nil unconditionally
597 for that argument. (`p' is a good way to do this.) */)
600 return interactive_p (1) ? Qt : Qnil;
604 /* Return 1 if function in which this appears was called using
605 call-interactively.
607 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
608 called is a built-in. */
611 interactive_p (exclude_subrs_p)
612 int exclude_subrs_p;
614 struct backtrace *btp;
615 Lisp_Object fun;
617 btp = backtrace_list;
619 /* If this isn't a byte-compiled function, there may be a frame at
620 the top for Finteractive_p. If so, skip it. */
621 fun = Findirect_function (*btp->function, Qnil);
622 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
623 || XSUBR (fun) == &Scalled_interactively_p))
624 btp = btp->next;
626 /* If we're running an Emacs 18-style byte-compiled function, there
627 may be a frame for Fbytecode at the top level. In any version of
628 Emacs there can be Fbytecode frames for subexpressions evaluated
629 inside catch and condition-case. Skip past them.
631 If this isn't a byte-compiled function, then we may now be
632 looking at several frames for special forms. Skip past them. */
633 while (btp
634 && (EQ (*btp->function, Qbytecode)
635 || btp->nargs == UNEVALLED))
636 btp = btp->next;
638 /* btp now points at the frame of the innermost function that isn't
639 a special form, ignoring frames for Finteractive_p and/or
640 Fbytecode at the top. If this frame is for a built-in function
641 (such as load or eval-region) return nil. */
642 fun = Findirect_function (*btp->function, Qnil);
643 if (exclude_subrs_p && SUBRP (fun))
644 return 0;
646 /* btp points to the frame of a Lisp function that called interactive-p.
647 Return t if that function was called interactively. */
648 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
649 return 1;
650 return 0;
654 DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
655 doc: /* Define NAME as a function.
656 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
657 See also the function `interactive'.
658 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
659 (args)
660 Lisp_Object args;
662 register Lisp_Object fn_name;
663 register Lisp_Object defn;
665 fn_name = Fcar (args);
666 CHECK_SYMBOL (fn_name);
667 defn = Fcons (Qlambda, Fcdr (args));
668 if (!NILP (Vpurify_flag))
669 defn = Fpurecopy (defn);
670 if (CONSP (XSYMBOL (fn_name)->function)
671 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
672 LOADHIST_ATTACH (Fcons (Qt, fn_name));
673 Ffset (fn_name, defn);
674 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
675 return fn_name;
678 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
679 doc: /* Define NAME as a macro.
680 The actual definition looks like
681 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
682 When the macro is called, as in (NAME ARGS...),
683 the function (lambda ARGLIST BODY...) is applied to
684 the list ARGS... as it appears in the expression,
685 and the result should be a form to be evaluated instead of the original.
687 DECL is a declaration, optional, which can specify how to indent
688 calls to this macro and how Edebug should handle it. It looks like this:
689 (declare SPECS...)
690 The elements can look like this:
691 (indent INDENT)
692 Set NAME's `lisp-indent-function' property to INDENT.
694 (debug DEBUG)
695 Set NAME's `edebug-form-spec' property to DEBUG. (This is
696 equivalent to writing a `def-edebug-spec' for the macro.)
697 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
698 (args)
699 Lisp_Object args;
701 register Lisp_Object fn_name;
702 register Lisp_Object defn;
703 Lisp_Object lambda_list, doc, tail;
705 fn_name = Fcar (args);
706 CHECK_SYMBOL (fn_name);
707 lambda_list = Fcar (Fcdr (args));
708 tail = Fcdr (Fcdr (args));
710 doc = Qnil;
711 if (STRINGP (Fcar (tail)))
713 doc = XCAR (tail);
714 tail = XCDR (tail);
717 while (CONSP (Fcar (tail))
718 && EQ (Fcar (Fcar (tail)), Qdeclare))
720 if (!NILP (Vmacro_declaration_function))
722 struct gcpro gcpro1;
723 GCPRO1 (args);
724 call2 (Vmacro_declaration_function, fn_name, Fcar (tail));
725 UNGCPRO;
728 tail = Fcdr (tail);
731 if (NILP (doc))
732 tail = Fcons (lambda_list, tail);
733 else
734 tail = Fcons (lambda_list, Fcons (doc, tail));
735 defn = Fcons (Qmacro, Fcons (Qlambda, tail));
737 if (!NILP (Vpurify_flag))
738 defn = Fpurecopy (defn);
739 if (CONSP (XSYMBOL (fn_name)->function)
740 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
741 LOADHIST_ATTACH (Fcons (Qt, fn_name));
742 Ffset (fn_name, defn);
743 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
744 return fn_name;
748 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
749 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
750 Setting the value of NEW-ALIAS will subsequently set the value of BASE-VARIABLE,
751 and getting the value of NEW-ALIAS will return the value BASE-VARIABLE has.
752 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
753 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
754 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
755 itself an alias.
756 The return value is BASE-VARIABLE. */)
757 (new_alias, base_variable, docstring)
758 Lisp_Object new_alias, base_variable, docstring;
760 struct Lisp_Symbol *sym;
762 CHECK_SYMBOL (new_alias);
763 CHECK_SYMBOL (base_variable);
765 if (SYMBOL_CONSTANT_P (new_alias))
766 error ("Cannot make a constant an alias");
768 sym = XSYMBOL (new_alias);
769 sym->indirect_variable = 1;
770 sym->value = base_variable;
771 sym->constant = SYMBOL_CONSTANT_P (base_variable);
772 LOADHIST_ATTACH (new_alias);
773 if (!NILP (docstring))
774 Fput (new_alias, Qvariable_documentation, docstring);
775 else
776 Fput (new_alias, Qvariable_documentation, Qnil);
778 return base_variable;
782 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
783 doc: /* Define SYMBOL as a variable, and return SYMBOL.
784 You are not required to define a variable in order to use it,
785 but the definition can supply documentation and an initial value
786 in a way that tags can recognize.
788 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
789 If SYMBOL is buffer-local, its default value is what is set;
790 buffer-local values are not affected.
791 INITVALUE and DOCSTRING are optional.
792 If DOCSTRING starts with *, this variable is identified as a user option.
793 This means that M-x set-variable recognizes it.
794 See also `user-variable-p'.
795 If INITVALUE is missing, SYMBOL's value is not set.
797 If SYMBOL has a local binding, then this form affects the local
798 binding. This is usually not what you want. Thus, if you need to
799 load a file defining variables, with this form or with `defconst' or
800 `defcustom', you should always load that file _outside_ any bindings
801 for these variables. \(`defconst' and `defcustom' behave similarly in
802 this respect.)
803 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
804 (args)
805 Lisp_Object args;
807 register Lisp_Object sym, tem, tail;
809 sym = Fcar (args);
810 tail = Fcdr (args);
811 if (!NILP (Fcdr (Fcdr (tail))))
812 error ("Too many arguments");
814 tem = Fdefault_boundp (sym);
815 if (!NILP (tail))
817 if (SYMBOL_CONSTANT_P (sym))
819 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
820 Lisp_Object tem = Fcar (tail);
821 if (! (CONSP (tem)
822 && EQ (XCAR (tem), Qquote)
823 && CONSP (XCDR (tem))
824 && EQ (XCAR (XCDR (tem)), sym)))
825 error ("Constant symbol `%s' specified in defvar",
826 SDATA (SYMBOL_NAME (sym)));
829 if (NILP (tem))
830 Fset_default (sym, Feval (Fcar (tail)));
831 else
832 { /* Check if there is really a global binding rather than just a let
833 binding that shadows the global unboundness of the var. */
834 volatile struct specbinding *pdl = specpdl_ptr;
835 while (--pdl >= specpdl)
837 if (EQ (pdl->symbol, sym) && !pdl->func
838 && EQ (pdl->old_value, Qunbound))
840 message_with_string ("Warning: defvar ignored because %s is let-bound",
841 SYMBOL_NAME (sym), 1);
842 break;
846 tail = Fcdr (tail);
847 tem = Fcar (tail);
848 if (!NILP (tem))
850 if (!NILP (Vpurify_flag))
851 tem = Fpurecopy (tem);
852 Fput (sym, Qvariable_documentation, tem);
854 LOADHIST_ATTACH (sym);
856 else
857 /* Simple (defvar <var>) should not count as a definition at all.
858 It could get in the way of other definitions, and unloading this
859 package could try to make the variable unbound. */
862 return sym;
865 DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
866 doc: /* Define SYMBOL as a constant variable.
867 The intent is that neither programs nor users should ever change this value.
868 Always sets the value of SYMBOL to the result of evalling INITVALUE.
869 If SYMBOL is buffer-local, its default value is what is set;
870 buffer-local values are not affected.
871 DOCSTRING is optional.
873 If SYMBOL has a local binding, then this form sets the local binding's
874 value. However, you should normally not make local bindings for
875 variables defined with this form.
876 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
877 (args)
878 Lisp_Object args;
880 register Lisp_Object sym, tem;
882 sym = Fcar (args);
883 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
884 error ("Too many arguments");
886 tem = Feval (Fcar (Fcdr (args)));
887 if (!NILP (Vpurify_flag))
888 tem = Fpurecopy (tem);
889 Fset_default (sym, tem);
890 tem = Fcar (Fcdr (Fcdr (args)));
891 if (!NILP (tem))
893 if (!NILP (Vpurify_flag))
894 tem = Fpurecopy (tem);
895 Fput (sym, Qvariable_documentation, tem);
897 LOADHIST_ATTACH (sym);
898 return sym;
901 /* Error handler used in Fuser_variable_p. */
902 static Lisp_Object
903 user_variable_p_eh (ignore)
904 Lisp_Object ignore;
906 return Qnil;
909 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
910 doc: /* Return t if VARIABLE is intended to be set and modified by users.
911 \(The alternative is a variable used internally in a Lisp program.)
912 A variable is a user variable if
913 \(1) the first character of its documentation is `*', or
914 \(2) it is customizable (its property list contains a non-nil value
915 of `standard-value' or `custom-autoload'), or
916 \(3) it is an alias for another user variable.
917 Return nil if VARIABLE is an alias and there is a loop in the
918 chain of symbols. */)
919 (variable)
920 Lisp_Object variable;
922 Lisp_Object documentation;
924 if (!SYMBOLP (variable))
925 return Qnil;
927 /* If indirect and there's an alias loop, don't check anything else. */
928 if (XSYMBOL (variable)->indirect_variable
929 && NILP (internal_condition_case_1 (indirect_variable, variable,
930 Qt, user_variable_p_eh)))
931 return Qnil;
933 while (1)
935 documentation = Fget (variable, Qvariable_documentation);
936 if (INTEGERP (documentation) && XINT (documentation) < 0)
937 return Qt;
938 if (STRINGP (documentation)
939 && ((unsigned char) SREF (documentation, 0) == '*'))
940 return Qt;
941 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
942 if (CONSP (documentation)
943 && STRINGP (XCAR (documentation))
944 && INTEGERP (XCDR (documentation))
945 && XINT (XCDR (documentation)) < 0)
946 return Qt;
947 /* Customizable? See `custom-variable-p'. */
948 if ((!NILP (Fget (variable, intern ("standard-value"))))
949 || (!NILP (Fget (variable, intern ("custom-autoload")))))
950 return Qt;
952 if (!XSYMBOL (variable)->indirect_variable)
953 return Qnil;
955 /* An indirect variable? Let's follow the chain. */
956 variable = XSYMBOL (variable)->value;
960 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
961 doc: /* Bind variables according to VARLIST then eval BODY.
962 The value of the last form in BODY is returned.
963 Each element of VARLIST is a symbol (which is bound to nil)
964 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
965 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
966 usage: (let* VARLIST BODY...) */)
967 (args)
968 Lisp_Object args;
970 Lisp_Object varlist, val, elt;
971 int count = SPECPDL_INDEX ();
972 struct gcpro gcpro1, gcpro2, gcpro3;
974 GCPRO3 (args, elt, varlist);
976 varlist = Fcar (args);
977 while (!NILP (varlist))
979 QUIT;
980 elt = Fcar (varlist);
981 if (SYMBOLP (elt))
982 specbind (elt, Qnil);
983 else if (! NILP (Fcdr (Fcdr (elt))))
984 Fsignal (Qerror,
985 Fcons (build_string ("`let' bindings can have only one value-form"),
986 elt));
987 else
989 val = Feval (Fcar (Fcdr (elt)));
990 specbind (Fcar (elt), val);
992 varlist = Fcdr (varlist);
994 UNGCPRO;
995 val = Fprogn (Fcdr (args));
996 return unbind_to (count, val);
999 DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
1000 doc: /* Bind variables according to VARLIST then eval BODY.
1001 The value of the last form in BODY is returned.
1002 Each element of VARLIST is a symbol (which is bound to nil)
1003 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1004 All the VALUEFORMs are evalled before any symbols are bound.
1005 usage: (let VARLIST BODY...) */)
1006 (args)
1007 Lisp_Object args;
1009 Lisp_Object *temps, tem;
1010 register Lisp_Object elt, varlist;
1011 int count = SPECPDL_INDEX ();
1012 register int argnum;
1013 struct gcpro gcpro1, gcpro2;
1015 varlist = Fcar (args);
1017 /* Make space to hold the values to give the bound variables */
1018 elt = Flength (varlist);
1019 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object));
1021 /* Compute the values and store them in `temps' */
1023 GCPRO2 (args, *temps);
1024 gcpro2.nvars = 0;
1026 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
1028 QUIT;
1029 elt = Fcar (varlist);
1030 if (SYMBOLP (elt))
1031 temps [argnum++] = Qnil;
1032 else if (! NILP (Fcdr (Fcdr (elt))))
1033 Fsignal (Qerror,
1034 Fcons (build_string ("`let' bindings can have only one value-form"),
1035 elt));
1036 else
1037 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
1038 gcpro2.nvars = argnum;
1040 UNGCPRO;
1042 varlist = Fcar (args);
1043 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
1045 elt = Fcar (varlist);
1046 tem = temps[argnum++];
1047 if (SYMBOLP (elt))
1048 specbind (elt, tem);
1049 else
1050 specbind (Fcar (elt), tem);
1053 elt = Fprogn (Fcdr (args));
1054 return unbind_to (count, elt);
1057 DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
1058 doc: /* If TEST yields non-nil, eval BODY... and repeat.
1059 The order of execution is thus TEST, BODY, TEST, BODY and so on
1060 until TEST returns nil.
1061 usage: (while TEST BODY...) */)
1062 (args)
1063 Lisp_Object args;
1065 Lisp_Object test, body;
1066 struct gcpro gcpro1, gcpro2;
1068 GCPRO2 (test, body);
1070 test = Fcar (args);
1071 body = Fcdr (args);
1072 while (!NILP (Feval (test)))
1074 QUIT;
1075 Fprogn (body);
1078 UNGCPRO;
1079 return Qnil;
1082 DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
1083 doc: /* Return result of expanding macros at top level of FORM.
1084 If FORM is not a macro call, it is returned unchanged.
1085 Otherwise, the macro is expanded and the expansion is considered
1086 in place of FORM. When a non-macro-call results, it is returned.
1088 The second optional arg ENVIRONMENT specifies an environment of macro
1089 definitions to shadow the loaded ones for use in file byte-compilation. */)
1090 (form, environment)
1091 Lisp_Object form;
1092 Lisp_Object environment;
1094 /* With cleanups from Hallvard Furuseth. */
1095 register Lisp_Object expander, sym, def, tem;
1097 while (1)
1099 /* Come back here each time we expand a macro call,
1100 in case it expands into another macro call. */
1101 if (!CONSP (form))
1102 break;
1103 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1104 def = sym = XCAR (form);
1105 tem = Qnil;
1106 /* Trace symbols aliases to other symbols
1107 until we get a symbol that is not an alias. */
1108 while (SYMBOLP (def))
1110 QUIT;
1111 sym = def;
1112 tem = Fassq (sym, environment);
1113 if (NILP (tem))
1115 def = XSYMBOL (sym)->function;
1116 if (!EQ (def, Qunbound))
1117 continue;
1119 break;
1121 /* Right now TEM is the result from SYM in ENVIRONMENT,
1122 and if TEM is nil then DEF is SYM's function definition. */
1123 if (NILP (tem))
1125 /* SYM is not mentioned in ENVIRONMENT.
1126 Look at its function definition. */
1127 if (EQ (def, Qunbound) || !CONSP (def))
1128 /* Not defined or definition not suitable */
1129 break;
1130 if (EQ (XCAR (def), Qautoload))
1132 /* Autoloading function: will it be a macro when loaded? */
1133 tem = Fnth (make_number (4), def);
1134 if (EQ (tem, Qt) || EQ (tem, Qmacro))
1135 /* Yes, load it and try again. */
1137 struct gcpro gcpro1;
1138 GCPRO1 (form);
1139 do_autoload (def, sym);
1140 UNGCPRO;
1141 continue;
1143 else
1144 break;
1146 else if (!EQ (XCAR (def), Qmacro))
1147 break;
1148 else expander = XCDR (def);
1150 else
1152 expander = XCDR (tem);
1153 if (NILP (expander))
1154 break;
1156 form = apply1 (expander, XCDR (form));
1158 return form;
1161 DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
1162 doc: /* Eval BODY allowing nonlocal exits using `throw'.
1163 TAG is evalled to get the tag to use; it must not be nil.
1165 Then the BODY is executed.
1166 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1167 If no throw happens, `catch' returns the value of the last BODY form.
1168 If a throw happens, it specifies the value to return from `catch'.
1169 usage: (catch TAG BODY...) */)
1170 (args)
1171 Lisp_Object args;
1173 register Lisp_Object tag;
1174 struct gcpro gcpro1;
1176 GCPRO1 (args);
1177 tag = Feval (Fcar (args));
1178 UNGCPRO;
1179 return internal_catch (tag, Fprogn, Fcdr (args));
1182 /* Set up a catch, then call C function FUNC on argument ARG.
1183 FUNC should return a Lisp_Object.
1184 This is how catches are done from within C code. */
1186 Lisp_Object
1187 internal_catch (tag, func, arg)
1188 Lisp_Object tag;
1189 Lisp_Object (*func) ();
1190 Lisp_Object arg;
1192 /* This structure is made part of the chain `catchlist'. */
1193 struct catchtag c;
1195 /* Fill in the components of c, and put it on the list. */
1196 c.next = catchlist;
1197 c.tag = tag;
1198 c.val = Qnil;
1199 c.backlist = backtrace_list;
1200 c.handlerlist = handlerlist;
1201 c.lisp_eval_depth = lisp_eval_depth;
1202 c.pdlcount = SPECPDL_INDEX ();
1203 c.poll_suppress_count = poll_suppress_count;
1204 c.interrupt_input_blocked = interrupt_input_blocked;
1205 c.gcpro = gcprolist;
1206 c.byte_stack = byte_stack_list;
1207 catchlist = &c;
1209 /* Call FUNC. */
1210 if (! _setjmp (c.jmp))
1211 c.val = (*func) (arg);
1213 /* Throw works by a longjmp that comes right here. */
1214 catchlist = c.next;
1215 return c.val;
1218 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1219 jump to that CATCH, returning VALUE as the value of that catch.
1221 This is the guts Fthrow and Fsignal; they differ only in the way
1222 they choose the catch tag to throw to. A catch tag for a
1223 condition-case form has a TAG of Qnil.
1225 Before each catch is discarded, unbind all special bindings and
1226 execute all unwind-protect clauses made above that catch. Unwind
1227 the handler stack as we go, so that the proper handlers are in
1228 effect for each unwind-protect clause we run. At the end, restore
1229 some static info saved in CATCH, and longjmp to the location
1230 specified in the
1232 This is used for correct unwinding in Fthrow and Fsignal. */
1234 static void
1235 unwind_to_catch (catch, value)
1236 struct catchtag *catch;
1237 Lisp_Object value;
1239 register int last_time;
1241 /* Save the value in the tag. */
1242 catch->val = value;
1244 /* Restore certain special C variables. */
1245 set_poll_suppress_count (catch->poll_suppress_count);
1246 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked);
1247 handling_signal = 0;
1248 immediate_quit = 0;
1252 last_time = catchlist == catch;
1254 /* Unwind the specpdl stack, and then restore the proper set of
1255 handlers. */
1256 unbind_to (catchlist->pdlcount, Qnil);
1257 handlerlist = catchlist->handlerlist;
1258 catchlist = catchlist->next;
1260 while (! last_time);
1262 #if HAVE_X_WINDOWS
1263 /* If x_catch_errors was done, turn it off now.
1264 (First we give unbind_to a chance to do that.) */
1265 x_fully_uncatch_errors ();
1266 #endif
1268 byte_stack_list = catch->byte_stack;
1269 gcprolist = catch->gcpro;
1270 #ifdef DEBUG_GCPRO
1271 if (gcprolist != 0)
1272 gcpro_level = gcprolist->level + 1;
1273 else
1274 gcpro_level = 0;
1275 #endif
1276 backtrace_list = catch->backlist;
1277 lisp_eval_depth = catch->lisp_eval_depth;
1279 _longjmp (catch->jmp, 1);
1282 DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
1283 doc: /* Throw to the catch for TAG and return VALUE from it.
1284 Both TAG and VALUE are evalled. */)
1285 (tag, value)
1286 register Lisp_Object tag, value;
1288 register struct catchtag *c;
1290 while (1)
1292 if (!NILP (tag))
1293 for (c = catchlist; c; c = c->next)
1295 if (EQ (c->tag, tag))
1296 unwind_to_catch (c, value);
1298 tag = Fsignal (Qno_catch, Fcons (tag, Fcons (value, Qnil)));
1303 DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
1304 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
1305 If BODYFORM completes normally, its value is returned
1306 after executing the UNWINDFORMS.
1307 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1308 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1309 (args)
1310 Lisp_Object args;
1312 Lisp_Object val;
1313 int count = SPECPDL_INDEX ();
1315 record_unwind_protect (Fprogn, Fcdr (args));
1316 val = Feval (Fcar (args));
1317 return unbind_to (count, val);
1320 /* Chain of condition handlers currently in effect.
1321 The elements of this chain are contained in the stack frames
1322 of Fcondition_case and internal_condition_case.
1323 When an error is signaled (by calling Fsignal, below),
1324 this chain is searched for an element that applies. */
1326 struct handler *handlerlist;
1328 DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
1329 doc: /* Regain control when an error is signaled.
1330 Executes BODYFORM and returns its value if no error happens.
1331 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1332 where the BODY is made of Lisp expressions.
1334 A handler is applicable to an error
1335 if CONDITION-NAME is one of the error's condition names.
1336 If an error happens, the first applicable handler is run.
1338 The car of a handler may be a list of condition names
1339 instead of a single condition name.
1341 When a handler handles an error,
1342 control returns to the condition-case and the handler BODY... is executed
1343 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1344 VAR may be nil; then you do not get access to the signal information.
1346 The value of the last BODY form is returned from the condition-case.
1347 See also the function `signal' for more info.
1348 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1349 (args)
1350 Lisp_Object args;
1352 register Lisp_Object bodyform, handlers;
1353 volatile Lisp_Object var;
1355 var = Fcar (args);
1356 bodyform = Fcar (Fcdr (args));
1357 handlers = Fcdr (Fcdr (args));
1359 return internal_lisp_condition_case (var, bodyform, handlers);
1362 /* Like Fcondition_case, but the args are separate
1363 rather than passed in a list. Used by Fbyte_code. */
1365 Lisp_Object
1366 internal_lisp_condition_case (var, bodyform, handlers)
1367 volatile Lisp_Object var;
1368 Lisp_Object bodyform, handlers;
1370 Lisp_Object val;
1371 struct catchtag c;
1372 struct handler h;
1374 CHECK_SYMBOL (var);
1376 for (val = handlers; CONSP (val); val = XCDR (val))
1378 Lisp_Object tem;
1379 tem = XCAR (val);
1380 if (! (NILP (tem)
1381 || (CONSP (tem)
1382 && (SYMBOLP (XCAR (tem))
1383 || CONSP (XCAR (tem))))))
1384 error ("Invalid condition handler", tem);
1387 c.tag = Qnil;
1388 c.val = Qnil;
1389 c.backlist = backtrace_list;
1390 c.handlerlist = handlerlist;
1391 c.lisp_eval_depth = lisp_eval_depth;
1392 c.pdlcount = SPECPDL_INDEX ();
1393 c.poll_suppress_count = poll_suppress_count;
1394 c.interrupt_input_blocked = interrupt_input_blocked;
1395 c.gcpro = gcprolist;
1396 c.byte_stack = byte_stack_list;
1397 if (_setjmp (c.jmp))
1399 if (!NILP (h.var))
1400 specbind (h.var, c.val);
1401 val = Fprogn (Fcdr (h.chosen_clause));
1403 /* Note that this just undoes the binding of h.var; whoever
1404 longjumped to us unwound the stack to c.pdlcount before
1405 throwing. */
1406 unbind_to (c.pdlcount, Qnil);
1407 return val;
1409 c.next = catchlist;
1410 catchlist = &c;
1412 h.var = var;
1413 h.handler = handlers;
1414 h.next = handlerlist;
1415 h.tag = &c;
1416 handlerlist = &h;
1418 val = Feval (bodyform);
1419 catchlist = c.next;
1420 handlerlist = h.next;
1421 return val;
1424 /* Call the function BFUN with no arguments, catching errors within it
1425 according to HANDLERS. If there is an error, call HFUN with
1426 one argument which is the data that describes the error:
1427 (SIGNALNAME . DATA)
1429 HANDLERS can be a list of conditions to catch.
1430 If HANDLERS is Qt, catch all errors.
1431 If HANDLERS is Qerror, catch all errors
1432 but allow the debugger to run if that is enabled. */
1434 Lisp_Object
1435 internal_condition_case (bfun, handlers, hfun)
1436 Lisp_Object (*bfun) ();
1437 Lisp_Object handlers;
1438 Lisp_Object (*hfun) ();
1440 Lisp_Object val;
1441 struct catchtag c;
1442 struct handler h;
1444 /* Since Fsignal will close off all calls to x_catch_errors,
1445 we will get the wrong results if some are not closed now. */
1446 #if HAVE_X_WINDOWS
1447 if (x_catching_errors ())
1448 abort ();
1449 #endif
1451 c.tag = Qnil;
1452 c.val = Qnil;
1453 c.backlist = backtrace_list;
1454 c.handlerlist = handlerlist;
1455 c.lisp_eval_depth = lisp_eval_depth;
1456 c.pdlcount = SPECPDL_INDEX ();
1457 c.poll_suppress_count = poll_suppress_count;
1458 c.interrupt_input_blocked = interrupt_input_blocked;
1459 c.gcpro = gcprolist;
1460 c.byte_stack = byte_stack_list;
1461 if (_setjmp (c.jmp))
1463 return (*hfun) (c.val);
1465 c.next = catchlist;
1466 catchlist = &c;
1467 h.handler = handlers;
1468 h.var = Qnil;
1469 h.next = handlerlist;
1470 h.tag = &c;
1471 handlerlist = &h;
1473 val = (*bfun) ();
1474 catchlist = c.next;
1475 handlerlist = h.next;
1476 return val;
1479 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1481 Lisp_Object
1482 internal_condition_case_1 (bfun, arg, handlers, hfun)
1483 Lisp_Object (*bfun) ();
1484 Lisp_Object arg;
1485 Lisp_Object handlers;
1486 Lisp_Object (*hfun) ();
1488 Lisp_Object val;
1489 struct catchtag c;
1490 struct handler h;
1492 /* Since Fsignal will close off all calls to x_catch_errors,
1493 we will get the wrong results if some are not closed now. */
1494 #if HAVE_X_WINDOWS
1495 if (x_catching_errors ())
1496 abort ();
1497 #endif
1499 c.tag = Qnil;
1500 c.val = Qnil;
1501 c.backlist = backtrace_list;
1502 c.handlerlist = handlerlist;
1503 c.lisp_eval_depth = lisp_eval_depth;
1504 c.pdlcount = SPECPDL_INDEX ();
1505 c.poll_suppress_count = poll_suppress_count;
1506 c.interrupt_input_blocked = interrupt_input_blocked;
1507 c.gcpro = gcprolist;
1508 c.byte_stack = byte_stack_list;
1509 if (_setjmp (c.jmp))
1511 return (*hfun) (c.val);
1513 c.next = catchlist;
1514 catchlist = &c;
1515 h.handler = handlers;
1516 h.var = Qnil;
1517 h.next = handlerlist;
1518 h.tag = &c;
1519 handlerlist = &h;
1521 val = (*bfun) (arg);
1522 catchlist = c.next;
1523 handlerlist = h.next;
1524 return val;
1528 /* Like internal_condition_case but call BFUN with NARGS as first,
1529 and ARGS as second argument. */
1531 Lisp_Object
1532 internal_condition_case_2 (bfun, nargs, args, handlers, hfun)
1533 Lisp_Object (*bfun) ();
1534 int nargs;
1535 Lisp_Object *args;
1536 Lisp_Object handlers;
1537 Lisp_Object (*hfun) ();
1539 Lisp_Object val;
1540 struct catchtag c;
1541 struct handler h;
1543 /* Since Fsignal will close off all calls to x_catch_errors,
1544 we will get the wrong results if some are not closed now. */
1545 #if HAVE_X_WINDOWS
1546 if (x_catching_errors ())
1547 abort ();
1548 #endif
1550 c.tag = Qnil;
1551 c.val = Qnil;
1552 c.backlist = backtrace_list;
1553 c.handlerlist = handlerlist;
1554 c.lisp_eval_depth = lisp_eval_depth;
1555 c.pdlcount = SPECPDL_INDEX ();
1556 c.poll_suppress_count = poll_suppress_count;
1557 c.interrupt_input_blocked = interrupt_input_blocked;
1558 c.gcpro = gcprolist;
1559 c.byte_stack = byte_stack_list;
1560 if (_setjmp (c.jmp))
1562 return (*hfun) (c.val);
1564 c.next = catchlist;
1565 catchlist = &c;
1566 h.handler = handlers;
1567 h.var = Qnil;
1568 h.next = handlerlist;
1569 h.tag = &c;
1570 handlerlist = &h;
1572 val = (*bfun) (nargs, args);
1573 catchlist = c.next;
1574 handlerlist = h.next;
1575 return val;
1579 static Lisp_Object find_handler_clause P_ ((Lisp_Object, Lisp_Object,
1580 Lisp_Object, Lisp_Object,
1581 Lisp_Object *));
1583 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
1584 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1585 This function does not return.
1587 An error symbol is a symbol with an `error-conditions' property
1588 that is a list of condition names.
1589 A handler for any of those names will get to handle this signal.
1590 The symbol `error' should normally be one of them.
1592 DATA should be a list. Its elements are printed as part of the error message.
1593 See Info anchor `(elisp)Definition of signal' for some details on how this
1594 error message is constructed.
1595 If the signal is handled, DATA is made available to the handler.
1596 See also the function `condition-case'. */)
1597 (error_symbol, data)
1598 Lisp_Object error_symbol, data;
1600 /* When memory is full, ERROR-SYMBOL is nil,
1601 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1602 That is a special case--don't do this in other situations. */
1603 register struct handler *allhandlers = handlerlist;
1604 Lisp_Object conditions;
1605 extern int gc_in_progress;
1606 extern int waiting_for_input;
1607 Lisp_Object debugger_value;
1608 Lisp_Object string;
1609 Lisp_Object real_error_symbol;
1610 struct backtrace *bp;
1612 immediate_quit = handling_signal = 0;
1613 abort_on_gc = 0;
1614 if (gc_in_progress || waiting_for_input)
1615 abort ();
1617 if (NILP (error_symbol))
1618 real_error_symbol = Fcar (data);
1619 else
1620 real_error_symbol = error_symbol;
1622 #if 0 /* rms: I don't know why this was here,
1623 but it is surely wrong for an error that is handled. */
1624 #ifdef HAVE_X_WINDOWS
1625 if (display_hourglass_p)
1626 cancel_hourglass ();
1627 #endif
1628 #endif
1630 /* This hook is used by edebug. */
1631 if (! NILP (Vsignal_hook_function)
1632 && ! NILP (error_symbol))
1634 /* Edebug takes care of restoring these variables when it exits. */
1635 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
1636 max_lisp_eval_depth = lisp_eval_depth + 20;
1638 if (SPECPDL_INDEX () + 40 > max_specpdl_size)
1639 max_specpdl_size = SPECPDL_INDEX () + 40;
1641 call2 (Vsignal_hook_function, error_symbol, data);
1644 conditions = Fget (real_error_symbol, Qerror_conditions);
1646 /* Remember from where signal was called. Skip over the frame for
1647 `signal' itself. If a frame for `error' follows, skip that,
1648 too. Don't do this when ERROR_SYMBOL is nil, because that
1649 is a memory-full error. */
1650 Vsignaling_function = Qnil;
1651 if (backtrace_list && !NILP (error_symbol))
1653 bp = backtrace_list->next;
1654 if (bp && bp->function && EQ (*bp->function, Qerror))
1655 bp = bp->next;
1656 if (bp && bp->function)
1657 Vsignaling_function = *bp->function;
1660 for (; handlerlist; handlerlist = handlerlist->next)
1662 register Lisp_Object clause;
1664 clause = find_handler_clause (handlerlist->handler, conditions,
1665 error_symbol, data, &debugger_value);
1667 if (EQ (clause, Qlambda))
1669 /* We can't return values to code which signaled an error, but we
1670 can continue code which has signaled a quit. */
1671 if (EQ (real_error_symbol, Qquit))
1672 return Qnil;
1673 else
1674 error ("Cannot return from the debugger in an error");
1677 if (!NILP (clause))
1679 Lisp_Object unwind_data;
1680 struct handler *h = handlerlist;
1682 handlerlist = allhandlers;
1684 if (NILP (error_symbol))
1685 unwind_data = data;
1686 else
1687 unwind_data = Fcons (error_symbol, data);
1688 h->chosen_clause = clause;
1689 unwind_to_catch (h->tag, unwind_data);
1693 handlerlist = allhandlers;
1694 /* If no handler is present now, try to run the debugger,
1695 and if that fails, throw to top level. */
1696 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value);
1697 if (catchlist != 0)
1698 Fthrow (Qtop_level, Qt);
1700 if (! NILP (error_symbol))
1701 data = Fcons (error_symbol, data);
1703 string = Ferror_message_string (data);
1704 fatal ("%s", SDATA (string), 0);
1707 /* Return nonzero iff LIST is a non-nil atom or
1708 a list containing one of CONDITIONS. */
1710 static int
1711 wants_debugger (list, conditions)
1712 Lisp_Object list, conditions;
1714 if (NILP (list))
1715 return 0;
1716 if (! CONSP (list))
1717 return 1;
1719 while (CONSP (conditions))
1721 Lisp_Object this, tail;
1722 this = XCAR (conditions);
1723 for (tail = list; CONSP (tail); tail = XCDR (tail))
1724 if (EQ (XCAR (tail), this))
1725 return 1;
1726 conditions = XCDR (conditions);
1728 return 0;
1731 /* Return 1 if an error with condition-symbols CONDITIONS,
1732 and described by SIGNAL-DATA, should skip the debugger
1733 according to debugger-ignored-errors. */
1735 static int
1736 skip_debugger (conditions, data)
1737 Lisp_Object conditions, data;
1739 Lisp_Object tail;
1740 int first_string = 1;
1741 Lisp_Object error_message;
1743 error_message = Qnil;
1744 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
1746 if (STRINGP (XCAR (tail)))
1748 if (first_string)
1750 error_message = Ferror_message_string (data);
1751 first_string = 0;
1754 if (fast_string_match (XCAR (tail), error_message) >= 0)
1755 return 1;
1757 else
1759 Lisp_Object contail;
1761 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
1762 if (EQ (XCAR (tail), XCAR (contail)))
1763 return 1;
1767 return 0;
1770 /* Value of Qlambda means we have called debugger and user has continued.
1771 There are two ways to pass SIG and DATA:
1772 = SIG is the error symbol, and DATA is the rest of the data.
1773 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1774 This is for memory-full errors only.
1776 Store value returned from debugger into *DEBUGGER_VALUE_PTR.
1778 We need to increase max_specpdl_size temporarily around
1779 anything we do that can push on the specpdl, so as not to get
1780 a second error here in case we're handling specpdl overflow. */
1782 static Lisp_Object
1783 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr)
1784 Lisp_Object handlers, conditions, sig, data;
1785 Lisp_Object *debugger_value_ptr;
1787 register Lisp_Object h;
1788 register Lisp_Object tem;
1790 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */
1791 return Qt;
1792 /* error is used similarly, but means print an error message
1793 and run the debugger if that is enabled. */
1794 if (EQ (handlers, Qerror)
1795 || !NILP (Vdebug_on_signal)) /* This says call debugger even if
1796 there is a handler. */
1798 int debugger_called = 0;
1799 Lisp_Object sig_symbol, combined_data;
1800 /* This is set to 1 if we are handling a memory-full error,
1801 because these must not run the debugger.
1802 (There is no room in memory to do that!) */
1803 int no_debugger = 0;
1805 if (NILP (sig))
1807 combined_data = data;
1808 sig_symbol = Fcar (data);
1809 no_debugger = 1;
1811 else
1813 combined_data = Fcons (sig, data);
1814 sig_symbol = sig;
1817 if (wants_debugger (Vstack_trace_on_error, conditions))
1819 max_specpdl_size++;
1820 #ifdef PROTOTYPES
1821 internal_with_output_to_temp_buffer ("*Backtrace*",
1822 (Lisp_Object (*) (Lisp_Object)) Fbacktrace,
1823 Qnil);
1824 #else
1825 internal_with_output_to_temp_buffer ("*Backtrace*",
1826 Fbacktrace, Qnil);
1827 #endif
1828 max_specpdl_size--;
1830 if (! no_debugger
1831 && (EQ (sig_symbol, Qquit)
1832 ? debug_on_quit
1833 : wants_debugger (Vdebug_on_error, conditions))
1834 && ! skip_debugger (conditions, combined_data)
1835 && when_entered_debugger < num_nonmacro_input_events)
1837 *debugger_value_ptr
1838 = call_debugger (Fcons (Qerror,
1839 Fcons (combined_data, Qnil)));
1840 debugger_called = 1;
1842 /* If there is no handler, return saying whether we ran the debugger. */
1843 if (EQ (handlers, Qerror))
1845 if (debugger_called)
1846 return Qlambda;
1847 return Qt;
1850 for (h = handlers; CONSP (h); h = Fcdr (h))
1852 Lisp_Object handler, condit;
1854 handler = Fcar (h);
1855 if (!CONSP (handler))
1856 continue;
1857 condit = Fcar (handler);
1858 /* Handle a single condition name in handler HANDLER. */
1859 if (SYMBOLP (condit))
1861 tem = Fmemq (Fcar (handler), conditions);
1862 if (!NILP (tem))
1863 return handler;
1865 /* Handle a list of condition names in handler HANDLER. */
1866 else if (CONSP (condit))
1868 while (CONSP (condit))
1870 tem = Fmemq (Fcar (condit), conditions);
1871 if (!NILP (tem))
1872 return handler;
1873 condit = XCDR (condit);
1877 return Qnil;
1880 /* dump an error message; called like printf */
1882 /* VARARGS 1 */
1883 void
1884 error (m, a1, a2, a3)
1885 char *m;
1886 char *a1, *a2, *a3;
1888 char buf[200];
1889 int size = 200;
1890 int mlen;
1891 char *buffer = buf;
1892 char *args[3];
1893 int allocated = 0;
1894 Lisp_Object string;
1896 args[0] = a1;
1897 args[1] = a2;
1898 args[2] = a3;
1900 mlen = strlen (m);
1902 while (1)
1904 int used = doprnt (buffer, size, m, m + mlen, 3, args);
1905 if (used < size)
1906 break;
1907 size *= 2;
1908 if (allocated)
1909 buffer = (char *) xrealloc (buffer, size);
1910 else
1912 buffer = (char *) xmalloc (size);
1913 allocated = 1;
1917 string = build_string (buffer);
1918 if (allocated)
1919 xfree (buffer);
1921 Fsignal (Qerror, Fcons (string, Qnil));
1922 abort ();
1925 DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
1926 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
1927 This means it contains a description for how to read arguments to give it.
1928 The value is nil for an invalid function or a symbol with no function
1929 definition.
1931 Interactively callable functions include strings and vectors (treated
1932 as keyboard macros), lambda-expressions that contain a top-level call
1933 to `interactive', autoload definitions made by `autoload' with non-nil
1934 fourth argument, and some of the built-in functions of Lisp.
1936 Also, a symbol satisfies `commandp' if its function definition does so.
1938 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1939 then strings and vectors are not accepted. */)
1940 (function, for_call_interactively)
1941 Lisp_Object function, for_call_interactively;
1943 register Lisp_Object fun;
1944 register Lisp_Object funcar;
1946 fun = function;
1948 fun = indirect_function (fun);
1949 if (EQ (fun, Qunbound))
1950 return Qnil;
1952 /* Emacs primitives are interactive if their DEFUN specifies an
1953 interactive spec. */
1954 if (SUBRP (fun))
1956 if (XSUBR (fun)->prompt)
1957 return Qt;
1958 else
1959 return Qnil;
1962 /* Bytecode objects are interactive if they are long enough to
1963 have an element whose index is COMPILED_INTERACTIVE, which is
1964 where the interactive spec is stored. */
1965 else if (COMPILEDP (fun))
1966 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
1967 ? Qt : Qnil);
1969 /* Strings and vectors are keyboard macros. */
1970 if (NILP (for_call_interactively) && (STRINGP (fun) || VECTORP (fun)))
1971 return Qt;
1973 /* Lists may represent commands. */
1974 if (!CONSP (fun))
1975 return Qnil;
1976 funcar = XCAR (fun);
1977 if (EQ (funcar, Qlambda))
1978 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
1979 if (EQ (funcar, Qautoload))
1980 return Fcar (Fcdr (Fcdr (XCDR (fun))));
1981 else
1982 return Qnil;
1985 /* ARGSUSED */
1986 DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
1987 doc: /* Define FUNCTION to autoload from FILE.
1988 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1989 Third arg DOCSTRING is documentation for the function.
1990 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1991 Fifth arg TYPE indicates the type of the object:
1992 nil or omitted says FUNCTION is a function,
1993 `keymap' says FUNCTION is really a keymap, and
1994 `macro' or t says FUNCTION is really a macro.
1995 Third through fifth args give info about the real definition.
1996 They default to nil.
1997 If FUNCTION is already defined other than as an autoload,
1998 this does nothing and returns nil. */)
1999 (function, file, docstring, interactive, type)
2000 Lisp_Object function, file, docstring, interactive, type;
2002 #ifdef NO_ARG_ARRAY
2003 Lisp_Object args[4];
2004 #endif
2006 CHECK_SYMBOL (function);
2007 CHECK_STRING (file);
2009 /* If function is defined and not as an autoload, don't override */
2010 if (!EQ (XSYMBOL (function)->function, Qunbound)
2011 && !(CONSP (XSYMBOL (function)->function)
2012 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
2013 return Qnil;
2015 if (NILP (Vpurify_flag))
2016 /* Only add entries after dumping, because the ones before are
2017 not useful and else we get loads of them from the loaddefs.el. */
2018 LOADHIST_ATTACH (Fcons (Qautoload, function));
2020 #ifdef NO_ARG_ARRAY
2021 args[0] = file;
2022 args[1] = docstring;
2023 args[2] = interactive;
2024 args[3] = type;
2026 return Ffset (function, Fcons (Qautoload, Flist (4, &args[0])));
2027 #else /* NO_ARG_ARRAY */
2028 return Ffset (function, Fcons (Qautoload, Flist (4, &file)));
2029 #endif /* not NO_ARG_ARRAY */
2032 Lisp_Object
2033 un_autoload (oldqueue)
2034 Lisp_Object oldqueue;
2036 register Lisp_Object queue, first, second;
2038 /* Queue to unwind is current value of Vautoload_queue.
2039 oldqueue is the shadowed value to leave in Vautoload_queue. */
2040 queue = Vautoload_queue;
2041 Vautoload_queue = oldqueue;
2042 while (CONSP (queue))
2044 first = XCAR (queue);
2045 second = Fcdr (first);
2046 first = Fcar (first);
2047 if (EQ (first, make_number (0)))
2048 Vfeatures = second;
2049 else
2050 Ffset (first, second);
2051 queue = XCDR (queue);
2053 return Qnil;
2056 /* Load an autoloaded function.
2057 FUNNAME is the symbol which is the function's name.
2058 FUNDEF is the autoload definition (a list). */
2060 void
2061 do_autoload (fundef, funname)
2062 Lisp_Object fundef, funname;
2064 int count = SPECPDL_INDEX ();
2065 Lisp_Object fun, queue, first, second;
2066 struct gcpro gcpro1, gcpro2, gcpro3;
2068 /* This is to make sure that loadup.el gives a clear picture
2069 of what files are preloaded and when. */
2070 if (! NILP (Vpurify_flag))
2071 error ("Attempt to autoload %s while preparing to dump",
2072 SDATA (SYMBOL_NAME (funname)));
2074 fun = funname;
2075 CHECK_SYMBOL (funname);
2076 GCPRO3 (fun, funname, fundef);
2078 /* Preserve the match data. */
2079 record_unwind_save_match_data ();
2081 /* Value saved here is to be restored into Vautoload_queue. */
2082 record_unwind_protect (un_autoload, Vautoload_queue);
2083 Vautoload_queue = Qt;
2084 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil, Qt);
2086 /* Save the old autoloads, in case we ever do an unload. */
2087 queue = Vautoload_queue;
2088 while (CONSP (queue))
2090 first = XCAR (queue);
2091 second = Fcdr (first);
2092 first = Fcar (first);
2094 if (SYMBOLP (first) && CONSP (second) && EQ (XCAR (second), Qautoload))
2095 Fput (first, Qautoload, (XCDR (second)));
2097 queue = XCDR (queue);
2100 /* Once loading finishes, don't undo it. */
2101 Vautoload_queue = Qt;
2102 unbind_to (count, Qnil);
2104 fun = Findirect_function (fun, Qnil);
2106 if (!NILP (Fequal (fun, fundef)))
2107 error ("Autoloading failed to define function %s",
2108 SDATA (SYMBOL_NAME (funname)));
2109 UNGCPRO;
2113 DEFUN ("eval", Feval, Seval, 1, 1, 0,
2114 doc: /* Evaluate FORM and return its value. */)
2115 (form)
2116 Lisp_Object form;
2118 Lisp_Object fun, val, original_fun, original_args;
2119 Lisp_Object funcar;
2120 struct backtrace backtrace;
2121 struct gcpro gcpro1, gcpro2, gcpro3;
2123 if (handling_signal)
2124 abort ();
2126 if (SYMBOLP (form))
2127 return Fsymbol_value (form);
2128 if (!CONSP (form))
2129 return form;
2131 QUIT;
2132 if ((consing_since_gc > gc_cons_threshold
2133 && consing_since_gc > gc_relative_threshold)
2135 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2137 GCPRO1 (form);
2138 Fgarbage_collect ();
2139 UNGCPRO;
2142 if (++lisp_eval_depth > max_lisp_eval_depth)
2144 if (max_lisp_eval_depth < 100)
2145 max_lisp_eval_depth = 100;
2146 if (lisp_eval_depth > max_lisp_eval_depth)
2147 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2150 original_fun = Fcar (form);
2151 original_args = Fcdr (form);
2153 backtrace.next = backtrace_list;
2154 backtrace_list = &backtrace;
2155 backtrace.function = &original_fun; /* This also protects them from gc */
2156 backtrace.args = &original_args;
2157 backtrace.nargs = UNEVALLED;
2158 backtrace.evalargs = 1;
2159 backtrace.debug_on_exit = 0;
2161 if (debug_on_next_call)
2162 do_debug_on_call (Qt);
2164 /* At this point, only original_fun and original_args
2165 have values that will be used below */
2166 retry:
2167 fun = Findirect_function (original_fun, Qnil);
2169 if (SUBRP (fun))
2171 Lisp_Object numargs;
2172 Lisp_Object argvals[8];
2173 Lisp_Object args_left;
2174 register int i, maxargs;
2176 args_left = original_args;
2177 numargs = Flength (args_left);
2179 CHECK_CONS_LIST ();
2181 if (XINT (numargs) < XSUBR (fun)->min_args ||
2182 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
2183 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
2185 if (XSUBR (fun)->max_args == UNEVALLED)
2187 backtrace.evalargs = 0;
2188 val = (*XSUBR (fun)->function) (args_left);
2189 goto done;
2192 if (XSUBR (fun)->max_args == MANY)
2194 /* Pass a vector of evaluated arguments */
2195 Lisp_Object *vals;
2196 register int argnum = 0;
2198 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2200 GCPRO3 (args_left, fun, fun);
2201 gcpro3.var = vals;
2202 gcpro3.nvars = 0;
2204 while (!NILP (args_left))
2206 vals[argnum++] = Feval (Fcar (args_left));
2207 args_left = Fcdr (args_left);
2208 gcpro3.nvars = argnum;
2211 backtrace.args = vals;
2212 backtrace.nargs = XINT (numargs);
2214 val = (*XSUBR (fun)->function) (XINT (numargs), vals);
2215 UNGCPRO;
2216 goto done;
2219 GCPRO3 (args_left, fun, fun);
2220 gcpro3.var = argvals;
2221 gcpro3.nvars = 0;
2223 maxargs = XSUBR (fun)->max_args;
2224 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
2226 argvals[i] = Feval (Fcar (args_left));
2227 gcpro3.nvars = ++i;
2230 UNGCPRO;
2232 backtrace.args = argvals;
2233 backtrace.nargs = XINT (numargs);
2235 switch (i)
2237 case 0:
2238 val = (*XSUBR (fun)->function) ();
2239 goto done;
2240 case 1:
2241 val = (*XSUBR (fun)->function) (argvals[0]);
2242 goto done;
2243 case 2:
2244 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]);
2245 goto done;
2246 case 3:
2247 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2248 argvals[2]);
2249 goto done;
2250 case 4:
2251 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2252 argvals[2], argvals[3]);
2253 goto done;
2254 case 5:
2255 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2256 argvals[3], argvals[4]);
2257 goto done;
2258 case 6:
2259 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2260 argvals[3], argvals[4], argvals[5]);
2261 goto done;
2262 case 7:
2263 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2264 argvals[3], argvals[4], argvals[5],
2265 argvals[6]);
2266 goto done;
2268 case 8:
2269 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2270 argvals[3], argvals[4], argvals[5],
2271 argvals[6], argvals[7]);
2272 goto done;
2274 default:
2275 /* Someone has created a subr that takes more arguments than
2276 is supported by this code. We need to either rewrite the
2277 subr to use a different argument protocol, or add more
2278 cases to this switch. */
2279 abort ();
2282 if (COMPILEDP (fun))
2283 val = apply_lambda (fun, original_args, 1);
2284 else
2286 if (!CONSP (fun))
2287 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2288 funcar = Fcar (fun);
2289 if (!SYMBOLP (funcar))
2290 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2291 if (EQ (funcar, Qautoload))
2293 do_autoload (fun, original_fun);
2294 goto retry;
2296 if (EQ (funcar, Qmacro))
2297 val = Feval (apply1 (Fcdr (fun), original_args));
2298 else if (EQ (funcar, Qlambda))
2299 val = apply_lambda (fun, original_args, 1);
2300 else
2301 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2303 done:
2304 CHECK_CONS_LIST ();
2306 lisp_eval_depth--;
2307 if (backtrace.debug_on_exit)
2308 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2309 backtrace_list = backtrace.next;
2311 return val;
2314 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
2315 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2316 Then return the value FUNCTION returns.
2317 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2318 usage: (apply FUNCTION &rest ARGUMENTS) */)
2319 (nargs, args)
2320 int nargs;
2321 Lisp_Object *args;
2323 register int i, numargs;
2324 register Lisp_Object spread_arg;
2325 register Lisp_Object *funcall_args;
2326 Lisp_Object fun;
2327 struct gcpro gcpro1;
2329 fun = args [0];
2330 funcall_args = 0;
2331 spread_arg = args [nargs - 1];
2332 CHECK_LIST (spread_arg);
2334 numargs = XINT (Flength (spread_arg));
2336 if (numargs == 0)
2337 return Ffuncall (nargs - 1, args);
2338 else if (numargs == 1)
2340 args [nargs - 1] = XCAR (spread_arg);
2341 return Ffuncall (nargs, args);
2344 numargs += nargs - 2;
2346 fun = indirect_function (fun);
2347 if (EQ (fun, Qunbound))
2349 /* Let funcall get the error */
2350 fun = args[0];
2351 goto funcall;
2354 if (SUBRP (fun))
2356 if (numargs < XSUBR (fun)->min_args
2357 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2358 goto funcall; /* Let funcall get the error */
2359 else if (XSUBR (fun)->max_args > numargs)
2361 /* Avoid making funcall cons up a yet another new vector of arguments
2362 by explicitly supplying nil's for optional values */
2363 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
2364 * sizeof (Lisp_Object));
2365 for (i = numargs; i < XSUBR (fun)->max_args;)
2366 funcall_args[++i] = Qnil;
2367 GCPRO1 (*funcall_args);
2368 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
2371 funcall:
2372 /* We add 1 to numargs because funcall_args includes the
2373 function itself as well as its arguments. */
2374 if (!funcall_args)
2376 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
2377 * sizeof (Lisp_Object));
2378 GCPRO1 (*funcall_args);
2379 gcpro1.nvars = 1 + numargs;
2382 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
2383 /* Spread the last arg we got. Its first element goes in
2384 the slot that it used to occupy, hence this value of I. */
2385 i = nargs - 1;
2386 while (!NILP (spread_arg))
2388 funcall_args [i++] = XCAR (spread_arg);
2389 spread_arg = XCDR (spread_arg);
2392 /* By convention, the caller needs to gcpro Ffuncall's args. */
2393 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
2396 /* Run hook variables in various ways. */
2398 enum run_hooks_condition {to_completion, until_success, until_failure};
2399 static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *,
2400 enum run_hooks_condition));
2402 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
2403 doc: /* Run each hook in HOOKS.
2404 Each argument should be a symbol, a hook variable.
2405 These symbols are processed in the order specified.
2406 If a hook symbol has a non-nil value, that value may be a function
2407 or a list of functions to be called to run the hook.
2408 If the value is a function, it is called with no arguments.
2409 If it is a list, the elements are called, in order, with no arguments.
2411 Major modes should not use this function directly to run their mode
2412 hook; they should use `run-mode-hooks' instead.
2414 Do not use `make-local-variable' to make a hook variable buffer-local.
2415 Instead, use `add-hook' and specify t for the LOCAL argument.
2416 usage: (run-hooks &rest HOOKS) */)
2417 (nargs, args)
2418 int nargs;
2419 Lisp_Object *args;
2421 Lisp_Object hook[1];
2422 register int i;
2424 for (i = 0; i < nargs; i++)
2426 hook[0] = args[i];
2427 run_hook_with_args (1, hook, to_completion);
2430 return Qnil;
2433 DEFUN ("run-hook-with-args", Frun_hook_with_args,
2434 Srun_hook_with_args, 1, MANY, 0,
2435 doc: /* Run HOOK with the specified arguments ARGS.
2436 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2437 value, that value may be a function or a list of functions to be
2438 called to run the hook. If the value is a function, it is called with
2439 the given arguments and its return value is returned. If it is a list
2440 of functions, those functions are called, in order,
2441 with the given arguments ARGS.
2442 It is best not to depend on the value returned by `run-hook-with-args',
2443 as that may change.
2445 Do not use `make-local-variable' to make a hook variable buffer-local.
2446 Instead, use `add-hook' and specify t for the LOCAL argument.
2447 usage: (run-hook-with-args HOOK &rest ARGS) */)
2448 (nargs, args)
2449 int nargs;
2450 Lisp_Object *args;
2452 return run_hook_with_args (nargs, args, to_completion);
2455 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
2456 Srun_hook_with_args_until_success, 1, MANY, 0,
2457 doc: /* Run HOOK with the specified arguments ARGS.
2458 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2459 value, that value may be a function or a list of functions to be
2460 called to run the hook. If the value is a function, it is called with
2461 the given arguments and its return value is returned.
2462 If it is a list of functions, those functions are called, in order,
2463 with the given arguments ARGS, until one of them
2464 returns a non-nil value. Then we return that value.
2465 However, if they all return nil, we return nil.
2467 Do not use `make-local-variable' to make a hook variable buffer-local.
2468 Instead, use `add-hook' and specify t for the LOCAL argument.
2469 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2470 (nargs, args)
2471 int nargs;
2472 Lisp_Object *args;
2474 return run_hook_with_args (nargs, args, until_success);
2477 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
2478 Srun_hook_with_args_until_failure, 1, MANY, 0,
2479 doc: /* Run HOOK with the specified arguments ARGS.
2480 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2481 value, that value may be a function or a list of functions to be
2482 called to run the hook. If the value is a function, it is called with
2483 the given arguments and its return value is returned.
2484 If it is a list of functions, those functions are called, in order,
2485 with the given arguments ARGS, until one of them returns nil.
2486 Then we return nil. However, if they all return non-nil, we return non-nil.
2488 Do not use `make-local-variable' to make a hook variable buffer-local.
2489 Instead, use `add-hook' and specify t for the LOCAL argument.
2490 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2491 (nargs, args)
2492 int nargs;
2493 Lisp_Object *args;
2495 return run_hook_with_args (nargs, args, until_failure);
2498 /* ARGS[0] should be a hook symbol.
2499 Call each of the functions in the hook value, passing each of them
2500 as arguments all the rest of ARGS (all NARGS - 1 elements).
2501 COND specifies a condition to test after each call
2502 to decide whether to stop.
2503 The caller (or its caller, etc) must gcpro all of ARGS,
2504 except that it isn't necessary to gcpro ARGS[0]. */
2506 static Lisp_Object
2507 run_hook_with_args (nargs, args, cond)
2508 int nargs;
2509 Lisp_Object *args;
2510 enum run_hooks_condition cond;
2512 Lisp_Object sym, val, ret;
2513 Lisp_Object globals;
2514 struct gcpro gcpro1, gcpro2, gcpro3;
2516 /* If we are dying or still initializing,
2517 don't do anything--it would probably crash if we tried. */
2518 if (NILP (Vrun_hooks))
2519 return Qnil;
2521 sym = args[0];
2522 val = find_symbol_value (sym);
2523 ret = (cond == until_failure ? Qt : Qnil);
2525 if (EQ (val, Qunbound) || NILP (val))
2526 return ret;
2527 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
2529 args[0] = val;
2530 return Ffuncall (nargs, args);
2532 else
2534 globals = Qnil;
2535 GCPRO3 (sym, val, globals);
2537 for (;
2538 CONSP (val) && ((cond == to_completion)
2539 || (cond == until_success ? NILP (ret)
2540 : !NILP (ret)));
2541 val = XCDR (val))
2543 if (EQ (XCAR (val), Qt))
2545 /* t indicates this hook has a local binding;
2546 it means to run the global binding too. */
2548 for (globals = Fdefault_value (sym);
2549 CONSP (globals) && ((cond == to_completion)
2550 || (cond == until_success ? NILP (ret)
2551 : !NILP (ret)));
2552 globals = XCDR (globals))
2554 args[0] = XCAR (globals);
2555 /* In a global value, t should not occur. If it does, we
2556 must ignore it to avoid an endless loop. */
2557 if (!EQ (args[0], Qt))
2558 ret = Ffuncall (nargs, args);
2561 else
2563 args[0] = XCAR (val);
2564 ret = Ffuncall (nargs, args);
2568 UNGCPRO;
2569 return ret;
2573 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2574 present value of that symbol.
2575 Call each element of FUNLIST,
2576 passing each of them the rest of ARGS.
2577 The caller (or its caller, etc) must gcpro all of ARGS,
2578 except that it isn't necessary to gcpro ARGS[0]. */
2580 Lisp_Object
2581 run_hook_list_with_args (funlist, nargs, args)
2582 Lisp_Object funlist;
2583 int nargs;
2584 Lisp_Object *args;
2586 Lisp_Object sym;
2587 Lisp_Object val;
2588 Lisp_Object globals;
2589 struct gcpro gcpro1, gcpro2, gcpro3;
2591 sym = args[0];
2592 globals = Qnil;
2593 GCPRO3 (sym, val, globals);
2595 for (val = funlist; CONSP (val); val = XCDR (val))
2597 if (EQ (XCAR (val), Qt))
2599 /* t indicates this hook has a local binding;
2600 it means to run the global binding too. */
2602 for (globals = Fdefault_value (sym);
2603 CONSP (globals);
2604 globals = XCDR (globals))
2606 args[0] = XCAR (globals);
2607 /* In a global value, t should not occur. If it does, we
2608 must ignore it to avoid an endless loop. */
2609 if (!EQ (args[0], Qt))
2610 Ffuncall (nargs, args);
2613 else
2615 args[0] = XCAR (val);
2616 Ffuncall (nargs, args);
2619 UNGCPRO;
2620 return Qnil;
2623 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2625 void
2626 run_hook_with_args_2 (hook, arg1, arg2)
2627 Lisp_Object hook, arg1, arg2;
2629 Lisp_Object temp[3];
2630 temp[0] = hook;
2631 temp[1] = arg1;
2632 temp[2] = arg2;
2634 Frun_hook_with_args (3, temp);
2637 /* Apply fn to arg */
2638 Lisp_Object
2639 apply1 (fn, arg)
2640 Lisp_Object fn, arg;
2642 struct gcpro gcpro1;
2644 GCPRO1 (fn);
2645 if (NILP (arg))
2646 RETURN_UNGCPRO (Ffuncall (1, &fn));
2647 gcpro1.nvars = 2;
2648 #ifdef NO_ARG_ARRAY
2650 Lisp_Object args[2];
2651 args[0] = fn;
2652 args[1] = arg;
2653 gcpro1.var = args;
2654 RETURN_UNGCPRO (Fapply (2, args));
2656 #else /* not NO_ARG_ARRAY */
2657 RETURN_UNGCPRO (Fapply (2, &fn));
2658 #endif /* not NO_ARG_ARRAY */
2661 /* Call function fn on no arguments */
2662 Lisp_Object
2663 call0 (fn)
2664 Lisp_Object fn;
2666 struct gcpro gcpro1;
2668 GCPRO1 (fn);
2669 RETURN_UNGCPRO (Ffuncall (1, &fn));
2672 /* Call function fn with 1 argument arg1 */
2673 /* ARGSUSED */
2674 Lisp_Object
2675 call1 (fn, arg1)
2676 Lisp_Object fn, arg1;
2678 struct gcpro gcpro1;
2679 #ifdef NO_ARG_ARRAY
2680 Lisp_Object args[2];
2682 args[0] = fn;
2683 args[1] = arg1;
2684 GCPRO1 (args[0]);
2685 gcpro1.nvars = 2;
2686 RETURN_UNGCPRO (Ffuncall (2, args));
2687 #else /* not NO_ARG_ARRAY */
2688 GCPRO1 (fn);
2689 gcpro1.nvars = 2;
2690 RETURN_UNGCPRO (Ffuncall (2, &fn));
2691 #endif /* not NO_ARG_ARRAY */
2694 /* Call function fn with 2 arguments arg1, arg2 */
2695 /* ARGSUSED */
2696 Lisp_Object
2697 call2 (fn, arg1, arg2)
2698 Lisp_Object fn, arg1, arg2;
2700 struct gcpro gcpro1;
2701 #ifdef NO_ARG_ARRAY
2702 Lisp_Object args[3];
2703 args[0] = fn;
2704 args[1] = arg1;
2705 args[2] = arg2;
2706 GCPRO1 (args[0]);
2707 gcpro1.nvars = 3;
2708 RETURN_UNGCPRO (Ffuncall (3, args));
2709 #else /* not NO_ARG_ARRAY */
2710 GCPRO1 (fn);
2711 gcpro1.nvars = 3;
2712 RETURN_UNGCPRO (Ffuncall (3, &fn));
2713 #endif /* not NO_ARG_ARRAY */
2716 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2717 /* ARGSUSED */
2718 Lisp_Object
2719 call3 (fn, arg1, arg2, arg3)
2720 Lisp_Object fn, arg1, arg2, arg3;
2722 struct gcpro gcpro1;
2723 #ifdef NO_ARG_ARRAY
2724 Lisp_Object args[4];
2725 args[0] = fn;
2726 args[1] = arg1;
2727 args[2] = arg2;
2728 args[3] = arg3;
2729 GCPRO1 (args[0]);
2730 gcpro1.nvars = 4;
2731 RETURN_UNGCPRO (Ffuncall (4, args));
2732 #else /* not NO_ARG_ARRAY */
2733 GCPRO1 (fn);
2734 gcpro1.nvars = 4;
2735 RETURN_UNGCPRO (Ffuncall (4, &fn));
2736 #endif /* not NO_ARG_ARRAY */
2739 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2740 /* ARGSUSED */
2741 Lisp_Object
2742 call4 (fn, arg1, arg2, arg3, arg4)
2743 Lisp_Object fn, arg1, arg2, arg3, arg4;
2745 struct gcpro gcpro1;
2746 #ifdef NO_ARG_ARRAY
2747 Lisp_Object args[5];
2748 args[0] = fn;
2749 args[1] = arg1;
2750 args[2] = arg2;
2751 args[3] = arg3;
2752 args[4] = arg4;
2753 GCPRO1 (args[0]);
2754 gcpro1.nvars = 5;
2755 RETURN_UNGCPRO (Ffuncall (5, args));
2756 #else /* not NO_ARG_ARRAY */
2757 GCPRO1 (fn);
2758 gcpro1.nvars = 5;
2759 RETURN_UNGCPRO (Ffuncall (5, &fn));
2760 #endif /* not NO_ARG_ARRAY */
2763 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2764 /* ARGSUSED */
2765 Lisp_Object
2766 call5 (fn, arg1, arg2, arg3, arg4, arg5)
2767 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
2769 struct gcpro gcpro1;
2770 #ifdef NO_ARG_ARRAY
2771 Lisp_Object args[6];
2772 args[0] = fn;
2773 args[1] = arg1;
2774 args[2] = arg2;
2775 args[3] = arg3;
2776 args[4] = arg4;
2777 args[5] = arg5;
2778 GCPRO1 (args[0]);
2779 gcpro1.nvars = 6;
2780 RETURN_UNGCPRO (Ffuncall (6, args));
2781 #else /* not NO_ARG_ARRAY */
2782 GCPRO1 (fn);
2783 gcpro1.nvars = 6;
2784 RETURN_UNGCPRO (Ffuncall (6, &fn));
2785 #endif /* not NO_ARG_ARRAY */
2788 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2789 /* ARGSUSED */
2790 Lisp_Object
2791 call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
2792 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
2794 struct gcpro gcpro1;
2795 #ifdef NO_ARG_ARRAY
2796 Lisp_Object args[7];
2797 args[0] = fn;
2798 args[1] = arg1;
2799 args[2] = arg2;
2800 args[3] = arg3;
2801 args[4] = arg4;
2802 args[5] = arg5;
2803 args[6] = arg6;
2804 GCPRO1 (args[0]);
2805 gcpro1.nvars = 7;
2806 RETURN_UNGCPRO (Ffuncall (7, args));
2807 #else /* not NO_ARG_ARRAY */
2808 GCPRO1 (fn);
2809 gcpro1.nvars = 7;
2810 RETURN_UNGCPRO (Ffuncall (7, &fn));
2811 #endif /* not NO_ARG_ARRAY */
2814 /* The caller should GCPRO all the elements of ARGS. */
2816 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2817 doc: /* Call first argument as a function, passing remaining arguments to it.
2818 Return the value that function returns.
2819 Thus, (funcall 'cons 'x 'y) returns (x . y).
2820 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2821 (nargs, args)
2822 int nargs;
2823 Lisp_Object *args;
2825 Lisp_Object fun;
2826 Lisp_Object funcar;
2827 int numargs = nargs - 1;
2828 Lisp_Object lisp_numargs;
2829 Lisp_Object val;
2830 struct backtrace backtrace;
2831 register Lisp_Object *internal_args;
2832 register int i;
2834 QUIT;
2835 if ((consing_since_gc > gc_cons_threshold
2836 && consing_since_gc > gc_relative_threshold)
2838 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2839 Fgarbage_collect ();
2841 if (++lisp_eval_depth > max_lisp_eval_depth)
2843 if (max_lisp_eval_depth < 100)
2844 max_lisp_eval_depth = 100;
2845 if (lisp_eval_depth > max_lisp_eval_depth)
2846 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2849 backtrace.next = backtrace_list;
2850 backtrace_list = &backtrace;
2851 backtrace.function = &args[0];
2852 backtrace.args = &args[1];
2853 backtrace.nargs = nargs - 1;
2854 backtrace.evalargs = 0;
2855 backtrace.debug_on_exit = 0;
2857 if (debug_on_next_call)
2858 do_debug_on_call (Qlambda);
2860 CHECK_CONS_LIST ();
2862 retry:
2864 fun = args[0];
2866 fun = Findirect_function (fun, Qnil);
2868 if (SUBRP (fun))
2870 if (numargs < XSUBR (fun)->min_args
2871 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2873 XSETFASTINT (lisp_numargs, numargs);
2874 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
2877 if (XSUBR (fun)->max_args == UNEVALLED)
2878 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2880 if (XSUBR (fun)->max_args == MANY)
2882 val = (*XSUBR (fun)->function) (numargs, args + 1);
2883 goto done;
2886 if (XSUBR (fun)->max_args > numargs)
2888 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2889 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
2890 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2891 internal_args[i] = Qnil;
2893 else
2894 internal_args = args + 1;
2895 switch (XSUBR (fun)->max_args)
2897 case 0:
2898 val = (*XSUBR (fun)->function) ();
2899 goto done;
2900 case 1:
2901 val = (*XSUBR (fun)->function) (internal_args[0]);
2902 goto done;
2903 case 2:
2904 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1]);
2905 goto done;
2906 case 3:
2907 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2908 internal_args[2]);
2909 goto done;
2910 case 4:
2911 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2912 internal_args[2], internal_args[3]);
2913 goto done;
2914 case 5:
2915 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2916 internal_args[2], internal_args[3],
2917 internal_args[4]);
2918 goto done;
2919 case 6:
2920 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2921 internal_args[2], internal_args[3],
2922 internal_args[4], internal_args[5]);
2923 goto done;
2924 case 7:
2925 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2926 internal_args[2], internal_args[3],
2927 internal_args[4], internal_args[5],
2928 internal_args[6]);
2929 goto done;
2931 case 8:
2932 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2933 internal_args[2], internal_args[3],
2934 internal_args[4], internal_args[5],
2935 internal_args[6], internal_args[7]);
2936 goto done;
2938 default:
2940 /* If a subr takes more than 8 arguments without using MANY
2941 or UNEVALLED, we need to extend this function to support it.
2942 Until this is done, there is no way to call the function. */
2943 abort ();
2946 if (COMPILEDP (fun))
2947 val = funcall_lambda (fun, numargs, args + 1);
2948 else
2950 if (!CONSP (fun))
2951 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2952 funcar = Fcar (fun);
2953 if (!SYMBOLP (funcar))
2954 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2955 if (EQ (funcar, Qlambda))
2956 val = funcall_lambda (fun, numargs, args + 1);
2957 else if (EQ (funcar, Qautoload))
2959 do_autoload (fun, args[0]);
2960 CHECK_CONS_LIST ();
2961 goto retry;
2963 else
2964 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2966 done:
2967 CHECK_CONS_LIST ();
2968 lisp_eval_depth--;
2969 if (backtrace.debug_on_exit)
2970 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2971 backtrace_list = backtrace.next;
2972 return val;
2975 Lisp_Object
2976 apply_lambda (fun, args, eval_flag)
2977 Lisp_Object fun, args;
2978 int eval_flag;
2980 Lisp_Object args_left;
2981 Lisp_Object numargs;
2982 register Lisp_Object *arg_vector;
2983 struct gcpro gcpro1, gcpro2, gcpro3;
2984 register int i;
2985 register Lisp_Object tem;
2987 numargs = Flength (args);
2988 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2989 args_left = args;
2991 GCPRO3 (*arg_vector, args_left, fun);
2992 gcpro1.nvars = 0;
2994 for (i = 0; i < XINT (numargs);)
2996 tem = Fcar (args_left), args_left = Fcdr (args_left);
2997 if (eval_flag) tem = Feval (tem);
2998 arg_vector[i++] = tem;
2999 gcpro1.nvars = i;
3002 UNGCPRO;
3004 if (eval_flag)
3006 backtrace_list->args = arg_vector;
3007 backtrace_list->nargs = i;
3009 backtrace_list->evalargs = 0;
3010 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
3012 /* Do the debug-on-exit now, while arg_vector still exists. */
3013 if (backtrace_list->debug_on_exit)
3014 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
3015 /* Don't do it again when we return to eval. */
3016 backtrace_list->debug_on_exit = 0;
3017 return tem;
3020 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3021 and return the result of evaluation.
3022 FUN must be either a lambda-expression or a compiled-code object. */
3024 static Lisp_Object
3025 funcall_lambda (fun, nargs, arg_vector)
3026 Lisp_Object fun;
3027 int nargs;
3028 register Lisp_Object *arg_vector;
3030 Lisp_Object val, syms_left, next;
3031 int count = SPECPDL_INDEX ();
3032 int i, optional, rest;
3034 if (CONSP (fun))
3036 syms_left = XCDR (fun);
3037 if (CONSP (syms_left))
3038 syms_left = XCAR (syms_left);
3039 else
3040 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
3042 else if (COMPILEDP (fun))
3043 syms_left = AREF (fun, COMPILED_ARGLIST);
3044 else
3045 abort ();
3047 i = optional = rest = 0;
3048 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
3050 QUIT;
3052 next = XCAR (syms_left);
3053 while (!SYMBOLP (next))
3054 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
3056 if (EQ (next, Qand_rest))
3057 rest = 1;
3058 else if (EQ (next, Qand_optional))
3059 optional = 1;
3060 else if (rest)
3062 specbind (next, Flist (nargs - i, &arg_vector[i]));
3063 i = nargs;
3065 else if (i < nargs)
3066 specbind (next, arg_vector[i++]);
3067 else if (!optional)
3068 return Fsignal (Qwrong_number_of_arguments,
3069 Fcons (fun, Fcons (make_number (nargs), Qnil)));
3070 else
3071 specbind (next, Qnil);
3074 if (!NILP (syms_left))
3075 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
3076 else if (i < nargs)
3077 return Fsignal (Qwrong_number_of_arguments,
3078 Fcons (fun, Fcons (make_number (nargs), Qnil)));
3080 if (CONSP (fun))
3081 val = Fprogn (XCDR (XCDR (fun)));
3082 else
3084 /* If we have not actually read the bytecode string
3085 and constants vector yet, fetch them from the file. */
3086 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
3087 Ffetch_bytecode (fun);
3088 val = Fbyte_code (AREF (fun, COMPILED_BYTECODE),
3089 AREF (fun, COMPILED_CONSTANTS),
3090 AREF (fun, COMPILED_STACK_DEPTH));
3093 return unbind_to (count, val);
3096 DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
3097 1, 1, 0,
3098 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3099 (object)
3100 Lisp_Object object;
3102 Lisp_Object tem;
3104 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
3106 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
3107 if (!CONSP (tem))
3109 tem = AREF (object, COMPILED_BYTECODE);
3110 if (CONSP (tem) && STRINGP (XCAR (tem)))
3111 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
3112 else
3113 error ("Invalid byte code");
3115 AREF (object, COMPILED_BYTECODE) = XCAR (tem);
3116 AREF (object, COMPILED_CONSTANTS) = XCDR (tem);
3118 return object;
3121 void
3122 grow_specpdl ()
3124 register int count = SPECPDL_INDEX ();
3125 if (specpdl_size >= max_specpdl_size)
3127 if (max_specpdl_size < 400)
3128 max_specpdl_size = 400;
3129 if (specpdl_size >= max_specpdl_size)
3130 Fsignal (Qerror,
3131 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil));
3133 specpdl_size *= 2;
3134 if (specpdl_size > max_specpdl_size)
3135 specpdl_size = max_specpdl_size;
3136 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
3137 specpdl_ptr = specpdl + count;
3140 void
3141 specbind (symbol, value)
3142 Lisp_Object symbol, value;
3144 Lisp_Object ovalue;
3145 Lisp_Object valcontents;
3147 CHECK_SYMBOL (symbol);
3148 if (specpdl_ptr == specpdl + specpdl_size)
3149 grow_specpdl ();
3151 /* The most common case is that of a non-constant symbol with a
3152 trivial value. Make that as fast as we can. */
3153 valcontents = SYMBOL_VALUE (symbol);
3154 if (!MISCP (valcontents) && !SYMBOL_CONSTANT_P (symbol))
3156 specpdl_ptr->symbol = symbol;
3157 specpdl_ptr->old_value = valcontents;
3158 specpdl_ptr->func = NULL;
3159 ++specpdl_ptr;
3160 SET_SYMBOL_VALUE (symbol, value);
3162 else
3164 Lisp_Object valcontents;
3166 ovalue = find_symbol_value (symbol);
3167 specpdl_ptr->func = 0;
3168 specpdl_ptr->old_value = ovalue;
3170 valcontents = XSYMBOL (symbol)->value;
3172 if (BUFFER_LOCAL_VALUEP (valcontents)
3173 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
3174 || BUFFER_OBJFWDP (valcontents))
3176 Lisp_Object where, current_buffer;
3178 current_buffer = Fcurrent_buffer ();
3180 /* For a local variable, record both the symbol and which
3181 buffer's or frame's value we are saving. */
3182 if (!NILP (Flocal_variable_p (symbol, Qnil)))
3183 where = current_buffer;
3184 else if (!BUFFER_OBJFWDP (valcontents)
3185 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
3186 where = XBUFFER_LOCAL_VALUE (valcontents)->frame;
3187 else
3188 where = Qnil;
3190 /* We're not using the `unused' slot in the specbinding
3191 structure because this would mean we have to do more
3192 work for simple variables. */
3193 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, current_buffer));
3195 /* If SYMBOL is a per-buffer variable which doesn't have a
3196 buffer-local value here, make the `let' change the global
3197 value by changing the value of SYMBOL in all buffers not
3198 having their own value. This is consistent with what
3199 happens with other buffer-local variables. */
3200 if (NILP (where)
3201 && BUFFER_OBJFWDP (valcontents))
3203 ++specpdl_ptr;
3204 Fset_default (symbol, value);
3205 return;
3208 else
3209 specpdl_ptr->symbol = symbol;
3211 specpdl_ptr++;
3212 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
3213 store_symval_forwarding (symbol, ovalue, value, NULL);
3214 else
3215 set_internal (symbol, value, 0, 1);
3219 void
3220 record_unwind_protect (function, arg)
3221 Lisp_Object (*function) P_ ((Lisp_Object));
3222 Lisp_Object arg;
3224 eassert (!handling_signal);
3226 if (specpdl_ptr == specpdl + specpdl_size)
3227 grow_specpdl ();
3228 specpdl_ptr->func = function;
3229 specpdl_ptr->symbol = Qnil;
3230 specpdl_ptr->old_value = arg;
3231 specpdl_ptr++;
3234 Lisp_Object
3235 unbind_to (count, value)
3236 int count;
3237 Lisp_Object value;
3239 Lisp_Object quitf = Vquit_flag;
3240 struct gcpro gcpro1, gcpro2;
3242 GCPRO2 (value, quitf);
3243 Vquit_flag = Qnil;
3245 while (specpdl_ptr != specpdl + count)
3247 /* Copy the binding, and decrement specpdl_ptr, before we do
3248 the work to unbind it. We decrement first
3249 so that an error in unbinding won't try to unbind
3250 the same entry again, and we copy the binding first
3251 in case more bindings are made during some of the code we run. */
3253 struct specbinding this_binding;
3254 this_binding = *--specpdl_ptr;
3256 if (this_binding.func != 0)
3257 (*this_binding.func) (this_binding.old_value);
3258 /* If the symbol is a list, it is really (SYMBOL WHERE
3259 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3260 frame. If WHERE is a buffer or frame, this indicates we
3261 bound a variable that had a buffer-local or frame-local
3262 binding. WHERE nil means that the variable had the default
3263 value when it was bound. CURRENT-BUFFER is the buffer that
3264 was current when the variable was bound. */
3265 else if (CONSP (this_binding.symbol))
3267 Lisp_Object symbol, where;
3269 symbol = XCAR (this_binding.symbol);
3270 where = XCAR (XCDR (this_binding.symbol));
3272 if (NILP (where))
3273 Fset_default (symbol, this_binding.old_value);
3274 else if (BUFFERP (where))
3275 set_internal (symbol, this_binding.old_value, XBUFFER (where), 1);
3276 else
3277 set_internal (symbol, this_binding.old_value, NULL, 1);
3279 else
3281 /* If variable has a trivial value (no forwarding), we can
3282 just set it. No need to check for constant symbols here,
3283 since that was already done by specbind. */
3284 if (!MISCP (SYMBOL_VALUE (this_binding.symbol)))
3285 SET_SYMBOL_VALUE (this_binding.symbol, this_binding.old_value);
3286 else
3287 set_internal (this_binding.symbol, this_binding.old_value, 0, 1);
3291 if (NILP (Vquit_flag) && !NILP (quitf))
3292 Vquit_flag = quitf;
3294 UNGCPRO;
3295 return value;
3298 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
3299 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3300 The debugger is entered when that frame exits, if the flag is non-nil. */)
3301 (level, flag)
3302 Lisp_Object level, flag;
3304 register struct backtrace *backlist = backtrace_list;
3305 register int i;
3307 CHECK_NUMBER (level);
3309 for (i = 0; backlist && i < XINT (level); i++)
3311 backlist = backlist->next;
3314 if (backlist)
3315 backlist->debug_on_exit = !NILP (flag);
3317 return flag;
3320 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
3321 doc: /* Print a trace of Lisp function calls currently active.
3322 Output stream used is value of `standard-output'. */)
3325 register struct backtrace *backlist = backtrace_list;
3326 register int i;
3327 Lisp_Object tail;
3328 Lisp_Object tem;
3329 extern Lisp_Object Vprint_level;
3330 struct gcpro gcpro1;
3332 XSETFASTINT (Vprint_level, 3);
3334 tail = Qnil;
3335 GCPRO1 (tail);
3337 while (backlist)
3339 write_string (backlist->debug_on_exit ? "* " : " ", 2);
3340 if (backlist->nargs == UNEVALLED)
3342 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
3343 write_string ("\n", -1);
3345 else
3347 tem = *backlist->function;
3348 Fprin1 (tem, Qnil); /* This can QUIT */
3349 write_string ("(", -1);
3350 if (backlist->nargs == MANY)
3352 for (tail = *backlist->args, i = 0;
3353 !NILP (tail);
3354 tail = Fcdr (tail), i++)
3356 if (i) write_string (" ", -1);
3357 Fprin1 (Fcar (tail), Qnil);
3360 else
3362 for (i = 0; i < backlist->nargs; i++)
3364 if (i) write_string (" ", -1);
3365 Fprin1 (backlist->args[i], Qnil);
3368 write_string (")\n", -1);
3370 backlist = backlist->next;
3373 Vprint_level = Qnil;
3374 UNGCPRO;
3375 return Qnil;
3378 DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
3379 doc: /* Return the function and arguments NFRAMES up from current execution point.
3380 If that frame has not evaluated the arguments yet (or is a special form),
3381 the value is (nil FUNCTION ARG-FORMS...).
3382 If that frame has evaluated its arguments and called its function already,
3383 the value is (t FUNCTION ARG-VALUES...).
3384 A &rest arg is represented as the tail of the list ARG-VALUES.
3385 FUNCTION is whatever was supplied as car of evaluated list,
3386 or a lambda expression for macro calls.
3387 If NFRAMES is more than the number of frames, the value is nil. */)
3388 (nframes)
3389 Lisp_Object nframes;
3391 register struct backtrace *backlist = backtrace_list;
3392 register int i;
3393 Lisp_Object tem;
3395 CHECK_NATNUM (nframes);
3397 /* Find the frame requested. */
3398 for (i = 0; backlist && i < XFASTINT (nframes); i++)
3399 backlist = backlist->next;
3401 if (!backlist)
3402 return Qnil;
3403 if (backlist->nargs == UNEVALLED)
3404 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
3405 else
3407 if (backlist->nargs == MANY)
3408 tem = *backlist->args;
3409 else
3410 tem = Flist (backlist->nargs, backlist->args);
3412 return Fcons (Qt, Fcons (*backlist->function, tem));
3417 void
3418 mark_backtrace ()
3420 register struct backtrace *backlist;
3421 register int i;
3423 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3425 mark_object (*backlist->function);
3427 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
3428 i = 0;
3429 else
3430 i = backlist->nargs - 1;
3431 for (; i >= 0; i--)
3432 mark_object (backlist->args[i]);
3436 void
3437 syms_of_eval ()
3439 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
3440 doc: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
3441 If Lisp code tries to increase the total number past this amount,
3442 an error is signaled.
3443 You can safely use a value considerably larger than the default value,
3444 if that proves inconveniently small. However, if you increase it too far,
3445 Emacs could run out of memory trying to make the stack bigger. */);
3447 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
3448 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3450 This limit serves to catch infinite recursions for you before they cause
3451 actual stack overflow in C, which would be fatal for Emacs.
3452 You can safely make it considerably larger than its default value,
3453 if that proves inconveniently small. However, if you increase it too far,
3454 Emacs could overflow the real C stack, and crash. */);
3456 DEFVAR_LISP ("quit-flag", &Vquit_flag,
3457 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3458 If the value is t, that means do an ordinary quit.
3459 If the value equals `throw-on-input', that means quit by throwing
3460 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3461 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3462 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3463 Vquit_flag = Qnil;
3465 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
3466 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3467 Note that `quit-flag' will still be set by typing C-g,
3468 so a quit will be signaled as soon as `inhibit-quit' is nil.
3469 To prevent this happening, set `quit-flag' to nil
3470 before making `inhibit-quit' nil. */);
3471 Vinhibit_quit = Qnil;
3473 Qinhibit_quit = intern ("inhibit-quit");
3474 staticpro (&Qinhibit_quit);
3476 Qautoload = intern ("autoload");
3477 staticpro (&Qautoload);
3479 Qdebug_on_error = intern ("debug-on-error");
3480 staticpro (&Qdebug_on_error);
3482 Qmacro = intern ("macro");
3483 staticpro (&Qmacro);
3485 Qdeclare = intern ("declare");
3486 staticpro (&Qdeclare);
3488 /* Note that the process handling also uses Qexit, but we don't want
3489 to staticpro it twice, so we just do it here. */
3490 Qexit = intern ("exit");
3491 staticpro (&Qexit);
3493 Qinteractive = intern ("interactive");
3494 staticpro (&Qinteractive);
3496 Qcommandp = intern ("commandp");
3497 staticpro (&Qcommandp);
3499 Qdefun = intern ("defun");
3500 staticpro (&Qdefun);
3502 Qand_rest = intern ("&rest");
3503 staticpro (&Qand_rest);
3505 Qand_optional = intern ("&optional");
3506 staticpro (&Qand_optional);
3508 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
3509 doc: /* *Non-nil means errors display a backtrace buffer.
3510 More precisely, this happens for any error that is handled
3511 by the editor command loop.
3512 If the value is a list, an error only means to display a backtrace
3513 if one of its condition symbols appears in the list. */);
3514 Vstack_trace_on_error = Qnil;
3516 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
3517 doc: /* *Non-nil means enter debugger if an error is signaled.
3518 Does not apply to errors handled by `condition-case' or those
3519 matched by `debug-ignored-errors'.
3520 If the value is a list, an error only means to enter the debugger
3521 if one of its condition symbols appears in the list.
3522 When you evaluate an expression interactively, this variable
3523 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3524 See also variable `debug-on-quit'. */);
3525 Vdebug_on_error = Qnil;
3527 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors,
3528 doc: /* *List of errors for which the debugger should not be called.
3529 Each element may be a condition-name or a regexp that matches error messages.
3530 If any element applies to a given error, that error skips the debugger
3531 and just returns to top level.
3532 This overrides the variable `debug-on-error'.
3533 It does not apply to errors handled by `condition-case'. */);
3534 Vdebug_ignored_errors = Qnil;
3536 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
3537 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3538 Does not apply if quit is handled by a `condition-case'. */);
3539 debug_on_quit = 0;
3541 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
3542 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3544 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue,
3545 doc: /* Non-nil means debugger may continue execution.
3546 This is nil when the debugger is called under circumstances where it
3547 might not be safe to continue. */);
3548 debugger_may_continue = 1;
3550 DEFVAR_LISP ("debugger", &Vdebugger,
3551 doc: /* Function to call to invoke debugger.
3552 If due to frame exit, args are `exit' and the value being returned;
3553 this function's value will be returned instead of that.
3554 If due to error, args are `error' and a list of the args to `signal'.
3555 If due to `apply' or `funcall' entry, one arg, `lambda'.
3556 If due to `eval' entry, one arg, t. */);
3557 Vdebugger = Qnil;
3559 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function,
3560 doc: /* If non-nil, this is a function for `signal' to call.
3561 It receives the same arguments that `signal' was given.
3562 The Edebug package uses this to regain control. */);
3563 Vsignal_hook_function = Qnil;
3565 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal,
3566 doc: /* *Non-nil means call the debugger regardless of condition handlers.
3567 Note that `debug-on-error', `debug-on-quit' and friends
3568 still determine whether to handle the particular condition. */);
3569 Vdebug_on_signal = Qnil;
3571 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function,
3572 doc: /* Function to process declarations in a macro definition.
3573 The function will be called with two args MACRO and DECL.
3574 MACRO is the name of the macro being defined.
3575 DECL is a list `(declare ...)' containing the declarations.
3576 The value the function returns is not used. */);
3577 Vmacro_declaration_function = Qnil;
3579 Vrun_hooks = intern ("run-hooks");
3580 staticpro (&Vrun_hooks);
3582 staticpro (&Vautoload_queue);
3583 Vautoload_queue = Qnil;
3584 staticpro (&Vsignaling_function);
3585 Vsignaling_function = Qnil;
3587 defsubr (&Sor);
3588 defsubr (&Sand);
3589 defsubr (&Sif);
3590 defsubr (&Scond);
3591 defsubr (&Sprogn);
3592 defsubr (&Sprog1);
3593 defsubr (&Sprog2);
3594 defsubr (&Ssetq);
3595 defsubr (&Squote);
3596 defsubr (&Sfunction);
3597 defsubr (&Sdefun);
3598 defsubr (&Sdefmacro);
3599 defsubr (&Sdefvar);
3600 defsubr (&Sdefvaralias);
3601 defsubr (&Sdefconst);
3602 defsubr (&Suser_variable_p);
3603 defsubr (&Slet);
3604 defsubr (&SletX);
3605 defsubr (&Swhile);
3606 defsubr (&Smacroexpand);
3607 defsubr (&Scatch);
3608 defsubr (&Sthrow);
3609 defsubr (&Sunwind_protect);
3610 defsubr (&Scondition_case);
3611 defsubr (&Ssignal);
3612 defsubr (&Sinteractive_p);
3613 defsubr (&Scalled_interactively_p);
3614 defsubr (&Scommandp);
3615 defsubr (&Sautoload);
3616 defsubr (&Seval);
3617 defsubr (&Sapply);
3618 defsubr (&Sfuncall);
3619 defsubr (&Srun_hooks);
3620 defsubr (&Srun_hook_with_args);
3621 defsubr (&Srun_hook_with_args_until_success);
3622 defsubr (&Srun_hook_with_args_until_failure);
3623 defsubr (&Sfetch_bytecode);
3624 defsubr (&Sbacktrace_debug);
3625 defsubr (&Sbacktrace);
3626 defsubr (&Sbacktrace_frame);
3629 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3630 (do not change this comment) */