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