1 /* Evaluator for GNU Emacs Lisp interpreter.
3 Copyright (C) 1985-1987, 1993-1995, 1999-2016 Free Software Foundation,
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or (at
11 your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26 #include "blockinput.h"
29 #include "dispextern.h"
32 /* Chain of condition and catch handlers currently in effect. */
34 struct handler
*handlerlist
;
36 /* Non-nil means record all fset's and provide's, to be undone
37 if the file being autoloaded is not fully loaded.
38 They are recorded by being consed onto the front of Vautoload_queue:
39 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
41 Lisp_Object Vautoload_queue
;
43 /* This holds either the symbol `run-hooks' or nil.
44 It is nil at an early stage of startup, and when Emacs
46 Lisp_Object Vrun_hooks
;
48 /* Current number of specbindings allocated in specpdl, not counting
49 the dummy entry specpdl[-1]. */
51 ptrdiff_t specpdl_size
;
53 /* Pointer to beginning of specpdl. A dummy entry specpdl[-1] exists
54 only so that its address can be taken. */
56 union specbinding
*specpdl
;
58 /* Pointer to first unused element in specpdl. */
60 union specbinding
*specpdl_ptr
;
62 /* Depth in Lisp evaluations and function calls. */
64 static EMACS_INT lisp_eval_depth
;
66 /* The value of num_nonmacro_input_events as of the last time we
67 started to enter the debugger. If we decide to enter the debugger
68 again when this is still equal to num_nonmacro_input_events, then we
69 know that the debugger itself has an error, and we should just
70 signal the error instead of entering an infinite loop of debugger
73 static EMACS_INT when_entered_debugger
;
75 /* The function from which the last `signal' was called. Set in
77 /* FIXME: We should probably get rid of this! */
78 Lisp_Object Vsignaling_function
;
80 /* If non-nil, Lisp code must not be run since some part of Emacs is in
81 an inconsistent state. Currently unused. */
82 Lisp_Object inhibit_lisp_code
;
84 /* These would ordinarily be static, but they need to be visible to GDB. */
85 bool backtrace_p (union specbinding
*) EXTERNALLY_VISIBLE
;
86 Lisp_Object
*backtrace_args (union specbinding
*) EXTERNALLY_VISIBLE
;
87 Lisp_Object
backtrace_function (union specbinding
*) EXTERNALLY_VISIBLE
;
88 union specbinding
*backtrace_next (union specbinding
*) EXTERNALLY_VISIBLE
;
89 union specbinding
*backtrace_top (void) EXTERNALLY_VISIBLE
;
91 static Lisp_Object
funcall_lambda (Lisp_Object
, ptrdiff_t, Lisp_Object
*);
92 static Lisp_Object
apply_lambda (Lisp_Object
, Lisp_Object
, ptrdiff_t);
93 static Lisp_Object
lambda_arity (Lisp_Object
);
96 specpdl_symbol (union specbinding
*pdl
)
98 eassert (pdl
->kind
>= SPECPDL_LET
);
99 return pdl
->let
.symbol
;
103 specpdl_old_value (union specbinding
*pdl
)
105 eassert (pdl
->kind
>= SPECPDL_LET
);
106 return pdl
->let
.old_value
;
110 set_specpdl_old_value (union specbinding
*pdl
, Lisp_Object val
)
112 eassert (pdl
->kind
>= SPECPDL_LET
);
113 pdl
->let
.old_value
= val
;
117 specpdl_where (union specbinding
*pdl
)
119 eassert (pdl
->kind
> SPECPDL_LET
);
120 return pdl
->let
.where
;
124 specpdl_arg (union specbinding
*pdl
)
126 eassert (pdl
->kind
== SPECPDL_UNWIND
);
127 return pdl
->unwind
.arg
;
131 backtrace_function (union specbinding
*pdl
)
133 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
134 return pdl
->bt
.function
;
138 backtrace_nargs (union specbinding
*pdl
)
140 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
141 return pdl
->bt
.nargs
;
145 backtrace_args (union specbinding
*pdl
)
147 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
152 backtrace_debug_on_exit (union specbinding
*pdl
)
154 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
155 return pdl
->bt
.debug_on_exit
;
158 /* Functions to modify slots of backtrace records. */
161 set_backtrace_args (union specbinding
*pdl
, Lisp_Object
*args
, ptrdiff_t nargs
)
163 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
165 pdl
->bt
.nargs
= nargs
;
169 set_backtrace_debug_on_exit (union specbinding
*pdl
, bool doe
)
171 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
172 pdl
->bt
.debug_on_exit
= doe
;
175 /* Helper functions to scan the backtrace. */
178 backtrace_p (union specbinding
*pdl
)
179 { return pdl
>= specpdl
; }
184 union specbinding
*pdl
= specpdl_ptr
- 1;
185 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
191 backtrace_next (union specbinding
*pdl
)
194 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
199 /* Return a pointer to somewhere near the top of the C stack. */
201 near_C_stack_top (void)
203 return backtrace_args (backtrace_top ());
207 init_eval_once (void)
210 union specbinding
*pdlvec
= xmalloc ((size
+ 1) * sizeof *specpdl
);
212 specpdl
= specpdl_ptr
= pdlvec
+ 1;
213 /* Don't forget to update docs (lispref node "Local Variables"). */
214 max_specpdl_size
= 1300; /* 1000 is not enough for CEDET's c-by.el. */
215 max_lisp_eval_depth
= 800;
220 static struct handler handlerlist_sentinel
;
226 specpdl_ptr
= specpdl
;
227 { /* Put a dummy catcher at top-level so that handlerlist is never NULL.
228 This is important since handlerlist->nextfree holds the freelist
229 which would otherwise leak every time we unwind back to top-level. */
230 handlerlist
= handlerlist_sentinel
.nextfree
= &handlerlist_sentinel
;
231 struct handler
*c
= push_handler (Qunbound
, CATCHER
);
232 eassert (c
== &handlerlist_sentinel
);
233 handlerlist_sentinel
.nextfree
= NULL
;
234 handlerlist_sentinel
.next
= NULL
;
237 debug_on_next_call
= 0;
239 /* This is less than the initial value of num_nonmacro_input_events. */
240 when_entered_debugger
= -1;
243 /* Unwind-protect function used by call_debugger. */
246 restore_stack_limits (Lisp_Object data
)
248 max_specpdl_size
= XINT (XCAR (data
));
249 max_lisp_eval_depth
= XINT (XCDR (data
));
252 static void grow_specpdl (void);
254 /* Call the Lisp debugger, giving it argument ARG. */
257 call_debugger (Lisp_Object arg
)
259 bool debug_while_redisplaying
;
260 ptrdiff_t count
= SPECPDL_INDEX ();
262 EMACS_INT old_depth
= max_lisp_eval_depth
;
263 /* Do not allow max_specpdl_size less than actual depth (Bug#16603). */
264 EMACS_INT old_max
= max (max_specpdl_size
, count
);
266 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
267 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
269 /* While debugging Bug#16603, previous value of 100 was found
270 too small to avoid specpdl overflow in the debugger itself. */
271 if (max_specpdl_size
- 200 < count
)
272 max_specpdl_size
= count
+ 200;
274 if (old_max
== count
)
276 /* We can enter the debugger due to specpdl overflow (Bug#16603). */
281 /* Restore limits after leaving the debugger. */
282 record_unwind_protect (restore_stack_limits
,
283 Fcons (make_number (old_max
),
284 make_number (old_depth
)));
286 #ifdef HAVE_WINDOW_SYSTEM
287 if (display_hourglass_p
)
291 debug_on_next_call
= 0;
292 when_entered_debugger
= num_nonmacro_input_events
;
294 /* Resetting redisplaying_p to 0 makes sure that debug output is
295 displayed if the debugger is invoked during redisplay. */
296 debug_while_redisplaying
= redisplaying_p
;
298 specbind (intern ("debugger-may-continue"),
299 debug_while_redisplaying
? Qnil
: Qt
);
300 specbind (Qinhibit_redisplay
, Qnil
);
301 specbind (Qinhibit_debugger
, Qt
);
303 #if 0 /* Binding this prevents execution of Lisp code during
304 redisplay, which necessarily leads to display problems. */
305 specbind (Qinhibit_eval_during_redisplay
, Qt
);
308 val
= apply1 (Vdebugger
, arg
);
310 /* Interrupting redisplay and resuming it later is not safe under
311 all circumstances. So, when the debugger returns, abort the
312 interrupted redisplay by going back to the top-level. */
313 if (debug_while_redisplaying
)
316 return unbind_to (count
, val
);
320 do_debug_on_call (Lisp_Object code
, ptrdiff_t count
)
322 debug_on_next_call
= 0;
323 set_backtrace_debug_on_exit (specpdl
+ count
, true);
324 call_debugger (list1 (code
));
327 /* NOTE!!! Every function that can call EVAL must protect its args
328 and temporaries from garbage collection while it needs them.
329 The definition of `For' shows what you have to do. */
331 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
332 doc
: /* Eval args until one of them yields non-nil, then return that value.
333 The remaining args are not evalled at all.
334 If all args return nil, return nil.
335 usage: (or CONDITIONS...) */)
338 Lisp_Object val
= Qnil
;
342 val
= eval_sub (XCAR (args
));
351 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
352 doc
: /* Eval args until one of them yields nil, then return nil.
353 The remaining args are not evalled at all.
354 If no arg yields nil, return the last arg's value.
355 usage: (and CONDITIONS...) */)
358 Lisp_Object val
= Qt
;
362 val
= eval_sub (XCAR (args
));
371 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
372 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
373 Returns the value of THEN or the value of the last of the ELSE's.
374 THEN must be one expression, but ELSE... can be zero or more expressions.
375 If COND yields nil, and there are no ELSE's, the value is nil.
376 usage: (if COND THEN ELSE...) */)
381 cond
= eval_sub (XCAR (args
));
384 return eval_sub (Fcar (XCDR (args
)));
385 return Fprogn (XCDR (XCDR (args
)));
388 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
389 doc
: /* Try each clause until one succeeds.
390 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
391 and, if the value is non-nil, this clause succeeds:
392 then the expressions in BODY are evaluated and the last one's
393 value is the value of the cond-form.
394 If a clause has one element, as in (CONDITION), then the cond-form
395 returns CONDITION's value, if that is non-nil.
396 If no clause succeeds, cond returns nil.
397 usage: (cond CLAUSES...) */)
400 Lisp_Object val
= args
;
404 Lisp_Object clause
= XCAR (args
);
405 val
= eval_sub (Fcar (clause
));
408 if (!NILP (XCDR (clause
)))
409 val
= Fprogn (XCDR (clause
));
418 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
419 doc
: /* Eval BODY forms sequentially and return value of last one.
420 usage: (progn BODY...) */)
423 Lisp_Object val
= Qnil
;
427 val
= eval_sub (XCAR (body
));
434 /* Evaluate BODY sequentially, discarding its value. Suitable for
435 record_unwind_protect. */
438 unwind_body (Lisp_Object body
)
443 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
444 doc
: /* Eval FIRST and BODY sequentially; return value from FIRST.
445 The value of FIRST is saved during the evaluation of the remaining args,
446 whose values are discarded.
447 usage: (prog1 FIRST BODY...) */)
451 Lisp_Object args_left
;
456 val
= eval_sub (XCAR (args_left
));
457 while (CONSP (args_left
= XCDR (args_left
)))
458 eval_sub (XCAR (args_left
));
463 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
464 doc
: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
465 The value of FORM2 is saved during the evaluation of the
466 remaining args, whose values are discarded.
467 usage: (prog2 FORM1 FORM2 BODY...) */)
470 eval_sub (XCAR (args
));
471 return Fprog1 (XCDR (args
));
474 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
475 doc
: /* Set each SYM to the value of its VAL.
476 The symbols SYM are variables; they are literal (not evaluated).
477 The values VAL are expressions; they are evaluated.
478 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
479 The second VAL is not computed until after the first SYM is set, and so on;
480 each VAL can use the new value of variables set earlier in the `setq'.
481 The return value of the `setq' form is the value of the last VAL.
482 usage: (setq [SYM VAL]...) */)
485 Lisp_Object val
, sym
, lex_binding
;
490 Lisp_Object args_left
= args
;
491 Lisp_Object numargs
= Flength (args
);
493 if (XINT (numargs
) & 1)
494 xsignal2 (Qwrong_number_of_arguments
, Qsetq
, numargs
);
498 val
= eval_sub (Fcar (XCDR (args_left
)));
499 sym
= XCAR (args_left
);
501 /* Like for eval_sub, we do not check declared_special here since
502 it's been done when let-binding. */
503 if (!NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
505 && !NILP (lex_binding
506 = Fassq (sym
, Vinternal_interpreter_environment
)))
507 XSETCDR (lex_binding
, val
); /* SYM is lexically bound. */
509 Fset (sym
, val
); /* SYM is dynamically bound. */
511 args_left
= Fcdr (XCDR (args_left
));
513 while (CONSP (args_left
));
519 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
520 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
521 Warning: `quote' does not construct its return value, but just returns
522 the value that was pre-constructed by the Lisp reader (see info node
523 `(elisp)Printed Representation').
524 This means that \\='(a . b) is not identical to (cons \\='a \\='b): the former
525 does not cons. Quoting should be reserved for constants that will
526 never be modified by side-effects, unless you like self-modifying code.
527 See the common pitfall in info node `(elisp)Rearrangement' for an example
528 of unexpected results when a quoted object is modified.
529 usage: (quote ARG) */)
532 if (CONSP (XCDR (args
)))
533 xsignal2 (Qwrong_number_of_arguments
, Qquote
, Flength (args
));
537 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
538 doc
: /* Like `quote', but preferred for objects which are functions.
539 In byte compilation, `function' causes its argument to be compiled.
540 `quote' cannot do that.
541 usage: (function ARG) */)
544 Lisp_Object quoted
= XCAR (args
);
546 if (CONSP (XCDR (args
)))
547 xsignal2 (Qwrong_number_of_arguments
, Qfunction
, Flength (args
));
549 if (!NILP (Vinternal_interpreter_environment
)
551 && EQ (XCAR (quoted
), Qlambda
))
552 { /* This is a lambda expression within a lexical environment;
553 return an interpreted closure instead of a simple lambda. */
554 Lisp_Object cdr
= XCDR (quoted
);
555 Lisp_Object tmp
= cdr
;
557 && (tmp
= XCDR (tmp
), CONSP (tmp
))
558 && (tmp
= XCAR (tmp
), CONSP (tmp
))
559 && (EQ (QCdocumentation
, XCAR (tmp
))))
560 { /* Handle the special (:documentation <form>) to build the docstring
562 Lisp_Object docstring
= eval_sub (Fcar (XCDR (tmp
)));
563 CHECK_STRING (docstring
);
564 cdr
= Fcons (XCAR (cdr
), Fcons (docstring
, XCDR (XCDR (cdr
))));
566 return Fcons (Qclosure
, Fcons (Vinternal_interpreter_environment
,
570 /* Simply quote the argument. */
575 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
576 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
577 Aliased variables always have the same value; setting one sets the other.
578 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
579 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
580 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
581 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
582 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
583 The return value is BASE-VARIABLE. */)
584 (Lisp_Object new_alias
, Lisp_Object base_variable
, Lisp_Object docstring
)
586 struct Lisp_Symbol
*sym
;
588 CHECK_SYMBOL (new_alias
);
589 CHECK_SYMBOL (base_variable
);
591 sym
= XSYMBOL (new_alias
);
594 /* Not sure why, but why not? */
595 error ("Cannot make a constant an alias");
597 switch (sym
->redirect
)
599 case SYMBOL_FORWARDED
:
600 error ("Cannot make an internal variable an alias");
601 case SYMBOL_LOCALIZED
:
602 error ("Don't know how to make a localized variable an alias");
603 case SYMBOL_PLAINVAL
:
604 case SYMBOL_VARALIAS
:
610 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
611 If n_a is bound, but b_v is not, set the value of b_v to n_a,
612 so that old-code that affects n_a before the aliasing is setup
614 if (NILP (Fboundp (base_variable
)))
615 set_internal (base_variable
, find_symbol_value (new_alias
), Qnil
, 1);
618 union specbinding
*p
;
620 for (p
= specpdl_ptr
; p
> specpdl
; )
621 if ((--p
)->kind
>= SPECPDL_LET
622 && (EQ (new_alias
, specpdl_symbol (p
))))
623 error ("Don't know how to make a let-bound variable an alias");
626 sym
->declared_special
= 1;
627 XSYMBOL (base_variable
)->declared_special
= 1;
628 sym
->redirect
= SYMBOL_VARALIAS
;
629 SET_SYMBOL_ALIAS (sym
, XSYMBOL (base_variable
));
630 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
631 LOADHIST_ATTACH (new_alias
);
632 /* Even if docstring is nil: remove old docstring. */
633 Fput (new_alias
, Qvariable_documentation
, docstring
);
635 return base_variable
;
638 static union specbinding
*
639 default_toplevel_binding (Lisp_Object symbol
)
641 union specbinding
*binding
= NULL
;
642 union specbinding
*pdl
= specpdl_ptr
;
643 while (pdl
> specpdl
)
645 switch ((--pdl
)->kind
)
647 case SPECPDL_LET_DEFAULT
:
649 if (EQ (specpdl_symbol (pdl
), symbol
))
654 case SPECPDL_UNWIND_PTR
:
655 case SPECPDL_UNWIND_INT
:
656 case SPECPDL_UNWIND_VOID
:
657 case SPECPDL_BACKTRACE
:
658 case SPECPDL_LET_LOCAL
:
668 DEFUN ("default-toplevel-value", Fdefault_toplevel_value
, Sdefault_toplevel_value
, 1, 1, 0,
669 doc
: /* Return SYMBOL's toplevel default value.
670 "Toplevel" means outside of any let binding. */)
673 union specbinding
*binding
= default_toplevel_binding (symbol
);
675 = binding
? specpdl_old_value (binding
) : Fdefault_value (symbol
);
676 if (!EQ (value
, Qunbound
))
678 xsignal1 (Qvoid_variable
, symbol
);
681 DEFUN ("set-default-toplevel-value", Fset_default_toplevel_value
,
682 Sset_default_toplevel_value
, 2, 2, 0,
683 doc
: /* Set SYMBOL's toplevel default value to VALUE.
684 "Toplevel" means outside of any let binding. */)
685 (Lisp_Object symbol
, Lisp_Object value
)
687 union specbinding
*binding
= default_toplevel_binding (symbol
);
689 set_specpdl_old_value (binding
, value
);
691 Fset_default (symbol
, value
);
695 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
696 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
697 You are not required to define a variable in order to use it, but
698 defining it lets you supply an initial value and documentation, which
699 can be referred to by the Emacs help facilities and other programming
700 tools. The `defvar' form also declares the variable as \"special\",
701 so that it is always dynamically bound even if `lexical-binding' is t.
703 The optional argument INITVALUE is evaluated, and used to set SYMBOL,
704 only if SYMBOL's value is void. If SYMBOL is buffer-local, its
705 default value is what is set; buffer-local values are not affected.
706 If INITVALUE is missing, SYMBOL's value is not set.
708 If SYMBOL has a local binding, then this form affects the local
709 binding. This is usually not what you want. Thus, if you need to
710 load a file defining variables, with this form or with `defconst' or
711 `defcustom', you should always load that file _outside_ any bindings
712 for these variables. (`defconst' and `defcustom' behave similarly in
715 The optional argument DOCSTRING is a documentation string for the
718 To define a user option, use `defcustom' instead of `defvar'.
719 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
722 Lisp_Object sym
, tem
, tail
;
729 if (CONSP (XCDR (tail
)) && CONSP (XCDR (XCDR (tail
))))
730 error ("Too many arguments");
732 tem
= Fdefault_boundp (sym
);
734 /* Do it before evaluating the initial value, for self-references. */
735 XSYMBOL (sym
)->declared_special
= 1;
738 Fset_default (sym
, eval_sub (XCAR (tail
)));
740 { /* Check if there is really a global binding rather than just a let
741 binding that shadows the global unboundness of the var. */
742 union specbinding
*binding
= default_toplevel_binding (sym
);
743 if (binding
&& EQ (specpdl_old_value (binding
), Qunbound
))
745 set_specpdl_old_value (binding
, eval_sub (XCAR (tail
)));
752 if (!NILP (Vpurify_flag
))
753 tem
= Fpurecopy (tem
);
754 Fput (sym
, Qvariable_documentation
, tem
);
756 LOADHIST_ATTACH (sym
);
758 else if (!NILP (Vinternal_interpreter_environment
)
759 && !XSYMBOL (sym
)->declared_special
)
760 /* A simple (defvar foo) with lexical scoping does "nothing" except
761 declare that var to be dynamically scoped *locally* (i.e. within
762 the current file or let-block). */
763 Vinternal_interpreter_environment
764 = Fcons (sym
, Vinternal_interpreter_environment
);
767 /* Simple (defvar <var>) should not count as a definition at all.
768 It could get in the way of other definitions, and unloading this
769 package could try to make the variable unbound. */
775 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
776 doc
: /* Define SYMBOL as a constant variable.
777 This declares that neither programs nor users should ever change the
778 value. This constancy is not actually enforced by Emacs Lisp, but
779 SYMBOL is marked as a special variable so that it is never lexically
782 The `defconst' form always sets the value of SYMBOL to the result of
783 evalling INITVALUE. If SYMBOL is buffer-local, its default value is
784 what is set; buffer-local values are not affected. If SYMBOL has a
785 local binding, then this form sets the local binding's value.
786 However, you should normally not make local bindings for variables
787 defined with this form.
789 The optional DOCSTRING specifies the variable's documentation string.
790 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
793 Lisp_Object sym
, tem
;
796 if (CONSP (Fcdr (XCDR (XCDR (args
)))))
797 error ("Too many arguments");
799 tem
= eval_sub (Fcar (XCDR (args
)));
800 if (!NILP (Vpurify_flag
))
801 tem
= Fpurecopy (tem
);
802 Fset_default (sym
, tem
);
803 XSYMBOL (sym
)->declared_special
= 1;
804 tem
= Fcar (XCDR (XCDR (args
)));
807 if (!NILP (Vpurify_flag
))
808 tem
= Fpurecopy (tem
);
809 Fput (sym
, Qvariable_documentation
, tem
);
811 Fput (sym
, Qrisky_local_variable
, Qt
);
812 LOADHIST_ATTACH (sym
);
816 /* Make SYMBOL lexically scoped. */
817 DEFUN ("internal-make-var-non-special", Fmake_var_non_special
,
818 Smake_var_non_special
, 1, 1, 0,
819 doc
: /* Internal function. */)
822 CHECK_SYMBOL (symbol
);
823 XSYMBOL (symbol
)->declared_special
= 0;
828 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
829 doc
: /* Bind variables according to VARLIST then eval BODY.
830 The value of the last form in BODY is returned.
831 Each element of VARLIST is a symbol (which is bound to nil)
832 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
833 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
834 usage: (let* VARLIST BODY...) */)
837 Lisp_Object varlist
, var
, val
, elt
, lexenv
;
838 ptrdiff_t count
= SPECPDL_INDEX ();
840 lexenv
= Vinternal_interpreter_environment
;
842 varlist
= XCAR (args
);
843 while (CONSP (varlist
))
847 elt
= XCAR (varlist
);
853 else if (! NILP (Fcdr (Fcdr (elt
))))
854 signal_error ("`let' bindings can have only one value-form", elt
);
858 val
= eval_sub (Fcar (Fcdr (elt
)));
861 if (!NILP (lexenv
) && SYMBOLP (var
)
862 && !XSYMBOL (var
)->declared_special
863 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
864 /* Lexically bind VAR by adding it to the interpreter's binding
868 = Fcons (Fcons (var
, val
), Vinternal_interpreter_environment
);
869 if (EQ (Vinternal_interpreter_environment
, lexenv
))
870 /* Save the old lexical environment on the specpdl stack,
871 but only for the first lexical binding, since we'll never
872 need to revert to one of the intermediate ones. */
873 specbind (Qinternal_interpreter_environment
, newenv
);
875 Vinternal_interpreter_environment
= newenv
;
880 varlist
= XCDR (varlist
);
883 val
= Fprogn (XCDR (args
));
884 return unbind_to (count
, val
);
887 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
888 doc
: /* Bind variables according to VARLIST then eval BODY.
889 The value of the last form in BODY is returned.
890 Each element of VARLIST is a symbol (which is bound to nil)
891 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
892 All the VALUEFORMs are evalled before any symbols are bound.
893 usage: (let VARLIST BODY...) */)
896 Lisp_Object
*temps
, tem
, lexenv
;
897 Lisp_Object elt
, varlist
;
898 ptrdiff_t count
= SPECPDL_INDEX ();
902 varlist
= XCAR (args
);
904 /* Make space to hold the values to give the bound variables. */
905 elt
= Flength (varlist
);
906 SAFE_ALLOCA_LISP (temps
, XFASTINT (elt
));
908 /* Compute the values and store them in `temps'. */
910 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
913 elt
= XCAR (varlist
);
915 temps
[argnum
++] = Qnil
;
916 else if (! NILP (Fcdr (Fcdr (elt
))))
917 signal_error ("`let' bindings can have only one value-form", elt
);
919 temps
[argnum
++] = eval_sub (Fcar (Fcdr (elt
)));
922 lexenv
= Vinternal_interpreter_environment
;
924 varlist
= XCAR (args
);
925 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
929 elt
= XCAR (varlist
);
930 var
= SYMBOLP (elt
) ? elt
: Fcar (elt
);
931 tem
= temps
[argnum
++];
933 if (!NILP (lexenv
) && SYMBOLP (var
)
934 && !XSYMBOL (var
)->declared_special
935 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
936 /* Lexically bind VAR by adding it to the lexenv alist. */
937 lexenv
= Fcons (Fcons (var
, tem
), lexenv
);
939 /* Dynamically bind VAR. */
943 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
944 /* Instantiate a new lexical environment. */
945 specbind (Qinternal_interpreter_environment
, lexenv
);
947 elt
= Fprogn (XCDR (args
));
949 return unbind_to (count
, elt
);
952 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
953 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
954 The order of execution is thus TEST, BODY, TEST, BODY and so on
955 until TEST returns nil.
956 usage: (while TEST BODY...) */)
959 Lisp_Object test
, body
;
963 while (!NILP (eval_sub (test
)))
972 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
973 doc
: /* Return result of expanding macros at top level of FORM.
974 If FORM is not a macro call, it is returned unchanged.
975 Otherwise, the macro is expanded and the expansion is considered
976 in place of FORM. When a non-macro-call results, it is returned.
978 The second optional arg ENVIRONMENT specifies an environment of macro
979 definitions to shadow the loaded ones for use in file byte-compilation. */)
980 (Lisp_Object form
, Lisp_Object environment
)
982 /* With cleanups from Hallvard Furuseth. */
983 register Lisp_Object expander
, sym
, def
, tem
;
987 /* Come back here each time we expand a macro call,
988 in case it expands into another macro call. */
991 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
992 def
= sym
= XCAR (form
);
994 /* Trace symbols aliases to other symbols
995 until we get a symbol that is not an alias. */
996 while (SYMBOLP (def
))
1000 tem
= Fassq (sym
, environment
);
1003 def
= XSYMBOL (sym
)->function
;
1009 /* Right now TEM is the result from SYM in ENVIRONMENT,
1010 and if TEM is nil then DEF is SYM's function definition. */
1013 /* SYM is not mentioned in ENVIRONMENT.
1014 Look at its function definition. */
1015 def
= Fautoload_do_load (def
, sym
, Qmacro
);
1017 /* Not defined or definition not suitable. */
1019 if (!EQ (XCAR (def
), Qmacro
))
1021 else expander
= XCDR (def
);
1025 expander
= XCDR (tem
);
1026 if (NILP (expander
))
1030 Lisp_Object newform
= apply1 (expander
, XCDR (form
));
1031 if (EQ (form
, newform
))
1040 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1041 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1042 TAG is evalled to get the tag to use; it must not be nil.
1044 Then the BODY is executed.
1045 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1046 If no throw happens, `catch' returns the value of the last BODY form.
1047 If a throw happens, it specifies the value to return from `catch'.
1048 usage: (catch TAG BODY...) */)
1051 Lisp_Object tag
= eval_sub (XCAR (args
));
1052 return internal_catch (tag
, Fprogn
, XCDR (args
));
1055 /* Assert that E is true, as a comment only. Use this instead of
1056 eassert (E) when E contains variables that might be clobbered by a
1059 #define clobbered_eassert(E) ((void) 0)
1061 /* Set up a catch, then call C function FUNC on argument ARG.
1062 FUNC should return a Lisp_Object.
1063 This is how catches are done from within C code. */
1066 internal_catch (Lisp_Object tag
,
1067 Lisp_Object (*func
) (Lisp_Object
), Lisp_Object arg
)
1069 /* This structure is made part of the chain `catchlist'. */
1070 struct handler
*c
= push_handler (tag
, CATCHER
);
1073 if (! sys_setjmp (c
->jmp
))
1075 Lisp_Object val
= func (arg
);
1076 clobbered_eassert (handlerlist
== c
);
1077 handlerlist
= handlerlist
->next
;
1081 { /* Throw works by a longjmp that comes right here. */
1082 Lisp_Object val
= handlerlist
->val
;
1083 clobbered_eassert (handlerlist
== c
);
1084 handlerlist
= handlerlist
->next
;
1089 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1090 jump to that CATCH, returning VALUE as the value of that catch.
1092 This is the guts of Fthrow and Fsignal; they differ only in the way
1093 they choose the catch tag to throw to. A catch tag for a
1094 condition-case form has a TAG of Qnil.
1096 Before each catch is discarded, unbind all special bindings and
1097 execute all unwind-protect clauses made above that catch. Unwind
1098 the handler stack as we go, so that the proper handlers are in
1099 effect for each unwind-protect clause we run. At the end, restore
1100 some static info saved in CATCH, and longjmp to the location
1103 This is used for correct unwinding in Fthrow and Fsignal. */
1105 static _Noreturn
void
1106 unwind_to_catch (struct handler
*catch, Lisp_Object value
)
1110 eassert (catch->next
);
1112 /* Save the value in the tag. */
1115 /* Restore certain special C variables. */
1116 set_poll_suppress_count (catch->poll_suppress_count
);
1117 unblock_input_to (catch->interrupt_input_blocked
);
1122 /* Unwind the specpdl stack, and then restore the proper set of
1124 unbind_to (handlerlist
->pdlcount
, Qnil
);
1125 last_time
= handlerlist
== catch;
1127 handlerlist
= handlerlist
->next
;
1129 while (! last_time
);
1131 eassert (handlerlist
== catch);
1133 byte_stack_list
= catch->byte_stack
;
1134 lisp_eval_depth
= catch->lisp_eval_depth
;
1136 sys_longjmp (catch->jmp
, 1);
1139 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1140 doc
: /* Throw to the catch for TAG and return VALUE from it.
1141 Both TAG and VALUE are evalled. */
1142 attributes
: noreturn
)
1143 (register Lisp_Object tag
, Lisp_Object value
)
1148 for (c
= handlerlist
; c
; c
= c
->next
)
1150 if (c
->type
== CATCHER_ALL
)
1151 unwind_to_catch (c
, Fcons (tag
, value
));
1152 if (c
->type
== CATCHER
&& EQ (c
->tag_or_ch
, tag
))
1153 unwind_to_catch (c
, value
);
1155 xsignal2 (Qno_catch
, tag
, value
);
1159 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1160 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1161 If BODYFORM completes normally, its value is returned
1162 after executing the UNWINDFORMS.
1163 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1164 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1168 ptrdiff_t count
= SPECPDL_INDEX ();
1170 record_unwind_protect (unwind_body
, XCDR (args
));
1171 val
= eval_sub (XCAR (args
));
1172 return unbind_to (count
, val
);
1175 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1176 doc
: /* Regain control when an error is signaled.
1177 Executes BODYFORM and returns its value if no error happens.
1178 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1179 where the BODY is made of Lisp expressions.
1181 A handler is applicable to an error
1182 if CONDITION-NAME is one of the error's condition names.
1183 If an error happens, the first applicable handler is run.
1185 The car of a handler may be a list of condition names instead of a
1186 single condition name; then it handles all of them. If the special
1187 condition name `debug' is present in this list, it allows another
1188 condition in the list to run the debugger if `debug-on-error' and the
1189 other usual mechanisms says it should (otherwise, `condition-case'
1190 suppresses the debugger).
1192 When a handler handles an error, control returns to the `condition-case'
1193 and it executes the handler's BODY...
1194 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1195 \(If VAR is nil, the handler can't access that information.)
1196 Then the value of the last BODY form is returned from the `condition-case'
1199 See also the function `signal' for more info.
1200 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1203 Lisp_Object var
= XCAR (args
);
1204 Lisp_Object bodyform
= XCAR (XCDR (args
));
1205 Lisp_Object handlers
= XCDR (XCDR (args
));
1207 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1210 /* Like Fcondition_case, but the args are separate
1211 rather than passed in a list. Used by Fbyte_code. */
1214 internal_lisp_condition_case (volatile Lisp_Object var
, Lisp_Object bodyform
,
1215 Lisp_Object handlers
)
1218 struct handler
*oldhandlerlist
= handlerlist
;
1223 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1225 Lisp_Object tem
= XCAR (val
);
1229 && (SYMBOLP (XCAR (tem
))
1230 || CONSP (XCAR (tem
))))))
1231 error ("Invalid condition handler: %s",
1232 SDATA (Fprin1_to_string (tem
, Qt
)));
1235 { /* The first clause is the one that should be checked first, so it should
1236 be added to handlerlist last. So we build in `clauses' a table that
1237 contains `handlers' but in reverse order. SAFE_ALLOCA won't work
1238 here due to the setjmp, so impose a MAX_ALLOCA limit. */
1239 if (MAX_ALLOCA
/ word_size
< clausenb
)
1240 memory_full (SIZE_MAX
);
1241 Lisp_Object
*clauses
= alloca (clausenb
* sizeof *clauses
);
1242 Lisp_Object
*volatile clauses_volatile
= clauses
;
1244 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1245 clauses
[--i
] = XCAR (val
);
1246 for (i
= 0; i
< clausenb
; i
++)
1248 Lisp_Object clause
= clauses
[i
];
1249 Lisp_Object condition
= CONSP (clause
) ? XCAR (clause
) : Qnil
;
1250 if (!CONSP (condition
))
1251 condition
= Fcons (condition
, Qnil
);
1252 struct handler
*c
= push_handler (condition
, CONDITION_CASE
);
1253 if (sys_setjmp (c
->jmp
))
1255 ptrdiff_t count
= SPECPDL_INDEX ();
1256 Lisp_Object val
= handlerlist
->val
;
1257 Lisp_Object
*chosen_clause
= clauses_volatile
;
1258 for (c
= handlerlist
->next
; c
!= oldhandlerlist
; c
= c
->next
)
1260 handlerlist
= oldhandlerlist
;
1263 if (!NILP (Vinternal_interpreter_environment
))
1264 specbind (Qinternal_interpreter_environment
,
1265 Fcons (Fcons (var
, val
),
1266 Vinternal_interpreter_environment
));
1268 specbind (var
, val
);
1270 val
= Fprogn (XCDR (*chosen_clause
));
1271 /* Note that this just undoes the binding of var; whoever
1272 longjumped to us unwound the stack to c.pdlcount before
1275 unbind_to (count
, Qnil
);
1281 val
= eval_sub (bodyform
);
1282 handlerlist
= oldhandlerlist
;
1286 /* Call the function BFUN with no arguments, catching errors within it
1287 according to HANDLERS. If there is an error, call HFUN with
1288 one argument which is the data that describes the error:
1291 HANDLERS can be a list of conditions to catch.
1292 If HANDLERS is Qt, catch all errors.
1293 If HANDLERS is Qerror, catch all errors
1294 but allow the debugger to run if that is enabled. */
1297 internal_condition_case (Lisp_Object (*bfun
) (void), Lisp_Object handlers
,
1298 Lisp_Object (*hfun
) (Lisp_Object
))
1300 struct handler
*c
= push_handler (handlers
, CONDITION_CASE
);
1301 if (sys_setjmp (c
->jmp
))
1303 Lisp_Object val
= handlerlist
->val
;
1304 clobbered_eassert (handlerlist
== c
);
1305 handlerlist
= handlerlist
->next
;
1310 Lisp_Object val
= bfun ();
1311 clobbered_eassert (handlerlist
== c
);
1312 handlerlist
= handlerlist
->next
;
1317 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1320 internal_condition_case_1 (Lisp_Object (*bfun
) (Lisp_Object
), Lisp_Object arg
,
1321 Lisp_Object handlers
,
1322 Lisp_Object (*hfun
) (Lisp_Object
))
1324 struct handler
*c
= push_handler (handlers
, CONDITION_CASE
);
1325 if (sys_setjmp (c
->jmp
))
1327 Lisp_Object val
= handlerlist
->val
;
1328 clobbered_eassert (handlerlist
== c
);
1329 handlerlist
= handlerlist
->next
;
1334 Lisp_Object val
= bfun (arg
);
1335 clobbered_eassert (handlerlist
== c
);
1336 handlerlist
= handlerlist
->next
;
1341 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1345 internal_condition_case_2 (Lisp_Object (*bfun
) (Lisp_Object
, Lisp_Object
),
1348 Lisp_Object handlers
,
1349 Lisp_Object (*hfun
) (Lisp_Object
))
1351 struct handler
*c
= push_handler (handlers
, CONDITION_CASE
);
1352 if (sys_setjmp (c
->jmp
))
1354 Lisp_Object val
= handlerlist
->val
;
1355 clobbered_eassert (handlerlist
== c
);
1356 handlerlist
= handlerlist
->next
;
1361 Lisp_Object val
= bfun (arg1
, arg2
);
1362 clobbered_eassert (handlerlist
== c
);
1363 handlerlist
= handlerlist
->next
;
1368 /* Like internal_condition_case but call BFUN with NARGS as first,
1369 and ARGS as second argument. */
1372 internal_condition_case_n (Lisp_Object (*bfun
) (ptrdiff_t, Lisp_Object
*),
1375 Lisp_Object handlers
,
1376 Lisp_Object (*hfun
) (Lisp_Object err
,
1380 struct handler
*c
= push_handler (handlers
, CONDITION_CASE
);
1381 if (sys_setjmp (c
->jmp
))
1383 Lisp_Object val
= handlerlist
->val
;
1384 clobbered_eassert (handlerlist
== c
);
1385 handlerlist
= handlerlist
->next
;
1386 return hfun (val
, nargs
, args
);
1390 Lisp_Object val
= bfun (nargs
, args
);
1391 clobbered_eassert (handlerlist
== c
);
1392 handlerlist
= handlerlist
->next
;
1398 push_handler (Lisp_Object tag_ch_val
, enum handlertype handlertype
)
1400 struct handler
*c
= push_handler_nosignal (tag_ch_val
, handlertype
);
1402 memory_full (sizeof *c
);
1407 push_handler_nosignal (Lisp_Object tag_ch_val
, enum handlertype handlertype
)
1409 struct handler
*c
= handlerlist
->nextfree
;
1412 c
= malloc (sizeof *c
);
1415 if (profiler_memory_running
)
1416 malloc_probe (sizeof *c
);
1418 handlerlist
->nextfree
= c
;
1420 c
->type
= handlertype
;
1421 c
->tag_or_ch
= tag_ch_val
;
1423 c
->next
= handlerlist
;
1424 c
->lisp_eval_depth
= lisp_eval_depth
;
1425 c
->pdlcount
= SPECPDL_INDEX ();
1426 c
->poll_suppress_count
= poll_suppress_count
;
1427 c
->interrupt_input_blocked
= interrupt_input_blocked
;
1428 c
->byte_stack
= byte_stack_list
;
1434 static Lisp_Object
find_handler_clause (Lisp_Object
, Lisp_Object
);
1435 static bool maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
,
1439 process_quit_flag (void)
1441 Lisp_Object flag
= Vquit_flag
;
1443 if (EQ (flag
, Qkill_emacs
))
1445 if (EQ (Vthrow_on_input
, flag
))
1446 Fthrow (Vthrow_on_input
, Qt
);
1447 Fsignal (Qquit
, Qnil
);
1450 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1451 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1452 This function does not return.
1454 An error symbol is a symbol with an `error-conditions' property
1455 that is a list of condition names.
1456 A handler for any of those names will get to handle this signal.
1457 The symbol `error' should normally be one of them.
1459 DATA should be a list. Its elements are printed as part of the error message.
1460 See Info anchor `(elisp)Definition of signal' for some details on how this
1461 error message is constructed.
1462 If the signal is handled, DATA is made available to the handler.
1463 See also the function `condition-case'. */)
1464 (Lisp_Object error_symbol
, Lisp_Object data
)
1466 /* When memory is full, ERROR-SYMBOL is nil,
1467 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1468 That is a special case--don't do this in other situations. */
1469 Lisp_Object conditions
;
1471 Lisp_Object real_error_symbol
1472 = (NILP (error_symbol
) ? Fcar (data
) : error_symbol
);
1473 register Lisp_Object clause
= Qnil
;
1478 if (gc_in_progress
|| waiting_for_input
)
1481 #if 0 /* rms: I don't know why this was here,
1482 but it is surely wrong for an error that is handled. */
1483 #ifdef HAVE_WINDOW_SYSTEM
1484 if (display_hourglass_p
)
1485 cancel_hourglass ();
1489 /* This hook is used by edebug. */
1490 if (! NILP (Vsignal_hook_function
)
1491 && ! NILP (error_symbol
))
1493 /* Edebug takes care of restoring these variables when it exits. */
1494 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1495 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1497 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1498 max_specpdl_size
= SPECPDL_INDEX () + 40;
1500 call2 (Vsignal_hook_function
, error_symbol
, data
);
1503 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1505 /* Remember from where signal was called. Skip over the frame for
1506 `signal' itself. If a frame for `error' follows, skip that,
1507 too. Don't do this when ERROR_SYMBOL is nil, because that
1508 is a memory-full error. */
1509 Vsignaling_function
= Qnil
;
1510 if (!NILP (error_symbol
))
1512 union specbinding
*pdl
= backtrace_next (backtrace_top ());
1513 if (backtrace_p (pdl
) && EQ (backtrace_function (pdl
), Qerror
))
1514 pdl
= backtrace_next (pdl
);
1515 if (backtrace_p (pdl
))
1516 Vsignaling_function
= backtrace_function (pdl
);
1519 for (h
= handlerlist
; h
; h
= h
->next
)
1521 if (h
->type
!= CONDITION_CASE
)
1523 clause
= find_handler_clause (h
->tag_or_ch
, conditions
);
1528 if (/* Don't run the debugger for a memory-full error.
1529 (There is no room in memory to do that!) */
1530 !NILP (error_symbol
)
1531 && (!NILP (Vdebug_on_signal
)
1532 /* If no handler is present now, try to run the debugger. */
1534 /* A `debug' symbol in the handler list disables the normal
1535 suppression of the debugger. */
1536 || (CONSP (clause
) && !NILP (Fmemq (Qdebug
, clause
)))
1537 /* Special handler that means "print a message and run debugger
1539 || EQ (h
->tag_or_ch
, Qerror
)))
1541 bool debugger_called
1542 = maybe_call_debugger (conditions
, error_symbol
, data
);
1543 /* We can't return values to code which signaled an error, but we
1544 can continue code which has signaled a quit. */
1545 if (debugger_called
&& EQ (real_error_symbol
, Qquit
))
1551 Lisp_Object unwind_data
1552 = (NILP (error_symbol
) ? data
: Fcons (error_symbol
, data
));
1554 unwind_to_catch (h
, unwind_data
);
1558 if (handlerlist
!= &handlerlist_sentinel
)
1559 /* FIXME: This will come right back here if there's no `top-level'
1560 catcher. A better solution would be to abort here, and instead
1561 add a catch-all condition handler so we never come here. */
1562 Fthrow (Qtop_level
, Qt
);
1565 if (! NILP (error_symbol
))
1566 data
= Fcons (error_symbol
, data
);
1568 string
= Ferror_message_string (data
);
1569 fatal ("%s", SDATA (string
));
1572 /* Internal version of Fsignal that never returns.
1573 Used for anything but Qquit (which can return from Fsignal). */
1576 xsignal (Lisp_Object error_symbol
, Lisp_Object data
)
1578 Fsignal (error_symbol
, data
);
1582 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1585 xsignal0 (Lisp_Object error_symbol
)
1587 xsignal (error_symbol
, Qnil
);
1591 xsignal1 (Lisp_Object error_symbol
, Lisp_Object arg
)
1593 xsignal (error_symbol
, list1 (arg
));
1597 xsignal2 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
)
1599 xsignal (error_symbol
, list2 (arg1
, arg2
));
1603 xsignal3 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
1605 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1608 /* Signal `error' with message S, and additional arg ARG.
1609 If ARG is not a genuine list, make it a one-element list. */
1612 signal_error (const char *s
, Lisp_Object arg
)
1614 Lisp_Object tortoise
, hare
;
1616 hare
= tortoise
= arg
;
1617 while (CONSP (hare
))
1624 tortoise
= XCDR (tortoise
);
1626 if (EQ (hare
, tortoise
))
1633 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1637 /* Return true if LIST is a non-nil atom or
1638 a list containing one of CONDITIONS. */
1641 wants_debugger (Lisp_Object list
, Lisp_Object conditions
)
1648 while (CONSP (conditions
))
1650 Lisp_Object
this, tail
;
1651 this = XCAR (conditions
);
1652 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1653 if (EQ (XCAR (tail
), this))
1655 conditions
= XCDR (conditions
);
1660 /* Return true if an error with condition-symbols CONDITIONS,
1661 and described by SIGNAL-DATA, should skip the debugger
1662 according to debugger-ignored-errors. */
1665 skip_debugger (Lisp_Object conditions
, Lisp_Object data
)
1668 bool first_string
= 1;
1669 Lisp_Object error_message
;
1671 error_message
= Qnil
;
1672 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1674 if (STRINGP (XCAR (tail
)))
1678 error_message
= Ferror_message_string (data
);
1682 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1687 Lisp_Object contail
;
1689 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1690 if (EQ (XCAR (tail
), XCAR (contail
)))
1698 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1699 SIG and DATA describe the signal. There are two ways to pass them:
1700 = SIG is the error symbol, and DATA is the rest of the data.
1701 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1702 This is for memory-full errors only. */
1704 maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
, Lisp_Object data
)
1706 Lisp_Object combined_data
;
1708 combined_data
= Fcons (sig
, data
);
1711 /* Don't try to run the debugger with interrupts blocked.
1712 The editing loop would return anyway. */
1713 ! input_blocked_p ()
1714 && NILP (Vinhibit_debugger
)
1715 /* Does user want to enter debugger for this kind of error? */
1718 : wants_debugger (Vdebug_on_error
, conditions
))
1719 && ! skip_debugger (conditions
, combined_data
)
1720 /* RMS: What's this for? */
1721 && when_entered_debugger
< num_nonmacro_input_events
)
1723 call_debugger (list2 (Qerror
, combined_data
));
1731 find_handler_clause (Lisp_Object handlers
, Lisp_Object conditions
)
1733 register Lisp_Object h
;
1735 /* t is used by handlers for all conditions, set up by C code. */
1736 if (EQ (handlers
, Qt
))
1739 /* error is used similarly, but means print an error message
1740 and run the debugger if that is enabled. */
1741 if (EQ (handlers
, Qerror
))
1744 for (h
= handlers
; CONSP (h
); h
= XCDR (h
))
1746 Lisp_Object handler
= XCAR (h
);
1747 if (!NILP (Fmemq (handler
, conditions
)))
1755 /* Format and return a string; called like vprintf. */
1757 vformat_string (const char *m
, va_list ap
)
1760 ptrdiff_t size
= sizeof buf
;
1761 ptrdiff_t size_max
= STRING_BYTES_BOUND
+ 1;
1766 used
= evxprintf (&buffer
, &size
, buf
, size_max
, m
, ap
);
1767 string
= make_string (buffer
, used
);
1774 /* Dump an error message; called like vprintf. */
1776 verror (const char *m
, va_list ap
)
1778 xsignal1 (Qerror
, vformat_string (m
, ap
));
1782 /* Dump an error message; called like printf. */
1786 error (const char *m
, ...)
1793 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1794 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1795 This means it contains a description for how to read arguments to give it.
1796 The value is nil for an invalid function or a symbol with no function
1799 Interactively callable functions include strings and vectors (treated
1800 as keyboard macros), lambda-expressions that contain a top-level call
1801 to `interactive', autoload definitions made by `autoload' with non-nil
1802 fourth argument, and some of the built-in functions of Lisp.
1804 Also, a symbol satisfies `commandp' if its function definition does so.
1806 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1807 then strings and vectors are not accepted. */)
1808 (Lisp_Object function
, Lisp_Object for_call_interactively
)
1810 register Lisp_Object fun
;
1811 register Lisp_Object funcar
;
1812 Lisp_Object if_prop
= Qnil
;
1816 fun
= indirect_function (fun
); /* Check cycles. */
1820 /* Check an `interactive-form' property if present, analogous to the
1821 function-documentation property. */
1823 while (SYMBOLP (fun
))
1825 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
1828 fun
= Fsymbol_function (fun
);
1831 /* Emacs primitives are interactive if their DEFUN specifies an
1832 interactive spec. */
1834 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
1836 /* Bytecode objects are interactive if they are long enough to
1837 have an element whose index is COMPILED_INTERACTIVE, which is
1838 where the interactive spec is stored. */
1839 else if (COMPILEDP (fun
))
1840 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1843 /* Strings and vectors are keyboard macros. */
1844 if (STRINGP (fun
) || VECTORP (fun
))
1845 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
1847 /* Lists may represent commands. */
1850 funcar
= XCAR (fun
);
1851 if (EQ (funcar
, Qclosure
))
1852 return (!NILP (Fassq (Qinteractive
, Fcdr (Fcdr (XCDR (fun
)))))
1854 else if (EQ (funcar
, Qlambda
))
1855 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
1856 else if (EQ (funcar
, Qautoload
))
1857 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
1862 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1863 doc
: /* Define FUNCTION to autoload from FILE.
1864 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1865 Third arg DOCSTRING is documentation for the function.
1866 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1867 Fifth arg TYPE indicates the type of the object:
1868 nil or omitted says FUNCTION is a function,
1869 `keymap' says FUNCTION is really a keymap, and
1870 `macro' or t says FUNCTION is really a macro.
1871 Third through fifth args give info about the real definition.
1872 They default to nil.
1873 If FUNCTION is already defined other than as an autoload,
1874 this does nothing and returns nil. */)
1875 (Lisp_Object function
, Lisp_Object file
, Lisp_Object docstring
, Lisp_Object interactive
, Lisp_Object type
)
1877 CHECK_SYMBOL (function
);
1878 CHECK_STRING (file
);
1880 /* If function is defined and not as an autoload, don't override. */
1881 if (!NILP (XSYMBOL (function
)->function
)
1882 && !AUTOLOADP (XSYMBOL (function
)->function
))
1885 if (!NILP (Vpurify_flag
) && EQ (docstring
, make_number (0)))
1886 /* `read1' in lread.c has found the docstring starting with "\
1887 and assumed the docstring will be provided by Snarf-documentation, so it
1888 passed us 0 instead. But that leads to accidental sharing in purecopy's
1889 hash-consing, so we use a (hopefully) unique integer instead. */
1890 docstring
= make_number (XHASH (function
));
1891 return Fdefalias (function
,
1892 list5 (Qautoload
, file
, docstring
, interactive
, type
),
1897 un_autoload (Lisp_Object oldqueue
)
1899 Lisp_Object queue
, first
, second
;
1901 /* Queue to unwind is current value of Vautoload_queue.
1902 oldqueue is the shadowed value to leave in Vautoload_queue. */
1903 queue
= Vautoload_queue
;
1904 Vautoload_queue
= oldqueue
;
1905 while (CONSP (queue
))
1907 first
= XCAR (queue
);
1908 second
= Fcdr (first
);
1909 first
= Fcar (first
);
1910 if (EQ (first
, make_number (0)))
1913 Ffset (first
, second
);
1914 queue
= XCDR (queue
);
1918 /* Load an autoloaded function.
1919 FUNNAME is the symbol which is the function's name.
1920 FUNDEF is the autoload definition (a list). */
1922 DEFUN ("autoload-do-load", Fautoload_do_load
, Sautoload_do_load
, 1, 3, 0,
1923 doc
: /* Load FUNDEF which should be an autoload.
1924 If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1925 in which case the function returns the new autoloaded function value.
1926 If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1927 it defines a macro. */)
1928 (Lisp_Object fundef
, Lisp_Object funname
, Lisp_Object macro_only
)
1930 ptrdiff_t count
= SPECPDL_INDEX ();
1932 if (!CONSP (fundef
) || !EQ (Qautoload
, XCAR (fundef
)))
1935 if (EQ (macro_only
, Qmacro
))
1937 Lisp_Object kind
= Fnth (make_number (4), fundef
);
1938 if (! (EQ (kind
, Qt
) || EQ (kind
, Qmacro
)))
1942 /* This is to make sure that loadup.el gives a clear picture
1943 of what files are preloaded and when. */
1944 if (! NILP (Vpurify_flag
))
1945 error ("Attempt to autoload %s while preparing to dump",
1946 SDATA (SYMBOL_NAME (funname
)));
1948 CHECK_SYMBOL (funname
);
1950 /* Preserve the match data. */
1951 record_unwind_save_match_data ();
1953 /* If autoloading gets an error (which includes the error of failing
1954 to define the function being called), we use Vautoload_queue
1955 to undo function definitions and `provide' calls made by
1956 the function. We do this in the specific case of autoloading
1957 because autoloading is not an explicit request "load this file",
1958 but rather a request to "call this function".
1960 The value saved here is to be restored into Vautoload_queue. */
1961 record_unwind_protect (un_autoload
, Vautoload_queue
);
1962 Vautoload_queue
= Qt
;
1963 /* If `macro_only', assume this autoload to be a "best-effort",
1964 so don't signal an error if autoloading fails. */
1965 Fload (Fcar (Fcdr (fundef
)), macro_only
, Qt
, Qnil
, Qt
);
1967 /* Once loading finishes, don't undo it. */
1968 Vautoload_queue
= Qt
;
1969 unbind_to (count
, Qnil
);
1975 Lisp_Object fun
= Findirect_function (funname
, Qnil
);
1977 if (!NILP (Fequal (fun
, fundef
)))
1978 error ("Autoloading failed to define function %s",
1979 SDATA (SYMBOL_NAME (funname
)));
1986 DEFUN ("eval", Feval
, Seval
, 1, 2, 0,
1987 doc
: /* Evaluate FORM and return its value.
1988 If LEXICAL is t, evaluate using lexical scoping.
1989 LEXICAL can also be an actual lexical environment, in the form of an
1990 alist mapping symbols to their value. */)
1991 (Lisp_Object form
, Lisp_Object lexical
)
1993 ptrdiff_t count
= SPECPDL_INDEX ();
1994 specbind (Qinternal_interpreter_environment
,
1995 CONSP (lexical
) || NILP (lexical
) ? lexical
: list1 (Qt
));
1996 return unbind_to (count
, eval_sub (form
));
1999 /* Grow the specpdl stack by one entry.
2000 The caller should have already initialized the entry.
2001 Signal an error on stack overflow.
2003 Make sure that there is always one unused entry past the top of the
2004 stack, so that the just-initialized entry is safely unwound if
2005 memory exhausted and an error is signaled here. Also, allocate a
2006 never-used entry just before the bottom of the stack; sometimes its
2007 address is taken. */
2014 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2016 ptrdiff_t count
= SPECPDL_INDEX ();
2017 ptrdiff_t max_size
= min (max_specpdl_size
, PTRDIFF_MAX
- 1000);
2018 union specbinding
*pdlvec
= specpdl
- 1;
2019 ptrdiff_t pdlvecsize
= specpdl_size
+ 1;
2020 if (max_size
<= specpdl_size
)
2022 if (max_specpdl_size
< 400)
2023 max_size
= max_specpdl_size
= 400;
2024 if (max_size
<= specpdl_size
)
2025 signal_error ("Variable binding depth exceeds max-specpdl-size",
2028 pdlvec
= xpalloc (pdlvec
, &pdlvecsize
, 1, max_size
+ 1, sizeof *specpdl
);
2029 specpdl
= pdlvec
+ 1;
2030 specpdl_size
= pdlvecsize
- 1;
2031 specpdl_ptr
= specpdl
+ count
;
2036 record_in_backtrace (Lisp_Object function
, Lisp_Object
*args
, ptrdiff_t nargs
)
2038 ptrdiff_t count
= SPECPDL_INDEX ();
2040 eassert (nargs
>= UNEVALLED
);
2041 specpdl_ptr
->bt
.kind
= SPECPDL_BACKTRACE
;
2042 specpdl_ptr
->bt
.debug_on_exit
= false;
2043 specpdl_ptr
->bt
.function
= function
;
2044 specpdl_ptr
->bt
.args
= args
;
2045 specpdl_ptr
->bt
.nargs
= nargs
;
2051 /* Eval a sub-expression of the current expression (i.e. in the same
2054 eval_sub (Lisp_Object form
)
2056 Lisp_Object fun
, val
, original_fun
, original_args
;
2060 /* Declare here, as this array may be accessed by call_debugger near
2061 the end of this function. See Bug#21245. */
2062 Lisp_Object argvals
[8];
2066 /* Look up its binding in the lexical environment.
2067 We do not pay attention to the declared_special flag here, since we
2068 already did that when let-binding the variable. */
2069 Lisp_Object lex_binding
2070 = !NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
2071 ? Fassq (form
, Vinternal_interpreter_environment
)
2073 if (CONSP (lex_binding
))
2074 return XCDR (lex_binding
);
2076 return Fsymbol_value (form
);
2086 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2088 if (max_lisp_eval_depth
< 100)
2089 max_lisp_eval_depth
= 100;
2090 if (lisp_eval_depth
> max_lisp_eval_depth
)
2091 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2094 original_fun
= XCAR (form
);
2095 original_args
= XCDR (form
);
2097 /* This also protects them from gc. */
2098 count
= record_in_backtrace (original_fun
, &original_args
, UNEVALLED
);
2100 if (debug_on_next_call
)
2101 do_debug_on_call (Qt
, count
);
2103 /* At this point, only original_fun and original_args
2104 have values that will be used below. */
2107 /* Optimize for no indirection. */
2110 fun
= Ffunction (Fcons (fun
, Qnil
));
2111 else if (!NILP (fun
) && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2112 fun
= indirect_function (fun
);
2116 Lisp_Object args_left
= original_args
;
2117 Lisp_Object numargs
= Flength (args_left
);
2121 if (XINT (numargs
) < XSUBR (fun
)->min_args
2122 || (XSUBR (fun
)->max_args
>= 0
2123 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2124 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2126 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2127 val
= (XSUBR (fun
)->function
.aUNEVALLED
) (args_left
);
2128 else if (XSUBR (fun
)->max_args
== MANY
)
2130 /* Pass a vector of evaluated arguments. */
2132 ptrdiff_t argnum
= 0;
2135 SAFE_ALLOCA_LISP (vals
, XINT (numargs
));
2137 while (!NILP (args_left
))
2139 vals
[argnum
++] = eval_sub (Fcar (args_left
));
2140 args_left
= Fcdr (args_left
);
2143 set_backtrace_args (specpdl
+ count
, vals
, XINT (numargs
));
2145 val
= (XSUBR (fun
)->function
.aMANY
) (XINT (numargs
), vals
);
2149 /* Do the debug-on-exit now, while VALS still exists. */
2150 if (backtrace_debug_on_exit (specpdl
+ count
))
2151 val
= call_debugger (list2 (Qexit
, val
));
2158 int i
, maxargs
= XSUBR (fun
)->max_args
;
2160 for (i
= 0; i
< maxargs
; i
++)
2162 argvals
[i
] = eval_sub (Fcar (args_left
));
2163 args_left
= Fcdr (args_left
);
2166 set_backtrace_args (specpdl
+ count
, argvals
, XINT (numargs
));
2171 val
= (XSUBR (fun
)->function
.a0 ());
2174 val
= (XSUBR (fun
)->function
.a1 (argvals
[0]));
2177 val
= (XSUBR (fun
)->function
.a2 (argvals
[0], argvals
[1]));
2180 val
= (XSUBR (fun
)->function
.a3
2181 (argvals
[0], argvals
[1], argvals
[2]));
2184 val
= (XSUBR (fun
)->function
.a4
2185 (argvals
[0], argvals
[1], argvals
[2], argvals
[3]));
2188 val
= (XSUBR (fun
)->function
.a5
2189 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2193 val
= (XSUBR (fun
)->function
.a6
2194 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2195 argvals
[4], argvals
[5]));
2198 val
= (XSUBR (fun
)->function
.a7
2199 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2200 argvals
[4], argvals
[5], argvals
[6]));
2204 val
= (XSUBR (fun
)->function
.a8
2205 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2206 argvals
[4], argvals
[5], argvals
[6], argvals
[7]));
2210 /* Someone has created a subr that takes more arguments than
2211 is supported by this code. We need to either rewrite the
2212 subr to use a different argument protocol, or add more
2213 cases to this switch. */
2218 else if (COMPILEDP (fun
))
2219 return apply_lambda (fun
, original_args
, count
);
2223 xsignal1 (Qvoid_function
, original_fun
);
2225 xsignal1 (Qinvalid_function
, original_fun
);
2226 funcar
= XCAR (fun
);
2227 if (!SYMBOLP (funcar
))
2228 xsignal1 (Qinvalid_function
, original_fun
);
2229 if (EQ (funcar
, Qautoload
))
2231 Fautoload_do_load (fun
, original_fun
, Qnil
);
2234 if (EQ (funcar
, Qmacro
))
2236 ptrdiff_t count1
= SPECPDL_INDEX ();
2238 /* Bind lexical-binding during expansion of the macro, so the
2239 macro can know reliably if the code it outputs will be
2240 interpreted using lexical-binding or not. */
2241 specbind (Qlexical_binding
,
2242 NILP (Vinternal_interpreter_environment
) ? Qnil
: Qt
);
2243 exp
= apply1 (Fcdr (fun
), original_args
);
2244 unbind_to (count1
, Qnil
);
2245 val
= eval_sub (exp
);
2247 else if (EQ (funcar
, Qlambda
)
2248 || EQ (funcar
, Qclosure
))
2249 return apply_lambda (fun
, original_args
, count
);
2251 xsignal1 (Qinvalid_function
, original_fun
);
2256 if (backtrace_debug_on_exit (specpdl
+ count
))
2257 val
= call_debugger (list2 (Qexit
, val
));
2263 DEFUN ("apply", Fapply
, Sapply
, 1, MANY
, 0,
2264 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2265 Then return the value FUNCTION returns.
2266 Thus, (apply \\='+ 1 2 \\='(3 4)) returns 10.
2267 usage: (apply FUNCTION &rest ARGUMENTS) */)
2268 (ptrdiff_t nargs
, Lisp_Object
*args
)
2270 ptrdiff_t i
, numargs
, funcall_nargs
;
2271 register Lisp_Object
*funcall_args
= NULL
;
2272 register Lisp_Object spread_arg
= args
[nargs
- 1];
2273 Lisp_Object fun
= args
[0];
2277 CHECK_LIST (spread_arg
);
2279 numargs
= XINT (Flength (spread_arg
));
2282 return Ffuncall (nargs
- 1, args
);
2283 else if (numargs
== 1)
2285 args
[nargs
- 1] = XCAR (spread_arg
);
2286 return Ffuncall (nargs
, args
);
2289 numargs
+= nargs
- 2;
2291 /* Optimize for no indirection. */
2292 if (SYMBOLP (fun
) && !NILP (fun
)
2293 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2295 fun
= indirect_function (fun
);
2297 /* Let funcall get the error. */
2301 if (SUBRP (fun
) && XSUBR (fun
)->max_args
> numargs
2302 /* Don't hide an error by adding missing arguments. */
2303 && numargs
>= XSUBR (fun
)->min_args
)
2305 /* Avoid making funcall cons up a yet another new vector of arguments
2306 by explicitly supplying nil's for optional values. */
2307 SAFE_ALLOCA_LISP (funcall_args
, 1 + XSUBR (fun
)->max_args
);
2308 memclear (funcall_args
+ numargs
+ 1,
2309 (XSUBR (fun
)->max_args
- numargs
) * word_size
);
2310 funcall_nargs
= 1 + XSUBR (fun
)->max_args
;
2313 { /* We add 1 to numargs because funcall_args includes the
2314 function itself as well as its arguments. */
2315 SAFE_ALLOCA_LISP (funcall_args
, 1 + numargs
);
2316 funcall_nargs
= 1 + numargs
;
2319 memcpy (funcall_args
, args
, nargs
* word_size
);
2320 /* Spread the last arg we got. Its first element goes in
2321 the slot that it used to occupy, hence this value of I. */
2323 while (!NILP (spread_arg
))
2325 funcall_args
[i
++] = XCAR (spread_arg
);
2326 spread_arg
= XCDR (spread_arg
);
2329 retval
= Ffuncall (funcall_nargs
, funcall_args
);
2335 /* Run hook variables in various ways. */
2338 funcall_nil (ptrdiff_t nargs
, Lisp_Object
*args
)
2340 Ffuncall (nargs
, args
);
2344 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2345 doc
: /* Run each hook in HOOKS.
2346 Each argument should be a symbol, a hook variable.
2347 These symbols are processed in the order specified.
2348 If a hook symbol has a non-nil value, that value may be a function
2349 or a list of functions to be called to run the hook.
2350 If the value is a function, it is called with no arguments.
2351 If it is a list, the elements are called, in order, with no arguments.
2353 Major modes should not use this function directly to run their mode
2354 hook; they should use `run-mode-hooks' instead.
2356 Do not use `make-local-variable' to make a hook variable buffer-local.
2357 Instead, use `add-hook' and specify t for the LOCAL argument.
2358 usage: (run-hooks &rest HOOKS) */)
2359 (ptrdiff_t nargs
, Lisp_Object
*args
)
2363 for (i
= 0; i
< nargs
; i
++)
2369 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2370 Srun_hook_with_args
, 1, MANY
, 0,
2371 doc
: /* Run HOOK with the specified arguments ARGS.
2372 HOOK should be a symbol, a hook variable. The value of HOOK
2373 may be nil, a function, or a list of functions. Call each
2374 function in order with arguments ARGS. The final return value
2377 Do not use `make-local-variable' to make a hook variable buffer-local.
2378 Instead, use `add-hook' and specify t for the LOCAL argument.
2379 usage: (run-hook-with-args HOOK &rest ARGS) */)
2380 (ptrdiff_t nargs
, Lisp_Object
*args
)
2382 return run_hook_with_args (nargs
, args
, funcall_nil
);
2385 /* NB this one still documents a specific non-nil return value.
2386 (As did run-hook-with-args and run-hook-with-args-until-failure
2387 until they were changed in 24.1.) */
2388 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2389 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2390 doc
: /* Run HOOK with the specified arguments ARGS.
2391 HOOK should be a symbol, a hook variable. The value of HOOK
2392 may be nil, a function, or a list of functions. Call each
2393 function in order with arguments ARGS, stopping at the first
2394 one that returns non-nil, and return that value. Otherwise (if
2395 all functions return nil, or if there are no functions to call),
2398 Do not use `make-local-variable' to make a hook variable buffer-local.
2399 Instead, use `add-hook' and specify t for the LOCAL argument.
2400 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2401 (ptrdiff_t nargs
, Lisp_Object
*args
)
2403 return run_hook_with_args (nargs
, args
, Ffuncall
);
2407 funcall_not (ptrdiff_t nargs
, Lisp_Object
*args
)
2409 return NILP (Ffuncall (nargs
, args
)) ? Qt
: Qnil
;
2412 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2413 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2414 doc
: /* Run HOOK with the specified arguments ARGS.
2415 HOOK should be a symbol, a hook variable. The value of HOOK
2416 may be nil, a function, or a list of functions. Call each
2417 function in order with arguments ARGS, stopping at the first
2418 one that returns nil, and return nil. Otherwise (if all functions
2419 return non-nil, or if there are no functions to call), return non-nil
2420 \(do not rely on the precise return value in this case).
2422 Do not use `make-local-variable' to make a hook variable buffer-local.
2423 Instead, use `add-hook' and specify t for the LOCAL argument.
2424 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2425 (ptrdiff_t nargs
, Lisp_Object
*args
)
2427 return NILP (run_hook_with_args (nargs
, args
, funcall_not
)) ? Qt
: Qnil
;
2431 run_hook_wrapped_funcall (ptrdiff_t nargs
, Lisp_Object
*args
)
2433 Lisp_Object tmp
= args
[0], ret
;
2436 ret
= Ffuncall (nargs
, args
);
2442 DEFUN ("run-hook-wrapped", Frun_hook_wrapped
, Srun_hook_wrapped
, 2, MANY
, 0,
2443 doc
: /* Run HOOK, passing each function through WRAP-FUNCTION.
2444 I.e. instead of calling each function FUN directly with arguments ARGS,
2445 it calls WRAP-FUNCTION with arguments FUN and ARGS.
2446 As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2447 aborts and returns that value.
2448 usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2449 (ptrdiff_t nargs
, Lisp_Object
*args
)
2451 return run_hook_with_args (nargs
, args
, run_hook_wrapped_funcall
);
2454 /* ARGS[0] should be a hook symbol.
2455 Call each of the functions in the hook value, passing each of them
2456 as arguments all the rest of ARGS (all NARGS - 1 elements).
2457 FUNCALL specifies how to call each function on the hook. */
2460 run_hook_with_args (ptrdiff_t nargs
, Lisp_Object
*args
,
2461 Lisp_Object (*funcall
) (ptrdiff_t nargs
, Lisp_Object
*args
))
2463 Lisp_Object sym
, val
, ret
= Qnil
;
2465 /* If we are dying or still initializing,
2466 don't do anything--it would probably crash if we tried. */
2467 if (NILP (Vrun_hooks
))
2471 val
= find_symbol_value (sym
);
2473 if (EQ (val
, Qunbound
) || NILP (val
))
2475 else if (!CONSP (val
) || FUNCTIONP (val
))
2478 return funcall (nargs
, args
);
2482 Lisp_Object global_vals
= Qnil
;
2485 CONSP (val
) && NILP (ret
);
2488 if (EQ (XCAR (val
), Qt
))
2490 /* t indicates this hook has a local binding;
2491 it means to run the global binding too. */
2492 global_vals
= Fdefault_value (sym
);
2493 if (NILP (global_vals
)) continue;
2495 if (!CONSP (global_vals
) || EQ (XCAR (global_vals
), Qlambda
))
2497 args
[0] = global_vals
;
2498 ret
= funcall (nargs
, args
);
2503 CONSP (global_vals
) && NILP (ret
);
2504 global_vals
= XCDR (global_vals
))
2506 args
[0] = XCAR (global_vals
);
2507 /* In a global value, t should not occur. If it does, we
2508 must ignore it to avoid an endless loop. */
2509 if (!EQ (args
[0], Qt
))
2510 ret
= funcall (nargs
, args
);
2516 args
[0] = XCAR (val
);
2517 ret
= funcall (nargs
, args
);
2525 /* Run the hook HOOK, giving each function no args. */
2528 run_hook (Lisp_Object hook
)
2530 Frun_hook_with_args (1, &hook
);
2533 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2536 run_hook_with_args_2 (Lisp_Object hook
, Lisp_Object arg1
, Lisp_Object arg2
)
2538 CALLN (Frun_hook_with_args
, hook
, arg1
, arg2
);
2541 /* Apply fn to arg. */
2543 apply1 (Lisp_Object fn
, Lisp_Object arg
)
2545 return NILP (arg
) ? Ffuncall (1, &fn
) : CALLN (Fapply
, fn
, arg
);
2548 /* Call function fn on no arguments. */
2550 call0 (Lisp_Object fn
)
2552 return Ffuncall (1, &fn
);
2555 /* Call function fn with 1 argument arg1. */
2558 call1 (Lisp_Object fn
, Lisp_Object arg1
)
2560 return CALLN (Ffuncall
, fn
, arg1
);
2563 /* Call function fn with 2 arguments arg1, arg2. */
2566 call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2568 return CALLN (Ffuncall
, fn
, arg1
, arg2
);
2571 /* Call function fn with 3 arguments arg1, arg2, arg3. */
2574 call3 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
2576 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
);
2579 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
2582 call4 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2585 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
);
2588 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
2591 call5 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2592 Lisp_Object arg4
, Lisp_Object arg5
)
2594 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
);
2597 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
2600 call6 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2601 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
)
2603 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
2606 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
2609 call7 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2610 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
, Lisp_Object arg7
)
2612 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
);
2615 DEFUN ("functionp", Ffunctionp
, Sfunctionp
, 1, 1, 0,
2616 doc
: /* Non-nil if OBJECT is a function. */)
2617 (Lisp_Object object
)
2619 if (FUNCTIONP (object
))
2624 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2625 doc
: /* Call first argument as a function, passing remaining arguments to it.
2626 Return the value that function returns.
2627 Thus, (funcall \\='cons \\='x \\='y) returns (x . y).
2628 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2629 (ptrdiff_t nargs
, Lisp_Object
*args
)
2631 Lisp_Object fun
, original_fun
;
2633 ptrdiff_t numargs
= nargs
- 1;
2634 Lisp_Object lisp_numargs
;
2636 Lisp_Object
*internal_args
;
2641 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2643 if (max_lisp_eval_depth
< 100)
2644 max_lisp_eval_depth
= 100;
2645 if (lisp_eval_depth
> max_lisp_eval_depth
)
2646 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2649 count
= record_in_backtrace (args
[0], &args
[1], nargs
- 1);
2653 if (debug_on_next_call
)
2654 do_debug_on_call (Qlambda
, count
);
2658 original_fun
= args
[0];
2662 /* Optimize for no indirection. */
2664 if (SYMBOLP (fun
) && !NILP (fun
)
2665 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2666 fun
= indirect_function (fun
);
2670 if (numargs
< XSUBR (fun
)->min_args
2671 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2673 XSETFASTINT (lisp_numargs
, numargs
);
2674 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
2677 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2678 xsignal1 (Qinvalid_function
, original_fun
);
2680 else if (XSUBR (fun
)->max_args
== MANY
)
2681 val
= (XSUBR (fun
)->function
.aMANY
) (numargs
, args
+ 1);
2684 Lisp_Object internal_argbuf
[8];
2685 if (XSUBR (fun
)->max_args
> numargs
)
2687 eassert (XSUBR (fun
)->max_args
<= ARRAYELTS (internal_argbuf
));
2688 internal_args
= internal_argbuf
;
2689 memcpy (internal_args
, args
+ 1, numargs
* word_size
);
2690 memclear (internal_args
+ numargs
,
2691 (XSUBR (fun
)->max_args
- numargs
) * word_size
);
2694 internal_args
= args
+ 1;
2695 switch (XSUBR (fun
)->max_args
)
2698 val
= (XSUBR (fun
)->function
.a0 ());
2701 val
= (XSUBR (fun
)->function
.a1 (internal_args
[0]));
2704 val
= (XSUBR (fun
)->function
.a2
2705 (internal_args
[0], internal_args
[1]));
2708 val
= (XSUBR (fun
)->function
.a3
2709 (internal_args
[0], internal_args
[1], internal_args
[2]));
2712 val
= (XSUBR (fun
)->function
.a4
2713 (internal_args
[0], internal_args
[1], internal_args
[2],
2717 val
= (XSUBR (fun
)->function
.a5
2718 (internal_args
[0], internal_args
[1], internal_args
[2],
2719 internal_args
[3], internal_args
[4]));
2722 val
= (XSUBR (fun
)->function
.a6
2723 (internal_args
[0], internal_args
[1], internal_args
[2],
2724 internal_args
[3], internal_args
[4], internal_args
[5]));
2727 val
= (XSUBR (fun
)->function
.a7
2728 (internal_args
[0], internal_args
[1], internal_args
[2],
2729 internal_args
[3], internal_args
[4], internal_args
[5],
2734 val
= (XSUBR (fun
)->function
.a8
2735 (internal_args
[0], internal_args
[1], internal_args
[2],
2736 internal_args
[3], internal_args
[4], internal_args
[5],
2737 internal_args
[6], internal_args
[7]));
2742 /* If a subr takes more than 8 arguments without using MANY
2743 or UNEVALLED, we need to extend this function to support it.
2744 Until this is done, there is no way to call the function. */
2749 else if (COMPILEDP (fun
))
2750 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2754 xsignal1 (Qvoid_function
, original_fun
);
2756 xsignal1 (Qinvalid_function
, original_fun
);
2757 funcar
= XCAR (fun
);
2758 if (!SYMBOLP (funcar
))
2759 xsignal1 (Qinvalid_function
, original_fun
);
2760 if (EQ (funcar
, Qlambda
)
2761 || EQ (funcar
, Qclosure
))
2762 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2763 else if (EQ (funcar
, Qautoload
))
2765 Fautoload_do_load (fun
, original_fun
, Qnil
);
2770 xsignal1 (Qinvalid_function
, original_fun
);
2774 if (backtrace_debug_on_exit (specpdl
+ count
))
2775 val
= call_debugger (list2 (Qexit
, val
));
2781 apply_lambda (Lisp_Object fun
, Lisp_Object args
, ptrdiff_t count
)
2783 Lisp_Object args_left
;
2786 Lisp_Object
*arg_vector
;
2790 numargs
= XFASTINT (Flength (args
));
2791 SAFE_ALLOCA_LISP (arg_vector
, numargs
);
2794 for (i
= 0; i
< numargs
; )
2796 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2797 tem
= eval_sub (tem
);
2798 arg_vector
[i
++] = tem
;
2801 set_backtrace_args (specpdl
+ count
, arg_vector
, i
);
2802 tem
= funcall_lambda (fun
, numargs
, arg_vector
);
2806 /* Do the debug-on-exit now, while arg_vector still exists. */
2807 if (backtrace_debug_on_exit (specpdl
+ count
))
2808 tem
= call_debugger (list2 (Qexit
, tem
));
2814 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2815 and return the result of evaluation.
2816 FUN must be either a lambda-expression or a compiled-code object. */
2819 funcall_lambda (Lisp_Object fun
, ptrdiff_t nargs
,
2820 register Lisp_Object
*arg_vector
)
2822 Lisp_Object val
, syms_left
, next
, lexenv
;
2823 ptrdiff_t count
= SPECPDL_INDEX ();
2825 bool optional
, rest
;
2829 if (EQ (XCAR (fun
), Qclosure
))
2831 fun
= XCDR (fun
); /* Drop `closure'. */
2832 lexenv
= XCAR (fun
);
2833 CHECK_LIST_CONS (fun
, fun
);
2837 syms_left
= XCDR (fun
);
2838 if (CONSP (syms_left
))
2839 syms_left
= XCAR (syms_left
);
2841 xsignal1 (Qinvalid_function
, fun
);
2843 else if (COMPILEDP (fun
))
2845 ptrdiff_t size
= ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
;
2846 if (size
<= COMPILED_STACK_DEPTH
)
2847 xsignal1 (Qinvalid_function
, fun
);
2848 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2849 if (INTEGERP (syms_left
))
2850 /* A byte-code object with a non-nil `push args' slot means we
2851 shouldn't bind any arguments, instead just call the byte-code
2852 interpreter directly; it will push arguments as necessary.
2854 Byte-code objects with either a non-existent, or a nil value for
2855 the `push args' slot (the default), have dynamically-bound
2856 arguments, and use the argument-binding code below instead (as do
2857 all interpreted functions, even lexically bound ones). */
2859 /* If we have not actually read the bytecode string
2860 and constants vector yet, fetch them from the file. */
2861 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2862 Ffetch_bytecode (fun
);
2863 return exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2864 AREF (fun
, COMPILED_CONSTANTS
),
2865 AREF (fun
, COMPILED_STACK_DEPTH
),
2874 i
= optional
= rest
= 0;
2875 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2879 next
= XCAR (syms_left
);
2880 if (!SYMBOLP (next
))
2881 xsignal1 (Qinvalid_function
, fun
);
2883 if (EQ (next
, Qand_rest
))
2885 else if (EQ (next
, Qand_optional
))
2892 arg
= Flist (nargs
- i
, &arg_vector
[i
]);
2896 arg
= arg_vector
[i
++];
2898 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2902 /* Bind the argument. */
2903 if (!NILP (lexenv
) && SYMBOLP (next
))
2904 /* Lexically bind NEXT by adding it to the lexenv alist. */
2905 lexenv
= Fcons (Fcons (next
, arg
), lexenv
);
2907 /* Dynamically bind NEXT. */
2908 specbind (next
, arg
);
2912 if (!NILP (syms_left
))
2913 xsignal1 (Qinvalid_function
, fun
);
2915 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2917 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
2918 /* Instantiate a new lexical environment. */
2919 specbind (Qinternal_interpreter_environment
, lexenv
);
2922 val
= Fprogn (XCDR (XCDR (fun
)));
2925 /* If we have not actually read the bytecode string
2926 and constants vector yet, fetch them from the file. */
2927 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2928 Ffetch_bytecode (fun
);
2929 val
= exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2930 AREF (fun
, COMPILED_CONSTANTS
),
2931 AREF (fun
, COMPILED_STACK_DEPTH
),
2935 return unbind_to (count
, val
);
2938 DEFUN ("func-arity", Ffunc_arity
, Sfunc_arity
, 1, 1, 0,
2939 doc
: /* Return minimum and maximum number of args allowed for FUNCTION.
2940 FUNCTION must be a function of some kind.
2941 The returned value is a cons cell (MIN . MAX). MIN is the minimum number
2942 of args. MAX is the maximum number, or the symbol `many', for a
2943 function with `&rest' args, or `unevalled' for a special form. */)
2944 (Lisp_Object function
)
2946 Lisp_Object original
;
2949 short minargs
, maxargs
;
2951 original
= function
;
2955 /* Optimize for no indirection. */
2956 function
= original
;
2957 if (SYMBOLP (function
) && !NILP (function
)
2958 && (function
= XSYMBOL (function
)->function
, SYMBOLP (function
)))
2959 function
= indirect_function (function
);
2961 if (SUBRP (function
))
2962 result
= Fsubr_arity (function
);
2963 else if (COMPILEDP (function
))
2964 result
= lambda_arity (function
);
2967 if (NILP (function
))
2968 xsignal1 (Qvoid_function
, original
);
2969 if (!CONSP (function
))
2970 xsignal1 (Qinvalid_function
, original
);
2971 funcar
= XCAR (function
);
2972 if (!SYMBOLP (funcar
))
2973 xsignal1 (Qinvalid_function
, original
);
2974 if (EQ (funcar
, Qlambda
)
2975 || EQ (funcar
, Qclosure
))
2976 result
= lambda_arity (function
);
2977 else if (EQ (funcar
, Qautoload
))
2979 Fautoload_do_load (function
, original
, Qnil
);
2983 xsignal1 (Qinvalid_function
, original
);
2988 /* FUN must be either a lambda-expression or a compiled-code object. */
2990 lambda_arity (Lisp_Object fun
)
2992 Lisp_Object val
, syms_left
, next
;
2993 ptrdiff_t minargs
, maxargs
;
2998 if (EQ (XCAR (fun
), Qclosure
))
3000 fun
= XCDR (fun
); /* Drop `closure'. */
3001 CHECK_LIST_CONS (fun
, fun
);
3003 syms_left
= XCDR (fun
);
3004 if (CONSP (syms_left
))
3005 syms_left
= XCAR (syms_left
);
3007 xsignal1 (Qinvalid_function
, fun
);
3009 else if (COMPILEDP (fun
))
3011 ptrdiff_t size
= ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
;
3012 if (size
<= COMPILED_STACK_DEPTH
)
3013 xsignal1 (Qinvalid_function
, fun
);
3014 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
3015 if (INTEGERP (syms_left
))
3016 return get_byte_code_arity (syms_left
);
3021 minargs
= maxargs
= optional
= 0;
3022 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
3024 next
= XCAR (syms_left
);
3025 if (!SYMBOLP (next
))
3026 xsignal1 (Qinvalid_function
, fun
);
3028 if (EQ (next
, Qand_rest
))
3029 return Fcons (make_number (minargs
), Qmany
);
3030 else if (EQ (next
, Qand_optional
))
3040 if (!NILP (syms_left
))
3041 xsignal1 (Qinvalid_function
, fun
);
3043 return Fcons (make_number (minargs
), make_number (maxargs
));
3047 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
3049 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3050 (Lisp_Object object
)
3054 if (COMPILEDP (object
))
3056 ptrdiff_t size
= ASIZE (object
) & PSEUDOVECTOR_SIZE_MASK
;
3057 if (size
<= COMPILED_STACK_DEPTH
)
3058 xsignal1 (Qinvalid_function
, object
);
3059 if (CONSP (AREF (object
, COMPILED_BYTECODE
)))
3061 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
3064 tem
= AREF (object
, COMPILED_BYTECODE
);
3065 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
3066 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
3068 error ("Invalid byte code");
3070 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
3071 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
3077 /* Return true if SYMBOL currently has a let-binding
3078 which was made in the buffer that is now current. */
3081 let_shadows_buffer_binding_p (struct Lisp_Symbol
*symbol
)
3083 union specbinding
*p
;
3084 Lisp_Object buf
= Fcurrent_buffer ();
3086 for (p
= specpdl_ptr
; p
> specpdl
; )
3087 if ((--p
)->kind
> SPECPDL_LET
)
3089 struct Lisp_Symbol
*let_bound_symbol
= XSYMBOL (specpdl_symbol (p
));
3090 eassert (let_bound_symbol
->redirect
!= SYMBOL_VARALIAS
);
3091 if (symbol
== let_bound_symbol
3092 && EQ (specpdl_where (p
), buf
))
3100 let_shadows_global_binding_p (Lisp_Object symbol
)
3102 union specbinding
*p
;
3104 for (p
= specpdl_ptr
; p
> specpdl
; )
3105 if ((--p
)->kind
>= SPECPDL_LET
&& EQ (specpdl_symbol (p
), symbol
))
3111 /* `specpdl_ptr' describes which variable is
3112 let-bound, so it can be properly undone when we unbind_to.
3113 It can be either a plain SPECPDL_LET or a SPECPDL_LET_LOCAL/DEFAULT.
3114 - SYMBOL is the variable being bound. Note that it should not be
3115 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3117 - WHERE tells us in which buffer the binding took place.
3118 This is used for SPECPDL_LET_LOCAL bindings (i.e. bindings to a
3119 buffer-local variable) as well as for SPECPDL_LET_DEFAULT bindings,
3120 i.e. bindings to the default value of a variable which can be
3124 specbind (Lisp_Object symbol
, Lisp_Object value
)
3126 struct Lisp_Symbol
*sym
;
3128 CHECK_SYMBOL (symbol
);
3129 sym
= XSYMBOL (symbol
);
3132 switch (sym
->redirect
)
3134 case SYMBOL_VARALIAS
:
3135 sym
= indirect_variable (sym
); XSETSYMBOL (symbol
, sym
); goto start
;
3136 case SYMBOL_PLAINVAL
:
3137 /* The most common case is that of a non-constant symbol with a
3138 trivial value. Make that as fast as we can. */
3139 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3140 specpdl_ptr
->let
.symbol
= symbol
;
3141 specpdl_ptr
->let
.old_value
= SYMBOL_VAL (sym
);
3144 SET_SYMBOL_VAL (sym
, value
);
3146 set_internal (symbol
, value
, Qnil
, 1);
3148 case SYMBOL_LOCALIZED
:
3149 if (SYMBOL_BLV (sym
)->frame_local
)
3150 error ("Frame-local vars cannot be let-bound");
3151 case SYMBOL_FORWARDED
:
3153 Lisp_Object ovalue
= find_symbol_value (symbol
);
3154 specpdl_ptr
->let
.kind
= SPECPDL_LET_LOCAL
;
3155 specpdl_ptr
->let
.symbol
= symbol
;
3156 specpdl_ptr
->let
.old_value
= ovalue
;
3157 specpdl_ptr
->let
.where
= Fcurrent_buffer ();
3159 eassert (sym
->redirect
!= SYMBOL_LOCALIZED
3160 || (EQ (SYMBOL_BLV (sym
)->where
, Fcurrent_buffer ())));
3162 if (sym
->redirect
== SYMBOL_LOCALIZED
)
3164 if (!blv_found (SYMBOL_BLV (sym
)))
3165 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3167 else if (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)))
3169 /* If SYMBOL is a per-buffer variable which doesn't have a
3170 buffer-local value here, make the `let' change the global
3171 value by changing the value of SYMBOL in all buffers not
3172 having their own value. This is consistent with what
3173 happens with other buffer-local variables. */
3174 if (NILP (Flocal_variable_p (symbol
, Qnil
)))
3176 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3178 Fset_default (symbol
, value
);
3183 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3186 set_internal (symbol
, value
, Qnil
, 1);
3189 default: emacs_abort ();
3193 /* Push unwind-protect entries of various types. */
3196 record_unwind_protect (void (*function
) (Lisp_Object
), Lisp_Object arg
)
3198 specpdl_ptr
->unwind
.kind
= SPECPDL_UNWIND
;
3199 specpdl_ptr
->unwind
.func
= function
;
3200 specpdl_ptr
->unwind
.arg
= arg
;
3205 record_unwind_protect_ptr (void (*function
) (void *), void *arg
)
3207 specpdl_ptr
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3208 specpdl_ptr
->unwind_ptr
.func
= function
;
3209 specpdl_ptr
->unwind_ptr
.arg
= arg
;
3214 record_unwind_protect_int (void (*function
) (int), int arg
)
3216 specpdl_ptr
->unwind_int
.kind
= SPECPDL_UNWIND_INT
;
3217 specpdl_ptr
->unwind_int
.func
= function
;
3218 specpdl_ptr
->unwind_int
.arg
= arg
;
3223 record_unwind_protect_void (void (*function
) (void))
3225 specpdl_ptr
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3226 specpdl_ptr
->unwind_void
.func
= function
;
3234 /* Push an unwind-protect entry that does nothing, so that
3235 set_unwind_protect_ptr can overwrite it later. */
3238 record_unwind_protect_nothing (void)
3240 record_unwind_protect_void (do_nothing
);
3243 /* Clear the unwind-protect entry COUNT, so that it does nothing.
3244 It need not be at the top of the stack. */
3247 clear_unwind_protect (ptrdiff_t count
)
3249 union specbinding
*p
= specpdl
+ count
;
3250 p
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3251 p
->unwind_void
.func
= do_nothing
;
3254 /* Set the unwind-protect entry COUNT so that it invokes FUNC (ARG).
3255 It need not be at the top of the stack. Discard the entry's
3256 previous value without invoking it. */
3259 set_unwind_protect (ptrdiff_t count
, void (*func
) (Lisp_Object
),
3262 union specbinding
*p
= specpdl
+ count
;
3263 p
->unwind
.kind
= SPECPDL_UNWIND
;
3264 p
->unwind
.func
= func
;
3265 p
->unwind
.arg
= arg
;
3269 set_unwind_protect_ptr (ptrdiff_t count
, void (*func
) (void *), void *arg
)
3271 union specbinding
*p
= specpdl
+ count
;
3272 p
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3273 p
->unwind_ptr
.func
= func
;
3274 p
->unwind_ptr
.arg
= arg
;
3277 /* Pop and execute entries from the unwind-protect stack until the
3278 depth COUNT is reached. Return VALUE. */
3281 unbind_to (ptrdiff_t count
, Lisp_Object value
)
3283 Lisp_Object quitf
= Vquit_flag
;
3287 while (specpdl_ptr
!= specpdl
+ count
)
3289 /* Decrement specpdl_ptr before we do the work to unbind it, so
3290 that an error in unbinding won't try to unbind the same entry
3291 again. Take care to copy any parts of the binding needed
3292 before invoking any code that can make more bindings. */
3296 switch (specpdl_ptr
->kind
)
3298 case SPECPDL_UNWIND
:
3299 specpdl_ptr
->unwind
.func (specpdl_ptr
->unwind
.arg
);
3301 case SPECPDL_UNWIND_PTR
:
3302 specpdl_ptr
->unwind_ptr
.func (specpdl_ptr
->unwind_ptr
.arg
);
3304 case SPECPDL_UNWIND_INT
:
3305 specpdl_ptr
->unwind_int
.func (specpdl_ptr
->unwind_int
.arg
);
3307 case SPECPDL_UNWIND_VOID
:
3308 specpdl_ptr
->unwind_void
.func ();
3310 case SPECPDL_BACKTRACE
:
3313 { /* If variable has a trivial value (no forwarding), we can
3314 just set it. No need to check for constant symbols here,
3315 since that was already done by specbind. */
3316 Lisp_Object sym
= specpdl_symbol (specpdl_ptr
);
3317 if (SYMBOLP (sym
) && XSYMBOL (sym
)->redirect
== SYMBOL_PLAINVAL
)
3319 SET_SYMBOL_VAL (XSYMBOL (sym
),
3320 specpdl_old_value (specpdl_ptr
));
3325 NOTE: we only ever come here if make_local_foo was used for
3326 the first time on this var within this let. */
3329 case SPECPDL_LET_DEFAULT
:
3330 Fset_default (specpdl_symbol (specpdl_ptr
),
3331 specpdl_old_value (specpdl_ptr
));
3333 case SPECPDL_LET_LOCAL
:
3335 Lisp_Object symbol
= specpdl_symbol (specpdl_ptr
);
3336 Lisp_Object where
= specpdl_where (specpdl_ptr
);
3337 Lisp_Object old_value
= specpdl_old_value (specpdl_ptr
);
3338 eassert (BUFFERP (where
));
3340 /* If this was a local binding, reset the value in the appropriate
3341 buffer, but only if that buffer's binding still exists. */
3342 if (!NILP (Flocal_variable_p (symbol
, where
)))
3343 set_internal (symbol
, old_value
, where
, 1);
3349 if (NILP (Vquit_flag
) && !NILP (quitf
))
3355 DEFUN ("special-variable-p", Fspecial_variable_p
, Sspecial_variable_p
, 1, 1, 0,
3356 doc
: /* Return non-nil if SYMBOL's global binding has been declared special.
3357 A special variable is one that will be bound dynamically, even in a
3358 context where binding is lexical by default. */)
3359 (Lisp_Object symbol
)
3361 CHECK_SYMBOL (symbol
);
3362 return XSYMBOL (symbol
)->declared_special
? Qt
: Qnil
;
3366 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3367 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3368 The debugger is entered when that frame exits, if the flag is non-nil. */)
3369 (Lisp_Object level
, Lisp_Object flag
)
3371 union specbinding
*pdl
= backtrace_top ();
3372 register EMACS_INT i
;
3374 CHECK_NUMBER (level
);
3376 for (i
= 0; backtrace_p (pdl
) && i
< XINT (level
); i
++)
3377 pdl
= backtrace_next (pdl
);
3379 if (backtrace_p (pdl
))
3380 set_backtrace_debug_on_exit (pdl
, !NILP (flag
));
3385 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3386 doc
: /* Print a trace of Lisp function calls currently active.
3387 Output stream used is value of `standard-output'. */)
3390 union specbinding
*pdl
= backtrace_top ();
3392 Lisp_Object old_print_level
= Vprint_level
;
3394 if (NILP (Vprint_level
))
3395 XSETFASTINT (Vprint_level
, 8);
3397 while (backtrace_p (pdl
))
3399 write_string (backtrace_debug_on_exit (pdl
) ? "* " : " ");
3400 if (backtrace_nargs (pdl
) == UNEVALLED
)
3402 Fprin1 (Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)),
3404 write_string ("\n");
3408 tem
= backtrace_function (pdl
);
3409 Fprin1 (tem
, Qnil
); /* This can QUIT. */
3413 for (i
= 0; i
< backtrace_nargs (pdl
); i
++)
3415 if (i
) write_string (" ");
3416 Fprin1 (backtrace_args (pdl
)[i
], Qnil
);
3419 write_string (")\n");
3421 pdl
= backtrace_next (pdl
);
3424 Vprint_level
= old_print_level
;
3428 static union specbinding
*
3429 get_backtrace_frame (Lisp_Object nframes
, Lisp_Object base
)
3431 union specbinding
*pdl
= backtrace_top ();
3432 register EMACS_INT i
;
3434 CHECK_NATNUM (nframes
);
3437 { /* Skip up to `base'. */
3438 base
= Findirect_function (base
, Qt
);
3439 while (backtrace_p (pdl
)
3440 && !EQ (base
, Findirect_function (backtrace_function (pdl
), Qt
)))
3441 pdl
= backtrace_next (pdl
);
3444 /* Find the frame requested. */
3445 for (i
= XFASTINT (nframes
); i
> 0 && backtrace_p (pdl
); i
--)
3446 pdl
= backtrace_next (pdl
);
3451 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 2, NULL
,
3452 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3453 If that frame has not evaluated the arguments yet (or is a special form),
3454 the value is (nil FUNCTION ARG-FORMS...).
3455 If that frame has evaluated its arguments and called its function already,
3456 the value is (t FUNCTION ARG-VALUES...).
3457 A &rest arg is represented as the tail of the list ARG-VALUES.
3458 FUNCTION is whatever was supplied as car of evaluated list,
3459 or a lambda expression for macro calls.
3460 If NFRAMES is more than the number of frames, the value is nil.
3461 If BASE is non-nil, it should be a function and NFRAMES counts from its
3462 nearest activation frame. */)
3463 (Lisp_Object nframes
, Lisp_Object base
)
3465 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3467 if (!backtrace_p (pdl
))
3469 if (backtrace_nargs (pdl
) == UNEVALLED
)
3471 Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)));
3474 Lisp_Object tem
= Flist (backtrace_nargs (pdl
), backtrace_args (pdl
));
3476 return Fcons (Qt
, Fcons (backtrace_function (pdl
), tem
));
3480 /* For backtrace-eval, we want to temporarily unwind the last few elements of
3481 the specpdl stack, and then rewind them. We store the pre-unwind values
3482 directly in the pre-existing specpdl elements (i.e. we swap the current
3483 value and the old value stored in the specpdl), kind of like the inplace
3484 pointer-reversal trick. As it turns out, the rewind does the same as the
3485 unwind, except it starts from the other end of the specpdl stack, so we use
3486 the same function for both unwind and rewind. */
3488 backtrace_eval_unrewind (int distance
)
3490 union specbinding
*tmp
= specpdl_ptr
;
3493 { /* It's a rewind rather than unwind. */
3494 tmp
+= distance
- 1;
3496 distance
= -distance
;
3499 for (; distance
> 0; distance
--)
3504 /* FIXME: Ideally we'd like to "temporarily unwind" (some of) those
3505 unwind_protect, but the problem is that we don't know how to
3506 rewind them afterwards. */
3507 case SPECPDL_UNWIND
:
3509 Lisp_Object oldarg
= tmp
->unwind
.arg
;
3510 if (tmp
->unwind
.func
== set_buffer_if_live
)
3511 tmp
->unwind
.arg
= Fcurrent_buffer ();
3512 else if (tmp
->unwind
.func
== save_excursion_restore
)
3513 tmp
->unwind
.arg
= save_excursion_save ();
3516 tmp
->unwind
.func (oldarg
);
3520 case SPECPDL_UNWIND_PTR
:
3521 case SPECPDL_UNWIND_INT
:
3522 case SPECPDL_UNWIND_VOID
:
3523 case SPECPDL_BACKTRACE
:
3526 { /* If variable has a trivial value (no forwarding), we can
3527 just set it. No need to check for constant symbols here,
3528 since that was already done by specbind. */
3529 Lisp_Object sym
= specpdl_symbol (tmp
);
3530 if (SYMBOLP (sym
) && XSYMBOL (sym
)->redirect
== SYMBOL_PLAINVAL
)
3532 Lisp_Object old_value
= specpdl_old_value (tmp
);
3533 set_specpdl_old_value (tmp
, SYMBOL_VAL (XSYMBOL (sym
)));
3534 SET_SYMBOL_VAL (XSYMBOL (sym
), old_value
);
3539 NOTE: we only ever come here if make_local_foo was used for
3540 the first time on this var within this let. */
3543 case SPECPDL_LET_DEFAULT
:
3545 Lisp_Object sym
= specpdl_symbol (tmp
);
3546 Lisp_Object old_value
= specpdl_old_value (tmp
);
3547 set_specpdl_old_value (tmp
, Fdefault_value (sym
));
3548 Fset_default (sym
, old_value
);
3551 case SPECPDL_LET_LOCAL
:
3553 Lisp_Object symbol
= specpdl_symbol (tmp
);
3554 Lisp_Object where
= specpdl_where (tmp
);
3555 Lisp_Object old_value
= specpdl_old_value (tmp
);
3556 eassert (BUFFERP (where
));
3558 /* If this was a local binding, reset the value in the appropriate
3559 buffer, but only if that buffer's binding still exists. */
3560 if (!NILP (Flocal_variable_p (symbol
, where
)))
3562 set_specpdl_old_value
3563 (tmp
, Fbuffer_local_value (symbol
, where
));
3564 set_internal (symbol
, old_value
, where
, 1);
3572 DEFUN ("backtrace-eval", Fbacktrace_eval
, Sbacktrace_eval
, 2, 3, NULL
,
3573 doc
: /* Evaluate EXP in the context of some activation frame.
3574 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3575 (Lisp_Object exp
, Lisp_Object nframes
, Lisp_Object base
)
3577 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3578 ptrdiff_t count
= SPECPDL_INDEX ();
3579 ptrdiff_t distance
= specpdl_ptr
- pdl
;
3580 eassert (distance
>= 0);
3582 if (!backtrace_p (pdl
))
3583 error ("Activation frame not found!");
3585 backtrace_eval_unrewind (distance
);
3586 record_unwind_protect_int (backtrace_eval_unrewind
, -distance
);
3588 /* Use eval_sub rather than Feval since the main motivation behind
3589 backtrace-eval is to be able to get/set the value of lexical variables
3590 from the debugger. */
3591 return unbind_to (count
, eval_sub (exp
));
3594 DEFUN ("backtrace--locals", Fbacktrace__locals
, Sbacktrace__locals
, 1, 2, NULL
,
3595 doc
: /* Return names and values of local variables of a stack frame.
3596 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3597 (Lisp_Object nframes
, Lisp_Object base
)
3599 union specbinding
*frame
= get_backtrace_frame (nframes
, base
);
3600 union specbinding
*prevframe
3601 = get_backtrace_frame (make_number (XFASTINT (nframes
) - 1), base
);
3602 ptrdiff_t distance
= specpdl_ptr
- frame
;
3603 Lisp_Object result
= Qnil
;
3604 eassert (distance
>= 0);
3606 if (!backtrace_p (prevframe
))
3607 error ("Activation frame not found!");
3608 if (!backtrace_p (frame
))
3609 error ("Activation frame not found!");
3611 /* The specpdl entries normally contain the symbol being bound along with its
3612 `old_value', so it can be restored. The new value to which it is bound is
3613 available in one of two places: either in the current value of the
3614 variable (if it hasn't been rebound yet) or in the `old_value' slot of the
3615 next specpdl entry for it.
3616 `backtrace_eval_unrewind' happens to swap the role of `old_value'
3617 and "new value", so we abuse it here, to fetch the new value.
3618 It's ugly (we'd rather not modify global data) and a bit inefficient,
3619 but it does the job for now. */
3620 backtrace_eval_unrewind (distance
);
3624 union specbinding
*tmp
= prevframe
;
3625 for (; tmp
> frame
; tmp
--)
3630 case SPECPDL_LET_DEFAULT
:
3631 case SPECPDL_LET_LOCAL
:
3633 Lisp_Object sym
= specpdl_symbol (tmp
);
3634 Lisp_Object val
= specpdl_old_value (tmp
);
3635 if (EQ (sym
, Qinternal_interpreter_environment
))
3637 Lisp_Object env
= val
;
3638 for (; CONSP (env
); env
= XCDR (env
))
3640 Lisp_Object binding
= XCAR (env
);
3641 if (CONSP (binding
))
3642 result
= Fcons (Fcons (XCAR (binding
),
3648 result
= Fcons (Fcons (sym
, val
), result
);
3652 case SPECPDL_UNWIND
:
3653 case SPECPDL_UNWIND_PTR
:
3654 case SPECPDL_UNWIND_INT
:
3655 case SPECPDL_UNWIND_VOID
:
3656 case SPECPDL_BACKTRACE
:
3665 /* Restore values from specpdl to original place. */
3666 backtrace_eval_unrewind (-distance
);
3675 union specbinding
*pdl
;
3676 for (pdl
= specpdl
; pdl
!= specpdl_ptr
; pdl
++)
3680 case SPECPDL_UNWIND
:
3681 mark_object (specpdl_arg (pdl
));
3684 case SPECPDL_BACKTRACE
:
3686 ptrdiff_t nargs
= backtrace_nargs (pdl
);
3687 mark_object (backtrace_function (pdl
));
3688 if (nargs
== UNEVALLED
)
3691 mark_object (backtrace_args (pdl
)[nargs
]);
3695 case SPECPDL_LET_DEFAULT
:
3696 case SPECPDL_LET_LOCAL
:
3697 mark_object (specpdl_where (pdl
));
3700 mark_object (specpdl_symbol (pdl
));
3701 mark_object (specpdl_old_value (pdl
));
3704 case SPECPDL_UNWIND_PTR
:
3705 case SPECPDL_UNWIND_INT
:
3706 case SPECPDL_UNWIND_VOID
:
3716 get_backtrace (Lisp_Object array
)
3718 union specbinding
*pdl
= backtrace_next (backtrace_top ());
3719 ptrdiff_t i
= 0, asize
= ASIZE (array
);
3721 /* Copy the backtrace contents into working memory. */
3722 for (; i
< asize
; i
++)
3724 if (backtrace_p (pdl
))
3726 ASET (array
, i
, backtrace_function (pdl
));
3727 pdl
= backtrace_next (pdl
);
3730 ASET (array
, i
, Qnil
);
3734 Lisp_Object
backtrace_top_function (void)
3736 union specbinding
*pdl
= backtrace_top ();
3737 return (backtrace_p (pdl
) ? backtrace_function (pdl
) : Qnil
);
3743 DEFVAR_INT ("max-specpdl-size", max_specpdl_size
,
3744 doc
: /* Limit on number of Lisp variable bindings and `unwind-protect's.
3745 If Lisp code tries to increase the total number past this amount,
3746 an error is signaled.
3747 You can safely use a value considerably larger than the default value,
3748 if that proves inconveniently small. However, if you increase it too far,
3749 Emacs could run out of memory trying to make the stack bigger.
3750 Note that this limit may be silently increased by the debugger
3751 if `debug-on-error' or `debug-on-quit' is set. */);
3753 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth
,
3754 doc
: /* Limit on depth in `eval', `apply' and `funcall' before error.
3756 This limit serves to catch infinite recursions for you before they cause
3757 actual stack overflow in C, which would be fatal for Emacs.
3758 You can safely make it considerably larger than its default value,
3759 if that proves inconveniently small. However, if you increase it too far,
3760 Emacs could overflow the real C stack, and crash. */);
3762 DEFVAR_LISP ("quit-flag", Vquit_flag
,
3763 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3764 If the value is t, that means do an ordinary quit.
3765 If the value equals `throw-on-input', that means quit by throwing
3766 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3767 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3768 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3771 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit
,
3772 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3773 Note that `quit-flag' will still be set by typing C-g,
3774 so a quit will be signaled as soon as `inhibit-quit' is nil.
3775 To prevent this happening, set `quit-flag' to nil
3776 before making `inhibit-quit' nil. */);
3777 Vinhibit_quit
= Qnil
;
3779 DEFSYM (Qsetq
, "setq");
3780 DEFSYM (Qinhibit_quit
, "inhibit-quit");
3781 DEFSYM (Qautoload
, "autoload");
3782 DEFSYM (Qinhibit_debugger
, "inhibit-debugger");
3783 DEFSYM (Qmacro
, "macro");
3785 /* Note that the process handling also uses Qexit, but we don't want
3786 to staticpro it twice, so we just do it here. */
3787 DEFSYM (Qexit
, "exit");
3789 DEFSYM (Qinteractive
, "interactive");
3790 DEFSYM (Qcommandp
, "commandp");
3791 DEFSYM (Qand_rest
, "&rest");
3792 DEFSYM (Qand_optional
, "&optional");
3793 DEFSYM (Qclosure
, "closure");
3794 DEFSYM (QCdocumentation
, ":documentation");
3795 DEFSYM (Qdebug
, "debug");
3797 DEFVAR_LISP ("inhibit-debugger", Vinhibit_debugger
,
3798 doc
: /* Non-nil means never enter the debugger.
3799 Normally set while the debugger is already active, to avoid recursive
3801 Vinhibit_debugger
= Qnil
;
3803 DEFVAR_LISP ("debug-on-error", Vdebug_on_error
,
3804 doc
: /* Non-nil means enter debugger if an error is signaled.
3805 Does not apply to errors handled by `condition-case' or those
3806 matched by `debug-ignored-errors'.
3807 If the value is a list, an error only means to enter the debugger
3808 if one of its condition symbols appears in the list.
3809 When you evaluate an expression interactively, this variable
3810 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3811 The command `toggle-debug-on-error' toggles this.
3812 See also the variable `debug-on-quit' and `inhibit-debugger'. */);
3813 Vdebug_on_error
= Qnil
;
3815 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors
,
3816 doc
: /* List of errors for which the debugger should not be called.
3817 Each element may be a condition-name or a regexp that matches error messages.
3818 If any element applies to a given error, that error skips the debugger
3819 and just returns to top level.
3820 This overrides the variable `debug-on-error'.
3821 It does not apply to errors handled by `condition-case'. */);
3822 Vdebug_ignored_errors
= Qnil
;
3824 DEFVAR_BOOL ("debug-on-quit", debug_on_quit
,
3825 doc
: /* Non-nil means enter debugger if quit is signaled (C-g, for example).
3826 Does not apply if quit is handled by a `condition-case'. */);
3829 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call
,
3830 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3832 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue
,
3833 doc
: /* Non-nil means debugger may continue execution.
3834 This is nil when the debugger is called under circumstances where it
3835 might not be safe to continue. */);
3836 debugger_may_continue
= 1;
3838 DEFVAR_LISP ("debugger", Vdebugger
,
3839 doc
: /* Function to call to invoke debugger.
3840 If due to frame exit, args are `exit' and the value being returned;
3841 this function's value will be returned instead of that.
3842 If due to error, args are `error' and a list of the args to `signal'.
3843 If due to `apply' or `funcall' entry, one arg, `lambda'.
3844 If due to `eval' entry, one arg, t. */);
3847 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function
,
3848 doc
: /* If non-nil, this is a function for `signal' to call.
3849 It receives the same arguments that `signal' was given.
3850 The Edebug package uses this to regain control. */);
3851 Vsignal_hook_function
= Qnil
;
3853 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal
,
3854 doc
: /* Non-nil means call the debugger regardless of condition handlers.
3855 Note that `debug-on-error', `debug-on-quit' and friends
3856 still determine whether to handle the particular condition. */);
3857 Vdebug_on_signal
= Qnil
;
3859 /* When lexical binding is being used,
3860 Vinternal_interpreter_environment is non-nil, and contains an alist
3861 of lexically-bound variable, or (t), indicating an empty
3862 environment. The lisp name of this variable would be
3863 `internal-interpreter-environment' if it weren't hidden.
3864 Every element of this list can be either a cons (VAR . VAL)
3865 specifying a lexical binding, or a single symbol VAR indicating
3866 that this variable should use dynamic scoping. */
3867 DEFSYM (Qinternal_interpreter_environment
,
3868 "internal-interpreter-environment");
3869 DEFVAR_LISP ("internal-interpreter-environment",
3870 Vinternal_interpreter_environment
,
3871 doc
: /* If non-nil, the current lexical environment of the lisp interpreter.
3872 When lexical binding is not being used, this variable is nil.
3873 A value of `(t)' indicates an empty environment, otherwise it is an
3874 alist of active lexical bindings. */);
3875 Vinternal_interpreter_environment
= Qnil
;
3876 /* Don't export this variable to Elisp, so no one can mess with it
3877 (Just imagine if someone makes it buffer-local). */
3878 Funintern (Qinternal_interpreter_environment
, Qnil
);
3880 Vrun_hooks
= intern_c_string ("run-hooks");
3881 staticpro (&Vrun_hooks
);
3883 staticpro (&Vautoload_queue
);
3884 Vautoload_queue
= Qnil
;
3885 staticpro (&Vsignaling_function
);
3886 Vsignaling_function
= Qnil
;
3888 inhibit_lisp_code
= Qnil
;
3899 defsubr (&Sfunction
);
3900 defsubr (&Sdefault_toplevel_value
);
3901 defsubr (&Sset_default_toplevel_value
);
3903 defsubr (&Sdefvaralias
);
3904 defsubr (&Sdefconst
);
3905 defsubr (&Smake_var_non_special
);
3909 defsubr (&Smacroexpand
);
3912 defsubr (&Sunwind_protect
);
3913 defsubr (&Scondition_case
);
3915 defsubr (&Scommandp
);
3916 defsubr (&Sautoload
);
3917 defsubr (&Sautoload_do_load
);
3920 defsubr (&Sfuncall
);
3921 defsubr (&Sfunc_arity
);
3922 defsubr (&Srun_hooks
);
3923 defsubr (&Srun_hook_with_args
);
3924 defsubr (&Srun_hook_with_args_until_success
);
3925 defsubr (&Srun_hook_with_args_until_failure
);
3926 defsubr (&Srun_hook_wrapped
);
3927 defsubr (&Sfetch_bytecode
);
3928 defsubr (&Sbacktrace_debug
);
3929 defsubr (&Sbacktrace
);
3930 defsubr (&Sbacktrace_frame
);
3931 defsubr (&Sbacktrace_eval
);
3932 defsubr (&Sbacktrace__locals
);
3933 defsubr (&Sspecial_variable_p
);
3934 defsubr (&Sfunctionp
);