1. Pypy
  2. Untitled project
  3. pypy

Commits

Carl Friedrich Bolz  committed 936da5f

back out 658f358e5f30

(breaks translation)

  • Participants
  • Parent commits c9b9d0b
  • Branches default

Comments (0)

Files changed (5)

File rpython/jit/metainterp/optimizeopt/rewrite.py

View file
 
 
     def find_rewritable_bool(self, op, args):
-        oldopnum = opboolinvers[op.getopnum()]
-        if oldopnum != -1:
+        try:
+            oldopnum = opboolinvers[op.getopnum()]
+        except KeyError:
+            pass
+        else:
             targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[0], args[1]],
                                                               None))
             if self.try_boolinvers(op, targs):
                 return True
 
-        oldopnum = opboolreflex[op.getopnum()] # FIXME: add INT_ADD, INT_MUL
-        if oldopnum != -1:
+        try:
+            oldopnum = opboolreflex[op.getopnum()] # FIXME: add INT_ADD, INT_MUL
+        except KeyError:
+            pass
+        else:
             targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]],
                                                               None))
             oldop = self.get_pure_result(targs)
                 self.make_equal_to(op.result, self.getvalue(oldop.result))
                 return True
 
-        reflex = opboolreflex[op.getopnum()]
-        if reflex != -1:
-            oldopnum = opboolinvers[reflex]
-            if oldopnum != -1:
-                targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]],
-                                                                  None))
-                if self.try_boolinvers(op, targs):
-                    return True
+        try:
+            oldopnum = opboolinvers[opboolreflex[op.getopnum()]]
+        except KeyError:
+            pass
+        else:
+            targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]],
+                                                              None))
+            if self.try_boolinvers(op, targs):
+                return True
 
         return False
 

File rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py

View file
                 op = opname[opnum]
             except KeyError:
                 continue
-            if 'float' in op:
+            if 'FLOAT' in op:
                 continue
             args = []
             for _ in range(oparity[opnum]):

File rpython/jit/metainterp/optimizeopt/util.py

View file
             opname = name[len(name_prefix):]
             if opname.isupper():
                 assert hasattr(resoperation.rop, opname)
-    for value, name in enumerate(resoperation.opname):
+    for value, name in resoperation.opname.items():
         if op_prefix and not name.startswith(op_prefix):
             continue
         if hasattr(Class, name_prefix + name):

File rpython/jit/metainterp/resoperation.py

View file
                                              ['descr=%r' % descr]))
 
     def getopname(self):
-        return opname[self.getopnum()]
+        try:
+            return opname[self.getopnum()].lower()
+        except KeyError:
+            return '<%d>' % self.getopnum()
 
     def is_guard(self):
         return rop._GUARD_FIRST <= self.getopnum() <= rop._GUARD_LAST
     pass
 
 opclasses = []   # mapping numbers to the concrete ResOp class
-opname = []      # mapping numbers to the original names, for debugging
+opname = {}      # mapping numbers to the original names, for debugging
 oparity = []     # mapping numbers to the arity of the operation or -1
 opwithdescr = [] # mapping numbers to a flag "takes a descr"
 
             arity, withdescr, boolresult = -1, True, False       # default
         setattr(rop, name, i)
         if not name.startswith('_'):
+            opname[i] = name
             cls = create_class_for_op(name, i, arity, withdescr)
             cls._cls_has_bool_result = boolresult
         else:
-            name = '<%d>' % i
             cls = None
-        opname.append(name.lower())
         opclasses.append(cls)
         oparity.append(arity)
         opwithdescr.append(withdescr)
-    assert len(opclasses) == len(oparity) == len(opwithdescr) == len(_oplist) == len(opname)
+    assert len(opclasses) == len(oparity) == len(opwithdescr) == len(_oplist)
 
 def get_base_class(mixin, base):
     try:
 setup(__name__ == '__main__')   # print out the table when run directly
 del _oplist
 
-def opdict_to_list(d, default=-1):
-    return [d.get(i, default) for i in range(len(opname))]
-
-opboolinvers = opdict_to_list({
+opboolinvers = {
     rop.INT_EQ: rop.INT_NE,
     rop.INT_NE: rop.INT_EQ,
     rop.INT_LT: rop.INT_GE,
 
     rop.PTR_EQ: rop.PTR_NE,
     rop.PTR_NE: rop.PTR_EQ,
-})
+}
 
-opboolreflex = opdict_to_list({
+opboolreflex = {
     rop.INT_EQ: rop.INT_EQ,
     rop.INT_NE: rop.INT_NE,
     rop.INT_LT: rop.INT_GT,
 
     rop.PTR_EQ: rop.PTR_EQ,
     rop.PTR_NE: rop.PTR_NE,
-})
+}
 
 
 def get_deep_immutable_oplist(operations):

File rpython/jit/metainterp/test/test_executor.py

View file
 
 def make_args_for_op(op, a, b):
     n=opname[op]
-    if n[0:3] == 'int' or n[0:4] == 'uint':
+    if n[0:3] == 'INT' or n[0:4] == 'UINT':
         arg1 = ConstInt(a)
         arg2 = ConstInt(b)
-    elif n[0:5] == 'float':
+    elif n[0:5] == 'FLOAT':
         arg1 = constfloat(float(a))
         arg2 = constfloat(float(b))
-    elif n[0:3] == 'ptr':
+    elif n[0:3] == 'PTR':
         arg1 = ConstPtr(rffi.cast(llmemory.GCREF, a))
         arg2 = ConstPtr(rffi.cast(llmemory.GCREF, b))
     else:
 
 def test_opboolinvers():
     cpu = FakeCPU()
-    for op1, op2 in enumerate(opboolinvers):
-        if op2 == -1:
-            continue
+    for op1, op2 in opboolinvers.items():
         for a in (1,2,3):
             for b in (1,2,3):
                 arg1, arg2 = make_args_for_op(op1, a, b)
 
 def test_opboolreflex():
     cpu = FakeCPU()
-    for op1, op2 in enumerate(opboolreflex):
-        if op2 == -1:
-            continue
+    for op1, op2 in opboolreflex.items():
         for a in (1,2,3):
             for b in (1,2,3):
                 arg1, arg2 = make_args_for_op(op1, a, b)