[pypy-svn] r51783 - in pypy/branch/unified-rtti/pypy/translator/c: src test

arigo at codespeak.net arigo at codespeak.net
Fri Feb 22 11:54:09 CET 2008


Author: arigo
Date: Fri Feb 22 11:54:08 2008
New Revision: 51783

Modified:
   pypy/branch/unified-rtti/pypy/translator/c/src/address.h
   pypy/branch/unified-rtti/pypy/translator/c/test/test_lladdresses.py
Log:
translation to C of adr|int, adr&int


Modified: pypy/branch/unified-rtti/pypy/translator/c/src/address.h
==============================================================================
--- pypy/branch/unified-rtti/pypy/translator/c/src/address.h	(original)
+++ pypy/branch/unified-rtti/pypy/translator/c/src/address.h	Fri Feb 22 11:54:08 2008
@@ -18,3 +18,7 @@
 
 #define OP_CAST_ADR_TO_INT(x, r)     r = ((long)x)
 #define OP_CAST_INT_TO_ADR(x, r)     r = ((void *)(x))
+
+/* XXX assumes that addresses fit in a long */
+#define OP_ADR_OR(x,y,r)    r = (char *)((long)(x) | (y))
+#define OP_ADR_AND(x,y,r)   r = (char *)((long)(x) & (y))

Modified: pypy/branch/unified-rtti/pypy/translator/c/test/test_lladdresses.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/translator/c/test/test_lladdresses.py	(original)
+++ pypy/branch/unified-rtti/pypy/translator/c/test/test_lladdresses.py	Fri Feb 22 11:54:08 2008
@@ -60,6 +60,44 @@
     res = fc(10, "c")
     assert res == "c"
 
+def test_flags_in_low_bits():
+    S = lltype.GcStruct('S', ('x', lltype.Signed))
+    def fn():
+        s = lltype.malloc(S)
+        a = cast_ptr_to_adr(s)
+        assert cast_adr_to_int(a) & 3 == 0
+        assert cast_adr_to_int(a | 0) & 3 == 0
+        assert cast_adr_to_int(a | 1) & 3 == 1
+        assert cast_adr_to_int(a | 2) & 3 == 2
+        assert cast_adr_to_int(a | 3) & 3 == 3
+        assert cast_adr_to_int(a & ~0) & 3 == 0
+        assert cast_adr_to_int(a & ~1) & 3 == 0
+        assert cast_adr_to_int(a & ~2) & 3 == 0
+        assert cast_adr_to_int(a & ~3) & 3 == 0
+        assert cast_adr_to_int((a | 1) & ~0) & 3 == 1
+        assert cast_adr_to_int((a | 1) & ~1) & 3 == 0
+        assert cast_adr_to_int((a | 1) & ~2) & 3 == 1
+        assert cast_adr_to_int((a | 1) & ~3) & 3 == 0
+        assert cast_adr_to_int((a | 2) & ~0) & 3 == 2
+        assert cast_adr_to_int((a | 2) & ~1) & 3 == 2
+        assert cast_adr_to_int((a | 2) & ~2) & 3 == 0
+        assert cast_adr_to_int((a | 2) & ~3) & 3 == 0
+        assert cast_adr_to_int((a | 3) & ~0) & 3 == 3
+        assert cast_adr_to_int((a | 3) & ~1) & 3 == 2
+        assert cast_adr_to_int((a | 3) & ~2) & 3 == 1
+        assert cast_adr_to_int((a | 3) & ~3) & 3 == 0
+        a |= 1
+        assert a != cast_ptr_to_adr(s)
+        a |= 2
+        assert a != cast_ptr_to_adr(s)
+        a &= ~1
+        assert a != cast_ptr_to_adr(s)
+        a &= ~2
+        assert a == cast_ptr_to_adr(s)
+        assert cast_adr_to_ptr(a, lltype.Ptr(S)) == s
+    fc = compile(fn, [])
+    fc()
+
 def test_raw_memcopy():
     def f():
         addr = raw_malloc(100)



More information about the Pypy-commit mailing list