[pypy-svn] r67159 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Mon Aug 24 15:20:48 CEST 2009


Author: arigo
Date: Mon Aug 24 15:20:48 2009
New Revision: 67159

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_slist.py
Log:
Oups, we forgot to add opimpl_check_resizable_neg_index to pyjitpl.py.


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Mon Aug 24 15:20:48 2009
@@ -402,6 +402,21 @@
         self.execute(rop.SETARRAYITEM_GC, [arraybox, indexbox, valuebox],
                      descr=arraydescr)
 
+    @arguments("orgpc", "box", "descr", "box")
+    def opimpl_check_resizable_neg_index(self, pc, listbox, lengthdesc,
+                                         indexbox):
+        negbox = self.metainterp.execute_and_record(
+            rop.INT_LT, [indexbox, ConstInt(0)])
+        # xxx inefficient
+        negbox = self.implement_guard_value(pc, negbox)
+        if negbox.getint():
+            # the index is < 0; add the array length to it
+            lenbox = self.metainterp.execute_and_record(
+                rop.GETFIELD_GC, [listbox], descr=lengthdesc)
+            indexbox = self.metainterp.execute_and_record(
+                rop.INT_ADD, [indexbox, lenbox])
+        self.make_result_box(indexbox)
+
     @arguments("orgpc", "box")
     def opimpl_check_zerodivisionerror(self, pc, box):
         nonzerobox = self.metainterp.execute_and_record(

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_slist.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_slist.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_slist.py	Mon Aug 24 15:20:48 2009
@@ -81,6 +81,15 @@
         assert res == f(21)
         self.check_loops(call=0)
 
+    def test_getitem_neg(self):
+        def f(n):
+            lst = [41]
+            lst.append(42)
+            return lst[n]
+        res = self.interp_operations(f, [-2], listops=True)
+        assert res == 41
+        self.check_history_(call=1)
+
 # we don't support resizable lists on ootype
 #class TestOOtype(ListTests, OOJitMixin):
 #    pass



More information about the Pypy-commit mailing list