[pypy-commit] pypy py3k: minor cleanup
pjenvey
noreply at buildbot.pypy.org
Wed Dec 19 00:45:00 CET 2012
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r59497:2a9a87c621be
Date: 2012-12-18 15:44 -0800
http://bitbucket.org/pypy/pypy/changeset/2a9a87c621be/
Log: minor cleanup
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -508,8 +508,8 @@
else:
from pypy.interpreter.astcompiler import consts
flags |= consts.PyCF_SOURCE_IS_UTF8
- source, flags = source_as_str(
- space, w_prog, 'exec', "string, bytes or code", flags)
+ source, flags = source_as_str(space, w_prog, 'exec',
+ "string, bytes or code", flags)
code = ec.compiler.compile(source, "<string>", 'exec', flags)
w_globals, w_locals = ensure_ns(space, w_globals, w_locals, 'exec',
@@ -1377,8 +1377,10 @@
def source_as_str(space, w_source, funcname, what, flags):
- """Return an unwrapped string (without NUL bytes) from some kind of
- wrapped source string and adjusted compiler flags"""
+ """Return source code as str0 with adjusted compiler flags
+
+ w_source must be a str or support the buffer interface
+ """
from pypy.interpreter.astcompiler import consts
if space.isinstance_w(w_source, space.w_unicode):
diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -27,8 +27,10 @@
"""
from pypy.interpreter.pyopcode import source_as_str
ec = space.getexecutioncontext()
- if flags & ~(ec.compiler.compiler_flags | consts.PyCF_ONLY_AST |
- consts.PyCF_DONT_IMPLY_DEDENT | consts.PyCF_SOURCE_IS_UTF8):
+ if flags & ~(ec.compiler.compiler_flags |
+ consts.PyCF_ONLY_AST |
+ consts.PyCF_DONT_IMPLY_DEDENT |
+ consts.PyCF_SOURCE_IS_UTF8):
raise OperationError(space.w_ValueError,
space.wrap("compile() unrecognized flags"))
@@ -47,23 +49,23 @@
flags |= ec.compiler.getcodeflags(caller.getcode())
if mode not in ('exec', 'eval', 'single'):
- raise OperationError(space.w_ValueError,
- space.wrap("compile() arg 3 must be 'exec', "
- "'eval' or 'single'"))
- # XXX optimize is not used
+ raise OperationError(
+ space.w_ValueError,
+ space.wrap("compile() arg 3 must be 'exec', 'eval' or 'single'"))
- if ast_node is None:
- if flags & consts.PyCF_ONLY_AST:
- mod = ec.compiler.compile_to_ast(source, filename, mode, flags)
- return space.wrap(mod)
- else:
- code = ec.compiler.compile(source, filename, mode, flags)
+ # XXX: optimize flag is not used
+
+ if ast_node is not None:
+ code = ec.compiler.compile_ast(ast_node, filename, mode, flags)
+ elif flags & consts.PyCF_ONLY_AST:
+ ast_node = ec.compiler.compile_to_ast(source, filename, mode, flags)
+ return space.wrap(ast_node)
else:
- code = ec.compiler.compile_ast(ast_node, filename, mode, flags)
+ code = ec.compiler.compile(source, filename, mode, flags)
return space.wrap(code)
-def eval(space, w_code, w_globals=None, w_locals=None):
+def eval(space, w_prog, w_globals=None, w_locals=None):
"""Evaluate the source in the context of globals and locals.
The source may be a string representing a Python expression
or a code object as returned by compile(). The globals and locals
@@ -73,10 +75,10 @@
from pypy.interpreter.pyopcode import ensure_ns, source_as_str
w_globals, w_locals = ensure_ns(space, w_globals, w_locals, 'eval')
- if space.isinstance_w(w_code, space.gettypeobject(PyCode.typedef)):
- code = space.interp_w(PyCode, w_code)
+ if space.isinstance_w(w_prog, space.gettypeobject(PyCode.typedef)):
+ code = space.interp_w(PyCode, w_prog)
else:
- source, flags = source_as_str(space, w_code, 'eval',
+ source, flags = source_as_str(space, w_prog, 'eval',
"string, bytes or code",
consts.PyCF_SOURCE_IS_UTF8)
# source.lstrip(' \t')
@@ -91,10 +93,9 @@
ec = space.getexecutioncontext()
code = ec.compiler.compile(source, "<string>", 'eval', flags)
- # xxx removed: adding '__builtins__' to the w_globals dict, if there
- # is none. This logic was removed as costly (it requires to get at
- # the gettopframe_nohidden()). I bet no test fails, and it's a really
- # obscure case.
+ # XXX: skip adding of __builtins__ to w_globals. it requires a
+ # costly gettopframe_nohidden() here and nobody seems to miss its
+ # absence
return code.exec_code(space, w_globals, w_locals)
More information about the pypy-commit
mailing list