[pypy-svn] r32136 - in pypy/branch/more-gckinds/pypy: annotation rpython rpython/lltypesystem

mwh at codespeak.net mwh at codespeak.net
Mon Sep 11 10:23:47 CEST 2006


Author: mwh
Date: Mon Sep 11 10:23:46 2006
New Revision: 32136

Modified:
   pypy/branch/more-gckinds/pypy/annotation/model.py
   pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lltype.py
   pypy/branch/more-gckinds/pypy/rpython/rptr.py
Log:
obscure fixes and hacks to get adt methods attached to interior pointers
working.
this was hard.


Modified: pypy/branch/more-gckinds/pypy/annotation/model.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/annotation/model.py	(original)
+++ pypy/branch/more-gckinds/pypy/annotation/model.py	Mon Sep 11 10:23:46 2006
@@ -568,6 +568,13 @@
         return s_val.ootype
     if isinstance(s_val, SomeOOStaticMeth):
         return s_val.method
+    if isinstance(s_val, SomeInteriorPtr):
+        p = s_val.ll_ptrtype
+        if 0 in p.offsets:
+            assert list(p.offsets).count(0) == 1
+            return lltype.Ptr(lltype.Ptr(p.PARENTTYPE)._interior_ptr_type_with_index(p.TO))
+        else:
+            return lltype.Ptr(p.PARENTTYPE)
     if isinstance(s_val, SomePtr):
         return s_val.ll_ptrtype
     for witness, T in annotation_to_ll_map:

Modified: pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/more-gckinds/pypy/rpython/lltypesystem/lltype.py	Mon Sep 11 10:23:46 2006
@@ -619,10 +619,15 @@
         o = self.TO._container_example()
         return _ptr(self, o, solid=True)
 
-    def _interior_ptr_type_with_index(self):
+    def _interior_ptr_type_with_index(self, TO):
         assert self.TO._gckind == 'gc'
-        R = GcStruct("Interior", ('ptr', self), ('index', Signed),
-                     hints={'interior_ptr_type':True})
+        if isinstance(TO, Struct):
+            R = GcStruct("Interior", ('ptr', self), ('index', Signed),
+                         hints={'interior_ptr_type':True},
+                         adtmeths=TO._adtmeths)
+        else:
+            R = GcStruct("Interior", ('ptr', self), ('index', Signed),
+                         hints={'interior_ptr_type':True})            
         return R
 
 class InteriorPtr(LowLevelType):

Modified: pypy/branch/more-gckinds/pypy/rpython/rptr.py
==============================================================================
--- pypy/branch/more-gckinds/pypy/rpython/rptr.py	(original)
+++ pypy/branch/more-gckinds/pypy/rpython/rptr.py	Mon Sep 11 10:23:46 2006
@@ -103,7 +103,7 @@
         if isinstance(ITEM_TYPE, ContainerType):
             if ARRAY._gckind == 'gc' and ITEM_TYPE._gckind == 'raw':
                 v_array, v_index = hop.inputargs(r_ptr, Signed)
-                INTERIOR_PTR_TYPE = r_ptr.lowleveltype._interior_ptr_type_with_index()
+                INTERIOR_PTR_TYPE = r_ptr.lowleveltype._interior_ptr_type_with_index(ITEM_TYPE)
                 v_interior_ptr = hop.genop('malloc', [flowmodel.Constant(INTERIOR_PTR_TYPE, Void)],
                                            resulttype = Ptr(INTERIOR_PTR_TYPE))
                 hop.genop('setfield',
@@ -181,6 +181,7 @@
 
     def __init__(self, adtmeth, rtyper):
         self.func = adtmeth.func
+        self.ll_ptrtype = adtmeth.ll_ptrtype
         self.lowleveltype = rtyper.getrepr(annmodel.lltype_to_annotation(adtmeth.ll_ptrtype)).lowleveltype
 
     def rtype_simple_call(self, hop):
@@ -189,7 +190,7 @@
         s_func = hop.rtyper.annotator.bookkeeper.immutablevalue(func)
         v_ptr = hop2.args_v[0]
         hop2.r_s_popfirstarg()
-        hop2.v_s_insertfirstarg(v_ptr, annmodel.SomePtr(self.lowleveltype))
+        hop2.v_s_insertfirstarg(v_ptr, annmodel.lltype_to_annotation(self.ll_ptrtype))
         hop2.v_s_insertfirstarg(flowmodel.Constant(func), s_func)
         return hop2.dispatch()
 
@@ -217,7 +218,7 @@
         self.resulttype = Ptr(ptrtype.TO)
         assert numitemoffsets <= 1
         if numitemoffsets > 0:
-            self.lowleveltype = Ptr(self.parentptrtype._interior_ptr_type_with_index())
+            self.lowleveltype = Ptr(self.parentptrtype._interior_ptr_type_with_index(self.resulttype.TO))
         else:
             self.lowleveltype = self.parentptrtype            
 
@@ -289,7 +290,7 @@
         ITEM_TYPE = ARRAY.OF
         if isinstance(ITEM_TYPE, ContainerType):
             v_array, v_index = hop.inputargs(r_ptr, Signed)
-            INTERIOR_PTR_TYPE = r_ptr.lowleveltype._interior_ptr_type_with_index()
+            INTERIOR_PTR_TYPE = r_ptr.lowleveltype._interior_ptr_type_with_index(ITEM_TYPE)
             v_interior_ptr = hop.genop('malloc', [flowmodel.Constant(INTERIOR_PTR_TYPE, Void)],
                                        resulttype = Ptr(INTERIOR_PTR_TYPE))
             hop.genop('setfield',



More information about the Pypy-commit mailing list