[pypy-svn] r25227 - in pypy/branch/jit-timeshifter-refactoring/timeshifter: . test

arigo at codespeak.net arigo at codespeak.net
Sun Apr 2 16:37:01 CEST 2006


Author: arigo
Date: Sun Apr  2 16:37:00 2006
New Revision: 25227

Added:
   pypy/branch/jit-timeshifter-refactoring/timeshifter/rcontainer.py
Modified:
   pypy/branch/jit-timeshifter-refactoring/timeshifter/test/test_timeshift.py
Log:
(pedronis, arre, arigo)  intermediate.


Added: pypy/branch/jit-timeshifter-refactoring/timeshifter/rcontainer.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-timeshifter-refactoring/timeshifter/rcontainer.py	Sun Apr  2 16:37:00 2006
@@ -0,0 +1,93 @@
+from pypy.jit.timeshifter import rvalue
+
+
+class AbstractContainer(object):
+    pass
+
+# ____________________________________________________________
+
+class cachedtype(type):
+    """Metaclass for classes that should only have one instance per
+    tuple of arguments given to the constructor."""
+
+    def __init__(selfcls, name, bases, dict):
+        super(cachedtype, selfcls).__init__(name, bases, dict)
+        selfcls._instancecache = {}
+
+    def __call__(selfcls, *args):
+        d = selfcls._instancecache
+        try:
+            return d[args]
+        except KeyError:
+            instance = d[args] = selfcls.__new__(selfcls, *args)
+            instance.__init__(*args)
+            return instance
+
+
+class StructTypeDesc(object):
+    __metaclass__ = cachedtype
+
+    def __init__(self, TYPE):
+        self.TYPE = TYPE
+        self.PTRTYPE = lltype.Ptr(TYPE)
+        self.gv_type = rgenop.constTYPE(self.TYPE)
+        self.gv_ptrtype = rgenop.constTYPE(self.PTRTYPE)
+
+        fielddescs = []
+        for name in self.TYPE._names:
+            FIELDTYPE = getattr(self.TYPE, name)
+            if isinstance(FIELDTYPE, lltype.ContainerType):
+                substructdesc = StructTypeDesc(FIELDTYPE)
+                for subfielddesc in substructdesc.fielddescs:
+                    dottedname = '%s.%s' % (name, subfielddesc.fieldname)
+                    index = len(fielddesc)
+                    fielddescs.append(StructFieldDesc(self.TYPE, dottedname,
+                                                      index))
+            else:
+                index = len(fielddesc)
+                fielddesc.append(StructFieldDesc(self.TYPE, name, index))
+        self.fielddescs = fielddescs
+
+    def _freeze_(self):
+        return True
+
+    def compact_repr(self): # goes in ll helper names
+        return "Desc_%s" % (self.TYPE._short_name(),)
+
+
+class StructFieldDesc(object):
+    __metaclass__ = cachedtype
+
+    def __init__(self, PTRTYPE, fieldname, index):
+        assert isinstance(PTRTYPE.TO, lltype.Struct)
+        RES1 = PTRTYPE.TO
+        for component in fieldname.split('.'):
+            LASTSTRUCT = RES1
+            RES1 = getattr(RES1, component)
+        assert not isinstance(RES1, lltype.ContainerType)
+        self.PTRTYPE = PTRTYPE
+        self.RESTYPE = RES1
+        self.gv_resulttype = rgenop.constTYPE(RESTYPE)
+        self.fieldname = fieldname
+        self.fieldname_gv = [rgenop.constFieldName(component)
+                             for component in fieldname.split('.')]
+        self.fieldindex = index
+        self.gv_default = rgenop.genconst(RES1._defl())
+        self.redboxcls = rvalue.ll_redboxcls(RES1)
+        self.immutable = LASTSTRUCT._hints.get('immutable', False)
+
+    def _freeze_(self):
+        return True
+
+    def compact_repr(self): # goes in ll helper names
+        return "Fld_%s_in_%s" % (self.fieldname.replace('.','_'),
+                                 self.PTRTYPE._short_name())
+
+
+class VirtualStruct(AbstractContainer):
+
+    def __init__(self, typedesc):
+        self.typedesc = typedesc
+        self.content_boxes = [desc.redboxcls(desc.gv_resulttype,
+                                             desc.gv_default)
+                              for desc in typedesc.fielddescs]

Modified: pypy/branch/jit-timeshifter-refactoring/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/branch/jit-timeshifter-refactoring/timeshifter/test/test_timeshift.py	(original)
+++ pypy/branch/jit-timeshifter-refactoring/timeshifter/test/test_timeshift.py	Sun Apr  2 16:37:00 2006
@@ -343,6 +343,7 @@
     assert insns == {}
 
 def test_simple_struct_malloc():
+    py.test.skip("blue containers: to be reimplemented")
     S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
                                       ('world', lltype.Signed))               
     def ll_function(x):
@@ -359,6 +360,7 @@
     assert insns == {}
 
 def test_inlined_substructure():
+    py.test.skip("blue containers: to be reimplemented")
     S = lltype.Struct('S', ('n', lltype.Signed))
     T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
     def ll_function(k):



More information about the Pypy-commit mailing list