[pypy-svn] r35690 - in pypy/dist/pypy/rpython: . lltypesystem test

pedronis at codespeak.net pedronis at codespeak.net
Wed Dec 13 18:37:12 CET 2006


Author: pedronis
Date: Wed Dec 13 18:37:08 2006
New Revision: 35690

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/lltypesystem/lloperation.py
   pypy/dist/pypy/rpython/test/test_rint.py
Log:
finish llong_neg/abs_ovf support



Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Wed Dec 13 18:37:08 2006
@@ -769,6 +769,20 @@
         except OverflowError:
             self.make_llexception()
 
+    def op_llong_neg_ovf(self, x):
+        assert type(x) is r_longlong
+        try:
+            return ovfcheck(-x)
+        except OverflowError:
+            self.make_llexception()
+
+    def op_llong_abs_ovf(self, x):
+        assert type(x) is r_longlong
+        try:
+            return ovfcheck(abs(x))
+        except OverflowError:
+            self.make_llexception()
+
     def _makefunc2(fn, operator, xtype, ytype=None):
         import sys
         d = sys._getframe(1).f_locals

Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py	Wed Dec 13 18:37:08 2006
@@ -223,7 +223,9 @@
 
     'llong_is_true':        LLOp(canfold=True),
     'llong_neg':            LLOp(canfold=True),
+    'llong_neg_ovf':        LLOp(canraise=(OverflowError,)),
     'llong_abs':            LLOp(canfold=True),
+    'llong_abs_ovf':        LLOp(canraise=(OverflowError,)),    
     'llong_invert':         LLOp(canfold=True),
 
     'llong_add':            LLOp(canfold=True),

Modified: pypy/dist/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rint.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rint.py	Wed Dec 13 18:37:08 2006
@@ -1,8 +1,9 @@
-import sys
+import sys, operator
 from pypy.translator.translator import TranslationContext
 from pypy.annotation import model as annmodel
 from pypy.rpython.test import snippet
-from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
+from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
+from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 
 class TestSnippet(object):
@@ -174,6 +175,24 @@
             assert res == f(inttype(0))
             assert type(res) == inttype
 
+    def test_neg_abs_ovf(self):
+        for op in (operator.neg, abs):
+            def f(x):
+                try:
+                    return ovfcheck(op(x))
+                except OverflowError:
+                    return 0
+            res = self.interpret(f, [-1])
+            assert res == 1
+            res = self.interpret(f, [int(-1<<(r_int.BITS-1))])
+            assert res == 0
+
+            res = self.interpret(f, [r_longlong(-1)])
+            assert res == 1
+            res = self.interpret(f, [r_longlong(-1)<<(r_longlong.BITS-1)])
+            assert res == 0
+            
+
 class TestLLtype(BaseTestRint, LLRtypeMixin):
     pass
 



More information about the Pypy-commit mailing list