[pypy-svn] r75938 - in pypy/trunk/pypy/jit/codewriter: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jul 6 19:27:37 CEST 2010


Author: arigo
Date: Tue Jul  6 19:27:36 2010
New Revision: 75938

Modified:
   pypy/trunk/pypy/jit/codewriter/jtransform.py
   pypy/trunk/pypy/jit/codewriter/test/test_flatten.py
Log:
Merge r75925 from branch/reflex-support:

    start some support for very simple force_cast cases


Modified: pypy/trunk/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/trunk/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/trunk/pypy/jit/codewriter/jtransform.py	Tue Jul  6 19:27:36 2010
@@ -667,7 +667,7 @@
             return self._rewrite_symmetric(op)
 
     def _is_gc(self, v):
-        return v.concretetype.TO._gckind == 'gc'
+        return getattr(getattr(v.concretetype, "TO", None), "_gckind", "?") == 'gc'
 
     def _rewrite_cmp_ptrs(self, op):
         if self._is_gc(op.args[0]):
@@ -701,6 +701,17 @@
             #return op
             raise NotImplementedError("cast_ptr_to_int")
 
+    def rewrite_op_force_cast(self, op):
+        from pypy.rpython.lltypesystem.rffi import size_and_sign
+        from pypy.rlib.rarithmetic import intmask
+        assert not self._is_gc(op.args[0])
+        size1, unsigned1 = size_and_sign(op.args[0].concretetype)
+        size2, unsigned2 = size_and_sign(op.result.concretetype)
+        if size1 == size2 and unsigned1 == unsigned2:
+            return
+        raise NotImplementedError("cast not supported yet: %s" % (op, ))
+
+
     # ----------
     # Renames, from the _old opname to the _new one.
     # The new operation is optionally further processed by rewrite_operation().

Modified: pypy/trunk/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/trunk/pypy/jit/codewriter/test/test_flatten.py	(original)
+++ pypy/trunk/pypy/jit/codewriter/test/test_flatten.py	Tue Jul  6 19:27:36 2010
@@ -729,3 +729,32 @@
             int_between %i0, %i1, %i2 -> %i3
             int_return %i3
         """, transform=True)
+
+    def test_force_cast(self):
+        py.test.skip("later")
+        from pypy.rpython.lltypesystem import rffi
+        def f(n):
+            c = chr(n)
+            return rffi.cast(rffi.INT, c)
+        self.encoding_test(f, [42], """
+            int_return %i0
+        """, transform=True)
+        def g(n):
+            return rffi.cast(rffi.UCHAR, n)
+        self.encoding_test(g, [42], """
+            int_and %i0, $255 -> %i1
+            int_return %i1
+        """, transform=True)
+        def h(n):
+            return rffi.cast(rffi.SCHAR, n)
+        self.encoding_test(h, [42], """
+            ...
+        """, transform=True)
+
+    def test_force_cast_pointer(self):
+        from pypy.rpython.lltypesystem import rffi
+        def h(p):
+            return rffi.cast(rffi.VOIDP, p)
+        self.encoding_test(h, [lltype.nullptr(rffi.CCHARP.TO)], """
+            int_return %i0
+        """, transform=True)



More information about the Pypy-commit mailing list