Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: less-stringly-ops
Changeset: r66228:f8b3a9be2076
Date: 2013-08-19 18:02 +0100
http://bitbucket.org/pypy/pypy/changeset/f8b3a9be2076/

Log:    Move special-case registrations next to the relevant definitions

diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -8,7 +8,6 @@
 
 from rpython.tool.uid import uid, Hashable
 from rpython.tool.sourcetools import PY_IDENTIFIER, nice_repr_for_func
-from rpython.rlib.rarithmetic import is_valid_int, r_longlong, r_ulonglong, 
r_uint
 
 
 """
@@ -504,7 +503,8 @@
     if not __debug__:
         return
     try:
-
+        from rpython.rlib.rarithmetic import (is_valid_int, r_longlong,
+            r_ulonglong, r_uint)
         vars_previous_blocks = {}
 
         exitblocks = {graph.returnblock: 1,   # retval
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -7,8 +7,8 @@
 import __future__
 import operator
 from rpython.tool.sourcetools import compile2
-from rpython.rlib.rarithmetic import ovfcheck
 from rpython.flowspace.model import Constant, WrapException, const
+from rpython.flowspace.specialcase import register_flow_sc
 
 class _OpHolder(object): pass
 op = _OpHolder()
@@ -97,6 +97,7 @@
         if pyfunc is None:
             oper.pyfunc = operator_func
     if ovf:
+        from rpython.rlib.rarithmetic import ovfcheck
         ovf_func = lambda *args: ovfcheck(oper.pyfunc(*args))
         add_operator(name + '_ovf', arity, symbol, pyfunc=ovf_func)
 
@@ -288,6 +289,9 @@
 if hasattr(__builtin__, 'next'):
     func2op[__builtin__.next] = op.next
 
+for fn, oper in func2op.items():
+    register_flow_sc(fn)(oper.make_sc())
+
 
 op_appendices = {
     OverflowError: 'ovf',
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -1,8 +1,3 @@
-from rpython.flowspace.model import Constant
-from rpython.flowspace.operation import func2op
-from rpython.rlib.rarithmetic import r_uint
-from rpython.rlib.objectmodel import we_are_translated
-
 SPECIAL_CASES = {}
 
 def register_flow_sc(func):
@@ -22,6 +17,16 @@
     args = [space.unwrap(arg) for arg in args_w]
     return space.import_name(*args)
 
+@register_flow_sc(locals)
+def sc_locals(space, args):
+    raise Exception(
+        "A function calling locals() is not RPython.  "
+        "Note that if you're translating code outside the PyPy "
+        "repository, a likely cause is that py.test's --assert=rewrite "
+        "mode is getting in the way.  You should copy the file "
+        "pytest.ini from the root of the PyPy repository into your "
+        "own project.")
+
 # _________________________________________________________________________
 # a simplified version of the basic printing routines, for RPython programs
 class StdOutBuffer:
@@ -44,32 +49,3 @@
         s = '\n'
     import os
     os.write(1, s)
-
-# _________________________________________________________________________
-
-@register_flow_sc(r_uint)
-def sc_r_uint(space, args_w):
-    # special case to constant-fold r_uint(32-bit-constant)
-    # (normally, the 32-bit constant is a long, and is not allowed to
-    # show up in the flow graphs at all)
-    [w_value] = args_w
-    if isinstance(w_value, Constant):
-        return Constant(r_uint(w_value.value))
-    return space.frame.do_operation('simple_call', space.wrap(r_uint), w_value)
-
-@register_flow_sc(we_are_translated)
-def sc_we_are_translated(space, args_w):
-    return Constant(True)
-
-@register_flow_sc(locals)
-def sc_locals(space, args):
-    raise Exception(
-        "A function calling locals() is not RPython.  "
-        "Note that if you're translating code outside the PyPy "
-        "repository, a likely cause is that py.test's --assert=rewrite "
-        "mode is getting in the way.  You should copy the file "
-        "pytest.ini from the root of the PyPy repository into your "
-        "own project.")
-
-for fn, oper in func2op.items():
-    register_flow_sc(fn)(oper.make_sc())
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -10,6 +10,9 @@
 import math
 import inspect
 from rpython.tool.sourcetools import rpython_wrapper
+from rpython.rtyper.extregistry import ExtRegistryEntry
+from rpython.flowspace.specialcase import register_flow_sc
+from rpython.flowspace.model import Constant
 
 # specialize is a decorator factory for attaching _annspecialcase_
 # attributes to functions: for example
@@ -23,7 +26,6 @@
 # def f(...
 #
 
-from rpython.rtyper.extregistry import ExtRegistryEntry
 
 class _Specialize(object):
     def memo(self):
@@ -278,7 +280,11 @@
 
 def we_are_translated():
     return False
-# annotation -> True (replaced by the flow objspace)
+
+@register_flow_sc(we_are_translated)
+def sc_we_are_translated(space, args_w):
+    return Constant(True)
+
 
 def keepalive_until_here(*values):
     pass
diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -33,6 +33,8 @@
 import sys, struct
 from rpython.rtyper import extregistry
 from rpython.rlib import objectmodel
+from rpython.flowspace.model import Constant, const
+from rpython.flowspace.specialcase import register_flow_sc
 
 """
 Long-term target:
@@ -513,6 +515,16 @@
 r_int = build_int('r_int', True, LONG_BIT)
 r_uint = build_int('r_uint', False, LONG_BIT)
 
+@register_flow_sc(r_uint)
+def sc_r_uint(space, args_w):
+    # (normally, the 32-bit constant is a long, and is not allowed to
+    # show up in the flow graphs at all)
+    [w_value] = args_w
+    if isinstance(w_value, Constant):
+        return Constant(r_uint(w_value.value))
+    return space.frame.do_operation('simple_call', const(r_uint), w_value)
+
+
 r_longlong = build_int('r_longlong', True, 64)
 r_ulonglong = build_int('r_ulonglong', False, 64)
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to