aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorKenichi Handa2012-08-16 21:25:17 +0900
committerKenichi Handa2012-08-16 21:25:17 +0900
commitd75ffb4ed0b2e72a9361a07d16a5c884a9459728 (patch)
tree8ac5a6a8ae033fef7fbc7fb7b09a703ef4b0ed5b /src/eval.c
parent69c41c4070c86baac11a627e9c3d366420aeb7cc (diff)
parent250c8ab9b8f6322959fa3122db83944c30c3894b (diff)
downloademacs-d75ffb4ed0b2e72a9361a07d16a5c884a9459728.tar.gz
emacs-d75ffb4ed0b2e72a9361a07d16a5c884a9459728.zip
merge trunk
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c138
1 files changed, 71 insertions, 67 deletions
diff --git a/src/eval.c b/src/eval.c
index f16fdc6dd4c..f3f14d60e1c 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -691,18 +691,6 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
691 /* Do it before evaluating the initial value, for self-references. */ 691 /* Do it before evaluating the initial value, for self-references. */
692 XSYMBOL (sym)->declared_special = 1; 692 XSYMBOL (sym)->declared_special = 1;
693 693
694 if (SYMBOL_CONSTANT_P (sym))
695 {
696 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
697 Lisp_Object tem1 = Fcar (tail);
698 if (! (CONSP (tem1)
699 && EQ (XCAR (tem1), Qquote)
700 && CONSP (XCDR (tem1))
701 && EQ (XCAR (XCDR (tem1)), sym)))
702 error ("Constant symbol `%s' specified in defvar",
703 SDATA (SYMBOL_NAME (sym)));
704 }
705
706 if (NILP (tem)) 694 if (NILP (tem))
707 Fset_default (sym, eval_sub (Fcar (tail))); 695 Fset_default (sym, eval_sub (Fcar (tail)));
708 else 696 else
@@ -1000,26 +988,14 @@ definitions to shadow the loaded ones for use in file byte-compilation. */)
1000 { 988 {
1001 /* SYM is not mentioned in ENVIRONMENT. 989 /* SYM is not mentioned in ENVIRONMENT.
1002 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;
1003 if (EQ (def, Qunbound) || !CONSP (def)) 995 if (EQ (def, Qunbound) || !CONSP (def))
1004 /* Not defined or definition not suitable. */ 996 /* Not defined or definition not suitable. */
1005 break; 997 break;
1006 if (EQ (XCAR (def), Qautoload)) 998 if (!EQ (XCAR (def), Qmacro))
1007 {
1008 /* Autoloading function: will it be a macro when loaded? */
1009 tem = Fnth (make_number (4), def);
1010 if (EQ (tem, Qt) || EQ (tem, Qmacro))
1011 /* Yes, load it and try again. */
1012 {
1013 struct gcpro gcpro1;
1014 GCPRO1 (form);
1015 do_autoload (def, sym);
1016 UNGCPRO;
1017 continue;
1018 }
1019 else
1020 break;
1021 }
1022 else if (!EQ (XCAR (def), Qmacro))
1023 break; 999 break;
1024 else expander = XCDR (def); 1000 else expander = XCDR (def);
1025 } 1001 }
@@ -1423,7 +1399,9 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1423 ptrdiff_t nargs, 1399 ptrdiff_t nargs,
1424 Lisp_Object *args, 1400 Lisp_Object *args,
1425 Lisp_Object handlers, 1401 Lisp_Object handlers,
1426 Lisp_Object (*hfun) (Lisp_Object)) 1402 Lisp_Object (*hfun) (Lisp_Object err,
1403 ptrdiff_t nargs,
1404 Lisp_Object *args))
1427{ 1405{
1428 Lisp_Object val; 1406 Lisp_Object val;
1429 struct catchtag c; 1407 struct catchtag c;
@@ -1441,7 +1419,7 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1441 c.byte_stack = byte_stack_list; 1419 c.byte_stack = byte_stack_list;
1442 if (_setjmp (c.jmp)) 1420 if (_setjmp (c.jmp))
1443 { 1421 {
1444 return (*hfun) (c.val); 1422 return (*hfun) (c.val, nargs, args);
1445 } 1423 }
1446 c.next = catchlist; 1424 c.next = catchlist;
1447 catchlist = &c; 1425 catchlist = &c;
@@ -1964,22 +1942,35 @@ un_autoload (Lisp_Object oldqueue)
1964 FUNNAME is the symbol which is the function's name. 1942 FUNNAME is the symbol which is the function's name.
1965 FUNDEF is the autoload definition (a list). */ 1943 FUNDEF is the autoload definition (a list). */
1966 1944
1967void 1945DEFUN ("autoload-do-load", Fautoload_do_load, Sautoload_do_load, 1, 3, 0,
1968do_autoload (Lisp_Object fundef, Lisp_Object funname) 1946 doc: /* Load FUNDEF which should be an autoload.
1947If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1948in which case the function returns the new autoloaded function value.
1949If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1950it is defines a macro. */)
1951 (Lisp_Object fundef, Lisp_Object funname, Lisp_Object macro_only)
1969{ 1952{
1970 ptrdiff_t count = SPECPDL_INDEX (); 1953 ptrdiff_t count = SPECPDL_INDEX ();
1971 Lisp_Object fun;
1972 struct gcpro gcpro1, gcpro2, gcpro3; 1954 struct gcpro gcpro1, gcpro2, gcpro3;
1973 1955
1956 if (!CONSP (fundef) || !EQ (Qautoload, XCAR (fundef)))
1957 return fundef;
1958
1959 if (EQ (macro_only, Qmacro))
1960 {
1961 Lisp_Object kind = Fnth (make_number (4), fundef);
1962 if (! (EQ (kind, Qt) || EQ (kind, Qmacro)))
1963 return fundef;
1964 }
1965
1974 /* This is to make sure that loadup.el gives a clear picture 1966 /* This is to make sure that loadup.el gives a clear picture
1975 of what files are preloaded and when. */ 1967 of what files are preloaded and when. */
1976 if (! NILP (Vpurify_flag)) 1968 if (! NILP (Vpurify_flag))
1977 error ("Attempt to autoload %s while preparing to dump", 1969 error ("Attempt to autoload %s while preparing to dump",
1978 SDATA (SYMBOL_NAME (funname))); 1970 SDATA (SYMBOL_NAME (funname)));
1979 1971
1980 fun = funname;
1981 CHECK_SYMBOL (funname); 1972 CHECK_SYMBOL (funname);
1982 GCPRO3 (fun, funname, fundef); 1973 GCPRO3 (funname, fundef, macro_only);
1983 1974
1984 /* Preserve the match data. */ 1975 /* Preserve the match data. */
1985 record_unwind_save_match_data (); 1976 record_unwind_save_match_data ();
@@ -1994,18 +1985,28 @@ do_autoload (Lisp_Object fundef, Lisp_Object funname)
1994 The value saved here is to be restored into Vautoload_queue. */ 1985 The value saved here is to be restored into Vautoload_queue. */
1995 record_unwind_protect (un_autoload, Vautoload_queue); 1986 record_unwind_protect (un_autoload, Vautoload_queue);
1996 Vautoload_queue = Qt; 1987 Vautoload_queue = Qt;
1997 Fload (Fcar (Fcdr (fundef)), Qnil, Qt, Qnil, Qt); 1988 /* If `macro_only', assume this autoload to be a "best-effort",
1989 so don't signal an error if autoloading fails. */
1990 Fload (Fcar (Fcdr (fundef)), macro_only, Qt, Qnil, Qt);
1998 1991
1999 /* Once loading finishes, don't undo it. */ 1992 /* Once loading finishes, don't undo it. */
2000 Vautoload_queue = Qt; 1993 Vautoload_queue = Qt;
2001 unbind_to (count, Qnil); 1994 unbind_to (count, Qnil);
2002 1995
2003 fun = Findirect_function (fun, Qnil);
2004
2005 if (!NILP (Fequal (fun, fundef)))
2006 error ("Autoloading failed to define function %s",
2007 SDATA (SYMBOL_NAME (funname)));
2008 UNGCPRO; 1996 UNGCPRO;
1997
1998 if (NILP (funname))
1999 return Qnil;
2000 else
2001 {
2002 Lisp_Object fun = Findirect_function (funname, Qnil);
2003
2004 if (!NILP (Fequal (fun, fundef)))
2005 error ("Autoloading failed to define function %s",
2006 SDATA (SYMBOL_NAME (funname)));
2007 else
2008 return fun;
2009 }
2009} 2010}
2010 2011
2011 2012
@@ -2052,15 +2053,7 @@ eval_sub (Lisp_Object form)
2052 return form; 2053 return form;
2053 2054
2054 QUIT; 2055 QUIT;
2055 if ((consing_since_gc > gc_cons_threshold 2056 maybe_gc ();
2056 && consing_since_gc > gc_relative_threshold)
2057 ||
2058 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2059 {
2060 GCPRO1 (form);
2061 Fgarbage_collect ();
2062 UNGCPRO;
2063 }
2064 2057
2065 if (++lisp_eval_depth > max_lisp_eval_depth) 2058 if (++lisp_eval_depth > max_lisp_eval_depth)
2066 { 2059 {
@@ -2103,7 +2096,7 @@ eval_sub (Lisp_Object form)
2103 args_left = original_args; 2096 args_left = original_args;
2104 numargs = Flength (args_left); 2097 numargs = Flength (args_left);
2105 2098
2106 CHECK_CONS_LIST (); 2099 check_cons_list ();
2107 2100
2108 if (XINT (numargs) < XSUBR (fun)->min_args 2101 if (XINT (numargs) < XSUBR (fun)->min_args
2109 || (XSUBR (fun)->max_args >= 0 2102 || (XSUBR (fun)->max_args >= 0
@@ -2220,18 +2213,30 @@ eval_sub (Lisp_Object form)
2220 xsignal1 (Qinvalid_function, original_fun); 2213 xsignal1 (Qinvalid_function, original_fun);
2221 if (EQ (funcar, Qautoload)) 2214 if (EQ (funcar, Qautoload))
2222 { 2215 {
2223 do_autoload (fun, original_fun); 2216 Fautoload_do_load (fun, original_fun, Qnil);
2224 goto retry; 2217 goto retry;
2225 } 2218 }
2226 if (EQ (funcar, Qmacro)) 2219 if (EQ (funcar, Qmacro))
2227 val = eval_sub (apply1 (Fcdr (fun), original_args)); 2220 {
2221 ptrdiff_t count = SPECPDL_INDEX ();
2222 extern Lisp_Object Qlexical_binding;
2223 Lisp_Object exp;
2224 /* Bind lexical-binding during expansion of the macro, so the
2225 macro can know reliably if the code it outputs will be
2226 interpreted using lexical-binding or not. */
2227 specbind (Qlexical_binding,
2228 NILP (Vinternal_interpreter_environment) ? Qnil : Qt);
2229 exp = apply1 (Fcdr (fun), original_args);
2230 unbind_to (count, Qnil);
2231 val = eval_sub (exp);
2232 }
2228 else if (EQ (funcar, Qlambda) 2233 else if (EQ (funcar, Qlambda)
2229 || EQ (funcar, Qclosure)) 2234 || EQ (funcar, Qclosure))
2230 val = apply_lambda (fun, original_args); 2235 val = apply_lambda (fun, original_args);
2231 else 2236 else
2232 xsignal1 (Qinvalid_function, original_fun); 2237 xsignal1 (Qinvalid_function, original_fun);
2233 } 2238 }
2234 CHECK_CONS_LIST (); 2239 check_cons_list ();
2235 2240
2236 lisp_eval_depth--; 2241 lisp_eval_depth--;
2237 if (backtrace.debug_on_exit) 2242 if (backtrace.debug_on_exit)
@@ -2310,7 +2315,7 @@ usage: (apply FUNCTION &rest ARGUMENTS) */)
2310 gcpro1.nvars = 1 + numargs; 2315 gcpro1.nvars = 1 + numargs;
2311 } 2316 }
2312 2317
2313 memcpy (funcall_args, args, nargs * sizeof (Lisp_Object)); 2318 memcpy (funcall_args, args, nargs * word_size);
2314 /* Spread the last arg we got. Its first element goes in 2319 /* Spread the last arg we got. Its first element goes in
2315 the slot that it used to occupy, hence this value of I. */ 2320 the slot that it used to occupy, hence this value of I. */
2316 i = nargs - 1; 2321 i = nargs - 1;
@@ -2749,11 +2754,6 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2749 ptrdiff_t i; 2754 ptrdiff_t i;
2750 2755
2751 QUIT; 2756 QUIT;
2752 if ((consing_since_gc > gc_cons_threshold
2753 && consing_since_gc > gc_relative_threshold)
2754 ||
2755 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2756 Fgarbage_collect ();
2757 2757
2758 if (++lisp_eval_depth > max_lisp_eval_depth) 2758 if (++lisp_eval_depth > max_lisp_eval_depth)
2759 { 2759 {
@@ -2766,14 +2766,17 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2766 backtrace.next = backtrace_list; 2766 backtrace.next = backtrace_list;
2767 backtrace_list = &backtrace; 2767 backtrace_list = &backtrace;
2768 backtrace.function = &args[0]; 2768 backtrace.function = &args[0];
2769 backtrace.args = &args[1]; 2769 backtrace.args = &args[1]; /* This also GCPROs them. */
2770 backtrace.nargs = nargs - 1; 2770 backtrace.nargs = nargs - 1;
2771 backtrace.debug_on_exit = 0; 2771 backtrace.debug_on_exit = 0;
2772 2772
2773 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2774 maybe_gc ();
2775
2773 if (debug_on_next_call) 2776 if (debug_on_next_call)
2774 do_debug_on_call (Qlambda); 2777 do_debug_on_call (Qlambda);
2775 2778
2776 CHECK_CONS_LIST (); 2779 check_cons_list ();
2777 2780
2778 original_fun = args[0]; 2781 original_fun = args[0];
2779 2782
@@ -2805,7 +2808,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2805 { 2808 {
2806 internal_args = alloca (XSUBR (fun)->max_args 2809 internal_args = alloca (XSUBR (fun)->max_args
2807 * sizeof *internal_args); 2810 * sizeof *internal_args);
2808 memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object)); 2811 memcpy (internal_args, args + 1, numargs * word_size);
2809 for (i = numargs; i < XSUBR (fun)->max_args; i++) 2812 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2810 internal_args[i] = Qnil; 2813 internal_args[i] = Qnil;
2811 } 2814 }
@@ -2881,14 +2884,14 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
2881 val = funcall_lambda (fun, numargs, args + 1); 2884 val = funcall_lambda (fun, numargs, args + 1);
2882 else if (EQ (funcar, Qautoload)) 2885 else if (EQ (funcar, Qautoload))
2883 { 2886 {
2884 do_autoload (fun, original_fun); 2887 Fautoload_do_load (fun, original_fun, Qnil);
2885 CHECK_CONS_LIST (); 2888 check_cons_list ();
2886 goto retry; 2889 goto retry;
2887 } 2890 }
2888 else 2891 else
2889 xsignal1 (Qinvalid_function, original_fun); 2892 xsignal1 (Qinvalid_function, original_fun);
2890 } 2893 }
2891 CHECK_CONS_LIST (); 2894 check_cons_list ();
2892 lisp_eval_depth--; 2895 lisp_eval_depth--;
2893 if (backtrace.debug_on_exit) 2896 if (backtrace.debug_on_exit)
2894 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); 2897 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
@@ -3606,6 +3609,7 @@ alist of active lexical bindings. */);
3606 defsubr (&Scalled_interactively_p); 3609 defsubr (&Scalled_interactively_p);
3607 defsubr (&Scommandp); 3610 defsubr (&Scommandp);
3608 defsubr (&Sautoload); 3611 defsubr (&Sautoload);
3612 defsubr (&Sautoload_do_load);
3609 defsubr (&Seval); 3613 defsubr (&Seval);
3610 defsubr (&Sapply); 3614 defsubr (&Sapply);
3611 defsubr (&Sfuncall); 3615 defsubr (&Sfuncall);