Author: Ronan Lamy <[email protected]>
Branch: flowoperators
Changeset: r65216:95ee9391ba6f
Date: 2013-05-03 19:35 +0100
http://bitbucket.org/pypy/pypy/changeset/95ee9391ba6f/

Log:    Kill OperationName (use a mapping of functions to operators instead)

diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -99,10 +99,13 @@
 add_operator('userdel', 1, 'del')
 add_operator('buffer', 1, 'buffer')   # see buffer.py
 
+# Add _ovf ops
+for oper in [op.neg, op.abs, op.add, op.sub, op.mul, op.floordiv, op.div,
+        op.mod, op.lshift]:
+    add_operator(oper.name + '_ovf', oper.arity, oper.symbol)
+
 
 FunctionByName = {}   # dict {"operation_name": <built-in function>}
-OperationName  = {}   # dict {<built-in function>: "operation_name"}
-Arity          = {}   # dict {"operation name": number of arguments}
 
 # ____________________________________________________________
 
@@ -306,11 +309,12 @@
 ]
 
 # build the dictionaries
+func2op = {}
 for name, func in Table:
     if name not in FunctionByName:
         FunctionByName[name] = func
-    if func not in OperationName:
-        OperationName[func] = name
+    if func not in func2op:
+        func2op[func] = getattr(op, name)
 del Table  # INTERNAL ONLY, use the dicts declared at the top of the file
 
 # insert all operators
@@ -319,15 +323,14 @@
         func = getattr(operator, name)
         if name not in FunctionByName:
             FunctionByName[name] = func
-        if func not in OperationName:
-            OperationName[func] = name
+        if func not in func2op:
+            func2op[func] = getattr(op, name)
 
 # Other functions that get directly translated to SpaceOperators
-func2op = {type: op.type, operator.truth: op.nonzero}
+func2op[type] = op.type
+func2op[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 = {
diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -1,5 +1,5 @@
 from rpython.flowspace.model import Constant
-from rpython.flowspace.operation import OperationName, op
+from rpython.flowspace.operation import func2op, op
 from rpython.rlib.rarithmetic import r_uint
 from rpython.rlib.objectmodel import we_are_translated
 
@@ -9,19 +9,18 @@
     return space.import_name(*args)
 
 def sc_operator(space, fn, args_w):
-    opname = OperationName[fn]
-    oper = getattr(op, opname)
+    oper = func2op[fn]
     if len(args_w) != oper.arity:
-        if opname == 'pow' and len(args_w) == 2:
+        if oper is op.pow and len(args_w) == 2:
             args_w = args_w + [Constant(None)]
-        elif opname == 'getattr' and len(args_w) == 3:
+        elif oper is op.getattr and len(args_w) == 3:
             return space.frame.do_operation('simple_call', Constant(getattr), 
*args_w)
         else:
             raise Exception("should call %r with exactly %d arguments" % (
                 fn, oper.arity))
     # completely replace the call with the underlying
     # operation and its limited implicit exceptions semantic
-    return getattr(space, opname)(*args_w)
+    return getattr(space, oper.name)(*args_w)
 
 # _________________________________________________________________________
 # a simplified version of the basic printing routines, for RPython programs
@@ -72,5 +71,5 @@
 SPECIAL_CASES = {__import__: sc_import, r_uint: sc_r_uint,
         we_are_translated: sc_we_are_translated,
         locals: sc_locals}
-for fn in OperationName:
+for fn in func2op:
     SPECIAL_CASES[fn] = sc_operator
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to