1 /* Evaluator for GNU Emacs Lisp interpreter.
3 Copyright (C) 1985-1987, 1993-1995, 1999-2013 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
25 #include "blockinput.h"
28 #include "dispextern.h"
29 #include "frame.h" /* For XFRAME. */
35 /* Chain of condition and catch handlers currently in effect. */
37 struct handler
*handlerlist
;
40 /* Count levels of GCPRO to detect failure to UNGCPRO. */
44 Lisp_Object Qautoload
, Qmacro
, Qexit
, Qinteractive
, Qcommandp
;
45 Lisp_Object Qinhibit_quit
;
46 Lisp_Object Qand_rest
;
47 static Lisp_Object Qand_optional
;
48 static Lisp_Object Qinhibit_debugger
;
49 static Lisp_Object Qdeclare
;
50 Lisp_Object Qinternal_interpreter_environment
, Qclosure
;
52 static Lisp_Object Qdebug
;
54 /* This holds either the symbol `run-hooks' or nil.
55 It is nil at an early stage of startup, and when Emacs
58 Lisp_Object Vrun_hooks
;
60 /* Non-nil means record all fset's and provide's, to be undone
61 if the file being autoloaded is not fully loaded.
62 They are recorded by being consed onto the front of Vautoload_queue:
63 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
65 Lisp_Object Vautoload_queue
;
67 /* Current number of specbindings allocated in specpdl, not counting
68 the dummy entry specpdl[-1]. */
70 ptrdiff_t specpdl_size
;
72 /* Pointer to beginning of specpdl. A dummy entry specpdl[-1] exists
73 only so that its address can be taken. */
75 union specbinding
*specpdl
;
77 /* Pointer to first unused element in specpdl. */
79 union specbinding
*specpdl_ptr
;
81 /* Depth in Lisp evaluations and function calls. */
83 EMACS_INT lisp_eval_depth
;
85 /* The value of num_nonmacro_input_events as of the last time we
86 started to enter the debugger. If we decide to enter the debugger
87 again when this is still equal to num_nonmacro_input_events, then we
88 know that the debugger itself has an error, and we should just
89 signal the error instead of entering an infinite loop of debugger
92 static EMACS_INT when_entered_debugger
;
94 /* The function from which the last `signal' was called. Set in
96 /* FIXME: We should probably get rid of this! */
97 Lisp_Object Vsignaling_function
;
99 /* If non-nil, Lisp code must not be run since some part of Emacs is
100 in an inconsistent state. Currently, x-create-frame uses this to
101 avoid triggering window-configuration-change-hook while the new
102 frame is half-initialized. */
103 Lisp_Object inhibit_lisp_code
;
105 /* These would ordinarily be static, but they need to be visible to GDB. */
106 bool backtrace_p (union specbinding
*) EXTERNALLY_VISIBLE
;
107 Lisp_Object
*backtrace_args (union specbinding
*) EXTERNALLY_VISIBLE
;
108 Lisp_Object
backtrace_function (union specbinding
*) EXTERNALLY_VISIBLE
;
109 union specbinding
*backtrace_next (union specbinding
*) EXTERNALLY_VISIBLE
;
110 union specbinding
*backtrace_top (void) EXTERNALLY_VISIBLE
;
112 static Lisp_Object
funcall_lambda (Lisp_Object
, ptrdiff_t, Lisp_Object
*);
113 static Lisp_Object
apply_lambda (Lisp_Object fun
, Lisp_Object args
);
116 specpdl_symbol (union specbinding
*pdl
)
118 eassert (pdl
->kind
>= SPECPDL_LET
);
119 return pdl
->let
.symbol
;
123 specpdl_old_value (union specbinding
*pdl
)
125 eassert (pdl
->kind
>= SPECPDL_LET
);
126 return pdl
->let
.old_value
;
130 set_specpdl_old_value (union specbinding
*pdl
, Lisp_Object val
)
132 eassert (pdl
->kind
>= SPECPDL_LET
);
133 pdl
->let
.old_value
= val
;
137 specpdl_where (union specbinding
*pdl
)
139 eassert (pdl
->kind
> SPECPDL_LET
);
140 return pdl
->let
.where
;
144 specpdl_arg (union specbinding
*pdl
)
146 eassert (pdl
->kind
== SPECPDL_UNWIND
);
147 return pdl
->unwind
.arg
;
151 backtrace_function (union specbinding
*pdl
)
153 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
154 return pdl
->bt
.function
;
158 backtrace_nargs (union specbinding
*pdl
)
160 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
161 return pdl
->bt
.nargs
;
165 backtrace_args (union specbinding
*pdl
)
167 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
172 backtrace_debug_on_exit (union specbinding
*pdl
)
174 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
175 return pdl
->bt
.debug_on_exit
;
178 /* Functions to modify slots of backtrace records. */
181 set_backtrace_args (union specbinding
*pdl
, Lisp_Object
*args
)
183 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
188 set_backtrace_nargs (union specbinding
*pdl
, ptrdiff_t n
)
190 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
195 set_backtrace_debug_on_exit (union specbinding
*pdl
, bool doe
)
197 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
198 pdl
->bt
.debug_on_exit
= doe
;
201 /* Helper functions to scan the backtrace. */
204 backtrace_p (union specbinding
*pdl
)
205 { return pdl
>= specpdl
; }
210 union specbinding
*pdl
= specpdl_ptr
- 1;
211 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
217 backtrace_next (union specbinding
*pdl
)
220 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
227 init_eval_once (void)
230 union specbinding
*pdlvec
= xmalloc ((size
+ 1) * sizeof *specpdl
);
232 specpdl
= specpdl_ptr
= pdlvec
+ 1;
233 /* Don't forget to update docs (lispref node "Local Variables"). */
234 max_specpdl_size
= 1300; /* 1000 is not enough for CEDET's c-by.el. */
235 max_lisp_eval_depth
= 600;
243 specpdl_ptr
= specpdl
;
246 debug_on_next_call
= 0;
251 /* This is less than the initial value of num_nonmacro_input_events. */
252 when_entered_debugger
= -1;
255 /* Unwind-protect function used by call_debugger. */
258 restore_stack_limits (Lisp_Object data
)
260 max_specpdl_size
= XINT (XCAR (data
));
261 max_lisp_eval_depth
= XINT (XCDR (data
));
264 /* Call the Lisp debugger, giving it argument ARG. */
267 call_debugger (Lisp_Object arg
)
269 bool debug_while_redisplaying
;
270 ptrdiff_t count
= SPECPDL_INDEX ();
272 EMACS_INT old_max
= max_specpdl_size
;
274 /* Temporarily bump up the stack limits,
275 so the debugger won't run out of stack. */
277 max_specpdl_size
+= 1;
278 record_unwind_protect (restore_stack_limits
,
279 Fcons (make_number (old_max
),
280 make_number (max_lisp_eval_depth
)));
281 max_specpdl_size
= old_max
;
283 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
284 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
286 if (max_specpdl_size
- 100 < SPECPDL_INDEX ())
287 max_specpdl_size
= SPECPDL_INDEX () + 100;
289 #ifdef HAVE_WINDOW_SYSTEM
290 if (display_hourglass_p
)
294 debug_on_next_call
= 0;
295 when_entered_debugger
= num_nonmacro_input_events
;
297 /* Resetting redisplaying_p to 0 makes sure that debug output is
298 displayed if the debugger is invoked during redisplay. */
299 debug_while_redisplaying
= redisplaying_p
;
301 specbind (intern ("debugger-may-continue"),
302 debug_while_redisplaying
? Qnil
: Qt
);
303 specbind (Qinhibit_redisplay
, Qnil
);
304 specbind (Qinhibit_debugger
, Qt
);
306 #if 0 /* Binding this prevents execution of Lisp code during
307 redisplay, which necessarily leads to display problems. */
308 specbind (Qinhibit_eval_during_redisplay
, Qt
);
311 val
= apply1 (Vdebugger
, arg
);
313 /* Interrupting redisplay and resuming it later is not safe under
314 all circumstances. So, when the debugger returns, abort the
315 interrupted redisplay by going back to the top-level. */
316 if (debug_while_redisplaying
)
319 return unbind_to (count
, val
);
323 do_debug_on_call (Lisp_Object code
)
325 debug_on_next_call
= 0;
326 set_backtrace_debug_on_exit (specpdl_ptr
- 1, true);
327 call_debugger (list1 (code
));
330 /* NOTE!!! Every function that can call EVAL must protect its args
331 and temporaries from garbage collection while it needs them.
332 The definition of `For' shows what you have to do. */
334 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
335 doc
: /* Eval args until one of them yields non-nil, then return that value.
336 The remaining args are not evalled at all.
337 If all args return nil, return nil.
338 usage: (or CONDITIONS...) */)
341 register Lisp_Object val
= Qnil
;
348 val
= eval_sub (XCAR (args
));
358 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
359 doc
: /* Eval args until one of them yields nil, then return nil.
360 The remaining args are not evalled at all.
361 If no arg yields nil, return the last arg's value.
362 usage: (and CONDITIONS...) */)
365 register Lisp_Object val
= Qt
;
372 val
= eval_sub (XCAR (args
));
382 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
383 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
384 Returns the value of THEN or the value of the last of the ELSE's.
385 THEN must be one expression, but ELSE... can be zero or more expressions.
386 If COND yields nil, and there are no ELSE's, the value is nil.
387 usage: (if COND THEN ELSE...) */)
394 cond
= eval_sub (XCAR (args
));
398 return eval_sub (Fcar (XCDR (args
)));
399 return Fprogn (XCDR (XCDR (args
)));
402 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
403 doc
: /* Try each clause until one succeeds.
404 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
405 and, if the value is non-nil, this clause succeeds:
406 then the expressions in BODY are evaluated and the last one's
407 value is the value of the cond-form.
408 If a clause has one element, as in (CONDITION), then the cond-form
409 returns CONDITION's value, if that is non-nil.
410 If no clause succeeds, cond returns nil.
411 usage: (cond CLAUSES...) */)
414 Lisp_Object val
= args
;
420 Lisp_Object clause
= XCAR (args
);
421 val
= eval_sub (Fcar (clause
));
424 if (!NILP (XCDR (clause
)))
425 val
= Fprogn (XCDR (clause
));
435 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
436 doc
: /* Eval BODY forms sequentially and return value of last one.
437 usage: (progn BODY...) */)
440 Lisp_Object val
= Qnil
;
447 val
= eval_sub (XCAR (body
));
455 /* Evaluate BODY sequentially, discarding its value. Suitable for
456 record_unwind_protect. */
459 unwind_body (Lisp_Object body
)
464 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
465 doc
: /* Eval FIRST and BODY sequentially; return value from FIRST.
466 The value of FIRST is saved during the evaluation of the remaining args,
467 whose values are discarded.
468 usage: (prog1 FIRST BODY...) */)
472 Lisp_Object args_left
;
473 struct gcpro gcpro1
, gcpro2
;
479 val
= eval_sub (XCAR (args_left
));
480 while (CONSP (args_left
= XCDR (args_left
)))
481 eval_sub (XCAR (args_left
));
487 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
488 doc
: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
489 The value of FORM2 is saved during the evaluation of the
490 remaining args, whose values are discarded.
491 usage: (prog2 FORM1 FORM2 BODY...) */)
497 eval_sub (XCAR (args
));
499 return Fprog1 (XCDR (args
));
502 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
503 doc
: /* Set each SYM to the value of its VAL.
504 The symbols SYM are variables; they are literal (not evaluated).
505 The values VAL are expressions; they are evaluated.
506 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
507 The second VAL is not computed until after the first SYM is set, and so on;
508 each VAL can use the new value of variables set earlier in the `setq'.
509 The return value of the `setq' form is the value of the last VAL.
510 usage: (setq [SYM VAL]...) */)
513 Lisp_Object val
, sym
, lex_binding
;
518 Lisp_Object args_left
= args
;
524 val
= eval_sub (Fcar (XCDR (args_left
)));
525 sym
= XCAR (args_left
);
527 /* Like for eval_sub, we do not check declared_special here since
528 it's been done when let-binding. */
529 if (!NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
531 && !NILP (lex_binding
532 = Fassq (sym
, Vinternal_interpreter_environment
)))
533 XSETCDR (lex_binding
, val
); /* SYM is lexically bound. */
535 Fset (sym
, val
); /* SYM is dynamically bound. */
537 args_left
= Fcdr (XCDR (args_left
));
539 while (CONSP (args_left
));
547 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
548 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
549 Warning: `quote' does not construct its return value, but just returns
550 the value that was pre-constructed by the Lisp reader (see info node
551 `(elisp)Printed Representation').
552 This means that '(a . b) is not identical to (cons 'a 'b): the former
553 does not cons. Quoting should be reserved for constants that will
554 never be modified by side-effects, unless you like self-modifying code.
555 See the common pitfall in info node `(elisp)Rearrangement' for an example
556 of unexpected results when a quoted object is modified.
557 usage: (quote ARG) */)
560 if (CONSP (XCDR (args
)))
561 xsignal2 (Qwrong_number_of_arguments
, Qquote
, Flength (args
));
565 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
566 doc
: /* Like `quote', but preferred for objects which are functions.
567 In byte compilation, `function' causes its argument to be compiled.
568 `quote' cannot do that.
569 usage: (function ARG) */)
572 Lisp_Object quoted
= XCAR (args
);
574 if (CONSP (XCDR (args
)))
575 xsignal2 (Qwrong_number_of_arguments
, Qfunction
, Flength (args
));
577 if (!NILP (Vinternal_interpreter_environment
)
579 && EQ (XCAR (quoted
), Qlambda
))
580 /* This is a lambda expression within a lexical environment;
581 return an interpreted closure instead of a simple lambda. */
582 return Fcons (Qclosure
, Fcons (Vinternal_interpreter_environment
,
585 /* Simply quote the argument. */
590 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
591 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
592 Aliased variables always have the same value; setting one sets the other.
593 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
594 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
595 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
596 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
597 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
598 The return value is BASE-VARIABLE. */)
599 (Lisp_Object new_alias
, Lisp_Object base_variable
, Lisp_Object docstring
)
601 struct Lisp_Symbol
*sym
;
603 CHECK_SYMBOL (new_alias
);
604 CHECK_SYMBOL (base_variable
);
606 sym
= XSYMBOL (new_alias
);
609 /* Not sure why, but why not? */
610 error ("Cannot make a constant an alias");
612 switch (sym
->redirect
)
614 case SYMBOL_FORWARDED
:
615 error ("Cannot make an internal variable an alias");
616 case SYMBOL_LOCALIZED
:
617 error ("Don't know how to make a localized variable an alias");
620 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
621 If n_a is bound, but b_v is not, set the value of b_v to n_a,
622 so that old-code that affects n_a before the aliasing is setup
624 if (NILP (Fboundp (base_variable
)))
625 set_internal (base_variable
, find_symbol_value (new_alias
), Qnil
, 1);
628 union specbinding
*p
;
630 for (p
= specpdl_ptr
; p
> specpdl
; )
631 if ((--p
)->kind
>= SPECPDL_LET
632 && (EQ (new_alias
, specpdl_symbol (p
))))
633 error ("Don't know how to make a let-bound variable an alias");
636 sym
->declared_special
= 1;
637 XSYMBOL (base_variable
)->declared_special
= 1;
638 sym
->redirect
= SYMBOL_VARALIAS
;
639 SET_SYMBOL_ALIAS (sym
, XSYMBOL (base_variable
));
640 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
641 LOADHIST_ATTACH (new_alias
);
642 /* Even if docstring is nil: remove old docstring. */
643 Fput (new_alias
, Qvariable_documentation
, docstring
);
645 return base_variable
;
648 static union specbinding
*
649 default_toplevel_binding (Lisp_Object symbol
)
651 union specbinding
*binding
= NULL
;
652 union specbinding
*pdl
= specpdl_ptr
;
653 while (pdl
> specpdl
)
655 switch ((--pdl
)->kind
)
657 case SPECPDL_LET_DEFAULT
:
659 if (EQ (specpdl_symbol (pdl
), symbol
))
667 DEFUN ("default-toplevel-value", Fdefault_toplevel_value
, Sdefault_toplevel_value
, 1, 1, 0,
668 doc
: /* Return SYMBOL's toplevel default value.
669 "Toplevel" means outside of any let binding. */)
672 union specbinding
*binding
= default_toplevel_binding (symbol
);
674 = binding
? specpdl_old_value (binding
) : Fdefault_value (symbol
);
675 if (!EQ (value
, Qunbound
))
677 xsignal1 (Qvoid_variable
, symbol
);
680 DEFUN ("set-default-toplevel-value", Fset_default_toplevel_value
,
681 Sset_default_toplevel_value
, 2, 2, 0,
682 doc
: /* Set SYMBOL's toplevel default value to VALUE.
683 "Toplevel" means outside of any let binding. */)
684 (Lisp_Object symbol
, Lisp_Object value
)
686 union specbinding
*binding
= default_toplevel_binding (symbol
);
688 set_specpdl_old_value (binding
, value
);
690 Fset_default (symbol
, value
);
694 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
695 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
696 You are not required to define a variable in order to use it, but
697 defining it lets you supply an initial value and documentation, which
698 can be referred to by the Emacs help facilities and other programming
699 tools. The `defvar' form also declares the variable as \"special\",
700 so that it is always dynamically bound even if `lexical-binding' is t.
702 The optional argument INITVALUE is evaluated, and used to set SYMBOL,
703 only if SYMBOL's value is void. If SYMBOL is buffer-local, its
704 default value is what is set; buffer-local values are not affected.
705 If INITVALUE is missing, SYMBOL's value is not set.
707 If SYMBOL has a local binding, then this form affects the local
708 binding. This is usually not what you want. Thus, if you need to
709 load a file defining variables, with this form or with `defconst' or
710 `defcustom', you should always load that file _outside_ any bindings
711 for these variables. \(`defconst' and `defcustom' behave similarly in
714 The optional argument DOCSTRING is a documentation string for the
717 To define a user option, use `defcustom' instead of `defvar'.
718 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
721 Lisp_Object sym
, tem
, tail
;
728 if (CONSP (XCDR (tail
)) && CONSP (XCDR (XCDR (tail
))))
729 error ("Too many arguments");
731 tem
= Fdefault_boundp (sym
);
733 /* Do it before evaluating the initial value, for self-references. */
734 XSYMBOL (sym
)->declared_special
= 1;
737 Fset_default (sym
, eval_sub (XCAR (tail
)));
739 { /* Check if there is really a global binding rather than just a let
740 binding that shadows the global unboundness of the var. */
741 union specbinding
*binding
= default_toplevel_binding (sym
);
742 if (binding
&& EQ (specpdl_old_value (binding
), Qunbound
))
744 set_specpdl_old_value (binding
, eval_sub (XCAR (tail
)));
751 if (!NILP (Vpurify_flag
))
752 tem
= Fpurecopy (tem
);
753 Fput (sym
, Qvariable_documentation
, tem
);
755 LOADHIST_ATTACH (sym
);
757 else if (!NILP (Vinternal_interpreter_environment
)
758 && !XSYMBOL (sym
)->declared_special
)
759 /* A simple (defvar foo) with lexical scoping does "nothing" except
760 declare that var to be dynamically scoped *locally* (i.e. within
761 the current file or let-block). */
762 Vinternal_interpreter_environment
763 = Fcons (sym
, Vinternal_interpreter_environment
);
766 /* Simple (defvar <var>) should not count as a definition at all.
767 It could get in the way of other definitions, and unloading this
768 package could try to make the variable unbound. */
774 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
775 doc
: /* Define SYMBOL as a constant variable.
776 This declares that neither programs nor users should ever change the
777 value. This constancy is not actually enforced by Emacs Lisp, but
778 SYMBOL is marked as a special variable so that it is never lexically
781 The `defconst' form always sets the value of SYMBOL to the result of
782 evalling INITVALUE. If SYMBOL is buffer-local, its default value is
783 what is set; buffer-local values are not affected. If SYMBOL has a
784 local binding, then this form sets the local binding's value.
785 However, you should normally not make local bindings for variables
786 defined with this form.
788 The optional DOCSTRING specifies the variable's documentation string.
789 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
792 Lisp_Object sym
, tem
;
795 if (CONSP (Fcdr (XCDR (XCDR (args
)))))
796 error ("Too many arguments");
798 tem
= eval_sub (Fcar (XCDR (args
)));
799 if (!NILP (Vpurify_flag
))
800 tem
= Fpurecopy (tem
);
801 Fset_default (sym
, tem
);
802 XSYMBOL (sym
)->declared_special
= 1;
803 tem
= Fcar (XCDR (XCDR (args
)));
806 if (!NILP (Vpurify_flag
))
807 tem
= Fpurecopy (tem
);
808 Fput (sym
, Qvariable_documentation
, tem
);
810 Fput (sym
, Qrisky_local_variable
, Qt
);
811 LOADHIST_ATTACH (sym
);
815 /* Make SYMBOL lexically scoped. */
816 DEFUN ("internal-make-var-non-special", Fmake_var_non_special
,
817 Smake_var_non_special
, 1, 1, 0,
818 doc
: /* Internal function. */)
821 CHECK_SYMBOL (symbol
);
822 XSYMBOL (symbol
)->declared_special
= 0;
827 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
828 doc
: /* Bind variables according to VARLIST then eval BODY.
829 The value of the last form in BODY is returned.
830 Each element of VARLIST is a symbol (which is bound to nil)
831 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
832 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
833 usage: (let* VARLIST BODY...) */)
836 Lisp_Object varlist
, var
, val
, elt
, lexenv
;
837 ptrdiff_t count
= SPECPDL_INDEX ();
838 struct gcpro gcpro1
, gcpro2
, gcpro3
;
840 GCPRO3 (args
, elt
, varlist
);
842 lexenv
= Vinternal_interpreter_environment
;
844 varlist
= XCAR (args
);
845 while (CONSP (varlist
))
849 elt
= XCAR (varlist
);
855 else if (! NILP (Fcdr (Fcdr (elt
))))
856 signal_error ("`let' bindings can have only one value-form", elt
);
860 val
= eval_sub (Fcar (Fcdr (elt
)));
863 if (!NILP (lexenv
) && SYMBOLP (var
)
864 && !XSYMBOL (var
)->declared_special
865 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
866 /* Lexically bind VAR by adding it to the interpreter's binding
870 = Fcons (Fcons (var
, val
), Vinternal_interpreter_environment
);
871 if (EQ (Vinternal_interpreter_environment
, lexenv
))
872 /* Save the old lexical environment on the specpdl stack,
873 but only for the first lexical binding, since we'll never
874 need to revert to one of the intermediate ones. */
875 specbind (Qinternal_interpreter_environment
, newenv
);
877 Vinternal_interpreter_environment
= newenv
;
882 varlist
= XCDR (varlist
);
885 val
= Fprogn (XCDR (args
));
886 return unbind_to (count
, val
);
889 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
890 doc
: /* Bind variables according to VARLIST then eval BODY.
891 The value of the last form in BODY is returned.
892 Each element of VARLIST is a symbol (which is bound to nil)
893 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
894 All the VALUEFORMs are evalled before any symbols are bound.
895 usage: (let VARLIST BODY...) */)
898 Lisp_Object
*temps
, tem
, lexenv
;
899 register Lisp_Object elt
, varlist
;
900 ptrdiff_t count
= SPECPDL_INDEX ();
902 struct gcpro gcpro1
, gcpro2
;
905 varlist
= XCAR (args
);
907 /* Make space to hold the values to give the bound variables. */
908 elt
= Flength (varlist
);
909 SAFE_ALLOCA_LISP (temps
, XFASTINT (elt
));
911 /* Compute the values and store them in `temps'. */
913 GCPRO2 (args
, *temps
);
916 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
919 elt
= XCAR (varlist
);
921 temps
[argnum
++] = Qnil
;
922 else if (! NILP (Fcdr (Fcdr (elt
))))
923 signal_error ("`let' bindings can have only one value-form", elt
);
925 temps
[argnum
++] = eval_sub (Fcar (Fcdr (elt
)));
926 gcpro2
.nvars
= argnum
;
930 lexenv
= Vinternal_interpreter_environment
;
932 varlist
= XCAR (args
);
933 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
937 elt
= XCAR (varlist
);
938 var
= SYMBOLP (elt
) ? elt
: Fcar (elt
);
939 tem
= temps
[argnum
++];
941 if (!NILP (lexenv
) && SYMBOLP (var
)
942 && !XSYMBOL (var
)->declared_special
943 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
944 /* Lexically bind VAR by adding it to the lexenv alist. */
945 lexenv
= Fcons (Fcons (var
, tem
), lexenv
);
947 /* Dynamically bind VAR. */
951 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
952 /* Instantiate a new lexical environment. */
953 specbind (Qinternal_interpreter_environment
, lexenv
);
955 elt
= Fprogn (XCDR (args
));
957 return unbind_to (count
, elt
);
960 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
961 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
962 The order of execution is thus TEST, BODY, TEST, BODY and so on
963 until TEST returns nil.
964 usage: (while TEST BODY...) */)
967 Lisp_Object test
, body
;
968 struct gcpro gcpro1
, gcpro2
;
974 while (!NILP (eval_sub (test
)))
984 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
985 doc
: /* Return result of expanding macros at top level of FORM.
986 If FORM is not a macro call, it is returned unchanged.
987 Otherwise, the macro is expanded and the expansion is considered
988 in place of FORM. When a non-macro-call results, it is returned.
990 The second optional arg ENVIRONMENT specifies an environment of macro
991 definitions to shadow the loaded ones for use in file byte-compilation. */)
992 (Lisp_Object form
, Lisp_Object environment
)
994 /* With cleanups from Hallvard Furuseth. */
995 register Lisp_Object expander
, sym
, def
, tem
;
999 /* Come back here each time we expand a macro call,
1000 in case it expands into another macro call. */
1003 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1004 def
= sym
= XCAR (form
);
1006 /* Trace symbols aliases to other symbols
1007 until we get a symbol that is not an alias. */
1008 while (SYMBOLP (def
))
1012 tem
= Fassq (sym
, environment
);
1015 def
= XSYMBOL (sym
)->function
;
1021 /* Right now TEM is the result from SYM in ENVIRONMENT,
1022 and if TEM is nil then DEF is SYM's function definition. */
1025 /* SYM is not mentioned in ENVIRONMENT.
1026 Look at its function definition. */
1027 struct gcpro gcpro1
;
1029 def
= Fautoload_do_load (def
, sym
, Qmacro
);
1032 /* Not defined or definition not suitable. */
1034 if (!EQ (XCAR (def
), Qmacro
))
1036 else expander
= XCDR (def
);
1040 expander
= XCDR (tem
);
1041 if (NILP (expander
))
1045 Lisp_Object newform
= apply1 (expander
, XCDR (form
));
1046 if (EQ (form
, newform
))
1055 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1056 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1057 TAG is evalled to get the tag to use; it must not be nil.
1059 Then the BODY is executed.
1060 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1061 If no throw happens, `catch' returns the value of the last BODY form.
1062 If a throw happens, it specifies the value to return from `catch'.
1063 usage: (catch TAG BODY...) */)
1066 register Lisp_Object tag
;
1067 struct gcpro gcpro1
;
1070 tag
= eval_sub (XCAR (args
));
1072 return internal_catch (tag
, Fprogn
, XCDR (args
));
1075 /* Assert that E is true, as a comment only. Use this instead of
1076 eassert (E) when E contains variables that might be clobbered by a
1079 #define clobbered_eassert(E) ((void) 0)
1081 /* Set up a catch, then call C function FUNC on argument ARG.
1082 FUNC should return a Lisp_Object.
1083 This is how catches are done from within C code. */
1086 internal_catch (Lisp_Object tag
, Lisp_Object (*func
) (Lisp_Object
), Lisp_Object arg
)
1088 /* This structure is made part of the chain `catchlist'. */
1091 /* Fill in the components of c, and put it on the list. */
1092 PUSH_HANDLER (c
, tag
, CATCHER
);
1095 if (! sys_setjmp (c
->jmp
))
1097 Lisp_Object val
= (*func
) (arg
);
1098 clobbered_eassert (handlerlist
== c
);
1099 handlerlist
= handlerlist
->next
;
1103 { /* Throw works by a longjmp that comes right here. */
1104 Lisp_Object val
= handlerlist
->val
;
1105 clobbered_eassert (handlerlist
== c
);
1106 handlerlist
= handlerlist
->next
;
1111 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1112 jump to that CATCH, returning VALUE as the value of that catch.
1114 This is the guts of Fthrow and Fsignal; they differ only in the way
1115 they choose the catch tag to throw to. A catch tag for a
1116 condition-case form has a TAG of Qnil.
1118 Before each catch is discarded, unbind all special bindings and
1119 execute all unwind-protect clauses made above that catch. Unwind
1120 the handler stack as we go, so that the proper handlers are in
1121 effect for each unwind-protect clause we run. At the end, restore
1122 some static info saved in CATCH, and longjmp to the location
1125 This is used for correct unwinding in Fthrow and Fsignal. */
1127 static _Noreturn
void
1128 unwind_to_catch (struct handler
*catch, Lisp_Object value
)
1132 /* Save the value in the tag. */
1135 /* Restore certain special C variables. */
1136 set_poll_suppress_count (catch->poll_suppress_count
);
1137 unblock_input_to (catch->interrupt_input_blocked
);
1142 /* Unwind the specpdl stack, and then restore the proper set of
1144 unbind_to (handlerlist
->pdlcount
, Qnil
);
1145 last_time
= handlerlist
== catch;
1147 handlerlist
= handlerlist
->next
;
1149 while (! last_time
);
1151 eassert (handlerlist
== catch);
1153 byte_stack_list
= catch->byte_stack
;
1154 gcprolist
= catch->gcpro
;
1156 gcpro_level
= gcprolist
? gcprolist
->level
+ 1 : 0;
1158 lisp_eval_depth
= catch->lisp_eval_depth
;
1160 sys_longjmp (catch->jmp
, 1);
1163 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1164 doc
: /* Throw to the catch for TAG and return VALUE from it.
1165 Both TAG and VALUE are evalled. */)
1166 (register Lisp_Object tag
, Lisp_Object value
)
1171 for (c
= handlerlist
; c
; c
= c
->next
)
1173 if (c
->type
== CATCHER
&& EQ (c
->tag_or_ch
, tag
))
1174 unwind_to_catch (c
, value
);
1176 xsignal2 (Qno_catch
, tag
, value
);
1180 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1181 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1182 If BODYFORM completes normally, its value is returned
1183 after executing the UNWINDFORMS.
1184 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1185 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1189 ptrdiff_t count
= SPECPDL_INDEX ();
1191 record_unwind_protect (unwind_body
, XCDR (args
));
1192 val
= eval_sub (XCAR (args
));
1193 return unbind_to (count
, val
);
1196 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1197 doc
: /* Regain control when an error is signaled.
1198 Executes BODYFORM and returns its value if no error happens.
1199 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1200 where the BODY is made of Lisp expressions.
1202 A handler is applicable to an error
1203 if CONDITION-NAME is one of the error's condition names.
1204 If an error happens, the first applicable handler is run.
1206 The car of a handler may be a list of condition names instead of a
1207 single condition name; then it handles all of them. If the special
1208 condition name `debug' is present in this list, it allows another
1209 condition in the list to run the debugger if `debug-on-error' and the
1210 other usual mechanisms says it should (otherwise, `condition-case'
1211 suppresses the debugger).
1213 When a handler handles an error, control returns to the `condition-case'
1214 and it executes the handler's BODY...
1215 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1216 \(If VAR is nil, the handler can't access that information.)
1217 Then the value of the last BODY form is returned from the `condition-case'
1220 See also the function `signal' for more info.
1221 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1224 Lisp_Object var
= XCAR (args
);
1225 Lisp_Object bodyform
= XCAR (XCDR (args
));
1226 Lisp_Object handlers
= XCDR (XCDR (args
));
1228 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1231 /* Like Fcondition_case, but the args are separate
1232 rather than passed in a list. Used by Fbyte_code. */
1235 internal_lisp_condition_case (volatile Lisp_Object var
, Lisp_Object bodyform
,
1236 Lisp_Object handlers
)
1240 struct handler
*oldhandlerlist
= handlerlist
;
1245 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1247 Lisp_Object tem
= XCAR (val
);
1251 && (SYMBOLP (XCAR (tem
))
1252 || CONSP (XCAR (tem
))))))
1253 error ("Invalid condition handler: %s",
1254 SDATA (Fprin1_to_string (tem
, Qt
)));
1257 { /* The first clause is the one that should be checked first, so it should
1258 be added to handlerlist last. So we build in `clauses' a table that
1259 contains `handlers' but in reverse order. */
1260 Lisp_Object
*clauses
= alloca (clausenb
* sizeof (Lisp_Object
*));
1261 Lisp_Object
*volatile clauses_volatile
= clauses
;
1263 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1264 clauses
[--i
] = XCAR (val
);
1265 for (i
= 0; i
< clausenb
; i
++)
1267 Lisp_Object clause
= clauses
[i
];
1268 Lisp_Object condition
= XCAR (clause
);
1269 if (!CONSP (condition
))
1270 condition
= Fcons (condition
, Qnil
);
1271 PUSH_HANDLER (c
, condition
, CONDITION_CASE
);
1272 if (sys_setjmp (c
->jmp
))
1274 ptrdiff_t count
= SPECPDL_INDEX ();
1275 Lisp_Object val
= handlerlist
->val
;
1276 Lisp_Object
*chosen_clause
= clauses_volatile
;
1277 for (c
= handlerlist
->next
; c
!= oldhandlerlist
; c
= c
->next
)
1279 handlerlist
= oldhandlerlist
;
1282 if (!NILP (Vinternal_interpreter_environment
))
1283 specbind (Qinternal_interpreter_environment
,
1284 Fcons (Fcons (var
, val
),
1285 Vinternal_interpreter_environment
));
1287 specbind (var
, val
);
1289 val
= Fprogn (XCDR (*chosen_clause
));
1290 /* Note that this just undoes the binding of var; whoever
1291 longjumped to us unwound the stack to c.pdlcount before
1294 unbind_to (count
, Qnil
);
1300 val
= eval_sub (bodyform
);
1301 handlerlist
= oldhandlerlist
;
1305 /* Call the function BFUN with no arguments, catching errors within it
1306 according to HANDLERS. If there is an error, call HFUN with
1307 one argument which is the data that describes the error:
1310 HANDLERS can be a list of conditions to catch.
1311 If HANDLERS is Qt, catch all errors.
1312 If HANDLERS is Qerror, catch all errors
1313 but allow the debugger to run if that is enabled. */
1316 internal_condition_case (Lisp_Object (*bfun
) (void), Lisp_Object handlers
,
1317 Lisp_Object (*hfun
) (Lisp_Object
))
1322 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1323 if (sys_setjmp (c
->jmp
))
1325 Lisp_Object val
= handlerlist
->val
;
1326 clobbered_eassert (handlerlist
== c
);
1327 handlerlist
= handlerlist
->next
;
1328 return (*hfun
) (val
);
1332 clobbered_eassert (handlerlist
== c
);
1333 handlerlist
= handlerlist
->next
;
1337 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1340 internal_condition_case_1 (Lisp_Object (*bfun
) (Lisp_Object
), Lisp_Object arg
,
1341 Lisp_Object handlers
, Lisp_Object (*hfun
) (Lisp_Object
))
1346 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1347 if (sys_setjmp (c
->jmp
))
1349 Lisp_Object val
= handlerlist
->val
;
1350 clobbered_eassert (handlerlist
== c
);
1351 handlerlist
= handlerlist
->next
;
1352 return (*hfun
) (val
);
1355 val
= (*bfun
) (arg
);
1356 clobbered_eassert (handlerlist
== c
);
1357 handlerlist
= handlerlist
->next
;
1361 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1365 internal_condition_case_2 (Lisp_Object (*bfun
) (Lisp_Object
, Lisp_Object
),
1368 Lisp_Object handlers
,
1369 Lisp_Object (*hfun
) (Lisp_Object
))
1374 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1375 if (sys_setjmp (c
->jmp
))
1377 Lisp_Object val
= handlerlist
->val
;
1378 clobbered_eassert (handlerlist
== c
);
1379 handlerlist
= handlerlist
->next
;
1380 return (*hfun
) (val
);
1383 val
= (*bfun
) (arg1
, arg2
);
1384 clobbered_eassert (handlerlist
== c
);
1385 handlerlist
= handlerlist
->next
;
1389 /* Like internal_condition_case but call BFUN with NARGS as first,
1390 and ARGS as second argument. */
1393 internal_condition_case_n (Lisp_Object (*bfun
) (ptrdiff_t, Lisp_Object
*),
1396 Lisp_Object handlers
,
1397 Lisp_Object (*hfun
) (Lisp_Object err
,
1404 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1405 if (sys_setjmp (c
->jmp
))
1407 Lisp_Object val
= handlerlist
->val
;
1408 clobbered_eassert (handlerlist
== c
);
1409 handlerlist
= handlerlist
->next
;
1410 return (*hfun
) (val
, nargs
, args
);
1413 val
= (*bfun
) (nargs
, args
);
1414 clobbered_eassert (handlerlist
== c
);
1415 handlerlist
= handlerlist
->next
;
1420 static Lisp_Object
find_handler_clause (Lisp_Object
, Lisp_Object
);
1421 static bool maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
,
1425 process_quit_flag (void)
1427 Lisp_Object flag
= Vquit_flag
;
1429 if (EQ (flag
, Qkill_emacs
))
1431 if (EQ (Vthrow_on_input
, flag
))
1432 Fthrow (Vthrow_on_input
, Qt
);
1433 Fsignal (Qquit
, Qnil
);
1436 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1437 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1438 This function does not return.
1440 An error symbol is a symbol with an `error-conditions' property
1441 that is a list of condition names.
1442 A handler for any of those names will get to handle this signal.
1443 The symbol `error' should normally be one of them.
1445 DATA should be a list. Its elements are printed as part of the error message.
1446 See Info anchor `(elisp)Definition of signal' for some details on how this
1447 error message is constructed.
1448 If the signal is handled, DATA is made available to the handler.
1449 See also the function `condition-case'. */)
1450 (Lisp_Object error_symbol
, Lisp_Object data
)
1452 /* When memory is full, ERROR-SYMBOL is nil,
1453 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1454 That is a special case--don't do this in other situations. */
1455 Lisp_Object conditions
;
1457 Lisp_Object real_error_symbol
1458 = (NILP (error_symbol
) ? Fcar (data
) : error_symbol
);
1459 register Lisp_Object clause
= Qnil
;
1464 if (gc_in_progress
|| waiting_for_input
)
1467 #if 0 /* rms: I don't know why this was here,
1468 but it is surely wrong for an error that is handled. */
1469 #ifdef HAVE_WINDOW_SYSTEM
1470 if (display_hourglass_p
)
1471 cancel_hourglass ();
1475 /* This hook is used by edebug. */
1476 if (! NILP (Vsignal_hook_function
)
1477 && ! NILP (error_symbol
))
1479 /* Edebug takes care of restoring these variables when it exits. */
1480 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1481 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1483 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1484 max_specpdl_size
= SPECPDL_INDEX () + 40;
1486 call2 (Vsignal_hook_function
, error_symbol
, data
);
1489 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1491 /* Remember from where signal was called. Skip over the frame for
1492 `signal' itself. If a frame for `error' follows, skip that,
1493 too. Don't do this when ERROR_SYMBOL is nil, because that
1494 is a memory-full error. */
1495 Vsignaling_function
= Qnil
;
1496 if (!NILP (error_symbol
))
1498 union specbinding
*pdl
= backtrace_next (backtrace_top ());
1499 if (backtrace_p (pdl
) && EQ (backtrace_function (pdl
), Qerror
))
1500 pdl
= backtrace_next (pdl
);
1501 if (backtrace_p (pdl
))
1502 Vsignaling_function
= backtrace_function (pdl
);
1505 for (h
= handlerlist
; h
; h
= h
->next
)
1507 if (h
->type
!= CONDITION_CASE
)
1509 clause
= find_handler_clause (h
->tag_or_ch
, conditions
);
1514 if (/* Don't run the debugger for a memory-full error.
1515 (There is no room in memory to do that!) */
1516 !NILP (error_symbol
)
1517 && (!NILP (Vdebug_on_signal
)
1518 /* If no handler is present now, try to run the debugger. */
1520 /* A `debug' symbol in the handler list disables the normal
1521 suppression of the debugger. */
1522 || (CONSP (clause
) && CONSP (XCAR (clause
))
1523 && !NILP (Fmemq (Qdebug
, XCAR (clause
))))
1524 /* Special handler that means "print a message and run debugger
1526 || EQ (h
->tag_or_ch
, Qerror
)))
1528 bool debugger_called
1529 = maybe_call_debugger (conditions
, error_symbol
, data
);
1530 /* We can't return values to code which signaled an error, but we
1531 can continue code which has signaled a quit. */
1532 if (debugger_called
&& EQ (real_error_symbol
, Qquit
))
1538 Lisp_Object unwind_data
1539 = (NILP (error_symbol
) ? data
: Fcons (error_symbol
, data
));
1541 unwind_to_catch (h
, unwind_data
);
1545 if (handlerlist
!= 0)
1546 Fthrow (Qtop_level
, Qt
);
1549 if (! NILP (error_symbol
))
1550 data
= Fcons (error_symbol
, data
);
1552 string
= Ferror_message_string (data
);
1553 fatal ("%s", SDATA (string
));
1556 /* Internal version of Fsignal that never returns.
1557 Used for anything but Qquit (which can return from Fsignal). */
1560 xsignal (Lisp_Object error_symbol
, Lisp_Object data
)
1562 Fsignal (error_symbol
, data
);
1566 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1569 xsignal0 (Lisp_Object error_symbol
)
1571 xsignal (error_symbol
, Qnil
);
1575 xsignal1 (Lisp_Object error_symbol
, Lisp_Object arg
)
1577 xsignal (error_symbol
, list1 (arg
));
1581 xsignal2 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
)
1583 xsignal (error_symbol
, list2 (arg1
, arg2
));
1587 xsignal3 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
1589 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1592 /* Signal `error' with message S, and additional arg ARG.
1593 If ARG is not a genuine list, make it a one-element list. */
1596 signal_error (const char *s
, Lisp_Object arg
)
1598 Lisp_Object tortoise
, hare
;
1600 hare
= tortoise
= arg
;
1601 while (CONSP (hare
))
1608 tortoise
= XCDR (tortoise
);
1610 if (EQ (hare
, tortoise
))
1617 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1621 /* Return true if LIST is a non-nil atom or
1622 a list containing one of CONDITIONS. */
1625 wants_debugger (Lisp_Object list
, Lisp_Object conditions
)
1632 while (CONSP (conditions
))
1634 Lisp_Object
this, tail
;
1635 this = XCAR (conditions
);
1636 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1637 if (EQ (XCAR (tail
), this))
1639 conditions
= XCDR (conditions
);
1644 /* Return true if an error with condition-symbols CONDITIONS,
1645 and described by SIGNAL-DATA, should skip the debugger
1646 according to debugger-ignored-errors. */
1649 skip_debugger (Lisp_Object conditions
, Lisp_Object data
)
1652 bool first_string
= 1;
1653 Lisp_Object error_message
;
1655 error_message
= Qnil
;
1656 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1658 if (STRINGP (XCAR (tail
)))
1662 error_message
= Ferror_message_string (data
);
1666 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1671 Lisp_Object contail
;
1673 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1674 if (EQ (XCAR (tail
), XCAR (contail
)))
1682 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1683 SIG and DATA describe the signal. There are two ways to pass them:
1684 = SIG is the error symbol, and DATA is the rest of the data.
1685 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1686 This is for memory-full errors only. */
1688 maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
, Lisp_Object data
)
1690 Lisp_Object combined_data
;
1692 combined_data
= Fcons (sig
, data
);
1695 /* Don't try to run the debugger with interrupts blocked.
1696 The editing loop would return anyway. */
1697 ! input_blocked_p ()
1698 && NILP (Vinhibit_debugger
)
1699 /* Does user want to enter debugger for this kind of error? */
1702 : wants_debugger (Vdebug_on_error
, conditions
))
1703 && ! skip_debugger (conditions
, combined_data
)
1704 /* RMS: What's this for? */
1705 && when_entered_debugger
< num_nonmacro_input_events
)
1707 call_debugger (list2 (Qerror
, combined_data
));
1715 find_handler_clause (Lisp_Object handlers
, Lisp_Object conditions
)
1717 register Lisp_Object h
;
1719 /* t is used by handlers for all conditions, set up by C code. */
1720 if (EQ (handlers
, Qt
))
1723 /* error is used similarly, but means print an error message
1724 and run the debugger if that is enabled. */
1725 if (EQ (handlers
, Qerror
))
1728 for (h
= handlers
; CONSP (h
); h
= XCDR (h
))
1730 Lisp_Object handler
= XCAR (h
);
1731 if (!NILP (Fmemq (handler
, conditions
)))
1739 /* Dump an error message; called like vprintf. */
1741 verror (const char *m
, va_list ap
)
1744 ptrdiff_t size
= sizeof buf
;
1745 ptrdiff_t size_max
= STRING_BYTES_BOUND
+ 1;
1750 used
= evxprintf (&buffer
, &size
, buf
, size_max
, m
, ap
);
1751 string
= make_string (buffer
, used
);
1755 xsignal1 (Qerror
, string
);
1759 /* Dump an error message; called like printf. */
1763 error (const char *m
, ...)
1770 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1771 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1772 This means it contains a description for how to read arguments to give it.
1773 The value is nil for an invalid function or a symbol with no function
1776 Interactively callable functions include strings and vectors (treated
1777 as keyboard macros), lambda-expressions that contain a top-level call
1778 to `interactive', autoload definitions made by `autoload' with non-nil
1779 fourth argument, and some of the built-in functions of Lisp.
1781 Also, a symbol satisfies `commandp' if its function definition does so.
1783 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1784 then strings and vectors are not accepted. */)
1785 (Lisp_Object function
, Lisp_Object for_call_interactively
)
1787 register Lisp_Object fun
;
1788 register Lisp_Object funcar
;
1789 Lisp_Object if_prop
= Qnil
;
1793 fun
= indirect_function (fun
); /* Check cycles. */
1797 /* Check an `interactive-form' property if present, analogous to the
1798 function-documentation property. */
1800 while (SYMBOLP (fun
))
1802 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
1805 fun
= Fsymbol_function (fun
);
1808 /* Emacs primitives are interactive if their DEFUN specifies an
1809 interactive spec. */
1811 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
1813 /* Bytecode objects are interactive if they are long enough to
1814 have an element whose index is COMPILED_INTERACTIVE, which is
1815 where the interactive spec is stored. */
1816 else if (COMPILEDP (fun
))
1817 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1820 /* Strings and vectors are keyboard macros. */
1821 if (STRINGP (fun
) || VECTORP (fun
))
1822 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
1824 /* Lists may represent commands. */
1827 funcar
= XCAR (fun
);
1828 if (EQ (funcar
, Qclosure
))
1829 return (!NILP (Fassq (Qinteractive
, Fcdr (Fcdr (XCDR (fun
)))))
1831 else if (EQ (funcar
, Qlambda
))
1832 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
1833 else if (EQ (funcar
, Qautoload
))
1834 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
1839 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1840 doc
: /* Define FUNCTION to autoload from FILE.
1841 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1842 Third arg DOCSTRING is documentation for the function.
1843 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1844 Fifth arg TYPE indicates the type of the object:
1845 nil or omitted says FUNCTION is a function,
1846 `keymap' says FUNCTION is really a keymap, and
1847 `macro' or t says FUNCTION is really a macro.
1848 Third through fifth args give info about the real definition.
1849 They default to nil.
1850 If FUNCTION is already defined other than as an autoload,
1851 this does nothing and returns nil. */)
1852 (Lisp_Object function
, Lisp_Object file
, Lisp_Object docstring
, Lisp_Object interactive
, Lisp_Object type
)
1854 CHECK_SYMBOL (function
);
1855 CHECK_STRING (file
);
1857 /* If function is defined and not as an autoload, don't override. */
1858 if (!NILP (XSYMBOL (function
)->function
)
1859 && !AUTOLOADP (XSYMBOL (function
)->function
))
1862 if (!NILP (Vpurify_flag
) && EQ (docstring
, make_number (0)))
1863 /* `read1' in lread.c has found the docstring starting with "\
1864 and assumed the docstring will be provided by Snarf-documentation, so it
1865 passed us 0 instead. But that leads to accidental sharing in purecopy's
1866 hash-consing, so we use a (hopefully) unique integer instead. */
1867 docstring
= make_number (XHASH (function
));
1868 return Fdefalias (function
,
1869 list5 (Qautoload
, file
, docstring
, interactive
, type
),
1874 un_autoload (Lisp_Object oldqueue
)
1876 Lisp_Object queue
, first
, second
;
1878 /* Queue to unwind is current value of Vautoload_queue.
1879 oldqueue is the shadowed value to leave in Vautoload_queue. */
1880 queue
= Vautoload_queue
;
1881 Vautoload_queue
= oldqueue
;
1882 while (CONSP (queue
))
1884 first
= XCAR (queue
);
1885 second
= Fcdr (first
);
1886 first
= Fcar (first
);
1887 if (EQ (first
, make_number (0)))
1890 Ffset (first
, second
);
1891 queue
= XCDR (queue
);
1895 /* Load an autoloaded function.
1896 FUNNAME is the symbol which is the function's name.
1897 FUNDEF is the autoload definition (a list). */
1899 DEFUN ("autoload-do-load", Fautoload_do_load
, Sautoload_do_load
, 1, 3, 0,
1900 doc
: /* Load FUNDEF which should be an autoload.
1901 If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1902 in which case the function returns the new autoloaded function value.
1903 If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1904 it is defines a macro. */)
1905 (Lisp_Object fundef
, Lisp_Object funname
, Lisp_Object macro_only
)
1907 ptrdiff_t count
= SPECPDL_INDEX ();
1908 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1910 if (!CONSP (fundef
) || !EQ (Qautoload
, XCAR (fundef
)))
1913 if (EQ (macro_only
, Qmacro
))
1915 Lisp_Object kind
= Fnth (make_number (4), fundef
);
1916 if (! (EQ (kind
, Qt
) || EQ (kind
, Qmacro
)))
1920 /* This is to make sure that loadup.el gives a clear picture
1921 of what files are preloaded and when. */
1922 if (! NILP (Vpurify_flag
))
1923 error ("Attempt to autoload %s while preparing to dump",
1924 SDATA (SYMBOL_NAME (funname
)));
1926 CHECK_SYMBOL (funname
);
1927 GCPRO3 (funname
, fundef
, macro_only
);
1929 /* Preserve the match data. */
1930 record_unwind_save_match_data ();
1932 /* If autoloading gets an error (which includes the error of failing
1933 to define the function being called), we use Vautoload_queue
1934 to undo function definitions and `provide' calls made by
1935 the function. We do this in the specific case of autoloading
1936 because autoloading is not an explicit request "load this file",
1937 but rather a request to "call this function".
1939 The value saved here is to be restored into Vautoload_queue. */
1940 record_unwind_protect (un_autoload
, Vautoload_queue
);
1941 Vautoload_queue
= Qt
;
1942 /* If `macro_only', assume this autoload to be a "best-effort",
1943 so don't signal an error if autoloading fails. */
1944 Fload (Fcar (Fcdr (fundef
)), macro_only
, Qt
, Qnil
, Qt
);
1946 /* Once loading finishes, don't undo it. */
1947 Vautoload_queue
= Qt
;
1948 unbind_to (count
, Qnil
);
1956 Lisp_Object fun
= Findirect_function (funname
, Qnil
);
1958 if (!NILP (Fequal (fun
, fundef
)))
1959 error ("Autoloading failed to define function %s",
1960 SDATA (SYMBOL_NAME (funname
)));
1967 DEFUN ("eval", Feval
, Seval
, 1, 2, 0,
1968 doc
: /* Evaluate FORM and return its value.
1969 If LEXICAL is t, evaluate using lexical scoping.
1970 LEXICAL can also be an actual lexical environment, in the form of an
1971 alist mapping symbols to their value. */)
1972 (Lisp_Object form
, Lisp_Object lexical
)
1974 ptrdiff_t count
= SPECPDL_INDEX ();
1975 specbind (Qinternal_interpreter_environment
,
1976 CONSP (lexical
) || NILP (lexical
) ? lexical
: list1 (Qt
));
1977 return unbind_to (count
, eval_sub (form
));
1980 /* Grow the specpdl stack by one entry.
1981 The caller should have already initialized the entry.
1982 Signal an error on stack overflow.
1984 Make sure that there is always one unused entry past the top of the
1985 stack, so that the just-initialized entry is safely unwound if
1986 memory exhausted and an error is signaled here. Also, allocate a
1987 never-used entry just before the bottom of the stack; sometimes its
1988 address is taken. */
1995 if (specpdl_ptr
== specpdl
+ specpdl_size
)
1997 ptrdiff_t count
= SPECPDL_INDEX ();
1998 ptrdiff_t max_size
= min (max_specpdl_size
, PTRDIFF_MAX
- 1000);
1999 union specbinding
*pdlvec
= specpdl
- 1;
2000 ptrdiff_t pdlvecsize
= specpdl_size
+ 1;
2001 if (max_size
<= specpdl_size
)
2003 if (max_specpdl_size
< 400)
2004 max_size
= max_specpdl_size
= 400;
2005 if (max_size
<= specpdl_size
)
2006 signal_error ("Variable binding depth exceeds max-specpdl-size",
2009 pdlvec
= xpalloc (pdlvec
, &pdlvecsize
, 1, max_size
+ 1, sizeof *specpdl
);
2010 specpdl
= pdlvec
+ 1;
2011 specpdl_size
= pdlvecsize
- 1;
2012 specpdl_ptr
= specpdl
+ count
;
2017 record_in_backtrace (Lisp_Object function
, Lisp_Object
*args
, ptrdiff_t nargs
)
2019 eassert (nargs
>= UNEVALLED
);
2020 specpdl_ptr
->bt
.kind
= SPECPDL_BACKTRACE
;
2021 specpdl_ptr
->bt
.debug_on_exit
= false;
2022 specpdl_ptr
->bt
.function
= function
;
2023 specpdl_ptr
->bt
.args
= args
;
2024 specpdl_ptr
->bt
.nargs
= nargs
;
2028 /* Eval a sub-expression of the current expression (i.e. in the same
2031 eval_sub (Lisp_Object form
)
2033 Lisp_Object fun
, val
, original_fun
, original_args
;
2035 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2039 /* Look up its binding in the lexical environment.
2040 We do not pay attention to the declared_special flag here, since we
2041 already did that when let-binding the variable. */
2042 Lisp_Object lex_binding
2043 = !NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
2044 ? Fassq (form
, Vinternal_interpreter_environment
)
2046 if (CONSP (lex_binding
))
2047 return XCDR (lex_binding
);
2049 return Fsymbol_value (form
);
2061 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2063 if (max_lisp_eval_depth
< 100)
2064 max_lisp_eval_depth
= 100;
2065 if (lisp_eval_depth
> max_lisp_eval_depth
)
2066 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2069 original_fun
= XCAR (form
);
2070 original_args
= XCDR (form
);
2072 /* This also protects them from gc. */
2073 record_in_backtrace (original_fun
, &original_args
, UNEVALLED
);
2075 if (debug_on_next_call
)
2076 do_debug_on_call (Qt
);
2078 /* At this point, only original_fun and original_args
2079 have values that will be used below. */
2082 /* Optimize for no indirection. */
2085 fun
= Ffunction (Fcons (fun
, Qnil
));
2086 else if (!NILP (fun
) && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2087 fun
= indirect_function (fun
);
2091 Lisp_Object numargs
;
2092 Lisp_Object argvals
[8];
2093 Lisp_Object args_left
;
2094 register int i
, maxargs
;
2096 args_left
= original_args
;
2097 numargs
= Flength (args_left
);
2101 if (XINT (numargs
) < XSUBR (fun
)->min_args
2102 || (XSUBR (fun
)->max_args
>= 0
2103 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2104 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2106 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2107 val
= (XSUBR (fun
)->function
.aUNEVALLED
) (args_left
);
2108 else if (XSUBR (fun
)->max_args
== MANY
)
2110 /* Pass a vector of evaluated arguments. */
2112 ptrdiff_t argnum
= 0;
2115 SAFE_ALLOCA_LISP (vals
, XINT (numargs
));
2117 GCPRO3 (args_left
, fun
, fun
);
2121 while (!NILP (args_left
))
2123 vals
[argnum
++] = eval_sub (Fcar (args_left
));
2124 args_left
= Fcdr (args_left
);
2125 gcpro3
.nvars
= argnum
;
2128 set_backtrace_args (specpdl_ptr
- 1, vals
);
2129 set_backtrace_nargs (specpdl_ptr
- 1, XINT (numargs
));
2131 val
= (XSUBR (fun
)->function
.aMANY
) (XINT (numargs
), vals
);
2137 GCPRO3 (args_left
, fun
, fun
);
2138 gcpro3
.var
= argvals
;
2141 maxargs
= XSUBR (fun
)->max_args
;
2142 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2144 argvals
[i
] = eval_sub (Fcar (args_left
));
2150 set_backtrace_args (specpdl_ptr
- 1, argvals
);
2151 set_backtrace_nargs (specpdl_ptr
- 1, XINT (numargs
));
2156 val
= (XSUBR (fun
)->function
.a0 ());
2159 val
= (XSUBR (fun
)->function
.a1 (argvals
[0]));
2162 val
= (XSUBR (fun
)->function
.a2 (argvals
[0], argvals
[1]));
2165 val
= (XSUBR (fun
)->function
.a3
2166 (argvals
[0], argvals
[1], argvals
[2]));
2169 val
= (XSUBR (fun
)->function
.a4
2170 (argvals
[0], argvals
[1], argvals
[2], argvals
[3]));
2173 val
= (XSUBR (fun
)->function
.a5
2174 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2178 val
= (XSUBR (fun
)->function
.a6
2179 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2180 argvals
[4], argvals
[5]));
2183 val
= (XSUBR (fun
)->function
.a7
2184 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2185 argvals
[4], argvals
[5], argvals
[6]));
2189 val
= (XSUBR (fun
)->function
.a8
2190 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2191 argvals
[4], argvals
[5], argvals
[6], argvals
[7]));
2195 /* Someone has created a subr that takes more arguments than
2196 is supported by this code. We need to either rewrite the
2197 subr to use a different argument protocol, or add more
2198 cases to this switch. */
2203 else if (COMPILEDP (fun
))
2204 val
= apply_lambda (fun
, original_args
);
2208 xsignal1 (Qvoid_function
, original_fun
);
2210 xsignal1 (Qinvalid_function
, original_fun
);
2211 funcar
= XCAR (fun
);
2212 if (!SYMBOLP (funcar
))
2213 xsignal1 (Qinvalid_function
, original_fun
);
2214 if (EQ (funcar
, Qautoload
))
2216 Fautoload_do_load (fun
, original_fun
, Qnil
);
2219 if (EQ (funcar
, Qmacro
))
2221 ptrdiff_t count
= SPECPDL_INDEX ();
2223 /* Bind lexical-binding during expansion of the macro, so the
2224 macro can know reliably if the code it outputs will be
2225 interpreted using lexical-binding or not. */
2226 specbind (Qlexical_binding
,
2227 NILP (Vinternal_interpreter_environment
) ? Qnil
: Qt
);
2228 exp
= apply1 (Fcdr (fun
), original_args
);
2229 unbind_to (count
, Qnil
);
2230 val
= eval_sub (exp
);
2232 else if (EQ (funcar
, Qlambda
)
2233 || EQ (funcar
, Qclosure
))
2234 val
= apply_lambda (fun
, original_args
);
2236 xsignal1 (Qinvalid_function
, original_fun
);
2241 if (backtrace_debug_on_exit (specpdl_ptr
- 1))
2242 val
= call_debugger (list2 (Qexit
, val
));
2248 DEFUN ("apply", Fapply
, Sapply
, 1, MANY
, 0,
2249 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2250 Then return the value FUNCTION returns.
2251 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2252 usage: (apply FUNCTION &rest ARGUMENTS) */)
2253 (ptrdiff_t nargs
, Lisp_Object
*args
)
2257 register Lisp_Object spread_arg
;
2258 register Lisp_Object
*funcall_args
;
2259 Lisp_Object fun
, retval
;
2260 struct gcpro gcpro1
;
2265 spread_arg
= args
[nargs
- 1];
2266 CHECK_LIST (spread_arg
);
2268 numargs
= XINT (Flength (spread_arg
));
2271 return Ffuncall (nargs
- 1, args
);
2272 else if (numargs
== 1)
2274 args
[nargs
- 1] = XCAR (spread_arg
);
2275 return Ffuncall (nargs
, args
);
2278 numargs
+= nargs
- 2;
2280 /* Optimize for no indirection. */
2281 if (SYMBOLP (fun
) && !NILP (fun
)
2282 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2283 fun
= indirect_function (fun
);
2286 /* Let funcall get the error. */
2293 if (numargs
< XSUBR (fun
)->min_args
2294 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2295 goto funcall
; /* Let funcall get the error. */
2296 else if (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
> numargs
)
2298 /* Avoid making funcall cons up a yet another new vector of arguments
2299 by explicitly supplying nil's for optional values. */
2300 SAFE_ALLOCA_LISP (funcall_args
, 1 + XSUBR (fun
)->max_args
);
2301 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2302 funcall_args
[++i
] = Qnil
;
2303 GCPRO1 (*funcall_args
);
2304 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2308 /* We add 1 to numargs because funcall_args includes the
2309 function itself as well as its arguments. */
2312 SAFE_ALLOCA_LISP (funcall_args
, 1 + numargs
);
2313 GCPRO1 (*funcall_args
);
2314 gcpro1
.nvars
= 1 + numargs
;
2317 memcpy (funcall_args
, args
, nargs
* word_size
);
2318 /* Spread the last arg we got. Its first element goes in
2319 the slot that it used to occupy, hence this value of I. */
2321 while (!NILP (spread_arg
))
2323 funcall_args
[i
++] = XCAR (spread_arg
);
2324 spread_arg
= XCDR (spread_arg
);
2327 /* By convention, the caller needs to gcpro Ffuncall's args. */
2328 retval
= Ffuncall (gcpro1
.nvars
, funcall_args
);
2335 /* Run hook variables in various ways. */
2338 funcall_nil (ptrdiff_t nargs
, Lisp_Object
*args
)
2340 Ffuncall (nargs
, args
);
2344 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2345 doc
: /* Run each hook in HOOKS.
2346 Each argument should be a symbol, a hook variable.
2347 These symbols are processed in the order specified.
2348 If a hook symbol has a non-nil value, that value may be a function
2349 or a list of functions to be called to run the hook.
2350 If the value is a function, it is called with no arguments.
2351 If it is a list, the elements are called, in order, with no arguments.
2353 Major modes should not use this function directly to run their mode
2354 hook; they should use `run-mode-hooks' instead.
2356 Do not use `make-local-variable' to make a hook variable buffer-local.
2357 Instead, use `add-hook' and specify t for the LOCAL argument.
2358 usage: (run-hooks &rest HOOKS) */)
2359 (ptrdiff_t nargs
, Lisp_Object
*args
)
2361 Lisp_Object hook
[1];
2364 for (i
= 0; i
< nargs
; i
++)
2367 run_hook_with_args (1, hook
, funcall_nil
);
2373 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2374 Srun_hook_with_args
, 1, MANY
, 0,
2375 doc
: /* Run HOOK with the specified arguments ARGS.
2376 HOOK should be a symbol, a hook variable. The value of HOOK
2377 may be nil, a function, or a list of functions. Call each
2378 function in order with arguments ARGS. The final return value
2381 Do not use `make-local-variable' to make a hook variable buffer-local.
2382 Instead, use `add-hook' and specify t for the LOCAL argument.
2383 usage: (run-hook-with-args HOOK &rest ARGS) */)
2384 (ptrdiff_t nargs
, Lisp_Object
*args
)
2386 return run_hook_with_args (nargs
, args
, funcall_nil
);
2389 /* NB this one still documents a specific non-nil return value.
2390 (As did run-hook-with-args and run-hook-with-args-until-failure
2391 until they were changed in 24.1.) */
2392 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2393 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2394 doc
: /* Run HOOK with the specified arguments ARGS.
2395 HOOK should be a symbol, a hook variable. The value of HOOK
2396 may be nil, a function, or a list of functions. Call each
2397 function in order with arguments ARGS, stopping at the first
2398 one that returns non-nil, and return that value. Otherwise (if
2399 all functions return nil, or if there are no functions to call),
2402 Do not use `make-local-variable' to make a hook variable buffer-local.
2403 Instead, use `add-hook' and specify t for the LOCAL argument.
2404 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2405 (ptrdiff_t nargs
, Lisp_Object
*args
)
2407 return run_hook_with_args (nargs
, args
, Ffuncall
);
2411 funcall_not (ptrdiff_t nargs
, Lisp_Object
*args
)
2413 return NILP (Ffuncall (nargs
, args
)) ? Qt
: Qnil
;
2416 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2417 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2418 doc
: /* Run HOOK with the specified arguments ARGS.
2419 HOOK should be a symbol, a hook variable. The value of HOOK
2420 may be nil, a function, or a list of functions. Call each
2421 function in order with arguments ARGS, stopping at the first
2422 one that returns nil, and return nil. Otherwise (if all functions
2423 return non-nil, or if there are no functions to call), return non-nil
2424 \(do not rely on the precise return value in this case).
2426 Do not use `make-local-variable' to make a hook variable buffer-local.
2427 Instead, use `add-hook' and specify t for the LOCAL argument.
2428 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2429 (ptrdiff_t nargs
, Lisp_Object
*args
)
2431 return NILP (run_hook_with_args (nargs
, args
, funcall_not
)) ? Qt
: Qnil
;
2435 run_hook_wrapped_funcall (ptrdiff_t nargs
, Lisp_Object
*args
)
2437 Lisp_Object tmp
= args
[0], ret
;
2440 ret
= Ffuncall (nargs
, args
);
2446 DEFUN ("run-hook-wrapped", Frun_hook_wrapped
, Srun_hook_wrapped
, 2, MANY
, 0,
2447 doc
: /* Run HOOK, passing each function through WRAP-FUNCTION.
2448 I.e. instead of calling each function FUN directly with arguments ARGS,
2449 it calls WRAP-FUNCTION with arguments FUN and ARGS.
2450 As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2451 aborts and returns that value.
2452 usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2453 (ptrdiff_t nargs
, Lisp_Object
*args
)
2455 return run_hook_with_args (nargs
, args
, run_hook_wrapped_funcall
);
2458 /* ARGS[0] should be a hook symbol.
2459 Call each of the functions in the hook value, passing each of them
2460 as arguments all the rest of ARGS (all NARGS - 1 elements).
2461 FUNCALL specifies how to call each function on the hook.
2462 The caller (or its caller, etc) must gcpro all of ARGS,
2463 except that it isn't necessary to gcpro ARGS[0]. */
2466 run_hook_with_args (ptrdiff_t nargs
, Lisp_Object
*args
,
2467 Lisp_Object (*funcall
) (ptrdiff_t nargs
, Lisp_Object
*args
))
2469 Lisp_Object sym
, val
, ret
= Qnil
;
2470 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2472 /* If we are dying or still initializing,
2473 don't do anything--it would probably crash if we tried. */
2474 if (NILP (Vrun_hooks
))
2478 val
= find_symbol_value (sym
);
2480 if (EQ (val
, Qunbound
) || NILP (val
))
2482 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2485 return funcall (nargs
, args
);
2489 Lisp_Object global_vals
= Qnil
;
2490 GCPRO3 (sym
, val
, global_vals
);
2493 CONSP (val
) && NILP (ret
);
2496 if (EQ (XCAR (val
), Qt
))
2498 /* t indicates this hook has a local binding;
2499 it means to run the global binding too. */
2500 global_vals
= Fdefault_value (sym
);
2501 if (NILP (global_vals
)) continue;
2503 if (!CONSP (global_vals
) || EQ (XCAR (global_vals
), Qlambda
))
2505 args
[0] = global_vals
;
2506 ret
= funcall (nargs
, args
);
2511 CONSP (global_vals
) && NILP (ret
);
2512 global_vals
= XCDR (global_vals
))
2514 args
[0] = XCAR (global_vals
);
2515 /* In a global value, t should not occur. If it does, we
2516 must ignore it to avoid an endless loop. */
2517 if (!EQ (args
[0], Qt
))
2518 ret
= funcall (nargs
, args
);
2524 args
[0] = XCAR (val
);
2525 ret
= funcall (nargs
, args
);
2534 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2537 run_hook_with_args_2 (Lisp_Object hook
, Lisp_Object arg1
, Lisp_Object arg2
)
2539 Lisp_Object temp
[3];
2544 Frun_hook_with_args (3, temp
);
2547 /* Apply fn to arg. */
2549 apply1 (Lisp_Object fn
, Lisp_Object arg
)
2551 struct gcpro gcpro1
;
2555 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2558 Lisp_Object args
[2];
2562 RETURN_UNGCPRO (Fapply (2, args
));
2566 /* Call function fn on no arguments. */
2568 call0 (Lisp_Object fn
)
2570 struct gcpro gcpro1
;
2573 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2576 /* Call function fn with 1 argument arg1. */
2579 call1 (Lisp_Object fn
, Lisp_Object arg1
)
2581 struct gcpro gcpro1
;
2582 Lisp_Object args
[2];
2588 RETURN_UNGCPRO (Ffuncall (2, args
));
2591 /* Call function fn with 2 arguments arg1, arg2. */
2594 call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2596 struct gcpro gcpro1
;
2597 Lisp_Object args
[3];
2603 RETURN_UNGCPRO (Ffuncall (3, args
));
2606 /* Call function fn with 3 arguments arg1, arg2, arg3. */
2609 call3 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
2611 struct gcpro gcpro1
;
2612 Lisp_Object args
[4];
2619 RETURN_UNGCPRO (Ffuncall (4, args
));
2622 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
2625 call4 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2628 struct gcpro gcpro1
;
2629 Lisp_Object args
[5];
2637 RETURN_UNGCPRO (Ffuncall (5, args
));
2640 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
2643 call5 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2644 Lisp_Object arg4
, Lisp_Object arg5
)
2646 struct gcpro gcpro1
;
2647 Lisp_Object args
[6];
2656 RETURN_UNGCPRO (Ffuncall (6, args
));
2659 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
2662 call6 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2663 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
)
2665 struct gcpro gcpro1
;
2666 Lisp_Object args
[7];
2676 RETURN_UNGCPRO (Ffuncall (7, args
));
2679 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
2682 call7 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2683 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
, Lisp_Object arg7
)
2685 struct gcpro gcpro1
;
2686 Lisp_Object args
[8];
2697 RETURN_UNGCPRO (Ffuncall (8, args
));
2700 /* The caller should GCPRO all the elements of ARGS. */
2702 DEFUN ("functionp", Ffunctionp
, Sfunctionp
, 1, 1, 0,
2703 doc
: /* Non-nil if OBJECT is a function. */)
2704 (Lisp_Object object
)
2706 if (FUNCTIONP (object
))
2711 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2712 doc
: /* Call first argument as a function, passing remaining arguments to it.
2713 Return the value that function returns.
2714 Thus, (funcall 'cons 'x 'y) returns (x . y).
2715 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2716 (ptrdiff_t nargs
, Lisp_Object
*args
)
2718 Lisp_Object fun
, original_fun
;
2720 ptrdiff_t numargs
= nargs
- 1;
2721 Lisp_Object lisp_numargs
;
2723 register Lisp_Object
*internal_args
;
2728 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2730 if (max_lisp_eval_depth
< 100)
2731 max_lisp_eval_depth
= 100;
2732 if (lisp_eval_depth
> max_lisp_eval_depth
)
2733 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2736 /* This also GCPROs them. */
2737 record_in_backtrace (args
[0], &args
[1], nargs
- 1);
2739 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2742 if (debug_on_next_call
)
2743 do_debug_on_call (Qlambda
);
2747 original_fun
= args
[0];
2751 /* Optimize for no indirection. */
2753 if (SYMBOLP (fun
) && !NILP (fun
)
2754 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2755 fun
= indirect_function (fun
);
2759 if (numargs
< XSUBR (fun
)->min_args
2760 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2762 XSETFASTINT (lisp_numargs
, numargs
);
2763 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
2766 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2767 xsignal1 (Qinvalid_function
, original_fun
);
2769 else if (XSUBR (fun
)->max_args
== MANY
)
2770 val
= (XSUBR (fun
)->function
.aMANY
) (numargs
, args
+ 1);
2773 if (XSUBR (fun
)->max_args
> numargs
)
2775 internal_args
= alloca (XSUBR (fun
)->max_args
2776 * sizeof *internal_args
);
2777 memcpy (internal_args
, args
+ 1, numargs
* word_size
);
2778 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2779 internal_args
[i
] = Qnil
;
2782 internal_args
= args
+ 1;
2783 switch (XSUBR (fun
)->max_args
)
2786 val
= (XSUBR (fun
)->function
.a0 ());
2789 val
= (XSUBR (fun
)->function
.a1 (internal_args
[0]));
2792 val
= (XSUBR (fun
)->function
.a2
2793 (internal_args
[0], internal_args
[1]));
2796 val
= (XSUBR (fun
)->function
.a3
2797 (internal_args
[0], internal_args
[1], internal_args
[2]));
2800 val
= (XSUBR (fun
)->function
.a4
2801 (internal_args
[0], internal_args
[1], internal_args
[2],
2805 val
= (XSUBR (fun
)->function
.a5
2806 (internal_args
[0], internal_args
[1], internal_args
[2],
2807 internal_args
[3], internal_args
[4]));
2810 val
= (XSUBR (fun
)->function
.a6
2811 (internal_args
[0], internal_args
[1], internal_args
[2],
2812 internal_args
[3], internal_args
[4], internal_args
[5]));
2815 val
= (XSUBR (fun
)->function
.a7
2816 (internal_args
[0], internal_args
[1], internal_args
[2],
2817 internal_args
[3], internal_args
[4], internal_args
[5],
2822 val
= (XSUBR (fun
)->function
.a8
2823 (internal_args
[0], internal_args
[1], internal_args
[2],
2824 internal_args
[3], internal_args
[4], internal_args
[5],
2825 internal_args
[6], internal_args
[7]));
2830 /* If a subr takes more than 8 arguments without using MANY
2831 or UNEVALLED, we need to extend this function to support it.
2832 Until this is done, there is no way to call the function. */
2837 else if (COMPILEDP (fun
))
2838 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2842 xsignal1 (Qvoid_function
, original_fun
);
2844 xsignal1 (Qinvalid_function
, original_fun
);
2845 funcar
= XCAR (fun
);
2846 if (!SYMBOLP (funcar
))
2847 xsignal1 (Qinvalid_function
, original_fun
);
2848 if (EQ (funcar
, Qlambda
)
2849 || EQ (funcar
, Qclosure
))
2850 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2851 else if (EQ (funcar
, Qautoload
))
2853 Fautoload_do_load (fun
, original_fun
, Qnil
);
2858 xsignal1 (Qinvalid_function
, original_fun
);
2862 if (backtrace_debug_on_exit (specpdl_ptr
- 1))
2863 val
= call_debugger (list2 (Qexit
, val
));
2869 apply_lambda (Lisp_Object fun
, Lisp_Object args
)
2871 Lisp_Object args_left
;
2874 register Lisp_Object
*arg_vector
;
2875 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2876 register Lisp_Object tem
;
2879 numargs
= XFASTINT (Flength (args
));
2880 SAFE_ALLOCA_LISP (arg_vector
, numargs
);
2883 GCPRO3 (*arg_vector
, args_left
, fun
);
2886 for (i
= 0; i
< numargs
; )
2888 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2889 tem
= eval_sub (tem
);
2890 arg_vector
[i
++] = tem
;
2896 set_backtrace_args (specpdl_ptr
- 1, arg_vector
);
2897 set_backtrace_nargs (specpdl_ptr
- 1, i
);
2898 tem
= funcall_lambda (fun
, numargs
, arg_vector
);
2900 /* Do the debug-on-exit now, while arg_vector still exists. */
2901 if (backtrace_debug_on_exit (specpdl_ptr
- 1))
2903 /* Don't do it again when we return to eval. */
2904 set_backtrace_debug_on_exit (specpdl_ptr
- 1, false);
2905 tem
= call_debugger (list2 (Qexit
, tem
));
2911 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2912 and return the result of evaluation.
2913 FUN must be either a lambda-expression or a compiled-code object. */
2916 funcall_lambda (Lisp_Object fun
, ptrdiff_t nargs
,
2917 register Lisp_Object
*arg_vector
)
2919 Lisp_Object val
, syms_left
, next
, lexenv
;
2920 ptrdiff_t count
= SPECPDL_INDEX ();
2922 bool optional
, rest
;
2926 if (EQ (XCAR (fun
), Qclosure
))
2928 fun
= XCDR (fun
); /* Drop `closure'. */
2929 lexenv
= XCAR (fun
);
2930 CHECK_LIST_CONS (fun
, fun
);
2934 syms_left
= XCDR (fun
);
2935 if (CONSP (syms_left
))
2936 syms_left
= XCAR (syms_left
);
2938 xsignal1 (Qinvalid_function
, fun
);
2940 else if (COMPILEDP (fun
))
2942 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2943 if (INTEGERP (syms_left
))
2944 /* A byte-code object with a non-nil `push args' slot means we
2945 shouldn't bind any arguments, instead just call the byte-code
2946 interpreter directly; it will push arguments as necessary.
2948 Byte-code objects with either a non-existent, or a nil value for
2949 the `push args' slot (the default), have dynamically-bound
2950 arguments, and use the argument-binding code below instead (as do
2951 all interpreted functions, even lexically bound ones). */
2953 /* If we have not actually read the bytecode string
2954 and constants vector yet, fetch them from the file. */
2955 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2956 Ffetch_bytecode (fun
);
2957 return exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2958 AREF (fun
, COMPILED_CONSTANTS
),
2959 AREF (fun
, COMPILED_STACK_DEPTH
),
2968 i
= optional
= rest
= 0;
2969 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2973 next
= XCAR (syms_left
);
2974 if (!SYMBOLP (next
))
2975 xsignal1 (Qinvalid_function
, fun
);
2977 if (EQ (next
, Qand_rest
))
2979 else if (EQ (next
, Qand_optional
))
2986 arg
= Flist (nargs
- i
, &arg_vector
[i
]);
2990 arg
= arg_vector
[i
++];
2992 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2996 /* Bind the argument. */
2997 if (!NILP (lexenv
) && SYMBOLP (next
))
2998 /* Lexically bind NEXT by adding it to the lexenv alist. */
2999 lexenv
= Fcons (Fcons (next
, arg
), lexenv
);
3001 /* Dynamically bind NEXT. */
3002 specbind (next
, arg
);
3006 if (!NILP (syms_left
))
3007 xsignal1 (Qinvalid_function
, fun
);
3009 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3011 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
3012 /* Instantiate a new lexical environment. */
3013 specbind (Qinternal_interpreter_environment
, lexenv
);
3016 val
= Fprogn (XCDR (XCDR (fun
)));
3019 /* If we have not actually read the bytecode string
3020 and constants vector yet, fetch them from the file. */
3021 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
3022 Ffetch_bytecode (fun
);
3023 val
= exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
3024 AREF (fun
, COMPILED_CONSTANTS
),
3025 AREF (fun
, COMPILED_STACK_DEPTH
),
3029 return unbind_to (count
, val
);
3032 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
3034 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3035 (Lisp_Object object
)
3039 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
3041 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
3044 tem
= AREF (object
, COMPILED_BYTECODE
);
3045 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
3046 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
3048 error ("Invalid byte code");
3050 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
3051 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
3056 /* Return true if SYMBOL currently has a let-binding
3057 which was made in the buffer that is now current. */
3060 let_shadows_buffer_binding_p (struct Lisp_Symbol
*symbol
)
3062 union specbinding
*p
;
3063 Lisp_Object buf
= Fcurrent_buffer ();
3065 for (p
= specpdl_ptr
; p
> specpdl
; )
3066 if ((--p
)->kind
> SPECPDL_LET
)
3068 struct Lisp_Symbol
*let_bound_symbol
= XSYMBOL (specpdl_symbol (p
));
3069 eassert (let_bound_symbol
->redirect
!= SYMBOL_VARALIAS
);
3070 if (symbol
== let_bound_symbol
3071 && EQ (specpdl_where (p
), buf
))
3079 let_shadows_global_binding_p (Lisp_Object symbol
)
3081 union specbinding
*p
;
3083 for (p
= specpdl_ptr
; p
> specpdl
; )
3084 if ((--p
)->kind
>= SPECPDL_LET
&& EQ (specpdl_symbol (p
), symbol
))
3090 /* `specpdl_ptr' describes which variable is
3091 let-bound, so it can be properly undone when we unbind_to.
3092 It can be either a plain SPECPDL_LET or a SPECPDL_LET_LOCAL/DEFAULT.
3093 - SYMBOL is the variable being bound. Note that it should not be
3094 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3096 - WHERE tells us in which buffer the binding took place.
3097 This is used for SPECPDL_LET_LOCAL bindings (i.e. bindings to a
3098 buffer-local variable) as well as for SPECPDL_LET_DEFAULT bindings,
3099 i.e. bindings to the default value of a variable which can be
3103 specbind (Lisp_Object symbol
, Lisp_Object value
)
3105 struct Lisp_Symbol
*sym
;
3107 CHECK_SYMBOL (symbol
);
3108 sym
= XSYMBOL (symbol
);
3111 switch (sym
->redirect
)
3113 case SYMBOL_VARALIAS
:
3114 sym
= indirect_variable (sym
); XSETSYMBOL (symbol
, sym
); goto start
;
3115 case SYMBOL_PLAINVAL
:
3116 /* The most common case is that of a non-constant symbol with a
3117 trivial value. Make that as fast as we can. */
3118 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3119 specpdl_ptr
->let
.symbol
= symbol
;
3120 specpdl_ptr
->let
.old_value
= SYMBOL_VAL (sym
);
3123 SET_SYMBOL_VAL (sym
, value
);
3125 set_internal (symbol
, value
, Qnil
, 1);
3127 case SYMBOL_LOCALIZED
:
3128 if (SYMBOL_BLV (sym
)->frame_local
)
3129 error ("Frame-local vars cannot be let-bound");
3130 case SYMBOL_FORWARDED
:
3132 Lisp_Object ovalue
= find_symbol_value (symbol
);
3133 specpdl_ptr
->let
.kind
= SPECPDL_LET_LOCAL
;
3134 specpdl_ptr
->let
.symbol
= symbol
;
3135 specpdl_ptr
->let
.old_value
= ovalue
;
3136 specpdl_ptr
->let
.where
= Fcurrent_buffer ();
3138 eassert (sym
->redirect
!= SYMBOL_LOCALIZED
3139 || (EQ (SYMBOL_BLV (sym
)->where
, Fcurrent_buffer ())));
3141 if (sym
->redirect
== SYMBOL_LOCALIZED
)
3143 if (!blv_found (SYMBOL_BLV (sym
)))
3144 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3146 else if (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)))
3148 /* If SYMBOL is a per-buffer variable which doesn't have a
3149 buffer-local value here, make the `let' change the global
3150 value by changing the value of SYMBOL in all buffers not
3151 having their own value. This is consistent with what
3152 happens with other buffer-local variables. */
3153 if (NILP (Flocal_variable_p (symbol
, Qnil
)))
3155 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3157 Fset_default (symbol
, value
);
3162 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3165 set_internal (symbol
, value
, Qnil
, 1);
3168 default: emacs_abort ();
3172 /* Push unwind-protect entries of various types. */
3175 record_unwind_protect (void (*function
) (Lisp_Object
), Lisp_Object arg
)
3177 specpdl_ptr
->unwind
.kind
= SPECPDL_UNWIND
;
3178 specpdl_ptr
->unwind
.func
= function
;
3179 specpdl_ptr
->unwind
.arg
= arg
;
3184 record_unwind_protect_ptr (void (*function
) (void *), void *arg
)
3186 specpdl_ptr
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3187 specpdl_ptr
->unwind_ptr
.func
= function
;
3188 specpdl_ptr
->unwind_ptr
.arg
= arg
;
3193 record_unwind_protect_int (void (*function
) (int), int arg
)
3195 specpdl_ptr
->unwind_int
.kind
= SPECPDL_UNWIND_INT
;
3196 specpdl_ptr
->unwind_int
.func
= function
;
3197 specpdl_ptr
->unwind_int
.arg
= arg
;
3202 record_unwind_protect_void (void (*function
) (void))
3204 specpdl_ptr
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3205 specpdl_ptr
->unwind_void
.func
= function
;
3213 /* Push an unwind-protect entry that does nothing, so that
3214 set_unwind_protect_ptr can overwrite it later. */
3217 record_unwind_protect_nothing (void)
3219 record_unwind_protect_void (do_nothing
);
3222 /* Clear the unwind-protect entry COUNT, so that it does nothing.
3223 It need not be at the top of the stack. */
3226 clear_unwind_protect (ptrdiff_t count
)
3228 union specbinding
*p
= specpdl
+ count
;
3229 p
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3230 p
->unwind_void
.func
= do_nothing
;
3233 /* Set the unwind-protect entry COUNT so that it invokes FUNC (ARG).
3234 It need not be at the top of the stack. Discard the entry's
3235 previous value without invoking it. */
3238 set_unwind_protect (ptrdiff_t count
, void (*func
) (Lisp_Object
),
3241 union specbinding
*p
= specpdl
+ count
;
3242 p
->unwind
.kind
= SPECPDL_UNWIND
;
3243 p
->unwind
.func
= func
;
3244 p
->unwind
.arg
= arg
;
3248 set_unwind_protect_ptr (ptrdiff_t count
, void (*func
) (void *), void *arg
)
3250 union specbinding
*p
= specpdl
+ count
;
3251 p
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3252 p
->unwind_ptr
.func
= func
;
3253 p
->unwind_ptr
.arg
= arg
;
3256 /* Pop and execute entries from the unwind-protect stack until the
3257 depth COUNT is reached. Return VALUE. */
3260 unbind_to (ptrdiff_t count
, Lisp_Object value
)
3262 Lisp_Object quitf
= Vquit_flag
;
3263 struct gcpro gcpro1
, gcpro2
;
3265 GCPRO2 (value
, quitf
);
3268 while (specpdl_ptr
!= specpdl
+ count
)
3270 /* Decrement specpdl_ptr before we do the work to unbind it, so
3271 that an error in unbinding won't try to unbind the same entry
3272 again. Take care to copy any parts of the binding needed
3273 before invoking any code that can make more bindings. */
3277 switch (specpdl_ptr
->kind
)
3279 case SPECPDL_UNWIND
:
3280 specpdl_ptr
->unwind
.func (specpdl_ptr
->unwind
.arg
);
3282 case SPECPDL_UNWIND_PTR
:
3283 specpdl_ptr
->unwind_ptr
.func (specpdl_ptr
->unwind_ptr
.arg
);
3285 case SPECPDL_UNWIND_INT
:
3286 specpdl_ptr
->unwind_int
.func (specpdl_ptr
->unwind_int
.arg
);
3288 case SPECPDL_UNWIND_VOID
:
3289 specpdl_ptr
->unwind_void
.func ();
3291 case SPECPDL_BACKTRACE
:
3294 { /* If variable has a trivial value (no forwarding), we can
3295 just set it. No need to check for constant symbols here,
3296 since that was already done by specbind. */
3297 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (specpdl_ptr
));
3298 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3300 SET_SYMBOL_VAL (sym
, specpdl_old_value (specpdl_ptr
));
3305 NOTE: we only ever come here if make_local_foo was used for
3306 the first time on this var within this let. */
3309 case SPECPDL_LET_DEFAULT
:
3310 Fset_default (specpdl_symbol (specpdl_ptr
),
3311 specpdl_old_value (specpdl_ptr
));
3313 case SPECPDL_LET_LOCAL
:
3315 Lisp_Object symbol
= specpdl_symbol (specpdl_ptr
);
3316 Lisp_Object where
= specpdl_where (specpdl_ptr
);
3317 Lisp_Object old_value
= specpdl_old_value (specpdl_ptr
);
3318 eassert (BUFFERP (where
));
3320 /* If this was a local binding, reset the value in the appropriate
3321 buffer, but only if that buffer's binding still exists. */
3322 if (!NILP (Flocal_variable_p (symbol
, where
)))
3323 set_internal (symbol
, old_value
, where
, 1);
3329 if (NILP (Vquit_flag
) && !NILP (quitf
))
3336 DEFUN ("special-variable-p", Fspecial_variable_p
, Sspecial_variable_p
, 1, 1, 0,
3337 doc
: /* Return non-nil if SYMBOL's global binding has been declared special.
3338 A special variable is one that will be bound dynamically, even in a
3339 context where binding is lexical by default. */)
3340 (Lisp_Object symbol
)
3342 CHECK_SYMBOL (symbol
);
3343 return XSYMBOL (symbol
)->declared_special
? Qt
: Qnil
;
3347 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3348 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3349 The debugger is entered when that frame exits, if the flag is non-nil. */)
3350 (Lisp_Object level
, Lisp_Object flag
)
3352 union specbinding
*pdl
= backtrace_top ();
3353 register EMACS_INT i
;
3355 CHECK_NUMBER (level
);
3357 for (i
= 0; backtrace_p (pdl
) && i
< XINT (level
); i
++)
3358 pdl
= backtrace_next (pdl
);
3360 if (backtrace_p (pdl
))
3361 set_backtrace_debug_on_exit (pdl
, !NILP (flag
));
3366 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3367 doc
: /* Print a trace of Lisp function calls currently active.
3368 Output stream used is value of `standard-output'. */)
3371 union specbinding
*pdl
= backtrace_top ();
3373 Lisp_Object old_print_level
= Vprint_level
;
3375 if (NILP (Vprint_level
))
3376 XSETFASTINT (Vprint_level
, 8);
3378 while (backtrace_p (pdl
))
3380 write_string (backtrace_debug_on_exit (pdl
) ? "* " : " ", 2);
3381 if (backtrace_nargs (pdl
) == UNEVALLED
)
3383 Fprin1 (Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)),
3385 write_string ("\n", -1);
3389 tem
= backtrace_function (pdl
);
3390 Fprin1 (tem
, Qnil
); /* This can QUIT. */
3391 write_string ("(", -1);
3394 for (i
= 0; i
< backtrace_nargs (pdl
); i
++)
3396 if (i
) write_string (" ", -1);
3397 Fprin1 (backtrace_args (pdl
)[i
], Qnil
);
3400 write_string (")\n", -1);
3402 pdl
= backtrace_next (pdl
);
3405 Vprint_level
= old_print_level
;
3409 static union specbinding
*
3410 get_backtrace_frame (Lisp_Object nframes
, Lisp_Object base
)
3412 union specbinding
*pdl
= backtrace_top ();
3413 register EMACS_INT i
;
3415 CHECK_NATNUM (nframes
);
3418 { /* Skip up to `base'. */
3419 base
= Findirect_function (base
, Qt
);
3420 while (backtrace_p (pdl
)
3421 && !EQ (base
, Findirect_function (backtrace_function (pdl
), Qt
)))
3422 pdl
= backtrace_next (pdl
);
3425 /* Find the frame requested. */
3426 for (i
= XFASTINT (nframes
); i
> 0 && backtrace_p (pdl
); i
--)
3427 pdl
= backtrace_next (pdl
);
3432 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 2, NULL
,
3433 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3434 If that frame has not evaluated the arguments yet (or is a special form),
3435 the value is (nil FUNCTION ARG-FORMS...).
3436 If that frame has evaluated its arguments and called its function already,
3437 the value is (t FUNCTION ARG-VALUES...).
3438 A &rest arg is represented as the tail of the list ARG-VALUES.
3439 FUNCTION is whatever was supplied as car of evaluated list,
3440 or a lambda expression for macro calls.
3441 If NFRAMES is more than the number of frames, the value is nil.
3442 If BASE is non-nil, it should be a function and NFRAMES counts from its
3443 nearest activation frame. */)
3444 (Lisp_Object nframes
, Lisp_Object base
)
3446 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3448 if (!backtrace_p (pdl
))
3450 if (backtrace_nargs (pdl
) == UNEVALLED
)
3452 Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)));
3455 Lisp_Object tem
= Flist (backtrace_nargs (pdl
), backtrace_args (pdl
));
3457 return Fcons (Qt
, Fcons (backtrace_function (pdl
), tem
));
3461 /* For backtrace-eval, we want to temporarily unwind the last few elements of
3462 the specpdl stack, and then rewind them. We store the pre-unwind values
3463 directly in the pre-existing specpdl elements (i.e. we swap the current
3464 value and the old value stored in the specpdl), kind of like the inplace
3465 pointer-reversal trick. As it turns out, the rewind does the same as the
3466 unwind, except it starts from the other end of the specpdl stack, so we use
3467 the same function for both unwind and rewind. */
3469 backtrace_eval_unrewind (int distance
)
3471 union specbinding
*tmp
= specpdl_ptr
;
3474 { /* It's a rewind rather than unwind. */
3475 tmp
+= distance
- 1;
3477 distance
= -distance
;
3480 for (; distance
> 0; distance
--)
3486 /* FIXME: Ideally we'd like to "temporarily unwind" (some of) those
3487 unwind_protect, but the problem is that we don't know how to
3488 rewind them afterwards. */
3489 case SPECPDL_UNWIND
:
3490 case SPECPDL_UNWIND_PTR
:
3491 case SPECPDL_UNWIND_INT
:
3492 case SPECPDL_UNWIND_VOID
:
3493 case SPECPDL_BACKTRACE
:
3496 { /* If variable has a trivial value (no forwarding), we can
3497 just set it. No need to check for constant symbols here,
3498 since that was already done by specbind. */
3499 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (tmp
));
3500 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3502 Lisp_Object old_value
= specpdl_old_value (tmp
);
3503 set_specpdl_old_value (tmp
, SYMBOL_VAL (sym
));
3504 SET_SYMBOL_VAL (sym
, old_value
);
3509 NOTE: we only ever come here if make_local_foo was used for
3510 the first time on this var within this let. */
3513 case SPECPDL_LET_DEFAULT
:
3515 Lisp_Object sym
= specpdl_symbol (tmp
);
3516 Lisp_Object old_value
= specpdl_old_value (tmp
);
3517 set_specpdl_old_value (tmp
, Fdefault_value (sym
));
3518 Fset_default (sym
, old_value
);
3521 case SPECPDL_LET_LOCAL
:
3523 Lisp_Object symbol
= specpdl_symbol (tmp
);
3524 Lisp_Object where
= specpdl_where (tmp
);
3525 Lisp_Object old_value
= specpdl_old_value (tmp
);
3526 eassert (BUFFERP (where
));
3528 /* If this was a local binding, reset the value in the appropriate
3529 buffer, but only if that buffer's binding still exists. */
3530 if (!NILP (Flocal_variable_p (symbol
, where
)))
3532 set_specpdl_old_value
3533 (tmp
, Fbuffer_local_value (symbol
, where
));
3534 set_internal (symbol
, old_value
, where
, 1);
3542 DEFUN ("backtrace-eval", Fbacktrace_eval
, Sbacktrace_eval
, 2, 3, NULL
,
3543 doc
: /* Evaluate EXP in the context of some activation frame.
3544 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3545 (Lisp_Object exp
, Lisp_Object nframes
, Lisp_Object base
)
3547 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3548 ptrdiff_t count
= SPECPDL_INDEX ();
3549 ptrdiff_t distance
= specpdl_ptr
- pdl
;
3550 eassert (distance
>= 0);
3552 if (!backtrace_p (pdl
))
3553 error ("Activation frame not found!");
3555 backtrace_eval_unrewind (distance
);
3556 record_unwind_protect_int (backtrace_eval_unrewind
, -distance
);
3558 /* Use eval_sub rather than Feval since the main motivation behind
3559 backtrace-eval is to be able to get/set the value of lexical variables
3560 from the debugger. */
3561 return unbind_to (count
, eval_sub (exp
));
3567 union specbinding
*pdl
;
3568 for (pdl
= specpdl
; pdl
!= specpdl_ptr
; pdl
++)
3572 case SPECPDL_UNWIND
:
3573 mark_object (specpdl_arg (pdl
));
3576 case SPECPDL_BACKTRACE
:
3578 ptrdiff_t nargs
= backtrace_nargs (pdl
);
3579 mark_object (backtrace_function (pdl
));
3580 if (nargs
== UNEVALLED
)
3583 mark_object (backtrace_args (pdl
)[nargs
]);
3587 case SPECPDL_LET_DEFAULT
:
3588 case SPECPDL_LET_LOCAL
:
3589 mark_object (specpdl_where (pdl
));
3592 mark_object (specpdl_symbol (pdl
));
3593 mark_object (specpdl_old_value (pdl
));
3600 get_backtrace (Lisp_Object array
)
3602 union specbinding
*pdl
= backtrace_next (backtrace_top ());
3603 ptrdiff_t i
= 0, asize
= ASIZE (array
);
3605 /* Copy the backtrace contents into working memory. */
3606 for (; i
< asize
; i
++)
3608 if (backtrace_p (pdl
))
3610 ASET (array
, i
, backtrace_function (pdl
));
3611 pdl
= backtrace_next (pdl
);
3614 ASET (array
, i
, Qnil
);
3618 Lisp_Object
backtrace_top_function (void)
3620 union specbinding
*pdl
= backtrace_top ();
3621 return (backtrace_p (pdl
) ? backtrace_function (pdl
) : Qnil
);
3627 DEFVAR_INT ("max-specpdl-size", max_specpdl_size
,
3628 doc
: /* Limit on number of Lisp variable bindings and `unwind-protect's.
3629 If Lisp code tries to increase the total number past this amount,
3630 an error is signaled.
3631 You can safely use a value considerably larger than the default value,
3632 if that proves inconveniently small. However, if you increase it too far,
3633 Emacs could run out of memory trying to make the stack bigger. */);
3635 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth
,
3636 doc
: /* Limit on depth in `eval', `apply' and `funcall' before error.
3638 This limit serves to catch infinite recursions for you before they cause
3639 actual stack overflow in C, which would be fatal for Emacs.
3640 You can safely make it considerably larger than its default value,
3641 if that proves inconveniently small. However, if you increase it too far,
3642 Emacs could overflow the real C stack, and crash. */);
3644 DEFVAR_LISP ("quit-flag", Vquit_flag
,
3645 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3646 If the value is t, that means do an ordinary quit.
3647 If the value equals `throw-on-input', that means quit by throwing
3648 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3649 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3650 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3653 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit
,
3654 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3655 Note that `quit-flag' will still be set by typing C-g,
3656 so a quit will be signaled as soon as `inhibit-quit' is nil.
3657 To prevent this happening, set `quit-flag' to nil
3658 before making `inhibit-quit' nil. */);
3659 Vinhibit_quit
= Qnil
;
3661 DEFSYM (Qinhibit_quit
, "inhibit-quit");
3662 DEFSYM (Qautoload
, "autoload");
3663 DEFSYM (Qinhibit_debugger
, "inhibit-debugger");
3664 DEFSYM (Qmacro
, "macro");
3665 DEFSYM (Qdeclare
, "declare");
3667 /* Note that the process handling also uses Qexit, but we don't want
3668 to staticpro it twice, so we just do it here. */
3669 DEFSYM (Qexit
, "exit");
3671 DEFSYM (Qinteractive
, "interactive");
3672 DEFSYM (Qcommandp
, "commandp");
3673 DEFSYM (Qand_rest
, "&rest");
3674 DEFSYM (Qand_optional
, "&optional");
3675 DEFSYM (Qclosure
, "closure");
3676 DEFSYM (Qdebug
, "debug");
3678 DEFVAR_LISP ("inhibit-debugger", Vinhibit_debugger
,
3679 doc
: /* Non-nil means never enter the debugger.
3680 Normally set while the debugger is already active, to avoid recursive
3682 Vinhibit_debugger
= Qnil
;
3684 DEFVAR_LISP ("debug-on-error", Vdebug_on_error
,
3685 doc
: /* Non-nil means enter debugger if an error is signaled.
3686 Does not apply to errors handled by `condition-case' or those
3687 matched by `debug-ignored-errors'.
3688 If the value is a list, an error only means to enter the debugger
3689 if one of its condition symbols appears in the list.
3690 When you evaluate an expression interactively, this variable
3691 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3692 The command `toggle-debug-on-error' toggles this.
3693 See also the variable `debug-on-quit' and `inhibit-debugger'. */);
3694 Vdebug_on_error
= Qnil
;
3696 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors
,
3697 doc
: /* List of errors for which the debugger should not be called.
3698 Each element may be a condition-name or a regexp that matches error messages.
3699 If any element applies to a given error, that error skips the debugger
3700 and just returns to top level.
3701 This overrides the variable `debug-on-error'.
3702 It does not apply to errors handled by `condition-case'. */);
3703 Vdebug_ignored_errors
= Qnil
;
3705 DEFVAR_BOOL ("debug-on-quit", debug_on_quit
,
3706 doc
: /* Non-nil means enter debugger if quit is signaled (C-g, for example).
3707 Does not apply if quit is handled by a `condition-case'. */);
3710 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call
,
3711 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3713 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue
,
3714 doc
: /* Non-nil means debugger may continue execution.
3715 This is nil when the debugger is called under circumstances where it
3716 might not be safe to continue. */);
3717 debugger_may_continue
= 1;
3719 DEFVAR_LISP ("debugger", Vdebugger
,
3720 doc
: /* Function to call to invoke debugger.
3721 If due to frame exit, args are `exit' and the value being returned;
3722 this function's value will be returned instead of that.
3723 If due to error, args are `error' and a list of the args to `signal'.
3724 If due to `apply' or `funcall' entry, one arg, `lambda'.
3725 If due to `eval' entry, one arg, t. */);
3728 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function
,
3729 doc
: /* If non-nil, this is a function for `signal' to call.
3730 It receives the same arguments that `signal' was given.
3731 The Edebug package uses this to regain control. */);
3732 Vsignal_hook_function
= Qnil
;
3734 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal
,
3735 doc
: /* Non-nil means call the debugger regardless of condition handlers.
3736 Note that `debug-on-error', `debug-on-quit' and friends
3737 still determine whether to handle the particular condition. */);
3738 Vdebug_on_signal
= Qnil
;
3740 /* When lexical binding is being used,
3741 Vinternal_interpreter_environment is non-nil, and contains an alist
3742 of lexically-bound variable, or (t), indicating an empty
3743 environment. The lisp name of this variable would be
3744 `internal-interpreter-environment' if it weren't hidden.
3745 Every element of this list can be either a cons (VAR . VAL)
3746 specifying a lexical binding, or a single symbol VAR indicating
3747 that this variable should use dynamic scoping. */
3748 DEFSYM (Qinternal_interpreter_environment
,
3749 "internal-interpreter-environment");
3750 DEFVAR_LISP ("internal-interpreter-environment",
3751 Vinternal_interpreter_environment
,
3752 doc
: /* If non-nil, the current lexical environment of the lisp interpreter.
3753 When lexical binding is not being used, this variable is nil.
3754 A value of `(t)' indicates an empty environment, otherwise it is an
3755 alist of active lexical bindings. */);
3756 Vinternal_interpreter_environment
= Qnil
;
3757 /* Don't export this variable to Elisp, so no one can mess with it
3758 (Just imagine if someone makes it buffer-local). */
3759 Funintern (Qinternal_interpreter_environment
, Qnil
);
3761 DEFSYM (Vrun_hooks
, "run-hooks");
3763 staticpro (&Vautoload_queue
);
3764 Vautoload_queue
= Qnil
;
3765 staticpro (&Vsignaling_function
);
3766 Vsignaling_function
= Qnil
;
3768 inhibit_lisp_code
= Qnil
;
3779 defsubr (&Sfunction
);
3780 defsubr (&Sdefault_toplevel_value
);
3781 defsubr (&Sset_default_toplevel_value
);
3783 defsubr (&Sdefvaralias
);
3784 defsubr (&Sdefconst
);
3785 defsubr (&Smake_var_non_special
);
3789 defsubr (&Smacroexpand
);
3792 defsubr (&Sunwind_protect
);
3793 defsubr (&Scondition_case
);
3795 defsubr (&Scommandp
);
3796 defsubr (&Sautoload
);
3797 defsubr (&Sautoload_do_load
);
3800 defsubr (&Sfuncall
);
3801 defsubr (&Srun_hooks
);
3802 defsubr (&Srun_hook_with_args
);
3803 defsubr (&Srun_hook_with_args_until_success
);
3804 defsubr (&Srun_hook_with_args_until_failure
);
3805 defsubr (&Srun_hook_wrapped
);
3806 defsubr (&Sfetch_bytecode
);
3807 defsubr (&Sbacktrace_debug
);
3808 defsubr (&Sbacktrace
);
3809 defsubr (&Sbacktrace_frame
);
3810 defsubr (&Sbacktrace_eval
);
3811 defsubr (&Sspecial_variable_p
);
3812 defsubr (&Sfunctionp
);