1 /* Evaluator for GNU Emacs Lisp interpreter.
3 Copyright (C) 1985-1987, 1993-1995, 1999-2014 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
11 (at 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"
31 /* Chain of condition and catch handlers currently in effect. */
33 struct handler
*handlerlist
;
36 /* Count levels of GCPRO to detect failure to UNGCPRO. */
40 Lisp_Object Qautoload
, Qmacro
, Qexit
, Qinteractive
, Qcommandp
;
41 Lisp_Object Qinhibit_quit
;
42 Lisp_Object Qand_rest
;
43 static Lisp_Object Qand_optional
;
44 static Lisp_Object Qinhibit_debugger
;
45 static Lisp_Object Qdeclare
;
46 Lisp_Object Qinternal_interpreter_environment
, Qclosure
;
48 static Lisp_Object Qdebug
;
50 /* This holds either the symbol `run-hooks' or nil.
51 It is nil at an early stage of startup, and when Emacs
54 Lisp_Object Vrun_hooks
;
56 /* Non-nil means record all fset's and provide's, to be undone
57 if the file being autoloaded is not fully loaded.
58 They are recorded by being consed onto the front of Vautoload_queue:
59 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
61 Lisp_Object Vautoload_queue
;
63 /* Current number of specbindings allocated in specpdl, not counting
64 the dummy entry specpdl[-1]. */
66 ptrdiff_t specpdl_size
;
68 /* Pointer to beginning of specpdl. A dummy entry specpdl[-1] exists
69 only so that its address can be taken. */
71 union specbinding
*specpdl
;
73 /* Pointer to first unused element in specpdl. */
75 union specbinding
*specpdl_ptr
;
77 /* Depth in Lisp evaluations and function calls. */
79 EMACS_INT lisp_eval_depth
;
81 /* The value of num_nonmacro_input_events as of the last time we
82 started to enter the debugger. If we decide to enter the debugger
83 again when this is still equal to num_nonmacro_input_events, then we
84 know that the debugger itself has an error, and we should just
85 signal the error instead of entering an infinite loop of debugger
88 static EMACS_INT when_entered_debugger
;
90 /* The function from which the last `signal' was called. Set in
92 /* FIXME: We should probably get rid of this! */
93 Lisp_Object Vsignaling_function
;
95 /* If non-nil, Lisp code must not be run since some part of Emacs is
96 in an inconsistent state. Currently, x-create-frame uses this to
97 avoid triggering window-configuration-change-hook while the new
98 frame is half-initialized. */
99 Lisp_Object inhibit_lisp_code
;
101 /* These would ordinarily be static, but they need to be visible to GDB. */
102 bool backtrace_p (union specbinding
*) EXTERNALLY_VISIBLE
;
103 Lisp_Object
*backtrace_args (union specbinding
*) EXTERNALLY_VISIBLE
;
104 Lisp_Object
backtrace_function (union specbinding
*) EXTERNALLY_VISIBLE
;
105 union specbinding
*backtrace_next (union specbinding
*) EXTERNALLY_VISIBLE
;
106 union specbinding
*backtrace_top (void) EXTERNALLY_VISIBLE
;
108 static Lisp_Object
funcall_lambda (Lisp_Object
, ptrdiff_t, Lisp_Object
*);
109 static Lisp_Object
apply_lambda (Lisp_Object fun
, Lisp_Object args
);
112 specpdl_symbol (union specbinding
*pdl
)
114 eassert (pdl
->kind
>= SPECPDL_LET
);
115 return pdl
->let
.symbol
;
119 specpdl_old_value (union specbinding
*pdl
)
121 eassert (pdl
->kind
>= SPECPDL_LET
);
122 return pdl
->let
.old_value
;
126 set_specpdl_old_value (union specbinding
*pdl
, Lisp_Object val
)
128 eassert (pdl
->kind
>= SPECPDL_LET
);
129 pdl
->let
.old_value
= val
;
133 specpdl_where (union specbinding
*pdl
)
135 eassert (pdl
->kind
> SPECPDL_LET
);
136 return pdl
->let
.where
;
140 specpdl_arg (union specbinding
*pdl
)
142 eassert (pdl
->kind
== SPECPDL_UNWIND
);
143 return pdl
->unwind
.arg
;
147 backtrace_function (union specbinding
*pdl
)
149 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
150 return pdl
->bt
.function
;
154 backtrace_nargs (union specbinding
*pdl
)
156 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
157 return pdl
->bt
.nargs
;
161 backtrace_args (union specbinding
*pdl
)
163 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
168 backtrace_debug_on_exit (union specbinding
*pdl
)
170 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
171 return pdl
->bt
.debug_on_exit
;
174 /* Functions to modify slots of backtrace records. */
177 set_backtrace_args (union specbinding
*pdl
, Lisp_Object
*args
)
179 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
184 set_backtrace_nargs (union specbinding
*pdl
, ptrdiff_t n
)
186 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
191 set_backtrace_debug_on_exit (union specbinding
*pdl
, bool doe
)
193 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
194 pdl
->bt
.debug_on_exit
= doe
;
197 /* Helper functions to scan the backtrace. */
200 backtrace_p (union specbinding
*pdl
)
201 { return pdl
>= specpdl
; }
206 union specbinding
*pdl
= specpdl_ptr
- 1;
207 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
213 backtrace_next (union specbinding
*pdl
)
216 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
223 init_eval_once (void)
226 union specbinding
*pdlvec
= xmalloc ((size
+ 1) * sizeof *specpdl
);
228 specpdl
= specpdl_ptr
= pdlvec
+ 1;
229 /* Don't forget to update docs (lispref node "Local Variables"). */
230 max_specpdl_size
= 1300; /* 1000 is not enough for CEDET's c-by.el. */
231 max_lisp_eval_depth
= 600;
236 static struct handler handlerlist_sentinel
;
241 specpdl_ptr
= specpdl
;
242 { /* Put a dummy catcher at top-level so that handlerlist is never NULL.
243 This is important since handlerlist->nextfree holds the freelist
244 which would otherwise leak every time we unwind back to top-level. */
246 handlerlist
= handlerlist_sentinel
.nextfree
= &handlerlist_sentinel
;
247 PUSH_HANDLER (c
, Qunbound
, CATCHER
);
248 eassert (c
== &handlerlist_sentinel
);
249 handlerlist_sentinel
.nextfree
= NULL
;
250 handlerlist_sentinel
.next
= NULL
;
253 debug_on_next_call
= 0;
258 /* This is less than the initial value of num_nonmacro_input_events. */
259 when_entered_debugger
= -1;
262 /* Unwind-protect function used by call_debugger. */
265 restore_stack_limits (Lisp_Object data
)
267 max_specpdl_size
= XINT (XCAR (data
));
268 max_lisp_eval_depth
= XINT (XCDR (data
));
271 static void grow_specpdl (void);
273 /* Call the Lisp debugger, giving it argument ARG. */
276 call_debugger (Lisp_Object arg
)
278 bool debug_while_redisplaying
;
279 ptrdiff_t count
= SPECPDL_INDEX ();
281 EMACS_INT old_depth
= max_lisp_eval_depth
;
282 /* Do not allow max_specpdl_size less than actual depth (Bug#16603). */
283 EMACS_INT old_max
= max (max_specpdl_size
, count
);
285 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
286 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
288 /* While debugging Bug#16603, previous value of 100 was found
289 too small to avoid specpdl overflow in the debugger itself. */
290 if (max_specpdl_size
- 200 < count
)
291 max_specpdl_size
= count
+ 200;
293 if (old_max
== count
)
295 /* We can enter the debugger due to specpdl overflow (Bug#16603). */
300 /* Restore limits after leaving the debugger. */
301 record_unwind_protect (restore_stack_limits
,
302 Fcons (make_number (old_max
),
303 make_number (old_depth
)));
305 #ifdef HAVE_WINDOW_SYSTEM
306 if (display_hourglass_p
)
310 debug_on_next_call
= 0;
311 when_entered_debugger
= num_nonmacro_input_events
;
313 /* Resetting redisplaying_p to 0 makes sure that debug output is
314 displayed if the debugger is invoked during redisplay. */
315 debug_while_redisplaying
= redisplaying_p
;
317 specbind (intern ("debugger-may-continue"),
318 debug_while_redisplaying
? Qnil
: Qt
);
319 specbind (Qinhibit_redisplay
, Qnil
);
320 specbind (Qinhibit_debugger
, Qt
);
322 #if 0 /* Binding this prevents execution of Lisp code during
323 redisplay, which necessarily leads to display problems. */
324 specbind (Qinhibit_eval_during_redisplay
, Qt
);
327 val
= apply1 (Vdebugger
, arg
);
329 /* Interrupting redisplay and resuming it later is not safe under
330 all circumstances. So, when the debugger returns, abort the
331 interrupted redisplay by going back to the top-level. */
332 if (debug_while_redisplaying
)
335 return unbind_to (count
, val
);
339 do_debug_on_call (Lisp_Object code
)
341 debug_on_next_call
= 0;
342 set_backtrace_debug_on_exit (specpdl_ptr
- 1, true);
343 call_debugger (list1 (code
));
346 /* NOTE!!! Every function that can call EVAL must protect its args
347 and temporaries from garbage collection while it needs them.
348 The definition of `For' shows what you have to do. */
350 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
351 doc
: /* Eval args until one of them yields non-nil, then return that value.
352 The remaining args are not evalled at all.
353 If all args return nil, return nil.
354 usage: (or CONDITIONS...) */)
357 register Lisp_Object val
= Qnil
;
364 val
= eval_sub (XCAR (args
));
374 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
375 doc
: /* Eval args until one of them yields nil, then return nil.
376 The remaining args are not evalled at all.
377 If no arg yields nil, return the last arg's value.
378 usage: (and CONDITIONS...) */)
381 register Lisp_Object val
= Qt
;
388 val
= eval_sub (XCAR (args
));
398 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
399 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
400 Returns the value of THEN or the value of the last of the ELSE's.
401 THEN must be one expression, but ELSE... can be zero or more expressions.
402 If COND yields nil, and there are no ELSE's, the value is nil.
403 usage: (if COND THEN ELSE...) */)
410 cond
= eval_sub (XCAR (args
));
414 return eval_sub (Fcar (XCDR (args
)));
415 return Fprogn (XCDR (XCDR (args
)));
418 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
419 doc
: /* Try each clause until one succeeds.
420 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
421 and, if the value is non-nil, this clause succeeds:
422 then the expressions in BODY are evaluated and the last one's
423 value is the value of the cond-form.
424 If a clause has one element, as in (CONDITION), then the cond-form
425 returns CONDITION's value, if that is non-nil.
426 If no clause succeeds, cond returns nil.
427 usage: (cond CLAUSES...) */)
430 Lisp_Object val
= args
;
436 Lisp_Object clause
= XCAR (args
);
437 val
= eval_sub (Fcar (clause
));
440 if (!NILP (XCDR (clause
)))
441 val
= Fprogn (XCDR (clause
));
451 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
452 doc
: /* Eval BODY forms sequentially and return value of last one.
453 usage: (progn BODY...) */)
456 Lisp_Object val
= Qnil
;
463 val
= eval_sub (XCAR (body
));
471 /* Evaluate BODY sequentially, discarding its value. Suitable for
472 record_unwind_protect. */
475 unwind_body (Lisp_Object body
)
480 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
481 doc
: /* Eval FIRST and BODY sequentially; return value from FIRST.
482 The value of FIRST is saved during the evaluation of the remaining args,
483 whose values are discarded.
484 usage: (prog1 FIRST BODY...) */)
488 Lisp_Object args_left
;
489 struct gcpro gcpro1
, gcpro2
;
495 val
= eval_sub (XCAR (args_left
));
496 while (CONSP (args_left
= XCDR (args_left
)))
497 eval_sub (XCAR (args_left
));
503 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
504 doc
: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
505 The value of FORM2 is saved during the evaluation of the
506 remaining args, whose values are discarded.
507 usage: (prog2 FORM1 FORM2 BODY...) */)
513 eval_sub (XCAR (args
));
515 return Fprog1 (XCDR (args
));
518 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
519 doc
: /* Set each SYM to the value of its VAL.
520 The symbols SYM are variables; they are literal (not evaluated).
521 The values VAL are expressions; they are evaluated.
522 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
523 The second VAL is not computed until after the first SYM is set, and so on;
524 each VAL can use the new value of variables set earlier in the `setq'.
525 The return value of the `setq' form is the value of the last VAL.
526 usage: (setq [SYM VAL]...) */)
529 Lisp_Object val
, sym
, lex_binding
;
534 Lisp_Object args_left
= args
;
540 val
= eval_sub (Fcar (XCDR (args_left
)));
541 sym
= XCAR (args_left
);
543 /* Like for eval_sub, we do not check declared_special here since
544 it's been done when let-binding. */
545 if (!NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
547 && !NILP (lex_binding
548 = Fassq (sym
, Vinternal_interpreter_environment
)))
549 XSETCDR (lex_binding
, val
); /* SYM is lexically bound. */
551 Fset (sym
, val
); /* SYM is dynamically bound. */
553 args_left
= Fcdr (XCDR (args_left
));
555 while (CONSP (args_left
));
563 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
564 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
565 Warning: `quote' does not construct its return value, but just returns
566 the value that was pre-constructed by the Lisp reader (see info node
567 `(elisp)Printed Representation').
568 This means that '(a . b) is not identical to (cons 'a 'b): the former
569 does not cons. Quoting should be reserved for constants that will
570 never be modified by side-effects, unless you like self-modifying code.
571 See the common pitfall in info node `(elisp)Rearrangement' for an example
572 of unexpected results when a quoted object is modified.
573 usage: (quote ARG) */)
576 if (CONSP (XCDR (args
)))
577 xsignal2 (Qwrong_number_of_arguments
, Qquote
, Flength (args
));
581 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
582 doc
: /* Like `quote', but preferred for objects which are functions.
583 In byte compilation, `function' causes its argument to be compiled.
584 `quote' cannot do that.
585 usage: (function ARG) */)
588 Lisp_Object quoted
= XCAR (args
);
590 if (CONSP (XCDR (args
)))
591 xsignal2 (Qwrong_number_of_arguments
, Qfunction
, Flength (args
));
593 if (!NILP (Vinternal_interpreter_environment
)
595 && EQ (XCAR (quoted
), Qlambda
))
596 /* This is a lambda expression within a lexical environment;
597 return an interpreted closure instead of a simple lambda. */
598 return Fcons (Qclosure
, Fcons (Vinternal_interpreter_environment
,
601 /* Simply quote the argument. */
606 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
607 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
608 Aliased variables always have the same value; setting one sets the other.
609 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
610 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
611 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
612 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
613 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
614 The return value is BASE-VARIABLE. */)
615 (Lisp_Object new_alias
, Lisp_Object base_variable
, Lisp_Object docstring
)
617 struct Lisp_Symbol
*sym
;
619 CHECK_SYMBOL (new_alias
);
620 CHECK_SYMBOL (base_variable
);
622 sym
= XSYMBOL (new_alias
);
625 /* Not sure why, but why not? */
626 error ("Cannot make a constant an alias");
628 switch (sym
->redirect
)
630 case SYMBOL_FORWARDED
:
631 error ("Cannot make an internal variable an alias");
632 case SYMBOL_LOCALIZED
:
633 error ("Don't know how to make a localized variable an alias");
636 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
637 If n_a is bound, but b_v is not, set the value of b_v to n_a,
638 so that old-code that affects n_a before the aliasing is setup
640 if (NILP (Fboundp (base_variable
)))
641 set_internal (base_variable
, find_symbol_value (new_alias
), Qnil
, 1);
644 union specbinding
*p
;
646 for (p
= specpdl_ptr
; p
> specpdl
; )
647 if ((--p
)->kind
>= SPECPDL_LET
648 && (EQ (new_alias
, specpdl_symbol (p
))))
649 error ("Don't know how to make a let-bound variable an alias");
652 sym
->declared_special
= 1;
653 XSYMBOL (base_variable
)->declared_special
= 1;
654 sym
->redirect
= SYMBOL_VARALIAS
;
655 SET_SYMBOL_ALIAS (sym
, XSYMBOL (base_variable
));
656 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
657 LOADHIST_ATTACH (new_alias
);
658 /* Even if docstring is nil: remove old docstring. */
659 Fput (new_alias
, Qvariable_documentation
, docstring
);
661 return base_variable
;
664 static union specbinding
*
665 default_toplevel_binding (Lisp_Object symbol
)
667 union specbinding
*binding
= NULL
;
668 union specbinding
*pdl
= specpdl_ptr
;
669 while (pdl
> specpdl
)
671 switch ((--pdl
)->kind
)
673 case SPECPDL_LET_DEFAULT
:
675 if (EQ (specpdl_symbol (pdl
), symbol
))
683 DEFUN ("default-toplevel-value", Fdefault_toplevel_value
, Sdefault_toplevel_value
, 1, 1, 0,
684 doc
: /* Return SYMBOL's toplevel default value.
685 "Toplevel" means outside of any let binding. */)
688 union specbinding
*binding
= default_toplevel_binding (symbol
);
690 = binding
? specpdl_old_value (binding
) : Fdefault_value (symbol
);
691 if (!EQ (value
, Qunbound
))
693 xsignal1 (Qvoid_variable
, symbol
);
696 DEFUN ("set-default-toplevel-value", Fset_default_toplevel_value
,
697 Sset_default_toplevel_value
, 2, 2, 0,
698 doc
: /* Set SYMBOL's toplevel default value to VALUE.
699 "Toplevel" means outside of any let binding. */)
700 (Lisp_Object symbol
, Lisp_Object value
)
702 union specbinding
*binding
= default_toplevel_binding (symbol
);
704 set_specpdl_old_value (binding
, value
);
706 Fset_default (symbol
, value
);
710 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
711 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
712 You are not required to define a variable in order to use it, but
713 defining it lets you supply an initial value and documentation, which
714 can be referred to by the Emacs help facilities and other programming
715 tools. The `defvar' form also declares the variable as \"special\",
716 so that it is always dynamically bound even if `lexical-binding' is t.
718 The optional argument INITVALUE is evaluated, and used to set SYMBOL,
719 only if SYMBOL's value is void. If SYMBOL is buffer-local, its
720 default value is what is set; buffer-local values are not affected.
721 If INITVALUE is missing, SYMBOL's value is not set.
723 If SYMBOL has a local binding, then this form affects the local
724 binding. This is usually not what you want. Thus, if you need to
725 load a file defining variables, with this form or with `defconst' or
726 `defcustom', you should always load that file _outside_ any bindings
727 for these variables. \(`defconst' and `defcustom' behave similarly in
730 The optional argument DOCSTRING is a documentation string for the
733 To define a user option, use `defcustom' instead of `defvar'.
734 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
737 Lisp_Object sym
, tem
, tail
;
744 if (CONSP (XCDR (tail
)) && CONSP (XCDR (XCDR (tail
))))
745 error ("Too many arguments");
747 tem
= Fdefault_boundp (sym
);
749 /* Do it before evaluating the initial value, for self-references. */
750 XSYMBOL (sym
)->declared_special
= 1;
753 Fset_default (sym
, eval_sub (XCAR (tail
)));
755 { /* Check if there is really a global binding rather than just a let
756 binding that shadows the global unboundness of the var. */
757 union specbinding
*binding
= default_toplevel_binding (sym
);
758 if (binding
&& EQ (specpdl_old_value (binding
), Qunbound
))
760 set_specpdl_old_value (binding
, eval_sub (XCAR (tail
)));
767 if (!NILP (Vpurify_flag
))
768 tem
= Fpurecopy (tem
);
769 Fput (sym
, Qvariable_documentation
, tem
);
771 LOADHIST_ATTACH (sym
);
773 else if (!NILP (Vinternal_interpreter_environment
)
774 && !XSYMBOL (sym
)->declared_special
)
775 /* A simple (defvar foo) with lexical scoping does "nothing" except
776 declare that var to be dynamically scoped *locally* (i.e. within
777 the current file or let-block). */
778 Vinternal_interpreter_environment
779 = Fcons (sym
, Vinternal_interpreter_environment
);
782 /* Simple (defvar <var>) should not count as a definition at all.
783 It could get in the way of other definitions, and unloading this
784 package could try to make the variable unbound. */
790 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
791 doc
: /* Define SYMBOL as a constant variable.
792 This declares that neither programs nor users should ever change the
793 value. This constancy is not actually enforced by Emacs Lisp, but
794 SYMBOL is marked as a special variable so that it is never lexically
797 The `defconst' form always sets the value of SYMBOL to the result of
798 evalling INITVALUE. If SYMBOL is buffer-local, its default value is
799 what is set; buffer-local values are not affected. If SYMBOL has a
800 local binding, then this form sets the local binding's value.
801 However, you should normally not make local bindings for variables
802 defined with this form.
804 The optional DOCSTRING specifies the variable's documentation string.
805 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
808 Lisp_Object sym
, tem
;
811 if (CONSP (Fcdr (XCDR (XCDR (args
)))))
812 error ("Too many arguments");
814 tem
= eval_sub (Fcar (XCDR (args
)));
815 if (!NILP (Vpurify_flag
))
816 tem
= Fpurecopy (tem
);
817 Fset_default (sym
, tem
);
818 XSYMBOL (sym
)->declared_special
= 1;
819 tem
= Fcar (XCDR (XCDR (args
)));
822 if (!NILP (Vpurify_flag
))
823 tem
= Fpurecopy (tem
);
824 Fput (sym
, Qvariable_documentation
, tem
);
826 Fput (sym
, Qrisky_local_variable
, Qt
);
827 LOADHIST_ATTACH (sym
);
831 /* Make SYMBOL lexically scoped. */
832 DEFUN ("internal-make-var-non-special", Fmake_var_non_special
,
833 Smake_var_non_special
, 1, 1, 0,
834 doc
: /* Internal function. */)
837 CHECK_SYMBOL (symbol
);
838 XSYMBOL (symbol
)->declared_special
= 0;
843 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
844 doc
: /* Bind variables according to VARLIST then eval BODY.
845 The value of the last form in BODY is returned.
846 Each element of VARLIST is a symbol (which is bound to nil)
847 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
848 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
849 usage: (let* VARLIST BODY...) */)
852 Lisp_Object varlist
, var
, val
, elt
, lexenv
;
853 ptrdiff_t count
= SPECPDL_INDEX ();
854 struct gcpro gcpro1
, gcpro2
, gcpro3
;
856 GCPRO3 (args
, elt
, varlist
);
858 lexenv
= Vinternal_interpreter_environment
;
860 varlist
= XCAR (args
);
861 while (CONSP (varlist
))
865 elt
= XCAR (varlist
);
871 else if (! NILP (Fcdr (Fcdr (elt
))))
872 signal_error ("`let' bindings can have only one value-form", elt
);
876 val
= eval_sub (Fcar (Fcdr (elt
)));
879 if (!NILP (lexenv
) && SYMBOLP (var
)
880 && !XSYMBOL (var
)->declared_special
881 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
882 /* Lexically bind VAR by adding it to the interpreter's binding
886 = Fcons (Fcons (var
, val
), Vinternal_interpreter_environment
);
887 if (EQ (Vinternal_interpreter_environment
, lexenv
))
888 /* Save the old lexical environment on the specpdl stack,
889 but only for the first lexical binding, since we'll never
890 need to revert to one of the intermediate ones. */
891 specbind (Qinternal_interpreter_environment
, newenv
);
893 Vinternal_interpreter_environment
= newenv
;
898 varlist
= XCDR (varlist
);
901 val
= Fprogn (XCDR (args
));
902 return unbind_to (count
, val
);
905 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
906 doc
: /* Bind variables according to VARLIST then eval BODY.
907 The value of the last form in BODY is returned.
908 Each element of VARLIST is a symbol (which is bound to nil)
909 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
910 All the VALUEFORMs are evalled before any symbols are bound.
911 usage: (let VARLIST BODY...) */)
914 Lisp_Object
*temps
, tem
, lexenv
;
915 register Lisp_Object elt
, varlist
;
916 ptrdiff_t count
= SPECPDL_INDEX ();
918 struct gcpro gcpro1
, gcpro2
;
921 varlist
= XCAR (args
);
923 /* Make space to hold the values to give the bound variables. */
924 elt
= Flength (varlist
);
925 SAFE_ALLOCA_LISP (temps
, XFASTINT (elt
));
927 /* Compute the values and store them in `temps'. */
929 GCPRO2 (args
, *temps
);
932 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
935 elt
= XCAR (varlist
);
937 temps
[argnum
++] = Qnil
;
938 else if (! NILP (Fcdr (Fcdr (elt
))))
939 signal_error ("`let' bindings can have only one value-form", elt
);
941 temps
[argnum
++] = eval_sub (Fcar (Fcdr (elt
)));
942 gcpro2
.nvars
= argnum
;
946 lexenv
= Vinternal_interpreter_environment
;
948 varlist
= XCAR (args
);
949 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
953 elt
= XCAR (varlist
);
954 var
= SYMBOLP (elt
) ? elt
: Fcar (elt
);
955 tem
= temps
[argnum
++];
957 if (!NILP (lexenv
) && SYMBOLP (var
)
958 && !XSYMBOL (var
)->declared_special
959 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
960 /* Lexically bind VAR by adding it to the lexenv alist. */
961 lexenv
= Fcons (Fcons (var
, tem
), lexenv
);
963 /* Dynamically bind VAR. */
967 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
968 /* Instantiate a new lexical environment. */
969 specbind (Qinternal_interpreter_environment
, lexenv
);
971 elt
= Fprogn (XCDR (args
));
973 return unbind_to (count
, elt
);
976 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
977 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
978 The order of execution is thus TEST, BODY, TEST, BODY and so on
979 until TEST returns nil.
980 usage: (while TEST BODY...) */)
983 Lisp_Object test
, body
;
984 struct gcpro gcpro1
, gcpro2
;
990 while (!NILP (eval_sub (test
)))
1000 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
1001 doc
: /* Return result of expanding macros at top level of FORM.
1002 If FORM is not a macro call, it is returned unchanged.
1003 Otherwise, the macro is expanded and the expansion is considered
1004 in place of FORM. When a non-macro-call results, it is returned.
1006 The second optional arg ENVIRONMENT specifies an environment of macro
1007 definitions to shadow the loaded ones for use in file byte-compilation. */)
1008 (Lisp_Object form
, Lisp_Object environment
)
1010 /* With cleanups from Hallvard Furuseth. */
1011 register Lisp_Object expander
, sym
, def
, tem
;
1015 /* Come back here each time we expand a macro call,
1016 in case it expands into another macro call. */
1019 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1020 def
= sym
= XCAR (form
);
1022 /* Trace symbols aliases to other symbols
1023 until we get a symbol that is not an alias. */
1024 while (SYMBOLP (def
))
1028 tem
= Fassq (sym
, environment
);
1031 def
= XSYMBOL (sym
)->function
;
1037 /* Right now TEM is the result from SYM in ENVIRONMENT,
1038 and if TEM is nil then DEF is SYM's function definition. */
1041 /* SYM is not mentioned in ENVIRONMENT.
1042 Look at its function definition. */
1043 struct gcpro gcpro1
;
1045 def
= Fautoload_do_load (def
, sym
, Qmacro
);
1048 /* Not defined or definition not suitable. */
1050 if (!EQ (XCAR (def
), Qmacro
))
1052 else expander
= XCDR (def
);
1056 expander
= XCDR (tem
);
1057 if (NILP (expander
))
1061 Lisp_Object newform
= apply1 (expander
, XCDR (form
));
1062 if (EQ (form
, newform
))
1071 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1072 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1073 TAG is evalled to get the tag to use; it must not be nil.
1075 Then the BODY is executed.
1076 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1077 If no throw happens, `catch' returns the value of the last BODY form.
1078 If a throw happens, it specifies the value to return from `catch'.
1079 usage: (catch TAG BODY...) */)
1082 register Lisp_Object tag
;
1083 struct gcpro gcpro1
;
1086 tag
= eval_sub (XCAR (args
));
1088 return internal_catch (tag
, Fprogn
, XCDR (args
));
1091 /* Assert that E is true, as a comment only. Use this instead of
1092 eassert (E) when E contains variables that might be clobbered by a
1095 #define clobbered_eassert(E) ((void) 0)
1097 /* Set up a catch, then call C function FUNC on argument ARG.
1098 FUNC should return a Lisp_Object.
1099 This is how catches are done from within C code. */
1102 internal_catch (Lisp_Object tag
, Lisp_Object (*func
) (Lisp_Object
), Lisp_Object arg
)
1104 /* This structure is made part of the chain `catchlist'. */
1107 /* Fill in the components of c, and put it on the list. */
1108 PUSH_HANDLER (c
, tag
, CATCHER
);
1111 if (! sys_setjmp (c
->jmp
))
1113 Lisp_Object val
= (*func
) (arg
);
1114 clobbered_eassert (handlerlist
== c
);
1115 handlerlist
= handlerlist
->next
;
1119 { /* Throw works by a longjmp that comes right here. */
1120 Lisp_Object val
= handlerlist
->val
;
1121 clobbered_eassert (handlerlist
== c
);
1122 handlerlist
= handlerlist
->next
;
1127 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1128 jump to that CATCH, returning VALUE as the value of that catch.
1130 This is the guts of Fthrow and Fsignal; they differ only in the way
1131 they choose the catch tag to throw to. A catch tag for a
1132 condition-case form has a TAG of Qnil.
1134 Before each catch is discarded, unbind all special bindings and
1135 execute all unwind-protect clauses made above that catch. Unwind
1136 the handler stack as we go, so that the proper handlers are in
1137 effect for each unwind-protect clause we run. At the end, restore
1138 some static info saved in CATCH, and longjmp to the location
1141 This is used for correct unwinding in Fthrow and Fsignal. */
1143 static _Noreturn
void
1144 unwind_to_catch (struct handler
*catch, Lisp_Object value
)
1148 eassert (catch->next
);
1150 /* Save the value in the tag. */
1153 /* Restore certain special C variables. */
1154 set_poll_suppress_count (catch->poll_suppress_count
);
1155 unblock_input_to (catch->interrupt_input_blocked
);
1160 /* Unwind the specpdl stack, and then restore the proper set of
1162 unbind_to (handlerlist
->pdlcount
, Qnil
);
1163 last_time
= handlerlist
== catch;
1165 handlerlist
= handlerlist
->next
;
1167 while (! last_time
);
1169 eassert (handlerlist
== catch);
1171 gcprolist
= catch->gcpro
;
1173 gcpro_level
= gcprolist
? gcprolist
->level
+ 1 : 0;
1175 lisp_eval_depth
= catch->lisp_eval_depth
;
1177 sys_longjmp (catch->jmp
, 1);
1180 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1181 doc
: /* Throw to the catch for TAG and return VALUE from it.
1182 Both TAG and VALUE are evalled. */)
1183 (register Lisp_Object tag
, Lisp_Object value
)
1188 for (c
= handlerlist
; c
; c
= c
->next
)
1190 if (c
->type
== CATCHER
&& EQ (c
->tag_or_ch
, tag
))
1191 unwind_to_catch (c
, value
);
1193 xsignal2 (Qno_catch
, tag
, value
);
1197 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1198 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1199 If BODYFORM completes normally, its value is returned
1200 after executing the UNWINDFORMS.
1201 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1202 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1206 ptrdiff_t count
= SPECPDL_INDEX ();
1208 record_unwind_protect (unwind_body
, XCDR (args
));
1209 val
= eval_sub (XCAR (args
));
1210 return unbind_to (count
, val
);
1213 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1214 doc
: /* Regain control when an error is signaled.
1215 Executes BODYFORM and returns its value if no error happens.
1216 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1217 where the BODY is made of Lisp expressions.
1219 A handler is applicable to an error
1220 if CONDITION-NAME is one of the error's condition names.
1221 If an error happens, the first applicable handler is run.
1223 The car of a handler may be a list of condition names instead of a
1224 single condition name; then it handles all of them. If the special
1225 condition name `debug' is present in this list, it allows another
1226 condition in the list to run the debugger if `debug-on-error' and the
1227 other usual mechanisms says it should (otherwise, `condition-case'
1228 suppresses the debugger).
1230 When a handler handles an error, control returns to the `condition-case'
1231 and it executes the handler's BODY...
1232 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1233 \(If VAR is nil, the handler can't access that information.)
1234 Then the value of the last BODY form is returned from the `condition-case'
1237 See also the function `signal' for more info.
1238 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1241 Lisp_Object var
= XCAR (args
);
1242 Lisp_Object bodyform
= XCAR (XCDR (args
));
1243 Lisp_Object handlers
= XCDR (XCDR (args
));
1245 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1248 /* Like Fcondition_case, but the args are separate
1249 rather than passed in a list. Used by Fbyte_code. */
1252 internal_lisp_condition_case (volatile Lisp_Object var
, Lisp_Object bodyform
,
1253 Lisp_Object handlers
)
1257 struct handler
*oldhandlerlist
= handlerlist
;
1262 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1264 Lisp_Object tem
= XCAR (val
);
1268 && (SYMBOLP (XCAR (tem
))
1269 || CONSP (XCAR (tem
))))))
1270 error ("Invalid condition handler: %s",
1271 SDATA (Fprin1_to_string (tem
, Qt
)));
1274 { /* The first clause is the one that should be checked first, so it should
1275 be added to handlerlist last. So we build in `clauses' a table that
1276 contains `handlers' but in reverse order. */
1277 Lisp_Object
*clauses
= alloca (clausenb
* sizeof (Lisp_Object
*));
1278 Lisp_Object
*volatile clauses_volatile
= clauses
;
1280 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1281 clauses
[--i
] = XCAR (val
);
1282 for (i
= 0; i
< clausenb
; i
++)
1284 Lisp_Object clause
= clauses
[i
];
1285 Lisp_Object condition
= XCAR (clause
);
1286 if (!CONSP (condition
))
1287 condition
= Fcons (condition
, Qnil
);
1288 PUSH_HANDLER (c
, condition
, CONDITION_CASE
);
1289 if (sys_setjmp (c
->jmp
))
1291 ptrdiff_t count
= SPECPDL_INDEX ();
1292 Lisp_Object val
= handlerlist
->val
;
1293 Lisp_Object
*chosen_clause
= clauses_volatile
;
1294 for (c
= handlerlist
->next
; c
!= oldhandlerlist
; c
= c
->next
)
1296 handlerlist
= oldhandlerlist
;
1299 if (!NILP (Vinternal_interpreter_environment
))
1300 specbind (Qinternal_interpreter_environment
,
1301 Fcons (Fcons (var
, val
),
1302 Vinternal_interpreter_environment
));
1304 specbind (var
, val
);
1306 val
= Fprogn (XCDR (*chosen_clause
));
1307 /* Note that this just undoes the binding of var; whoever
1308 longjumped to us unwound the stack to c.pdlcount before
1311 unbind_to (count
, Qnil
);
1317 val
= eval_sub (bodyform
);
1318 handlerlist
= oldhandlerlist
;
1322 /* Call the function BFUN with no arguments, catching errors within it
1323 according to HANDLERS. If there is an error, call HFUN with
1324 one argument which is the data that describes the error:
1327 HANDLERS can be a list of conditions to catch.
1328 If HANDLERS is Qt, catch all errors.
1329 If HANDLERS is Qerror, catch all errors
1330 but allow the debugger to run if that is enabled. */
1333 internal_condition_case (Lisp_Object (*bfun
) (void), Lisp_Object handlers
,
1334 Lisp_Object (*hfun
) (Lisp_Object
))
1339 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1340 if (sys_setjmp (c
->jmp
))
1342 Lisp_Object val
= handlerlist
->val
;
1343 clobbered_eassert (handlerlist
== c
);
1344 handlerlist
= handlerlist
->next
;
1345 return (*hfun
) (val
);
1349 clobbered_eassert (handlerlist
== c
);
1350 handlerlist
= handlerlist
->next
;
1354 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1357 internal_condition_case_1 (Lisp_Object (*bfun
) (Lisp_Object
), Lisp_Object arg
,
1358 Lisp_Object handlers
, Lisp_Object (*hfun
) (Lisp_Object
))
1363 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1364 if (sys_setjmp (c
->jmp
))
1366 Lisp_Object val
= handlerlist
->val
;
1367 clobbered_eassert (handlerlist
== c
);
1368 handlerlist
= handlerlist
->next
;
1369 return (*hfun
) (val
);
1372 val
= (*bfun
) (arg
);
1373 clobbered_eassert (handlerlist
== c
);
1374 handlerlist
= handlerlist
->next
;
1378 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1382 internal_condition_case_2 (Lisp_Object (*bfun
) (Lisp_Object
, Lisp_Object
),
1385 Lisp_Object handlers
,
1386 Lisp_Object (*hfun
) (Lisp_Object
))
1391 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1392 if (sys_setjmp (c
->jmp
))
1394 Lisp_Object val
= handlerlist
->val
;
1395 clobbered_eassert (handlerlist
== c
);
1396 handlerlist
= handlerlist
->next
;
1397 return (*hfun
) (val
);
1400 val
= (*bfun
) (arg1
, arg2
);
1401 clobbered_eassert (handlerlist
== c
);
1402 handlerlist
= handlerlist
->next
;
1406 /* Like internal_condition_case but call BFUN with NARGS as first,
1407 and ARGS as second argument. */
1410 internal_condition_case_n (Lisp_Object (*bfun
) (ptrdiff_t, Lisp_Object
*),
1413 Lisp_Object handlers
,
1414 Lisp_Object (*hfun
) (Lisp_Object err
,
1421 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1422 if (sys_setjmp (c
->jmp
))
1424 Lisp_Object val
= handlerlist
->val
;
1425 clobbered_eassert (handlerlist
== c
);
1426 handlerlist
= handlerlist
->next
;
1427 return (*hfun
) (val
, nargs
, args
);
1430 val
= (*bfun
) (nargs
, args
);
1431 clobbered_eassert (handlerlist
== c
);
1432 handlerlist
= handlerlist
->next
;
1437 static Lisp_Object
find_handler_clause (Lisp_Object
, Lisp_Object
);
1438 static bool maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
,
1442 process_quit_flag (void)
1444 Lisp_Object flag
= Vquit_flag
;
1446 if (EQ (flag
, Qkill_emacs
))
1448 if (EQ (Vthrow_on_input
, flag
))
1449 Fthrow (Vthrow_on_input
, Qt
);
1450 Fsignal (Qquit
, Qnil
);
1453 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1454 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1455 This function does not return.
1457 An error symbol is a symbol with an `error-conditions' property
1458 that is a list of condition names.
1459 A handler for any of those names will get to handle this signal.
1460 The symbol `error' should normally be one of them.
1462 DATA should be a list. Its elements are printed as part of the error message.
1463 See Info anchor `(elisp)Definition of signal' for some details on how this
1464 error message is constructed.
1465 If the signal is handled, DATA is made available to the handler.
1466 See also the function `condition-case'. */)
1467 (Lisp_Object error_symbol
, Lisp_Object data
)
1469 /* When memory is full, ERROR-SYMBOL is nil,
1470 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1471 That is a special case--don't do this in other situations. */
1472 Lisp_Object conditions
;
1474 Lisp_Object real_error_symbol
1475 = (NILP (error_symbol
) ? Fcar (data
) : error_symbol
);
1476 register Lisp_Object clause
= Qnil
;
1480 if (waiting_for_input
)
1483 #if 0 /* rms: I don't know why this was here,
1484 but it is surely wrong for an error that is handled. */
1485 #ifdef HAVE_WINDOW_SYSTEM
1486 if (display_hourglass_p
)
1487 cancel_hourglass ();
1491 /* This hook is used by edebug. */
1492 if (! NILP (Vsignal_hook_function
)
1493 && ! NILP (error_symbol
))
1495 /* Edebug takes care of restoring these variables when it exits. */
1496 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1497 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1499 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1500 max_specpdl_size
= SPECPDL_INDEX () + 40;
1502 call2 (Vsignal_hook_function
, error_symbol
, data
);
1505 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1507 /* Remember from where signal was called. Skip over the frame for
1508 `signal' itself. If a frame for `error' follows, skip that,
1509 too. Don't do this when ERROR_SYMBOL is nil, because that
1510 is a memory-full error. */
1511 Vsignaling_function
= Qnil
;
1512 if (!NILP (error_symbol
))
1514 union specbinding
*pdl
= backtrace_next (backtrace_top ());
1515 if (backtrace_p (pdl
) && EQ (backtrace_function (pdl
), Qerror
))
1516 pdl
= backtrace_next (pdl
);
1517 if (backtrace_p (pdl
))
1518 Vsignaling_function
= backtrace_function (pdl
);
1521 for (h
= handlerlist
; h
; h
= h
->next
)
1523 if (h
->type
!= CONDITION_CASE
)
1525 clause
= find_handler_clause (h
->tag_or_ch
, conditions
);
1530 if (/* Don't run the debugger for a memory-full error.
1531 (There is no room in memory to do that!) */
1532 !NILP (error_symbol
)
1533 && (!NILP (Vdebug_on_signal
)
1534 /* If no handler is present now, try to run the debugger. */
1536 /* A `debug' symbol in the handler list disables the normal
1537 suppression of the debugger. */
1538 || (CONSP (clause
) && CONSP (clause
)
1539 && !NILP (Fmemq (Qdebug
, clause
)))
1540 /* Special handler that means "print a message and run debugger
1542 || EQ (h
->tag_or_ch
, Qerror
)))
1544 bool debugger_called
1545 = maybe_call_debugger (conditions
, error_symbol
, data
);
1546 /* We can't return values to code which signaled an error, but we
1547 can continue code which has signaled a quit. */
1548 if (debugger_called
&& EQ (real_error_symbol
, Qquit
))
1554 Lisp_Object unwind_data
1555 = (NILP (error_symbol
) ? data
: Fcons (error_symbol
, data
));
1557 unwind_to_catch (h
, unwind_data
);
1561 if (handlerlist
!= &handlerlist_sentinel
)
1562 /* FIXME: This will come right back here if there's no `top-level'
1563 catcher. A better solution would be to abort here, and instead
1564 add a catch-all condition handler so we never come here. */
1565 Fthrow (Qtop_level
, Qt
);
1568 if (! NILP (error_symbol
))
1569 data
= Fcons (error_symbol
, data
);
1571 string
= Ferror_message_string (data
);
1572 fatal ("%s", SDATA (string
));
1575 /* Internal version of Fsignal that never returns.
1576 Used for anything but Qquit (which can return from Fsignal). */
1579 xsignal (Lisp_Object error_symbol
, Lisp_Object data
)
1581 Fsignal (error_symbol
, data
);
1585 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1588 xsignal0 (Lisp_Object error_symbol
)
1590 xsignal (error_symbol
, Qnil
);
1594 xsignal1 (Lisp_Object error_symbol
, Lisp_Object arg
)
1596 xsignal (error_symbol
, list1 (arg
));
1600 xsignal2 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
)
1602 xsignal (error_symbol
, list2 (arg1
, arg2
));
1606 xsignal3 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
1608 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1611 /* Signal `error' with message S, and additional arg ARG.
1612 If ARG is not a genuine list, make it a one-element list. */
1615 signal_error (const char *s
, Lisp_Object arg
)
1617 Lisp_Object tortoise
, hare
;
1619 hare
= tortoise
= arg
;
1620 while (CONSP (hare
))
1627 tortoise
= XCDR (tortoise
);
1629 if (EQ (hare
, tortoise
))
1636 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1640 /* Return true if LIST is a non-nil atom or
1641 a list containing one of CONDITIONS. */
1644 wants_debugger (Lisp_Object list
, Lisp_Object conditions
)
1651 while (CONSP (conditions
))
1653 Lisp_Object
this, tail
;
1654 this = XCAR (conditions
);
1655 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1656 if (EQ (XCAR (tail
), this))
1658 conditions
= XCDR (conditions
);
1663 /* Return true if an error with condition-symbols CONDITIONS,
1664 and described by SIGNAL-DATA, should skip the debugger
1665 according to debugger-ignored-errors. */
1668 skip_debugger (Lisp_Object conditions
, Lisp_Object data
)
1671 bool first_string
= 1;
1672 Lisp_Object error_message
;
1674 error_message
= Qnil
;
1675 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1677 if (STRINGP (XCAR (tail
)))
1681 error_message
= Ferror_message_string (data
);
1685 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1690 Lisp_Object contail
;
1692 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1693 if (EQ (XCAR (tail
), XCAR (contail
)))
1701 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1702 SIG and DATA describe the signal. There are two ways to pass them:
1703 = SIG is the error symbol, and DATA is the rest of the data.
1704 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1705 This is for memory-full errors only. */
1707 maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
, Lisp_Object data
)
1709 Lisp_Object combined_data
;
1711 combined_data
= Fcons (sig
, data
);
1714 /* Don't try to run the debugger with interrupts blocked.
1715 The editing loop would return anyway. */
1716 ! input_blocked_p ()
1717 && NILP (Vinhibit_debugger
)
1718 /* Does user want to enter debugger for this kind of error? */
1721 : wants_debugger (Vdebug_on_error
, conditions
))
1722 && ! skip_debugger (conditions
, combined_data
)
1723 /* RMS: What's this for? */
1724 && when_entered_debugger
< num_nonmacro_input_events
)
1726 call_debugger (list2 (Qerror
, combined_data
));
1734 find_handler_clause (Lisp_Object handlers
, Lisp_Object conditions
)
1736 register Lisp_Object h
;
1738 /* t is used by handlers for all conditions, set up by C code. */
1739 if (EQ (handlers
, Qt
))
1742 /* error is used similarly, but means print an error message
1743 and run the debugger if that is enabled. */
1744 if (EQ (handlers
, Qerror
))
1747 for (h
= handlers
; CONSP (h
); h
= XCDR (h
))
1749 Lisp_Object handler
= XCAR (h
);
1750 if (!NILP (Fmemq (handler
, conditions
)))
1758 /* Dump an error message; called like vprintf. */
1760 verror (const char *m
, va_list ap
)
1763 ptrdiff_t size
= sizeof buf
;
1764 ptrdiff_t size_max
= STRING_BYTES_BOUND
+ 1;
1769 used
= evxprintf (&buffer
, &size
, buf
, size_max
, m
, ap
);
1770 string
= make_string (buffer
, used
);
1774 xsignal1 (Qerror
, string
);
1778 /* Dump an error message; called like printf. */
1782 error (const char *m
, ...)
1789 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1790 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1791 This means it contains a description for how to read arguments to give it.
1792 The value is nil for an invalid function or a symbol with no function
1795 Interactively callable functions include strings and vectors (treated
1796 as keyboard macros), lambda-expressions that contain a top-level call
1797 to `interactive', autoload definitions made by `autoload' with non-nil
1798 fourth argument, and some of the built-in functions of Lisp.
1800 Also, a symbol satisfies `commandp' if its function definition does so.
1802 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1803 then strings and vectors are not accepted. */)
1804 (Lisp_Object function
, Lisp_Object for_call_interactively
)
1806 register Lisp_Object fun
;
1807 register Lisp_Object funcar
;
1808 Lisp_Object if_prop
= Qnil
;
1812 fun
= indirect_function (fun
); /* Check cycles. */
1816 /* Check an `interactive-form' property if present, analogous to the
1817 function-documentation property. */
1819 while (SYMBOLP (fun
))
1821 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
1824 fun
= Fsymbol_function (fun
);
1827 /* Emacs primitives are interactive if their DEFUN specifies an
1828 interactive spec. */
1830 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
1832 /* Bytecode objects are interactive if they are long enough to
1833 have an element whose index is COMPILED_INTERACTIVE, which is
1834 where the interactive spec is stored. */
1835 else if (COMPILEDP (fun
))
1836 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1839 /* Strings and vectors are keyboard macros. */
1840 if (STRINGP (fun
) || VECTORP (fun
))
1841 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
1843 /* Lists may represent commands. */
1846 funcar
= XCAR (fun
);
1847 if (EQ (funcar
, Qclosure
))
1848 return (!NILP (Fassq (Qinteractive
, Fcdr (Fcdr (XCDR (fun
)))))
1850 else if (EQ (funcar
, Qlambda
))
1851 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
1852 else if (EQ (funcar
, Qautoload
))
1853 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
1858 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1859 doc
: /* Define FUNCTION to autoload from FILE.
1860 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1861 Third arg DOCSTRING is documentation for the function.
1862 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1863 Fifth arg TYPE indicates the type of the object:
1864 nil or omitted says FUNCTION is a function,
1865 `keymap' says FUNCTION is really a keymap, and
1866 `macro' or t says FUNCTION is really a macro.
1867 Third through fifth args give info about the real definition.
1868 They default to nil.
1869 If FUNCTION is already defined other than as an autoload,
1870 this does nothing and returns nil. */)
1871 (Lisp_Object function
, Lisp_Object file
, Lisp_Object docstring
, Lisp_Object interactive
, Lisp_Object type
)
1873 CHECK_SYMBOL (function
);
1874 CHECK_STRING (file
);
1876 /* If function is defined and not as an autoload, don't override. */
1877 if (!NILP (XSYMBOL (function
)->function
)
1878 && !AUTOLOADP (XSYMBOL (function
)->function
))
1881 if (!NILP (Vpurify_flag
) && EQ (docstring
, make_number (0)))
1882 /* `read1' in lread.c has found the docstring starting with "\
1883 and assumed the docstring will be provided by Snarf-documentation, so it
1884 passed us 0 instead. But that leads to accidental sharing in purecopy's
1885 hash-consing, so we use a (hopefully) unique integer instead. */
1886 docstring
= make_number (XHASH (function
));
1887 return Fdefalias (function
,
1888 list5 (Qautoload
, file
, docstring
, interactive
, type
),
1893 un_autoload (Lisp_Object oldqueue
)
1895 Lisp_Object queue
, first
, second
;
1897 /* Queue to unwind is current value of Vautoload_queue.
1898 oldqueue is the shadowed value to leave in Vautoload_queue. */
1899 queue
= Vautoload_queue
;
1900 Vautoload_queue
= oldqueue
;
1901 while (CONSP (queue
))
1903 first
= XCAR (queue
);
1904 second
= Fcdr (first
);
1905 first
= Fcar (first
);
1906 if (EQ (first
, make_number (0)))
1909 Ffset (first
, second
);
1910 queue
= XCDR (queue
);
1914 /* Load an autoloaded function.
1915 FUNNAME is the symbol which is the function's name.
1916 FUNDEF is the autoload definition (a list). */
1918 DEFUN ("autoload-do-load", Fautoload_do_load
, Sautoload_do_load
, 1, 3, 0,
1919 doc
: /* Load FUNDEF which should be an autoload.
1920 If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1921 in which case the function returns the new autoloaded function value.
1922 If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1923 it is defines a macro. */)
1924 (Lisp_Object fundef
, Lisp_Object funname
, Lisp_Object macro_only
)
1926 ptrdiff_t count
= SPECPDL_INDEX ();
1927 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1929 if (!CONSP (fundef
) || !EQ (Qautoload
, XCAR (fundef
)))
1932 if (EQ (macro_only
, Qmacro
))
1934 Lisp_Object kind
= Fnth (make_number (4), fundef
);
1935 if (! (EQ (kind
, Qt
) || EQ (kind
, Qmacro
)))
1939 /* This is to make sure that loadup.el gives a clear picture
1940 of what files are preloaded and when. */
1941 if (! NILP (Vpurify_flag
))
1942 error ("Attempt to autoload %s while preparing to dump",
1943 SDATA (SYMBOL_NAME (funname
)));
1945 CHECK_SYMBOL (funname
);
1946 GCPRO3 (funname
, fundef
, macro_only
);
1948 /* Preserve the match data. */
1949 record_unwind_save_match_data ();
1951 /* If autoloading gets an error (which includes the error of failing
1952 to define the function being called), we use Vautoload_queue
1953 to undo function definitions and `provide' calls made by
1954 the function. We do this in the specific case of autoloading
1955 because autoloading is not an explicit request "load this file",
1956 but rather a request to "call this function".
1958 The value saved here is to be restored into Vautoload_queue. */
1959 record_unwind_protect (un_autoload
, Vautoload_queue
);
1960 Vautoload_queue
= Qt
;
1961 /* If `macro_only', assume this autoload to be a "best-effort",
1962 so don't signal an error if autoloading fails. */
1963 Fload (Fcar (Fcdr (fundef
)), macro_only
, Qt
, Qnil
, Qt
);
1965 /* Once loading finishes, don't undo it. */
1966 Vautoload_queue
= Qt
;
1967 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 eassert (nargs
>= UNEVALLED
);
2039 specpdl_ptr
->bt
.kind
= SPECPDL_BACKTRACE
;
2040 specpdl_ptr
->bt
.debug_on_exit
= false;
2041 specpdl_ptr
->bt
.function
= function
;
2042 specpdl_ptr
->bt
.args
= args
;
2043 specpdl_ptr
->bt
.nargs
= nargs
;
2047 /* Eval a sub-expression of the current expression (i.e. in the same
2050 eval_sub (Lisp_Object form
)
2052 Lisp_Object fun
, val
, original_fun
, original_args
;
2054 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2058 /* Look up its binding in the lexical environment.
2059 We do not pay attention to the declared_special flag here, since we
2060 already did that when let-binding the variable. */
2061 Lisp_Object lex_binding
2062 = !NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
2063 ? Fassq (form
, Vinternal_interpreter_environment
)
2065 if (CONSP (lex_binding
))
2066 return XCDR (lex_binding
);
2068 return Fsymbol_value (form
);
2080 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2082 if (max_lisp_eval_depth
< 100)
2083 max_lisp_eval_depth
= 100;
2084 if (lisp_eval_depth
> max_lisp_eval_depth
)
2085 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2088 original_fun
= XCAR (form
);
2089 original_args
= XCDR (form
);
2091 /* This also protects them from gc. */
2092 record_in_backtrace (original_fun
, &original_args
, UNEVALLED
);
2094 if (debug_on_next_call
)
2095 do_debug_on_call (Qt
);
2097 /* At this point, only original_fun and original_args
2098 have values that will be used below. */
2101 /* Optimize for no indirection. */
2104 fun
= Ffunction (Fcons (fun
, Qnil
));
2105 else if (!NILP (fun
) && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2106 fun
= indirect_function (fun
);
2110 Lisp_Object numargs
;
2111 Lisp_Object argvals
[8];
2112 Lisp_Object args_left
;
2113 register int i
, maxargs
;
2115 args_left
= original_args
;
2116 numargs
= Flength (args_left
);
2118 if (XINT (numargs
) < XSUBR (fun
)->min_args
2119 || (XSUBR (fun
)->max_args
>= 0
2120 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2121 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2123 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2124 val
= (XSUBR (fun
)->function
.aUNEVALLED
) (args_left
);
2125 else if (XSUBR (fun
)->max_args
== MANY
)
2127 /* Pass a vector of evaluated arguments. */
2129 ptrdiff_t argnum
= 0;
2132 SAFE_ALLOCA_LISP (vals
, XINT (numargs
));
2134 GCPRO3 (args_left
, fun
, fun
);
2138 while (!NILP (args_left
))
2140 vals
[argnum
++] = eval_sub (Fcar (args_left
));
2141 args_left
= Fcdr (args_left
);
2142 gcpro3
.nvars
= argnum
;
2145 set_backtrace_args (specpdl_ptr
- 1, vals
);
2146 set_backtrace_nargs (specpdl_ptr
- 1, XINT (numargs
));
2148 val
= (XSUBR (fun
)->function
.aMANY
) (XINT (numargs
), vals
);
2154 GCPRO3 (args_left
, fun
, fun
);
2155 gcpro3
.var
= argvals
;
2158 maxargs
= XSUBR (fun
)->max_args
;
2159 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2161 argvals
[i
] = eval_sub (Fcar (args_left
));
2167 set_backtrace_args (specpdl_ptr
- 1, argvals
);
2168 set_backtrace_nargs (specpdl_ptr
- 1, XINT (numargs
));
2173 val
= (XSUBR (fun
)->function
.a0 ());
2176 val
= (XSUBR (fun
)->function
.a1 (argvals
[0]));
2179 val
= (XSUBR (fun
)->function
.a2 (argvals
[0], argvals
[1]));
2182 val
= (XSUBR (fun
)->function
.a3
2183 (argvals
[0], argvals
[1], argvals
[2]));
2186 val
= (XSUBR (fun
)->function
.a4
2187 (argvals
[0], argvals
[1], argvals
[2], argvals
[3]));
2190 val
= (XSUBR (fun
)->function
.a5
2191 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2195 val
= (XSUBR (fun
)->function
.a6
2196 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2197 argvals
[4], argvals
[5]));
2200 val
= (XSUBR (fun
)->function
.a7
2201 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2202 argvals
[4], argvals
[5], argvals
[6]));
2206 val
= (XSUBR (fun
)->function
.a8
2207 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2208 argvals
[4], argvals
[5], argvals
[6], argvals
[7]));
2212 /* Someone has created a subr that takes more arguments than
2213 is supported by this code. We need to either rewrite the
2214 subr to use a different argument protocol, or add more
2215 cases to this switch. */
2220 else if (COMPILEDP (fun
))
2221 val
= apply_lambda (fun
, original_args
);
2225 xsignal1 (Qvoid_function
, original_fun
);
2227 xsignal1 (Qinvalid_function
, original_fun
);
2228 funcar
= XCAR (fun
);
2229 if (!SYMBOLP (funcar
))
2230 xsignal1 (Qinvalid_function
, original_fun
);
2231 if (EQ (funcar
, Qautoload
))
2233 Fautoload_do_load (fun
, original_fun
, Qnil
);
2236 if (EQ (funcar
, Qmacro
))
2238 ptrdiff_t count
= SPECPDL_INDEX ();
2240 /* Bind lexical-binding during expansion of the macro, so the
2241 macro can know reliably if the code it outputs will be
2242 interpreted using lexical-binding or not. */
2243 specbind (Qlexical_binding
,
2244 NILP (Vinternal_interpreter_environment
) ? Qnil
: Qt
);
2245 exp
= apply1 (Fcdr (fun
), original_args
);
2246 unbind_to (count
, Qnil
);
2247 val
= eval_sub (exp
);
2249 else if (EQ (funcar
, Qlambda
)
2250 || EQ (funcar
, Qclosure
))
2251 val
= apply_lambda (fun
, original_args
);
2253 xsignal1 (Qinvalid_function
, original_fun
);
2257 if (backtrace_debug_on_exit (specpdl_ptr
- 1))
2258 val
= call_debugger (list2 (Qexit
, val
));
2264 DEFUN ("apply", Fapply
, Sapply
, 1, MANY
, 0,
2265 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2266 Then return the value FUNCTION returns.
2267 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2268 usage: (apply FUNCTION &rest ARGUMENTS) */)
2269 (ptrdiff_t nargs
, Lisp_Object
*args
)
2273 register Lisp_Object spread_arg
;
2274 register Lisp_Object
*funcall_args
;
2275 Lisp_Object fun
, retval
;
2276 struct gcpro gcpro1
;
2281 spread_arg
= args
[nargs
- 1];
2282 CHECK_LIST (spread_arg
);
2284 numargs
= XINT (Flength (spread_arg
));
2287 return Ffuncall (nargs
- 1, args
);
2288 else if (numargs
== 1)
2290 args
[nargs
- 1] = XCAR (spread_arg
);
2291 return Ffuncall (nargs
, args
);
2294 numargs
+= nargs
- 2;
2296 /* Optimize for no indirection. */
2297 if (SYMBOLP (fun
) && !NILP (fun
)
2298 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2299 fun
= indirect_function (fun
);
2302 /* Let funcall get the error. */
2309 if (numargs
< XSUBR (fun
)->min_args
2310 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2311 goto funcall
; /* Let funcall get the error. */
2312 else if (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
> numargs
)
2314 /* Avoid making funcall cons up a yet another new vector of arguments
2315 by explicitly supplying nil's for optional values. */
2316 SAFE_ALLOCA_LISP (funcall_args
, 1 + XSUBR (fun
)->max_args
);
2317 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2318 funcall_args
[++i
] = Qnil
;
2319 GCPRO1 (*funcall_args
);
2320 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2324 /* We add 1 to numargs because funcall_args includes the
2325 function itself as well as its arguments. */
2328 SAFE_ALLOCA_LISP (funcall_args
, 1 + numargs
);
2329 GCPRO1 (*funcall_args
);
2330 gcpro1
.nvars
= 1 + numargs
;
2333 memcpy (funcall_args
, args
, nargs
* word_size
);
2334 /* Spread the last arg we got. Its first element goes in
2335 the slot that it used to occupy, hence this value of I. */
2337 while (!NILP (spread_arg
))
2339 funcall_args
[i
++] = XCAR (spread_arg
);
2340 spread_arg
= XCDR (spread_arg
);
2343 /* By convention, the caller needs to gcpro Ffuncall's args. */
2344 retval
= Ffuncall (gcpro1
.nvars
, funcall_args
);
2351 /* Run hook variables in various ways. */
2354 funcall_nil (ptrdiff_t nargs
, Lisp_Object
*args
)
2356 Ffuncall (nargs
, args
);
2360 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2361 doc
: /* Run each hook in HOOKS.
2362 Each argument should be a symbol, a hook variable.
2363 These symbols are processed in the order specified.
2364 If a hook symbol has a non-nil value, that value may be a function
2365 or a list of functions to be called to run the hook.
2366 If the value is a function, it is called with no arguments.
2367 If it is a list, the elements are called, in order, with no arguments.
2369 Major modes should not use this function directly to run their mode
2370 hook; they should use `run-mode-hooks' instead.
2372 Do not use `make-local-variable' to make a hook variable buffer-local.
2373 Instead, use `add-hook' and specify t for the LOCAL argument.
2374 usage: (run-hooks &rest HOOKS) */)
2375 (ptrdiff_t nargs
, Lisp_Object
*args
)
2377 Lisp_Object hook
[1];
2380 for (i
= 0; i
< nargs
; i
++)
2383 run_hook_with_args (1, hook
, funcall_nil
);
2389 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2390 Srun_hook_with_args
, 1, MANY
, 0,
2391 doc
: /* Run HOOK with the specified arguments ARGS.
2392 HOOK should be a symbol, a hook variable. The value of HOOK
2393 may be nil, a function, or a list of functions. Call each
2394 function in order with arguments ARGS. The final return value
2397 Do not use `make-local-variable' to make a hook variable buffer-local.
2398 Instead, use `add-hook' and specify t for the LOCAL argument.
2399 usage: (run-hook-with-args HOOK &rest ARGS) */)
2400 (ptrdiff_t nargs
, Lisp_Object
*args
)
2402 return run_hook_with_args (nargs
, args
, funcall_nil
);
2405 /* NB this one still documents a specific non-nil return value.
2406 (As did run-hook-with-args and run-hook-with-args-until-failure
2407 until they were changed in 24.1.) */
2408 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2409 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2410 doc
: /* Run HOOK with the specified arguments ARGS.
2411 HOOK should be a symbol, a hook variable. The value of HOOK
2412 may be nil, a function, or a list of functions. Call each
2413 function in order with arguments ARGS, stopping at the first
2414 one that returns non-nil, and return that value. Otherwise (if
2415 all functions return nil, or if there are no functions to call),
2418 Do not use `make-local-variable' to make a hook variable buffer-local.
2419 Instead, use `add-hook' and specify t for the LOCAL argument.
2420 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2421 (ptrdiff_t nargs
, Lisp_Object
*args
)
2423 return run_hook_with_args (nargs
, args
, Ffuncall
);
2427 funcall_not (ptrdiff_t nargs
, Lisp_Object
*args
)
2429 return NILP (Ffuncall (nargs
, args
)) ? Qt
: Qnil
;
2432 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2433 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2434 doc
: /* Run HOOK with the specified arguments ARGS.
2435 HOOK should be a symbol, a hook variable. The value of HOOK
2436 may be nil, a function, or a list of functions. Call each
2437 function in order with arguments ARGS, stopping at the first
2438 one that returns nil, and return nil. Otherwise (if all functions
2439 return non-nil, or if there are no functions to call), return non-nil
2440 \(do not rely on the precise return value in this case).
2442 Do not use `make-local-variable' to make a hook variable buffer-local.
2443 Instead, use `add-hook' and specify t for the LOCAL argument.
2444 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2445 (ptrdiff_t nargs
, Lisp_Object
*args
)
2447 return NILP (run_hook_with_args (nargs
, args
, funcall_not
)) ? Qt
: Qnil
;
2451 run_hook_wrapped_funcall (ptrdiff_t nargs
, Lisp_Object
*args
)
2453 Lisp_Object tmp
= args
[0], ret
;
2456 ret
= Ffuncall (nargs
, args
);
2462 DEFUN ("run-hook-wrapped", Frun_hook_wrapped
, Srun_hook_wrapped
, 2, MANY
, 0,
2463 doc
: /* Run HOOK, passing each function through WRAP-FUNCTION.
2464 I.e. instead of calling each function FUN directly with arguments ARGS,
2465 it calls WRAP-FUNCTION with arguments FUN and ARGS.
2466 As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2467 aborts and returns that value.
2468 usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2469 (ptrdiff_t nargs
, Lisp_Object
*args
)
2471 return run_hook_with_args (nargs
, args
, run_hook_wrapped_funcall
);
2474 /* ARGS[0] should be a hook symbol.
2475 Call each of the functions in the hook value, passing each of them
2476 as arguments all the rest of ARGS (all NARGS - 1 elements).
2477 FUNCALL specifies how to call each function on the hook.
2478 The caller (or its caller, etc) must gcpro all of ARGS,
2479 except that it isn't necessary to gcpro ARGS[0]. */
2482 run_hook_with_args (ptrdiff_t nargs
, Lisp_Object
*args
,
2483 Lisp_Object (*funcall
) (ptrdiff_t nargs
, Lisp_Object
*args
))
2485 Lisp_Object sym
, val
, ret
= Qnil
;
2486 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2488 /* If we are dying or still initializing,
2489 don't do anything--it would probably crash if we tried. */
2490 if (NILP (Vrun_hooks
))
2494 val
= find_symbol_value (sym
);
2496 if (EQ (val
, Qunbound
) || NILP (val
))
2498 else if (!CONSP (val
) || FUNCTIONP (val
))
2501 return funcall (nargs
, args
);
2505 Lisp_Object global_vals
= Qnil
;
2506 GCPRO3 (sym
, val
, global_vals
);
2509 CONSP (val
) && NILP (ret
);
2512 if (EQ (XCAR (val
), Qt
))
2514 /* t indicates this hook has a local binding;
2515 it means to run the global binding too. */
2516 global_vals
= Fdefault_value (sym
);
2517 if (NILP (global_vals
)) continue;
2519 if (!CONSP (global_vals
) || EQ (XCAR (global_vals
), Qlambda
))
2521 args
[0] = global_vals
;
2522 ret
= funcall (nargs
, args
);
2527 CONSP (global_vals
) && NILP (ret
);
2528 global_vals
= XCDR (global_vals
))
2530 args
[0] = XCAR (global_vals
);
2531 /* In a global value, t should not occur. If it does, we
2532 must ignore it to avoid an endless loop. */
2533 if (!EQ (args
[0], Qt
))
2534 ret
= funcall (nargs
, args
);
2540 args
[0] = XCAR (val
);
2541 ret
= funcall (nargs
, args
);
2550 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2553 run_hook_with_args_2 (Lisp_Object hook
, Lisp_Object arg1
, Lisp_Object arg2
)
2555 Lisp_Object temp
[3];
2560 Frun_hook_with_args (3, temp
);
2563 /* Apply fn to arg. */
2565 apply1 (Lisp_Object fn
, Lisp_Object arg
)
2567 struct gcpro gcpro1
;
2571 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2574 Lisp_Object args
[2];
2578 RETURN_UNGCPRO (Fapply (2, args
));
2582 /* Call function fn on no arguments. */
2584 call0 (Lisp_Object fn
)
2586 struct gcpro gcpro1
;
2589 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2592 /* Call function fn with 1 argument arg1. */
2595 call1 (Lisp_Object fn
, Lisp_Object arg1
)
2597 struct gcpro gcpro1
;
2598 Lisp_Object args
[2];
2604 RETURN_UNGCPRO (Ffuncall (2, args
));
2607 /* Call function fn with 2 arguments arg1, arg2. */
2610 call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2612 struct gcpro gcpro1
;
2613 Lisp_Object args
[3];
2619 RETURN_UNGCPRO (Ffuncall (3, args
));
2622 /* Call function fn with 3 arguments arg1, arg2, arg3. */
2625 call3 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
2627 struct gcpro gcpro1
;
2628 Lisp_Object args
[4];
2635 RETURN_UNGCPRO (Ffuncall (4, args
));
2638 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
2641 call4 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2644 struct gcpro gcpro1
;
2645 Lisp_Object args
[5];
2653 RETURN_UNGCPRO (Ffuncall (5, args
));
2656 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
2659 call5 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2660 Lisp_Object arg4
, Lisp_Object arg5
)
2662 struct gcpro gcpro1
;
2663 Lisp_Object args
[6];
2672 RETURN_UNGCPRO (Ffuncall (6, args
));
2675 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
2678 call6 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2679 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
)
2681 struct gcpro gcpro1
;
2682 Lisp_Object args
[7];
2692 RETURN_UNGCPRO (Ffuncall (7, args
));
2695 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
2698 call7 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2699 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
, Lisp_Object arg7
)
2701 struct gcpro gcpro1
;
2702 Lisp_Object args
[8];
2713 RETURN_UNGCPRO (Ffuncall (8, args
));
2716 /* The caller should GCPRO all the elements of ARGS. */
2718 DEFUN ("functionp", Ffunctionp
, Sfunctionp
, 1, 1, 0,
2719 doc
: /* Non-nil if OBJECT is a function. */)
2720 (Lisp_Object object
)
2722 if (FUNCTIONP (object
))
2727 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2728 doc
: /* Call first argument as a function, passing remaining arguments to it.
2729 Return the value that function returns.
2730 Thus, (funcall 'cons 'x 'y) returns (x . y).
2731 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2732 (ptrdiff_t nargs
, Lisp_Object
*args
)
2734 Lisp_Object fun
, original_fun
;
2736 ptrdiff_t numargs
= nargs
- 1;
2737 Lisp_Object lisp_numargs
;
2739 register Lisp_Object
*internal_args
;
2744 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2746 if (max_lisp_eval_depth
< 100)
2747 max_lisp_eval_depth
= 100;
2748 if (lisp_eval_depth
> max_lisp_eval_depth
)
2749 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2752 /* This also GCPROs them. */
2753 record_in_backtrace (args
[0], &args
[1], nargs
- 1);
2755 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2758 if (debug_on_next_call
)
2759 do_debug_on_call (Qlambda
);
2761 original_fun
= args
[0];
2765 /* Optimize for no indirection. */
2767 if (SYMBOLP (fun
) && !NILP (fun
)
2768 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2769 fun
= indirect_function (fun
);
2773 if (numargs
< XSUBR (fun
)->min_args
2774 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2776 XSETFASTINT (lisp_numargs
, numargs
);
2777 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
2780 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2781 xsignal1 (Qinvalid_function
, original_fun
);
2783 else if (XSUBR (fun
)->max_args
== MANY
)
2784 val
= (XSUBR (fun
)->function
.aMANY
) (numargs
, args
+ 1);
2787 if (XSUBR (fun
)->max_args
> numargs
)
2789 internal_args
= alloca (XSUBR (fun
)->max_args
2790 * sizeof *internal_args
);
2791 memcpy (internal_args
, args
+ 1, numargs
* word_size
);
2792 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2793 internal_args
[i
] = Qnil
;
2796 internal_args
= args
+ 1;
2797 switch (XSUBR (fun
)->max_args
)
2800 val
= (XSUBR (fun
)->function
.a0 ());
2803 val
= (XSUBR (fun
)->function
.a1 (internal_args
[0]));
2806 val
= (XSUBR (fun
)->function
.a2
2807 (internal_args
[0], internal_args
[1]));
2810 val
= (XSUBR (fun
)->function
.a3
2811 (internal_args
[0], internal_args
[1], internal_args
[2]));
2814 val
= (XSUBR (fun
)->function
.a4
2815 (internal_args
[0], internal_args
[1], internal_args
[2],
2819 val
= (XSUBR (fun
)->function
.a5
2820 (internal_args
[0], internal_args
[1], internal_args
[2],
2821 internal_args
[3], internal_args
[4]));
2824 val
= (XSUBR (fun
)->function
.a6
2825 (internal_args
[0], internal_args
[1], internal_args
[2],
2826 internal_args
[3], internal_args
[4], internal_args
[5]));
2829 val
= (XSUBR (fun
)->function
.a7
2830 (internal_args
[0], internal_args
[1], internal_args
[2],
2831 internal_args
[3], internal_args
[4], internal_args
[5],
2836 val
= (XSUBR (fun
)->function
.a8
2837 (internal_args
[0], internal_args
[1], internal_args
[2],
2838 internal_args
[3], internal_args
[4], internal_args
[5],
2839 internal_args
[6], internal_args
[7]));
2844 /* If a subr takes more than 8 arguments without using MANY
2845 or UNEVALLED, we need to extend this function to support it.
2846 Until this is done, there is no way to call the function. */
2851 else if (COMPILEDP (fun
))
2852 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2856 xsignal1 (Qvoid_function
, original_fun
);
2858 xsignal1 (Qinvalid_function
, original_fun
);
2859 funcar
= XCAR (fun
);
2860 if (!SYMBOLP (funcar
))
2861 xsignal1 (Qinvalid_function
, original_fun
);
2862 if (EQ (funcar
, Qlambda
)
2863 || EQ (funcar
, Qclosure
))
2864 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2865 else if (EQ (funcar
, Qautoload
))
2867 Fautoload_do_load (fun
, original_fun
, Qnil
);
2871 xsignal1 (Qinvalid_function
, original_fun
);
2874 if (backtrace_debug_on_exit (specpdl_ptr
- 1))
2875 val
= call_debugger (list2 (Qexit
, val
));
2881 apply_lambda (Lisp_Object fun
, Lisp_Object args
)
2883 Lisp_Object args_left
;
2886 register Lisp_Object
*arg_vector
;
2887 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2888 register Lisp_Object tem
;
2891 numargs
= XFASTINT (Flength (args
));
2892 SAFE_ALLOCA_LISP (arg_vector
, numargs
);
2895 GCPRO3 (*arg_vector
, args_left
, fun
);
2898 for (i
= 0; i
< numargs
; )
2900 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2901 tem
= eval_sub (tem
);
2902 arg_vector
[i
++] = tem
;
2908 set_backtrace_args (specpdl_ptr
- 1, arg_vector
);
2909 set_backtrace_nargs (specpdl_ptr
- 1, i
);
2910 tem
= funcall_lambda (fun
, numargs
, arg_vector
);
2912 /* Do the debug-on-exit now, while arg_vector still exists. */
2913 if (backtrace_debug_on_exit (specpdl_ptr
- 1))
2915 /* Don't do it again when we return to eval. */
2916 set_backtrace_debug_on_exit (specpdl_ptr
- 1, false);
2917 tem
= call_debugger (list2 (Qexit
, tem
));
2923 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2924 and return the result of evaluation.
2925 FUN must be either a lambda-expression or a compiled-code object. */
2928 funcall_lambda (Lisp_Object fun
, ptrdiff_t nargs
,
2929 register Lisp_Object
*arg_vector
)
2931 Lisp_Object val
, syms_left
, next
, lexenv
;
2932 ptrdiff_t count
= SPECPDL_INDEX ();
2934 bool optional
, rest
;
2938 if (EQ (XCAR (fun
), Qclosure
))
2940 fun
= XCDR (fun
); /* Drop `closure'. */
2941 lexenv
= XCAR (fun
);
2942 CHECK_LIST_CONS (fun
, fun
);
2946 syms_left
= XCDR (fun
);
2947 if (CONSP (syms_left
))
2948 syms_left
= XCAR (syms_left
);
2950 xsignal1 (Qinvalid_function
, fun
);
2952 else if (COMPILEDP (fun
))
2954 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2955 if (INTEGERP (syms_left
))
2956 /* A byte-code object with a non-nil `push args' slot means we
2957 shouldn't bind any arguments, instead just call the byte-code
2958 interpreter directly; it will push arguments as necessary.
2960 Byte-code objects with either a non-existent, or a nil value for
2961 the `push args' slot (the default), have dynamically-bound
2962 arguments, and use the argument-binding code below instead (as do
2963 all interpreted functions, even lexically bound ones). */
2965 /* If we have not actually read the bytecode string
2966 and constants vector yet, fetch them from the file. */
2967 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2968 Ffetch_bytecode (fun
);
2969 return exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2970 AREF (fun
, COMPILED_CONSTANTS
),
2971 AREF (fun
, COMPILED_STACK_DEPTH
),
2980 i
= optional
= rest
= 0;
2981 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2985 next
= XCAR (syms_left
);
2986 if (!SYMBOLP (next
))
2987 xsignal1 (Qinvalid_function
, fun
);
2989 if (EQ (next
, Qand_rest
))
2991 else if (EQ (next
, Qand_optional
))
2998 arg
= Flist (nargs
- i
, &arg_vector
[i
]);
3002 arg
= arg_vector
[i
++];
3004 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3008 /* Bind the argument. */
3009 if (!NILP (lexenv
) && SYMBOLP (next
))
3010 /* Lexically bind NEXT by adding it to the lexenv alist. */
3011 lexenv
= Fcons (Fcons (next
, arg
), lexenv
);
3013 /* Dynamically bind NEXT. */
3014 specbind (next
, arg
);
3018 if (!NILP (syms_left
))
3019 xsignal1 (Qinvalid_function
, fun
);
3021 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3023 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
3024 /* Instantiate a new lexical environment. */
3025 specbind (Qinternal_interpreter_environment
, lexenv
);
3028 val
= Fprogn (XCDR (XCDR (fun
)));
3031 /* If we have not actually read the bytecode string
3032 and constants vector yet, fetch them from the file. */
3033 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
3034 Ffetch_bytecode (fun
);
3035 val
= exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
3036 AREF (fun
, COMPILED_CONSTANTS
),
3037 AREF (fun
, COMPILED_STACK_DEPTH
),
3041 return unbind_to (count
, val
);
3044 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
3046 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3047 (Lisp_Object object
)
3051 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
3053 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
3056 tem
= AREF (object
, COMPILED_BYTECODE
);
3057 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
3058 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
3060 error ("Invalid byte code");
3062 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
3063 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
3068 /* Return true if SYMBOL currently has a let-binding
3069 which was made in the buffer that is now current. */
3072 let_shadows_buffer_binding_p (struct Lisp_Symbol
*symbol
)
3074 union specbinding
*p
;
3075 Lisp_Object buf
= Fcurrent_buffer ();
3077 for (p
= specpdl_ptr
; p
> specpdl
; )
3078 if ((--p
)->kind
> SPECPDL_LET
)
3080 struct Lisp_Symbol
*let_bound_symbol
= XSYMBOL (specpdl_symbol (p
));
3081 eassert (let_bound_symbol
->redirect
!= SYMBOL_VARALIAS
);
3082 if (symbol
== let_bound_symbol
3083 && EQ (specpdl_where (p
), buf
))
3091 let_shadows_global_binding_p (Lisp_Object symbol
)
3093 union specbinding
*p
;
3095 for (p
= specpdl_ptr
; p
> specpdl
; )
3096 if ((--p
)->kind
>= SPECPDL_LET
&& EQ (specpdl_symbol (p
), symbol
))
3102 /* `specpdl_ptr' describes which variable is
3103 let-bound, so it can be properly undone when we unbind_to.
3104 It can be either a plain SPECPDL_LET or a SPECPDL_LET_LOCAL/DEFAULT.
3105 - SYMBOL is the variable being bound. Note that it should not be
3106 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3108 - WHERE tells us in which buffer the binding took place.
3109 This is used for SPECPDL_LET_LOCAL bindings (i.e. bindings to a
3110 buffer-local variable) as well as for SPECPDL_LET_DEFAULT bindings,
3111 i.e. bindings to the default value of a variable which can be
3115 specbind (Lisp_Object symbol
, Lisp_Object value
)
3117 struct Lisp_Symbol
*sym
;
3119 CHECK_SYMBOL (symbol
);
3120 sym
= XSYMBOL (symbol
);
3123 switch (sym
->redirect
)
3125 case SYMBOL_VARALIAS
:
3126 sym
= indirect_variable (sym
); XSETSYMBOL (symbol
, sym
); goto start
;
3127 case SYMBOL_PLAINVAL
:
3128 /* The most common case is that of a non-constant symbol with a
3129 trivial value. Make that as fast as we can. */
3130 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3131 specpdl_ptr
->let
.symbol
= symbol
;
3132 specpdl_ptr
->let
.old_value
= SYMBOL_VAL (sym
);
3135 SET_SYMBOL_VAL (sym
, value
);
3137 set_internal (symbol
, value
, Qnil
, 1);
3139 case SYMBOL_LOCALIZED
:
3140 if (SYMBOL_BLV (sym
)->frame_local
)
3141 error ("Frame-local vars cannot be let-bound");
3142 case SYMBOL_FORWARDED
:
3144 Lisp_Object ovalue
= find_symbol_value (symbol
);
3145 specpdl_ptr
->let
.kind
= SPECPDL_LET_LOCAL
;
3146 specpdl_ptr
->let
.symbol
= symbol
;
3147 specpdl_ptr
->let
.old_value
= ovalue
;
3148 specpdl_ptr
->let
.where
= Fcurrent_buffer ();
3150 eassert (sym
->redirect
!= SYMBOL_LOCALIZED
3151 || (EQ (SYMBOL_BLV (sym
)->where
, Fcurrent_buffer ())));
3153 if (sym
->redirect
== SYMBOL_LOCALIZED
)
3155 if (!blv_found (SYMBOL_BLV (sym
)))
3156 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3158 else if (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)))
3160 /* If SYMBOL is a per-buffer variable which doesn't have a
3161 buffer-local value here, make the `let' change the global
3162 value by changing the value of SYMBOL in all buffers not
3163 having their own value. This is consistent with what
3164 happens with other buffer-local variables. */
3165 if (NILP (Flocal_variable_p (symbol
, Qnil
)))
3167 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3169 Fset_default (symbol
, value
);
3174 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3177 set_internal (symbol
, value
, Qnil
, 1);
3180 default: emacs_abort ();
3184 /* Push unwind-protect entries of various types. */
3187 record_unwind_protect (void (*function
) (Lisp_Object
), Lisp_Object arg
)
3189 specpdl_ptr
->unwind
.kind
= SPECPDL_UNWIND
;
3190 specpdl_ptr
->unwind
.func
= function
;
3191 specpdl_ptr
->unwind
.arg
= arg
;
3196 record_unwind_protect_ptr (void (*function
) (void *), void *arg
)
3198 specpdl_ptr
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3199 specpdl_ptr
->unwind_ptr
.func
= function
;
3200 specpdl_ptr
->unwind_ptr
.arg
= arg
;
3205 record_unwind_protect_int (void (*function
) (int), int arg
)
3207 specpdl_ptr
->unwind_int
.kind
= SPECPDL_UNWIND_INT
;
3208 specpdl_ptr
->unwind_int
.func
= function
;
3209 specpdl_ptr
->unwind_int
.arg
= arg
;
3214 record_unwind_protect_void (void (*function
) (void))
3216 specpdl_ptr
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3217 specpdl_ptr
->unwind_void
.func
= function
;
3225 /* Push an unwind-protect entry that does nothing, so that
3226 set_unwind_protect_ptr can overwrite it later. */
3229 record_unwind_protect_nothing (void)
3231 record_unwind_protect_void (do_nothing
);
3234 /* Clear the unwind-protect entry COUNT, so that it does nothing.
3235 It need not be at the top of the stack. */
3238 clear_unwind_protect (ptrdiff_t count
)
3240 union specbinding
*p
= specpdl
+ count
;
3241 p
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3242 p
->unwind_void
.func
= do_nothing
;
3245 /* Set the unwind-protect entry COUNT so that it invokes FUNC (ARG).
3246 It need not be at the top of the stack. Discard the entry's
3247 previous value without invoking it. */
3250 set_unwind_protect (ptrdiff_t count
, void (*func
) (Lisp_Object
),
3253 union specbinding
*p
= specpdl
+ count
;
3254 p
->unwind
.kind
= SPECPDL_UNWIND
;
3255 p
->unwind
.func
= func
;
3256 p
->unwind
.arg
= arg
;
3260 set_unwind_protect_ptr (ptrdiff_t count
, void (*func
) (void *), void *arg
)
3262 union specbinding
*p
= specpdl
+ count
;
3263 p
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3264 p
->unwind_ptr
.func
= func
;
3265 p
->unwind_ptr
.arg
= arg
;
3268 /* Pop and execute entries from the unwind-protect stack until the
3269 depth COUNT is reached. Return VALUE. */
3272 unbind_to (ptrdiff_t count
, Lisp_Object value
)
3274 Lisp_Object quitf
= Vquit_flag
;
3275 struct gcpro gcpro1
, gcpro2
;
3277 GCPRO2 (value
, quitf
);
3280 while (specpdl_ptr
!= specpdl
+ count
)
3282 /* Decrement specpdl_ptr before we do the work to unbind it, so
3283 that an error in unbinding won't try to unbind the same entry
3284 again. Take care to copy any parts of the binding needed
3285 before invoking any code that can make more bindings. */
3289 switch (specpdl_ptr
->kind
)
3291 case SPECPDL_UNWIND
:
3292 specpdl_ptr
->unwind
.func (specpdl_ptr
->unwind
.arg
);
3294 case SPECPDL_UNWIND_PTR
:
3295 specpdl_ptr
->unwind_ptr
.func (specpdl_ptr
->unwind_ptr
.arg
);
3297 case SPECPDL_UNWIND_INT
:
3298 specpdl_ptr
->unwind_int
.func (specpdl_ptr
->unwind_int
.arg
);
3300 case SPECPDL_UNWIND_VOID
:
3301 specpdl_ptr
->unwind_void
.func ();
3303 case SPECPDL_BACKTRACE
:
3306 { /* If variable has a trivial value (no forwarding), we can
3307 just set it. No need to check for constant symbols here,
3308 since that was already done by specbind. */
3309 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (specpdl_ptr
));
3310 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3312 SET_SYMBOL_VAL (sym
, specpdl_old_value (specpdl_ptr
));
3317 NOTE: we only ever come here if make_local_foo was used for
3318 the first time on this var within this let. */
3321 case SPECPDL_LET_DEFAULT
:
3322 Fset_default (specpdl_symbol (specpdl_ptr
),
3323 specpdl_old_value (specpdl_ptr
));
3325 case SPECPDL_LET_LOCAL
:
3327 Lisp_Object symbol
= specpdl_symbol (specpdl_ptr
);
3328 Lisp_Object where
= specpdl_where (specpdl_ptr
);
3329 Lisp_Object old_value
= specpdl_old_value (specpdl_ptr
);
3330 eassert (BUFFERP (where
));
3332 /* If this was a local binding, reset the value in the appropriate
3333 buffer, but only if that buffer's binding still exists. */
3334 if (!NILP (Flocal_variable_p (symbol
, where
)))
3335 set_internal (symbol
, old_value
, where
, 1);
3341 if (NILP (Vquit_flag
) && !NILP (quitf
))
3348 DEFUN ("special-variable-p", Fspecial_variable_p
, Sspecial_variable_p
, 1, 1, 0,
3349 doc
: /* Return non-nil if SYMBOL's global binding has been declared special.
3350 A special variable is one that will be bound dynamically, even in a
3351 context where binding is lexical by default. */)
3352 (Lisp_Object symbol
)
3354 CHECK_SYMBOL (symbol
);
3355 return XSYMBOL (symbol
)->declared_special
? Qt
: Qnil
;
3359 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3360 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3361 The debugger is entered when that frame exits, if the flag is non-nil. */)
3362 (Lisp_Object level
, Lisp_Object flag
)
3364 union specbinding
*pdl
= backtrace_top ();
3365 register EMACS_INT i
;
3367 CHECK_NUMBER (level
);
3369 for (i
= 0; backtrace_p (pdl
) && i
< XINT (level
); i
++)
3370 pdl
= backtrace_next (pdl
);
3372 if (backtrace_p (pdl
))
3373 set_backtrace_debug_on_exit (pdl
, !NILP (flag
));
3378 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3379 doc
: /* Print a trace of Lisp function calls currently active.
3380 Output stream used is value of `standard-output'. */)
3383 union specbinding
*pdl
= backtrace_top ();
3385 Lisp_Object old_print_level
= Vprint_level
;
3387 if (NILP (Vprint_level
))
3388 XSETFASTINT (Vprint_level
, 8);
3390 while (backtrace_p (pdl
))
3392 write_string (backtrace_debug_on_exit (pdl
) ? "* " : " ", 2);
3393 if (backtrace_nargs (pdl
) == UNEVALLED
)
3395 Fprin1 (Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)),
3397 write_string ("\n", -1);
3401 tem
= backtrace_function (pdl
);
3402 Fprin1 (tem
, Qnil
); /* This can QUIT. */
3403 write_string ("(", -1);
3406 for (i
= 0; i
< backtrace_nargs (pdl
); i
++)
3408 if (i
) write_string (" ", -1);
3409 Fprin1 (backtrace_args (pdl
)[i
], Qnil
);
3412 write_string (")\n", -1);
3414 pdl
= backtrace_next (pdl
);
3417 Vprint_level
= old_print_level
;
3421 static union specbinding
*
3422 get_backtrace_frame (Lisp_Object nframes
, Lisp_Object base
)
3424 union specbinding
*pdl
= backtrace_top ();
3425 register EMACS_INT i
;
3427 CHECK_NATNUM (nframes
);
3430 { /* Skip up to `base'. */
3431 base
= Findirect_function (base
, Qt
);
3432 while (backtrace_p (pdl
)
3433 && !EQ (base
, Findirect_function (backtrace_function (pdl
), Qt
)))
3434 pdl
= backtrace_next (pdl
);
3437 /* Find the frame requested. */
3438 for (i
= XFASTINT (nframes
); i
> 0 && backtrace_p (pdl
); i
--)
3439 pdl
= backtrace_next (pdl
);
3444 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 2, NULL
,
3445 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3446 If that frame has not evaluated the arguments yet (or is a special form),
3447 the value is (nil FUNCTION ARG-FORMS...).
3448 If that frame has evaluated its arguments and called its function already,
3449 the value is (t FUNCTION ARG-VALUES...).
3450 A &rest arg is represented as the tail of the list ARG-VALUES.
3451 FUNCTION is whatever was supplied as car of evaluated list,
3452 or a lambda expression for macro calls.
3453 If NFRAMES is more than the number of frames, the value is nil.
3454 If BASE is non-nil, it should be a function and NFRAMES counts from its
3455 nearest activation frame. */)
3456 (Lisp_Object nframes
, Lisp_Object base
)
3458 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3460 if (!backtrace_p (pdl
))
3462 if (backtrace_nargs (pdl
) == UNEVALLED
)
3464 Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)));
3467 Lisp_Object tem
= Flist (backtrace_nargs (pdl
), backtrace_args (pdl
));
3469 return Fcons (Qt
, Fcons (backtrace_function (pdl
), tem
));
3473 /* For backtrace-eval, we want to temporarily unwind the last few elements of
3474 the specpdl stack, and then rewind them. We store the pre-unwind values
3475 directly in the pre-existing specpdl elements (i.e. we swap the current
3476 value and the old value stored in the specpdl), kind of like the inplace
3477 pointer-reversal trick. As it turns out, the rewind does the same as the
3478 unwind, except it starts from the other end of the specpdl stack, so we use
3479 the same function for both unwind and rewind. */
3481 backtrace_eval_unrewind (int distance
)
3483 union specbinding
*tmp
= specpdl_ptr
;
3486 { /* It's a rewind rather than unwind. */
3487 tmp
+= distance
- 1;
3489 distance
= -distance
;
3492 for (; distance
> 0; distance
--)
3498 /* FIXME: Ideally we'd like to "temporarily unwind" (some of) those
3499 unwind_protect, but the problem is that we don't know how to
3500 rewind them afterwards. */
3501 case SPECPDL_UNWIND
:
3502 case SPECPDL_UNWIND_PTR
:
3503 case SPECPDL_UNWIND_INT
:
3504 case SPECPDL_UNWIND_VOID
:
3505 case SPECPDL_BACKTRACE
:
3508 { /* If variable has a trivial value (no forwarding), we can
3509 just set it. No need to check for constant symbols here,
3510 since that was already done by specbind. */
3511 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (tmp
));
3512 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3514 Lisp_Object old_value
= specpdl_old_value (tmp
);
3515 set_specpdl_old_value (tmp
, SYMBOL_VAL (sym
));
3516 SET_SYMBOL_VAL (sym
, old_value
);
3521 NOTE: we only ever come here if make_local_foo was used for
3522 the first time on this var within this let. */
3525 case SPECPDL_LET_DEFAULT
:
3527 Lisp_Object sym
= specpdl_symbol (tmp
);
3528 Lisp_Object old_value
= specpdl_old_value (tmp
);
3529 set_specpdl_old_value (tmp
, Fdefault_value (sym
));
3530 Fset_default (sym
, old_value
);
3533 case SPECPDL_LET_LOCAL
:
3535 Lisp_Object symbol
= specpdl_symbol (tmp
);
3536 Lisp_Object where
= specpdl_where (tmp
);
3537 Lisp_Object old_value
= specpdl_old_value (tmp
);
3538 eassert (BUFFERP (where
));
3540 /* If this was a local binding, reset the value in the appropriate
3541 buffer, but only if that buffer's binding still exists. */
3542 if (!NILP (Flocal_variable_p (symbol
, where
)))
3544 set_specpdl_old_value
3545 (tmp
, Fbuffer_local_value (symbol
, where
));
3546 set_internal (symbol
, old_value
, where
, 1);
3554 DEFUN ("backtrace-eval", Fbacktrace_eval
, Sbacktrace_eval
, 2, 3, NULL
,
3555 doc
: /* Evaluate EXP in the context of some activation frame.
3556 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3557 (Lisp_Object exp
, Lisp_Object nframes
, Lisp_Object base
)
3559 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3560 ptrdiff_t count
= SPECPDL_INDEX ();
3561 ptrdiff_t distance
= specpdl_ptr
- pdl
;
3562 eassert (distance
>= 0);
3564 if (!backtrace_p (pdl
))
3565 error ("Activation frame not found!");
3567 backtrace_eval_unrewind (distance
);
3568 record_unwind_protect_int (backtrace_eval_unrewind
, -distance
);
3570 /* Use eval_sub rather than Feval since the main motivation behind
3571 backtrace-eval is to be able to get/set the value of lexical variables
3572 from the debugger. */
3573 return unbind_to (count
, eval_sub (exp
));
3576 DEFUN ("backtrace--locals", Fbacktrace__locals
, Sbacktrace__locals
, 1, 2, NULL
,
3577 doc
: /* Return names and values of local variables of a stack frame.
3578 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3579 (Lisp_Object nframes
, Lisp_Object base
)
3581 union specbinding
*frame
= get_backtrace_frame (nframes
, base
);
3582 union specbinding
*prevframe
3583 = get_backtrace_frame (make_number (XFASTINT (nframes
) - 1), base
);
3584 ptrdiff_t distance
= specpdl_ptr
- frame
;
3585 Lisp_Object result
= Qnil
;
3586 eassert (distance
>= 0);
3588 if (!backtrace_p (prevframe
))
3589 error ("Activation frame not found!");
3590 if (!backtrace_p (frame
))
3591 error ("Activation frame not found!");
3593 /* The specpdl entries normally contain the symbol being bound along with its
3594 `old_value', so it can be restored. The new value to which it is bound is
3595 available in one of two places: either in the current value of the
3596 variable (if it hasn't been rebound yet) or in the `old_value' slot of the
3597 next specpdl entry for it.
3598 `backtrace_eval_unrewind' happens to swap the role of `old_value'
3599 and "new value", so we abuse it here, to fetch the new value.
3600 It's ugly (we'd rather not modify global data) and a bit inefficient,
3601 but it does the job for now. */
3602 backtrace_eval_unrewind (distance
);
3606 union specbinding
*tmp
= prevframe
;
3607 for (; tmp
> frame
; tmp
--)
3612 case SPECPDL_LET_DEFAULT
:
3613 case SPECPDL_LET_LOCAL
:
3615 Lisp_Object sym
= specpdl_symbol (tmp
);
3616 Lisp_Object val
= specpdl_old_value (tmp
);
3617 if (EQ (sym
, Qinternal_interpreter_environment
))
3619 Lisp_Object env
= val
;
3620 for (; CONSP (env
); env
= XCDR (env
))
3622 Lisp_Object binding
= XCAR (env
);
3623 if (CONSP (binding
))
3624 result
= Fcons (Fcons (XCAR (binding
),
3630 result
= Fcons (Fcons (sym
, val
), result
);
3636 /* Restore values from specpdl to original place. */
3637 backtrace_eval_unrewind (-distance
);
3644 get_backtrace (Lisp_Object array
)
3646 union specbinding
*pdl
= backtrace_next (backtrace_top ());
3647 ptrdiff_t i
= 0, asize
= ASIZE (array
);
3649 /* Copy the backtrace contents into working memory. */
3650 for (; i
< asize
; i
++)
3652 if (backtrace_p (pdl
))
3654 ASET (array
, i
, backtrace_function (pdl
));
3655 pdl
= backtrace_next (pdl
);
3658 ASET (array
, i
, Qnil
);
3662 Lisp_Object
backtrace_top_function (void)
3664 union specbinding
*pdl
= backtrace_top ();
3665 return (backtrace_p (pdl
) ? backtrace_function (pdl
) : Qnil
);
3671 DEFVAR_INT ("max-specpdl-size", max_specpdl_size
,
3672 doc
: /* Limit on number of Lisp variable bindings and `unwind-protect's.
3673 If Lisp code tries to increase the total number past this amount,
3674 an error is signaled.
3675 You can safely use a value considerably larger than the default value,
3676 if that proves inconveniently small. However, if you increase it too far,
3677 Emacs could run out of memory trying to make the stack bigger.
3678 Note that this limit may be silently increased by the debugger
3679 if `debug-on-error' or `debug-on-quit' is set. */);
3681 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth
,
3682 doc
: /* Limit on depth in `eval', `apply' and `funcall' before error.
3684 This limit serves to catch infinite recursions for you before they cause
3685 actual stack overflow in C, which would be fatal for Emacs.
3686 You can safely make it considerably larger than its default value,
3687 if that proves inconveniently small. However, if you increase it too far,
3688 Emacs could overflow the real C stack, and crash. */);
3690 DEFVAR_LISP ("quit-flag", Vquit_flag
,
3691 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3692 If the value is t, that means do an ordinary quit.
3693 If the value equals `throw-on-input', that means quit by throwing
3694 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3695 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3696 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3699 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit
,
3700 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3701 Note that `quit-flag' will still be set by typing C-g,
3702 so a quit will be signaled as soon as `inhibit-quit' is nil.
3703 To prevent this happening, set `quit-flag' to nil
3704 before making `inhibit-quit' nil. */);
3705 Vinhibit_quit
= Qnil
;
3707 DEFSYM (Qinhibit_quit
, "inhibit-quit");
3708 DEFSYM (Qautoload
, "autoload");
3709 DEFSYM (Qinhibit_debugger
, "inhibit-debugger");
3710 DEFSYM (Qmacro
, "macro");
3711 DEFSYM (Qdeclare
, "declare");
3713 /* Note that the process handling also uses Qexit, but we don't want
3714 to staticpro it twice, so we just do it here. */
3715 DEFSYM (Qexit
, "exit");
3717 DEFSYM (Qinteractive
, "interactive");
3718 DEFSYM (Qcommandp
, "commandp");
3719 DEFSYM (Qand_rest
, "&rest");
3720 DEFSYM (Qand_optional
, "&optional");
3721 DEFSYM (Qclosure
, "closure");
3722 DEFSYM (Qdebug
, "debug");
3724 DEFVAR_LISP ("inhibit-debugger", Vinhibit_debugger
,
3725 doc
: /* Non-nil means never enter the debugger.
3726 Normally set while the debugger is already active, to avoid recursive
3728 Vinhibit_debugger
= Qnil
;
3730 DEFVAR_LISP ("debug-on-error", Vdebug_on_error
,
3731 doc
: /* Non-nil means enter debugger if an error is signaled.
3732 Does not apply to errors handled by `condition-case' or those
3733 matched by `debug-ignored-errors'.
3734 If the value is a list, an error only means to enter the debugger
3735 if one of its condition symbols appears in the list.
3736 When you evaluate an expression interactively, this variable
3737 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3738 The command `toggle-debug-on-error' toggles this.
3739 See also the variable `debug-on-quit' and `inhibit-debugger'. */);
3740 Vdebug_on_error
= Qnil
;
3742 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors
,
3743 doc
: /* List of errors for which the debugger should not be called.
3744 Each element may be a condition-name or a regexp that matches error messages.
3745 If any element applies to a given error, that error skips the debugger
3746 and just returns to top level.
3747 This overrides the variable `debug-on-error'.
3748 It does not apply to errors handled by `condition-case'. */);
3749 Vdebug_ignored_errors
= Qnil
;
3751 DEFVAR_BOOL ("debug-on-quit", debug_on_quit
,
3752 doc
: /* Non-nil means enter debugger if quit is signaled (C-g, for example).
3753 Does not apply if quit is handled by a `condition-case'. */);
3756 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call
,
3757 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3759 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue
,
3760 doc
: /* Non-nil means debugger may continue execution.
3761 This is nil when the debugger is called under circumstances where it
3762 might not be safe to continue. */);
3763 debugger_may_continue
= 1;
3765 DEFVAR_LISP ("debugger", Vdebugger
,
3766 doc
: /* Function to call to invoke debugger.
3767 If due to frame exit, args are `exit' and the value being returned;
3768 this function's value will be returned instead of that.
3769 If due to error, args are `error' and a list of the args to `signal'.
3770 If due to `apply' or `funcall' entry, one arg, `lambda'.
3771 If due to `eval' entry, one arg, t. */);
3774 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function
,
3775 doc
: /* If non-nil, this is a function for `signal' to call.
3776 It receives the same arguments that `signal' was given.
3777 The Edebug package uses this to regain control. */);
3778 Vsignal_hook_function
= Qnil
;
3780 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal
,
3781 doc
: /* Non-nil means call the debugger regardless of condition handlers.
3782 Note that `debug-on-error', `debug-on-quit' and friends
3783 still determine whether to handle the particular condition. */);
3784 Vdebug_on_signal
= Qnil
;
3786 /* When lexical binding is being used,
3787 Vinternal_interpreter_environment is non-nil, and contains an alist
3788 of lexically-bound variable, or (t), indicating an empty
3789 environment. The lisp name of this variable would be
3790 `internal-interpreter-environment' if it weren't hidden.
3791 Every element of this list can be either a cons (VAR . VAL)
3792 specifying a lexical binding, or a single symbol VAR indicating
3793 that this variable should use dynamic scoping. */
3794 DEFSYM (Qinternal_interpreter_environment
,
3795 "internal-interpreter-environment");
3796 DEFVAR_LISP ("internal-interpreter-environment",
3797 Vinternal_interpreter_environment
,
3798 doc
: /* If non-nil, the current lexical environment of the lisp interpreter.
3799 When lexical binding is not being used, this variable is nil.
3800 A value of `(t)' indicates an empty environment, otherwise it is an
3801 alist of active lexical bindings. */);
3802 Vinternal_interpreter_environment
= Qnil
;
3803 /* Don't export this variable to Elisp, so no one can mess with it
3804 (Just imagine if someone makes it buffer-local). */
3805 Funintern (Qinternal_interpreter_environment
, Qnil
);
3807 DEFSYM (Vrun_hooks
, "run-hooks");
3809 staticpro (&Vautoload_queue
);
3810 Vautoload_queue
= Qnil
;
3811 staticpro (&Vsignaling_function
);
3812 Vsignaling_function
= Qnil
;
3814 inhibit_lisp_code
= Qnil
;
3825 defsubr (&Sfunction
);
3826 defsubr (&Sdefault_toplevel_value
);
3827 defsubr (&Sset_default_toplevel_value
);
3829 defsubr (&Sdefvaralias
);
3830 defsubr (&Sdefconst
);
3831 defsubr (&Smake_var_non_special
);
3835 defsubr (&Smacroexpand
);
3838 defsubr (&Sunwind_protect
);
3839 defsubr (&Scondition_case
);
3841 defsubr (&Scommandp
);
3842 defsubr (&Sautoload
);
3843 defsubr (&Sautoload_do_load
);
3846 defsubr (&Sfuncall
);
3847 defsubr (&Srun_hooks
);
3848 defsubr (&Srun_hook_with_args
);
3849 defsubr (&Srun_hook_with_args_until_success
);
3850 defsubr (&Srun_hook_with_args_until_failure
);
3851 defsubr (&Srun_hook_wrapped
);
3852 defsubr (&Sfetch_bytecode
);
3853 defsubr (&Sbacktrace_debug
);
3854 defsubr (&Sbacktrace
);
3855 defsubr (&Sbacktrace_frame
);
3856 defsubr (&Sbacktrace_eval
);
3857 defsubr (&Sbacktrace__locals
);
3858 defsubr (&Sspecial_variable_p
);
3859 defsubr (&Sfunctionp
);