Patch #1550800: make exec a function.
diff --git a/Doc/lib/libdis.tex b/Doc/lib/libdis.tex
index 5c53490..e61ca36 100644
--- a/Doc/lib/libdis.tex
+++ b/Doc/lib/libdis.tex
@@ -408,11 +408,6 @@
 This opcode implements \code{from module import *}.
 \end{opcodedesc}
 
-\begin{opcodedesc}{EXEC_STMT}{}
-Implements \code{exec TOS2,TOS1,TOS}.  The compiler fills
-missing optional parameters with \code{None}.
-\end{opcodedesc}
-
 \begin{opcodedesc}{POP_BLOCK}{}
 Removes one block from the block stack.  Per frame, there is a 
 stack of blocks, denoting nested loops, try statements, and such.
diff --git a/Doc/lib/libexcs.tex b/Doc/lib/libexcs.tex
index b64d57d..b6147bf 100644
--- a/Doc/lib/libexcs.tex
+++ b/Doc/lib/libexcs.tex
@@ -293,10 +293,10 @@
 \begin{excdesc}{SyntaxError}
 % XXXJH xref to these functions?
   Raised when the parser encounters a syntax error.  This may occur in
-  an \keyword{import} statement, in an \keyword{exec} statement, in a call
-  to the built-in function \function{eval()} or \function{input()}, or
-  when reading the initial script or standard input (also
-  interactively).
+  an \keyword{import} statement, in a call to the built-in functions
+  \function{exec()}, \function{execfile()}, \function{eval()} or
+  \function{input()}, or when reading the initial script or standard
+  input (also interactively).
 
   Instances of this class have attributes \member{filename},
   \member{lineno}, \member{offset} and \member{text} for easier access
diff --git a/Doc/lib/libfuncs.tex b/Doc/lib/libfuncs.tex
index f51f0d5..4dde065 100644
--- a/Doc/lib/libfuncs.tex
+++ b/Doc/lib/libfuncs.tex
@@ -178,7 +178,7 @@
 \begin{funcdesc}{compile}{string, filename, kind\optional{,
                           flags\optional{, dont_inherit}}}
   Compile the \var{string} into a code object.  Code objects can be
-  executed by an \keyword{exec} statement or evaluated by a call to
+  executed by a call to \function{exec()} or evaluated by a call to
   \function{eval()}.  The \var{filename} argument should
   give the file from which the code was read; pass some recognizable value
   if it wasn't read from a file (\code{'<string>'} is commonly used).
@@ -366,7 +366,7 @@
   compiled passing \code{'eval'} as the \var{kind} argument.
 
   Hints: dynamic execution of statements is supported by the
-  \keyword{exec} statement.  Execution of statements from a file is
+  \function{exec()} function.  Execution of statements from a file is
   supported by the \function{execfile()} function.  The
   \function{globals()} and \function{locals()} functions returns the
   current global and local dictionary, respectively, which may be
@@ -374,13 +374,47 @@
   \function{execfile()}.
 \end{funcdesc}
 
+
+\begin{funcdesc}{exec}{object\optional{, globals\optional{, locals}}}
+  This function supports dynamic execution of Python code.
+  \var{object} must be either a string, an open file object, or
+  a code object.  If it is a string, the string is parsed as a suite of
+  Python statements which is then executed (unless a syntax error
+  occurs).  If it is an open file, the file is parsed until \EOF{} and
+  executed.  If it is a code object, it is simply executed.  In all
+  cases, the code that's executed is expected to be valid as file
+  input (see the section ``File input'' in the Reference Manual).
+  Be aware that the \keyword{return} and \keyword{yield} statements may
+  not be used outside of function definitions even within the context of
+  code passed to the \function{exec()} function.
+  The return value is \code{None}.
+
+  In all cases, if the optional parts are omitted, the code is executed
+  in the current scope.  If only \var{globals} is provided, it must be
+  a dictionary, which will be used for both the global and the local
+  variables.  If \var{globals} and \var{locals} are given, they are used
+  for the global and local variables, respectively.  If provided,
+  \var{locals} can be any mapping object.
+
+  If the \var{globals} dictionary does not contain a value for the
+  key \code{__builtins__}, a reference to the dictionary of the built-in
+  module \module{__builtin__} is inserted under that key.  That way you
+  can control what builtins are available to the executed code by
+  inserting your own \code{__builtins__} dictionary into \var{globals}
+  before passing it to \function{exec()}.
+
+  \note{The built-in functions \function{globals()} and \function{locals()}
+        return the current global and local dictionary, respectively, which
+	may be useful to pass around for use as the second and third
+	argument to \function{exec()}.}
+\end{funcdesc}
+
 \begin{funcdesc}{execfile}{filename\optional{, globals\optional{, locals}}}
-  This function is similar to the
-  \keyword{exec} statement, but parses a file instead of a string.  It
+  This function is similar to the \function{exec()} function, but parses a
+  file given by the file name instead of a string.  It
   is different from the \keyword{import} statement in that it does not
   use the module administration --- it reads the file unconditionally
-  and does not create a new module.\footnote{It is used relatively
-  rarely so does not warrant being made into a statement.}
+  and does not create a new module.
 
   The arguments are a file name and two optional dictionaries.  The file is
   parsed and evaluated as a sequence of Python statements (similarly to a
diff --git a/Doc/lib/libhotshot.tex b/Doc/lib/libhotshot.tex
index 98e0b6d..ae089c2 100644
--- a/Doc/lib/libhotshot.tex
+++ b/Doc/lib/libhotshot.tex
@@ -61,7 +61,7 @@
 \end{methoddesc}
 
 \begin{methoddesc}{run}{cmd}
-Profile an \keyword{exec}-compatible string in the script environment.
+Profile an \function{exec()}-compatible string in the script environment.
 The globals from the \refmodule[main]{__main__} module are used as
 both the globals and locals for the script.
 \end{methoddesc}
@@ -76,7 +76,7 @@
 
 
 \begin{methoddesc}{runctx}{cmd, globals, locals}
-Evaluate an \keyword{exec}-compatible string in a specific environment.
+Profile an \function{exec()}-compatible string in a specific environment.
 The string is compiled before profiling begins.
 \end{methoddesc}
 
diff --git a/Doc/lib/libparser.tex b/Doc/lib/libparser.tex
index 15b46ae..a993624 100644
--- a/Doc/lib/libparser.tex
+++ b/Doc/lib/libparser.tex
@@ -193,8 +193,9 @@
 
 \begin{funcdesc}{compileast}{ast\optional{, filename\code{ = '<ast>'}}}
 The Python byte compiler can be invoked on an AST object to produce
-code objects which can be used as part of an \keyword{exec} statement or
-a call to the built-in \function{eval()}\bifuncindex{eval} function.
+code objects which can be used as part of a call to the built-in
+\function{exec()}\bifuncindex{exec} or \function{eval()}
+\bifuncindex{eval} functions.
 This function provides the interface to the compiler, passing the
 internal parse tree from \var{ast} to the parser, using the
 source file name specified by the \var{filename} parameter.
diff --git a/Doc/lib/libpdb.tex b/Doc/lib/libpdb.tex
index b252aeb..778a137 100644
--- a/Doc/lib/libpdb.tex
+++ b/Doc/lib/libpdb.tex
@@ -79,8 +79,8 @@
 explained below).  The optional \var{globals} and \var{locals}
 arguments specify the environment in which the code is executed; by
 default the dictionary of the module \refmodule[main]{__main__} is
-used.  (See the explanation of the \keyword{exec} statement or the
-\function{eval()} built-in function.)
+used.  (See the explanation of the built-in \function{exec()} or
+\function{eval()} functions.)
 \end{funcdesc}
 
 \begin{funcdesc}{runeval}{expression\optional{, globals\optional{, locals}}}
diff --git a/Doc/lib/libprofile.tex b/Doc/lib/libprofile.tex
index 0108b21..79a168c 100644
--- a/Doc/lib/libprofile.tex
+++ b/Doc/lib/libprofile.tex
@@ -319,9 +319,9 @@
 
 \begin{funcdesc}{run}{command\optional{, filename}}
 
-This function takes a single argument that has can be passed to the
-\keyword{exec} statement, and an optional file name.  In all cases this
-routine attempts to \keyword{exec} its first argument, and gather profiling
+This function takes a single argument that can be passed to the
+\function{exec()} function, and an optional file name.  In all cases this
+routine attempts to \function{exec()} its first argument, and gather profiling
 statistics from the execution. If no file name is present, then this
 function automatically prints a simple profiling report, sorted by the
 standard name string (file/line/function-name) that is presented in
diff --git a/Doc/lib/librexec.tex b/Doc/lib/librexec.tex
index 35619e6..3e54102 100644
--- a/Doc/lib/librexec.tex
+++ b/Doc/lib/librexec.tex
@@ -11,10 +11,10 @@
 \end{notice}
 
 This module contains the \class{RExec} class, which supports
-\method{r_eval()}, \method{r_execfile()}, \method{r_exec()}, and
+\method{r_exec()}, \method{r_eval()}, \method{r_execfile()}, and
 \method{r_import()} methods, which are restricted versions of the standard
-Python functions \method{eval()}, \method{execfile()} and
-the \keyword{exec} and \keyword{import} statements.
+Python functions \method{exec()}, \method{eval()}, \method{execfile()} and
+the \keyword{import} statement.
 Code executed in this restricted environment will
 only have access to modules and functions that are deemed safe; you
 can subclass \class{RExec} to add or remove capabilities as desired.
diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex
index b84daf4..ef1b802 100644
--- a/Doc/lib/libstdtypes.tex
+++ b/Doc/lib/libstdtypes.tex
@@ -1972,9 +1972,9 @@
 \withsubitem{(function object attribute)}{\ttindex{func_code}}
 
 A code object can be executed or evaluated by passing it (instead of a
-source string) to the \keyword{exec} statement or the built-in
-\function{eval()} function.
-\stindex{exec}
+source string) to the \function{exec()} or \function{eval()} 
+built-in functions.
+\bifuncindex{exec}
 \bifuncindex{eval}
 
 See the \citetitle[../ref/ref.html]{Python Reference Manual} for more
diff --git a/Doc/lib/libtraceback.tex b/Doc/lib/libtraceback.tex
index 80dc423..a87b1ef 100644
--- a/Doc/lib/libtraceback.tex
+++ b/Doc/lib/libtraceback.tex
@@ -139,7 +139,7 @@
 def run_user_code(envdir):
     source = raw_input(">>> ")
     try:
-        exec source in envdir
+        exec(source, envdir)
     except:
         print "Exception in user code:"
         print '-'*60