[pypy-svn] r27206 - pypy/dist/pypy/rpython/memory

arigo at codespeak.net arigo at codespeak.net
Sun May 14 18:57:22 CEST 2006


Author: arigo
Date: Sun May 14 18:57:19 2006
New Revision: 27206

Modified:
   pypy/dist/pypy/rpython/memory/convertlltype.py
   pypy/dist/pypy/rpython/memory/gc.py
   pypy/dist/pypy/rpython/memory/lltypelayout.py
Log:
(pedronis, arigo)
Some clean-ups in the memory simulator, needed for the sanity of
what we're working on.


Modified: pypy/dist/pypy/rpython/memory/convertlltype.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/convertlltype.py	(original)
+++ pypy/dist/pypy/rpython/memory/convertlltype.py	Sun May 14 18:57:19 2006
@@ -13,6 +13,16 @@
 FUNCTIONTYPES = (types.FunctionType, types.UnboundMethodType,
                  types.BuiltinFunctionType)
 
+
+def get_real_value(val_or_ptr):
+    if isinstance(val_or_ptr, llmemory.AddressOffset):
+        return lltypelayout.convert_offset_to_int(val_or_ptr)
+    return val_or_ptr
+
+def size_gc_header(gc, typeid):
+    return get_real_value(gc.size_gc_header(typeid))
+
+
 class LLTypeConverter(object):
     def __init__(self, address, gc=None, qt=None):
         self.type_to_typeid = {}
@@ -27,9 +37,7 @@
         TYPE = lltype.typeOf(val_or_ptr)
         if isinstance(TYPE, lltype.Primitive):
             assert inline_to_ptr is None
-            if isinstance(val_or_ptr, llmemory.AddressOffset):
-                return lltypelayout.convert_offset_to_int(val_or_ptr)
-            return val_or_ptr
+            return get_real_value(val_or_ptr)
         elif isinstance(TYPE, lltype.Array):
             return self.convert_array(val_or_ptr, inline_to_ptr)
         elif isinstance(TYPE, lltype.Struct):
@@ -61,8 +69,8 @@
             if self.gc is not None:
                 typeid = self.query_types.get_typeid(TYPE)
                 self.gc.init_gc_object_immortal(startaddr, typeid)
-                startaddr += self.gc.size_gc_header(typeid)
-                self.curraddress += self.gc.size_gc_header(typeid)
+                startaddr += size_gc_header(self.gc, typeid)
+                self.curraddress += size_gc_header(self.gc, typeid)
             ptr = init_object_on_address(startaddr, TYPE, arraylength)
             self.constantroots.append(ptr)
         self.converted[_array] = ptr
@@ -101,8 +109,8 @@
             if self.gc is not None:
                 typeid = self.query_types.get_typeid(TYPE)
                 self.gc.init_gc_object_immortal(startaddr, typeid)
-                startaddr += self.gc.size_gc_header(typeid)
-                self.curraddress += self.gc.size_gc_header(typeid)
+                startaddr += size_gc_header(self.gc, typeid)
+                self.curraddress += size_gc_header(self.gc, typeid)
             ptr = init_object_on_address(startaddr, TYPE, inlinedarraylength)
             self.constantroots.append(ptr)
         self.converted[_struct] = ptr
@@ -189,7 +197,7 @@
                 total_size += sizeof(cand._TYPE, length)
                 if self.gc is not None:
                     typeid = self.query_types.get_typeid(cand._TYPE)
-                    total_size += self.gc.size_gc_header(typeid)
+                    total_size += size_gc_header(self.gc, typeid)
                 for item in cand.items:
                     candidates.append(item)
             elif isinstance(cand, lltype._struct):
@@ -209,7 +217,7 @@
                         total_size += sizeof(TYPE)
                     if self.gc is not None:
                         typeid = self.query_types.get_typeid(TYPE)
-                        total_size += self.gc.size_gc_header(typeid)
+                        total_size += size_gc_header(self.gc, typeid)
                 for name in TYPE._flds:
                     candidates.append(getattr(cand, name))
             elif isinstance(cand, lltype._opaque):

Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py	(original)
+++ pypy/dist/pypy/rpython/memory/gc.py	Sun May 14 18:57:19 2006
@@ -11,14 +11,8 @@
 int_size = lltypesimulation.sizeof(lltype.Signed)
 
 class GCHeaderOffset(llmemory.AddressOffset):
-    def __init__(self, minimal_size):
-        self.minimal_size = minimal_size
-    def __int__(self):
-        from pypy.rpython.memory.lltypelayout import sizeof
-        return sizeof(self.minimal_size)
-    # XXX blech
-    def __radd__(self, other):
-        return int(self) + other
+    def __init__(self, minimal_layout):
+        self.minimal_layout = minimal_layout
 
 gc_header_two_ints = GCHeaderOffset(
     lltype.Struct("header", ("a", lltype.Signed), ("b", lltype.Signed)))

Modified: pypy/dist/pypy/rpython/memory/lltypelayout.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lltypelayout.py	(original)
+++ pypy/dist/pypy/rpython/memory/lltypelayout.py	Sun May 14 18:57:19 2006
@@ -102,7 +102,7 @@
     elif isinstance(offset, llmemory.ArrayItemsOffset):
         return get_fixed_size(lltype.Signed)
     elif isinstance(offset, GCHeaderOffset):
-        return sizeof(offset.minimal_size)
+        return sizeof(offset.minimal_layout)
     else:
         raise Exception("unknown offset type %r"%offset)
         



More information about the Pypy-commit mailing list