[pypy-svn] r14939 - in pypy/dist/pypy: annotation translator/test

pedronis at codespeak.net pedronis at codespeak.net
Fri Jul 22 19:44:51 CEST 2005


Author: pedronis
Date: Fri Jul 22 19:44:50 2005
New Revision: 14939

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
nonneg cleverness should not kill unsignedness + test



Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Fri Jul 22 19:44:50 2005
@@ -257,11 +257,11 @@
         if int1.nonneg and isinstance(op.args[1], Variable):
             case = opname in ('lt', 'le', 'eq')
             add_knowntypedata(knowntypedata, case, [op.args[1]],
-                              SomeInteger(nonneg=True))
+                              SomeInteger(nonneg=True, unsigned=int2.unsigned))
         if int2.nonneg and isinstance(op.args[0], Variable):
             case = opname in ('gt', 'ge', 'eq')
             add_knowntypedata(knowntypedata, case, [op.args[0]],
-                              SomeInteger(nonneg=True))
+                              SomeInteger(nonneg=True, unsigned=int1.unsigned))
         if knowntypedata:
             r.knowntypedata = knowntypedata
         return r

Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py	Fri Jul 22 19:44:50 2005
@@ -1272,6 +1272,24 @@
         s = a.build_types(f, [int, int])
         assert s == annmodel.SomeTuple([annmodel.SomeInteger(nonneg=True)] * 2)
 
+    def test_nonneg_cleverness_is_gentle_with_unsigned(self):
+        def witness1(x):
+            pass
+        def witness2(x):
+            pass        
+        def f(x):
+            if 0 < x:
+                witness1(x)
+            if x > 0:
+                witness2(x)
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [annmodel.SomeInteger(unsigned=True)])
+        wg1 = a.translator.getflowgraph(witness1)
+        wg2 = a.translator.getflowgraph(witness2)        
+        assert a.binding(wg1.getargs()[0]).unsigned is True
+        assert a.binding(wg2.getargs()[0]).unsigned is True        
+        
+
     def test_attr_moving_into_parent(self):
         class A: pass
         class B(A): pass



More information about the Pypy-commit mailing list