Feval: On Carbon/MacOSX call mac_check_for_quit_char at each stack frame.
[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
2164 #ifdef HAVE_CARBON
2165 mac_check_for_quit_char();
2166 #endif
2167 return val;
2168 }
2169 \f
2170 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
2171 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2172 Then return the value FUNCTION returns.
2173 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2174 usage: (apply FUNCTION &rest ARGUMENTS) */)
2175 (nargs, args)
2176 int nargs;
2177 Lisp_Object *args;
2178 {
2179 register int i, numargs;
2180 register Lisp_Object spread_arg;
2181 register Lisp_Object *funcall_args;
2182 Lisp_Object fun;
2183 struct gcpro gcpro1;
2184
2185 fun = args [0];
2186 funcall_args = 0;
2187 spread_arg = args [nargs - 1];
2188 CHECK_LIST (spread_arg);
2189
2190 numargs = XINT (Flength (spread_arg));
2191
2192 if (numargs == 0)
2193 return Ffuncall (nargs - 1, args);
2194 else if (numargs == 1)
2195 {
2196 args [nargs - 1] = XCAR (spread_arg);
2197 return Ffuncall (nargs, args);
2198 }
2199
2200 numargs += nargs - 2;
2201
2202 fun = indirect_function (fun);
2203 if (EQ (fun, Qunbound))
2204 {
2205 /* Let funcall get the error */
2206 fun = args[0];
2207 goto funcall;
2208 }
2209
2210 if (SUBRP (fun))
2211 {
2212 if (numargs < XSUBR (fun)->min_args
2213 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2214 goto funcall; /* Let funcall get the error */
2215 else if (XSUBR (fun)->max_args > numargs)
2216 {
2217 /* Avoid making funcall cons up a yet another new vector of arguments
2218 by explicitly supplying nil's for optional values */
2219 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
2220 * sizeof (Lisp_Object));
2221 for (i = numargs; i < XSUBR (fun)->max_args;)
2222 funcall_args[++i] = Qnil;
2223 GCPRO1 (*funcall_args);
2224 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
2225 }
2226 }
2227 funcall:
2228 /* We add 1 to numargs because funcall_args includes the
2229 function itself as well as its arguments. */
2230 if (!funcall_args)
2231 {
2232 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
2233 * sizeof (Lisp_Object));
2234 GCPRO1 (*funcall_args);
2235 gcpro1.nvars = 1 + numargs;
2236 }
2237
2238 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
2239 /* Spread the last arg we got. Its first element goes in
2240 the slot that it used to occupy, hence this value of I. */
2241 i = nargs - 1;
2242 while (!NILP (spread_arg))
2243 {
2244 funcall_args [i++] = XCAR (spread_arg);
2245 spread_arg = XCDR (spread_arg);
2246 }
2247
2248 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
2249 }
2250 \f
2251 /* Run hook variables in various ways. */
2252
2253 enum run_hooks_condition {to_completion, until_success, until_failure};
2254 static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *,
2255 enum run_hooks_condition));
2256
2257 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
2258 doc: /* Run each hook in HOOKS. Major mode functions use this.
2259 Each argument should be a symbol, a hook variable.
2260 These symbols are processed in the order specified.
2261 If a hook symbol has a non-nil value, that value may be a function
2262 or a list of functions to be called to run the hook.
2263 If the value is a function, it is called with no arguments.
2264 If it is a list, the elements are called, in order, with no arguments.
2265
2266 Do not use `make-local-variable' to make a hook variable buffer-local.
2267 Instead, use `add-hook' and specify t for the LOCAL argument.
2268 usage: (run-hooks &rest HOOKS) */)
2269 (nargs, args)
2270 int nargs;
2271 Lisp_Object *args;
2272 {
2273 Lisp_Object hook[1];
2274 register int i;
2275
2276 for (i = 0; i < nargs; i++)
2277 {
2278 hook[0] = args[i];
2279 run_hook_with_args (1, hook, to_completion);
2280 }
2281
2282 return Qnil;
2283 }
2284
2285 DEFUN ("run-hook-with-args", Frun_hook_with_args,
2286 Srun_hook_with_args, 1, MANY, 0,
2287 doc: /* Run HOOK with the specified arguments ARGS.
2288 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2289 value, that value may be a function or a list of functions to be
2290 called to run the hook. If the value is a function, it is called with
2291 the given arguments and its return value is returned. If it is a list
2292 of functions, those functions are called, in order,
2293 with the given arguments ARGS.
2294 It is best not to depend on the value return by `run-hook-with-args',
2295 as that may change.
2296
2297 Do not use `make-local-variable' to make a hook variable buffer-local.
2298 Instead, use `add-hook' and specify t for the LOCAL argument.
2299 usage: (run-hook-with-args HOOK &rest ARGS) */)
2300 (nargs, args)
2301 int nargs;
2302 Lisp_Object *args;
2303 {
2304 return run_hook_with_args (nargs, args, to_completion);
2305 }
2306
2307 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
2308 Srun_hook_with_args_until_success, 1, MANY, 0,
2309 doc: /* Run HOOK with the specified arguments ARGS.
2310 HOOK should be a symbol, a hook variable. Its value should
2311 be a list of functions. We call those functions, one by one,
2312 passing arguments ARGS to each of them, until one of them
2313 returns a non-nil value. Then we return that value.
2314 If all the functions return nil, we return nil.
2315
2316 Do not use `make-local-variable' to make a hook variable buffer-local.
2317 Instead, use `add-hook' and specify t for the LOCAL argument.
2318 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2319 (nargs, args)
2320 int nargs;
2321 Lisp_Object *args;
2322 {
2323 return run_hook_with_args (nargs, args, until_success);
2324 }
2325
2326 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
2327 Srun_hook_with_args_until_failure, 1, MANY, 0,
2328 doc: /* Run HOOK with the specified arguments ARGS.
2329 HOOK should be a symbol, a hook variable. Its value should
2330 be a list of functions. We call those functions, one by one,
2331 passing arguments ARGS to each of them, until one of them
2332 returns nil. Then we return nil.
2333 If all the functions return non-nil, we return non-nil.
2334
2335 Do not use `make-local-variable' to make a hook variable buffer-local.
2336 Instead, use `add-hook' and specify t for the LOCAL argument.
2337 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2338 (nargs, args)
2339 int nargs;
2340 Lisp_Object *args;
2341 {
2342 return run_hook_with_args (nargs, args, until_failure);
2343 }
2344
2345 /* ARGS[0] should be a hook symbol.
2346 Call each of the functions in the hook value, passing each of them
2347 as arguments all the rest of ARGS (all NARGS - 1 elements).
2348 COND specifies a condition to test after each call
2349 to decide whether to stop.
2350 The caller (or its caller, etc) must gcpro all of ARGS,
2351 except that it isn't necessary to gcpro ARGS[0]. */
2352
2353 static Lisp_Object
2354 run_hook_with_args (nargs, args, cond)
2355 int nargs;
2356 Lisp_Object *args;
2357 enum run_hooks_condition cond;
2358 {
2359 Lisp_Object sym, val, ret;
2360 Lisp_Object globals;
2361 struct gcpro gcpro1, gcpro2, gcpro3;
2362
2363 /* If we are dying or still initializing,
2364 don't do anything--it would probably crash if we tried. */
2365 if (NILP (Vrun_hooks))
2366 return Qnil;
2367
2368 sym = args[0];
2369 val = find_symbol_value (sym);
2370 ret = (cond == until_failure ? Qt : Qnil);
2371
2372 if (EQ (val, Qunbound) || NILP (val))
2373 return ret;
2374 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
2375 {
2376 args[0] = val;
2377 return Ffuncall (nargs, args);
2378 }
2379 else
2380 {
2381 globals = Qnil;
2382 GCPRO3 (sym, val, globals);
2383
2384 for (;
2385 CONSP (val) && ((cond == to_completion)
2386 || (cond == until_success ? NILP (ret)
2387 : !NILP (ret)));
2388 val = XCDR (val))
2389 {
2390 if (EQ (XCAR (val), Qt))
2391 {
2392 /* t indicates this hook has a local binding;
2393 it means to run the global binding too. */
2394
2395 for (globals = Fdefault_value (sym);
2396 CONSP (globals) && ((cond == to_completion)
2397 || (cond == until_success ? NILP (ret)
2398 : !NILP (ret)));
2399 globals = XCDR (globals))
2400 {
2401 args[0] = XCAR (globals);
2402 /* In a global value, t should not occur. If it does, we
2403 must ignore it to avoid an endless loop. */
2404 if (!EQ (args[0], Qt))
2405 ret = Ffuncall (nargs, args);
2406 }
2407 }
2408 else
2409 {
2410 args[0] = XCAR (val);
2411 ret = Ffuncall (nargs, args);
2412 }
2413 }
2414
2415 UNGCPRO;
2416 return ret;
2417 }
2418 }
2419
2420 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2421 present value of that symbol.
2422 Call each element of FUNLIST,
2423 passing each of them the rest of ARGS.
2424 The caller (or its caller, etc) must gcpro all of ARGS,
2425 except that it isn't necessary to gcpro ARGS[0]. */
2426
2427 Lisp_Object
2428 run_hook_list_with_args (funlist, nargs, args)
2429 Lisp_Object funlist;
2430 int nargs;
2431 Lisp_Object *args;
2432 {
2433 Lisp_Object sym;
2434 Lisp_Object val;
2435 Lisp_Object globals;
2436 struct gcpro gcpro1, gcpro2, gcpro3;
2437
2438 sym = args[0];
2439 globals = Qnil;
2440 GCPRO3 (sym, val, globals);
2441
2442 for (val = funlist; CONSP (val); val = XCDR (val))
2443 {
2444 if (EQ (XCAR (val), Qt))
2445 {
2446 /* t indicates this hook has a local binding;
2447 it means to run the global binding too. */
2448
2449 for (globals = Fdefault_value (sym);
2450 CONSP (globals);
2451 globals = XCDR (globals))
2452 {
2453 args[0] = XCAR (globals);
2454 /* In a global value, t should not occur. If it does, we
2455 must ignore it to avoid an endless loop. */
2456 if (!EQ (args[0], Qt))
2457 Ffuncall (nargs, args);
2458 }
2459 }
2460 else
2461 {
2462 args[0] = XCAR (val);
2463 Ffuncall (nargs, args);
2464 }
2465 }
2466 UNGCPRO;
2467 return Qnil;
2468 }
2469
2470 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2471
2472 void
2473 run_hook_with_args_2 (hook, arg1, arg2)
2474 Lisp_Object hook, arg1, arg2;
2475 {
2476 Lisp_Object temp[3];
2477 temp[0] = hook;
2478 temp[1] = arg1;
2479 temp[2] = arg2;
2480
2481 Frun_hook_with_args (3, temp);
2482 }
2483 \f
2484 /* Apply fn to arg */
2485 Lisp_Object
2486 apply1 (fn, arg)
2487 Lisp_Object fn, arg;
2488 {
2489 struct gcpro gcpro1;
2490
2491 GCPRO1 (fn);
2492 if (NILP (arg))
2493 RETURN_UNGCPRO (Ffuncall (1, &fn));
2494 gcpro1.nvars = 2;
2495 #ifdef NO_ARG_ARRAY
2496 {
2497 Lisp_Object args[2];
2498 args[0] = fn;
2499 args[1] = arg;
2500 gcpro1.var = args;
2501 RETURN_UNGCPRO (Fapply (2, args));
2502 }
2503 #else /* not NO_ARG_ARRAY */
2504 RETURN_UNGCPRO (Fapply (2, &fn));
2505 #endif /* not NO_ARG_ARRAY */
2506 }
2507
2508 /* Call function fn on no arguments */
2509 Lisp_Object
2510 call0 (fn)
2511 Lisp_Object fn;
2512 {
2513 struct gcpro gcpro1;
2514
2515 GCPRO1 (fn);
2516 RETURN_UNGCPRO (Ffuncall (1, &fn));
2517 }
2518
2519 /* Call function fn with 1 argument arg1 */
2520 /* ARGSUSED */
2521 Lisp_Object
2522 call1 (fn, arg1)
2523 Lisp_Object fn, arg1;
2524 {
2525 struct gcpro gcpro1;
2526 #ifdef NO_ARG_ARRAY
2527 Lisp_Object args[2];
2528
2529 args[0] = fn;
2530 args[1] = arg1;
2531 GCPRO1 (args[0]);
2532 gcpro1.nvars = 2;
2533 RETURN_UNGCPRO (Ffuncall (2, args));
2534 #else /* not NO_ARG_ARRAY */
2535 GCPRO1 (fn);
2536 gcpro1.nvars = 2;
2537 RETURN_UNGCPRO (Ffuncall (2, &fn));
2538 #endif /* not NO_ARG_ARRAY */
2539 }
2540
2541 /* Call function fn with 2 arguments arg1, arg2 */
2542 /* ARGSUSED */
2543 Lisp_Object
2544 call2 (fn, arg1, arg2)
2545 Lisp_Object fn, arg1, arg2;
2546 {
2547 struct gcpro gcpro1;
2548 #ifdef NO_ARG_ARRAY
2549 Lisp_Object args[3];
2550 args[0] = fn;
2551 args[1] = arg1;
2552 args[2] = arg2;
2553 GCPRO1 (args[0]);
2554 gcpro1.nvars = 3;
2555 RETURN_UNGCPRO (Ffuncall (3, args));
2556 #else /* not NO_ARG_ARRAY */
2557 GCPRO1 (fn);
2558 gcpro1.nvars = 3;
2559 RETURN_UNGCPRO (Ffuncall (3, &fn));
2560 #endif /* not NO_ARG_ARRAY */
2561 }
2562
2563 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2564 /* ARGSUSED */
2565 Lisp_Object
2566 call3 (fn, arg1, arg2, arg3)
2567 Lisp_Object fn, arg1, arg2, arg3;
2568 {
2569 struct gcpro gcpro1;
2570 #ifdef NO_ARG_ARRAY
2571 Lisp_Object args[4];
2572 args[0] = fn;
2573 args[1] = arg1;
2574 args[2] = arg2;
2575 args[3] = arg3;
2576 GCPRO1 (args[0]);
2577 gcpro1.nvars = 4;
2578 RETURN_UNGCPRO (Ffuncall (4, args));
2579 #else /* not NO_ARG_ARRAY */
2580 GCPRO1 (fn);
2581 gcpro1.nvars = 4;
2582 RETURN_UNGCPRO (Ffuncall (4, &fn));
2583 #endif /* not NO_ARG_ARRAY */
2584 }
2585
2586 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2587 /* ARGSUSED */
2588 Lisp_Object
2589 call4 (fn, arg1, arg2, arg3, arg4)
2590 Lisp_Object fn, arg1, arg2, arg3, arg4;
2591 {
2592 struct gcpro gcpro1;
2593 #ifdef NO_ARG_ARRAY
2594 Lisp_Object args[5];
2595 args[0] = fn;
2596 args[1] = arg1;
2597 args[2] = arg2;
2598 args[3] = arg3;
2599 args[4] = arg4;
2600 GCPRO1 (args[0]);
2601 gcpro1.nvars = 5;
2602 RETURN_UNGCPRO (Ffuncall (5, args));
2603 #else /* not NO_ARG_ARRAY */
2604 GCPRO1 (fn);
2605 gcpro1.nvars = 5;
2606 RETURN_UNGCPRO (Ffuncall (5, &fn));
2607 #endif /* not NO_ARG_ARRAY */
2608 }
2609
2610 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2611 /* ARGSUSED */
2612 Lisp_Object
2613 call5 (fn, arg1, arg2, arg3, arg4, arg5)
2614 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
2615 {
2616 struct gcpro gcpro1;
2617 #ifdef NO_ARG_ARRAY
2618 Lisp_Object args[6];
2619 args[0] = fn;
2620 args[1] = arg1;
2621 args[2] = arg2;
2622 args[3] = arg3;
2623 args[4] = arg4;
2624 args[5] = arg5;
2625 GCPRO1 (args[0]);
2626 gcpro1.nvars = 6;
2627 RETURN_UNGCPRO (Ffuncall (6, args));
2628 #else /* not NO_ARG_ARRAY */
2629 GCPRO1 (fn);
2630 gcpro1.nvars = 6;
2631 RETURN_UNGCPRO (Ffuncall (6, &fn));
2632 #endif /* not NO_ARG_ARRAY */
2633 }
2634
2635 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2636 /* ARGSUSED */
2637 Lisp_Object
2638 call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
2639 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
2640 {
2641 struct gcpro gcpro1;
2642 #ifdef NO_ARG_ARRAY
2643 Lisp_Object args[7];
2644 args[0] = fn;
2645 args[1] = arg1;
2646 args[2] = arg2;
2647 args[3] = arg3;
2648 args[4] = arg4;
2649 args[5] = arg5;
2650 args[6] = arg6;
2651 GCPRO1 (args[0]);
2652 gcpro1.nvars = 7;
2653 RETURN_UNGCPRO (Ffuncall (7, args));
2654 #else /* not NO_ARG_ARRAY */
2655 GCPRO1 (fn);
2656 gcpro1.nvars = 7;
2657 RETURN_UNGCPRO (Ffuncall (7, &fn));
2658 #endif /* not NO_ARG_ARRAY */
2659 }
2660
2661 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2662 doc: /* Call first argument as a function, passing remaining arguments to it.
2663 Return the value that function returns.
2664 Thus, (funcall 'cons 'x 'y) returns (x . y).
2665 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2666 (nargs, args)
2667 int nargs;
2668 Lisp_Object *args;
2669 {
2670 Lisp_Object fun;
2671 Lisp_Object funcar;
2672 int numargs = nargs - 1;
2673 Lisp_Object lisp_numargs;
2674 Lisp_Object val;
2675 struct backtrace backtrace;
2676 register Lisp_Object *internal_args;
2677 register int i;
2678
2679 QUIT;
2680 if (consing_since_gc > gc_cons_threshold)
2681 Fgarbage_collect ();
2682
2683 if (++lisp_eval_depth > max_lisp_eval_depth)
2684 {
2685 if (max_lisp_eval_depth < 100)
2686 max_lisp_eval_depth = 100;
2687 if (lisp_eval_depth > max_lisp_eval_depth)
2688 error ("Lisp nesting exceeds max-lisp-eval-depth");
2689 }
2690
2691 backtrace.next = backtrace_list;
2692 backtrace_list = &backtrace;
2693 backtrace.function = &args[0];
2694 backtrace.args = &args[1];
2695 backtrace.nargs = nargs - 1;
2696 backtrace.evalargs = 0;
2697 backtrace.debug_on_exit = 0;
2698
2699 if (debug_on_next_call)
2700 do_debug_on_call (Qlambda);
2701
2702 retry:
2703
2704 fun = args[0];
2705
2706 fun = Findirect_function (fun);
2707
2708 if (SUBRP (fun))
2709 {
2710 if (numargs < XSUBR (fun)->min_args
2711 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2712 {
2713 XSETFASTINT (lisp_numargs, numargs);
2714 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
2715 }
2716
2717 if (XSUBR (fun)->max_args == UNEVALLED)
2718 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2719
2720 if (XSUBR (fun)->max_args == MANY)
2721 {
2722 val = (*XSUBR (fun)->function) (numargs, args + 1);
2723 goto done;
2724 }
2725
2726 if (XSUBR (fun)->max_args > numargs)
2727 {
2728 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2729 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
2730 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2731 internal_args[i] = Qnil;
2732 }
2733 else
2734 internal_args = args + 1;
2735 switch (XSUBR (fun)->max_args)
2736 {
2737 case 0:
2738 val = (*XSUBR (fun)->function) ();
2739 goto done;
2740 case 1:
2741 val = (*XSUBR (fun)->function) (internal_args[0]);
2742 goto done;
2743 case 2:
2744 val = (*XSUBR (fun)->function) (internal_args[0],
2745 internal_args[1]);
2746 goto done;
2747 case 3:
2748 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2749 internal_args[2]);
2750 goto done;
2751 case 4:
2752 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2753 internal_args[2],
2754 internal_args[3]);
2755 goto done;
2756 case 5:
2757 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2758 internal_args[2], internal_args[3],
2759 internal_args[4]);
2760 goto done;
2761 case 6:
2762 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2763 internal_args[2], internal_args[3],
2764 internal_args[4], internal_args[5]);
2765 goto done;
2766 case 7:
2767 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2768 internal_args[2], internal_args[3],
2769 internal_args[4], internal_args[5],
2770 internal_args[6]);
2771 goto done;
2772
2773 case 8:
2774 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2775 internal_args[2], internal_args[3],
2776 internal_args[4], internal_args[5],
2777 internal_args[6], internal_args[7]);
2778 goto done;
2779
2780 default:
2781
2782 /* If a subr takes more than 8 arguments without using MANY
2783 or UNEVALLED, we need to extend this function to support it.
2784 Until this is done, there is no way to call the function. */
2785 abort ();
2786 }
2787 }
2788 if (COMPILEDP (fun))
2789 val = funcall_lambda (fun, numargs, args + 1);
2790 else
2791 {
2792 if (!CONSP (fun))
2793 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2794 funcar = Fcar (fun);
2795 if (!SYMBOLP (funcar))
2796 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2797 if (EQ (funcar, Qlambda))
2798 val = funcall_lambda (fun, numargs, args + 1);
2799 else if (EQ (funcar, Qautoload))
2800 {
2801 do_autoload (fun, args[0]);
2802 goto retry;
2803 }
2804 else
2805 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2806 }
2807 done:
2808 lisp_eval_depth--;
2809 if (backtrace.debug_on_exit)
2810 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2811 backtrace_list = backtrace.next;
2812 return val;
2813 }
2814 \f
2815 Lisp_Object
2816 apply_lambda (fun, args, eval_flag)
2817 Lisp_Object fun, args;
2818 int eval_flag;
2819 {
2820 Lisp_Object args_left;
2821 Lisp_Object numargs;
2822 register Lisp_Object *arg_vector;
2823 struct gcpro gcpro1, gcpro2, gcpro3;
2824 register int i;
2825 register Lisp_Object tem;
2826
2827 numargs = Flength (args);
2828 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2829 args_left = args;
2830
2831 GCPRO3 (*arg_vector, args_left, fun);
2832 gcpro1.nvars = 0;
2833
2834 for (i = 0; i < XINT (numargs);)
2835 {
2836 tem = Fcar (args_left), args_left = Fcdr (args_left);
2837 if (eval_flag) tem = Feval (tem);
2838 arg_vector[i++] = tem;
2839 gcpro1.nvars = i;
2840 }
2841
2842 UNGCPRO;
2843
2844 if (eval_flag)
2845 {
2846 backtrace_list->args = arg_vector;
2847 backtrace_list->nargs = i;
2848 }
2849 backtrace_list->evalargs = 0;
2850 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
2851
2852 /* Do the debug-on-exit now, while arg_vector still exists. */
2853 if (backtrace_list->debug_on_exit)
2854 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
2855 /* Don't do it again when we return to eval. */
2856 backtrace_list->debug_on_exit = 0;
2857 return tem;
2858 }
2859
2860 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2861 and return the result of evaluation.
2862 FUN must be either a lambda-expression or a compiled-code object. */
2863
2864 static Lisp_Object
2865 funcall_lambda (fun, nargs, arg_vector)
2866 Lisp_Object fun;
2867 int nargs;
2868 register Lisp_Object *arg_vector;
2869 {
2870 Lisp_Object val, syms_left, next;
2871 int count = SPECPDL_INDEX ();
2872 int i, optional, rest;
2873
2874 if (CONSP (fun))
2875 {
2876 syms_left = XCDR (fun);
2877 if (CONSP (syms_left))
2878 syms_left = XCAR (syms_left);
2879 else
2880 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2881 }
2882 else if (COMPILEDP (fun))
2883 syms_left = AREF (fun, COMPILED_ARGLIST);
2884 else
2885 abort ();
2886
2887 i = optional = rest = 0;
2888 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
2889 {
2890 QUIT;
2891
2892 next = XCAR (syms_left);
2893 while (!SYMBOLP (next))
2894 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2895
2896 if (EQ (next, Qand_rest))
2897 rest = 1;
2898 else if (EQ (next, Qand_optional))
2899 optional = 1;
2900 else if (rest)
2901 {
2902 specbind (next, Flist (nargs - i, &arg_vector[i]));
2903 i = nargs;
2904 }
2905 else if (i < nargs)
2906 specbind (next, arg_vector[i++]);
2907 else if (!optional)
2908 return Fsignal (Qwrong_number_of_arguments,
2909 Fcons (fun, Fcons (make_number (nargs), Qnil)));
2910 else
2911 specbind (next, Qnil);
2912 }
2913
2914 if (!NILP (syms_left))
2915 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2916 else if (i < nargs)
2917 return Fsignal (Qwrong_number_of_arguments,
2918 Fcons (fun, Fcons (make_number (nargs), Qnil)));
2919
2920 if (CONSP (fun))
2921 val = Fprogn (XCDR (XCDR (fun)));
2922 else
2923 {
2924 /* If we have not actually read the bytecode string
2925 and constants vector yet, fetch them from the file. */
2926 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
2927 Ffetch_bytecode (fun);
2928 val = Fbyte_code (AREF (fun, COMPILED_BYTECODE),
2929 AREF (fun, COMPILED_CONSTANTS),
2930 AREF (fun, COMPILED_STACK_DEPTH));
2931 }
2932
2933 return unbind_to (count, val);
2934 }
2935
2936 DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
2937 1, 1, 0,
2938 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2939 (object)
2940 Lisp_Object object;
2941 {
2942 Lisp_Object tem;
2943
2944 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
2945 {
2946 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
2947 if (!CONSP (tem))
2948 {
2949 tem = AREF (object, COMPILED_BYTECODE);
2950 if (CONSP (tem) && STRINGP (XCAR (tem)))
2951 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
2952 else
2953 error ("Invalid byte code");
2954 }
2955 AREF (object, COMPILED_BYTECODE) = XCAR (tem);
2956 AREF (object, COMPILED_CONSTANTS) = XCDR (tem);
2957 }
2958 return object;
2959 }
2960 \f
2961 void
2962 grow_specpdl ()
2963 {
2964 register int count = SPECPDL_INDEX ();
2965 if (specpdl_size >= max_specpdl_size)
2966 {
2967 if (max_specpdl_size < 400)
2968 max_specpdl_size = 400;
2969 if (specpdl_size >= max_specpdl_size)
2970 {
2971 if (!NILP (Vdebug_on_error))
2972 /* Leave room for some specpdl in the debugger. */
2973 max_specpdl_size = specpdl_size + 100;
2974 Fsignal (Qerror,
2975 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil));
2976 }
2977 }
2978 specpdl_size *= 2;
2979 if (specpdl_size > max_specpdl_size)
2980 specpdl_size = max_specpdl_size;
2981 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
2982 specpdl_ptr = specpdl + count;
2983 }
2984
2985 void
2986 specbind (symbol, value)
2987 Lisp_Object symbol, value;
2988 {
2989 Lisp_Object ovalue;
2990 Lisp_Object valcontents;
2991
2992 CHECK_SYMBOL (symbol);
2993 if (specpdl_ptr == specpdl + specpdl_size)
2994 grow_specpdl ();
2995
2996 /* The most common case is that of a non-constant symbol with a
2997 trivial value. Make that as fast as we can. */
2998 valcontents = SYMBOL_VALUE (symbol);
2999 if (!MISCP (valcontents) && !SYMBOL_CONSTANT_P (symbol))
3000 {
3001 specpdl_ptr->symbol = symbol;
3002 specpdl_ptr->old_value = valcontents;
3003 specpdl_ptr->func = NULL;
3004 ++specpdl_ptr;
3005 SET_SYMBOL_VALUE (symbol, value);
3006 }
3007 else
3008 {
3009 Lisp_Object valcontents;
3010
3011 ovalue = find_symbol_value (symbol);
3012 specpdl_ptr->func = 0;
3013 specpdl_ptr->old_value = ovalue;
3014
3015 valcontents = XSYMBOL (symbol)->value;
3016
3017 if (BUFFER_LOCAL_VALUEP (valcontents)
3018 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
3019 || BUFFER_OBJFWDP (valcontents))
3020 {
3021 Lisp_Object where, current_buffer;
3022
3023 current_buffer = Fcurrent_buffer ();
3024
3025 /* For a local variable, record both the symbol and which
3026 buffer's or frame's value we are saving. */
3027 if (!NILP (Flocal_variable_p (symbol, Qnil)))
3028 where = current_buffer;
3029 else if (!BUFFER_OBJFWDP (valcontents)
3030 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
3031 where = XBUFFER_LOCAL_VALUE (valcontents)->frame;
3032 else
3033 where = Qnil;
3034
3035 /* We're not using the `unused' slot in the specbinding
3036 structure because this would mean we have to do more
3037 work for simple variables. */
3038 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, current_buffer));
3039
3040 /* If SYMBOL is a per-buffer variable which doesn't have a
3041 buffer-local value here, make the `let' change the global
3042 value by changing the value of SYMBOL in all buffers not
3043 having their own value. This is consistent with what
3044 happens with other buffer-local variables. */
3045 if (NILP (where)
3046 && BUFFER_OBJFWDP (valcontents))
3047 {
3048 ++specpdl_ptr;
3049 Fset_default (symbol, value);
3050 return;
3051 }
3052 }
3053 else
3054 specpdl_ptr->symbol = symbol;
3055
3056 specpdl_ptr++;
3057 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
3058 store_symval_forwarding (symbol, ovalue, value, NULL);
3059 else
3060 set_internal (symbol, value, 0, 1);
3061 }
3062 }
3063
3064 void
3065 record_unwind_protect (function, arg)
3066 Lisp_Object (*function) P_ ((Lisp_Object));
3067 Lisp_Object arg;
3068 {
3069 if (specpdl_ptr == specpdl + specpdl_size)
3070 grow_specpdl ();
3071 specpdl_ptr->func = function;
3072 specpdl_ptr->symbol = Qnil;
3073 specpdl_ptr->old_value = arg;
3074 specpdl_ptr++;
3075 }
3076
3077 Lisp_Object
3078 unbind_to (count, value)
3079 int count;
3080 Lisp_Object value;
3081 {
3082 int quitf = !NILP (Vquit_flag);
3083 struct gcpro gcpro1;
3084
3085 GCPRO1 (value);
3086 Vquit_flag = Qnil;
3087
3088 while (specpdl_ptr != specpdl + count)
3089 {
3090 --specpdl_ptr;
3091
3092 if (specpdl_ptr->func != 0)
3093 (*specpdl_ptr->func) (specpdl_ptr->old_value);
3094 /* Note that a "binding" of nil is really an unwind protect,
3095 so in that case the "old value" is a list of forms to evaluate. */
3096 else if (NILP (specpdl_ptr->symbol))
3097 Fprogn (specpdl_ptr->old_value);
3098 /* If the symbol is a list, it is really (SYMBOL WHERE
3099 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3100 frame. If WHERE is a buffer or frame, this indicates we
3101 bound a variable that had a buffer-local or frame-local
3102 binding. WHERE nil means that the variable had the default
3103 value when it was bound. CURRENT-BUFFER is the buffer that
3104 was current when the variable was bound. */
3105 else if (CONSP (specpdl_ptr->symbol))
3106 {
3107 Lisp_Object symbol, where;
3108
3109 symbol = XCAR (specpdl_ptr->symbol);
3110 where = XCAR (XCDR (specpdl_ptr->symbol));
3111
3112 if (NILP (where))
3113 Fset_default (symbol, specpdl_ptr->old_value);
3114 else if (BUFFERP (where))
3115 set_internal (symbol, specpdl_ptr->old_value, XBUFFER (where), 1);
3116 else
3117 set_internal (symbol, specpdl_ptr->old_value, NULL, 1);
3118 }
3119 else
3120 {
3121 /* If variable has a trivial value (no forwarding), we can
3122 just set it. No need to check for constant symbols here,
3123 since that was already done by specbind. */
3124 if (!MISCP (SYMBOL_VALUE (specpdl_ptr->symbol)))
3125 SET_SYMBOL_VALUE (specpdl_ptr->symbol, specpdl_ptr->old_value);
3126 else
3127 set_internal (specpdl_ptr->symbol, specpdl_ptr->old_value, 0, 1);
3128 }
3129 }
3130
3131 if (NILP (Vquit_flag) && quitf)
3132 Vquit_flag = Qt;
3133
3134 UNGCPRO;
3135 return value;
3136 }
3137 \f
3138 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
3139 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3140 The debugger is entered when that frame exits, if the flag is non-nil. */)
3141 (level, flag)
3142 Lisp_Object level, flag;
3143 {
3144 register struct backtrace *backlist = backtrace_list;
3145 register int i;
3146
3147 CHECK_NUMBER (level);
3148
3149 for (i = 0; backlist && i < XINT (level); i++)
3150 {
3151 backlist = backlist->next;
3152 }
3153
3154 if (backlist)
3155 backlist->debug_on_exit = !NILP (flag);
3156
3157 return flag;
3158 }
3159
3160 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
3161 doc: /* Print a trace of Lisp function calls currently active.
3162 Output stream used is value of `standard-output'. */)
3163 ()
3164 {
3165 register struct backtrace *backlist = backtrace_list;
3166 register int i;
3167 Lisp_Object tail;
3168 Lisp_Object tem;
3169 extern Lisp_Object Vprint_level;
3170 struct gcpro gcpro1;
3171
3172 XSETFASTINT (Vprint_level, 3);
3173
3174 tail = Qnil;
3175 GCPRO1 (tail);
3176
3177 while (backlist)
3178 {
3179 write_string (backlist->debug_on_exit ? "* " : " ", 2);
3180 if (backlist->nargs == UNEVALLED)
3181 {
3182 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
3183 write_string ("\n", -1);
3184 }
3185 else
3186 {
3187 tem = *backlist->function;
3188 Fprin1 (tem, Qnil); /* This can QUIT */
3189 write_string ("(", -1);
3190 if (backlist->nargs == MANY)
3191 {
3192 for (tail = *backlist->args, i = 0;
3193 !NILP (tail);
3194 tail = Fcdr (tail), i++)
3195 {
3196 if (i) write_string (" ", -1);
3197 Fprin1 (Fcar (tail), Qnil);
3198 }
3199 }
3200 else
3201 {
3202 for (i = 0; i < backlist->nargs; i++)
3203 {
3204 if (i) write_string (" ", -1);
3205 Fprin1 (backlist->args[i], Qnil);
3206 }
3207 }
3208 write_string (")\n", -1);
3209 }
3210 backlist = backlist->next;
3211 }
3212
3213 Vprint_level = Qnil;
3214 UNGCPRO;
3215 return Qnil;
3216 }
3217
3218 DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
3219 doc: /* Return the function and arguments NFRAMES up from current execution point.
3220 If that frame has not evaluated the arguments yet (or is a special form),
3221 the value is (nil FUNCTION ARG-FORMS...).
3222 If that frame has evaluated its arguments and called its function already,
3223 the value is (t FUNCTION ARG-VALUES...).
3224 A &rest arg is represented as the tail of the list ARG-VALUES.
3225 FUNCTION is whatever was supplied as car of evaluated list,
3226 or a lambda expression for macro calls.
3227 If NFRAMES is more than the number of frames, the value is nil. */)
3228 (nframes)
3229 Lisp_Object nframes;
3230 {
3231 register struct backtrace *backlist = backtrace_list;
3232 register int i;
3233 Lisp_Object tem;
3234
3235 CHECK_NATNUM (nframes);
3236
3237 /* Find the frame requested. */
3238 for (i = 0; backlist && i < XFASTINT (nframes); i++)
3239 backlist = backlist->next;
3240
3241 if (!backlist)
3242 return Qnil;
3243 if (backlist->nargs == UNEVALLED)
3244 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
3245 else
3246 {
3247 if (backlist->nargs == MANY)
3248 tem = *backlist->args;
3249 else
3250 tem = Flist (backlist->nargs, backlist->args);
3251
3252 return Fcons (Qt, Fcons (*backlist->function, tem));
3253 }
3254 }
3255
3256 \f
3257 void
3258 syms_of_eval ()
3259 {
3260 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
3261 doc: /* *Limit on number of Lisp variable bindings & unwind-protects.
3262 If Lisp code tries to make more than this many at once,
3263 an error is signaled.
3264 You can safely use a value considerably larger than the default value,
3265 if that proves inconveniently small. However, if you increase it too far,
3266 Emacs could run out of memory trying to make the stack bigger. */);
3267
3268 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
3269 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3270
3271 This limit serves to catch infinite recursions for you before they cause
3272 actual stack overflow in C, which would be fatal for Emacs.
3273 You can safely make it considerably larger than its default value,
3274 if that proves inconveniently small. However, if you increase it too far,
3275 Emacs could overflow the real C stack, and crash. */);
3276
3277 DEFVAR_LISP ("quit-flag", &Vquit_flag,
3278 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3279 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'. */);
3280 Vquit_flag = Qnil;
3281
3282 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
3283 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3284 Note that `quit-flag' will still be set by typing C-g,
3285 so a quit will be signaled as soon as `inhibit-quit' is nil.
3286 To prevent this happening, set `quit-flag' to nil
3287 before making `inhibit-quit' nil. */);
3288 Vinhibit_quit = Qnil;
3289
3290 Qinhibit_quit = intern ("inhibit-quit");
3291 staticpro (&Qinhibit_quit);
3292
3293 Qautoload = intern ("autoload");
3294 staticpro (&Qautoload);
3295
3296 Qdebug_on_error = intern ("debug-on-error");
3297 staticpro (&Qdebug_on_error);
3298
3299 Qmacro = intern ("macro");
3300 staticpro (&Qmacro);
3301
3302 Qdeclare = intern ("declare");
3303 staticpro (&Qdeclare);
3304
3305 /* Note that the process handling also uses Qexit, but we don't want
3306 to staticpro it twice, so we just do it here. */
3307 Qexit = intern ("exit");
3308 staticpro (&Qexit);
3309
3310 Qinteractive = intern ("interactive");
3311 staticpro (&Qinteractive);
3312
3313 Qcommandp = intern ("commandp");
3314 staticpro (&Qcommandp);
3315
3316 Qdefun = intern ("defun");
3317 staticpro (&Qdefun);
3318
3319 Qdefvar = intern ("defvar");
3320 staticpro (&Qdefvar);
3321
3322 Qand_rest = intern ("&rest");
3323 staticpro (&Qand_rest);
3324
3325 Qand_optional = intern ("&optional");
3326 staticpro (&Qand_optional);
3327
3328 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
3329 doc: /* *Non-nil means errors display a backtrace buffer.
3330 More precisely, this happens for any error that is handled
3331 by the editor command loop.
3332 If the value is a list, an error only means to display a backtrace
3333 if one of its condition symbols appears in the list. */);
3334 Vstack_trace_on_error = Qnil;
3335
3336 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
3337 doc: /* *Non-nil means enter debugger if an error is signaled.
3338 Does not apply to errors handled by `condition-case' or those
3339 matched by `debug-ignored-errors'.
3340 If the value is a list, an error only means to enter the debugger
3341 if one of its condition symbols appears in the list.
3342 When you evaluate an expression interactively, this variable
3343 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3344 See also variable `debug-on-quit'. */);
3345 Vdebug_on_error = Qnil;
3346
3347 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors,
3348 doc: /* *List of errors for which the debugger should not be called.
3349 Each element may be a condition-name or a regexp that matches error messages.
3350 If any element applies to a given error, that error skips the debugger
3351 and just returns to top level.
3352 This overrides the variable `debug-on-error'.
3353 It does not apply to errors handled by `condition-case'. */);
3354 Vdebug_ignored_errors = Qnil;
3355
3356 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
3357 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3358 Does not apply if quit is handled by a `condition-case'.
3359 When you evaluate an expression interactively, this variable
3360 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
3361 debug_on_quit = 0;
3362
3363 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
3364 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3365
3366 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue,
3367 doc: /* Non-nil means debugger may continue execution.
3368 This is nil when the debugger is called under circumstances where it
3369 might not be safe to continue. */);
3370 debugger_may_continue = 1;
3371
3372 DEFVAR_LISP ("debugger", &Vdebugger,
3373 doc: /* Function to call to invoke debugger.
3374 If due to frame exit, args are `exit' and the value being returned;
3375 this function's value will be returned instead of that.
3376 If due to error, args are `error' and a list of the args to `signal'.
3377 If due to `apply' or `funcall' entry, one arg, `lambda'.
3378 If due to `eval' entry, one arg, t. */);
3379 Vdebugger = Qnil;
3380
3381 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function,
3382 doc: /* If non-nil, this is a function for `signal' to call.
3383 It receives the same arguments that `signal' was given.
3384 The Edebug package uses this to regain control. */);
3385 Vsignal_hook_function = Qnil;
3386
3387 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal,
3388 doc: /* *Non-nil means call the debugger regardless of condition handlers.
3389 Note that `debug-on-error', `debug-on-quit' and friends
3390 still determine whether to handle the particular condition. */);
3391 Vdebug_on_signal = Qnil;
3392
3393 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function,
3394 doc: /* Function to process declarations in a macro definition.
3395 The function will be called with two args MACRO and DECL.
3396 MACRO is the name of the macro being defined.
3397 DECL is a list `(declare ...)' containing the declarations.
3398 The value the function returns is not used. */);
3399 Vmacro_declaration_function = Qnil;
3400
3401 Vrun_hooks = intern ("run-hooks");
3402 staticpro (&Vrun_hooks);
3403
3404 staticpro (&Vautoload_queue);
3405 Vautoload_queue = Qnil;
3406 staticpro (&Vsignaling_function);
3407 Vsignaling_function = Qnil;
3408
3409 defsubr (&Sor);
3410 defsubr (&Sand);
3411 defsubr (&Sif);
3412 defsubr (&Scond);
3413 defsubr (&Sprogn);
3414 defsubr (&Sprog1);
3415 defsubr (&Sprog2);
3416 defsubr (&Ssetq);
3417 defsubr (&Squote);
3418 defsubr (&Sfunction);
3419 defsubr (&Sdefun);
3420 defsubr (&Sdefmacro);
3421 defsubr (&Sdefvar);
3422 defsubr (&Sdefvaralias);
3423 defsubr (&Sdefconst);
3424 defsubr (&Suser_variable_p);
3425 defsubr (&Slet);
3426 defsubr (&SletX);
3427 defsubr (&Swhile);
3428 defsubr (&Smacroexpand);
3429 defsubr (&Scatch);
3430 defsubr (&Sthrow);
3431 defsubr (&Sunwind_protect);
3432 defsubr (&Scondition_case);
3433 defsubr (&Ssignal);
3434 defsubr (&Sinteractive_p);
3435 defsubr (&Scommandp);
3436 defsubr (&Sautoload);
3437 defsubr (&Seval);
3438 defsubr (&Sapply);
3439 defsubr (&Sfuncall);
3440 defsubr (&Srun_hooks);
3441 defsubr (&Srun_hook_with_args);
3442 defsubr (&Srun_hook_with_args_until_success);
3443 defsubr (&Srun_hook_with_args_until_failure);
3444 defsubr (&Sfetch_bytecode);
3445 defsubr (&Sbacktrace_debug);
3446 defsubr (&Sbacktrace);
3447 defsubr (&Sbacktrace_frame);
3448 }