[pypy-commit] pypy translation-cleanup: Flowspacify COMPARE_OP

rlamy noreply at buildbot.pypy.org
Sat Sep 29 01:09:32 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57639:312c5669e4bf
Date: 2012-09-28 03:25 +0100
http://bitbucket.org/pypy/pypy/changeset/312c5669e4bf/

Log:	Flowspacify COMPARE_OP

	* Remove FlowObjSpace.w_str
	* Fixes an xfailing test

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -25,7 +25,6 @@
         msg += source_lines(self.frame.graph, None, offset=self.frame.last_instr)
         return "\n".join(msg)
 
-
 class StopFlowing(Exception):
     pass
 
@@ -220,6 +219,20 @@
 
 # ____________________________________________________________
 
+compare_method = [
+    "cmp_lt",   # "<"
+    "cmp_le",   # "<="
+    "cmp_eq",   # "=="
+    "cmp_ne",   # "!="
+    "cmp_gt",   # ">"
+    "cmp_ge",   # ">="
+    "cmp_in",
+    "cmp_not_in",
+    "cmp_is",
+    "cmp_is_not",
+    "cmp_exc_match",
+    ]
+
 class FlowSpaceFrame(pyframe.CPythonFrame):
 
     def __init__(self, space, func, constargs=None):
@@ -478,6 +491,45 @@
         unroller = SContinueLoop(startofloop)
         return self.unrollstack_and_jump(unroller)
 
+    def cmp_lt(self, w_1, w_2):
+        return self.space.lt(w_1, w_2)
+
+    def cmp_le(self, w_1, w_2):
+        return self.space.le(w_1, w_2)
+
+    def cmp_eq(self, w_1, w_2):
+        return self.space.eq(w_1, w_2)
+
+    def cmp_ne(self, w_1, w_2):
+        return self.space.ne(w_1, w_2)
+
+    def cmp_gt(self, w_1, w_2):
+        return self.space.gt(w_1, w_2)
+
+    def cmp_ge(self, w_1, w_2):
+        return self.space.ge(w_1, w_2)
+
+    def cmp_in(self, w_1, w_2):
+        return self.space.contains(w_2, w_1)
+
+    def cmp_not_in(self, w_1, w_2):
+        return self.space.not_(self.space.contains(w_2, w_1))
+
+    def cmp_is(self, w_1, w_2):
+        return self.space.is_(w_1, w_2)
+
+    def cmp_is_not(self, w_1, w_2):
+        return self.space.not_(self.space.is_(w_1, w_2))
+
+    def cmp_exc_match(self, w_1, w_2):
+        return self.space.newbool(self.space.exception_match(w_1, w_2))
+
+    def COMPARE_OP(self, testnum, next_instr):
+        w_2 = self.popvalue()
+        w_1 = self.popvalue()
+        w_result = getattr(self, compare_method[testnum])(w_1, w_2)
+        self.pushvalue(w_result)
+
     def RAISE_VARARGS(self, nbargs, next_instr):
         space = self.space
         if nbargs == 0:
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
@@ -68,9 +68,6 @@
             clsname = exc.__name__
             setattr(self, 'w_'+clsname, None)
         self.specialcases = SPECIAL_CASES.copy()
-        # w_str is needed because cmp_exc_match of frames checks against it,
-        # as string exceptions are deprecated
-        self.w_str = Constant(str)
         # objects which should keep their SomeObjectness
         self.not_really_const = NOT_REALLY_CONST
 
diff --git a/pypy/objspace/flow/test/test_objspace.py b/pypy/objspace/flow/test/test_objspace.py
--- a/pypy/objspace/flow/test/test_objspace.py
+++ b/pypy/objspace/flow/test/test_objspace.py
@@ -991,7 +991,6 @@
             self.codetest(f)
         assert 'div(5, 0)' in str(excinfo.value)
 
-    @py.test.mark.xfail
     def test_nonconstant_except(self):
         def f(exc_cls):
             try:


More information about the pypy-commit mailing list