diff options
| author | Yuan Fu | 2022-06-14 15:59:46 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-06-14 15:59:46 -0700 |
| commit | 98bfb240818bae14cd87a1ffeb8fae7cb7846e05 (patch) | |
| tree | 16e8ab06875ed54e110cf98ccdbd7e78f15905c6 /src/eval.c | |
| parent | 184d212042ffa5a4f02c92085d9b6e8346d66e99 (diff) | |
| parent | 787c4ad8b0776280305a220d6669c956d9ed8a5d (diff) | |
| download | emacs-98bfb240818bae14cd87a1ffeb8fae7cb7846e05.tar.gz emacs-98bfb240818bae14cd87a1ffeb8fae7cb7846e05.zip | |
Merge remote-tracking branch 'savannah/master' into feature/tree-sitter
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 106 |
1 files changed, 76 insertions, 30 deletions
diff --git a/src/eval.c b/src/eval.c index 3ec03de1376..45ddbab2a2c 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -707,7 +707,7 @@ DEFUN ("default-toplevel-value", Fdefault_toplevel_value, Sdefault_toplevel_valu | |||
| 707 | union specbinding *binding = default_toplevel_binding (symbol); | 707 | union specbinding *binding = default_toplevel_binding (symbol); |
| 708 | Lisp_Object value | 708 | Lisp_Object value |
| 709 | = binding ? specpdl_old_value (binding) : Fdefault_value (symbol); | 709 | = binding ? specpdl_old_value (binding) : Fdefault_value (symbol); |
| 710 | if (!EQ (value, Qunbound)) | 710 | if (!BASE_EQ (value, Qunbound)) |
| 711 | return value; | 711 | return value; |
| 712 | xsignal1 (Qvoid_variable, symbol); | 712 | xsignal1 (Qvoid_variable, symbol); |
| 713 | } | 713 | } |
| @@ -741,7 +741,9 @@ value. */) | |||
| 741 | and where the `foo` package only gets loaded when <foo-function> | 741 | and where the `foo` package only gets loaded when <foo-function> |
| 742 | is called, so the outer `let` incorrectly made the binding lexical | 742 | is called, so the outer `let` incorrectly made the binding lexical |
| 743 | because the <foo-var> wasn't yet declared as dynamic at that point. */ | 743 | because the <foo-var> wasn't yet declared as dynamic at that point. */ |
| 744 | error ("Defining as dynamic an already lexical var"); | 744 | xsignal2 (Qerror, |
| 745 | build_string ("Defining as dynamic an already lexical var"), | ||
| 746 | symbol); | ||
| 745 | 747 | ||
| 746 | XSYMBOL (symbol)->u.s.declared_special = true; | 748 | XSYMBOL (symbol)->u.s.declared_special = true; |
| 747 | if (!NILP (doc)) | 749 | if (!NILP (doc)) |
| @@ -754,6 +756,33 @@ value. */) | |||
| 754 | return Qnil; | 756 | return Qnil; |
| 755 | } | 757 | } |
| 756 | 758 | ||
| 759 | static Lisp_Object | ||
| 760 | defvar (Lisp_Object sym, Lisp_Object initvalue, Lisp_Object docstring, bool eval) | ||
| 761 | { | ||
| 762 | Lisp_Object tem; | ||
| 763 | |||
| 764 | CHECK_SYMBOL (sym); | ||
| 765 | |||
| 766 | tem = Fdefault_boundp (sym); | ||
| 767 | |||
| 768 | /* Do it before evaluating the initial value, for self-references. */ | ||
| 769 | Finternal__define_uninitialized_variable (sym, docstring); | ||
| 770 | |||
| 771 | if (NILP (tem)) | ||
| 772 | Fset_default (sym, eval ? eval_sub (initvalue) : initvalue); | ||
| 773 | else | ||
| 774 | { /* Check if there is really a global binding rather than just a let | ||
| 775 | binding that shadows the global unboundness of the var. */ | ||
| 776 | union specbinding *binding = default_toplevel_binding (sym); | ||
| 777 | if (binding && BASE_EQ (specpdl_old_value (binding), Qunbound)) | ||
| 778 | { | ||
| 779 | set_specpdl_old_value (binding, | ||
| 780 | eval ? eval_sub (initvalue) : initvalue); | ||
| 781 | } | ||
| 782 | } | ||
| 783 | return sym; | ||
| 784 | } | ||
| 785 | |||
| 757 | DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, | 786 | DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, |
| 758 | doc: /* Define SYMBOL as a variable, and return SYMBOL. | 787 | doc: /* Define SYMBOL as a variable, and return SYMBOL. |
| 759 | You are not required to define a variable in order to use it, but | 788 | You are not required to define a variable in order to use it, but |
| @@ -768,12 +797,10 @@ value. If SYMBOL is buffer-local, its default value is what is set; | |||
| 768 | buffer-local values are not affected. If INITVALUE is missing, | 797 | buffer-local values are not affected. If INITVALUE is missing, |
| 769 | SYMBOL's value is not set. | 798 | SYMBOL's value is not set. |
| 770 | 799 | ||
| 771 | If SYMBOL has a local binding, then this form affects the local | 800 | If SYMBOL is let-bound, then this form does not affect the local let |
| 772 | binding. This is usually not what you want. Thus, if you need to | 801 | binding but the toplevel default binding instead, like |
| 773 | load a file defining variables, with this form or with `defconst' or | 802 | `set-toplevel-default-binding`. |
| 774 | `defcustom', you should always load that file _outside_ any bindings | 803 | (`defcustom' behaves similarly in this respect.) |
| 775 | for these variables. (`defconst' and `defcustom' behave similarly in | ||
| 776 | this respect.) | ||
| 777 | 804 | ||
| 778 | The optional argument DOCSTRING is a documentation string for the | 805 | The optional argument DOCSTRING is a documentation string for the |
| 779 | variable. | 806 | variable. |
| @@ -784,7 +811,7 @@ To define a buffer-local variable, use `defvar-local'. | |||
| 784 | usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) | 811 | usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) |
| 785 | (Lisp_Object args) | 812 | (Lisp_Object args) |
| 786 | { | 813 | { |
| 787 | Lisp_Object sym, tem, tail; | 814 | Lisp_Object sym, tail; |
| 788 | 815 | ||
| 789 | sym = XCAR (args); | 816 | sym = XCAR (args); |
| 790 | tail = XCDR (args); | 817 | tail = XCDR (args); |
| @@ -796,24 +823,8 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) | |||
| 796 | if (!NILP (XCDR (tail)) && !NILP (XCDR (XCDR (tail)))) | 823 | if (!NILP (XCDR (tail)) && !NILP (XCDR (XCDR (tail)))) |
| 797 | error ("Too many arguments"); | 824 | error ("Too many arguments"); |
| 798 | Lisp_Object exp = XCAR (tail); | 825 | Lisp_Object exp = XCAR (tail); |
| 799 | |||
| 800 | tem = Fdefault_boundp (sym); | ||
| 801 | tail = XCDR (tail); | 826 | tail = XCDR (tail); |
| 802 | 827 | return defvar (sym, exp, CAR (tail), true); | |
| 803 | /* Do it before evaluating the initial value, for self-references. */ | ||
| 804 | Finternal__define_uninitialized_variable (sym, CAR (tail)); | ||
| 805 | |||
| 806 | if (NILP (tem)) | ||
| 807 | Fset_default (sym, eval_sub (exp)); | ||
| 808 | else | ||
| 809 | { /* Check if there is really a global binding rather than just a let | ||
| 810 | binding that shadows the global unboundness of the var. */ | ||
| 811 | union specbinding *binding = default_toplevel_binding (sym); | ||
| 812 | if (binding && EQ (specpdl_old_value (binding), Qunbound)) | ||
| 813 | { | ||
| 814 | set_specpdl_old_value (binding, eval_sub (exp)); | ||
| 815 | } | ||
| 816 | } | ||
| 817 | } | 828 | } |
| 818 | else if (!NILP (Vinternal_interpreter_environment) | 829 | else if (!NILP (Vinternal_interpreter_environment) |
| 819 | && (SYMBOLP (sym) && !XSYMBOL (sym)->u.s.declared_special)) | 830 | && (SYMBOLP (sym) && !XSYMBOL (sym)->u.s.declared_special)) |
| @@ -832,6 +843,14 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) | |||
| 832 | return sym; | 843 | return sym; |
| 833 | } | 844 | } |
| 834 | 845 | ||
| 846 | DEFUN ("defvar-1", Fdefvar_1, Sdefvar_1, 2, 3, 0, | ||
| 847 | doc: /* Like `defvar' but as a function. | ||
| 848 | More specifically behaves like (defvar SYM 'INITVALUE DOCSTRING). */) | ||
| 849 | (Lisp_Object sym, Lisp_Object initvalue, Lisp_Object docstring) | ||
| 850 | { | ||
| 851 | return defvar (sym, initvalue, docstring, false); | ||
| 852 | } | ||
| 853 | |||
| 835 | DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0, | 854 | DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0, |
| 836 | doc: /* Define SYMBOL as a constant variable. | 855 | doc: /* Define SYMBOL as a constant variable. |
| 837 | This declares that neither programs nor users should ever change the | 856 | This declares that neither programs nor users should ever change the |
| @@ -861,9 +880,18 @@ usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */) | |||
| 861 | error ("Too many arguments"); | 880 | error ("Too many arguments"); |
| 862 | docstring = XCAR (XCDR (XCDR (args))); | 881 | docstring = XCAR (XCDR (XCDR (args))); |
| 863 | } | 882 | } |
| 883 | tem = eval_sub (XCAR (XCDR (args))); | ||
| 884 | return Fdefconst_1 (sym, tem, docstring); | ||
| 885 | } | ||
| 864 | 886 | ||
| 887 | DEFUN ("defconst-1", Fdefconst_1, Sdefconst_1, 2, 3, 0, | ||
| 888 | doc: /* Like `defconst' but as a function. | ||
| 889 | More specifically, behaves like (defconst SYM 'INITVALUE DOCSTRING). */) | ||
| 890 | (Lisp_Object sym, Lisp_Object initvalue, Lisp_Object docstring) | ||
| 891 | { | ||
| 892 | CHECK_SYMBOL (sym); | ||
| 893 | Lisp_Object tem = initvalue; | ||
| 865 | Finternal__define_uninitialized_variable (sym, docstring); | 894 | Finternal__define_uninitialized_variable (sym, docstring); |
| 866 | tem = eval_sub (XCAR (XCDR (args))); | ||
| 867 | if (!NILP (Vpurify_flag)) | 895 | if (!NILP (Vpurify_flag)) |
| 868 | tem = Fpurecopy (tem); | 896 | tem = Fpurecopy (tem); |
| 869 | Fset_default (sym, tem); /* FIXME: set-default-toplevel-value? */ | 897 | Fset_default (sym, tem); /* FIXME: set-default-toplevel-value? */ |
| @@ -1223,6 +1251,13 @@ unwind_to_catch (struct handler *catch, enum nonlocal_exit type, | |||
| 1223 | set_poll_suppress_count (catch->poll_suppress_count); | 1251 | set_poll_suppress_count (catch->poll_suppress_count); |
| 1224 | unblock_input_to (catch->interrupt_input_blocked); | 1252 | unblock_input_to (catch->interrupt_input_blocked); |
| 1225 | 1253 | ||
| 1254 | #ifdef HAVE_X_WINDOWS | ||
| 1255 | /* Restore the X error handler stack. This is important because | ||
| 1256 | otherwise a display disconnect won't unwind the stack of error | ||
| 1257 | traps to the right depth. */ | ||
| 1258 | x_unwind_errors_to (catch->x_error_handler_depth); | ||
| 1259 | #endif | ||
| 1260 | |||
| 1226 | do | 1261 | do |
| 1227 | { | 1262 | { |
| 1228 | /* Unwind the specpdl stack, and then restore the proper set of | 1263 | /* Unwind the specpdl stack, and then restore the proper set of |
| @@ -1341,7 +1376,7 @@ internal_lisp_condition_case (Lisp_Object var, Lisp_Object bodyform, | |||
| 1341 | && (SYMBOLP (XCAR (tem)) | 1376 | && (SYMBOLP (XCAR (tem)) |
| 1342 | || CONSP (XCAR (tem)))))) | 1377 | || CONSP (XCAR (tem)))))) |
| 1343 | error ("Invalid condition handler: %s", | 1378 | error ("Invalid condition handler: %s", |
| 1344 | SDATA (Fprin1_to_string (tem, Qt))); | 1379 | SDATA (Fprin1_to_string (tem, Qt, Qnil))); |
| 1345 | if (CONSP (tem) && EQ (XCAR (tem), QCsuccess)) | 1380 | if (CONSP (tem) && EQ (XCAR (tem), QCsuccess)) |
| 1346 | success_handler = XCDR (tem); | 1381 | success_handler = XCDR (tem); |
| 1347 | else | 1382 | else |
| @@ -1597,6 +1632,9 @@ push_handler_nosignal (Lisp_Object tag_ch_val, enum handlertype handlertype) | |||
| 1597 | c->act_rec = get_act_rec (current_thread); | 1632 | c->act_rec = get_act_rec (current_thread); |
| 1598 | c->poll_suppress_count = poll_suppress_count; | 1633 | c->poll_suppress_count = poll_suppress_count; |
| 1599 | c->interrupt_input_blocked = interrupt_input_blocked; | 1634 | c->interrupt_input_blocked = interrupt_input_blocked; |
| 1635 | #ifdef HAVE_X_WINDOWS | ||
| 1636 | c->x_error_handler_depth = x_error_message_count; | ||
| 1637 | #endif | ||
| 1600 | handlerlist = c; | 1638 | handlerlist = c; |
| 1601 | return c; | 1639 | return c; |
| 1602 | } | 1640 | } |
| @@ -2740,7 +2778,7 @@ run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args, | |||
| 2740 | sym = args[0]; | 2778 | sym = args[0]; |
| 2741 | val = find_symbol_value (sym); | 2779 | val = find_symbol_value (sym); |
| 2742 | 2780 | ||
| 2743 | if (EQ (val, Qunbound) || NILP (val)) | 2781 | if (BASE_EQ (val, Qunbound) || NILP (val)) |
| 2744 | return ret; | 2782 | return ret; |
| 2745 | else if (!CONSP (val) || FUNCTIONP (val)) | 2783 | else if (!CONSP (val) || FUNCTIONP (val)) |
| 2746 | { | 2784 | { |
| @@ -2816,7 +2854,13 @@ apply1 (Lisp_Object fn, Lisp_Object arg) | |||
| 2816 | } | 2854 | } |
| 2817 | 2855 | ||
| 2818 | DEFUN ("functionp", Ffunctionp, Sfunctionp, 1, 1, 0, | 2856 | DEFUN ("functionp", Ffunctionp, Sfunctionp, 1, 1, 0, |
| 2819 | doc: /* Return t if OBJECT is a function. */) | 2857 | doc: /* Return t if OBJECT is a function. |
| 2858 | |||
| 2859 | An object is a function if it is callable via `funcall'; this includes | ||
| 2860 | symbols with function bindings, but excludes macros and special forms. | ||
| 2861 | |||
| 2862 | Ordinarily return nil if OBJECT is not a function, although t might be | ||
| 2863 | returned in rare cases. */) | ||
| 2820 | (Lisp_Object object) | 2864 | (Lisp_Object object) |
| 2821 | { | 2865 | { |
| 2822 | if (FUNCTIONP (object)) | 2866 | if (FUNCTIONP (object)) |
| @@ -4338,9 +4382,11 @@ alist of active lexical bindings. */); | |||
| 4338 | defsubr (&Sdefault_toplevel_value); | 4382 | defsubr (&Sdefault_toplevel_value); |
| 4339 | defsubr (&Sset_default_toplevel_value); | 4383 | defsubr (&Sset_default_toplevel_value); |
| 4340 | defsubr (&Sdefvar); | 4384 | defsubr (&Sdefvar); |
| 4385 | defsubr (&Sdefvar_1); | ||
| 4341 | defsubr (&Sdefvaralias); | 4386 | defsubr (&Sdefvaralias); |
| 4342 | DEFSYM (Qdefvaralias, "defvaralias"); | 4387 | DEFSYM (Qdefvaralias, "defvaralias"); |
| 4343 | defsubr (&Sdefconst); | 4388 | defsubr (&Sdefconst); |
| 4389 | defsubr (&Sdefconst_1); | ||
| 4344 | defsubr (&Sinternal__define_uninitialized_variable); | 4390 | defsubr (&Sinternal__define_uninitialized_variable); |
| 4345 | defsubr (&Smake_var_non_special); | 4391 | defsubr (&Smake_var_non_special); |
| 4346 | defsubr (&Slet); | 4392 | defsubr (&Slet); |