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