(vip-event-key): ignore consp events.
[emacs.git] / src / eval.c
blobcecf18cbfeb94625e433ac97a046b74378ca4b9e
1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <config.h>
23 #include "lisp.h"
24 #include "blockinput.h"
26 #ifndef standalone
27 #include "commands.h"
28 #include "keyboard.h"
29 #else
30 #define INTERACTIVE 1
31 #endif
33 #include <setjmp.h>
35 /* This definition is duplicated in alloc.c and keyboard.c */
36 /* Putting it in lisp.h makes cc bomb out! */
38 struct backtrace
40 struct backtrace *next;
41 Lisp_Object *function;
42 Lisp_Object *args; /* Points to vector of args. */
43 int nargs; /* Length of vector.
44 If nargs is UNEVALLED, args points to slot holding
45 list of unevalled args */
46 char evalargs;
47 /* Nonzero means call value of debugger when done with this operation. */
48 char debug_on_exit;
51 struct backtrace *backtrace_list;
53 /* This structure helps implement the `catch' and `throw' control
54 structure. A struct catchtag contains all the information needed
55 to restore the state of the interpreter after a non-local jump.
57 Handlers for error conditions (represented by `struct handler'
58 structures) just point to a catch tag to do the cleanup required
59 for their jumps.
61 catchtag structures are chained together in the C calling stack;
62 the `next' member points to the next outer catchtag.
64 A call like (throw TAG VAL) searches for a catchtag whose `tag'
65 member is TAG, and then unbinds to it. The `val' member is used to
66 hold VAL while the stack is unwound; `val' is returned as the value
67 of the catch form.
69 All the other members are concerned with restoring the interpreter
70 state. */
71 struct catchtag
73 Lisp_Object tag;
74 Lisp_Object val;
75 struct catchtag *next;
76 struct gcpro *gcpro;
77 jmp_buf jmp;
78 struct backtrace *backlist;
79 struct handler *handlerlist;
80 int lisp_eval_depth;
81 int pdlcount;
82 int poll_suppress_count;
85 struct catchtag *catchlist;
87 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
88 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag;
89 Lisp_Object Qmocklisp_arguments, Vmocklisp_arguments, Qmocklisp;
90 Lisp_Object Qand_rest, Qand_optional;
91 Lisp_Object Qdebug_on_error;
93 Lisp_Object Vrun_hooks;
95 /* Non-nil means record all fset's and provide's, to be undone
96 if the file being autoloaded is not fully loaded.
97 They are recorded by being consed onto the front of Vautoload_queue:
98 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
100 Lisp_Object Vautoload_queue;
102 /* Current number of specbindings allocated in specpdl. */
103 int specpdl_size;
105 /* Pointer to beginning of specpdl. */
106 struct specbinding *specpdl;
108 /* Pointer to first unused element in specpdl. */
109 struct specbinding *specpdl_ptr;
111 /* Maximum size allowed for specpdl allocation */
112 int max_specpdl_size;
114 /* Depth in Lisp evaluations and function calls. */
115 int lisp_eval_depth;
117 /* Maximum allowed depth in Lisp evaluations and function calls. */
118 int max_lisp_eval_depth;
120 /* Nonzero means enter debugger before next function call */
121 int debug_on_next_call;
123 /* List of conditions (non-nil atom means all) which cause a backtrace
124 if an error is handled by the command loop's error handler. */
125 Lisp_Object Vstack_trace_on_error;
127 /* List of conditions (non-nil atom means all) which enter the debugger
128 if an error is handled by the command loop's error handler. */
129 Lisp_Object Vdebug_on_error;
131 /* List of conditions and regexps specifying error messages which
132 do not enter the debugger even if Vdebug_on_errors says they should. */
133 Lisp_Object Vdebug_ignored_errors;
135 /* Nonzero means enter debugger if a quit signal
136 is handled by the command loop's error handler. */
137 int debug_on_quit;
139 /* The value of num_nonmacro_input_chars as of the last time we
140 started to enter the debugger. If we decide to enter the debugger
141 again when this is still equal to num_nonmacro_input_chars, then we
142 know that the debugger itself has an error, and we should just
143 signal the error instead of entering an infinite loop of debugger
144 invocations. */
145 int when_entered_debugger;
147 Lisp_Object Vdebugger;
149 void specbind (), record_unwind_protect ();
151 Lisp_Object run_hook_with_args ();
153 Lisp_Object funcall_lambda ();
154 extern Lisp_Object ml_apply (); /* Apply a mocklisp function to unevaluated argument list */
156 init_eval_once ()
158 specpdl_size = 50;
159 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
160 max_specpdl_size = 600;
161 max_lisp_eval_depth = 200;
163 Vrun_hooks = Qnil;
166 init_eval ()
168 specpdl_ptr = specpdl;
169 catchlist = 0;
170 handlerlist = 0;
171 backtrace_list = 0;
172 Vquit_flag = Qnil;
173 debug_on_next_call = 0;
174 lisp_eval_depth = 0;
175 /* This is less than the initial value of num_nonmacro_input_chars. */
176 when_entered_debugger = -1;
179 Lisp_Object
180 call_debugger (arg)
181 Lisp_Object arg;
183 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
184 max_lisp_eval_depth = lisp_eval_depth + 20;
185 if (specpdl_size + 40 > max_specpdl_size)
186 max_specpdl_size = specpdl_size + 40;
187 debug_on_next_call = 0;
188 when_entered_debugger = num_nonmacro_input_chars;
189 return apply1 (Vdebugger, arg);
192 do_debug_on_call (code)
193 Lisp_Object code;
195 debug_on_next_call = 0;
196 backtrace_list->debug_on_exit = 1;
197 call_debugger (Fcons (code, Qnil));
200 /* NOTE!!! Every function that can call EVAL must protect its args
201 and temporaries from garbage collection while it needs them.
202 The definition of `For' shows what you have to do. */
204 DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
205 "Eval args until one of them yields non-nil, then return that value.\n\
206 The remaining args are not evalled at all.\n\
207 If all args return nil, return nil.")
208 (args)
209 Lisp_Object args;
211 register Lisp_Object val;
212 Lisp_Object args_left;
213 struct gcpro gcpro1;
215 if (NILP(args))
216 return Qnil;
218 args_left = args;
219 GCPRO1 (args_left);
223 val = Feval (Fcar (args_left));
224 if (!NILP (val))
225 break;
226 args_left = Fcdr (args_left);
228 while (!NILP(args_left));
230 UNGCPRO;
231 return val;
234 DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
235 "Eval args until one of them yields nil, then return nil.\n\
236 The remaining args are not evalled at all.\n\
237 If no arg yields nil, return the last arg's value.")
238 (args)
239 Lisp_Object args;
241 register Lisp_Object val;
242 Lisp_Object args_left;
243 struct gcpro gcpro1;
245 if (NILP(args))
246 return Qt;
248 args_left = args;
249 GCPRO1 (args_left);
253 val = Feval (Fcar (args_left));
254 if (NILP (val))
255 break;
256 args_left = Fcdr (args_left);
258 while (!NILP(args_left));
260 UNGCPRO;
261 return val;
264 DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
265 "(if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE...\n\
266 Returns the value of THEN or the value of the last of the ELSE's.\n\
267 THEN must be one expression, but ELSE... can be zero or more expressions.\n\
268 If COND yields nil, and there are no ELSE's, the value is nil.")
269 (args)
270 Lisp_Object args;
272 register Lisp_Object cond;
273 struct gcpro gcpro1;
275 GCPRO1 (args);
276 cond = Feval (Fcar (args));
277 UNGCPRO;
279 if (!NILP (cond))
280 return Feval (Fcar (Fcdr (args)));
281 return Fprogn (Fcdr (Fcdr (args)));
284 DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
285 "(cond CLAUSES...): try each clause until one succeeds.\n\
286 Each clause looks like (CONDITION BODY...). CONDITION is evaluated\n\
287 and, if the value is non-nil, this clause succeeds:\n\
288 then the expressions in BODY are evaluated and the last one's\n\
289 value is the value of the cond-form.\n\
290 If no clause succeeds, cond returns nil.\n\
291 If a clause has one element, as in (CONDITION),\n\
292 CONDITION's value if non-nil is returned from the cond-form.")
293 (args)
294 Lisp_Object args;
296 register Lisp_Object clause, val;
297 struct gcpro gcpro1;
299 val = Qnil;
300 GCPRO1 (args);
301 while (!NILP (args))
303 clause = Fcar (args);
304 val = Feval (Fcar (clause));
305 if (!NILP (val))
307 if (!EQ (XCONS (clause)->cdr, Qnil))
308 val = Fprogn (XCONS (clause)->cdr);
309 break;
311 args = XCONS (args)->cdr;
313 UNGCPRO;
315 return val;
318 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
319 "(progn BODY...): eval BODY forms sequentially and return value of last one.")
320 (args)
321 Lisp_Object args;
323 register Lisp_Object val, tem;
324 Lisp_Object args_left;
325 struct gcpro gcpro1;
327 /* In Mocklisp code, symbols at the front of the progn arglist
328 are to be bound to zero. */
329 if (!EQ (Vmocklisp_arguments, Qt))
331 val = make_number (0);
332 while (!NILP (args) && (tem = Fcar (args), SYMBOLP (tem)))
334 QUIT;
335 specbind (tem, val), args = Fcdr (args);
339 if (NILP(args))
340 return Qnil;
342 args_left = args;
343 GCPRO1 (args_left);
347 val = Feval (Fcar (args_left));
348 args_left = Fcdr (args_left);
350 while (!NILP(args_left));
352 UNGCPRO;
353 return val;
356 DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
357 "(prog1 FIRST BODY...): eval FIRST and BODY sequentially; value from FIRST.\n\
358 The value of FIRST is saved during the evaluation of the remaining args,\n\
359 whose values are discarded.")
360 (args)
361 Lisp_Object args;
363 Lisp_Object val;
364 register Lisp_Object args_left;
365 struct gcpro gcpro1, gcpro2;
366 register int argnum = 0;
368 if (NILP(args))
369 return Qnil;
371 args_left = args;
372 val = Qnil;
373 GCPRO2 (args, val);
377 if (!(argnum++))
378 val = Feval (Fcar (args_left));
379 else
380 Feval (Fcar (args_left));
381 args_left = Fcdr (args_left);
383 while (!NILP(args_left));
385 UNGCPRO;
386 return val;
389 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
390 "(prog2 X Y BODY...): eval X, Y and BODY sequentially; value from Y.\n\
391 The value of Y is saved during the evaluation of the remaining args,\n\
392 whose values are discarded.")
393 (args)
394 Lisp_Object args;
396 Lisp_Object val;
397 register Lisp_Object args_left;
398 struct gcpro gcpro1, gcpro2;
399 register int argnum = -1;
401 val = Qnil;
403 if (NILP (args))
404 return Qnil;
406 args_left = args;
407 val = Qnil;
408 GCPRO2 (args, val);
412 if (!(argnum++))
413 val = Feval (Fcar (args_left));
414 else
415 Feval (Fcar (args_left));
416 args_left = Fcdr (args_left);
418 while (!NILP (args_left));
420 UNGCPRO;
421 return val;
424 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
425 "(setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL.\n\
426 The symbols SYM are variables; they are literal (not evaluated).\n\
427 The values VAL are expressions; they are evaluated.\n\
428 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.\n\
429 The second VAL is not computed until after the first SYM is set, and so on;\n\
430 each VAL can use the new value of variables set earlier in the `setq'.\n\
431 The return value of the `setq' form is the value of the last VAL.")
432 (args)
433 Lisp_Object args;
435 register Lisp_Object args_left;
436 register Lisp_Object val, sym;
437 struct gcpro gcpro1;
439 if (NILP(args))
440 return Qnil;
442 args_left = args;
443 GCPRO1 (args);
447 val = Feval (Fcar (Fcdr (args_left)));
448 sym = Fcar (args_left);
449 Fset (sym, val);
450 args_left = Fcdr (Fcdr (args_left));
452 while (!NILP(args_left));
454 UNGCPRO;
455 return val;
458 DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
459 "Return the argument, without evaluating it. `(quote x)' yields `x'.")
460 (args)
461 Lisp_Object args;
463 return Fcar (args);
466 DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
467 "Like `quote', but preferred for objects which are functions.\n\
468 In byte compilation, `function' causes its argument to be compiled.\n\
469 `quote' cannot do that.")
470 (args)
471 Lisp_Object args;
473 return Fcar (args);
476 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
477 "Return t if function in which this appears was called interactively.\n\
478 This means that the function was called with call-interactively (which\n\
479 includes being called as the binding of a key)\n\
480 and input is currently coming from the keyboard (not in keyboard macro).")
483 register struct backtrace *btp;
484 register Lisp_Object fun;
486 if (!INTERACTIVE)
487 return Qnil;
489 btp = backtrace_list;
491 /* If this isn't a byte-compiled function, there may be a frame at
492 the top for Finteractive_p itself. If so, skip it. */
493 fun = Findirect_function (*btp->function);
494 if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p)
495 btp = btp->next;
497 /* If we're running an Emacs 18-style byte-compiled function, there
498 may be a frame for Fbytecode. Now, given the strictest
499 definition, this function isn't really being called
500 interactively, but because that's the way Emacs 18 always builds
501 byte-compiled functions, we'll accept it for now. */
502 if (EQ (*btp->function, Qbytecode))
503 btp = btp->next;
505 /* If this isn't a byte-compiled function, then we may now be
506 looking at several frames for special forms. Skip past them. */
507 while (btp &&
508 btp->nargs == UNEVALLED)
509 btp = btp->next;
511 /* btp now points at the frame of the innermost function that isn't
512 a special form, ignoring frames for Finteractive_p and/or
513 Fbytecode at the top. If this frame is for a built-in function
514 (such as load or eval-region) return nil. */
515 fun = Findirect_function (*btp->function);
516 if (SUBRP (fun))
517 return Qnil;
518 /* btp points to the frame of a Lisp function that called interactive-p.
519 Return t if that function was called interactively. */
520 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
521 return Qt;
522 return Qnil;
525 DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
526 "(defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.\n\
527 The definition is (lambda ARGLIST [DOCSTRING] BODY...).\n\
528 See also the function `interactive'.")
529 (args)
530 Lisp_Object args;
532 register Lisp_Object fn_name;
533 register Lisp_Object defn;
535 fn_name = Fcar (args);
536 defn = Fcons (Qlambda, Fcdr (args));
537 if (!NILP (Vpurify_flag))
538 defn = Fpurecopy (defn);
539 Ffset (fn_name, defn);
540 LOADHIST_ATTACH (fn_name);
541 return fn_name;
544 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
545 "(defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.\n\
546 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).\n\
547 When the macro is called, as in (NAME ARGS...),\n\
548 the function (lambda ARGLIST BODY...) is applied to\n\
549 the list ARGS... as it appears in the expression,\n\
550 and the result should be a form to be evaluated instead of the original.")
551 (args)
552 Lisp_Object args;
554 register Lisp_Object fn_name;
555 register Lisp_Object defn;
557 fn_name = Fcar (args);
558 defn = Fcons (Qmacro, Fcons (Qlambda, Fcdr (args)));
559 if (!NILP (Vpurify_flag))
560 defn = Fpurecopy (defn);
561 Ffset (fn_name, defn);
562 LOADHIST_ATTACH (fn_name);
563 return fn_name;
566 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
567 "(defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable.\n\
568 You are not required to define a variable in order to use it,\n\
569 but the definition can supply documentation and an initial value\n\
570 in a way that tags can recognize.\n\n\
571 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.\n\
572 If SYMBOL is buffer-local, its default value is what is set;\n\
573 buffer-local values are not affected.\n\
574 INITVALUE and DOCSTRING are optional.\n\
575 If DOCSTRING starts with *, this variable is identified as a user option.\n\
576 This means that M-x set-variable and M-x edit-options recognize it.\n\
577 If INITVALUE is missing, SYMBOL's value is not set.")
578 (args)
579 Lisp_Object args;
581 register Lisp_Object sym, tem, tail;
583 sym = Fcar (args);
584 tail = Fcdr (args);
585 if (!NILP (Fcdr (Fcdr (tail))))
586 error ("too many arguments");
588 if (!NILP (tail))
590 tem = Fdefault_boundp (sym);
591 if (NILP (tem))
592 Fset_default (sym, Feval (Fcar (Fcdr (args))));
594 tail = Fcdr (Fcdr (args));
595 if (!NILP (Fcar (tail)))
597 tem = Fcar (tail);
598 if (!NILP (Vpurify_flag))
599 tem = Fpurecopy (tem);
600 Fput (sym, Qvariable_documentation, tem);
602 LOADHIST_ATTACH (sym);
603 return sym;
606 DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
607 "(defconst SYMBOL INITVALUE DOCSTRING): define SYMBOL as a constant variable.\n\
608 The intent is that programs do not change this value, but users may.\n\
609 Always sets the value of SYMBOL to the result of evalling INITVALUE.\n\
610 If SYMBOL is buffer-local, its default value is what is set;\n\
611 buffer-local values are not affected.\n\
612 DOCSTRING is optional.\n\
613 If DOCSTRING starts with *, this variable is identified as a user option.\n\
614 This means that M-x set-variable and M-x edit-options recognize it.\n\n\
615 Note: do not use `defconst' for user options in libraries that are not\n\
616 normally loaded, since it is useful for users to be able to specify\n\
617 their own values for such variables before loading the library.\n\
618 Since `defconst' unconditionally assigns the variable,\n\
619 it would override the user's choice.")
620 (args)
621 Lisp_Object args;
623 register Lisp_Object sym, tem;
625 sym = Fcar (args);
626 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
627 error ("too many arguments");
629 Fset_default (sym, Feval (Fcar (Fcdr (args))));
630 tem = Fcar (Fcdr (Fcdr (args)));
631 if (!NILP (tem))
633 if (!NILP (Vpurify_flag))
634 tem = Fpurecopy (tem);
635 Fput (sym, Qvariable_documentation, tem);
637 LOADHIST_ATTACH (sym);
638 return sym;
641 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
642 "Returns t if VARIABLE is intended to be set and modified by users.\n\
643 \(The alternative is a variable used internally in a Lisp program.)\n\
644 Determined by whether the first character of the documentation\n\
645 for the variable is `*'.")
646 (variable)
647 Lisp_Object variable;
649 Lisp_Object documentation;
651 documentation = Fget (variable, Qvariable_documentation);
652 if (INTEGERP (documentation) && XINT (documentation) < 0)
653 return Qt;
654 if (STRINGP (documentation)
655 && ((unsigned char) XSTRING (documentation)->data[0] == '*'))
656 return Qt;
657 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
658 if (CONSP (documentation)
659 && STRINGP (XCONS (documentation)->car)
660 && INTEGERP (XCONS (documentation)->cdr)
661 && XINT (XCONS (documentation)->cdr) < 0)
662 return Qt;
663 return Qnil;
666 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
667 "(let* VARLIST BODY...): bind variables according to VARLIST then eval BODY.\n\
668 The value of the last form in BODY is returned.\n\
669 Each element of VARLIST is a symbol (which is bound to nil)\n\
670 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\
671 Each VALUEFORM can refer to the symbols already bound by this VARLIST.")
672 (args)
673 Lisp_Object args;
675 Lisp_Object varlist, val, elt;
676 int count = specpdl_ptr - specpdl;
677 struct gcpro gcpro1, gcpro2, gcpro3;
679 GCPRO3 (args, elt, varlist);
681 varlist = Fcar (args);
682 while (!NILP (varlist))
684 QUIT;
685 elt = Fcar (varlist);
686 if (SYMBOLP (elt))
687 specbind (elt, Qnil);
688 else if (! NILP (Fcdr (Fcdr (elt))))
689 Fsignal (Qerror,
690 Fcons (build_string ("`let' bindings can have only one value-form"),
691 elt));
692 else
694 val = Feval (Fcar (Fcdr (elt)));
695 specbind (Fcar (elt), val);
697 varlist = Fcdr (varlist);
699 UNGCPRO;
700 val = Fprogn (Fcdr (args));
701 return unbind_to (count, val);
704 DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
705 "(let VARLIST BODY...): bind variables according to VARLIST then eval BODY.\n\
706 The value of the last form in BODY is returned.\n\
707 Each element of VARLIST is a symbol (which is bound to nil)\n\
708 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\
709 All the VALUEFORMs are evalled before any symbols are bound.")
710 (args)
711 Lisp_Object args;
713 Lisp_Object *temps, tem;
714 register Lisp_Object elt, varlist;
715 int count = specpdl_ptr - specpdl;
716 register int argnum;
717 struct gcpro gcpro1, gcpro2;
719 varlist = Fcar (args);
721 /* Make space to hold the values to give the bound variables */
722 elt = Flength (varlist);
723 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object));
725 /* Compute the values and store them in `temps' */
727 GCPRO2 (args, *temps);
728 gcpro2.nvars = 0;
730 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
732 QUIT;
733 elt = Fcar (varlist);
734 if (SYMBOLP (elt))
735 temps [argnum++] = Qnil;
736 else if (! NILP (Fcdr (Fcdr (elt))))
737 Fsignal (Qerror,
738 Fcons (build_string ("`let' bindings can have only one value-form"),
739 elt));
740 else
741 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
742 gcpro2.nvars = argnum;
744 UNGCPRO;
746 varlist = Fcar (args);
747 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
749 elt = Fcar (varlist);
750 tem = temps[argnum++];
751 if (SYMBOLP (elt))
752 specbind (elt, tem);
753 else
754 specbind (Fcar (elt), tem);
757 elt = Fprogn (Fcdr (args));
758 return unbind_to (count, elt);
761 DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
762 "(while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat.\n\
763 The order of execution is thus TEST, BODY, TEST, BODY and so on\n\
764 until TEST returns nil.")
765 (args)
766 Lisp_Object args;
768 Lisp_Object test, body, tem;
769 struct gcpro gcpro1, gcpro2;
771 GCPRO2 (test, body);
773 test = Fcar (args);
774 body = Fcdr (args);
775 while (tem = Feval (test),
776 (!EQ (Vmocklisp_arguments, Qt) ? XINT (tem) : !NILP (tem)))
778 QUIT;
779 Fprogn (body);
782 UNGCPRO;
783 return Qnil;
786 DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
787 "Return result of expanding macros at top level of FORM.\n\
788 If FORM is not a macro call, it is returned unchanged.\n\
789 Otherwise, the macro is expanded and the expansion is considered\n\
790 in place of FORM. When a non-macro-call results, it is returned.\n\n\
791 The second optional arg ENVIRONMENT species an environment of macro\n\
792 definitions to shadow the loaded ones for use in file byte-compilation.")
793 (form, environment)
794 register Lisp_Object form;
795 Lisp_Object environment;
797 /* With cleanups from Hallvard Furuseth. */
798 register Lisp_Object expander, sym, def, tem;
800 while (1)
802 /* Come back here each time we expand a macro call,
803 in case it expands into another macro call. */
804 if (!CONSP (form))
805 break;
806 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
807 def = sym = XCONS (form)->car;
808 tem = Qnil;
809 /* Trace symbols aliases to other symbols
810 until we get a symbol that is not an alias. */
811 while (SYMBOLP (def))
813 QUIT;
814 sym = def;
815 tem = Fassq (sym, environment);
816 if (NILP (tem))
818 def = XSYMBOL (sym)->function;
819 if (!EQ (def, Qunbound))
820 continue;
822 break;
824 /* Right now TEM is the result from SYM in ENVIRONMENT,
825 and if TEM is nil then DEF is SYM's function definition. */
826 if (NILP (tem))
828 /* SYM is not mentioned in ENVIRONMENT.
829 Look at its function definition. */
830 if (EQ (def, Qunbound) || !CONSP (def))
831 /* Not defined or definition not suitable */
832 break;
833 if (EQ (XCONS (def)->car, Qautoload))
835 /* Autoloading function: will it be a macro when loaded? */
836 tem = Fnth (make_number (4), def);
837 if (EQ (tem, Qt) || EQ (tem, Qmacro))
838 /* Yes, load it and try again. */
840 do_autoload (def, sym);
841 continue;
843 else
844 break;
846 else if (!EQ (XCONS (def)->car, Qmacro))
847 break;
848 else expander = XCONS (def)->cdr;
850 else
852 expander = XCONS (tem)->cdr;
853 if (NILP (expander))
854 break;
856 form = apply1 (expander, XCONS (form)->cdr);
858 return form;
861 DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
862 "(catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'.\n\
863 TAG is evalled to get the tag to use. Then the BODY is executed.\n\
864 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.\n\
865 If no throw happens, `catch' returns the value of the last BODY form.\n\
866 If a throw happens, it specifies the value to return from `catch'.")
867 (args)
868 Lisp_Object args;
870 register Lisp_Object tag;
871 struct gcpro gcpro1;
873 GCPRO1 (args);
874 tag = Feval (Fcar (args));
875 UNGCPRO;
876 return internal_catch (tag, Fprogn, Fcdr (args));
879 /* Set up a catch, then call C function FUNC on argument ARG.
880 FUNC should return a Lisp_Object.
881 This is how catches are done from within C code. */
883 Lisp_Object
884 internal_catch (tag, func, arg)
885 Lisp_Object tag;
886 Lisp_Object (*func) ();
887 Lisp_Object arg;
889 /* This structure is made part of the chain `catchlist'. */
890 struct catchtag c;
892 /* Fill in the components of c, and put it on the list. */
893 c.next = catchlist;
894 c.tag = tag;
895 c.val = Qnil;
896 c.backlist = backtrace_list;
897 c.handlerlist = handlerlist;
898 c.lisp_eval_depth = lisp_eval_depth;
899 c.pdlcount = specpdl_ptr - specpdl;
900 c.poll_suppress_count = poll_suppress_count;
901 c.gcpro = gcprolist;
902 catchlist = &c;
904 /* Call FUNC. */
905 if (! _setjmp (c.jmp))
906 c.val = (*func) (arg);
908 /* Throw works by a longjmp that comes right here. */
909 catchlist = c.next;
910 return c.val;
913 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
914 jump to that CATCH, returning VALUE as the value of that catch.
916 This is the guts Fthrow and Fsignal; they differ only in the way
917 they choose the catch tag to throw to. A catch tag for a
918 condition-case form has a TAG of Qnil.
920 Before each catch is discarded, unbind all special bindings and
921 execute all unwind-protect clauses made above that catch. Unwind
922 the handler stack as we go, so that the proper handlers are in
923 effect for each unwind-protect clause we run. At the end, restore
924 some static info saved in CATCH, and longjmp to the location
925 specified in the
927 This is used for correct unwinding in Fthrow and Fsignal. */
929 static void
930 unwind_to_catch (catch, value)
931 struct catchtag *catch;
932 Lisp_Object value;
934 register int last_time;
936 /* Save the value in the tag. */
937 catch->val = value;
939 /* Restore the polling-suppression count. */
940 set_poll_suppress_count (catch->poll_suppress_count);
944 last_time = catchlist == catch;
946 /* Unwind the specpdl stack, and then restore the proper set of
947 handlers. */
948 unbind_to (catchlist->pdlcount, Qnil);
949 handlerlist = catchlist->handlerlist;
950 catchlist = catchlist->next;
952 while (! last_time);
954 gcprolist = catch->gcpro;
955 backtrace_list = catch->backlist;
956 lisp_eval_depth = catch->lisp_eval_depth;
958 _longjmp (catch->jmp, 1);
961 DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
962 "(throw TAG VALUE): throw to the catch for TAG and return VALUE from it.\n\
963 Both TAG and VALUE are evalled.")
964 (tag, value)
965 register Lisp_Object tag, value;
967 register struct catchtag *c;
969 while (1)
971 if (!NILP (tag))
972 for (c = catchlist; c; c = c->next)
974 if (EQ (c->tag, tag))
975 unwind_to_catch (c, value);
977 tag = Fsignal (Qno_catch, Fcons (tag, Fcons (value, Qnil)));
982 DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
983 "Do BODYFORM, protecting with UNWINDFORMS.\n\
984 Usage looks like (unwind-protect BODYFORM UNWINDFORMS...).\n\
985 If BODYFORM completes normally, its value is returned\n\
986 after executing the UNWINDFORMS.\n\
987 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.")
988 (args)
989 Lisp_Object args;
991 Lisp_Object val;
992 int count = specpdl_ptr - specpdl;
994 record_unwind_protect (0, Fcdr (args));
995 val = Feval (Fcar (args));
996 return unbind_to (count, val);
999 /* Chain of condition handlers currently in effect.
1000 The elements of this chain are contained in the stack frames
1001 of Fcondition_case and internal_condition_case.
1002 When an error is signaled (by calling Fsignal, below),
1003 this chain is searched for an element that applies. */
1005 struct handler *handlerlist;
1007 DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
1008 "Regain control when an error is signaled.\n\
1009 Usage looks like (condition-case VAR BODYFORM HANDLERS...).\n\
1010 executes BODYFORM and returns its value if no error happens.\n\
1011 Each element of HANDLERS looks like (CONDITION-NAME BODY...)\n\
1012 where the BODY is made of Lisp expressions.\n\n\
1013 A handler is applicable to an error\n\
1014 if CONDITION-NAME is one of the error's condition names.\n\
1015 If an error happens, the first applicable handler is run.\n\
1017 The car of a handler may be a list of condition names\n\
1018 instead of a single condition name.\n\
1020 When a handler handles an error,\n\
1021 control returns to the condition-case and the handler BODY... is executed\n\
1022 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).\n\
1023 VAR may be nil; then you do not get access to the signal information.\n\
1025 The value of the last BODY form is returned from the condition-case.\n\
1026 See also the function `signal' for more info.")
1027 (args)
1028 Lisp_Object args;
1030 Lisp_Object val;
1031 struct catchtag c;
1032 struct handler h;
1033 register Lisp_Object var, bodyform, handlers;
1035 var = Fcar (args);
1036 bodyform = Fcar (Fcdr (args));
1037 handlers = Fcdr (Fcdr (args));
1038 CHECK_SYMBOL (var, 0);
1040 for (val = handlers; ! NILP (val); val = Fcdr (val))
1042 Lisp_Object tem;
1043 tem = Fcar (val);
1044 if (! (NILP (tem)
1045 || (CONSP (tem)
1046 && (SYMBOLP (XCONS (tem)->car)
1047 || CONSP (XCONS (tem)->car)))))
1048 error ("Invalid condition handler", tem);
1051 c.tag = Qnil;
1052 c.val = Qnil;
1053 c.backlist = backtrace_list;
1054 c.handlerlist = handlerlist;
1055 c.lisp_eval_depth = lisp_eval_depth;
1056 c.pdlcount = specpdl_ptr - specpdl;
1057 c.poll_suppress_count = poll_suppress_count;
1058 c.gcpro = gcprolist;
1059 if (_setjmp (c.jmp))
1061 if (!NILP (h.var))
1062 specbind (h.var, c.val);
1063 val = Fprogn (Fcdr (h.chosen_clause));
1065 /* Note that this just undoes the binding of h.var; whoever
1066 longjumped to us unwound the stack to c.pdlcount before
1067 throwing. */
1068 unbind_to (c.pdlcount, Qnil);
1069 return val;
1071 c.next = catchlist;
1072 catchlist = &c;
1074 h.var = var;
1075 h.handler = handlers;
1076 h.next = handlerlist;
1077 h.tag = &c;
1078 handlerlist = &h;
1080 val = Feval (bodyform);
1081 catchlist = c.next;
1082 handlerlist = h.next;
1083 return val;
1086 /* Call the function BFUN with no arguments, catching errors within it
1087 according to HANDLERS. If there is an error, call HFUN with
1088 one argument which is the data that describes the error:
1089 (SIGNALNAME . DATA)
1091 HANDLERS can be a list of conditions to catch.
1092 If HANDLERS is Qt, catch all errors.
1093 If HANDLERS is Qerror, catch all errors
1094 but allow the debugger to run if that is enabled. */
1096 Lisp_Object
1097 internal_condition_case (bfun, handlers, hfun)
1098 Lisp_Object (*bfun) ();
1099 Lisp_Object handlers;
1100 Lisp_Object (*hfun) ();
1102 Lisp_Object val;
1103 struct catchtag c;
1104 struct handler h;
1106 /* Since Fsignal resets this to 0, it had better be 0 now
1107 or else we have a potential bug. */
1108 if (interrupt_input_blocked != 0)
1109 abort ();
1111 c.tag = Qnil;
1112 c.val = Qnil;
1113 c.backlist = backtrace_list;
1114 c.handlerlist = handlerlist;
1115 c.lisp_eval_depth = lisp_eval_depth;
1116 c.pdlcount = specpdl_ptr - specpdl;
1117 c.poll_suppress_count = poll_suppress_count;
1118 c.gcpro = gcprolist;
1119 if (_setjmp (c.jmp))
1121 return (*hfun) (c.val);
1123 c.next = catchlist;
1124 catchlist = &c;
1125 h.handler = handlers;
1126 h.var = Qnil;
1127 h.next = handlerlist;
1128 h.tag = &c;
1129 handlerlist = &h;
1131 val = (*bfun) ();
1132 catchlist = c.next;
1133 handlerlist = h.next;
1134 return val;
1137 /* Like internal_condition_case but call HFUN with ARG as its argument. */
1139 Lisp_Object
1140 internal_condition_case_1 (bfun, arg, handlers, hfun)
1141 Lisp_Object (*bfun) ();
1142 Lisp_Object arg;
1143 Lisp_Object handlers;
1144 Lisp_Object (*hfun) ();
1146 Lisp_Object val;
1147 struct catchtag c;
1148 struct handler h;
1150 c.tag = Qnil;
1151 c.val = Qnil;
1152 c.backlist = backtrace_list;
1153 c.handlerlist = handlerlist;
1154 c.lisp_eval_depth = lisp_eval_depth;
1155 c.pdlcount = specpdl_ptr - specpdl;
1156 c.poll_suppress_count = poll_suppress_count;
1157 c.gcpro = gcprolist;
1158 if (_setjmp (c.jmp))
1160 return (*hfun) (c.val);
1162 c.next = catchlist;
1163 catchlist = &c;
1164 h.handler = handlers;
1165 h.var = Qnil;
1166 h.next = handlerlist;
1167 h.tag = &c;
1168 handlerlist = &h;
1170 val = (*bfun) (arg);
1171 catchlist = c.next;
1172 handlerlist = h.next;
1173 return val;
1176 static Lisp_Object find_handler_clause ();
1178 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
1179 "Signal an error. Args are ERROR-SYMBOL and associated DATA.\n\
1180 This function does not return.\n\n\
1181 An error symbol is a symbol with an `error-conditions' property\n\
1182 that is a list of condition names.\n\
1183 A handler for any of those names will get to handle this signal.\n\
1184 The symbol `error' should normally be one of them.\n\
1186 DATA should be a list. Its elements are printed as part of the error message.\n\
1187 If the signal is handled, DATA is made available to the handler.\n\
1188 See also the function `condition-case'.")
1189 (error_symbol, data)
1190 Lisp_Object error_symbol, data;
1192 register struct handler *allhandlers = handlerlist;
1193 Lisp_Object conditions;
1194 extern int gc_in_progress;
1195 extern int waiting_for_input;
1196 Lisp_Object debugger_value;
1198 quit_error_check ();
1199 immediate_quit = 0;
1200 if (gc_in_progress || waiting_for_input)
1201 abort ();
1203 #ifdef HAVE_X_WINDOWS
1204 TOTALLY_UNBLOCK_INPUT;
1205 #endif
1207 conditions = Fget (error_symbol, Qerror_conditions);
1209 for (; handlerlist; handlerlist = handlerlist->next)
1211 register Lisp_Object clause;
1212 clause = find_handler_clause (handlerlist->handler, conditions,
1213 error_symbol, data, &debugger_value);
1215 #if 0 /* Most callers are not prepared to handle gc if this returns.
1216 So, since this feature is not very useful, take it out. */
1217 /* If have called debugger and user wants to continue,
1218 just return nil. */
1219 if (EQ (clause, Qlambda))
1220 return debugger_value;
1221 #else
1222 if (EQ (clause, Qlambda))
1224 /* We can't return values to code which signaled an error, but we
1225 can continue code which has signaled a quit. */
1226 if (EQ (error_symbol, Qquit))
1227 return Qnil;
1228 else
1229 error ("Cannot return from the debugger in an error");
1231 #endif
1233 if (!NILP (clause))
1235 Lisp_Object unwind_data;
1236 struct handler *h = handlerlist;
1238 handlerlist = allhandlers;
1239 if (EQ (data, memory_signal_data))
1240 unwind_data = memory_signal_data;
1241 else
1242 unwind_data = Fcons (error_symbol, data);
1243 h->chosen_clause = clause;
1244 unwind_to_catch (h->tag, unwind_data);
1248 handlerlist = allhandlers;
1249 /* If no handler is present now, try to run the debugger,
1250 and if that fails, throw to top level. */
1251 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value);
1252 Fthrow (Qtop_level, Qt);
1255 /* Return nonzero iff LIST is a non-nil atom or
1256 a list containing one of CONDITIONS. */
1258 static int
1259 wants_debugger (list, conditions)
1260 Lisp_Object list, conditions;
1262 if (NILP (list))
1263 return 0;
1264 if (! CONSP (list))
1265 return 1;
1267 while (CONSP (conditions))
1269 Lisp_Object this, tail;
1270 this = XCONS (conditions)->car;
1271 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
1272 if (EQ (XCONS (tail)->car, this))
1273 return 1;
1274 conditions = XCONS (conditions)->cdr;
1276 return 0;
1279 /* Return 1 if an error with condition-symbols CONDITIONS,
1280 and described by SIGNAL-DATA, should skip the debugger
1281 according to debugger-ignore-errors. */
1283 static int
1284 skip_debugger (conditions, data)
1285 Lisp_Object conditions, data;
1287 Lisp_Object tail;
1288 int first_string = 1;
1289 Lisp_Object error_message;
1291 for (tail = Vdebug_ignored_errors; CONSP (tail);
1292 tail = XCONS (tail)->cdr)
1294 if (STRINGP (XCONS (tail)->car))
1296 if (first_string)
1298 error_message = Ferror_message_string (data);
1299 first_string = 0;
1301 if (fast_string_match (XCONS (tail)->car, error_message) >= 0)
1302 return 1;
1304 else
1306 Lisp_Object contail;
1308 for (contail = conditions; CONSP (contail);
1309 contail = XCONS (contail)->cdr)
1310 if (EQ (XCONS (tail)->car, XCONS (contail)->car))
1311 return 1;
1315 return 0;
1318 /* Value of Qlambda means we have called debugger and user has continued.
1319 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
1321 static Lisp_Object
1322 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr)
1323 Lisp_Object handlers, conditions, sig, data;
1324 Lisp_Object *debugger_value_ptr;
1326 register Lisp_Object h;
1327 register Lisp_Object tem;
1329 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */
1330 return Qt;
1331 if (EQ (handlers, Qerror)) /* error is used similarly, but means display a backtrace too */
1333 if (wants_debugger (Vstack_trace_on_error, conditions))
1334 internal_with_output_to_temp_buffer ("*Backtrace*", Fbacktrace, Qnil);
1335 if ((EQ (sig, Qquit)
1336 ? debug_on_quit
1337 : wants_debugger (Vdebug_on_error, conditions))
1338 && ! skip_debugger (conditions, Fcons (sig, data))
1339 && when_entered_debugger < num_nonmacro_input_chars)
1341 int count = specpdl_ptr - specpdl;
1342 specbind (Qdebug_on_error, Qnil);
1343 *debugger_value_ptr
1344 = call_debugger (Fcons (Qerror,
1345 Fcons (Fcons (sig, data),
1346 Qnil)));
1347 return unbind_to (count, Qlambda);
1349 return Qt;
1351 for (h = handlers; CONSP (h); h = Fcdr (h))
1353 Lisp_Object handler, condit;
1355 handler = Fcar (h);
1356 if (!CONSP (handler))
1357 continue;
1358 condit = Fcar (handler);
1359 /* Handle a single condition name in handler HANDLER. */
1360 if (SYMBOLP (condit))
1362 tem = Fmemq (Fcar (handler), conditions);
1363 if (!NILP (tem))
1364 return handler;
1366 /* Handle a list of condition names in handler HANDLER. */
1367 else if (CONSP (condit))
1369 while (CONSP (condit))
1371 tem = Fmemq (Fcar (condit), conditions);
1372 if (!NILP (tem))
1373 return handler;
1374 condit = XCONS (condit)->cdr;
1378 return Qnil;
1381 /* dump an error message; called like printf */
1383 /* VARARGS 1 */
1384 void
1385 error (m, a1, a2, a3)
1386 char *m;
1387 char *a1, *a2, *a3;
1389 char buf[200];
1390 int size = 200;
1391 int mlen;
1392 char *buffer = buf;
1393 char *args[3];
1394 int allocated = 0;
1395 Lisp_Object string;
1397 args[0] = a1;
1398 args[1] = a2;
1399 args[2] = a3;
1401 mlen = strlen (m);
1403 while (1)
1405 int used = doprnt (buf, size, m, m + mlen, 3, args);
1406 if (used < size)
1407 break;
1408 size *= 2;
1409 if (allocated)
1410 buffer = (char *) xrealloc (buffer, size);
1411 else
1413 buffer = (char *) xmalloc (size);
1414 allocated = 1;
1418 string = build_string (buf);
1419 if (allocated)
1420 free (buffer);
1422 Fsignal (Qerror, Fcons (string, Qnil));
1425 DEFUN ("commandp", Fcommandp, Scommandp, 1, 1, 0,
1426 "T if FUNCTION makes provisions for interactive calling.\n\
1427 This means it contains a description for how to read arguments to give it.\n\
1428 The value is nil for an invalid function or a symbol with no function\n\
1429 definition.\n\
1431 Interactively callable functions include strings and vectors (treated\n\
1432 as keyboard macros), lambda-expressions that contain a top-level call\n\
1433 to `interactive', autoload definitions made by `autoload' with non-nil\n\
1434 fourth argument, and some of the built-in functions of Lisp.\n\
1436 Also, a symbol satisfies `commandp' if its function definition does so.")
1437 (function)
1438 Lisp_Object function;
1440 register Lisp_Object fun;
1441 register Lisp_Object funcar;
1442 register Lisp_Object tem;
1443 register int i = 0;
1445 fun = function;
1447 fun = indirect_function (fun);
1448 if (EQ (fun, Qunbound))
1449 return Qnil;
1451 /* Emacs primitives are interactive if their DEFUN specifies an
1452 interactive spec. */
1453 if (SUBRP (fun))
1455 if (XSUBR (fun)->prompt)
1456 return Qt;
1457 else
1458 return Qnil;
1461 /* Bytecode objects are interactive if they are long enough to
1462 have an element whose index is COMPILED_INTERACTIVE, which is
1463 where the interactive spec is stored. */
1464 else if (COMPILEDP (fun))
1465 return ((XVECTOR (fun)->size & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
1466 ? Qt : Qnil);
1468 /* Strings and vectors are keyboard macros. */
1469 if (STRINGP (fun) || VECTORP (fun))
1470 return Qt;
1472 /* Lists may represent commands. */
1473 if (!CONSP (fun))
1474 return Qnil;
1475 funcar = Fcar (fun);
1476 if (!SYMBOLP (funcar))
1477 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1478 if (EQ (funcar, Qlambda))
1479 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
1480 if (EQ (funcar, Qmocklisp))
1481 return Qt; /* All mocklisp functions can be called interactively */
1482 if (EQ (funcar, Qautoload))
1483 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
1484 else
1485 return Qnil;
1488 /* ARGSUSED */
1489 DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
1490 "Define FUNCTION to autoload from FILE.\n\
1491 FUNCTION is a symbol; FILE is a file name string to pass to `load'.\n\
1492 Third arg DOCSTRING is documentation for the function.\n\
1493 Fourth arg INTERACTIVE if non-nil says function can be called interactively.\n\
1494 Fifth arg TYPE indicates the type of the object:\n\
1495 nil or omitted says FUNCTION is a function,\n\
1496 `keymap' says FUNCTION is really a keymap, and\n\
1497 `macro' or t says FUNCTION is really a macro.\n\
1498 Third through fifth args give info about the real definition.\n\
1499 They default to nil.\n\
1500 If FUNCTION is already defined other than as an autoload,\n\
1501 this does nothing and returns nil.")
1502 (function, file, docstring, interactive, type)
1503 Lisp_Object function, file, docstring, interactive, type;
1505 #ifdef NO_ARG_ARRAY
1506 Lisp_Object args[4];
1507 #endif
1509 CHECK_SYMBOL (function, 0);
1510 CHECK_STRING (file, 1);
1512 /* If function is defined and not as an autoload, don't override */
1513 if (!EQ (XSYMBOL (function)->function, Qunbound)
1514 && !(CONSP (XSYMBOL (function)->function)
1515 && EQ (XCONS (XSYMBOL (function)->function)->car, Qautoload)))
1516 return Qnil;
1518 #ifdef NO_ARG_ARRAY
1519 args[0] = file;
1520 args[1] = docstring;
1521 args[2] = interactive;
1522 args[3] = type;
1524 return Ffset (function, Fcons (Qautoload, Flist (4, &args[0])));
1525 #else /* NO_ARG_ARRAY */
1526 return Ffset (function, Fcons (Qautoload, Flist (4, &file)));
1527 #endif /* not NO_ARG_ARRAY */
1530 Lisp_Object
1531 un_autoload (oldqueue)
1532 Lisp_Object oldqueue;
1534 register Lisp_Object queue, first, second;
1536 /* Queue to unwind is current value of Vautoload_queue.
1537 oldqueue is the shadowed value to leave in Vautoload_queue. */
1538 queue = Vautoload_queue;
1539 Vautoload_queue = oldqueue;
1540 while (CONSP (queue))
1542 first = Fcar (queue);
1543 second = Fcdr (first);
1544 first = Fcar (first);
1545 if (EQ (second, Qnil))
1546 Vfeatures = first;
1547 else
1548 Ffset (first, second);
1549 queue = Fcdr (queue);
1551 return Qnil;
1554 do_autoload (fundef, funname)
1555 Lisp_Object fundef, funname;
1557 int count = specpdl_ptr - specpdl;
1558 Lisp_Object fun, val, queue, first, second;
1560 fun = funname;
1561 CHECK_SYMBOL (funname, 0);
1563 /* Value saved here is to be restored into Vautoload_queue */
1564 record_unwind_protect (un_autoload, Vautoload_queue);
1565 Vautoload_queue = Qt;
1566 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil);
1568 /* Save the old autoloads, in case we ever do an unload. */
1569 queue = Vautoload_queue;
1570 while (CONSP (queue))
1572 first = Fcar (queue);
1573 second = Fcdr (first);
1574 first = Fcar (first);
1576 /* Note: This test is subtle. The cdr of an autoload-queue entry
1577 may be an atom if the autoload entry was generated by a defalias
1578 or fset. */
1579 if (CONSP (second))
1580 Fput (first, Qautoload, (Fcdr (second)));
1582 queue = Fcdr (queue);
1585 /* Once loading finishes, don't undo it. */
1586 Vautoload_queue = Qt;
1587 unbind_to (count, Qnil);
1589 fun = Findirect_function (fun);
1591 if (!NILP (Fequal (fun, fundef)))
1592 error ("Autoloading failed to define function %s",
1593 XSYMBOL (funname)->name->data);
1596 DEFUN ("eval", Feval, Seval, 1, 1, 0,
1597 "Evaluate FORM and return its value.")
1598 (form)
1599 Lisp_Object form;
1601 Lisp_Object fun, val, original_fun, original_args;
1602 Lisp_Object funcar;
1603 struct backtrace backtrace;
1604 struct gcpro gcpro1, gcpro2, gcpro3;
1606 if (SYMBOLP (form))
1608 if (EQ (Vmocklisp_arguments, Qt))
1609 return Fsymbol_value (form);
1610 val = Fsymbol_value (form);
1611 if (NILP (val))
1612 XSETFASTINT (val, 0);
1613 else if (EQ (val, Qt))
1614 XSETFASTINT (val, 1);
1615 return val;
1617 if (!CONSP (form))
1618 return form;
1620 QUIT;
1621 if (consing_since_gc > gc_cons_threshold)
1623 GCPRO1 (form);
1624 Fgarbage_collect ();
1625 UNGCPRO;
1628 if (++lisp_eval_depth > max_lisp_eval_depth)
1630 if (max_lisp_eval_depth < 100)
1631 max_lisp_eval_depth = 100;
1632 if (lisp_eval_depth > max_lisp_eval_depth)
1633 error ("Lisp nesting exceeds max-lisp-eval-depth");
1636 original_fun = Fcar (form);
1637 original_args = Fcdr (form);
1639 backtrace.next = backtrace_list;
1640 backtrace_list = &backtrace;
1641 backtrace.function = &original_fun; /* This also protects them from gc */
1642 backtrace.args = &original_args;
1643 backtrace.nargs = UNEVALLED;
1644 backtrace.evalargs = 1;
1645 backtrace.debug_on_exit = 0;
1647 if (debug_on_next_call)
1648 do_debug_on_call (Qt);
1650 /* At this point, only original_fun and original_args
1651 have values that will be used below */
1652 retry:
1653 fun = Findirect_function (original_fun);
1655 if (SUBRP (fun))
1657 Lisp_Object numargs;
1658 Lisp_Object argvals[7];
1659 Lisp_Object args_left;
1660 register int i, maxargs;
1662 args_left = original_args;
1663 numargs = Flength (args_left);
1665 if (XINT (numargs) < XSUBR (fun)->min_args ||
1666 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
1667 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
1669 if (XSUBR (fun)->max_args == UNEVALLED)
1671 backtrace.evalargs = 0;
1672 val = (*XSUBR (fun)->function) (args_left);
1673 goto done;
1676 if (XSUBR (fun)->max_args == MANY)
1678 /* Pass a vector of evaluated arguments */
1679 Lisp_Object *vals;
1680 register int argnum = 0;
1682 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
1684 GCPRO3 (args_left, fun, fun);
1685 gcpro3.var = vals;
1686 gcpro3.nvars = 0;
1688 while (!NILP (args_left))
1690 vals[argnum++] = Feval (Fcar (args_left));
1691 args_left = Fcdr (args_left);
1692 gcpro3.nvars = argnum;
1695 backtrace.args = vals;
1696 backtrace.nargs = XINT (numargs);
1698 val = (*XSUBR (fun)->function) (XINT (numargs), vals);
1699 UNGCPRO;
1700 goto done;
1703 GCPRO3 (args_left, fun, fun);
1704 gcpro3.var = argvals;
1705 gcpro3.nvars = 0;
1707 maxargs = XSUBR (fun)->max_args;
1708 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
1710 argvals[i] = Feval (Fcar (args_left));
1711 gcpro3.nvars = ++i;
1714 UNGCPRO;
1716 backtrace.args = argvals;
1717 backtrace.nargs = XINT (numargs);
1719 switch (i)
1721 case 0:
1722 val = (*XSUBR (fun)->function) ();
1723 goto done;
1724 case 1:
1725 val = (*XSUBR (fun)->function) (argvals[0]);
1726 goto done;
1727 case 2:
1728 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]);
1729 goto done;
1730 case 3:
1731 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
1732 argvals[2]);
1733 goto done;
1734 case 4:
1735 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
1736 argvals[2], argvals[3]);
1737 goto done;
1738 case 5:
1739 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
1740 argvals[3], argvals[4]);
1741 goto done;
1742 case 6:
1743 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
1744 argvals[3], argvals[4], argvals[5]);
1745 goto done;
1746 case 7:
1747 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
1748 argvals[3], argvals[4], argvals[5],
1749 argvals[6]);
1750 goto done;
1752 default:
1753 /* Someone has created a subr that takes more arguments than
1754 is supported by this code. We need to either rewrite the
1755 subr to use a different argument protocol, or add more
1756 cases to this switch. */
1757 abort ();
1760 if (COMPILEDP (fun))
1761 val = apply_lambda (fun, original_args, 1);
1762 else
1764 if (!CONSP (fun))
1765 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1766 funcar = Fcar (fun);
1767 if (!SYMBOLP (funcar))
1768 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1769 if (EQ (funcar, Qautoload))
1771 do_autoload (fun, original_fun);
1772 goto retry;
1774 if (EQ (funcar, Qmacro))
1775 val = Feval (apply1 (Fcdr (fun), original_args));
1776 else if (EQ (funcar, Qlambda))
1777 val = apply_lambda (fun, original_args, 1);
1778 else if (EQ (funcar, Qmocklisp))
1779 val = ml_apply (fun, original_args);
1780 else
1781 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1783 done:
1784 if (!EQ (Vmocklisp_arguments, Qt))
1786 if (NILP (val))
1787 XSETFASTINT (val, 0);
1788 else if (EQ (val, Qt))
1789 XSETFASTINT (val, 1);
1791 lisp_eval_depth--;
1792 if (backtrace.debug_on_exit)
1793 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
1794 backtrace_list = backtrace.next;
1795 return val;
1798 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
1799 "Call FUNCTION with our remaining args, using our last arg as list of args.\n\
1800 Then return the value FUNCTION returns.\n\
1801 Thus, (apply '+ 1 2 '(3 4)) returns 10.")
1802 (nargs, args)
1803 int nargs;
1804 Lisp_Object *args;
1806 register int i, numargs;
1807 register Lisp_Object spread_arg;
1808 register Lisp_Object *funcall_args;
1809 Lisp_Object fun;
1810 struct gcpro gcpro1;
1812 fun = args [0];
1813 funcall_args = 0;
1814 spread_arg = args [nargs - 1];
1815 CHECK_LIST (spread_arg, nargs);
1817 numargs = XINT (Flength (spread_arg));
1819 if (numargs == 0)
1820 return Ffuncall (nargs - 1, args);
1821 else if (numargs == 1)
1823 args [nargs - 1] = XCONS (spread_arg)->car;
1824 return Ffuncall (nargs, args);
1827 numargs += nargs - 2;
1829 fun = indirect_function (fun);
1830 if (EQ (fun, Qunbound))
1832 /* Let funcall get the error */
1833 fun = args[0];
1834 goto funcall;
1837 if (SUBRP (fun))
1839 if (numargs < XSUBR (fun)->min_args
1840 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
1841 goto funcall; /* Let funcall get the error */
1842 else if (XSUBR (fun)->max_args > numargs)
1844 /* Avoid making funcall cons up a yet another new vector of arguments
1845 by explicitly supplying nil's for optional values */
1846 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
1847 * sizeof (Lisp_Object));
1848 for (i = numargs; i < XSUBR (fun)->max_args;)
1849 funcall_args[++i] = Qnil;
1850 GCPRO1 (*funcall_args);
1851 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
1854 funcall:
1855 /* We add 1 to numargs because funcall_args includes the
1856 function itself as well as its arguments. */
1857 if (!funcall_args)
1859 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
1860 * sizeof (Lisp_Object));
1861 GCPRO1 (*funcall_args);
1862 gcpro1.nvars = 1 + numargs;
1865 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
1866 /* Spread the last arg we got. Its first element goes in
1867 the slot that it used to occupy, hence this value of I. */
1868 i = nargs - 1;
1869 while (!NILP (spread_arg))
1871 funcall_args [i++] = XCONS (spread_arg)->car;
1872 spread_arg = XCONS (spread_arg)->cdr;
1875 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
1878 /* Run hook variables in various ways. */
1880 enum run_hooks_condition {to_completion, until_success, until_failure};
1882 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 1, MANY, 0,
1883 "Run each hook in HOOKS. Major mode functions use this.\n\
1884 Each argument should be a symbol, a hook variable.\n\
1885 These symbols are processed in the order specified.\n\
1886 If a hook symbol has a non-nil value, that value may be a function\n\
1887 or a list of functions to be called to run the hook.\n\
1888 If the value is a function, it is called with no arguments.\n\
1889 If it is a list, the elements are called, in order, with no arguments.\n\
1891 To make a hook variable buffer-local, use `make-local-hook',\n\
1892 not `make-local-variable'.")
1893 (nargs, args)
1894 int nargs;
1895 Lisp_Object *args;
1897 Lisp_Object hook[1];
1898 register int i;
1900 for (i = 0; i < nargs; i++)
1902 hook[0] = args[i];
1903 run_hook_with_args (1, hook, to_completion);
1906 return Qnil;
1909 DEFUN ("run-hook-with-args",
1910 Frun_hook_with_args, Srun_hook_with_args, 1, MANY, 0,
1911 "Run HOOK with the specified arguments ARGS.\n\
1912 HOOK should be a symbol, a hook variable. If HOOK has a non-nil\n\
1913 value, that value may be a function or a list of functions to be\n\
1914 called to run the hook. If the value is a function, it is called with\n\
1915 the given arguments and its return value is returned. If it is a list\n\
1916 of functions, those functions are called, in order,\n\
1917 with the given arguments ARGS.\n\
1918 It is best not to depend on the value return by `run-hook-with-args',\n\
1919 as that may change.\n\
1921 To make a hook variable buffer-local, use `make-local-hook',\n\
1922 not `make-local-variable'.")
1923 (nargs, args)
1924 int nargs;
1925 Lisp_Object *args;
1927 return run_hook_with_args (nargs, args, to_completion);
1930 DEFUN ("run-hook-with-args-until-success",
1931 Frun_hook_with_args_until_success, Srun_hook_with_args_until_success,
1932 1, MANY, 0,
1933 "Run HOOK with the specified arguments ARGS.\n\
1934 HOOK should be a symbol, a hook variable. Its value should\n\
1935 be a list of functions. We call those functions, one by one,\n\
1936 passing arguments ARGS to each of them, until one of them\n\
1937 returns a non-nil value. Then we return that value.\n\
1938 If all the functions return nil, we return nil.\n\
1940 To make a hook variable buffer-local, use `make-local-hook',\n\
1941 not `make-local-variable'.")
1942 (nargs, args)
1943 int nargs;
1944 Lisp_Object *args;
1946 return run_hook_with_args (nargs, args, until_success);
1949 DEFUN ("run-hook-with-args-until-failure",
1950 Frun_hook_with_args_until_failure, Srun_hook_with_args_until_failure,
1951 1, MANY, 0,
1952 "Run HOOK with the specified arguments ARGS.\n\
1953 HOOK should be a symbol, a hook variable. Its value should\n\
1954 be a list of functions. We call those functions, one by one,\n\
1955 passing arguments ARGS to each of them, until one of them\n\
1956 returns nil. Then we return nil.\n\
1957 If all the functions return non-nil, we return non-nil.\n\
1959 To make a hook variable buffer-local, use `make-local-hook',\n\
1960 not `make-local-variable'.")
1961 (nargs, args)
1962 int nargs;
1963 Lisp_Object *args;
1965 return run_hook_with_args (nargs, args, until_failure);
1968 /* ARGS[0] should be a hook symbol.
1969 Call each of the functions in the hook value, passing each of them
1970 as arguments all the rest of ARGS (all NARGS - 1 elements).
1971 COND specifies a condition to test after each call
1972 to decide whether to stop.
1973 The caller (or its caller, etc) must gcpro all of ARGS,
1974 except that it isn't necessary to gcpro ARGS[0]. */
1976 Lisp_Object
1977 run_hook_with_args (nargs, args, cond)
1978 int nargs;
1979 Lisp_Object *args;
1980 enum run_hooks_condition cond;
1982 Lisp_Object sym, val, ret;
1983 struct gcpro gcpro1, gcpro2;
1985 /* If we are dying or still initializing,
1986 don't do anything--it would probably crash if we tried. */
1987 if (NILP (Vrun_hooks))
1988 return;
1990 sym = args[0];
1991 val = find_symbol_value (sym);
1992 ret = (cond == until_failure ? Qt : Qnil);
1994 if (EQ (val, Qunbound) || NILP (val))
1995 return ret;
1996 else if (!CONSP (val) || EQ (XCONS (val)->car, Qlambda))
1998 args[0] = val;
1999 return Ffuncall (nargs, args);
2001 else
2003 GCPRO2 (sym, val);
2005 for (;
2006 CONSP (val) && ((cond == to_completion)
2007 || (cond == until_success ? NILP (ret)
2008 : !NILP (ret)));
2009 val = XCONS (val)->cdr)
2011 if (EQ (XCONS (val)->car, Qt))
2013 /* t indicates this hook has a local binding;
2014 it means to run the global binding too. */
2015 Lisp_Object globals;
2017 for (globals = Fdefault_value (sym);
2018 CONSP (globals) && ((cond == to_completion)
2019 || (cond == until_success ? NILP (ret)
2020 : !NILP (ret)));
2021 globals = XCONS (globals)->cdr)
2023 args[0] = XCONS (globals)->car;
2024 /* In a global value, t should not occur. If it does, we
2025 must ignore it to avoid an endless loop. */
2026 if (!EQ (args[0], Qt))
2027 ret = Ffuncall (nargs, args);
2030 else
2032 args[0] = XCONS (val)->car;
2033 ret = Ffuncall (nargs, args);
2037 UNGCPRO;
2038 return ret;
2042 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2043 present value of that symbol.
2044 Call each element of FUNLIST,
2045 passing each of them the rest of ARGS.
2046 The caller (or its caller, etc) must gcpro all of ARGS,
2047 except that it isn't necessary to gcpro ARGS[0]. */
2049 Lisp_Object
2050 run_hook_list_with_args (funlist, nargs, args)
2051 Lisp_Object funlist;
2052 int nargs;
2053 Lisp_Object *args;
2055 Lisp_Object sym;
2056 Lisp_Object val;
2057 struct gcpro gcpro1, gcpro2;
2059 sym = args[0];
2060 GCPRO2 (sym, val);
2062 for (val = funlist; CONSP (val); val = XCONS (val)->cdr)
2064 if (EQ (XCONS (val)->car, Qt))
2066 /* t indicates this hook has a local binding;
2067 it means to run the global binding too. */
2068 Lisp_Object globals;
2070 for (globals = Fdefault_value (sym);
2071 CONSP (globals);
2072 globals = XCONS (globals)->cdr)
2074 args[0] = XCONS (globals)->car;
2075 /* In a global value, t should not occur. If it does, we
2076 must ignore it to avoid an endless loop. */
2077 if (!EQ (args[0], Qt))
2078 Ffuncall (nargs, args);
2081 else
2083 args[0] = XCONS (val)->car;
2084 Ffuncall (nargs, args);
2087 UNGCPRO;
2088 return Qnil;
2091 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2093 void
2094 run_hook_with_args_2 (hook, arg1, arg2)
2095 Lisp_Object hook, arg1, arg2;
2097 Lisp_Object temp[3];
2098 temp[0] = hook;
2099 temp[1] = arg1;
2100 temp[2] = arg2;
2102 Frun_hook_with_args (3, temp);
2105 /* Apply fn to arg */
2106 Lisp_Object
2107 apply1 (fn, arg)
2108 Lisp_Object fn, arg;
2110 struct gcpro gcpro1;
2112 GCPRO1 (fn);
2113 if (NILP (arg))
2114 RETURN_UNGCPRO (Ffuncall (1, &fn));
2115 gcpro1.nvars = 2;
2116 #ifdef NO_ARG_ARRAY
2118 Lisp_Object args[2];
2119 args[0] = fn;
2120 args[1] = arg;
2121 gcpro1.var = args;
2122 RETURN_UNGCPRO (Fapply (2, args));
2124 #else /* not NO_ARG_ARRAY */
2125 RETURN_UNGCPRO (Fapply (2, &fn));
2126 #endif /* not NO_ARG_ARRAY */
2129 /* Call function fn on no arguments */
2130 Lisp_Object
2131 call0 (fn)
2132 Lisp_Object fn;
2134 struct gcpro gcpro1;
2136 GCPRO1 (fn);
2137 RETURN_UNGCPRO (Ffuncall (1, &fn));
2140 /* Call function fn with 1 argument arg1 */
2141 /* ARGSUSED */
2142 Lisp_Object
2143 call1 (fn, arg1)
2144 Lisp_Object fn, arg1;
2146 struct gcpro gcpro1;
2147 #ifdef NO_ARG_ARRAY
2148 Lisp_Object args[2];
2150 args[0] = fn;
2151 args[1] = arg1;
2152 GCPRO1 (args[0]);
2153 gcpro1.nvars = 2;
2154 RETURN_UNGCPRO (Ffuncall (2, args));
2155 #else /* not NO_ARG_ARRAY */
2156 GCPRO1 (fn);
2157 gcpro1.nvars = 2;
2158 RETURN_UNGCPRO (Ffuncall (2, &fn));
2159 #endif /* not NO_ARG_ARRAY */
2162 /* Call function fn with 2 arguments arg1, arg2 */
2163 /* ARGSUSED */
2164 Lisp_Object
2165 call2 (fn, arg1, arg2)
2166 Lisp_Object fn, arg1, arg2;
2168 struct gcpro gcpro1;
2169 #ifdef NO_ARG_ARRAY
2170 Lisp_Object args[3];
2171 args[0] = fn;
2172 args[1] = arg1;
2173 args[2] = arg2;
2174 GCPRO1 (args[0]);
2175 gcpro1.nvars = 3;
2176 RETURN_UNGCPRO (Ffuncall (3, args));
2177 #else /* not NO_ARG_ARRAY */
2178 GCPRO1 (fn);
2179 gcpro1.nvars = 3;
2180 RETURN_UNGCPRO (Ffuncall (3, &fn));
2181 #endif /* not NO_ARG_ARRAY */
2184 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2185 /* ARGSUSED */
2186 Lisp_Object
2187 call3 (fn, arg1, arg2, arg3)
2188 Lisp_Object fn, arg1, arg2, arg3;
2190 struct gcpro gcpro1;
2191 #ifdef NO_ARG_ARRAY
2192 Lisp_Object args[4];
2193 args[0] = fn;
2194 args[1] = arg1;
2195 args[2] = arg2;
2196 args[3] = arg3;
2197 GCPRO1 (args[0]);
2198 gcpro1.nvars = 4;
2199 RETURN_UNGCPRO (Ffuncall (4, args));
2200 #else /* not NO_ARG_ARRAY */
2201 GCPRO1 (fn);
2202 gcpro1.nvars = 4;
2203 RETURN_UNGCPRO (Ffuncall (4, &fn));
2204 #endif /* not NO_ARG_ARRAY */
2207 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2208 /* ARGSUSED */
2209 Lisp_Object
2210 call4 (fn, arg1, arg2, arg3, arg4)
2211 Lisp_Object fn, arg1, arg2, arg3, arg4;
2213 struct gcpro gcpro1;
2214 #ifdef NO_ARG_ARRAY
2215 Lisp_Object args[5];
2216 args[0] = fn;
2217 args[1] = arg1;
2218 args[2] = arg2;
2219 args[3] = arg3;
2220 args[4] = arg4;
2221 GCPRO1 (args[0]);
2222 gcpro1.nvars = 5;
2223 RETURN_UNGCPRO (Ffuncall (5, args));
2224 #else /* not NO_ARG_ARRAY */
2225 GCPRO1 (fn);
2226 gcpro1.nvars = 5;
2227 RETURN_UNGCPRO (Ffuncall (5, &fn));
2228 #endif /* not NO_ARG_ARRAY */
2231 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2232 /* ARGSUSED */
2233 Lisp_Object
2234 call5 (fn, arg1, arg2, arg3, arg4, arg5)
2235 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
2237 struct gcpro gcpro1;
2238 #ifdef NO_ARG_ARRAY
2239 Lisp_Object args[6];
2240 args[0] = fn;
2241 args[1] = arg1;
2242 args[2] = arg2;
2243 args[3] = arg3;
2244 args[4] = arg4;
2245 args[5] = arg5;
2246 GCPRO1 (args[0]);
2247 gcpro1.nvars = 6;
2248 RETURN_UNGCPRO (Ffuncall (6, args));
2249 #else /* not NO_ARG_ARRAY */
2250 GCPRO1 (fn);
2251 gcpro1.nvars = 6;
2252 RETURN_UNGCPRO (Ffuncall (6, &fn));
2253 #endif /* not NO_ARG_ARRAY */
2256 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2257 /* ARGSUSED */
2258 Lisp_Object
2259 call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
2260 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
2262 struct gcpro gcpro1;
2263 #ifdef NO_ARG_ARRAY
2264 Lisp_Object args[7];
2265 args[0] = fn;
2266 args[1] = arg1;
2267 args[2] = arg2;
2268 args[3] = arg3;
2269 args[4] = arg4;
2270 args[5] = arg5;
2271 args[6] = arg6;
2272 GCPRO1 (args[0]);
2273 gcpro1.nvars = 7;
2274 RETURN_UNGCPRO (Ffuncall (7, args));
2275 #else /* not NO_ARG_ARRAY */
2276 GCPRO1 (fn);
2277 gcpro1.nvars = 7;
2278 RETURN_UNGCPRO (Ffuncall (7, &fn));
2279 #endif /* not NO_ARG_ARRAY */
2282 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2283 "Call first argument as a function, passing remaining arguments to it.\n\
2284 Return the value that function returns.\n\
2285 Thus, (funcall 'cons 'x 'y) returns (x . y).")
2286 (nargs, args)
2287 int nargs;
2288 Lisp_Object *args;
2290 Lisp_Object fun;
2291 Lisp_Object funcar;
2292 int numargs = nargs - 1;
2293 Lisp_Object lisp_numargs;
2294 Lisp_Object val;
2295 struct backtrace backtrace;
2296 register Lisp_Object *internal_args;
2297 register int i;
2299 QUIT;
2300 if (consing_since_gc > gc_cons_threshold)
2301 Fgarbage_collect ();
2303 if (++lisp_eval_depth > max_lisp_eval_depth)
2305 if (max_lisp_eval_depth < 100)
2306 max_lisp_eval_depth = 100;
2307 if (lisp_eval_depth > max_lisp_eval_depth)
2308 error ("Lisp nesting exceeds max-lisp-eval-depth");
2311 backtrace.next = backtrace_list;
2312 backtrace_list = &backtrace;
2313 backtrace.function = &args[0];
2314 backtrace.args = &args[1];
2315 backtrace.nargs = nargs - 1;
2316 backtrace.evalargs = 0;
2317 backtrace.debug_on_exit = 0;
2319 if (debug_on_next_call)
2320 do_debug_on_call (Qlambda);
2322 retry:
2324 fun = args[0];
2326 fun = Findirect_function (fun);
2328 if (SUBRP (fun))
2330 if (numargs < XSUBR (fun)->min_args
2331 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2333 XSETFASTINT (lisp_numargs, numargs);
2334 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
2337 if (XSUBR (fun)->max_args == UNEVALLED)
2338 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2340 if (XSUBR (fun)->max_args == MANY)
2342 val = (*XSUBR (fun)->function) (numargs, args + 1);
2343 goto done;
2346 if (XSUBR (fun)->max_args > numargs)
2348 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2349 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
2350 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2351 internal_args[i] = Qnil;
2353 else
2354 internal_args = args + 1;
2355 switch (XSUBR (fun)->max_args)
2357 case 0:
2358 val = (*XSUBR (fun)->function) ();
2359 goto done;
2360 case 1:
2361 val = (*XSUBR (fun)->function) (internal_args[0]);
2362 goto done;
2363 case 2:
2364 val = (*XSUBR (fun)->function) (internal_args[0],
2365 internal_args[1]);
2366 goto done;
2367 case 3:
2368 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2369 internal_args[2]);
2370 goto done;
2371 case 4:
2372 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2373 internal_args[2],
2374 internal_args[3]);
2375 goto done;
2376 case 5:
2377 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2378 internal_args[2], internal_args[3],
2379 internal_args[4]);
2380 goto done;
2381 case 6:
2382 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2383 internal_args[2], internal_args[3],
2384 internal_args[4], internal_args[5]);
2385 goto done;
2386 case 7:
2387 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2388 internal_args[2], internal_args[3],
2389 internal_args[4], internal_args[5],
2390 internal_args[6]);
2391 goto done;
2393 default:
2395 /* If a subr takes more than 6 arguments without using MANY
2396 or UNEVALLED, we need to extend this function to support it.
2397 Until this is done, there is no way to call the function. */
2398 abort ();
2401 if (COMPILEDP (fun))
2402 val = funcall_lambda (fun, numargs, args + 1);
2403 else
2405 if (!CONSP (fun))
2406 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2407 funcar = Fcar (fun);
2408 if (!SYMBOLP (funcar))
2409 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2410 if (EQ (funcar, Qlambda))
2411 val = funcall_lambda (fun, numargs, args + 1);
2412 else if (EQ (funcar, Qmocklisp))
2413 val = ml_apply (fun, Flist (numargs, args + 1));
2414 else if (EQ (funcar, Qautoload))
2416 do_autoload (fun, args[0]);
2417 goto retry;
2419 else
2420 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2422 done:
2423 lisp_eval_depth--;
2424 if (backtrace.debug_on_exit)
2425 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2426 backtrace_list = backtrace.next;
2427 return val;
2430 Lisp_Object
2431 apply_lambda (fun, args, eval_flag)
2432 Lisp_Object fun, args;
2433 int eval_flag;
2435 Lisp_Object args_left;
2436 Lisp_Object numargs;
2437 register Lisp_Object *arg_vector;
2438 struct gcpro gcpro1, gcpro2, gcpro3;
2439 register int i;
2440 register Lisp_Object tem;
2442 numargs = Flength (args);
2443 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2444 args_left = args;
2446 GCPRO3 (*arg_vector, args_left, fun);
2447 gcpro1.nvars = 0;
2449 for (i = 0; i < XINT (numargs);)
2451 tem = Fcar (args_left), args_left = Fcdr (args_left);
2452 if (eval_flag) tem = Feval (tem);
2453 arg_vector[i++] = tem;
2454 gcpro1.nvars = i;
2457 UNGCPRO;
2459 if (eval_flag)
2461 backtrace_list->args = arg_vector;
2462 backtrace_list->nargs = i;
2464 backtrace_list->evalargs = 0;
2465 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
2467 /* Do the debug-on-exit now, while arg_vector still exists. */
2468 if (backtrace_list->debug_on_exit)
2469 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
2470 /* Don't do it again when we return to eval. */
2471 backtrace_list->debug_on_exit = 0;
2472 return tem;
2475 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2476 and return the result of evaluation.
2477 FUN must be either a lambda-expression or a compiled-code object. */
2479 Lisp_Object
2480 funcall_lambda (fun, nargs, arg_vector)
2481 Lisp_Object fun;
2482 int nargs;
2483 register Lisp_Object *arg_vector;
2485 Lisp_Object val, tem;
2486 register Lisp_Object syms_left;
2487 Lisp_Object numargs;
2488 register Lisp_Object next;
2489 int count = specpdl_ptr - specpdl;
2490 register int i;
2491 int optional = 0, rest = 0;
2493 specbind (Qmocklisp_arguments, Qt); /* t means NOT mocklisp! */
2495 XSETFASTINT (numargs, nargs);
2497 if (CONSP (fun))
2498 syms_left = Fcar (Fcdr (fun));
2499 else if (COMPILEDP (fun))
2500 syms_left = XVECTOR (fun)->contents[COMPILED_ARGLIST];
2501 else abort ();
2503 i = 0;
2504 for (; !NILP (syms_left); syms_left = Fcdr (syms_left))
2506 QUIT;
2507 next = Fcar (syms_left);
2508 while (!SYMBOLP (next))
2509 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2510 if (EQ (next, Qand_rest))
2511 rest = 1;
2512 else if (EQ (next, Qand_optional))
2513 optional = 1;
2514 else if (rest)
2516 specbind (next, Flist (nargs - i, &arg_vector[i]));
2517 i = nargs;
2519 else if (i < nargs)
2521 tem = arg_vector[i++];
2522 specbind (next, tem);
2524 else if (!optional)
2525 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
2526 else
2527 specbind (next, Qnil);
2530 if (i < nargs)
2531 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
2533 if (CONSP (fun))
2534 val = Fprogn (Fcdr (Fcdr (fun)));
2535 else
2537 /* If we have not actually read the bytecode string
2538 and constants vector yet, fetch them from the file. */
2539 if (CONSP (XVECTOR (fun)->contents[COMPILED_BYTECODE]))
2540 Ffetch_bytecode (fun);
2541 val = Fbyte_code (XVECTOR (fun)->contents[COMPILED_BYTECODE],
2542 XVECTOR (fun)->contents[COMPILED_CONSTANTS],
2543 XVECTOR (fun)->contents[COMPILED_STACK_DEPTH]);
2545 return unbind_to (count, val);
2548 DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
2549 1, 1, 0,
2550 "If byte-compiled OBJECT is lazy-loaded, fetch it now.")
2551 (object)
2552 Lisp_Object object;
2554 Lisp_Object tem;
2556 if (COMPILEDP (object)
2557 && CONSP (XVECTOR (object)->contents[COMPILED_BYTECODE]))
2559 tem = read_doc_string (XVECTOR (object)->contents[COMPILED_BYTECODE]);
2560 if (!CONSP (tem))
2561 error ("invalid byte code");
2562 XVECTOR (object)->contents[COMPILED_BYTECODE] = XCONS (tem)->car;
2563 XVECTOR (object)->contents[COMPILED_CONSTANTS] = XCONS (tem)->cdr;
2565 return object;
2568 void
2569 grow_specpdl ()
2571 register int count = specpdl_ptr - specpdl;
2572 if (specpdl_size >= max_specpdl_size)
2574 if (max_specpdl_size < 400)
2575 max_specpdl_size = 400;
2576 if (specpdl_size >= max_specpdl_size)
2578 if (!NILP (Vdebug_on_error))
2579 /* Leave room for some specpdl in the debugger. */
2580 max_specpdl_size = specpdl_size + 100;
2581 Fsignal (Qerror,
2582 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil));
2585 specpdl_size *= 2;
2586 if (specpdl_size > max_specpdl_size)
2587 specpdl_size = max_specpdl_size;
2588 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
2589 specpdl_ptr = specpdl + count;
2592 void
2593 specbind (symbol, value)
2594 Lisp_Object symbol, value;
2596 Lisp_Object ovalue;
2598 CHECK_SYMBOL (symbol, 0);
2600 if (specpdl_ptr == specpdl + specpdl_size)
2601 grow_specpdl ();
2602 specpdl_ptr->symbol = symbol;
2603 specpdl_ptr->func = 0;
2604 specpdl_ptr->old_value = ovalue = find_symbol_value (symbol);
2605 specpdl_ptr++;
2606 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
2607 store_symval_forwarding (symbol, ovalue, value);
2608 else
2609 Fset (symbol, value);
2612 void
2613 record_unwind_protect (function, arg)
2614 Lisp_Object (*function)();
2615 Lisp_Object arg;
2617 if (specpdl_ptr == specpdl + specpdl_size)
2618 grow_specpdl ();
2619 specpdl_ptr->func = function;
2620 specpdl_ptr->symbol = Qnil;
2621 specpdl_ptr->old_value = arg;
2622 specpdl_ptr++;
2625 Lisp_Object
2626 unbind_to (count, value)
2627 int count;
2628 Lisp_Object value;
2630 int quitf = !NILP (Vquit_flag);
2631 struct gcpro gcpro1;
2633 GCPRO1 (value);
2635 Vquit_flag = Qnil;
2637 while (specpdl_ptr != specpdl + count)
2639 --specpdl_ptr;
2640 if (specpdl_ptr->func != 0)
2641 (*specpdl_ptr->func) (specpdl_ptr->old_value);
2642 /* Note that a "binding" of nil is really an unwind protect,
2643 so in that case the "old value" is a list of forms to evaluate. */
2644 else if (NILP (specpdl_ptr->symbol))
2645 Fprogn (specpdl_ptr->old_value);
2646 else
2647 Fset (specpdl_ptr->symbol, specpdl_ptr->old_value);
2649 if (NILP (Vquit_flag) && quitf) Vquit_flag = Qt;
2651 UNGCPRO;
2653 return value;
2656 #if 0
2658 /* Get the value of symbol's global binding, even if that binding
2659 is not now dynamically visible. */
2661 Lisp_Object
2662 top_level_value (symbol)
2663 Lisp_Object symbol;
2665 register struct specbinding *ptr = specpdl;
2667 CHECK_SYMBOL (symbol, 0);
2668 for (; ptr != specpdl_ptr; ptr++)
2670 if (EQ (ptr->symbol, symbol))
2671 return ptr->old_value;
2673 return Fsymbol_value (symbol);
2676 Lisp_Object
2677 top_level_set (symbol, newval)
2678 Lisp_Object symbol, newval;
2680 register struct specbinding *ptr = specpdl;
2682 CHECK_SYMBOL (symbol, 0);
2683 for (; ptr != specpdl_ptr; ptr++)
2685 if (EQ (ptr->symbol, symbol))
2687 ptr->old_value = newval;
2688 return newval;
2691 return Fset (symbol, newval);
2694 #endif /* 0 */
2696 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
2697 "Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.\n\
2698 The debugger is entered when that frame exits, if the flag is non-nil.")
2699 (level, flag)
2700 Lisp_Object level, flag;
2702 register struct backtrace *backlist = backtrace_list;
2703 register int i;
2705 CHECK_NUMBER (level, 0);
2707 for (i = 0; backlist && i < XINT (level); i++)
2709 backlist = backlist->next;
2712 if (backlist)
2713 backlist->debug_on_exit = !NILP (flag);
2715 return flag;
2718 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
2719 "Print a trace of Lisp function calls currently active.\n\
2720 Output stream used is value of `standard-output'.")
2723 register struct backtrace *backlist = backtrace_list;
2724 register int i;
2725 Lisp_Object tail;
2726 Lisp_Object tem;
2727 extern Lisp_Object Vprint_level;
2728 struct gcpro gcpro1;
2730 XSETFASTINT (Vprint_level, 3);
2732 tail = Qnil;
2733 GCPRO1 (tail);
2735 while (backlist)
2737 write_string (backlist->debug_on_exit ? "* " : " ", 2);
2738 if (backlist->nargs == UNEVALLED)
2740 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
2741 write_string ("\n", -1);
2743 else
2745 tem = *backlist->function;
2746 Fprin1 (tem, Qnil); /* This can QUIT */
2747 write_string ("(", -1);
2748 if (backlist->nargs == MANY)
2750 for (tail = *backlist->args, i = 0;
2751 !NILP (tail);
2752 tail = Fcdr (tail), i++)
2754 if (i) write_string (" ", -1);
2755 Fprin1 (Fcar (tail), Qnil);
2758 else
2760 for (i = 0; i < backlist->nargs; i++)
2762 if (i) write_string (" ", -1);
2763 Fprin1 (backlist->args[i], Qnil);
2766 write_string (")\n", -1);
2768 backlist = backlist->next;
2771 Vprint_level = Qnil;
2772 UNGCPRO;
2773 return Qnil;
2776 DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, "",
2777 "Return the function and arguments NFRAMES up from current execution point.\n\
2778 If that frame has not evaluated the arguments yet (or is a special form),\n\
2779 the value is (nil FUNCTION ARG-FORMS...).\n\
2780 If that frame has evaluated its arguments and called its function already,\n\
2781 the value is (t FUNCTION ARG-VALUES...).\n\
2782 A &rest arg is represented as the tail of the list ARG-VALUES.\n\
2783 FUNCTION is whatever was supplied as car of evaluated list,\n\
2784 or a lambda expression for macro calls.\n\
2785 If NFRAMES is more than the number of frames, the value is nil.")
2786 (nframes)
2787 Lisp_Object nframes;
2789 register struct backtrace *backlist = backtrace_list;
2790 register int i;
2791 Lisp_Object tem;
2793 CHECK_NATNUM (nframes, 0);
2795 /* Find the frame requested. */
2796 for (i = 0; backlist && i < XFASTINT (nframes); i++)
2797 backlist = backlist->next;
2799 if (!backlist)
2800 return Qnil;
2801 if (backlist->nargs == UNEVALLED)
2802 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
2803 else
2805 if (backlist->nargs == MANY)
2806 tem = *backlist->args;
2807 else
2808 tem = Flist (backlist->nargs, backlist->args);
2810 return Fcons (Qt, Fcons (*backlist->function, tem));
2814 syms_of_eval ()
2816 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
2817 "Limit on number of Lisp variable bindings & unwind-protects before error.");
2819 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
2820 "Limit on depth in `eval', `apply' and `funcall' before error.\n\
2821 This limit is to catch infinite recursions for you before they cause\n\
2822 actual stack overflow in C, which would be fatal for Emacs.\n\
2823 You can safely make it considerably larger than its default value,\n\
2824 if that proves inconveniently small.");
2826 DEFVAR_LISP ("quit-flag", &Vquit_flag,
2827 "Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.\n\
2828 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'.");
2829 Vquit_flag = Qnil;
2831 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
2832 "Non-nil inhibits C-g quitting from happening immediately.\n\
2833 Note that `quit-flag' will still be set by typing C-g,\n\
2834 so a quit will be signaled as soon as `inhibit-quit' is nil.\n\
2835 To prevent this happening, set `quit-flag' to nil\n\
2836 before making `inhibit-quit' nil.");
2837 Vinhibit_quit = Qnil;
2839 Qinhibit_quit = intern ("inhibit-quit");
2840 staticpro (&Qinhibit_quit);
2842 Qautoload = intern ("autoload");
2843 staticpro (&Qautoload);
2845 Qdebug_on_error = intern ("debug-on-error");
2846 staticpro (&Qdebug_on_error);
2848 Qmacro = intern ("macro");
2849 staticpro (&Qmacro);
2851 /* Note that the process handling also uses Qexit, but we don't want
2852 to staticpro it twice, so we just do it here. */
2853 Qexit = intern ("exit");
2854 staticpro (&Qexit);
2856 Qinteractive = intern ("interactive");
2857 staticpro (&Qinteractive);
2859 Qcommandp = intern ("commandp");
2860 staticpro (&Qcommandp);
2862 Qdefun = intern ("defun");
2863 staticpro (&Qdefun);
2865 Qand_rest = intern ("&rest");
2866 staticpro (&Qand_rest);
2868 Qand_optional = intern ("&optional");
2869 staticpro (&Qand_optional);
2871 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
2872 "*Non-nil means automatically display a backtrace buffer\n\
2873 after any error that is handled by the editor command loop.\n\
2874 If the value is a list, an error only means to display a backtrace\n\
2875 if one of its condition symbols appears in the list.");
2876 Vstack_trace_on_error = Qnil;
2878 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
2879 "*Non-nil means enter debugger if an error is signaled.\n\
2880 Does not apply to errors handled by `condition-case'.\n\
2881 If the value is a list, an error only means to enter the debugger\n\
2882 if one of its condition symbols appears in the list.\n\
2883 See also variable `debug-on-quit'.");
2884 Vdebug_on_error = Qnil;
2886 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors,
2887 "*List of errors for which the debugger should not be called.\n\
2888 Each element may be a condition-name or a regexp that matches error messages.\n\
2889 If any element applies to a given error, that error skips the debugger\n\
2890 and just returns to top level.\n\
2891 This overrides the variable `debug-on-error'.\n\
2892 It does not apply to errors handled by `condition-case'.");
2893 Vdebug_ignored_errors = Qnil;
2895 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
2896 "*Non-nil means enter debugger if quit is signaled (C-g, for example).\n\
2897 Does not apply if quit is handled by a `condition-case'.");
2898 debug_on_quit = 0;
2900 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
2901 "Non-nil means enter debugger before next `eval', `apply' or `funcall'.");
2903 DEFVAR_LISP ("debugger", &Vdebugger,
2904 "Function to call to invoke debugger.\n\
2905 If due to frame exit, args are `exit' and the value being returned;\n\
2906 this function's value will be returned instead of that.\n\
2907 If due to error, args are `error' and a list of the args to `signal'.\n\
2908 If due to `apply' or `funcall' entry, one arg, `lambda'.\n\
2909 If due to `eval' entry, one arg, t.");
2910 Vdebugger = Qnil;
2912 Qmocklisp_arguments = intern ("mocklisp-arguments");
2913 staticpro (&Qmocklisp_arguments);
2914 DEFVAR_LISP ("mocklisp-arguments", &Vmocklisp_arguments,
2915 "While in a mocklisp function, the list of its unevaluated args.");
2916 Vmocklisp_arguments = Qt;
2918 DEFVAR_LISP ("run-hooks", &Vrun_hooks,
2919 "Set to the function `run-hooks', if that function has been defined.\n\
2920 Otherwise, nil (in a bare Emacs without preloaded Lisp code).");
2922 staticpro (&Vautoload_queue);
2923 Vautoload_queue = Qnil;
2925 defsubr (&Sor);
2926 defsubr (&Sand);
2927 defsubr (&Sif);
2928 defsubr (&Scond);
2929 defsubr (&Sprogn);
2930 defsubr (&Sprog1);
2931 defsubr (&Sprog2);
2932 defsubr (&Ssetq);
2933 defsubr (&Squote);
2934 defsubr (&Sfunction);
2935 defsubr (&Sdefun);
2936 defsubr (&Sdefmacro);
2937 defsubr (&Sdefvar);
2938 defsubr (&Sdefconst);
2939 defsubr (&Suser_variable_p);
2940 defsubr (&Slet);
2941 defsubr (&SletX);
2942 defsubr (&Swhile);
2943 defsubr (&Smacroexpand);
2944 defsubr (&Scatch);
2945 defsubr (&Sthrow);
2946 defsubr (&Sunwind_protect);
2947 defsubr (&Scondition_case);
2948 defsubr (&Ssignal);
2949 defsubr (&Sinteractive_p);
2950 defsubr (&Scommandp);
2951 defsubr (&Sautoload);
2952 defsubr (&Seval);
2953 defsubr (&Sapply);
2954 defsubr (&Sfuncall);
2955 defsubr (&Srun_hooks);
2956 defsubr (&Srun_hook_with_args);
2957 defsubr (&Srun_hook_with_args_until_success);
2958 defsubr (&Srun_hook_with_args_until_failure);
2959 defsubr (&Sfetch_bytecode);
2960 defsubr (&Sbacktrace_debug);
2961 defsubr (&Sbacktrace);
2962 defsubr (&Sbacktrace_frame);