[pypy-commit] pypy jit-ordereddict: Start

arigo noreply at buildbot.pypy.org
Wed Dec 25 23:12:02 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-ordereddict
Changeset: r68548:41fe706f73de
Date: 2013-12-25 22:36 +0100
http://bitbucket.org/pypy/pypy/changeset/41fe706f73de/

Log:	Start

diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -125,10 +125,12 @@
 
 class ArrayDescr(AbstractDescr):
     def __init__(self, A):
-        self.A = A
+        self.A = self.OUTERA = A
+        if isinstance(A, lltype.Struct):
+            self.A = A._flds[A._arrayfld]
 
     def __repr__(self):
-        return 'ArrayDescr(%r)' % (self.A,)
+        return 'ArrayDescr(%r)' % (self.OUTERA,)
 
     def is_array_of_pointers(self):
         return getkind(self.A.OF) == 'ref'
diff --git a/rpython/jit/backend/llsupport/test/test_descr.py b/rpython/jit/backend/llsupport/test/test_descr.py
--- a/rpython/jit/backend/llsupport/test/test_descr.py
+++ b/rpython/jit/backend/llsupport/test/test_descr.py
@@ -424,3 +424,11 @@
                          " <Array of Char > > >")
     # caching:
     assert fielddescr is get_field_arraylen_descr(c0, rstr.STR)
+
+def test_bytearray_descr():
+    c0 = GcCache(False)
+    descr = get_array_descr(c0, rstr.STR)   # for bytearray
+    assert descr.flag == FLAG_UNSIGNED
+    assert descr.basesize == struct.calcsize("PP")         # hash, length
+    assert descr.lendescr.offset == struct.calcsize("P")   # hash
+    assert not descr.is_array_of_pointers()
diff --git a/rpython/jit/codewriter/jtransform.py b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -13,6 +13,7 @@
 from rpython.rlib.jit import _we_are_jitted
 from rpython.rlib.rgc import lltype_is_gc
 from rpython.rtyper.lltypesystem import lltype, llmemory, rstr, rclass, rffi
+from rpython.rtyper.lltypesystem import rbytearray
 from rpython.rtyper.rclass import IR_QUASIIMMUTABLE, IR_QUASIIMMUTABLE_ARRAY
 from rpython.translator.unsimplify import varoftype
 
@@ -850,6 +851,13 @@
         elif optype == lltype.Ptr(rstr.UNICODE):
             opname = "unicodegetitem"
             return SpaceOperation(opname, [op.args[0], op.args[2]], op.result)
+        elif optype == lltype.Ptr(rbytearray.BYTEARRAY):
+            bytearraydescr = self.cpu.arraydescrof(rbytearray.BYTEARRAY)
+            v_index = op.args[2]
+            op = SpaceOperation('getarrayitem_gc_i',
+                                [op.args[0], v_index, bytearraydescr],
+                                op.result)
+            return op
         else:
             v_inst, v_index, c_field = op.args
             if op.result.concretetype is lltype.Void:
diff --git a/rpython/jit/metainterp/test/test_bytearray.py b/rpython/jit/metainterp/test/test_bytearray.py
--- a/rpython/jit/metainterp/test/test_bytearray.py
+++ b/rpython/jit/metainterp/test/test_bytearray.py
@@ -8,10 +8,18 @@
     def test_getitem(self):
         x = bytearray("foobar")
         def fn(n):
+            assert n >= 0
             return x[n]
         res = self.interp_operations(fn, [3])
         assert res == ord('b')
 
+    def test_getitem_negative(self):
+        x = bytearray("foobar")
+        def fn(n):
+            return x[n]
+        res = self.interp_operations(fn, [-2])
+        assert res == ord('a')
+
     def test_len(self):
         x = bytearray("foobar")
         def fn(n):
@@ -22,12 +30,22 @@
     def test_setitem(self):
         x = bytearray("foobar")
         def fn(n):
+            assert n >= 0
             x[n] = 3
             return x[3] + 1000 * x[4]
 
         res = self.interp_operations(fn, [3])
         assert res == 3 + 1000 * ord('a')
 
+    def test_setitem_negative(self):
+        x = bytearray("foobar")
+        def fn(n):
+            x[n] = 3
+            return x[3] + 1000 * x[4]
+
+        res = self.interp_operations(fn, [-2])
+        assert res == ord('b') + 1000 * 3
+
     def test_new_bytearray(self):
         def fn(n, m):
             x = bytearray(str(n))


More information about the pypy-commit mailing list