[pypy-svn] r51788 - in pypy/branch/unified-rtti/pypy: annotation rpython translator/c translator/c/src translator/c/test

arigo at codespeak.net arigo at codespeak.net
Fri Feb 22 13:37:22 CET 2008


Author: arigo
Date: Fri Feb 22 13:37:21 2008
New Revision: 51788

Modified:
   pypy/branch/unified-rtti/pypy/annotation/bookkeeper.py
   pypy/branch/unified-rtti/pypy/rpython/raddress.py
   pypy/branch/unified-rtti/pypy/translator/c/primitive.py
   pypy/branch/unified-rtti/pypy/translator/c/src/address.h
   pypy/branch/unified-rtti/pypy/translator/c/test/test_lladdresses.py
Log:
Support prebuilt fakeaddresswithflags.


Modified: pypy/branch/unified-rtti/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/annotation/bookkeeper.py	(original)
+++ pypy/branch/unified-rtti/pypy/annotation/bookkeeper.py	Fri Feb 22 13:37:21 2008
@@ -407,7 +407,8 @@
             result = entry.compute_annotation_bk(self)
         elif isinstance(x, lltype._ptr):
             result = SomePtr(lltype.typeOf(x))
-        elif isinstance(x, llmemory.fakeaddress):
+        elif isinstance(x, (llmemory.fakeaddress,
+                            llmemory.fakeaddresswithflags)):
             result = SomeAddress(is_null=not x)
         elif isinstance(x, ootype._static_meth):
             result = SomeOOStaticMeth(ootype.typeOf(x))

Modified: pypy/branch/unified-rtti/pypy/rpython/raddress.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/rpython/raddress.py	(original)
+++ pypy/branch/unified-rtti/pypy/rpython/raddress.py	Fri Feb 22 13:37:21 2008
@@ -2,7 +2,7 @@
 from pypy.tool.pairtype import pairtype
 from pypy.annotation import model as annmodel
 from pypy.rpython.lltypesystem.llmemory import NULL, Address, \
-     cast_adr_to_int, fakeaddress
+     cast_adr_to_int, fakeaddress, fakeaddresswithflags
 from pypy.rpython.rmodel import Repr, IntegerRepr
 from pypy.rpython.rptr import PtrRepr
 from pypy.rpython.lltypesystem import lltype
@@ -28,7 +28,8 @@
     def convert_const(self, value):
         # note that llarena.fakearenaaddress is not supported as a constant
         # in graphs
-        assert type(value) is fakeaddress
+        assert (type(value) is fakeaddress or
+                type(value) is fakeaddresswithflags)
         return value
 
     def ll_str(self, a):

Modified: pypy/branch/unified-rtti/pypy/translator/c/primitive.py
==============================================================================
--- pypy/branch/unified-rtti/pypy/translator/c/primitive.py	(original)
+++ pypy/branch/unified-rtti/pypy/translator/c/primitive.py	Fri Feb 22 13:37:21 2008
@@ -7,7 +7,8 @@
 from pypy.rpython.lltypesystem.llmemory import Address, \
      AddressOffset, ItemOffset, ArrayItemsOffset, FieldOffset, \
      CompositeOffset, ArrayLengthOffset, \
-     GCHeaderOffset, GCTypeInfoOffset
+     GCHeaderOffset, GCTypeInfoOffset, \
+     fakeaddress, fakeaddresswithflags
 from pypy.rpython.lltypesystem.llarena import RoundedUpForAllocation
 from pypy.translator.c.support import cdecl, barebonearray
 
@@ -126,7 +127,13 @@
 
 def name_address(value, db):
     if value:
-        return db.get(value.ref())
+        if type(value) is fakeaddress:
+            return db.get(value.ref())
+        elif type(value) is fakeaddresswithflags:
+            return 'ADR_OR(%s, %d)' % (name_address(value.adr, db),
+                                       value.flags)
+        else:
+            raise TypeError("not supported: name_address(%r)" % (value,))
     else:
         return 'NULL'
 

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 13:37:21 2008
@@ -20,5 +20,8 @@
 #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))
+#define ADR_OR(x,y)      ((char *)((long)(x) | (y)))
+#define ADR_AND(x,y)     ((char *)((long)(x) & (y)))
+
+#define OP_ADR_OR(x,y,r)    r = ADR_OR(x,y)
+#define OP_ADR_AND(x,y,r)   r = ADR_AND(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 13:37:21 2008
@@ -62,9 +62,17 @@
 
 def test_flags_in_low_bits():
     S = lltype.GcStruct('S', ('x', lltype.Signed))
-    def fn():
+    s1 = lltype.malloc(S)
+    s1.x = 42
+    a1 = cast_ptr_to_adr(s1) | 1
+    def fn(flag):
         s = lltype.malloc(S)
+        s.x = 6161
         a = cast_ptr_to_adr(s)
+        if flag:
+            a2 = a1
+        else:
+            a2 = a | 1
         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
@@ -95,8 +103,15 @@
         a &= ~2
         assert a == cast_ptr_to_adr(s)
         assert cast_adr_to_ptr(a, lltype.Ptr(S)) == s
-    fc = compile(fn, [])
-    fc()
+        s1bis = cast_adr_to_ptr(a1 & ~1, lltype.Ptr(S))
+        assert s1bis.x == 42
+        ster = cast_adr_to_ptr(a2 & ~1, lltype.Ptr(S))
+        return ster.x
+    fc = compile(fn, [int])
+    res = fc(1)
+    assert res == 42
+    res = fc(0)
+    assert res == 6161
 
 def test_raw_memcopy():
     def f():



More information about the Pypy-commit mailing list