Don't macro-inline non-performance-critical code.
[bpt/emacs.git] / src / eval.c
CommitLineData
db9f0278 1/* Evaluator for GNU Emacs Lisp interpreter.
73b0cd50 2 Copyright (C) 1985-1987, 1993-1995, 1999-2011 Free Software Foundation, Inc.
db9f0278
JB
3
4This file is part of GNU Emacs.
5
9ec0b715 6GNU Emacs is free software: you can redistribute it and/or modify
db9f0278 7it under the terms of the GNU General Public License as published by
9ec0b715
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
db9f0278
JB
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
9ec0b715 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
db9f0278
JB
18
19
18160b98 20#include <config.h>
eb3f1cc8 21#include <limits.h>
d7306fe6 22#include <setjmp.h>
4e2fe2e6 23#include <stdio.h>
db9f0278 24#include "lisp.h"
9ac0d9e0 25#include "blockinput.h"
db9f0278 26#include "commands.h"
1f98fa48 27#include "keyboard.h"
3648c842 28#include "dispextern.h"
94b612ad 29#include "frame.h" /* For XFRAME. */
db9f0278 30
b70e1a2b
SM
31#if HAVE_X_WINDOWS
32#include "xterm.h"
33#endif
34
db9f0278 35struct backtrace
4c576a83
GM
36{
37 struct backtrace *next;
38 Lisp_Object *function;
f6d62986 39 Lisp_Object *args; /* Points to vector of args. */
bbc6b304 40 ptrdiff_t nargs; /* Length of vector. */
f6d62986 41 /* Nonzero means call value of debugger when done with this operation. */
bbc6b304 42 unsigned int debug_on_exit : 1;
4c576a83 43};
db9f0278 44
57a96f5c 45static struct backtrace *backtrace_list;
244ed907
PE
46
47#if !BYTE_MARK_STACK
48static
49#endif
db9f0278
JB
50struct catchtag *catchlist;
51
244ed907
PE
52/* Chain of condition handlers currently in effect.
53 The elements of this chain are contained in the stack frames
54 of Fcondition_case and internal_condition_case.
55 When an error is signaled (by calling Fsignal, below),
56 this chain is searched for an element that applies. */
57
58#if !BYTE_MARK_STACK
59static
60#endif
61struct handler *handlerlist;
62
15934ffa
RS
63#ifdef DEBUG_GCPRO
64/* Count levels of GCPRO to detect failure to UNGCPRO. */
65int gcpro_level;
66#endif
67
6fd797f5 68Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
29208e82 69Lisp_Object Qinhibit_quit;
955cbe7b
PE
70Lisp_Object Qand_rest;
71static Lisp_Object Qand_optional;
72static Lisp_Object Qdebug_on_error;
73static Lisp_Object Qdeclare;
b9598260
SM
74Lisp_Object Qinternal_interpreter_environment, Qclosure;
75
ed008a6d 76static Lisp_Object Qdebug;
db9f0278 77
6e6e9f08
RS
78/* This holds either the symbol `run-hooks' or nil.
79 It is nil at an early stage of startup, and when Emacs
80 is shutting down. */
4c576a83 81
db9f0278
JB
82Lisp_Object Vrun_hooks;
83
84/* Non-nil means record all fset's and provide's, to be undone
85 if the file being autoloaded is not fully loaded.
86 They are recorded by being consed onto the front of Vautoload_queue:
47b82df9 87 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
db9f0278
JB
88
89Lisp_Object Vautoload_queue;
90
91/* Current number of specbindings allocated in specpdl. */
4c576a83 92
5816888b 93EMACS_INT specpdl_size;
db9f0278
JB
94
95/* Pointer to beginning of specpdl. */
4c576a83 96
db9f0278
JB
97struct specbinding *specpdl;
98
99/* Pointer to first unused element in specpdl. */
4c576a83 100
ab837828 101struct specbinding *specpdl_ptr;
db9f0278 102
db9f0278 103/* Depth in Lisp evaluations and function calls. */
4c576a83 104
57a96f5c 105static EMACS_INT lisp_eval_depth;
db9f0278 106
be857679 107/* The value of num_nonmacro_input_events as of the last time we
82da7701 108 started to enter the debugger. If we decide to enter the debugger
be857679 109 again when this is still equal to num_nonmacro_input_events, then we
82da7701
JB
110 know that the debugger itself has an error, and we should just
111 signal the error instead of entering an infinite loop of debugger
112 invocations. */
4c576a83 113
57a96f5c 114static int when_entered_debugger;
db9f0278 115
a2ff3819
GM
116/* The function from which the last `signal' was called. Set in
117 Fsignal. */
118
119Lisp_Object Vsignaling_function;
120
4c576a83
GM
121/* Set to non-zero while processing X events. Checked in Feval to
122 make sure the Lisp interpreter isn't called from a signal handler,
123 which is unsafe because the interpreter isn't reentrant. */
124
125int handling_signal;
126
f66c7cf8 127static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
f57e2426 128static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN;
2f7c71a1 129static int interactive_p (int);
7200d79c 130static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args);
cd64ea1d 131static Lisp_Object Ffetch_bytecode (Lisp_Object);
873759d5 132\f
dfcf069d 133void
d3da34e0 134init_eval_once (void)
db9f0278 135{
98e8eae1
PE
136 enum { size = 50 };
137 specpdl = (struct specbinding *) xmalloc (size * sizeof (struct specbinding));
138 specpdl_size = size;
270e8074 139 specpdl_ptr = specpdl;
6588243d 140 /* Don't forget to update docs (lispref node "Local Variables"). */
c530e1c2 141 max_specpdl_size = 1300; /* 1000 is not enough for CEDET's c-by.el. */
d46f6bbb 142 max_lisp_eval_depth = 600;
34d470ba
RS
143
144 Vrun_hooks = Qnil;
db9f0278
JB
145}
146
dfcf069d 147void
d3da34e0 148init_eval (void)
db9f0278
JB
149{
150 specpdl_ptr = specpdl;
151 catchlist = 0;
152 handlerlist = 0;
153 backtrace_list = 0;
154 Vquit_flag = Qnil;
155 debug_on_next_call = 0;
156 lisp_eval_depth = 0;
87e21fbd 157#ifdef DEBUG_GCPRO
15934ffa 158 gcpro_level = 0;
87e21fbd 159#endif
be857679 160 /* This is less than the initial value of num_nonmacro_input_events. */
b5b911f9 161 when_entered_debugger = -1;
db9f0278
JB
162}
163
f6d62986 164/* Unwind-protect function used by call_debugger. */
9f5903bb
RS
165
166static Lisp_Object
d3da34e0 167restore_stack_limits (Lisp_Object data)
9f5903bb
RS
168{
169 max_specpdl_size = XINT (XCAR (data));
170 max_lisp_eval_depth = XINT (XCDR (data));
538f78c3 171 return Qnil;
9f5903bb
RS
172}
173
174/* Call the Lisp debugger, giving it argument ARG. */
175
475545b5 176static Lisp_Object
d3da34e0 177call_debugger (Lisp_Object arg)
db9f0278 178{
3648c842 179 int debug_while_redisplaying;
aed13378 180 int count = SPECPDL_INDEX ();
3648c842 181 Lisp_Object val;
5816888b 182 EMACS_INT old_max = max_specpdl_size;
177c0ea7 183
9f5903bb
RS
184 /* Temporarily bump up the stack limits,
185 so the debugger won't run out of stack. */
177c0ea7 186
9f5903bb
RS
187 max_specpdl_size += 1;
188 record_unwind_protect (restore_stack_limits,
189 Fcons (make_number (old_max),
190 make_number (max_lisp_eval_depth)));
191 max_specpdl_size = old_max;
192
193 if (lisp_eval_depth + 40 > max_lisp_eval_depth)
194 max_lisp_eval_depth = lisp_eval_depth + 40;
195
98e8eae1 196 if (max_specpdl_size - 100 < SPECPDL_INDEX ())
9f5903bb 197 max_specpdl_size = SPECPDL_INDEX () + 100;
177c0ea7 198
d148e14d 199#ifdef HAVE_WINDOW_SYSTEM
df6c90d8
GM
200 if (display_hourglass_p)
201 cancel_hourglass ();
237c23b0
GM
202#endif
203
db9f0278 204 debug_on_next_call = 0;
be857679 205 when_entered_debugger = num_nonmacro_input_events;
3648c842
GM
206
207 /* Resetting redisplaying_p to 0 makes sure that debug output is
208 displayed if the debugger is invoked during redisplay. */
209 debug_while_redisplaying = redisplaying_p;
210 redisplaying_p = 0;
556d7314
GM
211 specbind (intern ("debugger-may-continue"),
212 debug_while_redisplaying ? Qnil : Qt);
8efb6cc7 213 specbind (Qinhibit_redisplay, Qnil);
9f5903bb 214 specbind (Qdebug_on_error, Qnil);
9db6f6b4
GM
215
216#if 0 /* Binding this prevents execution of Lisp code during
217 redisplay, which necessarily leads to display problems. */
8efb6cc7 218 specbind (Qinhibit_eval_during_redisplay, Qt);
9db6f6b4 219#endif
177c0ea7 220
3648c842
GM
221 val = apply1 (Vdebugger, arg);
222
223 /* Interrupting redisplay and resuming it later is not safe under
224 all circumstances. So, when the debugger returns, abort the
1b1acc13 225 interrupted redisplay by going back to the top-level. */
3648c842
GM
226 if (debug_while_redisplaying)
227 Ftop_level ();
228
556d7314 229 return unbind_to (count, val);
db9f0278
JB
230}
231
475545b5 232static void
d3da34e0 233do_debug_on_call (Lisp_Object code)
db9f0278
JB
234{
235 debug_on_next_call = 0;
236 backtrace_list->debug_on_exit = 1;
237 call_debugger (Fcons (code, Qnil));
238}
239\f
240/* NOTE!!! Every function that can call EVAL must protect its args
241 and temporaries from garbage collection while it needs them.
242 The definition of `For' shows what you have to do. */
243
244DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
9dbc9081
PJ
245 doc: /* Eval args until one of them yields non-nil, then return that value.
246The remaining args are not evalled at all.
247If all args return nil, return nil.
533eb34b 248usage: (or CONDITIONS...) */)
5842a27b 249 (Lisp_Object args)
db9f0278 250{
e509f168 251 register Lisp_Object val = Qnil;
db9f0278
JB
252 struct gcpro gcpro1;
253
e509f168 254 GCPRO1 (args);
db9f0278 255
e509f168 256 while (CONSP (args))
db9f0278 257 {
defb1411 258 val = eval_sub (XCAR (args));
265a9e55 259 if (!NILP (val))
db9f0278 260 break;
e509f168 261 args = XCDR (args);
db9f0278 262 }
db9f0278
JB
263
264 UNGCPRO;
265 return val;
266}
267
268DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
b8de5714 269 doc: /* Eval args until one of them yields nil, then return nil.
9dbc9081
PJ
270The remaining args are not evalled at all.
271If no arg yields nil, return the last arg's value.
533eb34b 272usage: (and CONDITIONS...) */)
5842a27b 273 (Lisp_Object args)
db9f0278 274{
e509f168 275 register Lisp_Object val = Qt;
db9f0278
JB
276 struct gcpro gcpro1;
277
e509f168 278 GCPRO1 (args);
db9f0278 279
e509f168 280 while (CONSP (args))
db9f0278 281 {
defb1411 282 val = eval_sub (XCAR (args));
265a9e55 283 if (NILP (val))
db9f0278 284 break;
e509f168 285 args = XCDR (args);
db9f0278 286 }
db9f0278
JB
287
288 UNGCPRO;
289 return val;
290}
291
292DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
b8de5714 293 doc: /* If COND yields non-nil, do THEN, else do ELSE...
9dbc9081
PJ
294Returns the value of THEN or the value of the last of the ELSE's.
295THEN must be one expression, but ELSE... can be zero or more expressions.
296If COND yields nil, and there are no ELSE's, the value is nil.
7a25dc6d 297usage: (if COND THEN ELSE...) */)
5842a27b 298 (Lisp_Object args)
db9f0278
JB
299{
300 register Lisp_Object cond;
301 struct gcpro gcpro1;
302
303 GCPRO1 (args);
defb1411 304 cond = eval_sub (Fcar (args));
db9f0278
JB
305 UNGCPRO;
306
265a9e55 307 if (!NILP (cond))
defb1411 308 return eval_sub (Fcar (Fcdr (args)));
db9f0278
JB
309 return Fprogn (Fcdr (Fcdr (args)));
310}
311
312DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
9dbc9081
PJ
313 doc: /* Try each clause until one succeeds.
314Each clause looks like (CONDITION BODY...). CONDITION is evaluated
315and, if the value is non-nil, this clause succeeds:
316then the expressions in BODY are evaluated and the last one's
317value is the value of the cond-form.
318If no clause succeeds, cond returns nil.
319If a clause has one element, as in (CONDITION),
320CONDITION's value if non-nil is returned from the cond-form.
7a25dc6d 321usage: (cond CLAUSES...) */)
5842a27b 322 (Lisp_Object args)
db9f0278
JB
323{
324 register Lisp_Object clause, val;
325 struct gcpro gcpro1;
326
327 val = Qnil;
328 GCPRO1 (args);
265a9e55 329 while (!NILP (args))
db9f0278
JB
330 {
331 clause = Fcar (args);
defb1411 332 val = eval_sub (Fcar (clause));
265a9e55 333 if (!NILP (val))
db9f0278 334 {
03699b14
KR
335 if (!EQ (XCDR (clause), Qnil))
336 val = Fprogn (XCDR (clause));
db9f0278
JB
337 break;
338 }
03699b14 339 args = XCDR (args);
db9f0278
JB
340 }
341 UNGCPRO;
342
343 return val;
344}
345
a7ca3326 346DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
9dbc9081 347 doc: /* Eval BODY forms sequentially and return value of last one.
5b4a1f50 348usage: (progn BODY...) */)
5842a27b 349 (Lisp_Object args)
db9f0278 350{
e509f168 351 register Lisp_Object val = Qnil;
db9f0278
JB
352 struct gcpro gcpro1;
353
e509f168 354 GCPRO1 (args);
db9f0278 355
e509f168 356 while (CONSP (args))
db9f0278 357 {
defb1411 358 val = eval_sub (XCAR (args));
e509f168 359 args = XCDR (args);
db9f0278 360 }
db9f0278
JB
361
362 UNGCPRO;
363 return val;
364}
365
366DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
bdee2ef3 367 doc: /* Eval FIRST and BODY sequentially; return value from FIRST.
9dbc9081
PJ
368The value of FIRST is saved during the evaluation of the remaining args,
369whose values are discarded.
7a25dc6d 370usage: (prog1 FIRST BODY...) */)
5842a27b 371 (Lisp_Object args)
db9f0278
JB
372{
373 Lisp_Object val;
374 register Lisp_Object args_left;
375 struct gcpro gcpro1, gcpro2;
376 register int argnum = 0;
377
9ac66b45 378 if (NILP (args))
db9f0278
JB
379 return Qnil;
380
381 args_left = args;
382 val = Qnil;
383 GCPRO2 (args, val);
384
385 do
386 {
ba83908c 387 Lisp_Object tem = eval_sub (XCAR (args_left));
db9f0278 388 if (!(argnum++))
ba83908c
SM
389 val = tem;
390 args_left = XCDR (args_left);
db9f0278 391 }
ba83908c 392 while (CONSP (args_left));
db9f0278
JB
393
394 UNGCPRO;
395 return val;
396}
397
398DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
bdee2ef3 399 doc: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
82fc29a1
JB
400The value of FORM2 is saved during the evaluation of the
401remaining args, whose values are discarded.
402usage: (prog2 FORM1 FORM2 BODY...) */)
5842a27b 403 (Lisp_Object args)
db9f0278
JB
404{
405 Lisp_Object val;
406 register Lisp_Object args_left;
407 struct gcpro gcpro1, gcpro2;
408 register int argnum = -1;
409
410 val = Qnil;
411
87d238ba 412 if (NILP (args))
db9f0278
JB
413 return Qnil;
414
415 args_left = args;
416 val = Qnil;
417 GCPRO2 (args, val);
418
419 do
420 {
ba83908c 421 Lisp_Object tem = eval_sub (XCAR (args_left));
db9f0278 422 if (!(argnum++))
ba83908c
SM
423 val = tem;
424 args_left = XCDR (args_left);
db9f0278 425 }
ba83908c 426 while (CONSP (args_left));
db9f0278
JB
427
428 UNGCPRO;
429 return val;
430}
431
432DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
9dbc9081
PJ
433 doc: /* Set each SYM to the value of its VAL.
434The symbols SYM are variables; they are literal (not evaluated).
435The values VAL are expressions; they are evaluated.
436Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
437The second VAL is not computed until after the first SYM is set, and so on;
438each VAL can use the new value of variables set earlier in the `setq'.
439The return value of the `setq' form is the value of the last VAL.
819586b2 440usage: (setq [SYM VAL]...) */)
5842a27b 441 (Lisp_Object args)
db9f0278
JB
442{
443 register Lisp_Object args_left;
b9598260 444 register Lisp_Object val, sym, lex_binding;
db9f0278
JB
445 struct gcpro gcpro1;
446
1283140e 447 if (NILP (args))
db9f0278
JB
448 return Qnil;
449
450 args_left = args;
451 GCPRO1 (args);
452
453 do
454 {
defb1411 455 val = eval_sub (Fcar (Fcdr (args_left)));
db9f0278 456 sym = Fcar (args_left);
b9598260 457
defb1411 458 /* Like for eval_sub, we do not check declared_special here since
f07a954e
SM
459 it's been done when let-binding. */
460 if (!NILP (Vinternal_interpreter_environment) /* Mere optimization! */
b9598260 461 && SYMBOLP (sym)
f07a954e
SM
462 && !NILP (lex_binding
463 = Fassq (sym, Vinternal_interpreter_environment)))
b9598260
SM
464 XSETCDR (lex_binding, val); /* SYM is lexically bound. */
465 else
466 Fset (sym, val); /* SYM is dynamically bound. */
467
db9f0278
JB
468 args_left = Fcdr (Fcdr (args_left));
469 }
5e617bc2 470 while (!NILP (args_left));
db9f0278
JB
471
472 UNGCPRO;
473 return val;
474}
177c0ea7 475
db9f0278 476DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
9dbc9081 477 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
91a15bc6
SM
478Warning: `quote' does not construct its return value, but just returns
479the value that was pre-constructed by the Lisp reader (see info node
480`(elisp)Printed Representation').
481This means that '(a . b) is not identical to (cons 'a 'b): the former
482does not cons. Quoting should be reserved for constants that will
483never be modified by side-effects, unless you like self-modifying code.
484See the common pitfall in info node `(elisp)Rearrangement' for an example
485of unexpected results when a quoted object is modified.
9dbc9081 486usage: (quote ARG) */)
5842a27b 487 (Lisp_Object args)
db9f0278 488{
1283140e
RS
489 if (!NILP (Fcdr (args)))
490 xsignal2 (Qwrong_number_of_arguments, Qquote, Flength (args));
db9f0278
JB
491 return Fcar (args);
492}
177c0ea7 493
db9f0278 494DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
9dbc9081
PJ
495 doc: /* Like `quote', but preferred for objects which are functions.
496In byte compilation, `function' causes its argument to be compiled.
497`quote' cannot do that.
498usage: (function ARG) */)
5842a27b 499 (Lisp_Object args)
db9f0278 500{
b9598260
SM
501 Lisp_Object quoted = XCAR (args);
502
1283140e
RS
503 if (!NILP (Fcdr (args)))
504 xsignal2 (Qwrong_number_of_arguments, Qfunction, Flength (args));
b9598260
SM
505
506 if (!NILP (Vinternal_interpreter_environment)
507 && CONSP (quoted)
508 && EQ (XCAR (quoted), Qlambda))
509 /* This is a lambda expression within a lexical environment;
510 return an interpreted closure instead of a simple lambda. */
23aba0ea
SM
511 return Fcons (Qclosure, Fcons (Vinternal_interpreter_environment,
512 XCDR (quoted)));
b9598260
SM
513 else
514 /* Simply quote the argument. */
515 return quoted;
db9f0278
JB
516}
517
e0f331ab 518
a7ca3326 519DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
84b17ab0 520 doc: /* Return t if the containing function was run directly by user input.
82fc29a1
JB
521This means that the function was called with `call-interactively'
522\(which includes being called as the binding of a key)
84b17ab0 523and input is currently coming from the keyboard (not a keyboard macro),
c63df42b
RS
524and Emacs is not running in batch mode (`noninteractive' is nil).
525
526The only known proper use of `interactive-p' is in deciding whether to
527display a helpful message, or how to display it. If you're thinking
528of using it for any other purpose, it is quite likely that you're
529making a mistake. Think: what do you want to do when the command is
530called from a keyboard macro?
531
84b17ab0
CY
532To test whether your function was called with `call-interactively',
533either (i) add an extra optional argument and give it an `interactive'
534spec that specifies non-nil unconditionally (such as \"p\"); or (ii)
535use `called-interactively-p'. */)
5842a27b 536 (void)
db9f0278 537{
b9598260 538 return interactive_p (1) ? Qt : Qnil;
e0f331ab
GM
539}
540
541
9d28c33e 542DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 1, 0,
84b17ab0 543 doc: /* Return t if the containing function was called by `call-interactively'.
9d28c33e
SM
544If KIND is `interactive', then only return t if the call was made
545interactively by the user, i.e. not in `noninteractive' mode nor
546when `executing-kbd-macro'.
547If KIND is `any', on the other hand, it will return t for any kind of
548interactive call, including being called as the binding of a key, or
549from a keyboard macro, or in `noninteractive' mode.
550
551The only known proper use of `interactive' for KIND is in deciding
552whether to display a helpful message, or how to display it. If you're
553thinking of using it for any other purpose, it is quite likely that
554you're making a mistake. Think: what do you want to do when the
555command is called from a keyboard macro?
84b17ab0
CY
556
557This function is meant for implementing advice and other
558function-modifying features. Instead of using this, it is sometimes
559cleaner to give your function an extra optional argument whose
560`interactive' spec specifies non-nil unconditionally (\"p\" is a good
9d28c33e 561way to do this), or via (not (or executing-kbd-macro noninteractive)). */)
5842a27b 562 (Lisp_Object kind)
c63df42b 563{
9d28c33e
SM
564 return ((INTERACTIVE || !EQ (kind, intern ("interactive")))
565 && interactive_p (1)) ? Qt : Qnil;
c63df42b
RS
566}
567
568
569/* Return 1 if function in which this appears was called using
570 call-interactively.
e0f331ab
GM
571
572 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
573 called is a built-in. */
574
2f7c71a1 575static int
d3da34e0 576interactive_p (int exclude_subrs_p)
e0f331ab
GM
577{
578 struct backtrace *btp;
579 Lisp_Object fun;
db9f0278 580
db9f0278 581 btp = backtrace_list;
daa37602
JB
582
583 /* If this isn't a byte-compiled function, there may be a frame at
e0f331ab 584 the top for Finteractive_p. If so, skip it. */
a7f96a35 585 fun = Findirect_function (*btp->function, Qnil);
0b31741c
RS
586 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
587 || XSUBR (fun) == &Scalled_interactively_p))
db9f0278 588 btp = btp->next;
daa37602
JB
589
590 /* If we're running an Emacs 18-style byte-compiled function, there
4402a9ed
RS
591 may be a frame for Fbytecode at the top level. In any version of
592 Emacs there can be Fbytecode frames for subexpressions evaluated
593 inside catch and condition-case. Skip past them.
daa37602 594
4402a9ed 595 If this isn't a byte-compiled function, then we may now be
daa37602 596 looking at several frames for special forms. Skip past them. */
4402a9ed
RS
597 while (btp
598 && (EQ (*btp->function, Qbytecode)
44f230aa 599 || btp->nargs == UNEVALLED))
a6e3fa71
JB
600 btp = btp->next;
601
f6d62986 602 /* `btp' now points at the frame of the innermost function that isn't
daa37602
JB
603 a special form, ignoring frames for Finteractive_p and/or
604 Fbytecode at the top. If this frame is for a built-in function
605 (such as load or eval-region) return nil. */
a7f96a35 606 fun = Findirect_function (*btp->function, Qnil);
e0f331ab
GM
607 if (exclude_subrs_p && SUBRP (fun))
608 return 0;
177c0ea7 609
f6d62986 610 /* `btp' points to the frame of a Lisp function that called interactive-p.
db9f0278
JB
611 Return t if that function was called interactively. */
612 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
e0f331ab
GM
613 return 1;
614 return 0;
db9f0278
JB
615}
616
e0f331ab 617
db9f0278 618DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
9dbc9081
PJ
619 doc: /* Define NAME as a function.
620The definition is (lambda ARGLIST [DOCSTRING] BODY...).
621See also the function `interactive'.
7a25dc6d 622usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
5842a27b 623 (Lisp_Object args)
db9f0278
JB
624{
625 register Lisp_Object fn_name;
626 register Lisp_Object defn;
627
628 fn_name = Fcar (args);
6992a868 629 CHECK_SYMBOL (fn_name);
db9f0278 630 defn = Fcons (Qlambda, Fcdr (args));
f07a954e
SM
631 if (!NILP (Vinternal_interpreter_environment)) /* Mere optimization! */
632 defn = Ffunction (Fcons (defn, Qnil));
265a9e55 633 if (!NILP (Vpurify_flag))
db9f0278 634 defn = Fpurecopy (defn);
f58e9f8c
RS
635 if (CONSP (XSYMBOL (fn_name)->function)
636 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
637 LOADHIST_ATTACH (Fcons (Qt, fn_name));
db9f0278 638 Ffset (fn_name, defn);
6fd797f5 639 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
db9f0278
JB
640 return fn_name;
641}
642
643DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
9dbc9081 644 doc: /* Define NAME as a macro.
0654d6e3
RS
645The actual definition looks like
646 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
9dbc9081
PJ
647When the macro is called, as in (NAME ARGS...),
648the function (lambda ARGLIST BODY...) is applied to
649the list ARGS... as it appears in the expression,
650and the result should be a form to be evaluated instead of the original.
0654d6e3
RS
651
652DECL is a declaration, optional, which can specify how to indent
4ba50634
JPW
653calls to this macro, how Edebug should handle it, and which argument
654should be treated as documentation. It looks like this:
0654d6e3
RS
655 (declare SPECS...)
656The elements can look like this:
657 (indent INDENT)
658 Set NAME's `lisp-indent-function' property to INDENT.
659
e509f168 660 (debug DEBUG)
0654d6e3 661 Set NAME's `edebug-form-spec' property to DEBUG. (This is
7d5c86e5 662 equivalent to writing a `def-edebug-spec' for the macro.)
4ba50634
JPW
663
664 (doc-string ELT)
665 Set NAME's `doc-string-elt' property to ELT.
666
0654d6e3 667usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
5842a27b 668 (Lisp_Object args)
db9f0278
JB
669{
670 register Lisp_Object fn_name;
671 register Lisp_Object defn;
d6edd563 672 Lisp_Object lambda_list, doc, tail;
db9f0278
JB
673
674 fn_name = Fcar (args);
8e975df9 675 CHECK_SYMBOL (fn_name);
d6edd563
GM
676 lambda_list = Fcar (Fcdr (args));
677 tail = Fcdr (Fcdr (args));
678
679 doc = Qnil;
680 if (STRINGP (Fcar (tail)))
681 {
e509f168
SM
682 doc = XCAR (tail);
683 tail = XCDR (tail);
d6edd563
GM
684 }
685
0193499f
SM
686 if (CONSP (Fcar (tail))
687 && EQ (Fcar (Fcar (tail)), Qdeclare))
d6edd563
GM
688 {
689 if (!NILP (Vmacro_declaration_function))
690 {
691 struct gcpro gcpro1;
692 GCPRO1 (args);
693 call2 (Vmacro_declaration_function, fn_name, Fcar (tail));
694 UNGCPRO;
695 }
177c0ea7 696
d6edd563
GM
697 tail = Fcdr (tail);
698 }
699
700 if (NILP (doc))
701 tail = Fcons (lambda_list, tail);
702 else
703 tail = Fcons (lambda_list, Fcons (doc, tail));
7200d79c 704
b9598260 705 defn = Fcons (Qlambda, tail);
f07a954e
SM
706 if (!NILP (Vinternal_interpreter_environment)) /* Mere optimization! */
707 defn = Ffunction (Fcons (defn, Qnil));
b9598260 708 defn = Fcons (Qmacro, defn);
177c0ea7 709
265a9e55 710 if (!NILP (Vpurify_flag))
db9f0278 711 defn = Fpurecopy (defn);
f58e9f8c
RS
712 if (CONSP (XSYMBOL (fn_name)->function)
713 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
714 LOADHIST_ATTACH (Fcons (Qt, fn_name));
db9f0278 715 Ffset (fn_name, defn);
6fd797f5 716 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
db9f0278
JB
717 return fn_name;
718}
719
19cebf5a 720
1848d15d 721DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
4a9308b8 722 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
e102f0d8 723Aliased variables always have the same value; setting one sets the other.
4a9308b8 724Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
dd60787c
GM
725omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
726or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
727itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
728then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
4a9308b8 729The return value is BASE-VARIABLE. */)
5842a27b 730 (Lisp_Object new_alias, Lisp_Object base_variable, Lisp_Object docstring)
19cebf5a
GM
731{
732 struct Lisp_Symbol *sym;
1848d15d 733
4a9308b8
JB
734 CHECK_SYMBOL (new_alias);
735 CHECK_SYMBOL (base_variable);
19cebf5a 736
4a9308b8 737 sym = XSYMBOL (new_alias);
ce5b453a
SM
738
739 if (sym->constant)
178f2507
SM
740 /* Not sure why, but why not? */
741 error ("Cannot make a constant an alias");
ce5b453a
SM
742
743 switch (sym->redirect)
744 {
745 case SYMBOL_FORWARDED:
746 error ("Cannot make an internal variable an alias");
747 case SYMBOL_LOCALIZED:
748 error ("Don't know how to make a localized variable an alias");
749 }
750
dd60787c 751 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
ce5b453a
SM
752 If n_a is bound, but b_v is not, set the value of b_v to n_a,
753 so that old-code that affects n_a before the aliasing is setup
754 still works. */
755 if (NILP (Fboundp (base_variable)))
94b612ad 756 set_internal (base_variable, find_symbol_value (new_alias), Qnil, 1);
ce5b453a
SM
757
758 {
759 struct specbinding *p;
760
761 for (p = specpdl_ptr - 1; p >= specpdl; p--)
762 if (p->func == NULL
763 && (EQ (new_alias,
764 CONSP (p->symbol) ? XCAR (p->symbol) : p->symbol)))
765 error ("Don't know how to make a let-bound variable an alias");
766 }
767
b9598260 768 sym->declared_special = 1;
0ac30604 769 XSYMBOL (base_variable)->declared_special = 1;
ce5b453a
SM
770 sym->redirect = SYMBOL_VARALIAS;
771 SET_SYMBOL_ALIAS (sym, XSYMBOL (base_variable));
4a9308b8
JB
772 sym->constant = SYMBOL_CONSTANT_P (base_variable);
773 LOADHIST_ATTACH (new_alias);
ce5b453a
SM
774 /* Even if docstring is nil: remove old docstring. */
775 Fput (new_alias, Qvariable_documentation, docstring);
1848d15d 776
4a9308b8 777 return base_variable;
19cebf5a
GM
778}
779
780
db9f0278 781DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
29357847 782 doc: /* Define SYMBOL as a variable, and return SYMBOL.
9dbc9081
PJ
783You are not required to define a variable in order to use it,
784but the definition can supply documentation and an initial value
785in a way that tags can recognize.
786
787INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
788If SYMBOL is buffer-local, its default value is what is set;
789 buffer-local values are not affected.
790INITVALUE and DOCSTRING are optional.
791If DOCSTRING starts with *, this variable is identified as a user option.
792 This means that M-x set-variable recognizes it.
793 See also `user-variable-p'.
794If INITVALUE is missing, SYMBOL's value is not set.
733f68b6
LT
795
796If SYMBOL has a local binding, then this form affects the local
797binding. This is usually not what you want. Thus, if you need to
798load a file defining variables, with this form or with `defconst' or
799`defcustom', you should always load that file _outside_ any bindings
800for these variables. \(`defconst' and `defcustom' behave similarly in
801this respect.)
2df5238c 802usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
5842a27b 803 (Lisp_Object args)
db9f0278 804{
a42ba017 805 register Lisp_Object sym, tem, tail;
db9f0278
JB
806
807 sym = Fcar (args);
a42ba017
RS
808 tail = Fcdr (args);
809 if (!NILP (Fcdr (Fcdr (tail))))
921baa95 810 error ("Too many arguments");
a42ba017 811
33568849 812 tem = Fdefault_boundp (sym);
a42ba017 813 if (!NILP (tail))
db9f0278 814 {
ba83908c
SM
815 /* Do it before evaluating the initial value, for self-references. */
816 XSYMBOL (sym)->declared_special = 1;
590130fb 817
1c9916a1
SM
818 if (SYMBOL_CONSTANT_P (sym))
819 {
820 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
1faed8ae
PE
821 Lisp_Object tem1 = Fcar (tail);
822 if (! (CONSP (tem1)
823 && EQ (XCAR (tem1), Qquote)
824 && CONSP (XCDR (tem1))
825 && EQ (XCAR (XCDR (tem1)), sym)))
1c9916a1
SM
826 error ("Constant symbol `%s' specified in defvar",
827 SDATA (SYMBOL_NAME (sym)));
828 }
829
265a9e55 830 if (NILP (tem))
defb1411 831 Fset_default (sym, eval_sub (Fcar (tail)));
d0bce91e
SM
832 else
833 { /* Check if there is really a global binding rather than just a let
834 binding that shadows the global unboundness of the var. */
b28d0d9a 835 volatile struct specbinding *pdl = specpdl_ptr;
d0bce91e
SM
836 while (--pdl >= specpdl)
837 {
838 if (EQ (pdl->symbol, sym) && !pdl->func
839 && EQ (pdl->old_value, Qunbound))
840 {
841 message_with_string ("Warning: defvar ignored because %s is let-bound",
842 SYMBOL_NAME (sym), 1);
843 break;
844 }
845 }
846 }
33568849 847 tail = Fcdr (tail);
e509f168
SM
848 tem = Fcar (tail);
849 if (!NILP (tem))
33568849 850 {
33568849
SM
851 if (!NILP (Vpurify_flag))
852 tem = Fpurecopy (tem);
853 Fput (sym, Qvariable_documentation, tem);
854 }
6fd797f5 855 LOADHIST_ATTACH (sym);
db9f0278 856 }
f07a954e
SM
857 else if (!NILP (Vinternal_interpreter_environment)
858 && !XSYMBOL (sym)->declared_special)
859 /* A simple (defvar foo) with lexical scoping does "nothing" except
860 declare that var to be dynamically scoped *locally* (i.e. within
861 the current file or let-block). */
862 Vinternal_interpreter_environment =
863 Fcons (sym, Vinternal_interpreter_environment);
33568849 864 else
d28a2170
PE
865 {
866 /* Simple (defvar <var>) should not count as a definition at all.
867 It could get in the way of other definitions, and unloading this
868 package could try to make the variable unbound. */
869 }
addf35fd 870
db9f0278
JB
871 return sym;
872}
873
874DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
9dbc9081
PJ
875 doc: /* Define SYMBOL as a constant variable.
876The intent is that neither programs nor users should ever change this value.
877Always sets the value of SYMBOL to the result of evalling INITVALUE.
878If SYMBOL is buffer-local, its default value is what is set;
879 buffer-local values are not affected.
880DOCSTRING is optional.
733f68b6
LT
881
882If SYMBOL has a local binding, then this form sets the local binding's
883value. However, you should normally not make local bindings for
884variables defined with this form.
7a25dc6d 885usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
5842a27b 886 (Lisp_Object args)
db9f0278
JB
887{
888 register Lisp_Object sym, tem;
889
890 sym = Fcar (args);
a42ba017 891 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
921baa95 892 error ("Too many arguments");
a42ba017 893
defb1411 894 tem = eval_sub (Fcar (Fcdr (args)));
1182a7cb
DL
895 if (!NILP (Vpurify_flag))
896 tem = Fpurecopy (tem);
897 Fset_default (sym, tem);
b9598260 898 XSYMBOL (sym)->declared_special = 1;
db9f0278 899 tem = Fcar (Fcdr (Fcdr (args)));
265a9e55 900 if (!NILP (tem))
db9f0278 901 {
265a9e55 902 if (!NILP (Vpurify_flag))
db9f0278
JB
903 tem = Fpurecopy (tem);
904 Fput (sym, Qvariable_documentation, tem);
905 }
873759d5 906 Fput (sym, Qrisky_local_variable, Qt);
6fd797f5 907 LOADHIST_ATTACH (sym);
db9f0278
JB
908 return sym;
909}
910
606cdb89
JB
911/* Error handler used in Fuser_variable_p. */
912static Lisp_Object
d3da34e0 913user_variable_p_eh (Lisp_Object ignore)
606cdb89
JB
914{
915 return Qnil;
916}
917
40a69fac
SM
918static Lisp_Object
919lisp_indirect_variable (Lisp_Object sym)
920{
cfcbfb1a
PE
921 struct Lisp_Symbol *s = indirect_variable (XSYMBOL (sym));
922 XSETSYMBOL (sym, s);
40a69fac
SM
923 return sym;
924}
925
db9f0278 926DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
606cdb89 927 doc: /* Return t if VARIABLE is intended to be set and modified by users.
9dbc9081 928\(The alternative is a variable used internally in a Lisp program.)
606cdb89
JB
929A variable is a user variable if
930\(1) the first character of its documentation is `*', or
931\(2) it is customizable (its property list contains a non-nil value
932 of `standard-value' or `custom-autoload'), or
933\(3) it is an alias for another user variable.
934Return nil if VARIABLE is an alias and there is a loop in the
935chain of symbols. */)
5842a27b 936 (Lisp_Object variable)
db9f0278
JB
937{
938 Lisp_Object documentation;
177c0ea7 939
5e78e475
RS
940 if (!SYMBOLP (variable))
941 return Qnil;
942
606cdb89 943 /* If indirect and there's an alias loop, don't check anything else. */
ce5b453a 944 if (XSYMBOL (variable)->redirect == SYMBOL_VARALIAS
40a69fac 945 && NILP (internal_condition_case_1 (lisp_indirect_variable, variable,
bb8e180f 946 Qt, user_variable_p_eh)))
606cdb89
JB
947 return Qnil;
948
949 while (1)
950 {
951 documentation = Fget (variable, Qvariable_documentation);
952 if (INTEGERP (documentation) && XINT (documentation) < 0)
bb8e180f 953 return Qt;
606cdb89 954 if (STRINGP (documentation)
bb8e180f
AS
955 && ((unsigned char) SREF (documentation, 0) == '*'))
956 return Qt;
606cdb89
JB
957 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
958 if (CONSP (documentation)
bb8e180f
AS
959 && STRINGP (XCAR (documentation))
960 && INTEGERP (XCDR (documentation))
961 && XINT (XCDR (documentation)) < 0)
962 return Qt;
606cdb89
JB
963 /* Customizable? See `custom-variable-p'. */
964 if ((!NILP (Fget (variable, intern ("standard-value"))))
bb8e180f
AS
965 || (!NILP (Fget (variable, intern ("custom-autoload")))))
966 return Qt;
606cdb89 967
ce5b453a 968 if (!(XSYMBOL (variable)->redirect == SYMBOL_VARALIAS))
bb8e180f 969 return Qnil;
606cdb89
JB
970
971 /* An indirect variable? Let's follow the chain. */
ce5b453a 972 XSETSYMBOL (variable, SYMBOL_ALIAS (XSYMBOL (variable)));
606cdb89 973 }
177c0ea7 974}
db9f0278
JB
975\f
976DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
9dbc9081
PJ
977 doc: /* Bind variables according to VARLIST then eval BODY.
978The value of the last form in BODY is returned.
979Each element of VARLIST is a symbol (which is bound to nil)
980or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
981Each VALUEFORM can refer to the symbols already bound by this VARLIST.
7a25dc6d 982usage: (let* VARLIST BODY...) */)
5842a27b 983 (Lisp_Object args)
db9f0278 984{
b9598260 985 Lisp_Object varlist, var, val, elt, lexenv;
aed13378 986 int count = SPECPDL_INDEX ();
db9f0278
JB
987 struct gcpro gcpro1, gcpro2, gcpro3;
988
989 GCPRO3 (args, elt, varlist);
990
b9598260
SM
991 lexenv = Vinternal_interpreter_environment;
992
db9f0278 993 varlist = Fcar (args);
b9598260 994 while (CONSP (varlist))
db9f0278
JB
995 {
996 QUIT;
b9598260
SM
997
998 elt = XCAR (varlist);
90165123 999 if (SYMBOLP (elt))
b9598260
SM
1000 {
1001 var = elt;
1002 val = Qnil;
1003 }
08564963 1004 else if (! NILP (Fcdr (Fcdr (elt))))
734d55a2 1005 signal_error ("`let' bindings can have only one value-form", elt);
db9f0278
JB
1006 else
1007 {
b9598260 1008 var = Fcar (elt);
defb1411 1009 val = eval_sub (Fcar (Fcdr (elt)));
db9f0278 1010 }
b9598260 1011
f07a954e
SM
1012 if (!NILP (lexenv) && SYMBOLP (var)
1013 && !XSYMBOL (var)->declared_special
1014 && NILP (Fmemq (var, Vinternal_interpreter_environment)))
b9598260
SM
1015 /* Lexically bind VAR by adding it to the interpreter's binding
1016 alist. */
1017 {
f07a954e
SM
1018 Lisp_Object newenv
1019 = Fcons (Fcons (var, val), Vinternal_interpreter_environment);
1020 if (EQ (Vinternal_interpreter_environment, lexenv))
1021 /* Save the old lexical environment on the specpdl stack,
1022 but only for the first lexical binding, since we'll never
1023 need to revert to one of the intermediate ones. */
1024 specbind (Qinternal_interpreter_environment, newenv);
1025 else
1026 Vinternal_interpreter_environment = newenv;
db9f0278 1027 }
b9598260
SM
1028 else
1029 specbind (var, val);
1030
1031 varlist = XCDR (varlist);
db9f0278
JB
1032 }
1033 UNGCPRO;
1034 val = Fprogn (Fcdr (args));
1035 return unbind_to (count, val);
1036}
1037
1038DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
9dbc9081
PJ
1039 doc: /* Bind variables according to VARLIST then eval BODY.
1040The value of the last form in BODY is returned.
1041Each element of VARLIST is a symbol (which is bound to nil)
1042or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1043All the VALUEFORMs are evalled before any symbols are bound.
7a25dc6d 1044usage: (let VARLIST BODY...) */)
5842a27b 1045 (Lisp_Object args)
db9f0278 1046{
b9598260 1047 Lisp_Object *temps, tem, lexenv;
db9f0278 1048 register Lisp_Object elt, varlist;
aed13378 1049 int count = SPECPDL_INDEX ();
f66c7cf8 1050 ptrdiff_t argnum;
db9f0278 1051 struct gcpro gcpro1, gcpro2;
3a7a9129 1052 USE_SAFE_ALLOCA;
db9f0278
JB
1053
1054 varlist = Fcar (args);
1055
f6d62986 1056 /* Make space to hold the values to give the bound variables. */
db9f0278 1057 elt = Flength (varlist);
b72e0717 1058 SAFE_ALLOCA_LISP (temps, XFASTINT (elt));
db9f0278 1059
f6d62986 1060 /* Compute the values and store them in `temps'. */
db9f0278
JB
1061
1062 GCPRO2 (args, *temps);
1063 gcpro2.nvars = 0;
1064
67ee9f6e 1065 for (argnum = 0; CONSP (varlist); varlist = XCDR (varlist))
db9f0278
JB
1066 {
1067 QUIT;
67ee9f6e 1068 elt = XCAR (varlist);
90165123 1069 if (SYMBOLP (elt))
db9f0278 1070 temps [argnum++] = Qnil;
08564963 1071 else if (! NILP (Fcdr (Fcdr (elt))))
734d55a2 1072 signal_error ("`let' bindings can have only one value-form", elt);
db9f0278 1073 else
defb1411 1074 temps [argnum++] = eval_sub (Fcar (Fcdr (elt)));
db9f0278
JB
1075 gcpro2.nvars = argnum;
1076 }
1077 UNGCPRO;
1078
b9598260
SM
1079 lexenv = Vinternal_interpreter_environment;
1080
db9f0278 1081 varlist = Fcar (args);
67ee9f6e 1082 for (argnum = 0; CONSP (varlist); varlist = XCDR (varlist))
db9f0278 1083 {
b9598260
SM
1084 Lisp_Object var;
1085
67ee9f6e 1086 elt = XCAR (varlist);
b9598260 1087 var = SYMBOLP (elt) ? elt : Fcar (elt);
db9f0278 1088 tem = temps[argnum++];
b9598260 1089
f07a954e
SM
1090 if (!NILP (lexenv) && SYMBOLP (var)
1091 && !XSYMBOL (var)->declared_special
1092 && NILP (Fmemq (var, Vinternal_interpreter_environment)))
b9598260
SM
1093 /* Lexically bind VAR by adding it to the lexenv alist. */
1094 lexenv = Fcons (Fcons (var, tem), lexenv);
db9f0278 1095 else
b9598260
SM
1096 /* Dynamically bind VAR. */
1097 specbind (var, tem);
db9f0278
JB
1098 }
1099
b9598260
SM
1100 if (!EQ (lexenv, Vinternal_interpreter_environment))
1101 /* Instantiate a new lexical environment. */
1102 specbind (Qinternal_interpreter_environment, lexenv);
1103
db9f0278 1104 elt = Fprogn (Fcdr (args));
3a7a9129 1105 SAFE_FREE ();
db9f0278
JB
1106 return unbind_to (count, elt);
1107}
1108
1109DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
9dbc9081
PJ
1110 doc: /* If TEST yields non-nil, eval BODY... and repeat.
1111The order of execution is thus TEST, BODY, TEST, BODY and so on
1112until TEST returns nil.
7a25dc6d 1113usage: (while TEST BODY...) */)
5842a27b 1114 (Lisp_Object args)
db9f0278 1115{
2b9bde76 1116 Lisp_Object test, body;
db9f0278
JB
1117 struct gcpro gcpro1, gcpro2;
1118
1119 GCPRO2 (test, body);
1120
1121 test = Fcar (args);
1122 body = Fcdr (args);
defb1411 1123 while (!NILP (eval_sub (test)))
db9f0278
JB
1124 {
1125 QUIT;
1126 Fprogn (body);
1127 }
1128
1129 UNGCPRO;
1130 return Qnil;
1131}
1132
1133DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
9dbc9081
PJ
1134 doc: /* Return result of expanding macros at top level of FORM.
1135If FORM is not a macro call, it is returned unchanged.
1136Otherwise, the macro is expanded and the expansion is considered
1137in place of FORM. When a non-macro-call results, it is returned.
1138
1139The second optional arg ENVIRONMENT specifies an environment of macro
1140definitions to shadow the loaded ones for use in file byte-compilation. */)
5842a27b 1141 (Lisp_Object form, Lisp_Object environment)
db9f0278 1142{
23d6b5a6 1143 /* With cleanups from Hallvard Furuseth. */
db9f0278
JB
1144 register Lisp_Object expander, sym, def, tem;
1145
1146 while (1)
1147 {
1148 /* Come back here each time we expand a macro call,
1149 in case it expands into another macro call. */
90165123 1150 if (!CONSP (form))
db9f0278 1151 break;
23d6b5a6 1152 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
03699b14 1153 def = sym = XCAR (form);
23d6b5a6 1154 tem = Qnil;
db9f0278
JB
1155 /* Trace symbols aliases to other symbols
1156 until we get a symbol that is not an alias. */
90165123 1157 while (SYMBOLP (def))
db9f0278
JB
1158 {
1159 QUIT;
23d6b5a6 1160 sym = def;
79e8bfbf 1161 tem = Fassq (sym, environment);
265a9e55 1162 if (NILP (tem))
db9f0278
JB
1163 {
1164 def = XSYMBOL (sym)->function;
23d6b5a6
JB
1165 if (!EQ (def, Qunbound))
1166 continue;
db9f0278 1167 }
23d6b5a6 1168 break;
db9f0278 1169 }
79e8bfbf 1170 /* Right now TEM is the result from SYM in ENVIRONMENT,
db9f0278 1171 and if TEM is nil then DEF is SYM's function definition. */
265a9e55 1172 if (NILP (tem))
db9f0278 1173 {
79e8bfbf 1174 /* SYM is not mentioned in ENVIRONMENT.
db9f0278 1175 Look at its function definition. */
90165123 1176 if (EQ (def, Qunbound) || !CONSP (def))
f6d62986 1177 /* Not defined or definition not suitable. */
db9f0278 1178 break;
03699b14 1179 if (EQ (XCAR (def), Qautoload))
db9f0278
JB
1180 {
1181 /* Autoloading function: will it be a macro when loaded? */
ee9ee63c 1182 tem = Fnth (make_number (4), def);
47ccd8b6 1183 if (EQ (tem, Qt) || EQ (tem, Qmacro))
ee9ee63c
JB
1184 /* Yes, load it and try again. */
1185 {
ca20916b
RS
1186 struct gcpro gcpro1;
1187 GCPRO1 (form);
ee9ee63c 1188 do_autoload (def, sym);
ca20916b 1189 UNGCPRO;
ee9ee63c
JB
1190 continue;
1191 }
1192 else
db9f0278 1193 break;
db9f0278 1194 }
03699b14 1195 else if (!EQ (XCAR (def), Qmacro))
db9f0278 1196 break;
03699b14 1197 else expander = XCDR (def);
db9f0278
JB
1198 }
1199 else
1200 {
03699b14 1201 expander = XCDR (tem);
265a9e55 1202 if (NILP (expander))
db9f0278
JB
1203 break;
1204 }
03699b14 1205 form = apply1 (expander, XCDR (form));
db9f0278
JB
1206 }
1207 return form;
1208}
1209\f
1210DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
9dbc9081
PJ
1211 doc: /* Eval BODY allowing nonlocal exits using `throw'.
1212TAG is evalled to get the tag to use; it must not be nil.
1213
1214Then the BODY is executed.
1d632ccf 1215Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
9dbc9081
PJ
1216If no throw happens, `catch' returns the value of the last BODY form.
1217If a throw happens, it specifies the value to return from `catch'.
7a25dc6d 1218usage: (catch TAG BODY...) */)
5842a27b 1219 (Lisp_Object args)
db9f0278
JB
1220{
1221 register Lisp_Object tag;
1222 struct gcpro gcpro1;
1223
1224 GCPRO1 (args);
defb1411 1225 tag = eval_sub (Fcar (args));
db9f0278
JB
1226 UNGCPRO;
1227 return internal_catch (tag, Fprogn, Fcdr (args));
1228}
1229
1230/* Set up a catch, then call C function FUNC on argument ARG.
1231 FUNC should return a Lisp_Object.
1232 This is how catches are done from within C code. */
1233
1234Lisp_Object
d3da34e0 1235internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object arg)
db9f0278
JB
1236{
1237 /* This structure is made part of the chain `catchlist'. */
1238 struct catchtag c;
1239
1240 /* Fill in the components of c, and put it on the list. */
1241 c.next = catchlist;
1242 c.tag = tag;
1243 c.val = Qnil;
1244 c.backlist = backtrace_list;
1245 c.handlerlist = handlerlist;
1246 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1247 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1248 c.poll_suppress_count = poll_suppress_count;
2659a09f 1249 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1250 c.gcpro = gcprolist;
bcf28080 1251 c.byte_stack = byte_stack_list;
db9f0278
JB
1252 catchlist = &c;
1253
1254 /* Call FUNC. */
1255 if (! _setjmp (c.jmp))
1256 c.val = (*func) (arg);
1257
1258 /* Throw works by a longjmp that comes right here. */
1259 catchlist = c.next;
1260 return c.val;
1261}
1262
ba410f40
JB
1263/* Unwind the specbind, catch, and handler stacks back to CATCH, and
1264 jump to that CATCH, returning VALUE as the value of that catch.
db9f0278 1265
ba410f40
JB
1266 This is the guts Fthrow and Fsignal; they differ only in the way
1267 they choose the catch tag to throw to. A catch tag for a
1268 condition-case form has a TAG of Qnil.
db9f0278 1269
ba410f40
JB
1270 Before each catch is discarded, unbind all special bindings and
1271 execute all unwind-protect clauses made above that catch. Unwind
1272 the handler stack as we go, so that the proper handlers are in
1273 effect for each unwind-protect clause we run. At the end, restore
1274 some static info saved in CATCH, and longjmp to the location
1275 specified in the
1276
1277 This is used for correct unwinding in Fthrow and Fsignal. */
db9f0278
JB
1278
1279static void
d3da34e0 1280unwind_to_catch (struct catchtag *catch, Lisp_Object value)
db9f0278
JB
1281{
1282 register int last_time;
1283
ba410f40
JB
1284 /* Save the value in the tag. */
1285 catch->val = value;
1286
0b31741c 1287 /* Restore certain special C variables. */
1cdc3155 1288 set_poll_suppress_count (catch->poll_suppress_count);
c1788fbc 1289 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked);
0b31741c 1290 handling_signal = 0;
69bbd6bd 1291 immediate_quit = 0;
82da7701 1292
db9f0278
JB
1293 do
1294 {
1295 last_time = catchlist == catch;
82da7701
JB
1296
1297 /* Unwind the specpdl stack, and then restore the proper set of
bb8e180f 1298 handlers. */
db9f0278
JB
1299 unbind_to (catchlist->pdlcount, Qnil);
1300 handlerlist = catchlist->handlerlist;
1301 catchlist = catchlist->next;
1302 }
1303 while (! last_time);
1304
a2a103bb 1305#if HAVE_X_WINDOWS
88019a63
RS
1306 /* If x_catch_errors was done, turn it off now.
1307 (First we give unbind_to a chance to do that.) */
e6aee454 1308#if 0 /* This would disable x_catch_errors after x_connection_closed.
bb8e180f
AS
1309 The catch must remain in effect during that delicate
1310 state. --lorentey */
88019a63 1311 x_fully_uncatch_errors ();
e6aee454 1312#endif
a2a103bb 1313#endif
88019a63 1314
bcf28080 1315 byte_stack_list = catch->byte_stack;
db9f0278 1316 gcprolist = catch->gcpro;
15934ffa 1317#ifdef DEBUG_GCPRO
d8e2b5ba 1318 gcpro_level = gcprolist ? gcprolist->level + 1 : 0;
15934ffa 1319#endif
db9f0278
JB
1320 backtrace_list = catch->backlist;
1321 lisp_eval_depth = catch->lisp_eval_depth;
177c0ea7 1322
ba410f40 1323 _longjmp (catch->jmp, 1);
db9f0278
JB
1324}
1325
a7ca3326 1326DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
9dbc9081
PJ
1327 doc: /* Throw to the catch for TAG and return VALUE from it.
1328Both TAG and VALUE are evalled. */)
5842a27b 1329 (register Lisp_Object tag, Lisp_Object value)
db9f0278
JB
1330{
1331 register struct catchtag *c;
1332
8788120f
KS
1333 if (!NILP (tag))
1334 for (c = catchlist; c; c = c->next)
1335 {
1336 if (EQ (c->tag, tag))
1337 unwind_to_catch (c, value);
1338 }
734d55a2 1339 xsignal2 (Qno_catch, tag, value);
db9f0278
JB
1340}
1341
1342
1343DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
9dbc9081
PJ
1344 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
1345If BODYFORM completes normally, its value is returned
1346after executing the UNWINDFORMS.
1347If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
7a25dc6d 1348usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
5842a27b 1349 (Lisp_Object args)
db9f0278
JB
1350{
1351 Lisp_Object val;
aed13378 1352 int count = SPECPDL_INDEX ();
db9f0278 1353
04b28167 1354 record_unwind_protect (Fprogn, Fcdr (args));
defb1411 1355 val = eval_sub (Fcar (args));
177c0ea7 1356 return unbind_to (count, val);
db9f0278
JB
1357}
1358\f
db9f0278 1359DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
9dbc9081 1360 doc: /* Regain control when an error is signaled.
1b1acc13 1361Executes BODYFORM and returns its value if no error happens.
9dbc9081
PJ
1362Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1363where the BODY is made of Lisp expressions.
1364
1365A handler is applicable to an error
1366if CONDITION-NAME is one of the error's condition names.
1367If an error happens, the first applicable handler is run.
1368
024a2d76
CY
1369The car of a handler may be a list of condition names instead of a
1370single condition name; then it handles all of them. If the special
1371condition name `debug' is present in this list, it allows another
1372condition in the list to run the debugger if `debug-on-error' and the
1373other usual mechanisms says it should (otherwise, `condition-case'
1374suppresses the debugger).
9dbc9081 1375
c997bb25
RS
1376When a handler handles an error, control returns to the `condition-case'
1377and it executes the handler's BODY...
d0acbbaf 1378with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
bb8e180f 1379\(If VAR is nil, the handler can't access that information.)
c997bb25
RS
1380Then the value of the last BODY form is returned from the `condition-case'
1381expression.
9dbc9081 1382
9dbc9081 1383See also the function `signal' for more info.
2b47b74d 1384usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
bb8e180f 1385 (Lisp_Object args)
db9f0278 1386{
17401c97
GM
1387 register Lisp_Object bodyform, handlers;
1388 volatile Lisp_Object var;
db9f0278 1389
82da7701
JB
1390 var = Fcar (args);
1391 bodyform = Fcar (Fcdr (args));
1392 handlers = Fcdr (Fcdr (args));
ee830945
RS
1393
1394 return internal_lisp_condition_case (var, bodyform, handlers);
1395}
1396
1397/* Like Fcondition_case, but the args are separate
1398 rather than passed in a list. Used by Fbyte_code. */
1399
1400Lisp_Object
d3da34e0
JB
1401internal_lisp_condition_case (volatile Lisp_Object var, Lisp_Object bodyform,
1402 Lisp_Object handlers)
ee830945
RS
1403{
1404 Lisp_Object val;
1405 struct catchtag c;
1406 struct handler h;
1407
b7826503 1408 CHECK_SYMBOL (var);
82da7701 1409
2b47b74d 1410 for (val = handlers; CONSP (val); val = XCDR (val))
82da7701
JB
1411 {
1412 Lisp_Object tem;
2b47b74d 1413 tem = XCAR (val);
5f96776a
RS
1414 if (! (NILP (tem)
1415 || (CONSP (tem)
03699b14
KR
1416 && (SYMBOLP (XCAR (tem))
1417 || CONSP (XCAR (tem))))))
e6c3da20
EZ
1418 error ("Invalid condition handler: %s",
1419 SDATA (Fprin1_to_string (tem, Qt)));
82da7701 1420 }
db9f0278
JB
1421
1422 c.tag = Qnil;
1423 c.val = Qnil;
1424 c.backlist = backtrace_list;
1425 c.handlerlist = handlerlist;
1426 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1427 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1428 c.poll_suppress_count = poll_suppress_count;
2659a09f 1429 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1430 c.gcpro = gcprolist;
bcf28080 1431 c.byte_stack = byte_stack_list;
db9f0278
JB
1432 if (_setjmp (c.jmp))
1433 {
265a9e55 1434 if (!NILP (h.var))
bb8e180f 1435 specbind (h.var, c.val);
9d58218c 1436 val = Fprogn (Fcdr (h.chosen_clause));
82da7701
JB
1437
1438 /* Note that this just undoes the binding of h.var; whoever
1439 longjumped to us unwound the stack to c.pdlcount before
1440 throwing. */
db9f0278
JB
1441 unbind_to (c.pdlcount, Qnil);
1442 return val;
1443 }
1444 c.next = catchlist;
1445 catchlist = &c;
177c0ea7 1446
82da7701
JB
1447 h.var = var;
1448 h.handler = handlers;
db9f0278 1449 h.next = handlerlist;
db9f0278
JB
1450 h.tag = &c;
1451 handlerlist = &h;
1452
defb1411 1453 val = eval_sub (bodyform);
db9f0278
JB
1454 catchlist = c.next;
1455 handlerlist = h.next;
1456 return val;
1457}
1458
f029ca5f
RS
1459/* Call the function BFUN with no arguments, catching errors within it
1460 according to HANDLERS. If there is an error, call HFUN with
1461 one argument which is the data that describes the error:
1462 (SIGNALNAME . DATA)
1463
1464 HANDLERS can be a list of conditions to catch.
1465 If HANDLERS is Qt, catch all errors.
1466 If HANDLERS is Qerror, catch all errors
1467 but allow the debugger to run if that is enabled. */
1468
db9f0278 1469Lisp_Object
d3da34e0
JB
1470internal_condition_case (Lisp_Object (*bfun) (void), Lisp_Object handlers,
1471 Lisp_Object (*hfun) (Lisp_Object))
db9f0278
JB
1472{
1473 Lisp_Object val;
1474 struct catchtag c;
1475 struct handler h;
1476
1477 c.tag = Qnil;
1478 c.val = Qnil;
1479 c.backlist = backtrace_list;
1480 c.handlerlist = handlerlist;
1481 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1482 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1483 c.poll_suppress_count = poll_suppress_count;
2659a09f 1484 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1485 c.gcpro = gcprolist;
bcf28080 1486 c.byte_stack = byte_stack_list;
db9f0278
JB
1487 if (_setjmp (c.jmp))
1488 {
9d58218c 1489 return (*hfun) (c.val);
db9f0278
JB
1490 }
1491 c.next = catchlist;
1492 catchlist = &c;
1493 h.handler = handlers;
1494 h.var = Qnil;
db9f0278
JB
1495 h.next = handlerlist;
1496 h.tag = &c;
1497 handlerlist = &h;
1498
1499 val = (*bfun) ();
1500 catchlist = c.next;
1501 handlerlist = h.next;
1502 return val;
1503}
1504
2659a09f 1505/* Like internal_condition_case but call BFUN with ARG as its argument. */
f029ca5f 1506
d227775c 1507Lisp_Object
d3da34e0
JB
1508internal_condition_case_1 (Lisp_Object (*bfun) (Lisp_Object), Lisp_Object arg,
1509 Lisp_Object handlers, Lisp_Object (*hfun) (Lisp_Object))
d227775c
RS
1510{
1511 Lisp_Object val;
1512 struct catchtag c;
1513 struct handler h;
1514
1515 c.tag = Qnil;
1516 c.val = Qnil;
1517 c.backlist = backtrace_list;
1518 c.handlerlist = handlerlist;
1519 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1520 c.pdlcount = SPECPDL_INDEX ();
d227775c 1521 c.poll_suppress_count = poll_suppress_count;
2659a09f 1522 c.interrupt_input_blocked = interrupt_input_blocked;
d227775c 1523 c.gcpro = gcprolist;
bcf28080 1524 c.byte_stack = byte_stack_list;
d227775c
RS
1525 if (_setjmp (c.jmp))
1526 {
9d58218c 1527 return (*hfun) (c.val);
d227775c
RS
1528 }
1529 c.next = catchlist;
1530 catchlist = &c;
1531 h.handler = handlers;
1532 h.var = Qnil;
1533 h.next = handlerlist;
1534 h.tag = &c;
1535 handlerlist = &h;
1536
1537 val = (*bfun) (arg);
1538 catchlist = c.next;
1539 handlerlist = h.next;
1540 return val;
1541}
10b29d41 1542
53967e09
CY
1543/* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1544 its arguments. */
1545
1546Lisp_Object
178f2507
SM
1547internal_condition_case_2 (Lisp_Object (*bfun) (Lisp_Object, Lisp_Object),
1548 Lisp_Object arg1,
1549 Lisp_Object arg2,
1550 Lisp_Object handlers,
1551 Lisp_Object (*hfun) (Lisp_Object))
53967e09
CY
1552{
1553 Lisp_Object val;
1554 struct catchtag c;
1555 struct handler h;
1556
53967e09
CY
1557 c.tag = Qnil;
1558 c.val = Qnil;
1559 c.backlist = backtrace_list;
1560 c.handlerlist = handlerlist;
1561 c.lisp_eval_depth = lisp_eval_depth;
1562 c.pdlcount = SPECPDL_INDEX ();
1563 c.poll_suppress_count = poll_suppress_count;
1564 c.interrupt_input_blocked = interrupt_input_blocked;
1565 c.gcpro = gcprolist;
1566 c.byte_stack = byte_stack_list;
1567 if (_setjmp (c.jmp))
1568 {
1569 return (*hfun) (c.val);
1570 }
1571 c.next = catchlist;
1572 catchlist = &c;
1573 h.handler = handlers;
1574 h.var = Qnil;
1575 h.next = handlerlist;
1576 h.tag = &c;
1577 handlerlist = &h;
1578
1579 val = (*bfun) (arg1, arg2);
1580 catchlist = c.next;
1581 handlerlist = h.next;
1582 return val;
1583}
10b29d41 1584
2659a09f 1585/* Like internal_condition_case but call BFUN with NARGS as first,
10b29d41
GM
1586 and ARGS as second argument. */
1587
1588Lisp_Object
f66c7cf8
PE
1589internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1590 ptrdiff_t nargs,
178f2507
SM
1591 Lisp_Object *args,
1592 Lisp_Object handlers,
1593 Lisp_Object (*hfun) (Lisp_Object))
10b29d41
GM
1594{
1595 Lisp_Object val;
1596 struct catchtag c;
1597 struct handler h;
1598
1599 c.tag = Qnil;
1600 c.val = Qnil;
1601 c.backlist = backtrace_list;
1602 c.handlerlist = handlerlist;
1603 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1604 c.pdlcount = SPECPDL_INDEX ();
10b29d41 1605 c.poll_suppress_count = poll_suppress_count;
2659a09f 1606 c.interrupt_input_blocked = interrupt_input_blocked;
10b29d41
GM
1607 c.gcpro = gcprolist;
1608 c.byte_stack = byte_stack_list;
1609 if (_setjmp (c.jmp))
1610 {
1611 return (*hfun) (c.val);
1612 }
1613 c.next = catchlist;
1614 catchlist = &c;
1615 h.handler = handlers;
1616 h.var = Qnil;
1617 h.next = handlerlist;
1618 h.tag = &c;
1619 handlerlist = &h;
1620
1621 val = (*bfun) (nargs, args);
1622 catchlist = c.next;
1623 handlerlist = h.next;
1624 return val;
1625}
1626
d227775c 1627\f
7d47b580 1628static Lisp_Object find_handler_clause (Lisp_Object, Lisp_Object);
e7f7fbaa
SM
1629static int maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig,
1630 Lisp_Object data);
db9f0278 1631
6d5eb5b0
SM
1632void
1633process_quit_flag (void)
1634{
1635 Lisp_Object flag = Vquit_flag;
1636 Vquit_flag = Qnil;
1637 if (EQ (flag, Qkill_emacs))
1638 Fkill_emacs (Qnil);
1639 if (EQ (Vthrow_on_input, flag))
1640 Fthrow (Vthrow_on_input, Qt);
1641 Fsignal (Qquit, Qnil);
1642}
1643
a7ca3326 1644DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
9dbc9081
PJ
1645 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1646This function does not return.
1647
1648An error symbol is a symbol with an `error-conditions' property
1649that is a list of condition names.
1650A handler for any of those names will get to handle this signal.
1651The symbol `error' should normally be one of them.
1652
1653DATA should be a list. Its elements are printed as part of the error message.
3297ec22
LT
1654See Info anchor `(elisp)Definition of signal' for some details on how this
1655error message is constructed.
9dbc9081
PJ
1656If the signal is handled, DATA is made available to the handler.
1657See also the function `condition-case'. */)
5842a27b 1658 (Lisp_Object error_symbol, Lisp_Object data)
db9f0278 1659{
bfa8ca43 1660 /* When memory is full, ERROR-SYMBOL is nil,
26631f2b
RS
1661 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1662 That is a special case--don't do this in other situations. */
db9f0278 1663 Lisp_Object conditions;
c11d3d17 1664 Lisp_Object string;
e7f7fbaa
SM
1665 Lisp_Object real_error_symbol
1666 = (NILP (error_symbol) ? Fcar (data) : error_symbol);
1667 register Lisp_Object clause = Qnil;
1668 struct handler *h;
a2ff3819 1669 struct backtrace *bp;
db9f0278 1670
346598f1 1671 immediate_quit = handling_signal = 0;
d063129f 1672 abort_on_gc = 0;
db9f0278
JB
1673 if (gc_in_progress || waiting_for_input)
1674 abort ();
1675
26631f2b
RS
1676#if 0 /* rms: I don't know why this was here,
1677 but it is surely wrong for an error that is handled. */
d148e14d 1678#ifdef HAVE_WINDOW_SYSTEM
df6c90d8
GM
1679 if (display_hourglass_p)
1680 cancel_hourglass ();
48f8dfa3 1681#endif
177c0ea7 1682#endif
48f8dfa3 1683
61ede770 1684 /* This hook is used by edebug. */
26631f2b
RS
1685 if (! NILP (Vsignal_hook_function)
1686 && ! NILP (error_symbol))
9f5903bb
RS
1687 {
1688 /* Edebug takes care of restoring these variables when it exits. */
1689 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
1690 max_lisp_eval_depth = lisp_eval_depth + 20;
1691
1692 if (SPECPDL_INDEX () + 40 > max_specpdl_size)
1693 max_specpdl_size = SPECPDL_INDEX () + 40;
1694
1695 call2 (Vsignal_hook_function, error_symbol, data);
1696 }
61ede770 1697
1ea9dec4 1698 conditions = Fget (real_error_symbol, Qerror_conditions);
db9f0278 1699
a2ff3819
GM
1700 /* Remember from where signal was called. Skip over the frame for
1701 `signal' itself. If a frame for `error' follows, skip that,
26631f2b
RS
1702 too. Don't do this when ERROR_SYMBOL is nil, because that
1703 is a memory-full error. */
090a072f 1704 Vsignaling_function = Qnil;
26631f2b 1705 if (backtrace_list && !NILP (error_symbol))
090a072f
GM
1706 {
1707 bp = backtrace_list->next;
1708 if (bp && bp->function && EQ (*bp->function, Qerror))
1709 bp = bp->next;
1710 if (bp && bp->function)
1711 Vsignaling_function = *bp->function;
1712 }
a2ff3819 1713
e7f7fbaa 1714 for (h = handlerlist; h; h = h->next)
db9f0278 1715 {
7d47b580 1716 clause = find_handler_clause (h->handler, conditions);
265a9e55 1717 if (!NILP (clause))
e7f7fbaa 1718 break;
db9f0278 1719 }
475545b5 1720
e7f7fbaa
SM
1721 if (/* Don't run the debugger for a memory-full error.
1722 (There is no room in memory to do that!) */
1723 !NILP (error_symbol)
1724 && (!NILP (Vdebug_on_signal)
1725 /* If no handler is present now, try to run the debugger. */
1726 || NILP (clause)
bd1ba3e8
CY
1727 /* A `debug' symbol in the handler list disables the normal
1728 suppression of the debugger. */
1729 || (CONSP (clause) && CONSP (XCAR (clause))
1730 && !NILP (Fmemq (Qdebug, XCAR (clause))))
e7f7fbaa
SM
1731 /* Special handler that means "print a message and run debugger
1732 if requested". */
1733 || EQ (h->handler, Qerror)))
1734 {
1735 int debugger_called
1736 = maybe_call_debugger (conditions, error_symbol, data);
1737 /* We can't return values to code which signaled an error, but we
1738 can continue code which has signaled a quit. */
1739 if (debugger_called && EQ (real_error_symbol, Qquit))
1740 return Qnil;
475545b5 1741 }
db9f0278 1742
e7f7fbaa
SM
1743 if (!NILP (clause))
1744 {
1745 Lisp_Object unwind_data
1746 = (NILP (error_symbol) ? data : Fcons (error_symbol, data));
475545b5 1747
e7f7fbaa
SM
1748 h->chosen_clause = clause;
1749 unwind_to_catch (h->tag, unwind_data);
1750 }
1751 else
1752 {
1753 if (catchlist != 0)
1754 Fthrow (Qtop_level, Qt);
1755 }
c11d3d17 1756
1ea9dec4 1757 if (! NILP (error_symbol))
c11d3d17 1758 data = Fcons (error_symbol, data);
475545b5 1759
c11d3d17 1760 string = Ferror_message_string (data);
583f48b9 1761 fatal ("%s", SDATA (string));
db9f0278
JB
1762}
1763
734d55a2
KS
1764/* Internal version of Fsignal that never returns.
1765 Used for anything but Qquit (which can return from Fsignal). */
1766
1767void
d3da34e0 1768xsignal (Lisp_Object error_symbol, Lisp_Object data)
734d55a2
KS
1769{
1770 Fsignal (error_symbol, data);
1771 abort ();
1772}
1773
1774/* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1775
1776void
d3da34e0 1777xsignal0 (Lisp_Object error_symbol)
734d55a2
KS
1778{
1779 xsignal (error_symbol, Qnil);
1780}
1781
1782void
d3da34e0 1783xsignal1 (Lisp_Object error_symbol, Lisp_Object arg)
734d55a2
KS
1784{
1785 xsignal (error_symbol, list1 (arg));
1786}
1787
1788void
d3da34e0 1789xsignal2 (Lisp_Object error_symbol, Lisp_Object arg1, Lisp_Object arg2)
734d55a2
KS
1790{
1791 xsignal (error_symbol, list2 (arg1, arg2));
1792}
1793
1794void
d3da34e0 1795xsignal3 (Lisp_Object error_symbol, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
734d55a2
KS
1796{
1797 xsignal (error_symbol, list3 (arg1, arg2, arg3));
1798}
1799
1800/* Signal `error' with message S, and additional arg ARG.
1801 If ARG is not a genuine list, make it a one-element list. */
1802
1803void
a8fe7202 1804signal_error (const char *s, Lisp_Object arg)
734d55a2
KS
1805{
1806 Lisp_Object tortoise, hare;
1807
1808 hare = tortoise = arg;
1809 while (CONSP (hare))
1810 {
1811 hare = XCDR (hare);
1812 if (!CONSP (hare))
1813 break;
1814
1815 hare = XCDR (hare);
1816 tortoise = XCDR (tortoise);
1817
1818 if (EQ (hare, tortoise))
1819 break;
1820 }
1821
1822 if (!NILP (hare))
1823 arg = Fcons (arg, Qnil); /* Make it a list. */
1824
1825 xsignal (Qerror, Fcons (build_string (s), arg));
1826}
1827
1828
e0f24100 1829/* Return nonzero if LIST is a non-nil atom or
128c0f66
RM
1830 a list containing one of CONDITIONS. */
1831
1832static int
d3da34e0 1833wants_debugger (Lisp_Object list, Lisp_Object conditions)
128c0f66 1834{
4de86b16 1835 if (NILP (list))
128c0f66
RM
1836 return 0;
1837 if (! CONSP (list))
1838 return 1;
1839
ab67260b 1840 while (CONSP (conditions))
128c0f66 1841 {
ab67260b 1842 Lisp_Object this, tail;
03699b14
KR
1843 this = XCAR (conditions);
1844 for (tail = list; CONSP (tail); tail = XCDR (tail))
1845 if (EQ (XCAR (tail), this))
128c0f66 1846 return 1;
03699b14 1847 conditions = XCDR (conditions);
128c0f66 1848 }
ab67260b 1849 return 0;
128c0f66
RM
1850}
1851
fc950e09
KH
1852/* Return 1 if an error with condition-symbols CONDITIONS,
1853 and described by SIGNAL-DATA, should skip the debugger
1b1acc13 1854 according to debugger-ignored-errors. */
fc950e09
KH
1855
1856static int
d3da34e0 1857skip_debugger (Lisp_Object conditions, Lisp_Object data)
fc950e09
KH
1858{
1859 Lisp_Object tail;
1860 int first_string = 1;
1861 Lisp_Object error_message;
1862
17401c97
GM
1863 error_message = Qnil;
1864 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
fc950e09 1865 {
03699b14 1866 if (STRINGP (XCAR (tail)))
fc950e09
KH
1867 {
1868 if (first_string)
1869 {
1870 error_message = Ferror_message_string (data);
1871 first_string = 0;
1872 }
177c0ea7 1873
03699b14 1874 if (fast_string_match (XCAR (tail), error_message) >= 0)
fc950e09
KH
1875 return 1;
1876 }
1877 else
1878 {
1879 Lisp_Object contail;
1880
17401c97 1881 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
03699b14 1882 if (EQ (XCAR (tail), XCAR (contail)))
fc950e09
KH
1883 return 1;
1884 }
1885 }
1886
1887 return 0;
1888}
1889
ddaa36e1 1890/* Call the debugger if calling it is currently enabled for CONDITIONS.
7d47b580
JB
1891 SIG and DATA describe the signal. There are two ways to pass them:
1892 = SIG is the error symbol, and DATA is the rest of the data.
1893 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1894 This is for memory-full errors only. */
ddaa36e1 1895static int
d3da34e0 1896maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, Lisp_Object data)
ddaa36e1
AS
1897{
1898 Lisp_Object combined_data;
1899
1900 combined_data = Fcons (sig, data);
1901
1902 if (
1903 /* Don't try to run the debugger with interrupts blocked.
1904 The editing loop would return anyway. */
1905 ! INPUT_BLOCKED_P
1906 /* Does user want to enter debugger for this kind of error? */
1907 && (EQ (sig, Qquit)
1908 ? debug_on_quit
1909 : wants_debugger (Vdebug_on_error, conditions))
1910 && ! skip_debugger (conditions, combined_data)
f6d62986 1911 /* RMS: What's this for? */
ddaa36e1
AS
1912 && when_entered_debugger < num_nonmacro_input_events)
1913 {
1914 call_debugger (Fcons (Qerror, Fcons (combined_data, Qnil)));
1915 return 1;
1916 }
1917
1918 return 0;
1919}
1920
db9f0278 1921static Lisp_Object
7d47b580 1922find_handler_clause (Lisp_Object handlers, Lisp_Object conditions)
db9f0278
JB
1923{
1924 register Lisp_Object h;
db9f0278 1925
f01cbfdd
RS
1926 /* t is used by handlers for all conditions, set up by C code. */
1927 if (EQ (handlers, Qt))
db9f0278 1928 return Qt;
f01cbfdd 1929
61ede770
RS
1930 /* error is used similarly, but means print an error message
1931 and run the debugger if that is enabled. */
e7f7fbaa
SM
1932 if (EQ (handlers, Qerror))
1933 return Qt;
f01cbfdd 1934
e7f7fbaa 1935 for (h = handlers; CONSP (h); h = XCDR (h))
db9f0278 1936 {
e7f7fbaa
SM
1937 Lisp_Object handler = XCAR (h);
1938 Lisp_Object condit, tem;
5f96776a 1939
5f96776a 1940 if (!CONSP (handler))
db9f0278 1941 continue;
e7f7fbaa 1942 condit = XCAR (handler);
5f96776a
RS
1943 /* Handle a single condition name in handler HANDLER. */
1944 if (SYMBOLP (condit))
1945 {
1946 tem = Fmemq (Fcar (handler), conditions);
1947 if (!NILP (tem))
1948 return handler;
1949 }
1950 /* Handle a list of condition names in handler HANDLER. */
1951 else if (CONSP (condit))
1952 {
f01cbfdd
RS
1953 Lisp_Object tail;
1954 for (tail = condit; CONSP (tail); tail = XCDR (tail))
5f96776a 1955 {
e7f7fbaa 1956 tem = Fmemq (XCAR (tail), conditions);
5f96776a 1957 if (!NILP (tem))
e7f7fbaa 1958 return handler;
5f96776a
RS
1959 }
1960 }
db9f0278 1961 }
f01cbfdd 1962
db9f0278
JB
1963 return Qnil;
1964}
1965
db9f0278 1966
f6d62986 1967/* Dump an error message; called like vprintf. */
db9f0278 1968void
b3ffc17c 1969verror (const char *m, va_list ap)
db9f0278 1970{
70476b54 1971 char buf[4000];
c2d1e36d
PE
1972 ptrdiff_t size = sizeof buf;
1973 ptrdiff_t size_max = STRING_BYTES_BOUND + 1;
9125da08 1974 char *buffer = buf;
c2d1e36d 1975 ptrdiff_t used;
9125da08
RS
1976 Lisp_Object string;
1977
d749b01b 1978 used = evxprintf (&buffer, &size, buf, size_max, m, ap);
5fdb398c 1979 string = make_string (buffer, used);
eb3f1cc8 1980 if (buffer != buf)
9ae6734f 1981 xfree (buffer);
9125da08 1982
734d55a2 1983 xsignal1 (Qerror, string);
db9f0278 1984}
b3ffc17c
DN
1985
1986
f6d62986 1987/* Dump an error message; called like printf. */
b3ffc17c
DN
1988
1989/* VARARGS 1 */
1990void
1991error (const char *m, ...)
1992{
1993 va_list ap;
1994 va_start (ap, m);
1995 verror (m, ap);
1996 va_end (ap);
1997}
db9f0278 1998\f
a7ca3326 1999DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
9dbc9081
PJ
2000 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
2001This means it contains a description for how to read arguments to give it.
2002The value is nil for an invalid function or a symbol with no function
2003definition.
2004
2005Interactively callable functions include strings and vectors (treated
2006as keyboard macros), lambda-expressions that contain a top-level call
2007to `interactive', autoload definitions made by `autoload' with non-nil
2008fourth argument, and some of the built-in functions of Lisp.
2009
e72706be
RS
2010Also, a symbol satisfies `commandp' if its function definition does so.
2011
2012If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
769b4fb2 2013then strings and vectors are not accepted. */)
5842a27b 2014 (Lisp_Object function, Lisp_Object for_call_interactively)
db9f0278
JB
2015{
2016 register Lisp_Object fun;
2017 register Lisp_Object funcar;
52b71f49 2018 Lisp_Object if_prop = Qnil;
db9f0278
JB
2019
2020 fun = function;
2021
52b71f49
SM
2022 fun = indirect_function (fun); /* Check cycles. */
2023 if (NILP (fun) || EQ (fun, Qunbound))
ffd56f97 2024 return Qnil;
db9f0278 2025
52b71f49
SM
2026 /* Check an `interactive-form' property if present, analogous to the
2027 function-documentation property. */
2028 fun = function;
2029 while (SYMBOLP (fun))
2030 {
2b9aa051 2031 Lisp_Object tmp = Fget (fun, Qinteractive_form);
52b71f49
SM
2032 if (!NILP (tmp))
2033 if_prop = Qt;
2034 fun = Fsymbol_function (fun);
2035 }
2036
db9f0278
JB
2037 /* Emacs primitives are interactive if their DEFUN specifies an
2038 interactive spec. */
90165123 2039 if (SUBRP (fun))
04724b69 2040 return XSUBR (fun)->intspec ? Qt : if_prop;
db9f0278
JB
2041
2042 /* Bytecode objects are interactive if they are long enough to
2043 have an element whose index is COMPILED_INTERACTIVE, which is
2044 where the interactive spec is stored. */
90165123 2045 else if (COMPILEDP (fun))
845975f5 2046 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
52b71f49 2047 ? Qt : if_prop);
db9f0278
JB
2048
2049 /* Strings and vectors are keyboard macros. */
52b71f49 2050 if (STRINGP (fun) || VECTORP (fun))
6e33efc4 2051 return (NILP (for_call_interactively) ? Qt : Qnil);
db9f0278
JB
2052
2053 /* Lists may represent commands. */
2054 if (!CONSP (fun))
2055 return Qnil;
ed16fb98 2056 funcar = XCAR (fun);
b38b1ec0 2057 if (EQ (funcar, Qclosure))
7200d79c
SM
2058 return (!NILP (Fassq (Qinteractive, Fcdr (Fcdr (XCDR (fun)))))
2059 ? Qt : if_prop);
23aba0ea 2060 else if (EQ (funcar, Qlambda))
52b71f49 2061 return !NILP (Fassq (Qinteractive, Fcdr (XCDR (fun)))) ? Qt : if_prop;
b38b1ec0 2062 else if (EQ (funcar, Qautoload))
52b71f49 2063 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun))))) ? Qt : if_prop;
db9f0278
JB
2064 else
2065 return Qnil;
2066}
2067
db9f0278 2068DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
9dbc9081
PJ
2069 doc: /* Define FUNCTION to autoload from FILE.
2070FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2071Third arg DOCSTRING is documentation for the function.
2072Fourth arg INTERACTIVE if non-nil says function can be called interactively.
2073Fifth arg TYPE indicates the type of the object:
2074 nil or omitted says FUNCTION is a function,
2075 `keymap' says FUNCTION is really a keymap, and
2076 `macro' or t says FUNCTION is really a macro.
2077Third through fifth args give info about the real definition.
2078They default to nil.
2079If FUNCTION is already defined other than as an autoload,
2080this does nothing and returns nil. */)
5842a27b 2081 (Lisp_Object function, Lisp_Object file, Lisp_Object docstring, Lisp_Object interactive, Lisp_Object type)
db9f0278 2082{
b7826503
PJ
2083 CHECK_SYMBOL (function);
2084 CHECK_STRING (file);
db9f0278 2085
f6d62986 2086 /* If function is defined and not as an autoload, don't override. */
db9f0278 2087 if (!EQ (XSYMBOL (function)->function, Qunbound)
90165123 2088 && !(CONSP (XSYMBOL (function)->function)
03699b14 2089 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
db9f0278
JB
2090 return Qnil;
2091
7973e637
SM
2092 if (NILP (Vpurify_flag))
2093 /* Only add entries after dumping, because the ones before are
2094 not useful and else we get loads of them from the loaddefs.el. */
2095 LOADHIST_ATTACH (Fcons (Qautoload, function));
905a9ed3 2096 else
a56eaaef 2097 /* We don't want the docstring in purespace (instead,
d6d23852
SM
2098 Snarf-documentation should (hopefully) overwrite it).
2099 We used to use 0 here, but that leads to accidental sharing in
2100 purecopy's hash-consing, so we use a (hopefully) unique integer
2101 instead. */
51639eac 2102 docstring = make_number (XPNTR (function));
a56eaaef
DN
2103 return Ffset (function,
2104 Fpurecopy (list5 (Qautoload, file, docstring,
2105 interactive, type)));
db9f0278
JB
2106}
2107
2108Lisp_Object
d3da34e0 2109un_autoload (Lisp_Object oldqueue)
db9f0278
JB
2110{
2111 register Lisp_Object queue, first, second;
2112
2113 /* Queue to unwind is current value of Vautoload_queue.
2114 oldqueue is the shadowed value to leave in Vautoload_queue. */
2115 queue = Vautoload_queue;
2116 Vautoload_queue = oldqueue;
2117 while (CONSP (queue))
2118 {
e509f168 2119 first = XCAR (queue);
db9f0278
JB
2120 second = Fcdr (first);
2121 first = Fcar (first);
47b82df9
RS
2122 if (EQ (first, make_number (0)))
2123 Vfeatures = second;
db9f0278
JB
2124 else
2125 Ffset (first, second);
e509f168 2126 queue = XCDR (queue);
db9f0278
JB
2127 }
2128 return Qnil;
2129}
2130
ca20916b
RS
2131/* Load an autoloaded function.
2132 FUNNAME is the symbol which is the function's name.
2133 FUNDEF is the autoload definition (a list). */
2134
045ba794 2135void
d3da34e0 2136do_autoload (Lisp_Object fundef, Lisp_Object funname)
db9f0278 2137{
aed13378 2138 int count = SPECPDL_INDEX ();
d945992e 2139 Lisp_Object fun;
ca20916b 2140 struct gcpro gcpro1, gcpro2, gcpro3;
db9f0278 2141
aea6173f
RS
2142 /* This is to make sure that loadup.el gives a clear picture
2143 of what files are preloaded and when. */
ab4db096
RS
2144 if (! NILP (Vpurify_flag))
2145 error ("Attempt to autoload %s while preparing to dump",
d5db4077 2146 SDATA (SYMBOL_NAME (funname)));
ab4db096 2147
db9f0278 2148 fun = funname;
b7826503 2149 CHECK_SYMBOL (funname);
ca20916b 2150 GCPRO3 (fun, funname, fundef);
db9f0278 2151
f87740dc 2152 /* Preserve the match data. */
89f2614d 2153 record_unwind_save_match_data ();
177c0ea7 2154
a04ee161
RS
2155 /* If autoloading gets an error (which includes the error of failing
2156 to define the function being called), we use Vautoload_queue
2157 to undo function definitions and `provide' calls made by
2158 the function. We do this in the specific case of autoloading
2159 because autoloading is not an explicit request "load this file",
2160 but rather a request to "call this function".
d3da34e0 2161
a04ee161 2162 The value saved here is to be restored into Vautoload_queue. */
db9f0278
JB
2163 record_unwind_protect (un_autoload, Vautoload_queue);
2164 Vautoload_queue = Qt;
7351b242 2165 Fload (Fcar (Fcdr (fundef)), Qnil, Qt, Qnil, Qt);
2a49b6e5 2166
db9f0278
JB
2167 /* Once loading finishes, don't undo it. */
2168 Vautoload_queue = Qt;
2169 unbind_to (count, Qnil);
2170
a7f96a35 2171 fun = Findirect_function (fun, Qnil);
ffd56f97 2172
76c2b0cc 2173 if (!NILP (Fequal (fun, fundef)))
db9f0278 2174 error ("Autoloading failed to define function %s",
d5db4077 2175 SDATA (SYMBOL_NAME (funname)));
ca20916b 2176 UNGCPRO;
db9f0278 2177}
4c576a83 2178
db9f0278 2179\f
a7ca3326 2180DEFUN ("eval", Feval, Seval, 1, 2, 0,
a0ee6f27
SM
2181 doc: /* Evaluate FORM and return its value.
2182If LEXICAL is t, evaluate using lexical scoping. */)
2183 (Lisp_Object form, Lisp_Object lexical)
defb1411
SM
2184{
2185 int count = SPECPDL_INDEX ();
a0ee6f27
SM
2186 specbind (Qinternal_interpreter_environment,
2187 NILP (lexical) ? Qnil : Fcons (Qt, Qnil));
defb1411
SM
2188 return unbind_to (count, eval_sub (form));
2189}
2190
2191/* Eval a sub-expression of the current expression (i.e. in the same
2192 lexical scope). */
2193Lisp_Object
2194eval_sub (Lisp_Object form)
db9f0278
JB
2195{
2196 Lisp_Object fun, val, original_fun, original_args;
2197 Lisp_Object funcar;
2198 struct backtrace backtrace;
2199 struct gcpro gcpro1, gcpro2, gcpro3;
2200
df470e3b 2201 if (handling_signal)
48f8dfa3 2202 abort ();
177c0ea7 2203
90165123 2204 if (SYMBOLP (form))
b9598260 2205 {
f07a954e
SM
2206 /* Look up its binding in the lexical environment.
2207 We do not pay attention to the declared_special flag here, since we
2208 already did that when let-binding the variable. */
2209 Lisp_Object lex_binding
2210 = !NILP (Vinternal_interpreter_environment) /* Mere optimization! */
2211 ? Fassq (form, Vinternal_interpreter_environment)
2212 : Qnil;
2213 if (CONSP (lex_binding))
2214 return XCDR (lex_binding);
2215 else
2216 return Fsymbol_value (form);
b9598260
SM
2217 }
2218
db9f0278
JB
2219 if (!CONSP (form))
2220 return form;
2221
2222 QUIT;
ee830945
RS
2223 if ((consing_since_gc > gc_cons_threshold
2224 && consing_since_gc > gc_relative_threshold)
2225 ||
2226 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
db9f0278
JB
2227 {
2228 GCPRO1 (form);
2229 Fgarbage_collect ();
2230 UNGCPRO;
2231 }
2232
2233 if (++lisp_eval_depth > max_lisp_eval_depth)
2234 {
2235 if (max_lisp_eval_depth < 100)
2236 max_lisp_eval_depth = 100;
2237 if (lisp_eval_depth > max_lisp_eval_depth)
921baa95 2238 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
db9f0278
JB
2239 }
2240
2241 original_fun = Fcar (form);
2242 original_args = Fcdr (form);
2243
2244 backtrace.next = backtrace_list;
2245 backtrace_list = &backtrace;
f6d62986 2246 backtrace.function = &original_fun; /* This also protects them from gc. */
db9f0278
JB
2247 backtrace.args = &original_args;
2248 backtrace.nargs = UNEVALLED;
db9f0278
JB
2249 backtrace.debug_on_exit = 0;
2250
2251 if (debug_on_next_call)
2252 do_debug_on_call (Qt);
2253
2254 /* At this point, only original_fun and original_args
f6d62986 2255 have values that will be used below. */
db9f0278 2256 retry:
8788120f
KS
2257
2258 /* Optimize for no indirection. */
2259 fun = original_fun;
2260 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2261 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2262 fun = indirect_function (fun);
db9f0278 2263
90165123 2264 if (SUBRP (fun))
db9f0278
JB
2265 {
2266 Lisp_Object numargs;
166c822d 2267 Lisp_Object argvals[8];
db9f0278
JB
2268 Lisp_Object args_left;
2269 register int i, maxargs;
2270
2271 args_left = original_args;
2272 numargs = Flength (args_left);
2273
c1788fbc
RS
2274 CHECK_CONS_LIST ();
2275
f6d62986
SM
2276 if (XINT (numargs) < XSUBR (fun)->min_args
2277 || (XSUBR (fun)->max_args >= 0
2278 && XSUBR (fun)->max_args < XINT (numargs)))
734d55a2 2279 xsignal2 (Qwrong_number_of_arguments, original_fun, numargs);
db9f0278 2280
ef1b0ba7 2281 else if (XSUBR (fun)->max_args == UNEVALLED)
bbc6b304 2282 val = (XSUBR (fun)->function.aUNEVALLED) (args_left);
ef1b0ba7 2283 else if (XSUBR (fun)->max_args == MANY)
db9f0278 2284 {
f6d62986 2285 /* Pass a vector of evaluated arguments. */
db9f0278 2286 Lisp_Object *vals;
f66c7cf8 2287 ptrdiff_t argnum = 0;
3a7a9129 2288 USE_SAFE_ALLOCA;
db9f0278 2289
b72e0717 2290 SAFE_ALLOCA_LISP (vals, XINT (numargs));
db9f0278
JB
2291
2292 GCPRO3 (args_left, fun, fun);
2293 gcpro3.var = vals;
2294 gcpro3.nvars = 0;
2295
265a9e55 2296 while (!NILP (args_left))
db9f0278 2297 {
defb1411 2298 vals[argnum++] = eval_sub (Fcar (args_left));
db9f0278
JB
2299 args_left = Fcdr (args_left);
2300 gcpro3.nvars = argnum;
2301 }
db9f0278
JB
2302
2303 backtrace.args = vals;
2304 backtrace.nargs = XINT (numargs);
2305
d5273788 2306 val = (XSUBR (fun)->function.aMANY) (XINT (numargs), vals);
a6e3fa71 2307 UNGCPRO;
3a7a9129 2308 SAFE_FREE ();
db9f0278 2309 }
ef1b0ba7 2310 else
db9f0278 2311 {
ef1b0ba7
SM
2312 GCPRO3 (args_left, fun, fun);
2313 gcpro3.var = argvals;
2314 gcpro3.nvars = 0;
db9f0278 2315
ef1b0ba7
SM
2316 maxargs = XSUBR (fun)->max_args;
2317 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
2318 {
a0ee6f27 2319 argvals[i] = eval_sub (Fcar (args_left));
ef1b0ba7
SM
2320 gcpro3.nvars = ++i;
2321 }
db9f0278 2322
ef1b0ba7 2323 UNGCPRO;
db9f0278 2324
ef1b0ba7
SM
2325 backtrace.args = argvals;
2326 backtrace.nargs = XINT (numargs);
2327
2328 switch (i)
2329 {
2330 case 0:
2331 val = (XSUBR (fun)->function.a0 ());
2332 break;
2333 case 1:
2334 val = (XSUBR (fun)->function.a1 (argvals[0]));
2335 break;
2336 case 2:
2337 val = (XSUBR (fun)->function.a2 (argvals[0], argvals[1]));
2338 break;
2339 case 3:
2340 val = (XSUBR (fun)->function.a3
2341 (argvals[0], argvals[1], argvals[2]));
2342 break;
2343 case 4:
2344 val = (XSUBR (fun)->function.a4
2345 (argvals[0], argvals[1], argvals[2], argvals[3]));
2346 break;
2347 case 5:
2348 val = (XSUBR (fun)->function.a5
2349 (argvals[0], argvals[1], argvals[2], argvals[3],
2350 argvals[4]));
2351 break;
2352 case 6:
2353 val = (XSUBR (fun)->function.a6
2354 (argvals[0], argvals[1], argvals[2], argvals[3],
2355 argvals[4], argvals[5]));
2356 break;
2357 case 7:
2358 val = (XSUBR (fun)->function.a7
2359 (argvals[0], argvals[1], argvals[2], argvals[3],
2360 argvals[4], argvals[5], argvals[6]));
2361 break;
2362
2363 case 8:
2364 val = (XSUBR (fun)->function.a8
2365 (argvals[0], argvals[1], argvals[2], argvals[3],
2366 argvals[4], argvals[5], argvals[6], argvals[7]));
2367 break;
2368
2369 default:
2370 /* Someone has created a subr that takes more arguments than
2371 is supported by this code. We need to either rewrite the
2372 subr to use a different argument protocol, or add more
2373 cases to this switch. */
2374 abort ();
2375 }
db9f0278
JB
2376 }
2377 }
ef1b0ba7 2378 else if (COMPILEDP (fun))
defb1411 2379 val = apply_lambda (fun, original_args);
db9f0278
JB
2380 else
2381 {
8788120f 2382 if (EQ (fun, Qunbound))
734d55a2 2383 xsignal1 (Qvoid_function, original_fun);
db9f0278 2384 if (!CONSP (fun))
734d55a2
KS
2385 xsignal1 (Qinvalid_function, original_fun);
2386 funcar = XCAR (fun);
90165123 2387 if (!SYMBOLP (funcar))
734d55a2 2388 xsignal1 (Qinvalid_function, original_fun);
db9f0278
JB
2389 if (EQ (funcar, Qautoload))
2390 {
2391 do_autoload (fun, original_fun);
2392 goto retry;
2393 }
2394 if (EQ (funcar, Qmacro))
defb1411
SM
2395 val = eval_sub (apply1 (Fcdr (fun), original_args));
2396 else if (EQ (funcar, Qlambda)
2397 || EQ (funcar, Qclosure))
2398 val = apply_lambda (fun, original_args);
db9f0278 2399 else
734d55a2 2400 xsignal1 (Qinvalid_function, original_fun);
db9f0278 2401 }
c1788fbc
RS
2402 CHECK_CONS_LIST ();
2403
db9f0278
JB
2404 lisp_eval_depth--;
2405 if (backtrace.debug_on_exit)
2406 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2407 backtrace_list = backtrace.next;
824eb35e 2408
db9f0278
JB
2409 return val;
2410}
2411\f
a7ca3326 2412DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
9dbc9081
PJ
2413 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2414Then return the value FUNCTION returns.
2415Thus, (apply '+ 1 2 '(3 4)) returns 10.
2416usage: (apply FUNCTION &rest ARGUMENTS) */)
f66c7cf8 2417 (ptrdiff_t nargs, Lisp_Object *args)
db9f0278 2418{
f66c7cf8 2419 ptrdiff_t i, numargs;
db9f0278
JB
2420 register Lisp_Object spread_arg;
2421 register Lisp_Object *funcall_args;
3a7a9129 2422 Lisp_Object fun, retval;
96d44c64 2423 struct gcpro gcpro1;
3a7a9129 2424 USE_SAFE_ALLOCA;
db9f0278
JB
2425
2426 fun = args [0];
2427 funcall_args = 0;
2428 spread_arg = args [nargs - 1];
b7826503 2429 CHECK_LIST (spread_arg);
177c0ea7 2430
db9f0278
JB
2431 numargs = XINT (Flength (spread_arg));
2432
2433 if (numargs == 0)
2434 return Ffuncall (nargs - 1, args);
2435 else if (numargs == 1)
2436 {
03699b14 2437 args [nargs - 1] = XCAR (spread_arg);
db9f0278
JB
2438 return Ffuncall (nargs, args);
2439 }
2440
a6e3fa71 2441 numargs += nargs - 2;
db9f0278 2442
8788120f
KS
2443 /* Optimize for no indirection. */
2444 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2445 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2446 fun = indirect_function (fun);
ffd56f97 2447 if (EQ (fun, Qunbound))
db9f0278 2448 {
f6d62986 2449 /* Let funcall get the error. */
ffd56f97
JB
2450 fun = args[0];
2451 goto funcall;
db9f0278
JB
2452 }
2453
90165123 2454 if (SUBRP (fun))
db9f0278
JB
2455 {
2456 if (numargs < XSUBR (fun)->min_args
2457 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
f6d62986 2458 goto funcall; /* Let funcall get the error. */
c5101a77 2459 else if (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args > numargs)
db9f0278
JB
2460 {
2461 /* Avoid making funcall cons up a yet another new vector of arguments
f6d62986 2462 by explicitly supplying nil's for optional values. */
b72e0717 2463 SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args);
db9f0278
JB
2464 for (i = numargs; i < XSUBR (fun)->max_args;)
2465 funcall_args[++i] = Qnil;
96d44c64
SM
2466 GCPRO1 (*funcall_args);
2467 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
db9f0278
JB
2468 }
2469 }
2470 funcall:
2471 /* We add 1 to numargs because funcall_args includes the
2472 function itself as well as its arguments. */
2473 if (!funcall_args)
a6e3fa71 2474 {
b72e0717 2475 SAFE_ALLOCA_LISP (funcall_args, 1 + numargs);
96d44c64
SM
2476 GCPRO1 (*funcall_args);
2477 gcpro1.nvars = 1 + numargs;
a6e3fa71
JB
2478 }
2479
72af86bd 2480 memcpy (funcall_args, args, nargs * sizeof (Lisp_Object));
db9f0278
JB
2481 /* Spread the last arg we got. Its first element goes in
2482 the slot that it used to occupy, hence this value of I. */
2483 i = nargs - 1;
265a9e55 2484 while (!NILP (spread_arg))
db9f0278 2485 {
03699b14
KR
2486 funcall_args [i++] = XCAR (spread_arg);
2487 spread_arg = XCDR (spread_arg);
db9f0278 2488 }
a6e3fa71 2489
96d44c64 2490 /* By convention, the caller needs to gcpro Ffuncall's args. */
3a7a9129
CY
2491 retval = Ffuncall (gcpro1.nvars, funcall_args);
2492 UNGCPRO;
2493 SAFE_FREE ();
2494
2495 return retval;
db9f0278
JB
2496}
2497\f
ff936e53
SM
2498/* Run hook variables in various ways. */
2499
f6d62986 2500static Lisp_Object
f66c7cf8 2501funcall_nil (ptrdiff_t nargs, Lisp_Object *args)
f6d62986
SM
2502{
2503 Ffuncall (nargs, args);
2504 return Qnil;
2505}
ff936e53 2506
a7ca3326 2507DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
9f685258 2508 doc: /* Run each hook in HOOKS.
9dbc9081
PJ
2509Each argument should be a symbol, a hook variable.
2510These symbols are processed in the order specified.
2511If a hook symbol has a non-nil value, that value may be a function
2512or a list of functions to be called to run the hook.
2513If the value is a function, it is called with no arguments.
2514If it is a list, the elements are called, in order, with no arguments.
2515
9f685258
LK
2516Major modes should not use this function directly to run their mode
2517hook; they should use `run-mode-hooks' instead.
2518
72e85d5d
RS
2519Do not use `make-local-variable' to make a hook variable buffer-local.
2520Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081 2521usage: (run-hooks &rest HOOKS) */)
f66c7cf8 2522 (ptrdiff_t nargs, Lisp_Object *args)
ff936e53
SM
2523{
2524 Lisp_Object hook[1];
f66c7cf8 2525 ptrdiff_t i;
ff936e53
SM
2526
2527 for (i = 0; i < nargs; i++)
2528 {
2529 hook[0] = args[i];
f6d62986 2530 run_hook_with_args (1, hook, funcall_nil);
ff936e53
SM
2531 }
2532
2533 return Qnil;
2534}
177c0ea7 2535
a7ca3326 2536DEFUN ("run-hook-with-args", Frun_hook_with_args,
9dbc9081
PJ
2537 Srun_hook_with_args, 1, MANY, 0,
2538 doc: /* Run HOOK with the specified arguments ARGS.
2539HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2540value, that value may be a function or a list of functions to be
2541called to run the hook. If the value is a function, it is called with
2542the given arguments and its return value is returned. If it is a list
2543of functions, those functions are called, in order,
2544with the given arguments ARGS.
d5e2c90c 2545It is best not to depend on the value returned by `run-hook-with-args',
9dbc9081
PJ
2546as that may change.
2547
72e85d5d
RS
2548Do not use `make-local-variable' to make a hook variable buffer-local.
2549Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081 2550usage: (run-hook-with-args HOOK &rest ARGS) */)
f66c7cf8 2551 (ptrdiff_t nargs, Lisp_Object *args)
ff936e53 2552{
f6d62986 2553 return run_hook_with_args (nargs, args, funcall_nil);
ff936e53
SM
2554}
2555
a0d76c27 2556DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
9dbc9081
PJ
2557 Srun_hook_with_args_until_success, 1, MANY, 0,
2558 doc: /* Run HOOK with the specified arguments ARGS.
d5e2c90c
RS
2559HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2560value, that value may be a function or a list of functions to be
2561called to run the hook. If the value is a function, it is called with
2562the given arguments and its return value is returned.
2563If it is a list of functions, those functions are called, in order,
2564with the given arguments ARGS, until one of them
9dbc9081 2565returns a non-nil value. Then we return that value.
d5e2c90c 2566However, if they all return nil, we return nil.
9dbc9081 2567
72e85d5d
RS
2568Do not use `make-local-variable' to make a hook variable buffer-local.
2569Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081 2570usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
f66c7cf8 2571 (ptrdiff_t nargs, Lisp_Object *args)
b0b667cb 2572{
f6d62986
SM
2573 return run_hook_with_args (nargs, args, Ffuncall);
2574}
2575
2576static Lisp_Object
f66c7cf8 2577funcall_not (ptrdiff_t nargs, Lisp_Object *args)
f6d62986
SM
2578{
2579 return NILP (Ffuncall (nargs, args)) ? Qt : Qnil;
ff936e53
SM
2580}
2581
a7ca3326 2582DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
9dbc9081
PJ
2583 Srun_hook_with_args_until_failure, 1, MANY, 0,
2584 doc: /* Run HOOK with the specified arguments ARGS.
d5e2c90c
RS
2585HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2586value, that value may be a function or a list of functions to be
2587called to run the hook. If the value is a function, it is called with
2588the given arguments and its return value is returned.
2589If it is a list of functions, those functions are called, in order,
2590with the given arguments ARGS, until one of them returns nil.
2591Then we return nil. However, if they all return non-nil, we return non-nil.
9dbc9081 2592
72e85d5d
RS
2593Do not use `make-local-variable' to make a hook variable buffer-local.
2594Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081 2595usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
f66c7cf8 2596 (ptrdiff_t nargs, Lisp_Object *args)
ff936e53 2597{
f6d62986 2598 return NILP (run_hook_with_args (nargs, args, funcall_not)) ? Qt : Qnil;
ff936e53
SM
2599}
2600
f6d62986 2601static Lisp_Object
f66c7cf8 2602run_hook_wrapped_funcall (ptrdiff_t nargs, Lisp_Object *args)
f6d62986
SM
2603{
2604 Lisp_Object tmp = args[0], ret;
2605 args[0] = args[1];
2606 args[1] = tmp;
2607 ret = Ffuncall (nargs, args);
2608 args[1] = args[0];
2609 args[0] = tmp;
2610 return ret;
2611}
2612
2613DEFUN ("run-hook-wrapped", Frun_hook_wrapped, Srun_hook_wrapped, 2, MANY, 0,
2614 doc: /* Run HOOK, passing each function through WRAP-FUNCTION.
2615I.e. instead of calling each function FUN directly with arguments ARGS,
2616it calls WRAP-FUNCTION with arguments FUN and ARGS.
2617As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2618aborts and returns that value.
2619usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
f66c7cf8 2620 (ptrdiff_t nargs, Lisp_Object *args)
f6d62986
SM
2621{
2622 return run_hook_with_args (nargs, args, run_hook_wrapped_funcall);
2623}
ff936e53 2624
c933ea05
RS
2625/* ARGS[0] should be a hook symbol.
2626 Call each of the functions in the hook value, passing each of them
2627 as arguments all the rest of ARGS (all NARGS - 1 elements).
f6d62986 2628 FUNCALL specifies how to call each function on the hook.
c933ea05
RS
2629 The caller (or its caller, etc) must gcpro all of ARGS,
2630 except that it isn't necessary to gcpro ARGS[0]. */
2631
f6d62986 2632Lisp_Object
f66c7cf8
PE
2633run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2634 Lisp_Object (*funcall) (ptrdiff_t nargs, Lisp_Object *args))
ff936e53 2635{
f6d62986 2636 Lisp_Object sym, val, ret = Qnil;
fada05d6 2637 struct gcpro gcpro1, gcpro2, gcpro3;
b0b667cb 2638
f029ca5f
RS
2639 /* If we are dying or still initializing,
2640 don't do anything--it would probably crash if we tried. */
2641 if (NILP (Vrun_hooks))
caff32a7 2642 return Qnil;
f029ca5f 2643
b0b667cb 2644 sym = args[0];
aa681b51 2645 val = find_symbol_value (sym);
ff936e53 2646
b0b667cb 2647 if (EQ (val, Qunbound) || NILP (val))
ff936e53 2648 return ret;
03699b14 2649 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
b0b667cb
KH
2650 {
2651 args[0] = val;
f6d62986 2652 return funcall (nargs, args);
b0b667cb
KH
2653 }
2654 else
2655 {
1faed8ae
PE
2656 Lisp_Object global_vals = Qnil;
2657 GCPRO3 (sym, val, global_vals);
cb9d21f8 2658
ff936e53 2659 for (;
f6d62986 2660 CONSP (val) && NILP (ret);
03699b14 2661 val = XCDR (val))
b0b667cb 2662 {
03699b14 2663 if (EQ (XCAR (val), Qt))
b0b667cb
KH
2664 {
2665 /* t indicates this hook has a local binding;
2666 it means to run the global binding too. */
1faed8ae
PE
2667 global_vals = Fdefault_value (sym);
2668 if (NILP (global_vals)) continue;
b0b667cb 2669
1faed8ae 2670 if (!CONSP (global_vals) || EQ (XCAR (global_vals), Qlambda))
b0b667cb 2671 {
1faed8ae 2672 args[0] = global_vals;
f6d62986 2673 ret = funcall (nargs, args);
8932b1c2
CY
2674 }
2675 else
2676 {
2677 for (;
f6d62986 2678 CONSP (global_vals) && NILP (ret);
1faed8ae 2679 global_vals = XCDR (global_vals))
8932b1c2 2680 {
1faed8ae 2681 args[0] = XCAR (global_vals);
8932b1c2
CY
2682 /* In a global value, t should not occur. If it does, we
2683 must ignore it to avoid an endless loop. */
2684 if (!EQ (args[0], Qt))
f6d62986 2685 ret = funcall (nargs, args);
8932b1c2 2686 }
b0b667cb
KH
2687 }
2688 }
2689 else
2690 {
03699b14 2691 args[0] = XCAR (val);
f6d62986 2692 ret = funcall (nargs, args);
b0b667cb
KH
2693 }
2694 }
cb9d21f8
RS
2695
2696 UNGCPRO;
ff936e53 2697 return ret;
b0b667cb
KH
2698 }
2699}
c933ea05 2700
7d48558f
RS
2701/* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2702
2703void
d3da34e0 2704run_hook_with_args_2 (Lisp_Object hook, Lisp_Object arg1, Lisp_Object arg2)
7d48558f
RS
2705{
2706 Lisp_Object temp[3];
2707 temp[0] = hook;
2708 temp[1] = arg1;
2709 temp[2] = arg2;
2710
2711 Frun_hook_with_args (3, temp);
2712}
ff936e53 2713\f
f6d62986 2714/* Apply fn to arg. */
db9f0278 2715Lisp_Object
d3da34e0 2716apply1 (Lisp_Object fn, Lisp_Object arg)
db9f0278 2717{
a6e3fa71
JB
2718 struct gcpro gcpro1;
2719
2720 GCPRO1 (fn);
265a9e55 2721 if (NILP (arg))
a6e3fa71
JB
2722 RETURN_UNGCPRO (Ffuncall (1, &fn));
2723 gcpro1.nvars = 2;
db9f0278
JB
2724 {
2725 Lisp_Object args[2];
2726 args[0] = fn;
2727 args[1] = arg;
a6e3fa71
JB
2728 gcpro1.var = args;
2729 RETURN_UNGCPRO (Fapply (2, args));
db9f0278 2730 }
db9f0278
JB
2731}
2732
f6d62986 2733/* Call function fn on no arguments. */
db9f0278 2734Lisp_Object
d3da34e0 2735call0 (Lisp_Object fn)
db9f0278 2736{
a6e3fa71
JB
2737 struct gcpro gcpro1;
2738
2739 GCPRO1 (fn);
2740 RETURN_UNGCPRO (Ffuncall (1, &fn));
db9f0278
JB
2741}
2742
f6d62986 2743/* Call function fn with 1 argument arg1. */
db9f0278
JB
2744/* ARGSUSED */
2745Lisp_Object
d3da34e0 2746call1 (Lisp_Object fn, Lisp_Object arg1)
db9f0278 2747{
a6e3fa71 2748 struct gcpro gcpro1;
177c0ea7 2749 Lisp_Object args[2];
a6e3fa71 2750
db9f0278 2751 args[0] = fn;
15285f9f 2752 args[1] = arg1;
a6e3fa71
JB
2753 GCPRO1 (args[0]);
2754 gcpro1.nvars = 2;
2755 RETURN_UNGCPRO (Ffuncall (2, args));
db9f0278
JB
2756}
2757
f6d62986 2758/* Call function fn with 2 arguments arg1, arg2. */
db9f0278
JB
2759/* ARGSUSED */
2760Lisp_Object
d3da34e0 2761call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2)
db9f0278 2762{
a6e3fa71 2763 struct gcpro gcpro1;
db9f0278
JB
2764 Lisp_Object args[3];
2765 args[0] = fn;
15285f9f
RS
2766 args[1] = arg1;
2767 args[2] = arg2;
a6e3fa71
JB
2768 GCPRO1 (args[0]);
2769 gcpro1.nvars = 3;
2770 RETURN_UNGCPRO (Ffuncall (3, args));
db9f0278
JB
2771}
2772
f6d62986 2773/* Call function fn with 3 arguments arg1, arg2, arg3. */
db9f0278
JB
2774/* ARGSUSED */
2775Lisp_Object
d3da34e0 2776call3 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
db9f0278 2777{
a6e3fa71 2778 struct gcpro gcpro1;
db9f0278
JB
2779 Lisp_Object args[4];
2780 args[0] = fn;
15285f9f
RS
2781 args[1] = arg1;
2782 args[2] = arg2;
2783 args[3] = arg3;
a6e3fa71
JB
2784 GCPRO1 (args[0]);
2785 gcpro1.nvars = 4;
2786 RETURN_UNGCPRO (Ffuncall (4, args));
db9f0278
JB
2787}
2788
f6d62986 2789/* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
a5a44b91
JB
2790/* ARGSUSED */
2791Lisp_Object
d3da34e0
JB
2792call4 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2793 Lisp_Object arg4)
a5a44b91
JB
2794{
2795 struct gcpro gcpro1;
a5a44b91
JB
2796 Lisp_Object args[5];
2797 args[0] = fn;
15285f9f
RS
2798 args[1] = arg1;
2799 args[2] = arg2;
2800 args[3] = arg3;
2801 args[4] = arg4;
a5a44b91
JB
2802 GCPRO1 (args[0]);
2803 gcpro1.nvars = 5;
2804 RETURN_UNGCPRO (Ffuncall (5, args));
a5a44b91
JB
2805}
2806
f6d62986 2807/* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
15285f9f
RS
2808/* ARGSUSED */
2809Lisp_Object
d3da34e0
JB
2810call5 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2811 Lisp_Object arg4, Lisp_Object arg5)
15285f9f
RS
2812{
2813 struct gcpro gcpro1;
15285f9f
RS
2814 Lisp_Object args[6];
2815 args[0] = fn;
2816 args[1] = arg1;
2817 args[2] = arg2;
2818 args[3] = arg3;
2819 args[4] = arg4;
2820 args[5] = arg5;
2821 GCPRO1 (args[0]);
2822 gcpro1.nvars = 6;
2823 RETURN_UNGCPRO (Ffuncall (6, args));
15285f9f
RS
2824}
2825
f6d62986 2826/* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
15285f9f
RS
2827/* ARGSUSED */
2828Lisp_Object
d3da34e0
JB
2829call6 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2830 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6)
15285f9f
RS
2831{
2832 struct gcpro gcpro1;
15285f9f
RS
2833 Lisp_Object args[7];
2834 args[0] = fn;
2835 args[1] = arg1;
2836 args[2] = arg2;
2837 args[3] = arg3;
2838 args[4] = arg4;
2839 args[5] = arg5;
2840 args[6] = arg6;
2841 GCPRO1 (args[0]);
2842 gcpro1.nvars = 7;
2843 RETURN_UNGCPRO (Ffuncall (7, args));
15285f9f
RS
2844}
2845
f6d62986 2846/* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
574c05e2
KK
2847/* ARGSUSED */
2848Lisp_Object
d3da34e0
JB
2849call7 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2850 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7)
574c05e2
KK
2851{
2852 struct gcpro gcpro1;
574c05e2
KK
2853 Lisp_Object args[8];
2854 args[0] = fn;
2855 args[1] = arg1;
2856 args[2] = arg2;
2857 args[3] = arg3;
2858 args[4] = arg4;
2859 args[5] = arg5;
2860 args[6] = arg6;
2861 args[7] = arg7;
2862 GCPRO1 (args[0]);
2863 gcpro1.nvars = 8;
2864 RETURN_UNGCPRO (Ffuncall (8, args));
574c05e2
KK
2865}
2866
6c2ef893
RS
2867/* The caller should GCPRO all the elements of ARGS. */
2868
a7ca3326 2869DEFUN ("functionp", Ffunctionp, Sfunctionp, 1, 1, 0,
7200d79c 2870 doc: /* Non-nil if OBJECT is a function. */)
c566235d 2871 (Lisp_Object object)
b9598260
SM
2872{
2873 if (SYMBOLP (object) && !NILP (Ffboundp (object)))
2874 {
ba83908c 2875 object = Findirect_function (object, Qt);
b9598260
SM
2876
2877 if (CONSP (object) && EQ (XCAR (object), Qautoload))
2878 {
2879 /* Autoloaded symbols are functions, except if they load
2880 macros or keymaps. */
2881 int i;
2882 for (i = 0; i < 4 && CONSP (object); i++)
2883 object = XCDR (object);
2884
2885 return (CONSP (object) && !NILP (XCAR (object))) ? Qnil : Qt;
2886 }
2887 }
2888
2889 if (SUBRP (object))
3c3ddb98 2890 return (XSUBR (object)->max_args != UNEVALLED) ? Qt : Qnil;
876c194c 2891 else if (COMPILEDP (object))
b9598260
SM
2892 return Qt;
2893 else if (CONSP (object))
2894 {
2895 Lisp_Object car = XCAR (object);
2896 return (EQ (car, Qlambda) || EQ (car, Qclosure)) ? Qt : Qnil;
2897 }
2898 else
2899 return Qnil;
2900}
2901
a7ca3326 2902DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
9dbc9081
PJ
2903 doc: /* Call first argument as a function, passing remaining arguments to it.
2904Return the value that function returns.
2905Thus, (funcall 'cons 'x 'y) returns (x . y).
2906usage: (funcall FUNCTION &rest ARGUMENTS) */)
f66c7cf8 2907 (ptrdiff_t nargs, Lisp_Object *args)
db9f0278 2908{
8788120f 2909 Lisp_Object fun, original_fun;
db9f0278 2910 Lisp_Object funcar;
f66c7cf8 2911 ptrdiff_t numargs = nargs - 1;
db9f0278
JB
2912 Lisp_Object lisp_numargs;
2913 Lisp_Object val;
2914 struct backtrace backtrace;
2915 register Lisp_Object *internal_args;
f66c7cf8 2916 ptrdiff_t i;
db9f0278
JB
2917
2918 QUIT;
ee830945
RS
2919 if ((consing_since_gc > gc_cons_threshold
2920 && consing_since_gc > gc_relative_threshold)
2921 ||
2922 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
a6e3fa71 2923 Fgarbage_collect ();
db9f0278
JB
2924
2925 if (++lisp_eval_depth > max_lisp_eval_depth)
2926 {
2927 if (max_lisp_eval_depth < 100)
2928 max_lisp_eval_depth = 100;
2929 if (lisp_eval_depth > max_lisp_eval_depth)
921baa95 2930 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
db9f0278
JB
2931 }
2932
2933 backtrace.next = backtrace_list;
2934 backtrace_list = &backtrace;
2935 backtrace.function = &args[0];
2936 backtrace.args = &args[1];
2937 backtrace.nargs = nargs - 1;
db9f0278
JB
2938 backtrace.debug_on_exit = 0;
2939
2940 if (debug_on_next_call)
2941 do_debug_on_call (Qlambda);
2942
fff3ff9c
KS
2943 CHECK_CONS_LIST ();
2944
8788120f
KS
2945 original_fun = args[0];
2946
db9f0278
JB
2947 retry:
2948
8788120f
KS
2949 /* Optimize for no indirection. */
2950 fun = original_fun;
2951 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2952 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2953 fun = indirect_function (fun);
db9f0278 2954
90165123 2955 if (SUBRP (fun))
db9f0278 2956 {
ef1b0ba7 2957 if (numargs < XSUBR (fun)->min_args
db9f0278
JB
2958 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2959 {
a631e24c 2960 XSETFASTINT (lisp_numargs, numargs);
734d55a2 2961 xsignal2 (Qwrong_number_of_arguments, original_fun, lisp_numargs);
db9f0278
JB
2962 }
2963
ef1b0ba7 2964 else if (XSUBR (fun)->max_args == UNEVALLED)
734d55a2 2965 xsignal1 (Qinvalid_function, original_fun);
db9f0278 2966
ef1b0ba7
SM
2967 else if (XSUBR (fun)->max_args == MANY)
2968 val = (XSUBR (fun)->function.aMANY) (numargs, args + 1);
db9f0278 2969 else
db9f0278 2970 {
ef1b0ba7
SM
2971 if (XSUBR (fun)->max_args > numargs)
2972 {
2973 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2974 memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object));
2975 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2976 internal_args[i] = Qnil;
2977 }
2978 else
2979 internal_args = args + 1;
2980 switch (XSUBR (fun)->max_args)
2981 {
2982 case 0:
2983 val = (XSUBR (fun)->function.a0 ());
2984 break;
2985 case 1:
2986 val = (XSUBR (fun)->function.a1 (internal_args[0]));
2987 break;
2988 case 2:
2989 val = (XSUBR (fun)->function.a2
2990 (internal_args[0], internal_args[1]));
2991 break;
2992 case 3:
2993 val = (XSUBR (fun)->function.a3
2994 (internal_args[0], internal_args[1], internal_args[2]));
2995 break;
2996 case 4:
2997 val = (XSUBR (fun)->function.a4
2998 (internal_args[0], internal_args[1], internal_args[2],
2999 internal_args[3]));
3000 break;
3001 case 5:
3002 val = (XSUBR (fun)->function.a5
3003 (internal_args[0], internal_args[1], internal_args[2],
3004 internal_args[3], internal_args[4]));
3005 break;
3006 case 6:
3007 val = (XSUBR (fun)->function.a6
3008 (internal_args[0], internal_args[1], internal_args[2],
3009 internal_args[3], internal_args[4], internal_args[5]));
3010 break;
3011 case 7:
3012 val = (XSUBR (fun)->function.a7
3013 (internal_args[0], internal_args[1], internal_args[2],
3014 internal_args[3], internal_args[4], internal_args[5],
3015 internal_args[6]));
3016 break;
3017
3018 case 8:
3019 val = (XSUBR (fun)->function.a8
3020 (internal_args[0], internal_args[1], internal_args[2],
3021 internal_args[3], internal_args[4], internal_args[5],
3022 internal_args[6], internal_args[7]));
3023 break;
3024
3025 default:
3026
3027 /* If a subr takes more than 8 arguments without using MANY
3028 or UNEVALLED, we need to extend this function to support it.
3029 Until this is done, there is no way to call the function. */
3030 abort ();
3031 }
db9f0278
JB
3032 }
3033 }
ef1b0ba7 3034 else if (COMPILEDP (fun))
db9f0278
JB
3035 val = funcall_lambda (fun, numargs, args + 1);
3036 else
3037 {
8788120f 3038 if (EQ (fun, Qunbound))
734d55a2 3039 xsignal1 (Qvoid_function, original_fun);
db9f0278 3040 if (!CONSP (fun))
734d55a2
KS
3041 xsignal1 (Qinvalid_function, original_fun);
3042 funcar = XCAR (fun);
90165123 3043 if (!SYMBOLP (funcar))
734d55a2 3044 xsignal1 (Qinvalid_function, original_fun);
defb1411
SM
3045 if (EQ (funcar, Qlambda)
3046 || EQ (funcar, Qclosure))
db9f0278 3047 val = funcall_lambda (fun, numargs, args + 1);
db9f0278
JB
3048 else if (EQ (funcar, Qautoload))
3049 {
8788120f 3050 do_autoload (fun, original_fun);
fff3ff9c 3051 CHECK_CONS_LIST ();
db9f0278
JB
3052 goto retry;
3053 }
3054 else
734d55a2 3055 xsignal1 (Qinvalid_function, original_fun);
db9f0278 3056 }
c1788fbc 3057 CHECK_CONS_LIST ();
db9f0278
JB
3058 lisp_eval_depth--;
3059 if (backtrace.debug_on_exit)
3060 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
3061 backtrace_list = backtrace.next;
3062 return val;
3063}
3064\f
2f7c71a1 3065static Lisp_Object
defb1411 3066apply_lambda (Lisp_Object fun, Lisp_Object args)
db9f0278
JB
3067{
3068 Lisp_Object args_left;
f66c7cf8 3069 ptrdiff_t i, numargs;
db9f0278
JB
3070 register Lisp_Object *arg_vector;
3071 struct gcpro gcpro1, gcpro2, gcpro3;
db9f0278 3072 register Lisp_Object tem;
3a7a9129 3073 USE_SAFE_ALLOCA;
db9f0278 3074
f66c7cf8 3075 numargs = XFASTINT (Flength (args));
c5101a77 3076 SAFE_ALLOCA_LISP (arg_vector, numargs);
db9f0278
JB
3077 args_left = args;
3078
3079 GCPRO3 (*arg_vector, args_left, fun);
3080 gcpro1.nvars = 0;
3081
c5101a77 3082 for (i = 0; i < numargs; )
db9f0278
JB
3083 {
3084 tem = Fcar (args_left), args_left = Fcdr (args_left);
defb1411 3085 tem = eval_sub (tem);
db9f0278
JB
3086 arg_vector[i++] = tem;
3087 gcpro1.nvars = i;
3088 }
3089
3090 UNGCPRO;
3091
f07a954e
SM
3092 backtrace_list->args = arg_vector;
3093 backtrace_list->nargs = i;
c5101a77 3094 tem = funcall_lambda (fun, numargs, arg_vector);
db9f0278
JB
3095
3096 /* Do the debug-on-exit now, while arg_vector still exists. */
3097 if (backtrace_list->debug_on_exit)
3098 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
3099 /* Don't do it again when we return to eval. */
3100 backtrace_list->debug_on_exit = 0;
3a7a9129 3101 SAFE_FREE ();
db9f0278
JB
3102 return tem;
3103}
3104
3105/* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3106 and return the result of evaluation.
3107 FUN must be either a lambda-expression or a compiled-code object. */
3108
2901f1d1 3109static Lisp_Object
f66c7cf8 3110funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
c5101a77 3111 register Lisp_Object *arg_vector)
db9f0278 3112{
defb1411 3113 Lisp_Object val, syms_left, next, lexenv;
aed13378 3114 int count = SPECPDL_INDEX ();
f66c7cf8 3115 ptrdiff_t i;
c5101a77 3116 int optional, rest;
db9f0278 3117
90165123 3118 if (CONSP (fun))
9ab90667 3119 {
defb1411
SM
3120 if (EQ (XCAR (fun), Qclosure))
3121 {
3122 fun = XCDR (fun); /* Drop `closure'. */
3123 lexenv = XCAR (fun);
23aba0ea 3124 CHECK_LIST_CONS (fun, fun);
defb1411
SM
3125 }
3126 else
3127 lexenv = Qnil;
9ab90667
GM
3128 syms_left = XCDR (fun);
3129 if (CONSP (syms_left))
3130 syms_left = XCAR (syms_left);
3131 else
734d55a2 3132 xsignal1 (Qinvalid_function, fun);
9ab90667 3133 }
90165123 3134 else if (COMPILEDP (fun))
defb1411 3135 {
798cb644
SM
3136 syms_left = AREF (fun, COMPILED_ARGLIST);
3137 if (INTEGERP (syms_left))
876c194c
SM
3138 /* A byte-code object with a non-nil `push args' slot means we
3139 shouldn't bind any arguments, instead just call the byte-code
3140 interpreter directly; it will push arguments as necessary.
3141
9173deec 3142 Byte-code objects with either a non-existent, or a nil value for
876c194c
SM
3143 the `push args' slot (the default), have dynamically-bound
3144 arguments, and use the argument-binding code below instead (as do
3145 all interpreted functions, even lexically bound ones). */
3146 {
3147 /* If we have not actually read the bytecode string
3148 and constants vector yet, fetch them from the file. */
3149 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
3150 Ffetch_bytecode (fun);
3151 return exec_byte_code (AREF (fun, COMPILED_BYTECODE),
3152 AREF (fun, COMPILED_CONSTANTS),
3153 AREF (fun, COMPILED_STACK_DEPTH),
798cb644 3154 syms_left,
876c194c
SM
3155 nargs, arg_vector);
3156 }
defb1411
SM
3157 lexenv = Qnil;
3158 }
9ab90667
GM
3159 else
3160 abort ();
db9f0278 3161
9ab90667
GM
3162 i = optional = rest = 0;
3163 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
db9f0278
JB
3164 {
3165 QUIT;
177c0ea7 3166
9ab90667 3167 next = XCAR (syms_left);
8788120f 3168 if (!SYMBOLP (next))
734d55a2 3169 xsignal1 (Qinvalid_function, fun);
177c0ea7 3170
db9f0278
JB
3171 if (EQ (next, Qand_rest))
3172 rest = 1;
3173 else if (EQ (next, Qand_optional))
3174 optional = 1;
db9f0278 3175 else
db9f0278 3176 {
e610eaca 3177 Lisp_Object arg;
defb1411
SM
3178 if (rest)
3179 {
e610eaca 3180 arg = Flist (nargs - i, &arg_vector[i]);
defb1411
SM
3181 i = nargs;
3182 }
3183 else if (i < nargs)
e610eaca 3184 arg = arg_vector[i++];
b9598260
SM
3185 else if (!optional)
3186 xsignal2 (Qwrong_number_of_arguments, fun, make_number (nargs));
3187 else
e610eaca 3188 arg = Qnil;
7200d79c 3189
b9598260 3190 /* Bind the argument. */
876c194c 3191 if (!NILP (lexenv) && SYMBOLP (next))
b9598260 3192 /* Lexically bind NEXT by adding it to the lexenv alist. */
e610eaca 3193 lexenv = Fcons (Fcons (next, arg), lexenv);
b9598260
SM
3194 else
3195 /* Dynamically bind NEXT. */
e610eaca 3196 specbind (next, arg);
db9f0278 3197 }
db9f0278
JB
3198 }
3199
9ab90667 3200 if (!NILP (syms_left))
734d55a2 3201 xsignal1 (Qinvalid_function, fun);
9ab90667 3202 else if (i < nargs)
734d55a2 3203 xsignal2 (Qwrong_number_of_arguments, fun, make_number (nargs));
db9f0278 3204
b9598260
SM
3205 if (!EQ (lexenv, Vinternal_interpreter_environment))
3206 /* Instantiate a new lexical environment. */
3207 specbind (Qinternal_interpreter_environment, lexenv);
3208
90165123 3209 if (CONSP (fun))
9ab90667 3210 val = Fprogn (XCDR (XCDR (fun)));
db9f0278 3211 else
ca248607
RS
3212 {
3213 /* If we have not actually read the bytecode string
3214 and constants vector yet, fetch them from the file. */
845975f5 3215 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
661c7d6e 3216 Ffetch_bytecode (fun);
b9598260
SM
3217 val = exec_byte_code (AREF (fun, COMPILED_BYTECODE),
3218 AREF (fun, COMPILED_CONSTANTS),
3219 AREF (fun, COMPILED_STACK_DEPTH),
3220 Qnil, 0, 0);
ca248607 3221 }
177c0ea7 3222
db9f0278
JB
3223 return unbind_to (count, val);
3224}
661c7d6e
KH
3225
3226DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
9dbc9081
PJ
3227 1, 1, 0,
3228 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
5842a27b 3229 (Lisp_Object object)
661c7d6e
KH
3230{
3231 Lisp_Object tem;
3232
845975f5 3233 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
661c7d6e 3234 {
845975f5 3235 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
5bbdb090 3236 if (!CONSP (tem))
845975f5
SM
3237 {
3238 tem = AREF (object, COMPILED_BYTECODE);
3239 if (CONSP (tem) && STRINGP (XCAR (tem)))
d5db4077 3240 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
845975f5
SM
3241 else
3242 error ("Invalid byte code");
3243 }
3ae565b3
SM
3244 ASET (object, COMPILED_BYTECODE, XCAR (tem));
3245 ASET (object, COMPILED_CONSTANTS, XCDR (tem));
661c7d6e
KH
3246 }
3247 return object;
3248}
db9f0278 3249\f
475545b5 3250static void
d3da34e0 3251grow_specpdl (void)
db9f0278 3252{
aed13378 3253 register int count = SPECPDL_INDEX ();
98e8eae1
PE
3254 int max_size =
3255 min (max_specpdl_size,
3256 min (max (PTRDIFF_MAX, SIZE_MAX) / sizeof (struct specbinding),
3257 INT_MAX));
3258 int size;
3259 if (max_size <= specpdl_size)
db9f0278
JB
3260 {
3261 if (max_specpdl_size < 400)
98e8eae1
PE
3262 max_size = max_specpdl_size = 400;
3263 if (max_size <= specpdl_size)
734d55a2 3264 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil);
db9f0278 3265 }
98e8eae1 3266 size = specpdl_size < max_size / 2 ? 2 * specpdl_size : max_size;
0065d054 3267 specpdl = xnrealloc (specpdl, size, sizeof *specpdl);
98e8eae1 3268 specpdl_size = size;
db9f0278
JB
3269 specpdl_ptr = specpdl + count;
3270}
3271
f6d62986 3272/* `specpdl_ptr->symbol' is a field which describes which variable is
4e2db1fe
SM
3273 let-bound, so it can be properly undone when we unbind_to.
3274 It can have the following two shapes:
3275 - SYMBOL : if it's a plain symbol, it means that we have let-bound
3276 a symbol that is not buffer-local (at least at the time
3277 the let binding started). Note also that it should not be
3278 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3279 to record V2 here).
3280 - (SYMBOL WHERE . BUFFER) : this means that it is a let-binding for
3281 variable SYMBOL which can be buffer-local. WHERE tells us
3282 which buffer is affected (or nil if the let-binding affects the
3283 global value of the variable) and BUFFER tells us which buffer was
3284 current (i.e. if WHERE is non-nil, then BUFFER==WHERE, otherwise
3285 BUFFER did not yet have a buffer-local value). */
3286
db9f0278 3287void
d3da34e0 3288specbind (Lisp_Object symbol, Lisp_Object value)
db9f0278 3289{
ce5b453a
SM
3290 struct Lisp_Symbol *sym;
3291
3292 eassert (!handling_signal);
db9f0278 3293
b7826503 3294 CHECK_SYMBOL (symbol);
ce5b453a 3295 sym = XSYMBOL (symbol);
db9f0278
JB
3296 if (specpdl_ptr == specpdl + specpdl_size)
3297 grow_specpdl ();
719177b3 3298
ce5b453a
SM
3299 start:
3300 switch (sym->redirect)
719177b3 3301 {
ce5b453a
SM
3302 case SYMBOL_VARALIAS:
3303 sym = indirect_variable (sym); XSETSYMBOL (symbol, sym); goto start;
3304 case SYMBOL_PLAINVAL:
bb8e180f
AS
3305 /* The most common case is that of a non-constant symbol with a
3306 trivial value. Make that as fast as we can. */
3307 specpdl_ptr->symbol = symbol;
3308 specpdl_ptr->old_value = SYMBOL_VAL (sym);
3309 specpdl_ptr->func = NULL;
3310 ++specpdl_ptr;
3311 if (!sym->constant)
3312 SET_SYMBOL_VAL (sym, value);
3313 else
3314 set_internal (symbol, value, Qnil, 1);
3315 break;
4e2db1fe
SM
3316 case SYMBOL_LOCALIZED:
3317 if (SYMBOL_BLV (sym)->frame_local)
3318 error ("Frame-local vars cannot be let-bound");
3319 case SYMBOL_FORWARDED:
ce5b453a
SM
3320 {
3321 Lisp_Object ovalue = find_symbol_value (symbol);
3322 specpdl_ptr->func = 0;
3323 specpdl_ptr->old_value = ovalue;
3324
3325 eassert (sym->redirect != SYMBOL_LOCALIZED
3326 || (EQ (SYMBOL_BLV (sym)->where,
3327 SYMBOL_BLV (sym)->frame_local ?
3328 Fselected_frame () : Fcurrent_buffer ())));
3329
3330 if (sym->redirect == SYMBOL_LOCALIZED
3331 || BUFFER_OBJFWDP (SYMBOL_FWD (sym)))
3332 {
3333 Lisp_Object where, cur_buf = Fcurrent_buffer ();
3334
3335 /* For a local variable, record both the symbol and which
3336 buffer's or frame's value we are saving. */
3337 if (!NILP (Flocal_variable_p (symbol, Qnil)))
3338 {
3339 eassert (sym->redirect != SYMBOL_LOCALIZED
3340 || (BLV_FOUND (SYMBOL_BLV (sym))
3341 && EQ (cur_buf, SYMBOL_BLV (sym)->where)));
3342 where = cur_buf;
3343 }
3344 else if (sym->redirect == SYMBOL_LOCALIZED
3345 && BLV_FOUND (SYMBOL_BLV (sym)))
3346 where = SYMBOL_BLV (sym)->where;
3347 else
3348 where = Qnil;
3349
3350 /* We're not using the `unused' slot in the specbinding
3351 structure because this would mean we have to do more
3352 work for simple variables. */
3353 /* FIXME: The third value `current_buffer' is only used in
3354 let_shadows_buffer_binding_p which is itself only used
3355 in set_internal for local_if_set. */
4e2db1fe 3356 eassert (NILP (where) || EQ (where, cur_buf));
ce5b453a
SM
3357 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, cur_buf));
3358
3359 /* If SYMBOL is a per-buffer variable which doesn't have a
3360 buffer-local value here, make the `let' change the global
3361 value by changing the value of SYMBOL in all buffers not
3362 having their own value. This is consistent with what
3363 happens with other buffer-local variables. */
3364 if (NILP (where)
3365 && sym->redirect == SYMBOL_FORWARDED)
3366 {
3367 eassert (BUFFER_OBJFWDP (SYMBOL_FWD (sym)));
3368 ++specpdl_ptr;
3369 Fset_default (symbol, value);
3370 return;
3371 }
3372 }
3373 else
3374 specpdl_ptr->symbol = symbol;
3375
3376 specpdl_ptr++;
94b612ad 3377 set_internal (symbol, value, Qnil, 1);
ce5b453a
SM
3378 break;
3379 }
3380 default: abort ();
9ab90667 3381 }
db9f0278
JB
3382}
3383
3384void
d3da34e0 3385record_unwind_protect (Lisp_Object (*function) (Lisp_Object), Lisp_Object arg)
db9f0278 3386{
9ba8e10d
CY
3387 eassert (!handling_signal);
3388
db9f0278
JB
3389 if (specpdl_ptr == specpdl + specpdl_size)
3390 grow_specpdl ();
3391 specpdl_ptr->func = function;
3392 specpdl_ptr->symbol = Qnil;
3393 specpdl_ptr->old_value = arg;
3394 specpdl_ptr++;
3395}
3396
3397Lisp_Object
d3da34e0 3398unbind_to (int count, Lisp_Object value)
db9f0278 3399{
5a073f50
KS
3400 Lisp_Object quitf = Vquit_flag;
3401 struct gcpro gcpro1, gcpro2;
db9f0278 3402
5a073f50 3403 GCPRO2 (value, quitf);
db9f0278
JB
3404 Vquit_flag = Qnil;
3405
3406 while (specpdl_ptr != specpdl + count)
3407 {
611a8f8c
RS
3408 /* Copy the binding, and decrement specpdl_ptr, before we do
3409 the work to unbind it. We decrement first
3410 so that an error in unbinding won't try to unbind
3411 the same entry again, and we copy the binding first
3412 in case more bindings are made during some of the code we run. */
eb700b82 3413
45f266dc
DL
3414 struct specbinding this_binding;
3415 this_binding = *--specpdl_ptr;
611a8f8c
RS
3416
3417 if (this_binding.func != 0)
3418 (*this_binding.func) (this_binding.old_value);
0967b4b0
GM
3419 /* If the symbol is a list, it is really (SYMBOL WHERE
3420 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3421 frame. If WHERE is a buffer or frame, this indicates we
1b1acc13
PJ
3422 bound a variable that had a buffer-local or frame-local
3423 binding. WHERE nil means that the variable had the default
0967b4b0 3424 value when it was bound. CURRENT-BUFFER is the buffer that
bb8e180f 3425 was current when the variable was bound. */
611a8f8c 3426 else if (CONSP (this_binding.symbol))
719177b3 3427 {
eb700b82 3428 Lisp_Object symbol, where;
719177b3 3429
611a8f8c
RS
3430 symbol = XCAR (this_binding.symbol);
3431 where = XCAR (XCDR (this_binding.symbol));
719177b3 3432
eb700b82 3433 if (NILP (where))
611a8f8c 3434 Fset_default (symbol, this_binding.old_value);
94b612ad
SM
3435 /* If `where' is non-nil, reset the value in the appropriate
3436 local binding, but only if that binding still exists. */
4e2db1fe
SM
3437 else if (BUFFERP (where)
3438 ? !NILP (Flocal_variable_p (symbol, where))
3439 : !NILP (Fassq (symbol, XFRAME (where)->param_alist)))
3440 set_internal (symbol, this_binding.old_value, where, 1);
719177b3 3441 }
94b612ad
SM
3442 /* If variable has a trivial value (no forwarding), we can
3443 just set it. No need to check for constant symbols here,
3444 since that was already done by specbind. */
3445 else if (XSYMBOL (this_binding.symbol)->redirect == SYMBOL_PLAINVAL)
3446 SET_SYMBOL_VAL (XSYMBOL (this_binding.symbol),
3447 this_binding.old_value);
db9f0278 3448 else
94b612ad
SM
3449 /* NOTE: we only ever come here if make_local_foo was used for
3450 the first time on this var within this let. */
3451 Fset_default (this_binding.symbol, this_binding.old_value);
db9f0278 3452 }
177c0ea7 3453
5a073f50
KS
3454 if (NILP (Vquit_flag) && !NILP (quitf))
3455 Vquit_flag = quitf;
db9f0278
JB
3456
3457 UNGCPRO;
db9f0278
JB
3458 return value;
3459}
b9598260 3460
4a330052 3461DEFUN ("special-variable-p", Fspecial_variable_p, Sspecial_variable_p, 1, 1, 0,
b9598260
SM
3462 doc: /* Return non-nil if SYMBOL's global binding has been declared special.
3463A special variable is one that will be bound dynamically, even in a
3464context where binding is lexical by default. */)
c566235d 3465 (Lisp_Object symbol)
b9598260
SM
3466{
3467 CHECK_SYMBOL (symbol);
3468 return XSYMBOL (symbol)->declared_special ? Qt : Qnil;
3469}
3470
db9f0278 3471\f
db9f0278 3472DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
9dbc9081
PJ
3473 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3474The debugger is entered when that frame exits, if the flag is non-nil. */)
5842a27b 3475 (Lisp_Object level, Lisp_Object flag)
db9f0278
JB
3476{
3477 register struct backtrace *backlist = backtrace_list;
3478 register int i;
3479
b7826503 3480 CHECK_NUMBER (level);
db9f0278
JB
3481
3482 for (i = 0; backlist && i < XINT (level); i++)
3483 {
3484 backlist = backlist->next;
3485 }
3486
3487 if (backlist)
265a9e55 3488 backlist->debug_on_exit = !NILP (flag);
db9f0278
JB
3489
3490 return flag;
3491}
3492
3493DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
9dbc9081
PJ
3494 doc: /* Print a trace of Lisp function calls currently active.
3495Output stream used is value of `standard-output'. */)
5842a27b 3496 (void)
db9f0278
JB
3497{
3498 register struct backtrace *backlist = backtrace_list;
db9f0278
JB
3499 Lisp_Object tail;
3500 Lisp_Object tem;
db9f0278 3501 struct gcpro gcpro1;
d4b6d95d 3502 Lisp_Object old_print_level = Vprint_level;
db9f0278 3503
d4b6d95d
LMI
3504 if (NILP (Vprint_level))
3505 XSETFASTINT (Vprint_level, 8);
db9f0278
JB
3506
3507 tail = Qnil;
3508 GCPRO1 (tail);
3509
3510 while (backlist)
3511 {
3512 write_string (backlist->debug_on_exit ? "* " : " ", 2);
44f230aa 3513 if (backlist->nargs == UNEVALLED)
db9f0278
JB
3514 {
3515 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
b6703b02 3516 write_string ("\n", -1);
db9f0278
JB
3517 }
3518 else
3519 {
3520 tem = *backlist->function;
f6d62986 3521 Fprin1 (tem, Qnil); /* This can QUIT. */
db9f0278 3522 write_string ("(", -1);
44f230aa
SM
3523 if (backlist->nargs == MANY)
3524 { /* FIXME: Can this happen? */
a3eed478 3525 int i;
db9f0278 3526 for (tail = *backlist->args, i = 0;
265a9e55 3527 !NILP (tail);
a3eed478 3528 tail = Fcdr (tail), i = 1)
db9f0278
JB
3529 {
3530 if (i) write_string (" ", -1);
3531 Fprin1 (Fcar (tail), Qnil);
3532 }
3533 }
3534 else
3535 {
f66c7cf8 3536 ptrdiff_t i;
db9f0278
JB
3537 for (i = 0; i < backlist->nargs; i++)
3538 {
3539 if (i) write_string (" ", -1);
3540 Fprin1 (backlist->args[i], Qnil);
3541 }
3542 }
b6703b02 3543 write_string (")\n", -1);
db9f0278 3544 }
db9f0278
JB
3545 backlist = backlist->next;
3546 }
3547
d4b6d95d 3548 Vprint_level = old_print_level;
db9f0278
JB
3549 UNGCPRO;
3550 return Qnil;
3551}
3552
17401c97 3553DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
9dbc9081
PJ
3554 doc: /* Return the function and arguments NFRAMES up from current execution point.
3555If that frame has not evaluated the arguments yet (or is a special form),
3556the value is (nil FUNCTION ARG-FORMS...).
3557If that frame has evaluated its arguments and called its function already,
3558the value is (t FUNCTION ARG-VALUES...).
3559A &rest arg is represented as the tail of the list ARG-VALUES.
3560FUNCTION is whatever was supplied as car of evaluated list,
3561or a lambda expression for macro calls.
3562If NFRAMES is more than the number of frames, the value is nil. */)
5842a27b 3563 (Lisp_Object nframes)
db9f0278
JB
3564{
3565 register struct backtrace *backlist = backtrace_list;
5d5d959d 3566 register EMACS_INT i;
db9f0278
JB
3567 Lisp_Object tem;
3568
b7826503 3569 CHECK_NATNUM (nframes);
db9f0278
JB
3570
3571 /* Find the frame requested. */
b6703b02 3572 for (i = 0; backlist && i < XFASTINT (nframes); i++)
db9f0278
JB
3573 backlist = backlist->next;
3574
3575 if (!backlist)
3576 return Qnil;
44f230aa 3577 if (backlist->nargs == UNEVALLED)
db9f0278
JB
3578 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
3579 else
3580 {
44f230aa 3581 if (backlist->nargs == MANY) /* FIXME: Can this happen? */
db9f0278
JB
3582 tem = *backlist->args;
3583 else
3584 tem = Flist (backlist->nargs, backlist->args);
3585
3586 return Fcons (Qt, Fcons (*backlist->function, tem));
3587 }
3588}
a2ff3819 3589
db9f0278 3590\f
244ed907 3591#if BYTE_MARK_STACK
4ce0541e 3592void
d3da34e0 3593mark_backtrace (void)
4ce0541e
SM
3594{
3595 register struct backtrace *backlist;
f66c7cf8 3596 ptrdiff_t i;
4ce0541e
SM
3597
3598 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3599 {
3600 mark_object (*backlist->function);
3601
44f230aa
SM
3602 if (backlist->nargs == UNEVALLED
3603 || backlist->nargs == MANY) /* FIXME: Can this happen? */
c5101a77 3604 i = 1;
4ce0541e 3605 else
c5101a77
PE
3606 i = backlist->nargs;
3607 while (i--)
4ce0541e
SM
3608 mark_object (backlist->args[i]);
3609 }
3610}
244ed907 3611#endif
4ce0541e 3612
dfcf069d 3613void
d3da34e0 3614syms_of_eval (void)
db9f0278 3615{
29208e82 3616 DEFVAR_INT ("max-specpdl-size", max_specpdl_size,
82fc29a1 3617 doc: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
9f5903bb 3618If Lisp code tries to increase the total number past this amount,
2520dc0c
RS
3619an error is signaled.
3620You can safely use a value considerably larger than the default value,
3621if that proves inconveniently small. However, if you increase it too far,
3622Emacs could run out of memory trying to make the stack bigger. */);
db9f0278 3623
29208e82 3624 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth,
9dbc9081 3625 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
2520dc0c
RS
3626
3627This limit serves to catch infinite recursions for you before they cause
9dbc9081
PJ
3628actual stack overflow in C, which would be fatal for Emacs.
3629You can safely make it considerably larger than its default value,
2520dc0c
RS
3630if that proves inconveniently small. However, if you increase it too far,
3631Emacs could overflow the real C stack, and crash. */);
db9f0278 3632
29208e82 3633 DEFVAR_LISP ("quit-flag", Vquit_flag,
9dbc9081 3634 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
42ed718e
RS
3635If the value is t, that means do an ordinary quit.
3636If the value equals `throw-on-input', that means quit by throwing
3637to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3638Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3639but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
db9f0278
JB
3640 Vquit_flag = Qnil;
3641
29208e82 3642 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit,
9dbc9081
PJ
3643 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3644Note that `quit-flag' will still be set by typing C-g,
3645so a quit will be signaled as soon as `inhibit-quit' is nil.
3646To prevent this happening, set `quit-flag' to nil
3647before making `inhibit-quit' nil. */);
db9f0278
JB
3648 Vinhibit_quit = Qnil;
3649
cd3520a4
JB
3650 DEFSYM (Qinhibit_quit, "inhibit-quit");
3651 DEFSYM (Qautoload, "autoload");
3652 DEFSYM (Qdebug_on_error, "debug-on-error");
3653 DEFSYM (Qmacro, "macro");
3654 DEFSYM (Qdeclare, "declare");
177c0ea7 3655
db9f0278
JB
3656 /* Note that the process handling also uses Qexit, but we don't want
3657 to staticpro it twice, so we just do it here. */
cd3520a4 3658 DEFSYM (Qexit, "exit");
b9598260 3659
cd3520a4
JB
3660 DEFSYM (Qinteractive, "interactive");
3661 DEFSYM (Qcommandp, "commandp");
3662 DEFSYM (Qdefun, "defun");
3663 DEFSYM (Qand_rest, "&rest");
3664 DEFSYM (Qand_optional, "&optional");
3665 DEFSYM (Qclosure, "closure");
3666 DEFSYM (Qdebug, "debug");
f01cbfdd 3667
29208e82 3668 DEFVAR_LISP ("debug-on-error", Vdebug_on_error,
9dbc9081
PJ
3669 doc: /* *Non-nil means enter debugger if an error is signaled.
3670Does not apply to errors handled by `condition-case' or those
3671matched by `debug-ignored-errors'.
3672If the value is a list, an error only means to enter the debugger
3673if one of its condition symbols appears in the list.
3674When you evaluate an expression interactively, this variable
3675is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
fbbdcf2f
CY
3676The command `toggle-debug-on-error' toggles this.
3677See also the variable `debug-on-quit'. */);
128c0f66 3678 Vdebug_on_error = Qnil;
db9f0278 3679
29208e82 3680 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors,
9dbc9081
PJ
3681 doc: /* *List of errors for which the debugger should not be called.
3682Each element may be a condition-name or a regexp that matches error messages.
3683If any element applies to a given error, that error skips the debugger
3684and just returns to top level.
3685This overrides the variable `debug-on-error'.
3686It does not apply to errors handled by `condition-case'. */);
fc950e09
KH
3687 Vdebug_ignored_errors = Qnil;
3688
29208e82 3689 DEFVAR_BOOL ("debug-on-quit", debug_on_quit,
82fc29a1
JB
3690 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3691Does not apply if quit is handled by a `condition-case'. */);
db9f0278
JB
3692 debug_on_quit = 0;
3693
29208e82 3694 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call,
9dbc9081 3695 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
db9f0278 3696
29208e82 3697 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue,
9dbc9081
PJ
3698 doc: /* Non-nil means debugger may continue execution.
3699This is nil when the debugger is called under circumstances where it
3700might not be safe to continue. */);
dac204bc 3701 debugger_may_continue = 1;
556d7314 3702
29208e82 3703 DEFVAR_LISP ("debugger", Vdebugger,
9dbc9081
PJ
3704 doc: /* Function to call to invoke debugger.
3705If due to frame exit, args are `exit' and the value being returned;
3706 this function's value will be returned instead of that.
3707If due to error, args are `error' and a list of the args to `signal'.
3708If due to `apply' or `funcall' entry, one arg, `lambda'.
3709If due to `eval' entry, one arg, t. */);
db9f0278
JB
3710 Vdebugger = Qnil;
3711
29208e82 3712 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function,
9dbc9081
PJ
3713 doc: /* If non-nil, this is a function for `signal' to call.
3714It receives the same arguments that `signal' was given.
3715The Edebug package uses this to regain control. */);
61ede770
RS
3716 Vsignal_hook_function = Qnil;
3717
29208e82 3718 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal,
9dbc9081
PJ
3719 doc: /* *Non-nil means call the debugger regardless of condition handlers.
3720Note that `debug-on-error', `debug-on-quit' and friends
3721still determine whether to handle the particular condition. */);
57a6e758 3722 Vdebug_on_signal = Qnil;
61ede770 3723
29208e82 3724 DEFVAR_LISP ("macro-declaration-function", Vmacro_declaration_function,
d6edd563
GM
3725 doc: /* Function to process declarations in a macro definition.
3726The function will be called with two args MACRO and DECL.
3727MACRO is the name of the macro being defined.
3728DECL is a list `(declare ...)' containing the declarations.
3729The value the function returns is not used. */);
3730 Vmacro_declaration_function = Qnil;
3731
b38b1ec0
SM
3732 /* When lexical binding is being used,
3733 vinternal_interpreter_environment is non-nil, and contains an alist
3734 of lexically-bound variable, or (t), indicating an empty
3735 environment. The lisp name of this variable would be
3736 `internal-interpreter-environment' if it weren't hidden.
3737 Every element of this list can be either a cons (VAR . VAL)
3738 specifying a lexical binding, or a single symbol VAR indicating
3739 that this variable should use dynamic scoping. */
cd3520a4 3740 DEFSYM (Qinternal_interpreter_environment, "internal-interpreter-environment");
b38b1ec0
SM
3741 DEFVAR_LISP ("internal-interpreter-environment",
3742 Vinternal_interpreter_environment,
b9598260
SM
3743 doc: /* If non-nil, the current lexical environment of the lisp interpreter.
3744When lexical binding is not being used, this variable is nil.
3745A value of `(t)' indicates an empty environment, otherwise it is an
3746alist of active lexical bindings. */);
3747 Vinternal_interpreter_environment = Qnil;
c80e3b4a 3748 /* Don't export this variable to Elisp, so no one can mess with it
b38b1ec0
SM
3749 (Just imagine if someone makes it buffer-local). */
3750 Funintern (Qinternal_interpreter_environment, Qnil);
b9598260 3751
cd3520a4 3752 DEFSYM (Vrun_hooks, "run-hooks");
db9f0278
JB
3753
3754 staticpro (&Vautoload_queue);
3755 Vautoload_queue = Qnil;
a2ff3819
GM
3756 staticpro (&Vsignaling_function);
3757 Vsignaling_function = Qnil;
db9f0278
JB
3758
3759 defsubr (&Sor);
3760 defsubr (&Sand);
3761 defsubr (&Sif);
3762 defsubr (&Scond);
3763 defsubr (&Sprogn);
3764 defsubr (&Sprog1);
3765 defsubr (&Sprog2);
3766 defsubr (&Ssetq);
3767 defsubr (&Squote);
3768 defsubr (&Sfunction);
3769 defsubr (&Sdefun);
3770 defsubr (&Sdefmacro);
3771 defsubr (&Sdefvar);
19cebf5a 3772 defsubr (&Sdefvaralias);
db9f0278
JB
3773 defsubr (&Sdefconst);
3774 defsubr (&Suser_variable_p);
3775 defsubr (&Slet);
3776 defsubr (&SletX);
3777 defsubr (&Swhile);
3778 defsubr (&Smacroexpand);
3779 defsubr (&Scatch);
3780 defsubr (&Sthrow);
3781 defsubr (&Sunwind_protect);
3782 defsubr (&Scondition_case);
3783 defsubr (&Ssignal);
3784 defsubr (&Sinteractive_p);
4b664e76 3785 defsubr (&Scalled_interactively_p);
db9f0278
JB
3786 defsubr (&Scommandp);
3787 defsubr (&Sautoload);
3788 defsubr (&Seval);
3789 defsubr (&Sapply);
3790 defsubr (&Sfuncall);
ff936e53
SM
3791 defsubr (&Srun_hooks);
3792 defsubr (&Srun_hook_with_args);
3793 defsubr (&Srun_hook_with_args_until_success);
3794 defsubr (&Srun_hook_with_args_until_failure);
f6d62986 3795 defsubr (&Srun_hook_wrapped);
661c7d6e 3796 defsubr (&Sfetch_bytecode);
db9f0278
JB
3797 defsubr (&Sbacktrace_debug);
3798 defsubr (&Sbacktrace);
3799 defsubr (&Sbacktrace_frame);
4a330052 3800 defsubr (&Sspecial_variable_p);
b9598260 3801 defsubr (&Sfunctionp);
db9f0278 3802}