[pypy-svn] r46811 - in pypy/dist/pypy: annotation rlib rlib/test rpython

arigo at codespeak.net arigo at codespeak.net
Sat Sep 22 11:03:01 CEST 2007


Author: arigo
Date: Sat Sep 22 11:02:59 2007
New Revision: 46811

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/rlib/rbigint.py
   pypy/dist/pypy/rlib/test/test_rbigint.py
   pypy/dist/pypy/rpython/rint.py
Log:
Remove this "very temporary hack".  This creates a path in rbigint
that the annotator doesn't know is unreachable, but on the other hand
the hack in the annotator was really getting in the way (see test
in the next checkin).


Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Sat Sep 22 11:02:59 2007
@@ -299,12 +299,6 @@
         r = SomeBool()
         if int1.is_immutable_constant() and int2.is_immutable_constant():
             r.const = operation(int1.const, int2.const)
-        else:
-            # XXX VERY temporary hack
-            if (opname == 'ge' and int2.is_immutable_constant() and
-                int2.const == 0 and
-                not rarithmetic.signedtype(int1.knowntype)):
-                r.const = True
         knowntypedata = {}
         # XXX HACK HACK HACK
         # propagate nonneg information between the two arguments

Modified: pypy/dist/pypy/rlib/rbigint.py
==============================================================================
--- pypy/dist/pypy/rlib/rbigint.py	(original)
+++ pypy/dist/pypy/rlib/rbigint.py	Sat Sep 22 11:02:59 2007
@@ -610,11 +610,10 @@
 digits_for_most_neg_long._annspecialcase_ = "specialize:argtype(0)"
 
 def args_from_rarith_int(x):
-    if x >= 0:
-        if x == 0:
-            return [0], 0
-        else:
-            return digits_from_nonneg_long(x), 1
+    if x > 0:
+        return digits_from_nonneg_long(x), 1
+    elif x == 0:
+        return [0], 0
     else:
         try:
             y = ovfcheck(-x)

Modified: pypy/dist/pypy/rlib/test/test_rbigint.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rbigint.py	(original)
+++ pypy/dist/pypy/rlib/test/test_rbigint.py	Sat Sep 22 11:02:59 2007
@@ -424,11 +424,15 @@
 
     def test_args_from_rarith_int(self):
         from pypy.rpython.test.test_llinterp import interpret
-        def fn():
-            return (rbigint.fromrarith_int(0),
-                    rbigint.fromrarith_int(17),
-                    rbigint.fromrarith_int(-17),
-                    rbigint.fromrarith_int(r_uint(0)),
-                    rbigint.fromrarith_int(r_uint(17)))
-        interpret(fn, [])
-
+        def fn(x):
+            n1 = rbigint.fromrarith_int(x)
+            n2 = rbigint.fromrarith_int(r_uint(x))
+            return '%s %s' % (n1.str(), n2.str())
+        res = interpret(fn, [0])
+        assert ''.join(res.chars) == '0 0'
+        res = interpret(fn, [sys.maxint])
+        assert ''.join(res.chars) == '%d %d' % (sys.maxint, sys.maxint)
+        res = interpret(fn, [-sys.maxint-1])
+        assert ''.join(res.chars) == '%d %d' % (-sys.maxint-1, sys.maxint+1)
+        res = interpret(fn, [-17])
+        assert ''.join(res.chars) == '%d %d' % (-17, 2*sys.maxint+2-17)

Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py	(original)
+++ pypy/dist/pypy/rpython/rint.py	Sat Sep 22 11:02:59 2007
@@ -346,14 +346,17 @@
         if hop.s_result.unsigned:
             zero = self.lowleveltype._defl()
             vlist.insert(0, hop.inputconst(self.lowleveltype, zero))
-            return hop.genop(self.opprefix + 'sub', vlist, resulttype=self)
+            return hop.genop(self.opprefix + 'neg', vlist, resulttype=self)
         else:
             return hop.genop(self.opprefix + 'neg', vlist, resulttype=self)
 
     def rtype_neg_ovf(self, hop):
         self = self.as_int
         if hop.s_result.unsigned:
-            raise TyperError("forbidden uint_neg_ovf")
+            # this is supported (and turns into just uint_neg) for
+            # rbigint.py
+            hop.exception_cannot_occur()
+            return self.rtype_neg(hop)
         else:
             vlist = hop.inputargs(self)
             hop.has_implicit_exception(OverflowError) # record we know about it



More information about the Pypy-commit mailing list