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

arigo at codespeak.net arigo at codespeak.net
Thu Sep 7 19:01:24 CEST 2006


Author: arigo
Date: Thu Sep  7 19:01:20 2006
New Revision: 32066

Modified:
   pypy/dist/pypy/jit/timeshifter/test/test_vlist.py
   pypy/dist/pypy/jit/timeshifter/vlist.py
Log:
Implemented all vlist operations that have an oopspec in rlist.


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 Sep  7 19:01:20 2006
@@ -74,3 +74,32 @@
         assert res == 12
         res = self.timeshift(ll_function, [0], [], policy=P_OOPSPEC)
         assert res == 0
+
+    def test_oop_vlist(self):
+        def ll_function():
+            lst = [3, 5]
+            five = lst.pop()        # [3]
+            lst.append(len(lst))    # [3, 1]
+            lst2 = list(lst)
+            three = lst.pop(0)      # [1]
+            lst.insert(0, 8)        # [8, 1]
+            lst.insert(2, 7)        # [8, 1, 7]
+            lst.append(not lst)     # [8, 1, 7, 0]
+            lst.reverse()           # [0, 7, 1, 8]
+            lst3 = lst2 + lst       # [3, 1, 0, 7, 1, 8]
+            del lst3[1]             # [3, 0, 7, 1, 8]
+            seven = lst3.pop(2)     # [3, 0, 1, 8]
+            lst3[0] = 9             # [9, 0, 1, 8]
+            nine = lst3.pop(-4)     # [0, 1, 8]
+            return (len(lst3) * 10000000 +
+                    lst3[0]   *  1000000 +
+                    lst3[1]   *   100000 +
+                    lst3[-1]  *    10000 +
+                    five      *     1000 +
+                    three     *      100 +
+                    seven     *       10 +
+                    nine      *        1)
+        assert ll_function() == 30185379
+        res = self.timeshift(ll_function, [], [], policy=P_OOPSPEC)
+        assert res == 30185379
+        self.check_insns({})

Modified: pypy/dist/pypy/jit/timeshifter/vlist.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/vlist.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/vlist.py	Thu Sep  7 19:01:20 2006
@@ -133,16 +133,29 @@
 def oop_newlist(jitstate, oopspecdesc, lengthbox, itembox=None):
     if lengthbox.is_constant():
         length = rvalue.ll_getvalue(lengthbox, lltype.Signed)
-        if length == 0 or itembox is not None:
-            return oopspecdesc.typedesc.factory(length, itembox)
+        return oopspecdesc.typedesc.factory(length, itembox)
     return oopspecdesc.residual_call(jitstate, [lengthbox, itembox])
 
+def oop_list_copy(jitstate, oopspecdesc, selfbox):
+    if isinstance(selfbox.content, VirtualList):
+        copybox = oopspecdesc.typedesc.factory(0, None)
+        copybox.content.item_boxes.extend(selfbox.content.item_boxes)
+        return copybox
+    else:
+        return oopspecdesc.residual_call(jitstate, [selfbox])
+
 def oop_list_len(jitstate, oopspecdesc, selfbox):
     if isinstance(selfbox.content, VirtualList):
         return rvalue.ll_fromvalue(jitstate, len(selfbox.content.item_boxes))
     else:
         return oopspecdesc.residual_call(jitstate, [selfbox])
 
+def oop_list_nonzero(jitstate, oopspecdesc, selfbox):
+    if isinstance(selfbox.content, VirtualList):
+        return rvalue.ll_fromvalue(jitstate, bool(selfbox.content.item_boxes))
+    else:
+        return oopspecdesc.residual_call(jitstate, [selfbox])
+
 def oop_list_append(jitstate, oopspecdesc, selfbox, itembox):
     if isinstance(selfbox.content, VirtualList):
         selfbox.content.item_boxes.append(itembox)
@@ -152,10 +165,23 @@
 def oop_list_insert(jitstate, oopspecdesc, selfbox, indexbox, itembox):
     if isinstance(selfbox.content, VirtualList) and indexbox.is_constant():
         index = rvalue.ll_getvalue(indexbox, lltype.Signed)
-        selfbox.content.item_boxes[index].insert(index, itembox)
+        # XXX what if the assert fails?
+        assert 0 <= index <= len(selfbox.content.item_boxes)
+        selfbox.content.item_boxes.insert(index, itembox)
     else:
         oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
 
+def oop_list_concat(jitstate, oopspecdesc, selfbox, otherbox):
+    if isinstance(selfbox.content, VirtualList):
+        assert isinstance(otherbox, rvalue.PtrRedBox)
+        if (otherbox.content is not None and
+            isinstance(otherbox.content, VirtualList)):
+            newbox = oopspecdesc.typedesc.factory(0, None)
+            newbox.content.item_boxes.extend(selfbox.content.item_boxes)
+            newbox.content.item_boxes.extend(otherbox.content.item_boxes)
+            return newbox
+    return oopspecdesc.residual_call(jitstate, [selfbox, otherbox])
+
 def oop_list_pop(jitstate, oopspecdesc, selfbox, indexbox=None):
     if indexbox is None:
         if isinstance(selfbox.content, VirtualList):
@@ -175,6 +201,12 @@
             return oopspecdesc.residual_exception(jitstate, IndexError)
     return oopspecdesc.residual_call(jitstate, [selfbox, indexbox])
 
+def oop_list_reverse(jitstate, oopspecdesc, selfbox):
+    if isinstance(selfbox.content, VirtualList):
+        selfbox.content.item_boxes.reverse()
+    else:
+        oopspecdesc.residual_call(jitstate, [selfbox])
+
 def oop_list_getitem(jitstate, oopspecdesc, selfbox, indexbox):
     if isinstance(selfbox.content, VirtualList) and indexbox.is_constant():
         index = rvalue.ll_getvalue(indexbox, lltype.Signed)
@@ -194,3 +226,13 @@
             oopspecdesc.residual_exception(jitstate, IndexError)
     else:
         oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
+
+def oop_list_delitem(jitstate, oopspecdesc, selfbox, indexbox):
+    if isinstance(selfbox.content, VirtualList) and indexbox.is_constant():
+        index = rvalue.ll_getvalue(indexbox, lltype.Signed)
+        try:
+            del selfbox.content.item_boxes[index]
+        except IndexError:
+            oopspecdesc.residual_exception(jitstate, IndexError)
+    else:
+        oopspecdesc.residual_call(jitstate, [selfbox, indexbox])



More information about the Pypy-commit mailing list