[pypy-commit] pypy flowoperators: setup SpaceOperators a bit more explicitly

rlamy noreply at buildbot.pypy.org
Fri Jul 5 19:41:53 CEST 2013


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: flowoperators
Changeset: r65215:c78d0f3c3045
Date: 2013-05-03 18:54 +0100
http://bitbucket.org/pypy/pypy/changeset/c78d0f3c3045/

Log:	setup SpaceOperators a bit more explicitly

diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -245,7 +245,6 @@
 Table = [
     ('id',              id),
     ('type',            new_style_type),
-    ('type',            type),
     ('isinstance',      isinstance),
     ('issubtype',       issubclass),
     ('repr',            repr),
@@ -257,9 +256,7 @@
     ('setattr',         setattr),
     ('delattr',         delattr),
     ('nonzero',         bool),
-    ('nonzero',         operator.truth),
     ('is_true',         bool),
-    ('is_true',         operator.truth),
     ('trunc',           unsupported),
     ('abs' ,            abs),
     ('hex',             hex),
@@ -307,22 +304,31 @@
     ('mod_ovf',         mod_ovf),
     ('lshift_ovf',      lshift_ovf),
 ]
-if hasattr(__builtin__, 'next'):
-    Table.append(('next', __builtin__.next))
 
-def setup():
-    # insert all operators
-    for name in vars(op):
-        if hasattr(operator, name):
-            Table.append((name, getattr(operator, name)))
-    # build the dictionaries
-    for name, func in Table:
+# build the dictionaries
+for name, func in Table:
+    if name not in FunctionByName:
+        FunctionByName[name] = func
+    if func not in OperationName:
+        OperationName[func] = name
+del Table  # INTERNAL ONLY, use the dicts declared at the top of the file
+
+# insert all operators
+for name in vars(op):
+    if hasattr(operator, name):
+        func = getattr(operator, name)
         if name not in FunctionByName:
             FunctionByName[name] = func
         if func not in OperationName:
             OperationName[func] = name
-setup()
-del Table, setup # INTERNAL ONLY, use the dicts declared at the top of the file
+
+# Other functions that get directly translated to SpaceOperators
+func2op = {type: op.type, operator.truth: op.nonzero}
+if hasattr(__builtin__, 'next'):
+    func2op[__builtin__.next] = op.next
+for func, oper in func2op.iteritems():
+    OperationName[func] = oper.name
+
 
 op_appendices = {
     OverflowError: 'ovf',


More information about the pypy-commit mailing list