def test_length_cache(self): h = HeapCache() h.new_array(box1, lengthbox1) assert h.arraylen(box1) is lengthbox1 assert h.arraylen(box2) is None h.arraylen_now_known(box2, lengthbox2) assert h.arraylen(box2) is lengthbox2
def test_length_cache(self): h = HeapCache() box1 = RefFrontendOp(1) box2 = RefFrontendOp(2) lengthbox1 = IntFrontendOp(11) lengthbox2 = IntFrontendOp(12) h.new_array(box1, lengthbox1) assert h.arraylen(box1) is lengthbox1 assert h.arraylen(box2) is None h.arraylen_now_known(box2, lengthbox2) assert h.arraylen(box2) is lengthbox2
def test_replace_box_with_const_in_array(self): h = HeapCache() box1 = RefFrontendOp(1) lengthbox2 = IntFrontendOp(2) lengthbox2.setint(10) h.arraylen_now_known(box1, lengthbox2) assert h.arraylen(box1) is lengthbox2 c10 = ConstInt(10) h.replace_box(lengthbox2, c10) assert c10.same_constant(h.arraylen(box1)) box2 = IntFrontendOp(2) box2.setint(12) h.setarrayitem(box1, index2, box2, descr1) assert h.getarrayitem(box1, index2, descr1) is box2 c12 = ConstInt(12) h.replace_box(box2, c12) assert c12.same_constant(h.getarrayitem(box1, index2, descr1))
def test_replace_box_array(self): h = HeapCache() h.setarrayitem(box1, index1, box2, descr1) h.setarrayitem(box1, index1, box3, descr2) h.arraylen_now_known(box1, lengthbox1) h.setarrayitem(box2, index2, box1, descr1) h.setarrayitem(box3, index2, box1, descr2) h.setarrayitem(box2, index2, box3, descr3) h.replace_box(box1, box4) assert h.arraylen(box4) is lengthbox1 assert h.getarrayitem(box4, index1, descr1) is box2 assert h.getarrayitem(box4, index1, descr2) is box3 assert h.getarrayitem(box2, index2, descr1) is box4 assert h.getarrayitem(box3, index2, descr2) is box4 assert h.getarrayitem(box2, index2, descr3) is box3 h.replace_box(lengthbox1, lengthbox2) assert h.arraylen(box4) is lengthbox2
def test_replace_box_array(self): py.test.skip("replacing a box with another box: not supported any more") h = HeapCache() h.setarrayitem(box1, index1, box2, descr1) h.setarrayitem(box1, index1, box3, descr2) h.arraylen_now_known(box1, lengthbox1) h.setarrayitem(box2, index2, box1, descr1) h.setarrayitem(box3, index2, box1, descr2) h.setarrayitem(box2, index2, box3, descr3) h.replace_box(box1, box4) assert h.arraylen(box4) is lengthbox1 assert h.getarrayitem(box4, index1, descr1) is box2 assert h.getarrayitem(box4, index1, descr2) is box3 assert h.getarrayitem(box2, index2, descr1) is box4 assert h.getarrayitem(box3, index2, descr2) is box4 assert h.getarrayitem(box2, index2, descr3) is box3 h.replace_box(lengthbox1, lengthbox2) assert h.arraylen(box4) is lengthbox2