comparison src/eval.c @ 39577:d93909a71fa4

(Fdefvaralias): New function. (specbind): Simplify the test if symbol is a constant. (syms_of_eval): Defsubr Fdefvaralias.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 05 Oct 2001 09:46:11 +0000
parents 57b9619e2e44
children 22a7c39a8c32
comparison
equal deleted inserted replaced
39576:d2a8cced572f 39577:d93909a71fa4
664 defn = Fpurecopy (defn); 664 defn = Fpurecopy (defn);
665 Ffset (fn_name, defn); 665 Ffset (fn_name, defn);
666 LOADHIST_ATTACH (fn_name); 666 LOADHIST_ATTACH (fn_name);
667 return fn_name; 667 return fn_name;
668 } 668 }
669
670
671 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 2, 0,
672 "Make SYMBOL a variable alias for symbol ALIASED.\n\
673 Setting the value of SYMBOL will subsequently set the value of ALIASED,\n\
674 and getting the value of SYMBOL will return the value ALIASED has.\n\
675 ALIASED 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
669 696
670 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, 697 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
671 "Define SYMBOL as a variable.\n\ 698 "Define SYMBOL as a variable.\n\
672 You are not required to define a variable in order to use it,\n\ 699 You are not required to define a variable in order to use it,\n\
673 but the definition can supply documentation and an initial value\n\ 700 but the definition can supply documentation and an initial value\n\
2899 void 2926 void
2900 specbind (symbol, value) 2927 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 {
2926 Lisp_Object valcontents; 2950 Lisp_Object valcontents;
2927 2951
3036 else 3060 else
3037 { 3061 {
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 }
3046 } 3070 }
3047 3071
3356 defsubr (&Squote); 3380 defsubr (&Squote);
3357 defsubr (&Sfunction); 3381 defsubr (&Sfunction);
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);
3364 defsubr (&SletX); 3389 defsubr (&SletX);
3365 defsubr (&Swhile); 3390 defsubr (&Swhile);