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