[pypy-commit] pypy translation-cleanup: Consolidate RPythonicity checks at the beginning of build_flow()
rlamy
noreply at buildbot.pypy.org
Wed Oct 10 21:44:31 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57988:e0c6bf5e3dbf
Date: 2012-10-10 20:43 +0100
http://bitbucket.org/pypy/pypy/changeset/e0c6bf5e3dbf/
Log: Consolidate RPythonicity checks at the beginning of build_flow()
diff --git a/pypy/objspace/flow/bytecode.py b/pypy/objspace/flow/bytecode.py
--- a/pypy/objspace/flow/bytecode.py
+++ b/pypy/objspace/flow/bytecode.py
@@ -38,8 +38,6 @@
self.co_firstlineno = firstlineno
self.co_lnotab = lnotab
self.signature = cpython_code_signature(self)
- if self.co_cellvars:
- raise ValueError("RPython functions cannot create closures")
@classmethod
def _from_code(cls, code):
@@ -72,9 +70,6 @@
closure = [Cell(Constant(c.cell_contents)) for c in closure]
else:
closure = []
- if not (self.co_flags & CO_NEWLOCALS):
- raise ValueError("The code object for a function should have "
- "the flag CO_NEWLOCALS set.")
if len(closure) != len(self.co_freevars):
raise ValueError("code object received a closure with "
"an unexpected number of free variables")
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -2,6 +2,8 @@
import __builtin__
import sys
import types
+from inspect import CO_NEWLOCALS
+
from pypy.interpreter.baseobjspace import ObjSpace
from pypy.interpreter.argument import ArgumentsForTranslation
from pypy.objspace.flow.model import (Constant, Variable, WrapException,
@@ -41,6 +43,17 @@
}
}
+def _assert_rpythonic(func):
+ """Raise ValueError if ``func`` is obviously not RPython"""
+ if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
+ raise ValueError("%r is tagged as NOT_RPYTHON" % (func,))
+ if func.func_code.co_cellvars:
+ raise ValueError("RPython functions cannot create closures")
+ if not (func.func_code.co_flags & CO_NEWLOCALS):
+ raise ValueError("The code object for a RPython function should have "
+ "the flag CO_NEWLOCALS set.")
+
+
# ______________________________________________________________________
class FlowObjSpace(object):
"""NOT_RPYTHON.
@@ -248,8 +261,7 @@
def build_flow(self, func):
"""
"""
- if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
- raise Exception, "%r is tagged as NOT_RPYTHON" % (func,)
+ _assert_rpythonic(func)
code = HostCode._from_code(func.func_code)
if (code.is_generator and
not hasattr(func, '_generator_next_method_of_')):
More information about the pypy-commit
mailing list