[pypy-svn] r53969 - in pypy/branch/jit-hotpath/pypy: jit/rainbow/test jit/timeshifter rpython/ootypesystem

antocuni at codespeak.net antocuni at codespeak.net
Mon Apr 21 12:40:03 CEST 2008


Author: antocuni
Date: Mon Apr 21 12:40:01 2008
New Revision: 53969

Modified:
   pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
   pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
   pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rtuple.py
   pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rtupletype.py
Log:
- implement materialize() for InstanceTypeDesc

- add the relevant hints to ootypesystem.tupletype

- test_compile_time_const_tuple passes!



Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_interpreter.py	Mon Apr 21 12:40:01 2008
@@ -2340,4 +2340,3 @@
     test_red_struct_array = _skip
     test_red_varsized_struct = _skip
     test_array_of_voids = _skip
-    test_compile_time_const_tuple = _skip    # needs vdict

Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/rcontainer.py	Mon Apr 21 12:40:01 2008
@@ -100,7 +100,13 @@
         self.gv_null = RGenOp.constPrebuiltGlobal(self.null)
 
         self._compute_fielddescs(RGenOp)
-        self._define_helpers(TYPE, fixsize)
+
+        if self._get_gckind(TYPE):     # no 'allocate' for inlined substructs
+            if self.immutable and self.noidentity:
+                self._define_materialize()
+            if fixsize:
+                self._define_devirtualize()
+            self._define_allocate(fixsize)
 
 
     def Ptr(self, TYPE):
@@ -197,13 +203,15 @@
     def _define_materialize(self):
         TYPE = self.TYPE
         descs = unrolling_iterable(self.fielddescs)
+        malloc = self.malloc
+        cast_pointer = self.cast_pointer
         
         def materialize(rgenop, boxes):
-            s = lltype.malloc(TYPE)
+            s = malloc(TYPE)
             i = 0
             for desc in descs:
                 v = rvalue.ll_getvalue(boxes[i], desc.RESTYPE)
-                tgt = lltype.cast_pointer(desc.PTRTYPE, s)
+                tgt = cast_pointer(desc.PTRTYPE, s)
                 setattr(tgt, desc.fieldname, v)
                 i = i + 1
             return rgenop.genconst(s)
@@ -239,17 +247,12 @@
         else:
             return object.__new__(StructTypeDesc)
 
-    def Ptr(self, TYPE):
-        return lltype.Ptr(TYPE)
-
-    def _define_helpers(self, TYPE, fixsize):
-        if TYPE._gckind == 'gc':    # no 'allocate' for inlined substructs
-            if self.immutable and self.noidentity:
-                self._define_materialize()
-            if fixsize:
-                self._define_devirtualize()
-            self._define_allocate(fixsize)
+    Ptr = staticmethod(lltype.Ptr)
+    malloc = staticmethod(lltype.malloc)
+    cast_pointer = staticmethod(lltype.cast_pointer)
 
+    def _get_gckind(self, TYPE):
+        return TYPE._gckind == 'gc'
 
 class InstanceTypeDesc(AbstractStructTypeDesc):
 
@@ -265,8 +268,16 @@
     def Ptr(self, TYPE):
         return TYPE
 
-    def _define_helpers(self, TYPE, fixsize):
-        pass
+    malloc = staticmethod(ootype.new)
+
+    @staticmethod
+    def cast_pointer(TYPE, obj):
+        if isinstance(TYPE, ootype.Instance):
+            return ootype.ooupcast(TYPE, obj)
+        return obj
+
+    def _get_gckind(self, TYPE):
+        return 'gc' # all instances and records are garbage collected
 
     def _iter_fields(self, TYPE):
         try:

Modified: pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rtuple.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rtuple.py	(original)
+++ pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rtuple.py	Mon Apr 21 12:40:01 2008
@@ -2,6 +2,7 @@
 from pypy.rpython.rtuple import AbstractTupleRepr, AbstractTupleIteratorRepr
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.ootypesystem import rstr
+from pypy.rpython.ootypesystem.rtupletype import TUPLE_TYPE
 
 
 class TupleRepr(AbstractTupleRepr):
@@ -9,7 +10,7 @@
 
     def __init__(self, rtyper, items_r):
         AbstractTupleRepr.__init__(self, rtyper, items_r)
-        self.lowleveltype = ootype.Record(dict(zip(self.fieldnames, self.lltypes)))
+        self.lowleveltype = TUPLE_TYPE(self.lltypes)
 
     def newtuple(cls, llops, r_tuple, items_v):
         # items_v should have the lowleveltype of the internal reprs

Modified: pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rtupletype.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rtupletype.py	(original)
+++ pypy/branch/jit-hotpath/pypy/rpython/ootypesystem/rtupletype.py	Mon Apr 21 12:40:01 2008
@@ -7,7 +7,8 @@
 
 def TUPLE_TYPE(field_lltypes):
     if len(field_lltypes) == 0:
-        return Void      # empty tuple
+        return ootype.Void      # empty tuple
     else:
         fields = [('item%d' % i, TYPE) for i, TYPE in enumerate(field_lltypes)]
-        return ootype.Record(dict(fields))
+        hints = {'immutable': True, 'noidentity': True}
+        return ootype.Record(dict(fields), _hints=hints)



More information about the Pypy-commit mailing list