Commits

Armin Rigo committed 41fe706

Start

  • Participants
  • Parent commits 34fbea0
  • Branches jit-ordereddict

Comments (0)

Files changed (4)

File rpython/jit/backend/llgraph/runner.py

 
 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'

File rpython/jit/backend/llsupport/test/test_descr.py

                          " <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()

File rpython/jit/codewriter/jtransform.py

 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
 
         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:

File rpython/jit/metainterp/test/test_bytearray.py

     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):
     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))