def boxresult(RESULT, result): if isinstance(RESULT, ootype.OOType): return history.BoxObj(ootype.cast_to_object(result)) elif RESULT is lltype.Float: return history.BoxFloat(result) else: return history.BoxInt(lltype.cast_primitive(ootype.Signed, result))
def wrap(cpu, value, in_const_box=False): if isinstance(lltype.typeOf(value), lltype.Ptr): if lltype.typeOf(value).TO._gckind == 'gc': value = lltype.cast_opaque_ptr(llmemory.GCREF, value) if in_const_box: return history.ConstPtr(value) else: return history.BoxPtr(value) else: adr = llmemory.cast_ptr_to_adr(value) value = cpu.cast_adr_to_int(adr) # fall through to the end of the function elif isinstance(lltype.typeOf(value), ootype.OOType): value = ootype.cast_to_object(value) if in_const_box: return history.ConstObj(value) else: return history.BoxObj(value) elif isinstance(value, float): if in_const_box: return history.ConstFloat(value) else: return history.BoxFloat(value) else: value = intmask(value) if in_const_box: return history.ConstInt(value) else: return history.BoxInt(value)
def do_getarrayitem_gc(self, arraybox, indexbox, arraydescr): assert isinstance(arraydescr, Descr) array = arraybox.getref_base() index = indexbox.getint() if arraydescr.typeinfo == REF: return history.BoxPtr(llimpl.do_getarrayitem_gc_ptr(array, index)) elif arraydescr.typeinfo == INT: return history.BoxInt( llimpl.do_getarrayitem_gc_int(array, index, self.memo_cast)) elif arraydescr.typeinfo == FLOAT: return history.BoxFloat( llimpl.do_getarrayitem_gc_float(array, index)) else: raise NotImplementedError
def do_getfield_gc(self, structbox, fielddescr): assert isinstance(fielddescr, Descr) struct = structbox.getref_base() if fielddescr.typeinfo == REF: return history.BoxPtr( llimpl.do_getfield_gc_ptr(struct, fielddescr.ofs)) elif fielddescr.typeinfo == INT: return history.BoxInt( llimpl.do_getfield_gc_int(struct, fielddescr.ofs, self.memo_cast)) elif fielddescr.typeinfo == FLOAT: return history.BoxFloat( llimpl.do_getfield_gc_float(struct, fielddescr.ofs)) else: raise NotImplementedError
def make_boxes_from_latest_values(self, faildescr): inputargs_and_holes = [] for i in range(len(faildescr._fail_args_types)): boxtype = faildescr._fail_args_types[i] if boxtype == history.INT: box = history.BoxInt(self.get_latest_value_int(i)) elif boxtype == history.REF: box = self.ts.BoxRef(self.get_latest_value_ref(i)) elif boxtype == history.FLOAT: box = history.BoxFloat(self.get_latest_value_float(i)) elif boxtype == history.HOLE: box = None else: assert False, "bad box type: num=%d" % ord(boxtype) inputargs_and_holes.append(box) return inputargs_and_holes
def do_getfield_raw(self, structbox, fielddescr): assert isinstance(fielddescr, Descr) struct = self.cast_int_to_adr(structbox.getint()) if fielddescr.typeinfo == REF: return history.BoxPtr( llimpl.do_getfield_raw_ptr(struct, fielddescr.ofs, self.memo_cast)) elif fielddescr.typeinfo == INT: return history.BoxInt( llimpl.do_getfield_raw_int(struct, fielddescr.ofs, self.memo_cast)) elif fielddescr.typeinfo == FLOAT: return history.BoxFloat( llimpl.do_getfield_raw_float(struct, fielddescr.ofs, self.memo_cast)) else: raise NotImplementedError
def do_call(self, args, calldescr): assert isinstance(calldescr, Descr) func = args[0].getint() for arg in args[1:]: if arg.type == REF: llimpl.do_call_pushptr(arg.getref_base()) elif arg.type == FLOAT: llimpl.do_call_pushfloat(arg.getfloat()) else: llimpl.do_call_pushint(arg.getint()) if calldescr.typeinfo == REF: return history.BoxPtr(llimpl.do_call_ptr(func, self.memo_cast)) elif calldescr.typeinfo == INT: return history.BoxInt(llimpl.do_call_int(func, self.memo_cast)) elif calldescr.typeinfo == FLOAT: return history.BoxFloat(llimpl.do_call_float(func, self.memo_cast)) elif calldescr.typeinfo == 'v': # void llimpl.do_call_void(func, self.memo_cast) else: raise NotImplementedError
def wrap(cpu, value, in_const_box=False): if isinstance(lltype.typeOf(value), lltype.Ptr): if lltype.typeOf(value).TO._gckind == 'gc': value = lltype.cast_opaque_ptr(llmemory.GCREF, value) if in_const_box: return history.ConstPtr(value) else: return history.BoxPtr(value) else: adr = llmemory.cast_ptr_to_adr(value) value = heaptracker.adr2int(adr) # fall through to the end of the function elif isinstance(lltype.typeOf(value), ootype.OOType): value = ootype.cast_to_object(value) if in_const_box: return history.ConstObj(value) else: return history.BoxObj(value) elif (isinstance(value, float) or longlong.is_longlong(lltype.typeOf(value))): if isinstance(value, float): value = longlong.getfloatstorage(value) else: value = rffi.cast(lltype.SignedLongLong, value) if in_const_box: return history.ConstFloat(value) else: return history.BoxFloat(value) elif isinstance(value, str) or isinstance(value, unicode): assert len(value) == 1 # must be a character value = ord(value) elif lltype.typeOf(value) is lltype.SingleFloat: value = longlong.singlefloat2int(value) else: value = intmask(value) if in_const_box: return history.ConstInt(value) else: return history.BoxInt(value)