Refill some copyright headers.
[bpt/emacs.git] / src / eval.c
index 89d353c..709a54f 100644 (file)
@@ -1,7 +1,7 @@
 /* Evaluator for GNU Emacs Lisp interpreter.
    Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001,
-                2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-                Free Software Foundation, Inc.
+                2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+                2011  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -79,7 +79,7 @@ Lisp_Object Vautoload_queue;
 
 /* Current number of specbindings allocated in specpdl.  */
 
-int specpdl_size;
+EMACS_INT specpdl_size;
 
 /* Pointer to beginning of specpdl.  */
 
@@ -95,7 +95,7 @@ EMACS_INT max_specpdl_size;
 
 /* Depth in Lisp evaluations and function calls.  */
 
-int lisp_eval_depth;
+EMACS_INT lisp_eval_depth;
 
 /* Maximum allowed depth in Lisp evaluations and function calls.  */
 
@@ -167,6 +167,8 @@ Lisp_Object Vmacro_declaration_function;
 
 static Lisp_Object funcall_lambda (Lisp_Object, int, Lisp_Object*);
 static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN;
+static int interactive_p (int);
+static Lisp_Object apply_lambda (Lisp_Object, Lisp_Object, int);
 \f
 void
 init_eval_once (void)
@@ -176,7 +178,7 @@ init_eval_once (void)
   specpdl_ptr = specpdl;
   /* Don't forget to update docs (lispref node "Local Variables").  */
   max_specpdl_size = 1000;
-  max_lisp_eval_depth = 500;
+  max_lisp_eval_depth = 600;
 
   Vrun_hooks = Qnil;
 }
@@ -216,7 +218,7 @@ call_debugger (Lisp_Object arg)
   int debug_while_redisplaying;
   int count = SPECPDL_INDEX ();
   Lisp_Object val;
-  int old_max = max_specpdl_size;
+  EMACS_INT old_max = max_specpdl_size;
 
   /* Temporarily bump up the stack limits,
      so the debugger won't run out of stack.  */
@@ -581,7 +583,7 @@ way to do this), or via (not (or executing-kbd-macro noninteractive)).  */)
     EXCLUDE_SUBRS_P non-zero means always return 0 if the function
     called is a built-in.  */
 
-int
+static int
 interactive_p (int exclude_subrs_p)
 {
   struct backtrace *btp;
@@ -1992,7 +1994,7 @@ void
 verror (const char *m, va_list ap)
 {
   char buf[200];
-  int size = 200;
+  EMACS_INT size = 200;
   int mlen;
   char *buffer = buf;
   char *args[3];
@@ -2003,7 +2005,7 @@ verror (const char *m, va_list ap)
 
   while (1)
     {
-      int used;
+      EMACS_INT used;
       used = doprnt (buffer, size, m, m + mlen, ap);
       if (used < size)
        break;
@@ -2291,14 +2293,12 @@ DEFUN ("eval", Feval, Seval, 1, 1, 0,
          (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
        xsignal2 (Qwrong_number_of_arguments, original_fun, numargs);
 
-      if (XSUBR (fun)->max_args == UNEVALLED)
+      else if (XSUBR (fun)->max_args == UNEVALLED)
        {
          backtrace.evalargs = 0;
          val = (XSUBR (fun)->function.aUNEVALLED) (args_left);
-         goto done;
        }
-
-      if (XSUBR (fun)->max_args == MANY)
+      else if (XSUBR (fun)->max_args == MANY)
        {
          /* Pass a vector of evaluated arguments */
          Lisp_Object *vals;
@@ -2324,73 +2324,76 @@ DEFUN ("eval", Feval, Seval, 1, 1, 0,
          val = (XSUBR (fun)->function.aMANY) (XINT (numargs), vals);
          UNGCPRO;
          SAFE_FREE ();
-         goto done;
        }
-
-      GCPRO3 (args_left, fun, fun);
-      gcpro3.var = argvals;
-      gcpro3.nvars = 0;
-
-      maxargs = XSUBR (fun)->max_args;
-      for (i = 0; i < maxargs; args_left = Fcdr (args_left))
+      else
        {
-         argvals[i] = Feval (Fcar (args_left));
-         gcpro3.nvars = ++i;
-       }
+         GCPRO3 (args_left, fun, fun);
+         gcpro3.var = argvals;
+         gcpro3.nvars = 0;
 
-      UNGCPRO;
+         maxargs = XSUBR (fun)->max_args;
+         for (i = 0; i < maxargs; args_left = Fcdr (args_left))
+           {
+             argvals[i] = Feval (Fcar (args_left));
+             gcpro3.nvars = ++i;
+           }
 
-      backtrace.args = argvals;
-      backtrace.nargs = XINT (numargs);
+         UNGCPRO;
 
-      switch (i)
-       {
-       case 0:
-         val = (XSUBR (fun)->function.a0) ();
-         goto done;
-       case 1:
-         val = (XSUBR (fun)->function.a1) (argvals[0]);
-         goto done;
-       case 2:
-         val = (XSUBR (fun)->function.a2) (argvals[0], argvals[1]);
-         goto done;
-       case 3:
-         val = (XSUBR (fun)->function.a3) (argvals[0], argvals[1],
-                                           argvals[2]);
-         goto done;
-       case 4:
-         val = (XSUBR (fun)->function.a4) (argvals[0], argvals[1],
-                                           argvals[2], argvals[3]);
-         goto done;
-       case 5:
-         val = (XSUBR (fun)->function.a5) (argvals[0], argvals[1], argvals[2],
-                                           argvals[3], argvals[4]);
-         goto done;
-       case 6:
-         val = (XSUBR (fun)->function.a6) (argvals[0], argvals[1], argvals[2],
-                                           argvals[3], argvals[4], argvals[5]);
-         goto done;
-       case 7:
-         val = (XSUBR (fun)->function.a7) (argvals[0], argvals[1], argvals[2],
-                                           argvals[3], argvals[4], argvals[5],
-                                           argvals[6]);
-         goto done;
-
-       case 8:
-         val = (XSUBR (fun)->function.a8) (argvals[0], argvals[1], argvals[2],
-                                           argvals[3], argvals[4], argvals[5],
-                                           argvals[6], argvals[7]);
-         goto done;
-
-       default:
-         /* Someone has created a subr that takes more arguments than
-            is supported by this code.  We need to either rewrite the
-            subr to use a different argument protocol, or add more
-            cases to this switch.  */
-         abort ();
+         backtrace.args = argvals;
+         backtrace.nargs = XINT (numargs);
+
+         switch (i)
+           {
+           case 0:
+             val = (XSUBR (fun)->function.a0 ());
+             break;
+           case 1:
+             val = (XSUBR (fun)->function.a1 (argvals[0]));
+             break;
+           case 2:
+             val = (XSUBR (fun)->function.a2 (argvals[0], argvals[1]));
+             break;
+           case 3:
+             val = (XSUBR (fun)->function.a3
+                    (argvals[0], argvals[1], argvals[2]));
+             break;
+           case 4:
+             val = (XSUBR (fun)->function.a4
+                    (argvals[0], argvals[1], argvals[2], argvals[3]));
+             break;
+           case 5:
+             val = (XSUBR (fun)->function.a5
+                    (argvals[0], argvals[1], argvals[2], argvals[3],
+                     argvals[4]));
+             break;
+           case 6:
+             val = (XSUBR (fun)->function.a6
+                    (argvals[0], argvals[1], argvals[2], argvals[3],
+                     argvals[4], argvals[5]));
+             break;
+           case 7:
+             val = (XSUBR (fun)->function.a7
+                    (argvals[0], argvals[1], argvals[2], argvals[3],
+                     argvals[4], argvals[5], argvals[6]));
+             break;
+
+           case 8:
+             val = (XSUBR (fun)->function.a8
+                    (argvals[0], argvals[1], argvals[2], argvals[3],
+                     argvals[4], argvals[5], argvals[6], argvals[7]));
+             break;
+
+           default:
+             /* Someone has created a subr that takes more arguments than
+                is supported by this code.  We need to either rewrite the
+                subr to use a different argument protocol, or add more
+                cases to this switch.  */
+             abort ();
+           }
        }
     }
-  if (COMPILEDP (fun))
+  else if (COMPILEDP (fun))
     val = apply_lambda (fun, original_args, 1);
   else
     {
@@ -2413,7 +2416,6 @@ DEFUN ("eval", Feval, Seval, 1, 1, 0,
       else
        xsignal1 (Qinvalid_function, original_fun);
     }
- done:
   CHECK_CONS_LIST ();
 
   lisp_eval_depth--;
@@ -2685,53 +2687,6 @@ run_hook_with_args (int nargs, Lisp_Object *args, enum run_hooks_condition cond)
     }
 }
 
-/* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
-   present value of that symbol.
-   Call each element of FUNLIST,
-   passing each of them the rest of ARGS.
-   The caller (or its caller, etc) must gcpro all of ARGS,
-   except that it isn't necessary to gcpro ARGS[0].  */
-
-Lisp_Object
-run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args)
-{
-  Lisp_Object sym;
-  Lisp_Object val;
-  Lisp_Object globals;
-  struct gcpro gcpro1, gcpro2, gcpro3;
-
-  sym = args[0];
-  globals = Qnil;
-  GCPRO3 (sym, val, globals);
-
-  for (val = funlist; CONSP (val); val = XCDR (val))
-    {
-      if (EQ (XCAR (val), Qt))
-       {
-         /* t indicates this hook has a local binding;
-            it means to run the global binding too.  */
-
-         for (globals = Fdefault_value (sym);
-              CONSP (globals);
-              globals = XCDR (globals))
-           {
-             args[0] = XCAR (globals);
-             /* In a global value, t should not occur.  If it does, we
-                must ignore it to avoid an endless loop.  */
-             if (!EQ (args[0], Qt))
-               Ffuncall (nargs, args);
-           }
-       }
-      else
-       {
-         args[0] = XCAR (val);
-         Ffuncall (nargs, args);
-       }
-    }
-  UNGCPRO;
-  return Qnil;
-}
-
 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2.  */
 
 void
@@ -2956,83 +2911,84 @@ usage: (funcall FUNCTION &rest ARGUMENTS)  */)
 
   if (SUBRP (fun))
     {
-       if (numargs < XSUBR (fun)->min_args
+      if (numargs < XSUBR (fun)->min_args
          || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
        {
          XSETFASTINT (lisp_numargs, numargs);
          xsignal2 (Qwrong_number_of_arguments, original_fun, lisp_numargs);
        }
 
-      if (XSUBR (fun)->max_args == UNEVALLED)
+      else if (XSUBR (fun)->max_args == UNEVALLED)
        xsignal1 (Qinvalid_function, original_fun);
 
-      if (XSUBR (fun)->max_args == MANY)
-       {
-         val = (XSUBR (fun)->function.aMANY) (numargs, args + 1);
-         goto done;
-       }
-
-      if (XSUBR (fun)->max_args > numargs)
-       {
-         internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
-         memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object));
-         for (i = numargs; i < XSUBR (fun)->max_args; i++)
-           internal_args[i] = Qnil;
-       }
+      else if (XSUBR (fun)->max_args == MANY)
+       val = (XSUBR (fun)->function.aMANY) (numargs, args + 1);
       else
-       internal_args = args + 1;
-      switch (XSUBR (fun)->max_args)
        {
-       case 0:
-         val = (XSUBR (fun)->function.a0) ();
-         goto done;
-       case 1:
-         val = (XSUBR (fun)->function.a1) (internal_args[0]);
-         goto done;
-       case 2:
-         val = (XSUBR (fun)->function.a2) (internal_args[0], internal_args[1]);
-         goto done;
-       case 3:
-         val = (XSUBR (fun)->function.a3) (internal_args[0], internal_args[1],
-                                           internal_args[2]);
-         goto done;
-       case 4:
-         val = (XSUBR (fun)->function.a4) (internal_args[0], internal_args[1],
-                                           internal_args[2], internal_args[3]);
-         goto done;
-       case 5:
-         val = (XSUBR (fun)->function.a5) (internal_args[0], internal_args[1],
-                                           internal_args[2], internal_args[3],
-                                           internal_args[4]);
-         goto done;
-       case 6:
-         val = (XSUBR (fun)->function.a6) (internal_args[0], internal_args[1],
-                                           internal_args[2], internal_args[3],
-                                           internal_args[4], internal_args[5]);
-         goto done;
-       case 7:
-         val = (XSUBR (fun)->function.a7) (internal_args[0], internal_args[1],
-                                           internal_args[2], internal_args[3],
-                                           internal_args[4], internal_args[5],
-                                           internal_args[6]);
-         goto done;
-
-       case 8:
-         val = (XSUBR (fun)->function.a8) (internal_args[0], internal_args[1],
-                                           internal_args[2], internal_args[3],
-                                           internal_args[4], internal_args[5],
-                                           internal_args[6], internal_args[7]);
-         goto done;
-
-       default:
-
-         /* If a subr takes more than 8 arguments without using MANY
-            or UNEVALLED, we need to extend this function to support it.
-            Until this is done, there is no way to call the function.  */
-         abort ();
+         if (XSUBR (fun)->max_args > numargs)
+           {
+             internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
+             memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object));
+             for (i = numargs; i < XSUBR (fun)->max_args; i++)
+               internal_args[i] = Qnil;
+           }
+         else
+           internal_args = args + 1;
+         switch (XSUBR (fun)->max_args)
+           {
+           case 0:
+             val = (XSUBR (fun)->function.a0 ());
+             break;
+           case 1:
+             val = (XSUBR (fun)->function.a1 (internal_args[0]));
+             break;
+           case 2:
+             val = (XSUBR (fun)->function.a2
+                    (internal_args[0], internal_args[1]));
+             break;
+           case 3:
+             val = (XSUBR (fun)->function.a3
+                    (internal_args[0], internal_args[1], internal_args[2]));
+             break;
+           case 4:
+             val = (XSUBR (fun)->function.a4
+                    (internal_args[0], internal_args[1], internal_args[2],
+                    internal_args[3]));
+             break;
+           case 5:
+             val = (XSUBR (fun)->function.a5
+                    (internal_args[0], internal_args[1], internal_args[2],
+                     internal_args[3], internal_args[4]));
+             break;
+           case 6:
+             val = (XSUBR (fun)->function.a6
+                    (internal_args[0], internal_args[1], internal_args[2],
+                     internal_args[3], internal_args[4], internal_args[5]));
+             break;
+           case 7:
+             val = (XSUBR (fun)->function.a7
+                    (internal_args[0], internal_args[1], internal_args[2],
+                     internal_args[3], internal_args[4], internal_args[5],
+                     internal_args[6]));
+             break;
+
+           case 8:
+             val = (XSUBR (fun)->function.a8
+                    (internal_args[0], internal_args[1], internal_args[2],
+                     internal_args[3], internal_args[4], internal_args[5],
+                     internal_args[6], internal_args[7]));
+             break;
+
+           default:
+
+             /* If a subr takes more than 8 arguments without using MANY
+                or UNEVALLED, we need to extend this function to support it.
+                Until this is done, there is no way to call the function.  */
+             abort ();
+           }
        }
     }
-  if (COMPILEDP (fun))
+  else if (COMPILEDP (fun))
     val = funcall_lambda (fun, numargs, args + 1);
   else
     {
@@ -3054,7 +3010,6 @@ usage: (funcall FUNCTION &rest ARGUMENTS)  */)
       else
        xsignal1 (Qinvalid_function, original_fun);
     }
- done:
   CHECK_CONS_LIST ();
   lisp_eval_depth--;
   if (backtrace.debug_on_exit)
@@ -3063,7 +3018,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS)  */)
   return val;
 }
 \f
-Lisp_Object
+static Lisp_Object
 apply_lambda (Lisp_Object fun, Lisp_Object args, int eval_flag)
 {
   Lisp_Object args_left;
@@ -3441,8 +3396,10 @@ Output stream used is value of `standard-output'.  */)
   Lisp_Object tail;
   Lisp_Object tem;
   struct gcpro gcpro1;
+  Lisp_Object old_print_level = Vprint_level;
 
-  XSETFASTINT (Vprint_level, 3);
+  if (NILP (Vprint_level))
+    XSETFASTINT (Vprint_level, 8);
 
   tail = Qnil;
   GCPRO1 (tail);
@@ -3483,7 +3440,7 @@ Output stream used is value of `standard-output'.  */)
       backlist = backlist->next;
     }
 
-  Vprint_level = Qnil;
+  Vprint_level = old_print_level;
   UNGCPRO;
   return Qnil;
 }
@@ -3742,5 +3699,3 @@ The value the function returns is not used.  */);
   defsubr (&Sbacktrace_frame);
 }
 
-/* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
-   (do not change this comment) */