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