[pypy-svn] r32837 - in pypy/dist/pypy: rpython/raisingops translator/backendopt

arigo at codespeak.net arigo at codespeak.net
Tue Oct 3 13:04:57 CEST 2006


Author: arigo
Date: Tue Oct  3 13:04:51 2006
New Revision: 32837

Modified:
   pypy/dist/pypy/rpython/raisingops/raisingops.py
   pypy/dist/pypy/translator/backendopt/raisingop2direct_call.py
Log:
Add support for llong_neg_ovf in raisingops.


Modified: pypy/dist/pypy/rpython/raisingops/raisingops.py
==============================================================================
--- pypy/dist/pypy/rpython/raisingops/raisingops.py	(original)
+++ pypy/dist/pypy/rpython/raisingops/raisingops.py	Tue Oct  3 13:04:51 2006
@@ -1,9 +1,16 @@
+import sys
 from pypy.rpython.rarithmetic import r_longlong, r_uint, intmask
 
 #XXX original SIGNED_RIGHT_SHIFT_ZERO_FILLS not taken into account
 #XXX assuming HAVE_LONG_LONG (int_mul_ovf)
 #XXX should int_mod and int_floordiv return an intmask(...) instead?
 
+LONG_MAX = sys.maxint
+LONG_MIN = -sys.maxint-1
+
+LLONG_MAX = r_longlong(2 ** (r_longlong.BITS-1) - 1)
+LLONG_MIN = -LLONG_MAX-1
+
 def int_floordiv_zer(x, y):
     '''#define OP_INT_FLOORDIV_ZER(x,y,r,err) \
         if ((y)) { OP_INT_FLOORDIV(x,y,r,err); } \
@@ -25,31 +32,30 @@
         raise ZeroDivisionError("unsigned integer division")
 
 def int_neg_ovf(x):
-    '''#define OP_INT_NEG_OVF(x,r,err) \
-        OP_INT_NEG(x,r,err); \
-        if ((x) >= 0 || (x) != -(x)); \
-        else FAIL_OVF(err, "integer negate")
-    '''
-    r = -x
-    if x >= 0 or x != r:
-        return r
-    else:
+    if x == LONG_MIN:
+        raise OverflowError("integer negate")
+    return -x
+
+def llong_neg_ovf(x):
+    if x == LLONG_MIN:
         raise OverflowError("integer negate")
+    return -x
 
 def int_abs_ovf(x):
-    '''#define OP_INT_ABS_OVF(x,r,err) \
-        OP_INT_ABS(x,r,err); \
-        if ((x) >= 0 || (x) != -(x)); \
-        else FAIL_OVF(err, "integer absolute")
-    '''
-    if x >= 0:
-        r = x
-    else:
-        r = -x
-    if x >= 0 or x != r:
-        return r
+    if x == LONG_MIN:
+        raise OverflowError("integer absolute")
+    if x < 0:
+        return -x
     else:
+        return x
+
+def llong_abs_ovf(x):
+    if x == LLONG_MIN:
         raise OverflowError("integer absolute")
+    if x < 0:
+        return -x
+    else:
+        return x
 
 def int_add_ovf(x, y):
     '''#define OP_INT_ADD_OVF(x,y,r,err) \

Modified: pypy/dist/pypy/translator/backendopt/raisingop2direct_call.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/raisingop2direct_call.py	(original)
+++ pypy/dist/pypy/translator/backendopt/raisingop2direct_call.py	Tue Oct  3 13:04:51 2006
@@ -16,7 +16,8 @@
 
     def is_raisingop(op):
         s = op.opname
-        if not s.startswith('int_') and not s.startswith('uint_') and not s.startswith('float_'):
+        if (not s.startswith('int_') and not s.startswith('uint_') and
+            not s.startswith('float_') and not s.startswith('llong_')):
            return False
         if not s.endswith('_zer') and not s.endswith('_ovf') and not s.endswith('_val'): #not s in special_operations:
            return False



More information about the Pypy-commit mailing list