[pypy-svn] r12855 - pypy/dist/pypy/rpython

ericvrp at codespeak.net ericvrp at codespeak.net
Sat May 28 00:25:07 CEST 2005


Author: ericvrp
Date: Sat May 28 00:25:07 2005
New Revision: 12855

Modified:
   pypy/dist/pypy/rpython/rbool.py
   pypy/dist/pypy/rpython/rfloat.py
   pypy/dist/pypy/rpython/rint.py
Log:
Added explicit casting. This should also work for signed <-> unsigned integers. Some backends require this feature (LLVM).


Modified: pypy/dist/pypy/rpython/rbool.py
==============================================================================
--- pypy/dist/pypy/rpython/rbool.py	(original)
+++ pypy/dist/pypy/rpython/rbool.py	Sat May 28 00:25:07 2005
@@ -1,27 +1,32 @@
-from pypy.annotation.pairtype import pair, pairtype
-from pypy.annotation.model import SomeBool, SomeFloat, SomeInteger
-from pypy.rpython.lltype import Bool
-from pypy.rpython.rtyper import receive
+from pypy.annotation.pairtype import pairtype
+from pypy.annotation.model import SomeFloat, SomeInteger, SomeBool, SomePBC
+from pypy.rpython.lltype import Signed, Unsigned, Bool, Float
+from pypy.rpython.rtyper import receive, direct_op
+from pypy.rpython.rtyper import TyperError
 
 
-debug = True
+debug = False
 
 class __extend__(pairtype(SomeBool, SomeInteger)):
 
     def rtype_convert_from_to((s_from, s_to), v):
-        if debug: print 'XXX TODO cast SomeBool->SomeInteger'
-        return v
+        if s_to.unsigned:
+            if debug: print 'explicit cast_bool_to_uint'
+            return direct_op('cast_bool_to_uint', [v], resulttype=Unsigned)
+        else:
+            if debug: print 'explicit cast_bool_to_int'
+            return direct_op('cast_bool_to_int', [v], resulttype=Signed)
 
 
 class __extend__(pairtype(SomeBool, SomeFloat)):
 
     def rtype_convert_from_to((s_from, s_to), v):
-        if debug: print 'XXX TODO cast SomeBool->SomeFloat'
-        return v
+        if debug: print 'explicit cast_bool_to_float'
+        return direct_op('cast_bool_to_float', [v], resulttype=Float)
 
 
 class __extend__(SomeBool):
 
     def rtype_is_true(s_bool):
-        v_bool = receive(Bool, arg=0)
+        v_bool = receive(Bool, 0)
         return v_bool

Modified: pypy/dist/pypy/rpython/rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/rfloat.py	(original)
+++ pypy/dist/pypy/rpython/rfloat.py	Sat May 28 00:25:07 2005
@@ -1,11 +1,11 @@
-from pypy.annotation.pairtype import pair, pairtype
+from pypy.annotation.pairtype import pairtype
 from pypy.annotation.model import SomeFloat, SomeInteger, SomeBool, SomePBC
 from pypy.rpython.lltype import Signed, Unsigned, Bool, Float
-from pypy.rpython.rtyper import peek_at_result_annotation, receive, direct_op
+from pypy.rpython.rtyper import receive, direct_op
 from pypy.rpython.rtyper import TyperError
 
 
-debug = True
+debug = False
 
 class __extend__(pairtype(SomeFloat, SomeFloat)):
 
@@ -33,13 +33,13 @@
 
     def rtype_pow((s_float1, s_float2), s_float3=SomePBC({None: True})):
         if isinstance(s_float3, SomeInteger):
-            v_float3_list = [receive(Float, arg=2)]
+            v_float3_list = [receive(Float, 2)]
         elif s_float3.is_constant() and s_float3.const is None:
             v_float3_list = []
         else:
             raise TyperError("pow() 3rd argument must be int or None")
-        v_float1 = receive(Float, arg=0)
-        v_float2 = receive(Float, arg=1)
+        v_float1 = receive(Float, 0)
+        v_float2 = receive(Float, 1)
         return direct_op('float_pow', [v_float1, v_float2] + v_float3_list, resulttype=Float)
 
     rtype_inplace_pow = rtype_pow
@@ -70,13 +70,13 @@
 #Helpers SomeFloat,Somefloat
 
 def _rtype_template((s_float1, s_float2), func):
-        v_float1 = receive(Float, arg=0)
-        v_float2 = receive(Float, arg=1)
+        v_float1 = receive(Float, 0)
+        v_float2 = receive(Float, 1)
         return direct_op('float_'+func, [v_float1, v_float2], resulttype=Float)
 
 def _rtype_compare_template((s_float1, s_float2), func):
-    v_float1 = receive(Float, arg=0)
-    v_float2 = receive(Float, arg=1)
+    v_float1 = receive(Float, 0)
+    v_float2 = receive(Float, 1)
     return direct_op('float_'+func, [v_float1, v_float2], resulttype=Bool)
 
 
@@ -85,8 +85,12 @@
 class __extend__(pairtype(SomeFloat, SomeInteger)):
 
     def rtype_convert_from_to((s_from, s_to), v):
-        if debug: print 'XXX TODO cast SomeFloat->SomeInteger'
-        return v
+        if s_to.unsigned:
+            if debug: print 'explicit cast_float_to_uint'
+            return direct_op('cast_float_to_uint', [v], resulttype=Unsigned)
+        else:
+            if debug: print 'explicit cast_float_to_int'
+            return direct_op('cast_float_to_int', [v], resulttype=Signed)
 
 
 #
@@ -94,8 +98,12 @@
 class __extend__(pairtype(SomeInteger, SomeFloat)):
 
     def rtype_convert_from_to((s_from, s_to), v):
-        if debug: print 'XXX TODO cast SomeInteger->SomeFloat'
-        return v
+        if s_from.unsigned:
+            if debug: print 'explicit cast_uint_to_float'
+            return direct_op('cast_uint_to_float', [v], resulttype=Float)
+        else:
+            if debug: print 'explicit cast_int_to_float'
+            return direct_op('cast_int_to_float', [v], resulttype=Float)
 
 
 #
@@ -103,8 +111,8 @@
 class __extend__(pairtype(SomeFloat, SomeBool)):
 
     def rtype_convert_from_to((s_from, s_to), v):
-        if debug: print 'XXX TODO cast SomeFloat->SomeBool'
-        return v
+        if debug: print 'explicit cast_float_to_bool'
+        return direct_op('cast_float_to_bool', [v], resulttype=Bool)  #XXX or can 'float_is_true' be reused here? 
 
 
 #
@@ -112,16 +120,16 @@
 class __extend__(SomeFloat):
 
     def rtype_is_true(s_float):
-        v_float = receive(Float, arg=0)
+        v_float = receive(Float, 0)
         return direct_op('float_is_true', [v_float], resulttype=Bool)
 
     def rtype_nonzero(s_float):
-        v_float = receive(Float, arg=0)
+        v_float = receive(Float, 0)
         return direct_op('float_nonzero', [v_float], resulttype=Bool)
 
     def rtype_neg(s_int):
-        v_int = receive(Float, arg=0)
+        v_int = receive(Float, 0)
         return direct_op('float_neg', [v_int], resulttype=Float)
 
     def rtype_pos(s_int):
-        return receive(Float, arg=0)
+        return receive(Float, 0)

Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py	(original)
+++ pypy/dist/pypy/rpython/rint.py	Sat May 28 00:25:07 2005
@@ -1,192 +1,190 @@
-from pypy.annotation.pairtype import pair, pairtype
-from pypy.annotation.model import SomeInteger, SomeBool, SomePBC
-from pypy.rpython.lltype import Signed, Unsigned, Bool
-from pypy.rpython.rtyper import peek_at_result_annotation, receive, direct_op
+from pypy.annotation.pairtype import pairtype
+from pypy.annotation.model import SomeFloat, SomeInteger, SomeBool, SomePBC
+from pypy.rpython.lltype import Signed, Unsigned, Bool, Float
+from pypy.rpython.rtyper import receive, direct_op
 from pypy.rpython.rtyper import TyperError
 
 
-debug = True
+debug = False
 
 class __extend__(pairtype(SomeInteger, SomeInteger)):
 
-    def rtype_convert_from_to((s_from, s_to), v):   #XXX What is v here?
-        if s_from.unsigned != s_to.unsigned:
+    def rtype_convert_from_to((s_from, s_to), v):
+        if s_from.unsigned != s_to.unsigned:        #XXX Can _receive_may_cast(...) be used here?
             if s_to.unsigned:
-                if debug: print 'explicit cast Signed->Unsigned'
-                v_int = receive(Signed, arg=0)
-                return direct_op('cast_int_to_uint', [v_int], resulttype=Unsigned)
+                if debug: print 'explicit cast_int_to_uint'
+                return direct_op('cast_int_to_uint', [v], resulttype=Unsigned)
             else:
-                if debug: print 'explicit cast Unsigned->Signed'
-                v_int = receive(Unsigned, arg=0)
-                return direct_op('cast_uint_to_int', [v_int], resulttype=Signed)
+                if debug: print 'explicit cast_uint_to_int'
+                return direct_op('cast_uint_to_int', [v], resulttype=Signed)
         return v
 
     #arithmetic
     
     def rtype_add((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_add', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_add', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_add = rtype_add
 
     def rtype_add_ovf((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_add_ovf', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_add_ovf', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_add_ovf = rtype_add_ovf
 
     def rtype_sub((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_sub', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_sub', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_sub = rtype_sub
 
     def rtype_sub_ovf((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_sub_ovf', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_sub_ovf', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_sub_ovf = rtype_sub_ovf
 
     def rtype_mul((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_mul', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_mul', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_mul = rtype_mul
 
     def rtype_div((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_div', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_div', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_div = rtype_div
 
     def rtype_mod((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_mod', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_mod', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_mod = rtype_mod
 
     def rtype_xor((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_xor', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_xor', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_xor = rtype_xor
 
     def rtype_and_((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_and', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_and', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_and = rtype_and_
 
     def rtype_or_((s_int1, s_int2)):
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_or', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_or', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_or = rtype_or_
 
     def rtype_lshift((s_int1, s_int2)):
         if s_int1.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_lshift', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_lshift', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_lshift = rtype_lshift
 
     def rtype_rshift((s_int1, s_int2)):
         if s_int1.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_rshift', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_rshift', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_rshift = rtype_rshift
 
     def rtype_lshift_ovf((s_int1, s_int2)):
         if s_int1.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_lshift_ovf', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_lshift_ovf', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_lshift_ovf = rtype_lshift_ovf
 
     def rtype_rshift_ovf((s_int1, s_int2)):
         if s_int1.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_rshift_ovf', [v_int1, v_int2], resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_rshift_ovf', [v_int1, v_int2], resulttype=Signed)
 
     rtype_inplace_rshift_ovf = rtype_rshift_ovf
@@ -194,20 +192,20 @@
     def rtype_pow((s_int1, s_int2), s_int3=SomePBC({None: True})):
         if isinstance(s_int3, SomeInteger):
             if s_int3.unsigned:
-                v_int3_list = [receive(Unsigned, arg=2)]
+                v_int3_list = [_receive_may_cast(s_int1, Unsigned, 2)]
             else:
-                v_int3_list = [receive(Signed, arg=2)]
+                v_int3_list = [_receive_may_cast(s_int1, Signed, 2)]
         elif s_int3.is_constant() and s_int3.const is None:
             v_int3_list = []
         else:
             raise TyperError("pow() 3rd argument must be int or None")
         if s_int1.unsigned or s_int2.unsigned:
-            v_int1 = receive(Unsigned, arg=0)
-            v_int2 = receive(Unsigned, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+            v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
             return direct_op('uint_pow', [v_int1, v_int2] + v_int3_list, resulttype=Unsigned)
         else:
-            v_int1 = receive(Signed, arg=0)
-            v_int2 = receive(Signed, arg=1)
+            v_int1 = _receive_may_cast(s_int1, Signed, 0)
+            v_int2 = _receive_may_cast(s_int2, Signed, 1)
             return direct_op('int_pow', [v_int1, v_int2] + v_int3_list, resulttype=Signed)
 
     rtype_inplace_pow = rtype_pow
@@ -234,18 +232,39 @@
     def rtype_ge(args):
         return _rtype_compare_template(args, 'ge')
 
+#Helper functions
+
+def _receive_may_cast(s_var, s_requested, arg):
+    v = receive(s_requested, arg)
+    s = (Signed,Unsigned)[s_var.unsigned]
+    if s != s_requested:
+        if s_requested is Unsigned:
+            if debug: print 'cast_int_to_uint'
+            return direct_op('cast_int_to_uint', [v], resulttype=Unsigned)
+        else:
+            if debug: print 'cast_uint_to_int'
+            return direct_op('cast_uint_to_int', [v], resulttype=Signed)
+    #elif debug:
+    #    if s_requested is Unsigned:
+    #        if debug: print 'fake cast_uint_to_uint'
+    #        return direct_op('cast_uint_to_uint', [v], resulttype=Unsigned)
+    #    else:
+    #        if debug: print 'fake cast_int_to_int'
+    #        return direct_op('cast_int_to_int', [v], resulttype=Signed)
+    return v
+    
 #Helper functions for comparisons
 
 def _rtype_compare_template((s_int1, s_int2), func):
     if s_int1.unsigned or s_int2.unsigned:
         if not s_int1.nonneg or not s_int2.nonneg:
             raise TyperError("comparing a signed and an unsigned number")
-        v_int1 = receive(Unsigned, arg=0)
-        v_int2 = receive(Unsigned, arg=1)
+        v_int1 = _receive_may_cast(s_int1, Unsigned, 0)
+        v_int2 = _receive_may_cast(s_int2, Unsigned, 1)
         return direct_op('uint_'+func, [v_int1, v_int2], resulttype=Bool)
     else:
-        v_int1 = receive(Signed, arg=0)
-        v_int2 = receive(Signed, arg=1)
+        v_int1 = _receive_may_cast(s_int1, Signed, 0)
+        v_int2 = _receive_may_cast(s_int2, Signed, 1)
         return direct_op('int_'+func, [v_int1, v_int2], resulttype=Bool)
 
 
@@ -254,32 +273,35 @@
 class __extend__(SomeInteger):
 
     def rtype_is_true(s_int):
-        v_int = receive(Signed, arg=0)
+        v_int = _receive_may_cast(s_int, Signed, 0)
         return direct_op('int_is_true', [v_int], resulttype=Bool)
 
     #Unary arithmetic operations    
     
     def rtype_abs(s_int):
         if s_int.unsigned:
-            v_int = receive(Unsigned, arg=0)
+            return _receive_may_cast(s_int, Unsigned, 0)
         else:
-            v_int = receive(Signed, arg=0)
-        return direct_op('int_abs', [v_int], resulttype=Signed) #XXX I would like to make this Unsigned, but the annotator insists it is Signed!
+            v_int = _receive_may_cast(s_int, Signed, 0)
+            return direct_op('int_abs', [v_int], resulttype=Signed) #XXX I would like to make this Unsigned, but the annotator insists it is Signed!
 
     def rtype_abs_ovf(s_int):
-        v_int = receive(Signed, arg=0)
-        return direct_op('int_abs_ovf', [v_int], resulttype=Signed) #XXX I would like to make this Unsigned, but the annotator insists it is Signed!
+        if s_int.unsigned:
+            return _receive_may_cast(s_int, Unsigned, 0)
+        else:
+            v_int = _receive_may_cast(s_int, Signed, 0)
+            direct_op('int_abs_ovf', [v_int], resulttype=Signed) #XXX I would like to make this Unsigned, but the annotator insists it is Signed!
 
     def rtype_invert(s_int):
-        v_int = receive(Signed, arg=0)
+        v_int = _receive_may_cast(s_int, Signed, 0)
         return direct_op('int_invert', [v_int], resulttype=Signed)
 
     def rtype_neg(s_int):
-        v_int = receive(Signed, arg=0)
+        v_int = _receive_may_cast(s_int, Signed, 0)
         return direct_op('int_neg', [v_int], resulttype=Signed)
 
     def rtype_pos(s_int):
         if s_int.unsigned:
-            return receive(Unsigned, arg=0)
+            return _receive_may_cast(s_int, Unsigned, 0)
         else:
-            return receive(Signed, arg=0)
+            return _receive_may_cast(s_int, Signed, 0)



More information about the Pypy-commit mailing list