def virtual_value(keybox, value, next): vv = VirtualValue(None, ConstAddr(LLtypeMixin.node_vtable_adr, LLtypeMixin.cpu), keybox) if not isinstance(next, OptValue): next = OptValue(next) vv.setfield(LLtypeMixin.nextdescr, next) vv.setfield(LLtypeMixin.valuedescr, OptValue(value)) return vv
def virtual_value(keybox, value, next): vv = VirtualValue(fakeoptimizer, ConstAddr(LLtypeMixin.node_vtable_adr, LLtypeMixin.cpu), keybox) if not isinstance(next, OptValue): next = OptValue(next) vv.setfield(LLtypeMixin.valuedescr, OptValue(value)) vv.setfield(LLtypeMixin.nextdescr, next) return vv
def test_virtual_adder_make_virtual(): b2s, b3s, b4s, b5s = [BoxPtr(), BoxInt(3), BoxPtr(), BoxPtr()] c1s = ConstInt(111) storage = Storage() memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) modifier = ResumeDataVirtualAdder(storage, memo) modifier.liveboxes_from_env = {} modifier.liveboxes = {} modifier.vfieldboxes = {} v4 = VirtualValue(fakeoptimizer, ConstAddr(LLtypeMixin.node_vtable_adr2, LLtypeMixin.cpu), b4s) v4.setfield(LLtypeMixin.nextdescr, OptValue(b2s)) v4.setfield(LLtypeMixin.valuedescr, OptValue(b3s)) v4.setfield(LLtypeMixin.otherdescr, OptValue(b5s)) v4._cached_sorted_fields = [LLtypeMixin.nextdescr, LLtypeMixin.valuedescr, LLtypeMixin.otherdescr] v2 = VirtualValue(fakeoptimizer, ConstAddr(LLtypeMixin.node_vtable_adr, LLtypeMixin.cpu), b2s) v2.setfield(LLtypeMixin.nextdescr, v4) v2.setfield(LLtypeMixin.valuedescr, OptValue(c1s)) v2._cached_sorted_fields = [LLtypeMixin.nextdescr, LLtypeMixin.valuedescr] modifier.register_virtual_fields(b2s, [b4s, c1s]) modifier.register_virtual_fields(b4s, [b2s, b3s, b5s]) values = {b2s: v2, b4s: v4} liveboxes = [] modifier._number_virtuals(liveboxes, values, 0) storage.rd_consts = memo.consts[:] storage.rd_numb = None # resume b3t, b5t = [BoxInt(33), BoxPtr(demo55o)] newboxes = _resume_remap(liveboxes, [#b2s -- virtual b3s, #b4s -- virtual #b2s -- again, shared #b3s -- again, shared b5s], b3t, b5t) metainterp = MyMetaInterp() reader = ResumeDataReader(storage, newboxes, metainterp) assert len(reader.virtuals) == 2 b2t = reader._decode_box(modifier._gettagged(b2s)) b4t = reader._decode_box(modifier._gettagged(b4s)) trace = metainterp.trace b2new = (rop.NEW_WITH_VTABLE, [ConstAddr(LLtypeMixin.node_vtable_adr, LLtypeMixin.cpu)], b2t, None) b4new = (rop.NEW_WITH_VTABLE, [ConstAddr(LLtypeMixin.node_vtable_adr2, LLtypeMixin.cpu)], b4t, None) b2set = [(rop.SETFIELD_GC, [b2t, b4t], None, LLtypeMixin.nextdescr), (rop.SETFIELD_GC, [b2t, c1s], None, LLtypeMixin.valuedescr)] b4set = [(rop.SETFIELD_GC, [b4t, b2t], None, LLtypeMixin.nextdescr), (rop.SETFIELD_GC, [b4t, b3t], None, LLtypeMixin.valuedescr), (rop.SETFIELD_GC, [b4t, b5t], None, LLtypeMixin.otherdescr)] if untag(modifier._gettagged(b2s))[0] == -2: expected = [b2new, b4new] + b2set + b4set else: expected = [b4new, b2new] + b4set + b2set for x, y in zip(expected, trace): assert x == y ptr = b2t.value._obj.container._as_ptr() assert lltype.typeOf(ptr) == lltype.Ptr(LLtypeMixin.NODE) assert ptr.value == 111 ptr2 = ptr.next ptr2 = lltype.cast_pointer(lltype.Ptr(LLtypeMixin.NODE2), ptr2) assert ptr2.other == demo55 assert ptr2.parent.value == 33 assert ptr2.parent.next == ptr