Use AC_SET_MAKE.
[bpt/emacs.git] / src / eval.c
CommitLineData
db9f0278 1/* Evaluator for GNU Emacs Lisp interpreter.
c6c5df7f 2 Copyright (C) 1985, 1986, 1987, 1993 Free Software Foundation, Inc.
db9f0278
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
18160b98 21#include <config.h>
db9f0278 22#include "lisp.h"
9ac0d9e0 23#include "blockinput.h"
db9f0278
JB
24
25#ifndef standalone
26#include "commands.h"
1f98fa48 27#include "keyboard.h"
db9f0278
JB
28#else
29#define INTERACTIVE 1
30#endif
31
32#include <setjmp.h>
33
34/* This definition is duplicated in alloc.c and keyboard.c */
35/* Putting it in lisp.h makes cc bomb out! */
36
37struct backtrace
38 {
39 struct backtrace *next;
40 Lisp_Object *function;
41 Lisp_Object *args; /* Points to vector of args. */
daa37602
JB
42 int nargs; /* Length of vector.
43 If nargs is UNEVALLED, args points to slot holding
44 list of unevalled args */
db9f0278
JB
45 char evalargs;
46 /* Nonzero means call value of debugger when done with this operation. */
47 char debug_on_exit;
48 };
49
50struct backtrace *backtrace_list;
51
82da7701
JB
52/* This structure helps implement the `catch' and `throw' control
53 structure. A struct catchtag contains all the information needed
54 to restore the state of the interpreter after a non-local jump.
55
56 Handlers for error conditions (represented by `struct handler'
57 structures) just point to a catch tag to do the cleanup required
58 for their jumps.
59
60 catchtag structures are chained together in the C calling stack;
61 the `next' member points to the next outer catchtag.
62
63 A call like (throw TAG VAL) searches for a catchtag whose `tag'
64 member is TAG, and then unbinds to it. The `val' member is used to
65 hold VAL while the stack is unwound; `val' is returned as the value
66 of the catch form.
67
68 All the other members are concerned with restoring the interpreter
69 state. */
db9f0278
JB
70struct catchtag
71 {
72 Lisp_Object tag;
73 Lisp_Object val;
74 struct catchtag *next;
75 struct gcpro *gcpro;
76 jmp_buf jmp;
77 struct backtrace *backlist;
78 struct handler *handlerlist;
79 int lisp_eval_depth;
80 int pdlcount;
81 int poll_suppress_count;
82 };
83
84struct catchtag *catchlist;
85
86Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
ad236261 87Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag;
db9f0278
JB
88Lisp_Object Qmocklisp_arguments, Vmocklisp_arguments, Qmocklisp;
89Lisp_Object Qand_rest, Qand_optional;
90Lisp_Object Qdebug_on_error;
91
92Lisp_Object Vrun_hooks;
93
94/* Non-nil means record all fset's and provide's, to be undone
95 if the file being autoloaded is not fully loaded.
96 They are recorded by being consed onto the front of Vautoload_queue:
97 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
98
99Lisp_Object Vautoload_queue;
100
101/* Current number of specbindings allocated in specpdl. */
102int specpdl_size;
103
104/* Pointer to beginning of specpdl. */
105struct specbinding *specpdl;
106
107/* Pointer to first unused element in specpdl. */
108struct specbinding *specpdl_ptr;
109
110/* Maximum size allowed for specpdl allocation */
111int max_specpdl_size;
112
113/* Depth in Lisp evaluations and function calls. */
114int lisp_eval_depth;
115
116/* Maximum allowed depth in Lisp evaluations and function calls. */
117int max_lisp_eval_depth;
118
119/* Nonzero means enter debugger before next function call */
120int debug_on_next_call;
121
128c0f66 122/* List of conditions (non-nil atom means all) which cause a backtrace
4de86b16 123 if an error is handled by the command loop's error handler. */
128c0f66 124Lisp_Object Vstack_trace_on_error;
db9f0278 125
128c0f66 126/* List of conditions (non-nil atom means all) which enter the debugger
4de86b16 127 if an error is handled by the command loop's error handler. */
128c0f66 128Lisp_Object Vdebug_on_error;
db9f0278
JB
129
130/* Nonzero means enter debugger if a quit signal
128c0f66 131 is handled by the command loop's error handler. */
db9f0278
JB
132int debug_on_quit;
133
82da7701
JB
134/* The value of num_nonmacro_input_chars as of the last time we
135 started to enter the debugger. If we decide to enter the debugger
136 again when this is still equal to num_nonmacro_input_chars, then we
137 know that the debugger itself has an error, and we should just
138 signal the error instead of entering an infinite loop of debugger
139 invocations. */
140int when_entered_debugger;
db9f0278
JB
141
142Lisp_Object Vdebugger;
143
144void specbind (), record_unwind_protect ();
145
146Lisp_Object funcall_lambda ();
147extern Lisp_Object ml_apply (); /* Apply a mocklisp function to unevaluated argument list */
148
149init_eval_once ()
150{
151 specpdl_size = 50;
152 specpdl = (struct specbinding *) malloc (specpdl_size * sizeof (struct specbinding));
153 max_specpdl_size = 600;
154 max_lisp_eval_depth = 200;
155}
156
157init_eval ()
158{
159 specpdl_ptr = specpdl;
160 catchlist = 0;
161 handlerlist = 0;
162 backtrace_list = 0;
163 Vquit_flag = Qnil;
164 debug_on_next_call = 0;
165 lisp_eval_depth = 0;
82da7701 166 when_entered_debugger = 0;
db9f0278
JB
167}
168
169Lisp_Object
170call_debugger (arg)
171 Lisp_Object arg;
172{
173 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
174 max_lisp_eval_depth = lisp_eval_depth + 20;
175 if (specpdl_size + 40 > max_specpdl_size)
176 max_specpdl_size = specpdl_size + 40;
177 debug_on_next_call = 0;
82da7701 178 when_entered_debugger = num_nonmacro_input_chars;
db9f0278
JB
179 return apply1 (Vdebugger, arg);
180}
181
182do_debug_on_call (code)
183 Lisp_Object code;
184{
185 debug_on_next_call = 0;
186 backtrace_list->debug_on_exit = 1;
187 call_debugger (Fcons (code, Qnil));
188}
189\f
190/* NOTE!!! Every function that can call EVAL must protect its args
191 and temporaries from garbage collection while it needs them.
192 The definition of `For' shows what you have to do. */
193
194DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
195 "Eval args until one of them yields non-nil, then return that value.\n\
196The remaining args are not evalled at all.\n\
197If all args return nil, return nil.")
198 (args)
199 Lisp_Object args;
200{
201 register Lisp_Object val;
202 Lisp_Object args_left;
203 struct gcpro gcpro1;
204
265a9e55 205 if (NILP(args))
db9f0278
JB
206 return Qnil;
207
208 args_left = args;
209 GCPRO1 (args_left);
210
211 do
212 {
213 val = Feval (Fcar (args_left));
265a9e55 214 if (!NILP (val))
db9f0278
JB
215 break;
216 args_left = Fcdr (args_left);
217 }
265a9e55 218 while (!NILP(args_left));
db9f0278
JB
219
220 UNGCPRO;
221 return val;
222}
223
224DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
225 "Eval args until one of them yields nil, then return nil.\n\
226The remaining args are not evalled at all.\n\
227If no arg yields nil, return the last arg's value.")
228 (args)
229 Lisp_Object args;
230{
231 register Lisp_Object val;
232 Lisp_Object args_left;
233 struct gcpro gcpro1;
234
265a9e55 235 if (NILP(args))
db9f0278
JB
236 return Qt;
237
238 args_left = args;
239 GCPRO1 (args_left);
240
241 do
242 {
243 val = Feval (Fcar (args_left));
265a9e55 244 if (NILP (val))
db9f0278
JB
245 break;
246 args_left = Fcdr (args_left);
247 }
265a9e55 248 while (!NILP(args_left));
db9f0278
JB
249
250 UNGCPRO;
251 return val;
252}
253
254DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
255 "(if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE...\n\
256Returns the value of THEN or the value of the last of the ELSE's.\n\
257THEN must be one expression, but ELSE... can be zero or more expressions.\n\
258If COND yields nil, and there are no ELSE's, the value is nil.")
259 (args)
260 Lisp_Object args;
261{
262 register Lisp_Object cond;
263 struct gcpro gcpro1;
264
265 GCPRO1 (args);
266 cond = Feval (Fcar (args));
267 UNGCPRO;
268
265a9e55 269 if (!NILP (cond))
db9f0278
JB
270 return Feval (Fcar (Fcdr (args)));
271 return Fprogn (Fcdr (Fcdr (args)));
272}
273
274DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
275 "(cond CLAUSES...): try each clause until one succeeds.\n\
276Each clause looks like (CONDITION BODY...). CONDITION is evaluated\n\
277and, if the value is non-nil, this clause succeeds:\n\
278then the expressions in BODY are evaluated and the last one's\n\
279value is the value of the cond-form.\n\
280If no clause succeeds, cond returns nil.\n\
281If a clause has one element, as in (CONDITION),\n\
282CONDITION's value if non-nil is returned from the cond-form.")
283 (args)
284 Lisp_Object args;
285{
286 register Lisp_Object clause, val;
287 struct gcpro gcpro1;
288
289 val = Qnil;
290 GCPRO1 (args);
265a9e55 291 while (!NILP (args))
db9f0278
JB
292 {
293 clause = Fcar (args);
294 val = Feval (Fcar (clause));
265a9e55 295 if (!NILP (val))
db9f0278
JB
296 {
297 if (!EQ (XCONS (clause)->cdr, Qnil))
298 val = Fprogn (XCONS (clause)->cdr);
299 break;
300 }
301 args = XCONS (args)->cdr;
302 }
303 UNGCPRO;
304
305 return val;
306}
307
308DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
309 "(progn BODY...): eval BODY forms sequentially and return value of last one.")
310 (args)
311 Lisp_Object args;
312{
313 register Lisp_Object val, tem;
314 Lisp_Object args_left;
315 struct gcpro gcpro1;
316
317 /* In Mocklisp code, symbols at the front of the progn arglist
318 are to be bound to zero. */
319 if (!EQ (Vmocklisp_arguments, Qt))
320 {
321 val = make_number (0);
265a9e55 322 while (!NILP (args) && (tem = Fcar (args), XTYPE (tem) == Lisp_Symbol))
db9f0278
JB
323 {
324 QUIT;
325 specbind (tem, val), args = Fcdr (args);
326 }
327 }
328
265a9e55 329 if (NILP(args))
db9f0278
JB
330 return Qnil;
331
332 args_left = args;
333 GCPRO1 (args_left);
334
335 do
336 {
337 val = Feval (Fcar (args_left));
338 args_left = Fcdr (args_left);
339 }
265a9e55 340 while (!NILP(args_left));
db9f0278
JB
341
342 UNGCPRO;
343 return val;
344}
345
346DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
347 "(prog1 FIRST BODY...): eval FIRST and BODY sequentially; value from FIRST.\n\
348The value of FIRST is saved during the evaluation of the remaining args,\n\
349whose values are discarded.")
350 (args)
351 Lisp_Object args;
352{
353 Lisp_Object val;
354 register Lisp_Object args_left;
355 struct gcpro gcpro1, gcpro2;
356 register int argnum = 0;
357
265a9e55 358 if (NILP(args))
db9f0278
JB
359 return Qnil;
360
361 args_left = args;
362 val = Qnil;
363 GCPRO2 (args, val);
364
365 do
366 {
367 if (!(argnum++))
368 val = Feval (Fcar (args_left));
369 else
370 Feval (Fcar (args_left));
371 args_left = Fcdr (args_left);
372 }
265a9e55 373 while (!NILP(args_left));
db9f0278
JB
374
375 UNGCPRO;
376 return val;
377}
378
379DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
380 "(prog1 X Y BODY...): eval X, Y and BODY sequentially; value from Y.\n\
381The value of Y is saved during the evaluation of the remaining args,\n\
382whose values are discarded.")
383 (args)
384 Lisp_Object args;
385{
386 Lisp_Object val;
387 register Lisp_Object args_left;
388 struct gcpro gcpro1, gcpro2;
389 register int argnum = -1;
390
391 val = Qnil;
392
87d238ba 393 if (NILP (args))
db9f0278
JB
394 return Qnil;
395
396 args_left = args;
397 val = Qnil;
398 GCPRO2 (args, val);
399
400 do
401 {
402 if (!(argnum++))
403 val = Feval (Fcar (args_left));
404 else
405 Feval (Fcar (args_left));
406 args_left = Fcdr (args_left);
407 }
87d238ba 408 while (!NILP (args_left));
db9f0278
JB
409
410 UNGCPRO;
411 return val;
412}
413
414DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
415 "(setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL.\n\
416The SYMs are not evaluated. Thus (setq x y) sets x to the value of y.\n\
87d238ba 417Each SYM is set before the next VAL is computed.\n\
196e7d3f 418The return value of the `setq' form is the value of the last VAL.")
db9f0278
JB
419 (args)
420 Lisp_Object args;
421{
422 register Lisp_Object args_left;
423 register Lisp_Object val, sym;
424 struct gcpro gcpro1;
425
265a9e55 426 if (NILP(args))
db9f0278
JB
427 return Qnil;
428
429 args_left = args;
430 GCPRO1 (args);
431
432 do
433 {
434 val = Feval (Fcar (Fcdr (args_left)));
435 sym = Fcar (args_left);
436 Fset (sym, val);
437 args_left = Fcdr (Fcdr (args_left));
438 }
265a9e55 439 while (!NILP(args_left));
db9f0278
JB
440
441 UNGCPRO;
442 return val;
443}
444
445DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
446 "Return the argument, without evaluating it. `(quote x)' yields `x'.")
447 (args)
448 Lisp_Object args;
449{
450 return Fcar (args);
451}
452
453DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
454 "Like `quote', but preferred for objects which are functions.\n\
455In byte compilation, `function' causes its argument to be compiled.\n\
456`quote' cannot do that.")
457 (args)
458 Lisp_Object args;
459{
460 return Fcar (args);
461}
462
463DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
464 "Return t if function in which this appears was called interactively.\n\
465This means that the function was called with call-interactively (which\n\
466includes being called as the binding of a key)\n\
467and input is currently coming from the keyboard (not in keyboard macro).")
468 ()
469{
470 register struct backtrace *btp;
471 register Lisp_Object fun;
472
473 if (!INTERACTIVE)
474 return Qnil;
475
db9f0278 476 btp = backtrace_list;
daa37602
JB
477
478 /* If this isn't a byte-compiled function, there may be a frame at
479 the top for Finteractive_p itself. If so, skip it. */
480 fun = Findirect_function (*btp->function);
481 if (XTYPE (fun) == Lisp_Subr
482 && (struct Lisp_Subr *) XPNTR (fun) == &Sinteractive_p)
db9f0278 483 btp = btp->next;
daa37602
JB
484
485 /* If we're running an Emacs 18-style byte-compiled function, there
486 may be a frame for Fbytecode. Now, given the strictest
487 definition, this function isn't really being called
488 interactively, but because that's the way Emacs 18 always builds
489 byte-compiled functions, we'll accept it for now. */
490 if (EQ (*btp->function, Qbytecode))
491 btp = btp->next;
492
493 /* If this isn't a byte-compiled function, then we may now be
494 looking at several frames for special forms. Skip past them. */
495 while (btp &&
496 btp->nargs == UNEVALLED)
a6e3fa71
JB
497 btp = btp->next;
498
daa37602
JB
499 /* btp now points at the frame of the innermost function that isn't
500 a special form, ignoring frames for Finteractive_p and/or
501 Fbytecode at the top. If this frame is for a built-in function
502 (such as load or eval-region) return nil. */
ffd56f97 503 fun = Findirect_function (*btp->function);
db9f0278
JB
504 if (XTYPE (fun) == Lisp_Subr)
505 return Qnil;
506 /* btp points to the frame of a Lisp function that called interactive-p.
507 Return t if that function was called interactively. */
508 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
509 return Qt;
510 return Qnil;
511}
512
513DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
514 "(defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.\n\
515The definition is (lambda ARGLIST [DOCSTRING] BODY...).\n\
516See also the function `interactive'.")
517 (args)
518 Lisp_Object args;
519{
520 register Lisp_Object fn_name;
521 register Lisp_Object defn;
522
523 fn_name = Fcar (args);
524 defn = Fcons (Qlambda, Fcdr (args));
265a9e55 525 if (!NILP (Vpurify_flag))
db9f0278
JB
526 defn = Fpurecopy (defn);
527 Ffset (fn_name, defn);
2a49b6e5 528 LOADHIST_ATTACH (fn_name);
db9f0278
JB
529 return fn_name;
530}
531
532DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
533 "(defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.\n\
534The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).\n\
535When the macro is called, as in (NAME ARGS...),\n\
536the function (lambda ARGLIST BODY...) is applied to\n\
537the list ARGS... as it appears in the expression,\n\
538and the result should be a form to be evaluated instead of the original.")
539 (args)
540 Lisp_Object args;
541{
542 register Lisp_Object fn_name;
543 register Lisp_Object defn;
544
545 fn_name = Fcar (args);
546 defn = Fcons (Qmacro, Fcons (Qlambda, Fcdr (args)));
265a9e55 547 if (!NILP (Vpurify_flag))
db9f0278
JB
548 defn = Fpurecopy (defn);
549 Ffset (fn_name, defn);
2a49b6e5 550 LOADHIST_ATTACH (fn_name);
db9f0278
JB
551 return fn_name;
552}
553
554DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
555 "(defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable.\n\
556You are not required to define a variable in order to use it,\n\
557but the definition can supply documentation and an initial value\n\
558in a way that tags can recognize.\n\n\
559INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.\n\
06ef7355
RS
560If SYMBOL is buffer-local, its default value is what is set;\n\
561 buffer-local values are not affected.\n\
db9f0278
JB
562INITVALUE and DOCSTRING are optional.\n\
563If DOCSTRING starts with *, this variable is identified as a user option.\n\
564 This means that M-x set-variable and M-x edit-options recognize it.\n\
565If INITVALUE is missing, SYMBOL's value is not set.")
566 (args)
567 Lisp_Object args;
568{
569 register Lisp_Object sym, tem;
570
571 sym = Fcar (args);
572 tem = Fcdr (args);
265a9e55 573 if (!NILP (tem))
db9f0278
JB
574 {
575 tem = Fdefault_boundp (sym);
265a9e55 576 if (NILP (tem))
db9f0278
JB
577 Fset_default (sym, Feval (Fcar (Fcdr (args))));
578 }
579 tem = Fcar (Fcdr (Fcdr (args)));
265a9e55 580 if (!NILP (tem))
db9f0278 581 {
265a9e55 582 if (!NILP (Vpurify_flag))
db9f0278
JB
583 tem = Fpurecopy (tem);
584 Fput (sym, Qvariable_documentation, tem);
585 }
2a49b6e5 586 LOADHIST_ATTACH (sym);
db9f0278
JB
587 return sym;
588}
589
590DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
591 "(defconst SYMBOL INITVALUE DOCSTRING): define SYMBOL as a constant variable.\n\
592The intent is that programs do not change this value, but users may.\n\
593Always sets the value of SYMBOL to the result of evalling INITVALUE.\n\
06ef7355
RS
594If SYMBOL is buffer-local, its default value is what is set;\n\
595 buffer-local values are not affected.\n\
db9f0278
JB
596DOCSTRING is optional.\n\
597If DOCSTRING starts with *, this variable is identified as a user option.\n\
598 This means that M-x set-variable and M-x edit-options recognize it.\n\n\
599Note: do not use `defconst' for user options in libraries that are not\n\
600normally loaded, since it is useful for users to be able to specify\n\
601their own values for such variables before loading the library.\n\
602Since `defconst' unconditionally assigns the variable,\n\
603it would override the user's choice.")
604 (args)
605 Lisp_Object args;
606{
607 register Lisp_Object sym, tem;
608
609 sym = Fcar (args);
610 Fset_default (sym, Feval (Fcar (Fcdr (args))));
611 tem = Fcar (Fcdr (Fcdr (args)));
265a9e55 612 if (!NILP (tem))
db9f0278 613 {
265a9e55 614 if (!NILP (Vpurify_flag))
db9f0278
JB
615 tem = Fpurecopy (tem);
616 Fput (sym, Qvariable_documentation, tem);
617 }
2a49b6e5 618 LOADHIST_ATTACH (sym);
db9f0278
JB
619 return sym;
620}
621
622DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
623 "Returns t if VARIABLE is intended to be set and modified by users.\n\
624\(The alternative is a variable used internally in a Lisp program.)\n\
625Determined by whether the first character of the documentation\n\
626for the variable is \"*\"")
627 (variable)
628 Lisp_Object variable;
629{
630 Lisp_Object documentation;
631
632 documentation = Fget (variable, Qvariable_documentation);
633 if (XTYPE (documentation) == Lisp_Int && XINT (documentation) < 0)
634 return Qt;
635 if ((XTYPE (documentation) == Lisp_String) &&
636 ((unsigned char) XSTRING (documentation)->data[0] == '*'))
637 return Qt;
638 return Qnil;
639}
640\f
641DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
642 "(let* VARLIST BODY...): bind variables according to VARLIST then eval BODY.\n\
643The value of the last form in BODY is returned.\n\
644Each element of VARLIST is a symbol (which is bound to nil)\n\
645or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\
646Each VALUEFORM can refer to the symbols already bound by this VARLIST.")
647 (args)
648 Lisp_Object args;
649{
650 Lisp_Object varlist, val, elt;
651 int count = specpdl_ptr - specpdl;
652 struct gcpro gcpro1, gcpro2, gcpro3;
653
654 GCPRO3 (args, elt, varlist);
655
656 varlist = Fcar (args);
265a9e55 657 while (!NILP (varlist))
db9f0278
JB
658 {
659 QUIT;
660 elt = Fcar (varlist);
661 if (XTYPE (elt) == Lisp_Symbol)
662 specbind (elt, Qnil);
08564963
JB
663 else if (! NILP (Fcdr (Fcdr (elt))))
664 Fsignal (Qerror,
665 Fcons (build_string ("`let' bindings can have only one value-form"),
666 elt));
db9f0278
JB
667 else
668 {
669 val = Feval (Fcar (Fcdr (elt)));
670 specbind (Fcar (elt), val);
671 }
672 varlist = Fcdr (varlist);
673 }
674 UNGCPRO;
675 val = Fprogn (Fcdr (args));
676 return unbind_to (count, val);
677}
678
679DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
680 "(let VARLIST BODY...): bind variables according to VARLIST then eval BODY.\n\
681The value of the last form in BODY is returned.\n\
682Each element of VARLIST is a symbol (which is bound to nil)\n\
683or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\
684All the VALUEFORMs are evalled before any symbols are bound.")
685 (args)
686 Lisp_Object args;
687{
688 Lisp_Object *temps, tem;
689 register Lisp_Object elt, varlist;
690 int count = specpdl_ptr - specpdl;
691 register int argnum;
692 struct gcpro gcpro1, gcpro2;
693
694 varlist = Fcar (args);
695
696 /* Make space to hold the values to give the bound variables */
697 elt = Flength (varlist);
698 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object));
699
700 /* Compute the values and store them in `temps' */
701
702 GCPRO2 (args, *temps);
703 gcpro2.nvars = 0;
704
265a9e55 705 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
db9f0278
JB
706 {
707 QUIT;
708 elt = Fcar (varlist);
709 if (XTYPE (elt) == Lisp_Symbol)
710 temps [argnum++] = Qnil;
08564963
JB
711 else if (! NILP (Fcdr (Fcdr (elt))))
712 Fsignal (Qerror,
713 Fcons (build_string ("`let' bindings can have only one value-form"),
714 elt));
db9f0278
JB
715 else
716 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
717 gcpro2.nvars = argnum;
718 }
719 UNGCPRO;
720
721 varlist = Fcar (args);
265a9e55 722 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
db9f0278
JB
723 {
724 elt = Fcar (varlist);
725 tem = temps[argnum++];
726 if (XTYPE (elt) == Lisp_Symbol)
727 specbind (elt, tem);
728 else
729 specbind (Fcar (elt), tem);
730 }
731
732 elt = Fprogn (Fcdr (args));
733 return unbind_to (count, elt);
734}
735
736DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
737 "(while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat.\n\
738The order of execution is thus TEST, BODY, TEST, BODY and so on\n\
739until TEST returns nil.")
740 (args)
741 Lisp_Object args;
742{
743 Lisp_Object test, body, tem;
744 struct gcpro gcpro1, gcpro2;
745
746 GCPRO2 (test, body);
747
748 test = Fcar (args);
749 body = Fcdr (args);
e3c24a74
RS
750 while (tem = Feval (test),
751 (!EQ (Vmocklisp_arguments, Qt) ? XINT (tem) : !NILP (tem)))
db9f0278
JB
752 {
753 QUIT;
754 Fprogn (body);
755 }
756
757 UNGCPRO;
758 return Qnil;
759}
760
761DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
762 "Return result of expanding macros at top level of FORM.\n\
763If FORM is not a macro call, it is returned unchanged.\n\
764Otherwise, the macro is expanded and the expansion is considered\n\
765in place of FORM. When a non-macro-call results, it is returned.\n\n\
766The second optional arg ENVIRONMENT species an environment of macro\n\
767definitions to shadow the loaded ones for use in file byte-compilation.")
768 (form, env)
769 register Lisp_Object form;
770 Lisp_Object env;
771{
23d6b5a6 772 /* With cleanups from Hallvard Furuseth. */
db9f0278
JB
773 register Lisp_Object expander, sym, def, tem;
774
775 while (1)
776 {
777 /* Come back here each time we expand a macro call,
778 in case it expands into another macro call. */
779 if (XTYPE (form) != Lisp_Cons)
780 break;
23d6b5a6
JB
781 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
782 def = sym = XCONS (form)->car;
783 tem = Qnil;
db9f0278
JB
784 /* Trace symbols aliases to other symbols
785 until we get a symbol that is not an alias. */
23d6b5a6 786 while (XTYPE (def) == Lisp_Symbol)
db9f0278
JB
787 {
788 QUIT;
23d6b5a6 789 sym = def;
db9f0278 790 tem = Fassq (sym, env);
265a9e55 791 if (NILP (tem))
db9f0278
JB
792 {
793 def = XSYMBOL (sym)->function;
23d6b5a6
JB
794 if (!EQ (def, Qunbound))
795 continue;
db9f0278 796 }
23d6b5a6 797 break;
db9f0278
JB
798 }
799 /* Right now TEM is the result from SYM in ENV,
800 and if TEM is nil then DEF is SYM's function definition. */
265a9e55 801 if (NILP (tem))
db9f0278
JB
802 {
803 /* SYM is not mentioned in ENV.
804 Look at its function definition. */
805 if (EQ (def, Qunbound)
806 || XTYPE (def) != Lisp_Cons)
807 /* Not defined or definition not suitable */
808 break;
809 if (EQ (XCONS (def)->car, Qautoload))
810 {
811 /* Autoloading function: will it be a macro when loaded? */
ee9ee63c 812 tem = Fnth (make_number (4), def);
47ccd8b6 813 if (EQ (tem, Qt) || EQ (tem, Qmacro))
ee9ee63c
JB
814 /* Yes, load it and try again. */
815 {
816 do_autoload (def, sym);
817 continue;
818 }
819 else
db9f0278 820 break;
db9f0278
JB
821 }
822 else if (!EQ (XCONS (def)->car, Qmacro))
823 break;
824 else expander = XCONS (def)->cdr;
825 }
826 else
827 {
828 expander = XCONS (tem)->cdr;
265a9e55 829 if (NILP (expander))
db9f0278
JB
830 break;
831 }
db9f0278
JB
832 form = apply1 (expander, XCONS (form)->cdr);
833 }
834 return form;
835}
836\f
837DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
838 "(catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'.\n\
839TAG is evalled to get the tag to use. Then the BODY is executed.\n\
840Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.\n\
841If no throw happens, `catch' returns the value of the last BODY form.\n\
842If a throw happens, it specifies the value to return from `catch'.")
843 (args)
844 Lisp_Object args;
845{
846 register Lisp_Object tag;
847 struct gcpro gcpro1;
848
849 GCPRO1 (args);
850 tag = Feval (Fcar (args));
851 UNGCPRO;
852 return internal_catch (tag, Fprogn, Fcdr (args));
853}
854
855/* Set up a catch, then call C function FUNC on argument ARG.
856 FUNC should return a Lisp_Object.
857 This is how catches are done from within C code. */
858
859Lisp_Object
860internal_catch (tag, func, arg)
861 Lisp_Object tag;
862 Lisp_Object (*func) ();
863 Lisp_Object arg;
864{
865 /* This structure is made part of the chain `catchlist'. */
866 struct catchtag c;
867
868 /* Fill in the components of c, and put it on the list. */
869 c.next = catchlist;
870 c.tag = tag;
871 c.val = Qnil;
872 c.backlist = backtrace_list;
873 c.handlerlist = handlerlist;
874 c.lisp_eval_depth = lisp_eval_depth;
875 c.pdlcount = specpdl_ptr - specpdl;
876 c.poll_suppress_count = poll_suppress_count;
877 c.gcpro = gcprolist;
878 catchlist = &c;
879
880 /* Call FUNC. */
881 if (! _setjmp (c.jmp))
882 c.val = (*func) (arg);
883
884 /* Throw works by a longjmp that comes right here. */
885 catchlist = c.next;
886 return c.val;
887}
888
ba410f40
JB
889/* Unwind the specbind, catch, and handler stacks back to CATCH, and
890 jump to that CATCH, returning VALUE as the value of that catch.
db9f0278 891
ba410f40
JB
892 This is the guts Fthrow and Fsignal; they differ only in the way
893 they choose the catch tag to throw to. A catch tag for a
894 condition-case form has a TAG of Qnil.
db9f0278 895
ba410f40
JB
896 Before each catch is discarded, unbind all special bindings and
897 execute all unwind-protect clauses made above that catch. Unwind
898 the handler stack as we go, so that the proper handlers are in
899 effect for each unwind-protect clause we run. At the end, restore
900 some static info saved in CATCH, and longjmp to the location
901 specified in the
902
903 This is used for correct unwinding in Fthrow and Fsignal. */
db9f0278
JB
904
905static void
ba410f40 906unwind_to_catch (catch, value)
db9f0278 907 struct catchtag *catch;
ba410f40 908 Lisp_Object value;
db9f0278
JB
909{
910 register int last_time;
911
ba410f40
JB
912 /* Save the value in the tag. */
913 catch->val = value;
914
82da7701 915 /* Restore the polling-suppression count. */
1cdc3155 916 set_poll_suppress_count (catch->poll_suppress_count);
82da7701 917
db9f0278
JB
918 do
919 {
920 last_time = catchlist == catch;
82da7701
JB
921
922 /* Unwind the specpdl stack, and then restore the proper set of
923 handlers. */
db9f0278
JB
924 unbind_to (catchlist->pdlcount, Qnil);
925 handlerlist = catchlist->handlerlist;
926 catchlist = catchlist->next;
927 }
928 while (! last_time);
929
930 gcprolist = catch->gcpro;
931 backtrace_list = catch->backlist;
932 lisp_eval_depth = catch->lisp_eval_depth;
ba410f40
JB
933
934 _longjmp (catch->jmp, 1);
db9f0278
JB
935}
936
937DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
938 "(throw TAG VALUE): throw to the catch for TAG and return VALUE from it.\n\
939Both TAG and VALUE are evalled.")
940 (tag, val)
941 register Lisp_Object tag, val;
942{
943 register struct catchtag *c;
944
945 while (1)
946 {
265a9e55 947 if (!NILP (tag))
db9f0278
JB
948 for (c = catchlist; c; c = c->next)
949 {
950 if (EQ (c->tag, tag))
ba410f40 951 unwind_to_catch (c, val);
db9f0278
JB
952 }
953 tag = Fsignal (Qno_catch, Fcons (tag, Fcons (val, Qnil)));
954 }
955}
956
957
958DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
959 "Do BODYFORM, protecting with UNWINDFORMS.\n\
960Usage looks like (unwind-protect BODYFORM UNWINDFORMS...).\n\
961If BODYFORM completes normally, its value is returned\n\
962after executing the UNWINDFORMS.\n\
963If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.")
964 (args)
965 Lisp_Object args;
966{
967 Lisp_Object val;
968 int count = specpdl_ptr - specpdl;
969
970 record_unwind_protect (0, Fcdr (args));
971 val = Feval (Fcar (args));
972 return unbind_to (count, val);
973}
974\f
975/* Chain of condition handlers currently in effect.
976 The elements of this chain are contained in the stack frames
977 of Fcondition_case and internal_condition_case.
978 When an error is signaled (by calling Fsignal, below),
979 this chain is searched for an element that applies. */
980
981struct handler *handlerlist;
982
983DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
984 "Regain control when an error is signaled.\n\
985Usage looks like (condition-case VAR BODYFORM HANDLERS...).\n\
986executes BODYFORM and returns its value if no error happens.\n\
987Each element of HANDLERS looks like (CONDITION-NAME BODY...)\n\
988where the BODY is made of Lisp expressions.\n\n\
989A handler is applicable to an error\n\
990if CONDITION-NAME is one of the error's condition names.\n\
991If an error happens, the first applicable handler is run.\n\
992\n\
633357d4
RS
993The car of a handler may be a list of condition names\n\
994instead of a single condition name.\n\
995\n\
db9f0278
JB
996When a handler handles an error,\n\
997control returns to the condition-case and the handler BODY... is executed\n\
998with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).\n\
999VAR may be nil; then you do not get access to the signal information.\n\
1000\n\
1001The value of the last BODY form is returned from the condition-case.\n\
1002See also the function `signal' for more info.")
1003 (args)
1004 Lisp_Object args;
1005{
1006 Lisp_Object val;
1007 struct catchtag c;
1008 struct handler h;
82da7701 1009 register Lisp_Object var, bodyform, handlers;
db9f0278 1010
82da7701
JB
1011 var = Fcar (args);
1012 bodyform = Fcar (Fcdr (args));
1013 handlers = Fcdr (Fcdr (args));
1014 CHECK_SYMBOL (var, 0);
1015
1016 for (val = handlers; ! NILP (val); val = Fcdr (val))
1017 {
1018 Lisp_Object tem;
1019 tem = Fcar (val);
5f96776a
RS
1020 if (! (NILP (tem)
1021 || (CONSP (tem)
1022 && (SYMBOLP (XCONS (tem)->car)
1023 || CONSP (XCONS (tem)->car)))))
82da7701
JB
1024 error ("Invalid condition handler", tem);
1025 }
db9f0278
JB
1026
1027 c.tag = Qnil;
1028 c.val = Qnil;
1029 c.backlist = backtrace_list;
1030 c.handlerlist = handlerlist;
1031 c.lisp_eval_depth = lisp_eval_depth;
1032 c.pdlcount = specpdl_ptr - specpdl;
1033 c.poll_suppress_count = poll_suppress_count;
1034 c.gcpro = gcprolist;
1035 if (_setjmp (c.jmp))
1036 {
265a9e55 1037 if (!NILP (h.var))
9d58218c
RS
1038 specbind (h.var, c.val);
1039 val = Fprogn (Fcdr (h.chosen_clause));
82da7701
JB
1040
1041 /* Note that this just undoes the binding of h.var; whoever
1042 longjumped to us unwound the stack to c.pdlcount before
1043 throwing. */
db9f0278
JB
1044 unbind_to (c.pdlcount, Qnil);
1045 return val;
1046 }
1047 c.next = catchlist;
1048 catchlist = &c;
db9f0278 1049
82da7701
JB
1050 h.var = var;
1051 h.handler = handlers;
db9f0278 1052 h.next = handlerlist;
db9f0278
JB
1053 h.tag = &c;
1054 handlerlist = &h;
1055
82da7701 1056 val = Feval (bodyform);
db9f0278
JB
1057 catchlist = c.next;
1058 handlerlist = h.next;
1059 return val;
1060}
1061
1062Lisp_Object
1063internal_condition_case (bfun, handlers, hfun)
1064 Lisp_Object (*bfun) ();
1065 Lisp_Object handlers;
1066 Lisp_Object (*hfun) ();
1067{
1068 Lisp_Object val;
1069 struct catchtag c;
1070 struct handler h;
1071
1072 c.tag = Qnil;
1073 c.val = Qnil;
1074 c.backlist = backtrace_list;
1075 c.handlerlist = handlerlist;
1076 c.lisp_eval_depth = lisp_eval_depth;
1077 c.pdlcount = specpdl_ptr - specpdl;
1078 c.poll_suppress_count = poll_suppress_count;
1079 c.gcpro = gcprolist;
1080 if (_setjmp (c.jmp))
1081 {
9d58218c 1082 return (*hfun) (c.val);
db9f0278
JB
1083 }
1084 c.next = catchlist;
1085 catchlist = &c;
1086 h.handler = handlers;
1087 h.var = Qnil;
db9f0278
JB
1088 h.next = handlerlist;
1089 h.tag = &c;
1090 handlerlist = &h;
1091
1092 val = (*bfun) ();
1093 catchlist = c.next;
1094 handlerlist = h.next;
1095 return val;
1096}
1097
d227775c
RS
1098Lisp_Object
1099internal_condition_case_1 (bfun, arg, handlers, hfun)
1100 Lisp_Object (*bfun) ();
1101 Lisp_Object arg;
1102 Lisp_Object handlers;
1103 Lisp_Object (*hfun) ();
1104{
1105 Lisp_Object val;
1106 struct catchtag c;
1107 struct handler h;
1108
1109 c.tag = Qnil;
1110 c.val = Qnil;
1111 c.backlist = backtrace_list;
1112 c.handlerlist = handlerlist;
1113 c.lisp_eval_depth = lisp_eval_depth;
1114 c.pdlcount = specpdl_ptr - specpdl;
1115 c.poll_suppress_count = poll_suppress_count;
1116 c.gcpro = gcprolist;
1117 if (_setjmp (c.jmp))
1118 {
9d58218c 1119 return (*hfun) (c.val);
d227775c
RS
1120 }
1121 c.next = catchlist;
1122 catchlist = &c;
1123 h.handler = handlers;
1124 h.var = Qnil;
1125 h.next = handlerlist;
1126 h.tag = &c;
1127 handlerlist = &h;
1128
1129 val = (*bfun) (arg);
1130 catchlist = c.next;
1131 handlerlist = h.next;
1132 return val;
1133}
1134\f
db9f0278
JB
1135static Lisp_Object find_handler_clause ();
1136
1137DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
4200e719 1138 "Signal an error. Args are ERROR-SYMBOL and associated DATA.\n\
db9f0278 1139This function does not return.\n\n\
4200e719 1140An error symbol is a symbol with an `error-conditions' property\n\
db9f0278
JB
1141that is a list of condition names.\n\
1142A handler for any of those names will get to handle this signal.\n\
1143The symbol `error' should normally be one of them.\n\
1144\n\
1145DATA should be a list. Its elements are printed as part of the error message.\n\
1146If the signal is handled, DATA is made available to the handler.\n\
1147See also the function `condition-case'.")
4200e719
RS
1148 (error_symbol, data)
1149 Lisp_Object error_symbol, data;
db9f0278
JB
1150{
1151 register struct handler *allhandlers = handlerlist;
1152 Lisp_Object conditions;
1153 extern int gc_in_progress;
1154 extern int waiting_for_input;
1155 Lisp_Object debugger_value;
1156
1157 quit_error_check ();
1158 immediate_quit = 0;
1159 if (gc_in_progress || waiting_for_input)
1160 abort ();
1161
e5d77022 1162#ifdef HAVE_X_WINDOWS
db9f0278 1163 TOTALLY_UNBLOCK_INPUT;
e5d77022 1164#endif
db9f0278 1165
4200e719 1166 conditions = Fget (error_symbol, Qerror_conditions);
db9f0278
JB
1167
1168 for (; handlerlist; handlerlist = handlerlist->next)
1169 {
1170 register Lisp_Object clause;
1171 clause = find_handler_clause (handlerlist->handler, conditions,
4200e719 1172 error_symbol, data, &debugger_value);
db9f0278
JB
1173
1174#if 0 /* Most callers are not prepared to handle gc if this returns.
1175 So, since this feature is not very useful, take it out. */
1176 /* If have called debugger and user wants to continue,
1177 just return nil. */
1178 if (EQ (clause, Qlambda))
1179 return debugger_value;
1180#else
1181 if (EQ (clause, Qlambda))
82da7701
JB
1182 {
1183 /* We can't return values to code which signalled an error, but we
1184 can continue code which has signalled a quit. */
4200e719 1185 if (EQ (error_symbol, Qquit))
82da7701
JB
1186 return Qnil;
1187 else
d3e6f8be 1188 error ("Cannot return from the debugger in an error");
82da7701 1189 }
db9f0278
JB
1190#endif
1191
265a9e55 1192 if (!NILP (clause))
db9f0278 1193 {
9d58218c 1194 Lisp_Object unwind_data;
db9f0278 1195 struct handler *h = handlerlist;
9d58218c 1196
db9f0278 1197 handlerlist = allhandlers;
9d58218c
RS
1198 if (data == memory_signal_data)
1199 unwind_data = memory_signal_data;
1200 else
1201 unwind_data = Fcons (error_symbol, data);
1202 h->chosen_clause = clause;
1203 unwind_to_catch (h->tag, unwind_data);
db9f0278
JB
1204 }
1205 }
1206
1207 handlerlist = allhandlers;
1208 /* If no handler is present now, try to run the debugger,
1209 and if that fails, throw to top level. */
4200e719 1210 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value);
db9f0278
JB
1211 Fthrow (Qtop_level, Qt);
1212}
1213
128c0f66
RM
1214/* Return nonzero iff LIST is a non-nil atom or
1215 a list containing one of CONDITIONS. */
1216
1217static int
1218wants_debugger (list, conditions)
1219 Lisp_Object list, conditions;
1220{
4de86b16 1221 if (NILP (list))
128c0f66
RM
1222 return 0;
1223 if (! CONSP (list))
1224 return 1;
1225
ab67260b 1226 while (CONSP (conditions))
128c0f66 1227 {
ab67260b
RS
1228 Lisp_Object this, tail;
1229 this = XCONS (conditions)->car;
1230 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr)
1231 if (EQ (XCONS (tail)->car, this))
128c0f66 1232 return 1;
128c0f66
RM
1233 conditions = XCONS (conditions)->cdr;
1234 }
ab67260b 1235 return 0;
128c0f66
RM
1236}
1237
1238/* Value of Qlambda means we have called debugger and user has continued.
1239 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
db9f0278
JB
1240
1241static Lisp_Object
1242find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr)
1243 Lisp_Object handlers, conditions, sig, data;
1244 Lisp_Object *debugger_value_ptr;
1245{
1246 register Lisp_Object h;
1247 register Lisp_Object tem;
db9f0278
JB
1248
1249 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */
1250 return Qt;
1251 if (EQ (handlers, Qerror)) /* error is used similarly, but means display a backtrace too */
1252 {
128c0f66 1253 if (wants_debugger (Vstack_trace_on_error, conditions))
db9f0278 1254 internal_with_output_to_temp_buffer ("*Backtrace*", Fbacktrace, Qnil);
ba410f40
JB
1255 if ((EQ (sig, Qquit)
1256 ? debug_on_quit
1257 : wants_debugger (Vdebug_on_error, conditions))
1258 && when_entered_debugger < num_nonmacro_input_chars)
db9f0278
JB
1259 {
1260 int count = specpdl_ptr - specpdl;
1261 specbind (Qdebug_on_error, Qnil);
1262 *debugger_value_ptr =
1263 call_debugger (Fcons (Qerror,
1264 Fcons (Fcons (sig, data),
1265 Qnil)));
1266 return unbind_to (count, Qlambda);
1267 }
1268 return Qt;
1269 }
1270 for (h = handlers; CONSP (h); h = Fcdr (h))
1271 {
5f96776a
RS
1272 Lisp_Object handler, condit;
1273
1274 handler = Fcar (h);
1275 if (!CONSP (handler))
db9f0278 1276 continue;
5f96776a
RS
1277 condit = Fcar (handler);
1278 /* Handle a single condition name in handler HANDLER. */
1279 if (SYMBOLP (condit))
1280 {
1281 tem = Fmemq (Fcar (handler), conditions);
1282 if (!NILP (tem))
1283 return handler;
1284 }
1285 /* Handle a list of condition names in handler HANDLER. */
1286 else if (CONSP (condit))
1287 {
1288 while (CONSP (condit))
1289 {
1290 tem = Fmemq (Fcar (condit), conditions);
1291 if (!NILP (tem))
1292 return handler;
1293 condit = XCONS (condit)->cdr;
1294 }
1295 }
db9f0278
JB
1296 }
1297 return Qnil;
1298}
1299
1300/* dump an error message; called like printf */
1301
1302/* VARARGS 1 */
1303void
1304error (m, a1, a2, a3)
1305 char *m;
9125da08 1306 char *a1, *a2, *a3;
db9f0278
JB
1307{
1308 char buf[200];
9125da08
RS
1309 int size = 200;
1310 int mlen;
1311 char *buffer = buf;
1312 char *args[3];
1313 int allocated = 0;
1314 Lisp_Object string;
1315
1316 args[0] = a1;
1317 args[1] = a2;
1318 args[2] = a3;
1319
1320 mlen = strlen (m);
db9f0278
JB
1321
1322 while (1)
9125da08
RS
1323 {
1324 int used = doprnt (buf, size, m, m + mlen, 3, args);
1325 if (used < size)
1326 break;
1327 size *= 2;
1328 if (allocated)
1329 buffer = (char *) xrealloc (buffer, size);
1330 buffer = (char *) xmalloc (size);
1331 }
1332
1333 string = build_string (buf);
1334 if (allocated)
1335 free (buffer);
1336
1337 Fsignal (Qerror, Fcons (string, Qnil));
db9f0278
JB
1338}
1339\f
1340DEFUN ("commandp", Fcommandp, Scommandp, 1, 1, 0,
1341 "T if FUNCTION makes provisions for interactive calling.\n\
1342This means it contains a description for how to read arguments to give it.\n\
1343The value is nil for an invalid function or a symbol with no function\n\
1344definition.\n\
1345\n\
1346Interactively callable functions include strings and vectors (treated\n\
1347as keyboard macros), lambda-expressions that contain a top-level call\n\
1348to `interactive', autoload definitions made by `autoload' with non-nil\n\
1349fourth argument, and some of the built-in functions of Lisp.\n\
1350\n\
1351Also, a symbol satisfies `commandp' if its function definition does so.")
1352 (function)
1353 Lisp_Object function;
1354{
1355 register Lisp_Object fun;
1356 register Lisp_Object funcar;
1357 register Lisp_Object tem;
1358 register int i = 0;
1359
1360 fun = function;
1361
ffd56f97
JB
1362 fun = indirect_function (fun);
1363 if (EQ (fun, Qunbound))
1364 return Qnil;
db9f0278
JB
1365
1366 /* Emacs primitives are interactive if their DEFUN specifies an
1367 interactive spec. */
1368 if (XTYPE (fun) == Lisp_Subr)
1369 {
1370 if (XSUBR (fun)->prompt)
1371 return Qt;
1372 else
1373 return Qnil;
1374 }
1375
1376 /* Bytecode objects are interactive if they are long enough to
1377 have an element whose index is COMPILED_INTERACTIVE, which is
1378 where the interactive spec is stored. */
1379 else if (XTYPE (fun) == Lisp_Compiled)
1380 return (XVECTOR (fun)->size > COMPILED_INTERACTIVE
1381 ? Qt : Qnil);
1382
1383 /* Strings and vectors are keyboard macros. */
1384 if (XTYPE (fun) == Lisp_String
1385 || XTYPE (fun) == Lisp_Vector)
1386 return Qt;
1387
1388 /* Lists may represent commands. */
1389 if (!CONSP (fun))
1390 return Qnil;
1391 funcar = Fcar (fun);
1392 if (XTYPE (funcar) != Lisp_Symbol)
1393 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1394 if (EQ (funcar, Qlambda))
1395 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
1396 if (EQ (funcar, Qmocklisp))
1397 return Qt; /* All mocklisp functions can be called interactively */
1398 if (EQ (funcar, Qautoload))
1399 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
1400 else
1401 return Qnil;
1402}
1403
1404/* ARGSUSED */
1405DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
1406 "Define FUNCTION to autoload from FILE.\n\
1407FUNCTION is a symbol; FILE is a file name string to pass to `load'.\n\
1408Third arg DOCSTRING is documentation for the function.\n\
1409Fourth arg INTERACTIVE if non-nil says function can be called interactively.\n\
ee9ee63c
JB
1410Fifth arg TYPE indicates the type of the object:\n\
1411 nil or omitted says FUNCTION is a function,\n\
1412 `keymap' says FUNCTION is really a keymap, and\n\
1413 `macro' or t says FUNCTION is really a macro.\n\
db9f0278
JB
1414Third through fifth args give info about the real definition.\n\
1415They default to nil.\n\
1416If FUNCTION is already defined other than as an autoload,\n\
1417this does nothing and returns nil.")
ee9ee63c
JB
1418 (function, file, docstring, interactive, type)
1419 Lisp_Object function, file, docstring, interactive, type;
db9f0278
JB
1420{
1421#ifdef NO_ARG_ARRAY
1422 Lisp_Object args[4];
1423#endif
1424
1425 CHECK_SYMBOL (function, 0);
1426 CHECK_STRING (file, 1);
1427
1428 /* If function is defined and not as an autoload, don't override */
1429 if (!EQ (XSYMBOL (function)->function, Qunbound)
1430 && !(XTYPE (XSYMBOL (function)->function) == Lisp_Cons
1431 && EQ (XCONS (XSYMBOL (function)->function)->car, Qautoload)))
1432 return Qnil;
1433
1434#ifdef NO_ARG_ARRAY
1435 args[0] = file;
1436 args[1] = docstring;
1437 args[2] = interactive;
ee9ee63c 1438 args[3] = type;
db9f0278
JB
1439
1440 return Ffset (function, Fcons (Qautoload, Flist (4, &args[0])));
1441#else /* NO_ARG_ARRAY */
1442 return Ffset (function, Fcons (Qautoload, Flist (4, &file)));
1443#endif /* not NO_ARG_ARRAY */
1444}
1445
1446Lisp_Object
1447un_autoload (oldqueue)
1448 Lisp_Object oldqueue;
1449{
1450 register Lisp_Object queue, first, second;
1451
1452 /* Queue to unwind is current value of Vautoload_queue.
1453 oldqueue is the shadowed value to leave in Vautoload_queue. */
1454 queue = Vautoload_queue;
1455 Vautoload_queue = oldqueue;
1456 while (CONSP (queue))
1457 {
1458 first = Fcar (queue);
1459 second = Fcdr (first);
1460 first = Fcar (first);
1461 if (EQ (second, Qnil))
1462 Vfeatures = first;
1463 else
1464 Ffset (first, second);
1465 queue = Fcdr (queue);
1466 }
1467 return Qnil;
1468}
1469
1470do_autoload (fundef, funname)
1471 Lisp_Object fundef, funname;
1472{
1473 int count = specpdl_ptr - specpdl;
2a49b6e5 1474 Lisp_Object fun, val, queue, first, second;
db9f0278
JB
1475
1476 fun = funname;
1477 CHECK_SYMBOL (funname, 0);
1478
1479 /* Value saved here is to be restored into Vautoload_queue */
1480 record_unwind_protect (un_autoload, Vautoload_queue);
1481 Vautoload_queue = Qt;
1482 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil);
2a49b6e5
RS
1483
1484 /* Save the old autoloads, in case we ever do an unload. */
1485 queue = Vautoload_queue;
1486 while (CONSP (queue))
1487 {
1488 first = Fcar (queue);
1489 second = Fcdr (first);
1490 first = Fcar (first);
5739ce6b
ER
1491
1492 /* Note: This test is subtle. The cdr of an autoload-queue entry
1493 may be an atom if the autoload entry was generated by a defalias
1494 or fset. */
1495 if (CONSP (second))
03e267c2 1496 Fput (first, Qautoload, (Fcdr (second)));
5739ce6b 1497
2a49b6e5
RS
1498 queue = Fcdr (queue);
1499 }
1500
db9f0278
JB
1501 /* Once loading finishes, don't undo it. */
1502 Vautoload_queue = Qt;
1503 unbind_to (count, Qnil);
1504
ffd56f97
JB
1505 fun = Findirect_function (fun);
1506
76c2b0cc 1507 if (!NILP (Fequal (fun, fundef)))
db9f0278
JB
1508 error ("Autoloading failed to define function %s",
1509 XSYMBOL (funname)->name->data);
1510}
1511\f
1512DEFUN ("eval", Feval, Seval, 1, 1, 0,
1513 "Evaluate FORM and return its value.")
1514 (form)
1515 Lisp_Object form;
1516{
1517 Lisp_Object fun, val, original_fun, original_args;
1518 Lisp_Object funcar;
1519 struct backtrace backtrace;
1520 struct gcpro gcpro1, gcpro2, gcpro3;
1521
1522 if (XTYPE (form) == Lisp_Symbol)
1523 {
1524 if (EQ (Vmocklisp_arguments, Qt))
1525 return Fsymbol_value (form);
1526 val = Fsymbol_value (form);
265a9e55 1527 if (NILP (val))
db9f0278
JB
1528 XFASTINT (val) = 0;
1529 else if (EQ (val, Qt))
1530 XFASTINT (val) = 1;
1531 return val;
1532 }
1533 if (!CONSP (form))
1534 return form;
1535
1536 QUIT;
1537 if (consing_since_gc > gc_cons_threshold)
1538 {
1539 GCPRO1 (form);
1540 Fgarbage_collect ();
1541 UNGCPRO;
1542 }
1543
1544 if (++lisp_eval_depth > max_lisp_eval_depth)
1545 {
1546 if (max_lisp_eval_depth < 100)
1547 max_lisp_eval_depth = 100;
1548 if (lisp_eval_depth > max_lisp_eval_depth)
1549 error ("Lisp nesting exceeds max-lisp-eval-depth");
1550 }
1551
1552 original_fun = Fcar (form);
1553 original_args = Fcdr (form);
1554
1555 backtrace.next = backtrace_list;
1556 backtrace_list = &backtrace;
1557 backtrace.function = &original_fun; /* This also protects them from gc */
1558 backtrace.args = &original_args;
1559 backtrace.nargs = UNEVALLED;
1560 backtrace.evalargs = 1;
1561 backtrace.debug_on_exit = 0;
1562
1563 if (debug_on_next_call)
1564 do_debug_on_call (Qt);
1565
1566 /* At this point, only original_fun and original_args
1567 have values that will be used below */
1568 retry:
ffd56f97 1569 fun = Findirect_function (original_fun);
db9f0278
JB
1570
1571 if (XTYPE (fun) == Lisp_Subr)
1572 {
1573 Lisp_Object numargs;
1574 Lisp_Object argvals[7];
1575 Lisp_Object args_left;
1576 register int i, maxargs;
1577
1578 args_left = original_args;
1579 numargs = Flength (args_left);
1580
1581 if (XINT (numargs) < XSUBR (fun)->min_args ||
1582 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
1583 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
1584
1585 if (XSUBR (fun)->max_args == UNEVALLED)
1586 {
1587 backtrace.evalargs = 0;
1588 val = (*XSUBR (fun)->function) (args_left);
1589 goto done;
1590 }
1591
1592 if (XSUBR (fun)->max_args == MANY)
1593 {
1594 /* Pass a vector of evaluated arguments */
1595 Lisp_Object *vals;
1596 register int argnum = 0;
1597
1598 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
1599
1600 GCPRO3 (args_left, fun, fun);
1601 gcpro3.var = vals;
1602 gcpro3.nvars = 0;
1603
265a9e55 1604 while (!NILP (args_left))
db9f0278
JB
1605 {
1606 vals[argnum++] = Feval (Fcar (args_left));
1607 args_left = Fcdr (args_left);
1608 gcpro3.nvars = argnum;
1609 }
db9f0278
JB
1610
1611 backtrace.args = vals;
1612 backtrace.nargs = XINT (numargs);
1613
1614 val = (*XSUBR (fun)->function) (XINT (numargs), vals);
a6e3fa71 1615 UNGCPRO;
db9f0278
JB
1616 goto done;
1617 }
1618
1619 GCPRO3 (args_left, fun, fun);
1620 gcpro3.var = argvals;
1621 gcpro3.nvars = 0;
1622
1623 maxargs = XSUBR (fun)->max_args;
1624 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
1625 {
1626 argvals[i] = Feval (Fcar (args_left));
1627 gcpro3.nvars = ++i;
1628 }
1629
1630 UNGCPRO;
1631
1632 backtrace.args = argvals;
1633 backtrace.nargs = XINT (numargs);
1634
1635 switch (i)
1636 {
1637 case 0:
1638 val = (*XSUBR (fun)->function) ();
1639 goto done;
1640 case 1:
1641 val = (*XSUBR (fun)->function) (argvals[0]);
1642 goto done;
1643 case 2:
1644 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]);
1645 goto done;
1646 case 3:
1647 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
1648 argvals[2]);
1649 goto done;
1650 case 4:
1651 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
1652 argvals[2], argvals[3]);
1653 goto done;
1654 case 5:
1655 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
1656 argvals[3], argvals[4]);
1657 goto done;
1658 case 6:
1659 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
1660 argvals[3], argvals[4], argvals[5]);
1661 goto done;
15c65264
RS
1662 case 7:
1663 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
1664 argvals[3], argvals[4], argvals[5],
1665 argvals[6]);
1666 goto done;
db9f0278
JB
1667
1668 default:
08564963
JB
1669 /* Someone has created a subr that takes more arguments than
1670 is supported by this code. We need to either rewrite the
1671 subr to use a different argument protocol, or add more
1672 cases to this switch. */
1673 abort ();
db9f0278
JB
1674 }
1675 }
1676 if (XTYPE (fun) == Lisp_Compiled)
1677 val = apply_lambda (fun, original_args, 1);
1678 else
1679 {
1680 if (!CONSP (fun))
1681 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1682 funcar = Fcar (fun);
1683 if (XTYPE (funcar) != Lisp_Symbol)
1684 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1685 if (EQ (funcar, Qautoload))
1686 {
1687 do_autoload (fun, original_fun);
1688 goto retry;
1689 }
1690 if (EQ (funcar, Qmacro))
1691 val = Feval (apply1 (Fcdr (fun), original_args));
1692 else if (EQ (funcar, Qlambda))
1693 val = apply_lambda (fun, original_args, 1);
1694 else if (EQ (funcar, Qmocklisp))
1695 val = ml_apply (fun, original_args);
1696 else
1697 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
1698 }
1699 done:
1700 if (!EQ (Vmocklisp_arguments, Qt))
1701 {
265a9e55 1702 if (NILP (val))
db9f0278
JB
1703 XFASTINT (val) = 0;
1704 else if (EQ (val, Qt))
1705 XFASTINT (val) = 1;
1706 }
1707 lisp_eval_depth--;
1708 if (backtrace.debug_on_exit)
1709 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
1710 backtrace_list = backtrace.next;
1711 return val;
1712}
1713\f
1714DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
1715 "Call FUNCTION with our remaining args, using our last arg as list of args.\n\
1716Thus, (apply '+ 1 2 '(3 4)) returns 10.")
1717 (nargs, args)
1718 int nargs;
1719 Lisp_Object *args;
1720{
1721 register int i, numargs;
1722 register Lisp_Object spread_arg;
1723 register Lisp_Object *funcall_args;
db9f0278 1724 Lisp_Object fun;
a6e3fa71 1725 struct gcpro gcpro1;
db9f0278
JB
1726
1727 fun = args [0];
1728 funcall_args = 0;
1729 spread_arg = args [nargs - 1];
1730 CHECK_LIST (spread_arg, nargs);
1731
1732 numargs = XINT (Flength (spread_arg));
1733
1734 if (numargs == 0)
1735 return Ffuncall (nargs - 1, args);
1736 else if (numargs == 1)
1737 {
1738 args [nargs - 1] = XCONS (spread_arg)->car;
1739 return Ffuncall (nargs, args);
1740 }
1741
a6e3fa71 1742 numargs += nargs - 2;
db9f0278 1743
ffd56f97
JB
1744 fun = indirect_function (fun);
1745 if (EQ (fun, Qunbound))
db9f0278 1746 {
ffd56f97
JB
1747 /* Let funcall get the error */
1748 fun = args[0];
1749 goto funcall;
db9f0278
JB
1750 }
1751
1752 if (XTYPE (fun) == Lisp_Subr)
1753 {
1754 if (numargs < XSUBR (fun)->min_args
1755 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
1756 goto funcall; /* Let funcall get the error */
1757 else if (XSUBR (fun)->max_args > numargs)
1758 {
1759 /* Avoid making funcall cons up a yet another new vector of arguments
1760 by explicitly supplying nil's for optional values */
1761 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
1762 * sizeof (Lisp_Object));
1763 for (i = numargs; i < XSUBR (fun)->max_args;)
1764 funcall_args[++i] = Qnil;
a6e3fa71
JB
1765 GCPRO1 (*funcall_args);
1766 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
db9f0278
JB
1767 }
1768 }
1769 funcall:
1770 /* We add 1 to numargs because funcall_args includes the
1771 function itself as well as its arguments. */
1772 if (!funcall_args)
a6e3fa71
JB
1773 {
1774 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
1775 * sizeof (Lisp_Object));
1776 GCPRO1 (*funcall_args);
1777 gcpro1.nvars = 1 + numargs;
1778 }
1779
db9f0278
JB
1780 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
1781 /* Spread the last arg we got. Its first element goes in
1782 the slot that it used to occupy, hence this value of I. */
1783 i = nargs - 1;
265a9e55 1784 while (!NILP (spread_arg))
db9f0278
JB
1785 {
1786 funcall_args [i++] = XCONS (spread_arg)->car;
1787 spread_arg = XCONS (spread_arg)->cdr;
1788 }
a6e3fa71
JB
1789
1790 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
db9f0278
JB
1791}
1792\f
1793/* Apply fn to arg */
1794Lisp_Object
1795apply1 (fn, arg)
1796 Lisp_Object fn, arg;
1797{
a6e3fa71
JB
1798 struct gcpro gcpro1;
1799
1800 GCPRO1 (fn);
265a9e55 1801 if (NILP (arg))
a6e3fa71
JB
1802 RETURN_UNGCPRO (Ffuncall (1, &fn));
1803 gcpro1.nvars = 2;
db9f0278
JB
1804#ifdef NO_ARG_ARRAY
1805 {
1806 Lisp_Object args[2];
1807 args[0] = fn;
1808 args[1] = arg;
a6e3fa71
JB
1809 gcpro1.var = args;
1810 RETURN_UNGCPRO (Fapply (2, args));
db9f0278
JB
1811 }
1812#else /* not NO_ARG_ARRAY */
a6e3fa71 1813 RETURN_UNGCPRO (Fapply (2, &fn));
db9f0278
JB
1814#endif /* not NO_ARG_ARRAY */
1815}
1816
1817/* Call function fn on no arguments */
1818Lisp_Object
1819call0 (fn)
1820 Lisp_Object fn;
1821{
a6e3fa71
JB
1822 struct gcpro gcpro1;
1823
1824 GCPRO1 (fn);
1825 RETURN_UNGCPRO (Ffuncall (1, &fn));
db9f0278
JB
1826}
1827
15285f9f 1828/* Call function fn with 1 argument arg1 */
db9f0278
JB
1829/* ARGSUSED */
1830Lisp_Object
15285f9f
RS
1831call1 (fn, arg1)
1832 Lisp_Object fn, arg1;
db9f0278 1833{
a6e3fa71 1834 struct gcpro gcpro1;
db9f0278 1835#ifdef NO_ARG_ARRAY
a6e3fa71
JB
1836 Lisp_Object args[2];
1837
db9f0278 1838 args[0] = fn;
15285f9f 1839 args[1] = arg1;
a6e3fa71
JB
1840 GCPRO1 (args[0]);
1841 gcpro1.nvars = 2;
1842 RETURN_UNGCPRO (Ffuncall (2, args));
db9f0278 1843#else /* not NO_ARG_ARRAY */
a6e3fa71
JB
1844 GCPRO1 (fn);
1845 gcpro1.nvars = 2;
1846 RETURN_UNGCPRO (Ffuncall (2, &fn));
db9f0278
JB
1847#endif /* not NO_ARG_ARRAY */
1848}
1849
15285f9f 1850/* Call function fn with 2 arguments arg1, arg2 */
db9f0278
JB
1851/* ARGSUSED */
1852Lisp_Object
15285f9f
RS
1853call2 (fn, arg1, arg2)
1854 Lisp_Object fn, arg1, arg2;
db9f0278 1855{
a6e3fa71 1856 struct gcpro gcpro1;
db9f0278
JB
1857#ifdef NO_ARG_ARRAY
1858 Lisp_Object args[3];
1859 args[0] = fn;
15285f9f
RS
1860 args[1] = arg1;
1861 args[2] = arg2;
a6e3fa71
JB
1862 GCPRO1 (args[0]);
1863 gcpro1.nvars = 3;
1864 RETURN_UNGCPRO (Ffuncall (3, args));
db9f0278 1865#else /* not NO_ARG_ARRAY */
a6e3fa71
JB
1866 GCPRO1 (fn);
1867 gcpro1.nvars = 3;
1868 RETURN_UNGCPRO (Ffuncall (3, &fn));
db9f0278
JB
1869#endif /* not NO_ARG_ARRAY */
1870}
1871
15285f9f 1872/* Call function fn with 3 arguments arg1, arg2, arg3 */
db9f0278
JB
1873/* ARGSUSED */
1874Lisp_Object
15285f9f
RS
1875call3 (fn, arg1, arg2, arg3)
1876 Lisp_Object fn, arg1, arg2, arg3;
db9f0278 1877{
a6e3fa71 1878 struct gcpro gcpro1;
db9f0278
JB
1879#ifdef NO_ARG_ARRAY
1880 Lisp_Object args[4];
1881 args[0] = fn;
15285f9f
RS
1882 args[1] = arg1;
1883 args[2] = arg2;
1884 args[3] = arg3;
a6e3fa71
JB
1885 GCPRO1 (args[0]);
1886 gcpro1.nvars = 4;
1887 RETURN_UNGCPRO (Ffuncall (4, args));
db9f0278 1888#else /* not NO_ARG_ARRAY */
a6e3fa71
JB
1889 GCPRO1 (fn);
1890 gcpro1.nvars = 4;
1891 RETURN_UNGCPRO (Ffuncall (4, &fn));
db9f0278
JB
1892#endif /* not NO_ARG_ARRAY */
1893}
1894
15285f9f 1895/* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
a5a44b91
JB
1896/* ARGSUSED */
1897Lisp_Object
15285f9f
RS
1898call4 (fn, arg1, arg2, arg3, arg4)
1899 Lisp_Object fn, arg1, arg2, arg3, arg4;
a5a44b91
JB
1900{
1901 struct gcpro gcpro1;
1902#ifdef NO_ARG_ARRAY
1903 Lisp_Object args[5];
1904 args[0] = fn;
15285f9f
RS
1905 args[1] = arg1;
1906 args[2] = arg2;
1907 args[3] = arg3;
1908 args[4] = arg4;
a5a44b91
JB
1909 GCPRO1 (args[0]);
1910 gcpro1.nvars = 5;
1911 RETURN_UNGCPRO (Ffuncall (5, args));
1912#else /* not NO_ARG_ARRAY */
1913 GCPRO1 (fn);
1914 gcpro1.nvars = 5;
1915 RETURN_UNGCPRO (Ffuncall (5, &fn));
1916#endif /* not NO_ARG_ARRAY */
1917}
1918
15285f9f
RS
1919/* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
1920/* ARGSUSED */
1921Lisp_Object
1922call5 (fn, arg1, arg2, arg3, arg4, arg5)
1923 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
1924{
1925 struct gcpro gcpro1;
1926#ifdef NO_ARG_ARRAY
1927 Lisp_Object args[6];
1928 args[0] = fn;
1929 args[1] = arg1;
1930 args[2] = arg2;
1931 args[3] = arg3;
1932 args[4] = arg4;
1933 args[5] = arg5;
1934 GCPRO1 (args[0]);
1935 gcpro1.nvars = 6;
1936 RETURN_UNGCPRO (Ffuncall (6, args));
1937#else /* not NO_ARG_ARRAY */
1938 GCPRO1 (fn);
1939 gcpro1.nvars = 6;
1940 RETURN_UNGCPRO (Ffuncall (6, &fn));
1941#endif /* not NO_ARG_ARRAY */
1942}
1943
1944/* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
1945/* ARGSUSED */
1946Lisp_Object
1947call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
1948 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
1949{
1950 struct gcpro gcpro1;
1951#ifdef NO_ARG_ARRAY
1952 Lisp_Object args[7];
1953 args[0] = fn;
1954 args[1] = arg1;
1955 args[2] = arg2;
1956 args[3] = arg3;
1957 args[4] = arg4;
1958 args[5] = arg5;
1959 args[6] = arg6;
1960 GCPRO1 (args[0]);
1961 gcpro1.nvars = 7;
1962 RETURN_UNGCPRO (Ffuncall (7, args));
1963#else /* not NO_ARG_ARRAY */
1964 GCPRO1 (fn);
1965 gcpro1.nvars = 7;
1966 RETURN_UNGCPRO (Ffuncall (7, &fn));
1967#endif /* not NO_ARG_ARRAY */
1968}
1969
db9f0278
JB
1970DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
1971 "Call first argument as a function, passing remaining arguments to it.\n\
1972Thus, (funcall 'cons 'x 'y) returns (x . y).")
1973 (nargs, args)
1974 int nargs;
1975 Lisp_Object *args;
1976{
1977 Lisp_Object fun;
1978 Lisp_Object funcar;
1979 int numargs = nargs - 1;
1980 Lisp_Object lisp_numargs;
1981 Lisp_Object val;
1982 struct backtrace backtrace;
1983 register Lisp_Object *internal_args;
1984 register int i;
1985
1986 QUIT;
1987 if (consing_since_gc > gc_cons_threshold)
a6e3fa71 1988 Fgarbage_collect ();
db9f0278
JB
1989
1990 if (++lisp_eval_depth > max_lisp_eval_depth)
1991 {
1992 if (max_lisp_eval_depth < 100)
1993 max_lisp_eval_depth = 100;
1994 if (lisp_eval_depth > max_lisp_eval_depth)
1995 error ("Lisp nesting exceeds max-lisp-eval-depth");
1996 }
1997
1998 backtrace.next = backtrace_list;
1999 backtrace_list = &backtrace;
2000 backtrace.function = &args[0];
2001 backtrace.args = &args[1];
2002 backtrace.nargs = nargs - 1;
2003 backtrace.evalargs = 0;
2004 backtrace.debug_on_exit = 0;
2005
2006 if (debug_on_next_call)
2007 do_debug_on_call (Qlambda);
2008
2009 retry:
2010
2011 fun = args[0];
ffd56f97
JB
2012
2013 fun = Findirect_function (fun);
db9f0278
JB
2014
2015 if (XTYPE (fun) == Lisp_Subr)
2016 {
2017 if (numargs < XSUBR (fun)->min_args
2018 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2019 {
2020 XFASTINT (lisp_numargs) = numargs;
2021 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
2022 }
2023
2024 if (XSUBR (fun)->max_args == UNEVALLED)
2025 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2026
2027 if (XSUBR (fun)->max_args == MANY)
2028 {
2029 val = (*XSUBR (fun)->function) (numargs, args + 1);
2030 goto done;
2031 }
2032
2033 if (XSUBR (fun)->max_args > numargs)
2034 {
2035 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2036 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
2037 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2038 internal_args[i] = Qnil;
2039 }
2040 else
2041 internal_args = args + 1;
2042 switch (XSUBR (fun)->max_args)
2043 {
2044 case 0:
2045 val = (*XSUBR (fun)->function) ();
2046 goto done;
2047 case 1:
2048 val = (*XSUBR (fun)->function) (internal_args[0]);
2049 goto done;
2050 case 2:
2051 val = (*XSUBR (fun)->function) (internal_args[0],
2052 internal_args[1]);
2053 goto done;
2054 case 3:
2055 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2056 internal_args[2]);
2057 goto done;
2058 case 4:
2059 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2060 internal_args[2],
2061 internal_args[3]);
2062 goto done;
2063 case 5:
2064 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2065 internal_args[2], internal_args[3],
2066 internal_args[4]);
2067 goto done;
2068 case 6:
2069 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2070 internal_args[2], internal_args[3],
2071 internal_args[4], internal_args[5]);
2072 goto done;
15c65264
RS
2073 case 7:
2074 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2075 internal_args[2], internal_args[3],
2076 internal_args[4], internal_args[5],
2077 internal_args[6]);
2078 goto done;
db9f0278
JB
2079
2080 default:
70ee42f7
JB
2081
2082 /* If a subr takes more than 6 arguments without using MANY
2083 or UNEVALLED, we need to extend this function to support it.
2084 Until this is done, there is no way to call the function. */
2085 abort ();
db9f0278
JB
2086 }
2087 }
2088 if (XTYPE (fun) == Lisp_Compiled)
2089 val = funcall_lambda (fun, numargs, args + 1);
2090 else
2091 {
2092 if (!CONSP (fun))
2093 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2094 funcar = Fcar (fun);
2095 if (XTYPE (funcar) != Lisp_Symbol)
2096 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2097 if (EQ (funcar, Qlambda))
2098 val = funcall_lambda (fun, numargs, args + 1);
2099 else if (EQ (funcar, Qmocklisp))
2100 val = ml_apply (fun, Flist (numargs, args + 1));
2101 else if (EQ (funcar, Qautoload))
2102 {
2103 do_autoload (fun, args[0]);
2104 goto retry;
2105 }
2106 else
2107 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2108 }
2109 done:
2110 lisp_eval_depth--;
2111 if (backtrace.debug_on_exit)
2112 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2113 backtrace_list = backtrace.next;
2114 return val;
2115}
2116\f
2117Lisp_Object
2118apply_lambda (fun, args, eval_flag)
2119 Lisp_Object fun, args;
2120 int eval_flag;
2121{
2122 Lisp_Object args_left;
2123 Lisp_Object numargs;
2124 register Lisp_Object *arg_vector;
2125 struct gcpro gcpro1, gcpro2, gcpro3;
2126 register int i;
2127 register Lisp_Object tem;
2128
2129 numargs = Flength (args);
2130 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2131 args_left = args;
2132
2133 GCPRO3 (*arg_vector, args_left, fun);
2134 gcpro1.nvars = 0;
2135
2136 for (i = 0; i < XINT (numargs);)
2137 {
2138 tem = Fcar (args_left), args_left = Fcdr (args_left);
2139 if (eval_flag) tem = Feval (tem);
2140 arg_vector[i++] = tem;
2141 gcpro1.nvars = i;
2142 }
2143
2144 UNGCPRO;
2145
2146 if (eval_flag)
2147 {
2148 backtrace_list->args = arg_vector;
2149 backtrace_list->nargs = i;
2150 }
2151 backtrace_list->evalargs = 0;
2152 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
2153
2154 /* Do the debug-on-exit now, while arg_vector still exists. */
2155 if (backtrace_list->debug_on_exit)
2156 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
2157 /* Don't do it again when we return to eval. */
2158 backtrace_list->debug_on_exit = 0;
2159 return tem;
2160}
2161
2162/* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2163 and return the result of evaluation.
2164 FUN must be either a lambda-expression or a compiled-code object. */
2165
2166Lisp_Object
2167funcall_lambda (fun, nargs, arg_vector)
2168 Lisp_Object fun;
2169 int nargs;
2170 register Lisp_Object *arg_vector;
2171{
2172 Lisp_Object val, tem;
2173 register Lisp_Object syms_left;
2174 Lisp_Object numargs;
2175 register Lisp_Object next;
2176 int count = specpdl_ptr - specpdl;
2177 register int i;
2178 int optional = 0, rest = 0;
2179
2180 specbind (Qmocklisp_arguments, Qt); /* t means NOT mocklisp! */
2181
2182 XFASTINT (numargs) = nargs;
2183
2184 if (XTYPE (fun) == Lisp_Cons)
2185 syms_left = Fcar (Fcdr (fun));
2186 else if (XTYPE (fun) == Lisp_Compiled)
2187 syms_left = XVECTOR (fun)->contents[COMPILED_ARGLIST];
2188 else abort ();
2189
2190 i = 0;
265a9e55 2191 for (; !NILP (syms_left); syms_left = Fcdr (syms_left))
db9f0278
JB
2192 {
2193 QUIT;
2194 next = Fcar (syms_left);
9ffa21d4
JB
2195 while (XTYPE (next) != Lisp_Symbol)
2196 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
db9f0278
JB
2197 if (EQ (next, Qand_rest))
2198 rest = 1;
2199 else if (EQ (next, Qand_optional))
2200 optional = 1;
2201 else if (rest)
2202 {
9ffa21d4 2203 specbind (next, Flist (nargs - i, &arg_vector[i]));
db9f0278
JB
2204 i = nargs;
2205 }
2206 else if (i < nargs)
2207 {
2208 tem = arg_vector[i++];
2209 specbind (next, tem);
2210 }
2211 else if (!optional)
2212 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
2213 else
2214 specbind (next, Qnil);
2215 }
2216
2217 if (i < nargs)
2218 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
2219
2220 if (XTYPE (fun) == Lisp_Cons)
2221 val = Fprogn (Fcdr (Fcdr (fun)));
2222 else
2223 val = Fbyte_code (XVECTOR (fun)->contents[COMPILED_BYTECODE],
2224 XVECTOR (fun)->contents[COMPILED_CONSTANTS],
2225 XVECTOR (fun)->contents[COMPILED_STACK_DEPTH]);
2226 return unbind_to (count, val);
2227}
2228\f
2229void
2230grow_specpdl ()
2231{
2232 register int count = specpdl_ptr - specpdl;
2233 if (specpdl_size >= max_specpdl_size)
2234 {
2235 if (max_specpdl_size < 400)
2236 max_specpdl_size = 400;
2237 if (specpdl_size >= max_specpdl_size)
2238 {
debee8fe
RS
2239 if (!NILP (Vdebug_on_error))
2240 /* Leave room for some specpdl in the debugger. */
2241 max_specpdl_size = specpdl_size + 100;
db9f0278
JB
2242 Fsignal (Qerror,
2243 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil));
db9f0278
JB
2244 }
2245 }
2246 specpdl_size *= 2;
2247 if (specpdl_size > max_specpdl_size)
2248 specpdl_size = max_specpdl_size;
2249 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
2250 specpdl_ptr = specpdl + count;
2251}
2252
2253void
2254specbind (symbol, value)
2255 Lisp_Object symbol, value;
2256{
2257 extern void store_symval_forwarding (); /* in eval.c */
2258 Lisp_Object ovalue;
2259
9ffa21d4
JB
2260 CHECK_SYMBOL (symbol, 0);
2261
db9f0278
JB
2262 if (specpdl_ptr == specpdl + specpdl_size)
2263 grow_specpdl ();
2264 specpdl_ptr->symbol = symbol;
2265 specpdl_ptr->func = 0;
d0f7cdc8 2266 specpdl_ptr->old_value = ovalue = find_symbol_value (symbol);
db9f0278
JB
2267 specpdl_ptr++;
2268 if (XTYPE (ovalue) == Lisp_Buffer_Objfwd)
2269 store_symval_forwarding (symbol, ovalue, value);
2270 else
2271 Fset (symbol, value);
2272}
2273
2274void
2275record_unwind_protect (function, arg)
2276 Lisp_Object (*function)();
2277 Lisp_Object arg;
2278{
2279 if (specpdl_ptr == specpdl + specpdl_size)
2280 grow_specpdl ();
2281 specpdl_ptr->func = function;
2282 specpdl_ptr->symbol = Qnil;
2283 specpdl_ptr->old_value = arg;
2284 specpdl_ptr++;
2285}
2286
2287Lisp_Object
2288unbind_to (count, value)
2289 int count;
2290 Lisp_Object value;
2291{
265a9e55 2292 int quitf = !NILP (Vquit_flag);
db9f0278
JB
2293 struct gcpro gcpro1;
2294
2295 GCPRO1 (value);
2296
2297 Vquit_flag = Qnil;
2298
2299 while (specpdl_ptr != specpdl + count)
2300 {
2301 --specpdl_ptr;
2302 if (specpdl_ptr->func != 0)
2303 (*specpdl_ptr->func) (specpdl_ptr->old_value);
2304 /* Note that a "binding" of nil is really an unwind protect,
2305 so in that case the "old value" is a list of forms to evaluate. */
265a9e55 2306 else if (NILP (specpdl_ptr->symbol))
db9f0278
JB
2307 Fprogn (specpdl_ptr->old_value);
2308 else
2309 Fset (specpdl_ptr->symbol, specpdl_ptr->old_value);
2310 }
265a9e55 2311 if (NILP (Vquit_flag) && quitf) Vquit_flag = Qt;
db9f0278
JB
2312
2313 UNGCPRO;
2314
2315 return value;
2316}
2317\f
2318#if 0
2319
2320/* Get the value of symbol's global binding, even if that binding
2321 is not now dynamically visible. */
2322
2323Lisp_Object
2324top_level_value (symbol)
2325 Lisp_Object symbol;
2326{
2327 register struct specbinding *ptr = specpdl;
2328
2329 CHECK_SYMBOL (symbol, 0);
2330 for (; ptr != specpdl_ptr; ptr++)
2331 {
2332 if (EQ (ptr->symbol, symbol))
2333 return ptr->old_value;
2334 }
2335 return Fsymbol_value (symbol);
2336}
2337
2338Lisp_Object
2339top_level_set (symbol, newval)
2340 Lisp_Object symbol, newval;
2341{
2342 register struct specbinding *ptr = specpdl;
2343
2344 CHECK_SYMBOL (symbol, 0);
2345 for (; ptr != specpdl_ptr; ptr++)
2346 {
2347 if (EQ (ptr->symbol, symbol))
2348 {
2349 ptr->old_value = newval;
2350 return newval;
2351 }
2352 }
2353 return Fset (symbol, newval);
2354}
2355
2356#endif /* 0 */
2357\f
2358DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
2359 "Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.\n\
2360The debugger is entered when that frame exits, if the flag is non-nil.")
2361 (level, flag)
2362 Lisp_Object level, flag;
2363{
2364 register struct backtrace *backlist = backtrace_list;
2365 register int i;
2366
2367 CHECK_NUMBER (level, 0);
2368
2369 for (i = 0; backlist && i < XINT (level); i++)
2370 {
2371 backlist = backlist->next;
2372 }
2373
2374 if (backlist)
265a9e55 2375 backlist->debug_on_exit = !NILP (flag);
db9f0278
JB
2376
2377 return flag;
2378}
2379
2380DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
2381 "Print a trace of Lisp function calls currently active.\n\
2382Output stream used is value of `standard-output'.")
2383 ()
2384{
2385 register struct backtrace *backlist = backtrace_list;
2386 register int i;
2387 Lisp_Object tail;
2388 Lisp_Object tem;
2389 extern Lisp_Object Vprint_level;
2390 struct gcpro gcpro1;
2391
db9f0278
JB
2392 XFASTINT (Vprint_level) = 3;
2393
2394 tail = Qnil;
2395 GCPRO1 (tail);
2396
2397 while (backlist)
2398 {
2399 write_string (backlist->debug_on_exit ? "* " : " ", 2);
2400 if (backlist->nargs == UNEVALLED)
2401 {
2402 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
2403 }
2404 else
2405 {
2406 tem = *backlist->function;
2407 Fprin1 (tem, Qnil); /* This can QUIT */
2408 write_string ("(", -1);
2409 if (backlist->nargs == MANY)
2410 {
2411 for (tail = *backlist->args, i = 0;
265a9e55 2412 !NILP (tail);
db9f0278
JB
2413 tail = Fcdr (tail), i++)
2414 {
2415 if (i) write_string (" ", -1);
2416 Fprin1 (Fcar (tail), Qnil);
2417 }
2418 }
2419 else
2420 {
2421 for (i = 0; i < backlist->nargs; i++)
2422 {
2423 if (i) write_string (" ", -1);
2424 Fprin1 (backlist->args[i], Qnil);
2425 }
2426 }
2427 }
2428 write_string (")\n", -1);
2429 backlist = backlist->next;
2430 }
2431
2432 Vprint_level = Qnil;
2433 UNGCPRO;
2434 return Qnil;
2435}
2436
2437DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, "",
2438 "Return the function and arguments N frames up from current execution point.\n\
2439If that frame has not evaluated the arguments yet (or is a special form),\n\
2440the value is (nil FUNCTION ARG-FORMS...).\n\
2441If that frame has evaluated its arguments and called its function already,\n\
2442the value is (t FUNCTION ARG-VALUES...).\n\
2443A &rest arg is represented as the tail of the list ARG-VALUES.\n\
2444FUNCTION is whatever was supplied as car of evaluated list,\n\
2445or a lambda expression for macro calls.\n\
2446If N is more than the number of frames, the value is nil.")
2447 (nframes)
2448 Lisp_Object nframes;
2449{
2450 register struct backtrace *backlist = backtrace_list;
2451 register int i;
2452 Lisp_Object tem;
2453
2454 CHECK_NATNUM (nframes, 0);
2455
2456 /* Find the frame requested. */
2457 for (i = 0; i < XFASTINT (nframes); i++)
2458 backlist = backlist->next;
2459
2460 if (!backlist)
2461 return Qnil;
2462 if (backlist->nargs == UNEVALLED)
2463 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
2464 else
2465 {
2466 if (backlist->nargs == MANY)
2467 tem = *backlist->args;
2468 else
2469 tem = Flist (backlist->nargs, backlist->args);
2470
2471 return Fcons (Qt, Fcons (*backlist->function, tem));
2472 }
2473}
2474\f
2475syms_of_eval ()
2476{
2477 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
2478 "Limit on number of Lisp variable bindings & unwind-protects before error.");
2479
2480 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
2481 "Limit on depth in `eval', `apply' and `funcall' before error.\n\
2482This limit is to catch infinite recursions for you before they cause\n\
2483actual stack overflow in C, which would be fatal for Emacs.\n\
2484You can safely make it considerably larger than its default value,\n\
2485if that proves inconveniently small.");
2486
2487 DEFVAR_LISP ("quit-flag", &Vquit_flag,
2488 "Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.\n\
2489Typing C-G sets `quit-flag' non-nil, regardless of `inhibit-quit'.");
2490 Vquit_flag = Qnil;
2491
2492 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
2493 "Non-nil inhibits C-g quitting from happening immediately.\n\
2494Note that `quit-flag' will still be set by typing C-g,\n\
2495so a quit will be signalled as soon as `inhibit-quit' is nil.\n\
2496To prevent this happening, set `quit-flag' to nil\n\
2497before making `inhibit-quit' nil.");
2498 Vinhibit_quit = Qnil;
2499
ad236261
JB
2500 Qinhibit_quit = intern ("inhibit-quit");
2501 staticpro (&Qinhibit_quit);
2502
db9f0278
JB
2503 Qautoload = intern ("autoload");
2504 staticpro (&Qautoload);
2505
2506 Qdebug_on_error = intern ("debug-on-error");
2507 staticpro (&Qdebug_on_error);
2508
2509 Qmacro = intern ("macro");
2510 staticpro (&Qmacro);
2511
2512 /* Note that the process handling also uses Qexit, but we don't want
2513 to staticpro it twice, so we just do it here. */
2514 Qexit = intern ("exit");
2515 staticpro (&Qexit);
2516
2517 Qinteractive = intern ("interactive");
2518 staticpro (&Qinteractive);
2519
2520 Qcommandp = intern ("commandp");
2521 staticpro (&Qcommandp);
2522
2523 Qdefun = intern ("defun");
2524 staticpro (&Qdefun);
2525
2526 Qand_rest = intern ("&rest");
2527 staticpro (&Qand_rest);
2528
2529 Qand_optional = intern ("&optional");
2530 staticpro (&Qand_optional);
2531
128c0f66 2532 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
db9f0278 2533 "*Non-nil means automatically display a backtrace buffer\n\
128c0f66
RM
2534after any error that is handled by the editor command loop.\n\
2535If the value is a list, an error only means to display a backtrace\n\
2536if one of its condition symbols appears in the list.");
2537 Vstack_trace_on_error = Qnil;
db9f0278 2538
128c0f66 2539 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
db9f0278
JB
2540 "*Non-nil means enter debugger if an error is signaled.\n\
2541Does not apply to errors handled by `condition-case'.\n\
128c0f66
RM
2542If the value is a list, an error only means to enter the debugger\n\
2543if one of its condition symbols appears in the list.\n\
db9f0278 2544See also variable `debug-on-quit'.");
128c0f66 2545 Vdebug_on_error = Qnil;
db9f0278
JB
2546
2547 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
2548 "*Non-nil means enter debugger if quit is signaled (C-G, for example).\n\
1b7d8239 2549Does not apply if quit is handled by a `condition-case'.");
db9f0278
JB
2550 debug_on_quit = 0;
2551
2552 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
2553 "Non-nil means enter debugger before next `eval', `apply' or `funcall'.");
2554
2555 DEFVAR_LISP ("debugger", &Vdebugger,
2556 "Function to call to invoke debugger.\n\
2557If due to frame exit, args are `exit' and the value being returned;\n\
2558 this function's value will be returned instead of that.\n\
2559If due to error, args are `error' and a list of the args to `signal'.\n\
2560If due to `apply' or `funcall' entry, one arg, `lambda'.\n\
2561If due to `eval' entry, one arg, t.");
2562 Vdebugger = Qnil;
2563
2564 Qmocklisp_arguments = intern ("mocklisp-arguments");
2565 staticpro (&Qmocklisp_arguments);
2566 DEFVAR_LISP ("mocklisp-arguments", &Vmocklisp_arguments,
2567 "While in a mocklisp function, the list of its unevaluated args.");
2568 Vmocklisp_arguments = Qt;
2569
2570 DEFVAR_LISP ("run-hooks", &Vrun_hooks,
2571 "Set to the function `run-hooks', if that function has been defined.\n\
2572Otherwise, nil (in a bare Emacs without preloaded Lisp code).");
2573 Vrun_hooks = Qnil;
2574
2575 staticpro (&Vautoload_queue);
2576 Vautoload_queue = Qnil;
2577
2578 defsubr (&Sor);
2579 defsubr (&Sand);
2580 defsubr (&Sif);
2581 defsubr (&Scond);
2582 defsubr (&Sprogn);
2583 defsubr (&Sprog1);
2584 defsubr (&Sprog2);
2585 defsubr (&Ssetq);
2586 defsubr (&Squote);
2587 defsubr (&Sfunction);
2588 defsubr (&Sdefun);
2589 defsubr (&Sdefmacro);
2590 defsubr (&Sdefvar);
2591 defsubr (&Sdefconst);
2592 defsubr (&Suser_variable_p);
2593 defsubr (&Slet);
2594 defsubr (&SletX);
2595 defsubr (&Swhile);
2596 defsubr (&Smacroexpand);
2597 defsubr (&Scatch);
2598 defsubr (&Sthrow);
2599 defsubr (&Sunwind_protect);
2600 defsubr (&Scondition_case);
2601 defsubr (&Ssignal);
2602 defsubr (&Sinteractive_p);
2603 defsubr (&Scommandp);
2604 defsubr (&Sautoload);
2605 defsubr (&Seval);
2606 defsubr (&Sapply);
2607 defsubr (&Sfuncall);
2608 defsubr (&Sbacktrace_debug);
2609 defsubr (&Sbacktrace);
2610 defsubr (&Sbacktrace_frame);
2611}