aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorJoakim Verona2012-07-27 02:22:03 +0200
committerJoakim Verona2012-07-27 02:22:03 +0200
commit5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f (patch)
tree5c55f1096a656a9759f0b53a0b5d1a2289bd366f /src/eval.c
parent0c5c85cf2b350c965bb1ffa5b2d77c2adebc406b (diff)
parent562157c814037dcba58a20cd6908a95992c22283 (diff)
downloademacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.tar.gz
emacs-5fb63197843dcae66f2fe0ddd6f4a9d560e9db2f.zip
upstream
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c121
1 files changed, 55 insertions, 66 deletions
diff --git a/src/eval.c b/src/eval.c
index 5a9327a99d8..a0a05ebf0dc 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -131,16 +131,14 @@ int handling_signal;
131Lisp_Object inhibit_lisp_code; 131Lisp_Object inhibit_lisp_code;
132 132
133static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *); 133static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
134static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN;
135static int interactive_p (int); 134static int interactive_p (int);
136static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args); 135static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args);
137static Lisp_Object Ffetch_bytecode (Lisp_Object);
138 136
139void 137void
140init_eval_once (void) 138init_eval_once (void)
141{ 139{
142 enum { size = 50 }; 140 enum { size = 50 };
143 specpdl = (struct specbinding *) xmalloc (size * sizeof (struct specbinding)); 141 specpdl = xmalloc (size * sizeof *specpdl);
144 specpdl_size = size; 142 specpdl_size = size;
145 specpdl_ptr = specpdl; 143 specpdl_ptr = specpdl;
146 /* Don't forget to update docs (lispref node "Local Variables"). */ 144 /* Don't forget to update docs (lispref node "Local Variables"). */
@@ -693,18 +691,6 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
693 /* Do it before evaluating the initial value, for self-references. */ 691 /* Do it before evaluating the initial value, for self-references. */
694 XSYMBOL (sym)->declared_special = 1; 692 XSYMBOL (sym)->declared_special = 1;
695 693
696 if (SYMBOL_CONSTANT_P (sym))
697 {
698 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
699 Lisp_Object tem1 = Fcar (tail);
700 if (! (CONSP (tem1)
701 && EQ (XCAR (tem1), Qquote)
702 && CONSP (XCDR (tem1))
703 && EQ (XCAR (XCDR (tem1)), sym)))
704 error ("Constant symbol `%s' specified in defvar",
705 SDATA (SYMBOL_NAME (sym)));
706 }
707
708 if (NILP (tem)) 694 if (NILP (tem))
709 Fset_default (sym, eval_sub (Fcar (tail))); 695 Fset_default (sym, eval_sub (Fcar (tail)));
710 else 696 else
@@ -1002,26 +988,14 @@ definitions to shadow the loaded ones for use in file byte-compilation. */)
1002 { 988 {
1003 /* SYM is not mentioned in ENVIRONMENT. 989 /* SYM is not mentioned in ENVIRONMENT.
1004 Look at its function definition. */ 990 Look at its function definition. */
991 struct gcpro gcpro1;
992 GCPRO1 (form);
993 def = Fautoload_do_load (def, sym, Qmacro);
994 UNGCPRO;
1005 if (EQ (def, Qunbound) || !CONSP (def)) 995 if (EQ (def, Qunbound) || !CONSP (def))
1006 /* Not defined or definition not suitable. */ 996 /* Not defined or definition not suitable. */
1007 break; 997 break;
1008 if (EQ (XCAR (def), Qautoload)) 998 if (!EQ (XCAR (def), Qmacro))
1009 {
1010 /* Autoloading function: will it be a macro when loaded? */
1011 tem = Fnth (make_number (4), def);
1012 if (EQ (tem, Qt) || EQ (tem, Qmacro))
1013 /* Yes, load it and try again. */
1014 {
1015 struct gcpro gcpro1;
1016 GCPRO1 (form);
1017 do_autoload (def, sym);
1018 UNGCPRO;
1019 continue;
1020 }
1021 else
1022 break;
1023 }
1024 else if (!EQ (XCAR (def), Qmacro))
1025 break; 999 break;
1026 else expander = XCDR (def); 1000 else expander = XCDR (def);
1027 } 1001 }
@@ -1111,10 +1085,10 @@ internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object
1111 1085
1112 This is used for correct unwinding in Fthrow and Fsignal. */ 1086 This is used for correct unwinding in Fthrow and Fsignal. */
1113 1087
1114static void 1088static _Noreturn void
1115unwind_to_catch (struct catchtag *catch, Lisp_Object value) 1089unwind_to_catch (struct catchtag *catch, Lisp_Object value)
1116{ 1090{
1117 register int last_time; 1091 int last_time;
1118 1092
1119 /* Save the value in the tag. */ 1093 /* Save the value in the tag. */
1120 catch->val = value; 1094 catch->val = value;
@@ -1966,22 +1940,35 @@ un_autoload (Lisp_Object oldqueue)
1966 FUNNAME is the symbol which is the function's name. 1940 FUNNAME is the symbol which is the function's name.
1967 FUNDEF is the autoload definition (a list). */ 1941 FUNDEF is the autoload definition (a list). */
1968 1942
1969void 1943DEFUN ("autoload-do-load", Fautoload_do_load, Sautoload_do_load, 1, 3, 0,
1970do_autoload (Lisp_Object fundef, Lisp_Object funname) 1944 doc: /* Load FUNDEF which should be an autoload.
1945If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1946in which case the function returns the new autoloaded function value.
1947If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1948it is defines a macro. */)
1949 (Lisp_Object fundef, Lisp_Object funname, Lisp_Object macro_only)
1971{ 1950{
1972 ptrdiff_t count = SPECPDL_INDEX (); 1951 ptrdiff_t count = SPECPDL_INDEX ();
1973 Lisp_Object fun;
1974 struct gcpro gcpro1, gcpro2, gcpro3; 1952 struct gcpro gcpro1, gcpro2, gcpro3;
1975 1953
1954 if (!CONSP (fundef) || !EQ (Qautoload, XCAR (fundef)))
1955 return fundef;
1956
1957 if (EQ (macro_only, Qmacro))
1958 {
1959 Lisp_Object kind = Fnth (make_number (4), fundef);
1960 if (! (EQ (kind, Qt) || EQ (kind, Qmacro)))
1961 return fundef;
1962 }
1963
1976 /* This is to make sure that loadup.el gives a clear picture 1964 /* This is to make sure that loadup.el gives a clear picture
1977 of what files are preloaded and when. */ 1965 of what files are preloaded and when. */
1978 if (! NILP (Vpurify_flag)) 1966 if (! NILP (Vpurify_flag))
1979 error ("Attempt to autoload %s while preparing to dump", 1967 error ("Attempt to autoload %s while preparing to dump",
1980 SDATA (SYMBOL_NAME (funname))); 1968 SDATA (SYMBOL_NAME (funname)));
1981 1969
1982 fun = funname;
1983 CHECK_SYMBOL (funname); 1970 CHECK_SYMBOL (funname);
1984 GCPRO3 (fun, funname, fundef); 1971 GCPRO3 (funname, fundef, macro_only);
1985 1972
1986 /* Preserve the match data. */ 1973 /* Preserve the match data. */
1987 record_unwind_save_match_data (); 1974 record_unwind_save_match_data ();
@@ -1996,18 +1983,28 @@ do_autoload (Lisp_Object fundef, Lisp_Object funname)
1996 The value saved here is to be restored into Vautoload_queue. */ 1983 The value saved here is to be restored into Vautoload_queue. */
1997 record_unwind_protect (un_autoload, Vautoload_queue); 1984 record_unwind_protect (un_autoload, Vautoload_queue);
1998 Vautoload_queue = Qt; 1985 Vautoload_queue = Qt;
1999 Fload (Fcar (Fcdr (fundef)), Qnil, Qt, Qnil, Qt); 1986 /* If `macro_only', assume this autoload to be a "best-effort",
1987 so don't signal an error if autoloading fails. */
1988 Fload (Fcar (Fcdr (fundef)), macro_only, Qt, Qnil, Qt);
2000 1989
2001 /* Once loading finishes, don't undo it. */ 1990 /* Once loading finishes, don't undo it. */
2002 Vautoload_queue = Qt; 1991 Vautoload_queue = Qt;
2003 unbind_to (count, Qnil); 1992 unbind_to (count, Qnil);
2004 1993
2005 fun = Findirect_function (fun, Qnil);
2006
2007 if (!NILP (Fequal (fun, fundef)))
2008 error ("Autoloading failed to define function %s",
2009 SDATA (SYMBOL_NAME (funname)));
2010 UNGCPRO; 1994 UNGCPRO;
1995
1996 if (NILP (funname))
1997 return Qnil;
1998 else
1999 {
2000 Lisp_Object fun = Findirect_function (funname, Qnil);
2001
2002 if (!NILP (Fequal (fun, fundef)))
2003 error ("Autoloading failed to define function %s",
2004 SDATA (SYMBOL_NAME (funname)));
2005 else
2006 return fun;
2007 }
2011} 2008}
2012 2009
2013 2010
@@ -2054,15 +2051,7 @@ eval_sub (Lisp_Object form)
2054 return form; 2051 return form;
2055 2052
2056 QUIT; 2053 QUIT;
2057 if ((consing_since_gc > gc_cons_threshold 2054 maybe_gc ();
2058 && consing_since_gc > gc_relative_threshold)
2059 ||
2060 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2061 {
2062 GCPRO1 (form);
2063 Fgarbage_collect ();
2064 UNGCPRO;
2065 }
2066 2055
2067 if (++lisp_eval_depth > max_lisp_eval_depth) 2056 if (++lisp_eval_depth > max_lisp_eval_depth)
2068 { 2057 {
@@ -2072,8 +2061,8 @@ eval_sub (Lisp_Object form)
2072 error ("Lisp nesting exceeds `max-lisp-eval-depth'"); 2061 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2073 } 2062 }
2074 2063
2075 original_fun = Fcar (form); 2064 original_fun = XCAR (form);
2076 original_args = Fcdr (form); 2065 original_args = XCDR (form);
2077 2066
2078 backtrace.next = backtrace_list; 2067 backtrace.next = backtrace_list;
2079 backtrace_list = &backtrace; 2068 backtrace_list = &backtrace;
@@ -2222,7 +2211,7 @@ eval_sub (Lisp_Object form)
2222 xsignal1 (Qinvalid_function, original_fun); 2211 xsignal1 (Qinvalid_function, original_fun);
2223 if (EQ (funcar, Qautoload)) 2212 if (EQ (funcar, Qautoload))
2224 { 2213 {
2225 do_autoload (fun, original_fun); 2214 Fautoload_do_load (fun, original_fun, Qnil);
2226 goto retry; 2215 goto retry;
2227 } 2216 }
2228 if (EQ (funcar, Qmacro)) 2217 if (EQ (funcar, Qmacro))
@@ -2243,7 +2232,7 @@ eval_sub (Lisp_Object form)
2243 return val; 2232 return val;
2244} 2233}
2245 2234
2246DEFUN ("apply", Fapply, Sapply, 2, MANY, 0, 2235DEFUN ("apply", Fapply, Sapply, 1, MANY, 0,
2247 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args. 2236 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2248Then return the value FUNCTION returns. 2237Then return the value FUNCTION returns.
2249Thus, (apply '+ 1 2 '(3 4)) returns 10. 2238Thus, (apply '+ 1 2 '(3 4)) returns 10.
@@ -2751,11 +2740,6 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2751 ptrdiff_t i; 2740 ptrdiff_t i;
2752 2741
2753 QUIT; 2742 QUIT;
2754 if ((consing_since_gc > gc_cons_threshold
2755 && consing_since_gc > gc_relative_threshold)
2756 ||
2757 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2758 Fgarbage_collect ();
2759 2743
2760 if (++lisp_eval_depth > max_lisp_eval_depth) 2744 if (++lisp_eval_depth > max_lisp_eval_depth)
2761 { 2745 {
@@ -2768,10 +2752,13 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2768 backtrace.next = backtrace_list; 2752 backtrace.next = backtrace_list;
2769 backtrace_list = &backtrace; 2753 backtrace_list = &backtrace;
2770 backtrace.function = &args[0]; 2754 backtrace.function = &args[0];
2771 backtrace.args = &args[1]; 2755 backtrace.args = &args[1]; /* This also GCPROs them. */
2772 backtrace.nargs = nargs - 1; 2756 backtrace.nargs = nargs - 1;
2773 backtrace.debug_on_exit = 0; 2757 backtrace.debug_on_exit = 0;
2774 2758
2759 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2760 maybe_gc ();
2761
2775 if (debug_on_next_call) 2762 if (debug_on_next_call)
2776 do_debug_on_call (Qlambda); 2763 do_debug_on_call (Qlambda);
2777 2764
@@ -2805,7 +2792,8 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2805 { 2792 {
2806 if (XSUBR (fun)->max_args > numargs) 2793 if (XSUBR (fun)->max_args > numargs)
2807 { 2794 {
2808 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object)); 2795 internal_args = alloca (XSUBR (fun)->max_args
2796 * sizeof *internal_args);
2809 memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object)); 2797 memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object));
2810 for (i = numargs; i < XSUBR (fun)->max_args; i++) 2798 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2811 internal_args[i] = Qnil; 2799 internal_args[i] = Qnil;
@@ -2882,7 +2870,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2882 val = funcall_lambda (fun, numargs, args + 1); 2870 val = funcall_lambda (fun, numargs, args + 1);
2883 else if (EQ (funcar, Qautoload)) 2871 else if (EQ (funcar, Qautoload))
2884 { 2872 {
2885 do_autoload (fun, original_fun); 2873 Fautoload_do_load (fun, original_fun, Qnil);
2886 CHECK_CONS_LIST (); 2874 CHECK_CONS_LIST ();
2887 goto retry; 2875 goto retry;
2888 } 2876 }
@@ -3607,6 +3595,7 @@ alist of active lexical bindings. */);
3607 defsubr (&Scalled_interactively_p); 3595 defsubr (&Scalled_interactively_p);
3608 defsubr (&Scommandp); 3596 defsubr (&Scommandp);
3609 defsubr (&Sautoload); 3597 defsubr (&Sautoload);
3598 defsubr (&Sautoload_do_load);
3610 defsubr (&Seval); 3599 defsubr (&Seval);
3611 defsubr (&Sapply); 3600 defsubr (&Sapply);
3612 defsubr (&Sfuncall); 3601 defsubr (&Sfuncall);