aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorGerd Moellmann2001-10-05 09:46:11 +0000
committerGerd Moellmann2001-10-05 09:46:11 +0000
commit19cebf5a641fb6be90f4512d468c53f0385539a8 (patch)
tree0a2ab8373df6c6291a3af8a591c6c2f9b7e05392 /src/eval.c
parent4fab758d0bbda830bd39d895dc98f970150ba5bf (diff)
downloademacs-19cebf5a641fb6be90f4512d468c53f0385539a8.tar.gz
emacs-19cebf5a641fb6be90f4512d468c53f0385539a8.zip
(Fdefvaralias): New function.
(specbind): Simplify the test if symbol is a constant. (syms_of_eval): Defsubr Fdefvaralias.
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/eval.c b/src/eval.c
index 7c423fe9675..10170548cf2 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -667,6 +667,33 @@ and the result should be a form to be evaluated instead of the original.")
667 return fn_name; 667 return fn_name;
668} 668}
669 669
670
671DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 2, 0,
672 "Make SYMBOL a variable alias for symbol ALIASED.\n\
673Setting the value of SYMBOL will subsequently set the value of ALIASED,\n\
674and getting the value of SYMBOL will return the value ALIASED has.\n\
675ALIASED nil means remove the alias; SYMBOL is unbound after that.")
676 (symbol, aliased)
677 Lisp_Object symbol, aliased;
678{
679 struct Lisp_Symbol *sym;
680
681 CHECK_SYMBOL (symbol, 0);
682 CHECK_SYMBOL (aliased, 1);
683
684 if (SYMBOL_CONSTANT_P (symbol))
685 error ("Cannot make a constant an alias");
686
687 sym = XSYMBOL (symbol);
688 sym->indirect_variable = 1;
689 sym->value = aliased;
690 sym->constant = SYMBOL_CONSTANT_P (aliased);
691 LOADHIST_ATTACH (symbol);
692
693 return aliased;
694}
695
696
670DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, 697DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
671 "Define SYMBOL as a variable.\n\ 698 "Define SYMBOL as a variable.\n\
672You are not required to define a variable in order to use it,\n\ 699You are not required to define a variable in order to use it,\n\
@@ -2901,25 +2928,22 @@ specbind (symbol, value)
2901 Lisp_Object symbol, value; 2928 Lisp_Object symbol, value;
2902{ 2929{
2903 Lisp_Object ovalue; 2930 Lisp_Object ovalue;
2931 Lisp_Object valcontents;
2904 2932
2905 CHECK_SYMBOL (symbol, 0); 2933 CHECK_SYMBOL (symbol, 0);
2906 if (specpdl_ptr == specpdl + specpdl_size) 2934 if (specpdl_ptr == specpdl + specpdl_size)
2907 grow_specpdl (); 2935 grow_specpdl ();
2908 2936
2909 /* The most common case is that a non-constant symbol with a trivial 2937 /* The most common case is that of a non-constant symbol with a
2910 value. Make that as fast as we can. */ 2938 trivial value. Make that as fast as we can. */
2911 if (!MISCP (XSYMBOL (symbol)->value) 2939 valcontents = SYMBOL_VALUE (symbol);
2912 && !EQ (symbol, Qnil) 2940 if (!MISCP (valcontents) && !SYMBOL_CONSTANT_P (symbol))
2913 && !EQ (symbol, Qt)
2914 && !(XSYMBOL (symbol)->name->data[0] == ':'
2915 && EQ (XSYMBOL (symbol)->obarray, initial_obarray)
2916 && !EQ (value, symbol)))
2917 { 2941 {
2918 specpdl_ptr->symbol = symbol; 2942 specpdl_ptr->symbol = symbol;
2919 specpdl_ptr->old_value = XSYMBOL (symbol)->value; 2943 specpdl_ptr->old_value = valcontents;
2920 specpdl_ptr->func = NULL; 2944 specpdl_ptr->func = NULL;
2921 ++specpdl_ptr; 2945 ++specpdl_ptr;
2922 XSYMBOL (symbol)->value = value; 2946 SET_SYMBOL_VALUE (symbol, value);
2923 } 2947 }
2924 else 2948 else
2925 { 2949 {
@@ -3038,8 +3062,8 @@ unbind_to (count, value)
3038 /* If variable has a trivial value (no forwarding), we can 3062 /* If variable has a trivial value (no forwarding), we can
3039 just set it. No need to check for constant symbols here, 3063 just set it. No need to check for constant symbols here,
3040 since that was already done by specbind. */ 3064 since that was already done by specbind. */
3041 if (!MISCP (XSYMBOL (specpdl_ptr->symbol)->value)) 3065 if (!MISCP (SYMBOL_VALUE (specpdl_ptr->symbol)))
3042 XSYMBOL (specpdl_ptr->symbol)->value = specpdl_ptr->old_value; 3066 SET_SYMBOL_VALUE (specpdl_ptr->symbol, specpdl_ptr->old_value);
3043 else 3067 else
3044 set_internal (specpdl_ptr->symbol, specpdl_ptr->old_value, 0, 1); 3068 set_internal (specpdl_ptr->symbol, specpdl_ptr->old_value, 0, 1);
3045 } 3069 }
@@ -3358,6 +3382,7 @@ still determine whether to handle the particular condition.");
3358 defsubr (&Sdefun); 3382 defsubr (&Sdefun);
3359 defsubr (&Sdefmacro); 3383 defsubr (&Sdefmacro);
3360 defsubr (&Sdefvar); 3384 defsubr (&Sdefvar);
3385 defsubr (&Sdefvaralias);
3361 defsubr (&Sdefconst); 3386 defsubr (&Sdefconst);
3362 defsubr (&Suser_variable_p); 3387 defsubr (&Suser_variable_p);
3363 defsubr (&Slet); 3388 defsubr (&Slet);