[pypy-svn] r29481 - in pypy/dist/pypy/jit/timeshifter: . test

arigo at codespeak.net arigo at codespeak.net
Thu Jun 29 11:28:22 CEST 2006


Author: arigo
Date: Thu Jun 29 11:28:20 2006
New Revision: 29481

Modified:
   pypy/dist/pypy/jit/timeshifter/rcontainer.py
   pypy/dist/pypy/jit/timeshifter/test/test_vlist.py
   pypy/dist/pypy/jit/timeshifter/vlist.py
Log:
(arre, pedronis, arigo)
Next test passes, by copying many methods from VirtualStruct to VirtualList.


Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py	Thu Jun 29 11:28:20 2006
@@ -160,7 +160,7 @@
 
     def __init__(self, typedesc):
         self.typedesc = typedesc
-        #self.fz_content initialized later
+        #self.fz_content_boxes initialized later
 
     def exactmatch(self, vstruct, outgoingvarboxes, memo):
         contmemo = memo.containers

Modified: pypy/dist/pypy/jit/timeshifter/test/test_vlist.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_vlist.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_vlist.py	Thu Jun 29 11:28:20 2006
@@ -14,3 +14,19 @@
     insns, res = timeshift(ll_function, [], [], policy=P_OOPSPEC)
     assert res == 12
     assert insns == {}
+
+def test_enter_block():
+    def ll_function(flag):
+        lst = []
+        lst.append(flag)
+        lst.append(131)
+        if flag:
+            return lst[0]
+        else:
+            return lst[1]
+    insns, res = timeshift(ll_function, [6], [], policy=P_OOPSPEC)
+    assert res == 6
+    assert insns == {'int_is_true': 1}
+    insns, res = timeshift(ll_function, [0], [], policy=P_OOPSPEC)
+    assert res == 131
+    assert insns == {'int_is_true': 1}

Modified: pypy/dist/pypy/jit/timeshifter/vlist.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/vlist.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/vlist.py	Thu Jun 29 11:28:20 2006
@@ -16,37 +16,92 @@
     def _freeze_(self):
         return True
 
+    def ll_factory(self):
+        vlist = VirtualList(self)
+        box = rvalue.PtrRedBox(self.gv_ptrtype)
+        box.content = vlist
+        vlist.ownbox = box
+        return box
+
+
+class FrozenVirtualList(AbstractContainer):
+
+    def __init__(self, typedesc):
+        self.typedesc = typedesc
+        #self.fz_item_boxes initialized later
+
+    def exactmatch(self, vlist, outgoingvarboxes, memo):
+        contmemo = memo.containers
+        if self in contmemo:
+            ok = vlist is contmemo[self]
+            if not ok:
+                outgoingvarboxes.append(vlist.ownbox)
+            return ok
+        if vlist in contmemo:
+            assert contmemo[vlist] is not self
+            outgoingvarboxes.append(vlist.ownbox)
+            return False
+        assert self.typedesc is vlist.typedesc
+        contmemo[self] = vlist
+        contmemo[vlist] = self
+        self_boxes = self.fz_item_boxes
+        vlist_boxes = vlist.item_boxes
+        fullmatch = True
+        for i in range(len(self_boxes)):
+            if not self_boxes[i].exactmatch(vlist_boxes[i],
+                                            outgoingvarboxes,
+                                            memo):
+                fullmatch = False
+        return fullmatch
+
 
 class VirtualList(AbstractContainer):
 
     def __init__(self, typedesc):
         self.typedesc = typedesc
         self.item_boxes = []
+        # self.ownbox = ...    set in ll_factory
 
     def enter_block(self, newblock, incoming, memo):
-        pass
+        contmemo = memo.containers
+        if self not in contmemo:
+            contmemo[self] = None
+            for box in self.item_boxes:
+                box.enter_block(newblock, incoming, memo)
 
     def force_runtime_container(self, jitstate):
-        pass
+        assert 0
 
     def freeze(self, memo):
-        pass
+        contmemo = memo.containers
+        try:
+            return contmemo[self]
+        except KeyError:
+            result = contmemo[self] = FrozenVirtualList(self.typedesc)
+            frozens = [box.freeze(memo) for box in self.item_boxes]
+            result.fz_item_boxes = frozens
+            return result
 
     def copy(self, memo):
-        pass
+        contmemo = memo.containers
+        try:
+            return contmemo[self]
+        except KeyError:
+            result = contmemo[self] = VirtualList(self.typedesc)
+            result.item_boxes = [box.copy(memo)
+                                 for box in self.item_boxes]
+            result.ownbox = self.ownbox.copy(memo)
+            return result
 
     def replace(self, memo):
-        pass
+        assert 0
 
 
 def oop_newlist(jitstate, typedesc, lengthbox):
     assert lengthbox.is_constant()
     length = rvalue.ll_getvalue(lengthbox, lltype.Signed)
     assert length == 0
-    vlist = VirtualList(typedesc)
-    box = rvalue.PtrRedBox(typedesc.gv_ptrtype)
-    box.content = vlist
-    return box
+    return typedesc.ll_factory()
 
 def oop_list_append(jitstate, selfbox, itembox):
     assert isinstance(selfbox.content, VirtualList)



More information about the Pypy-commit mailing list