Example #1
0
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))
Example #2
0
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)
Example #3
0
 class MyMIFrame:
     jitcode = JitCode("test")
     jitcode.setup("\xFF"               # illegal instruction
                   "\x00\x00\x01\x02"   # int_add/ii>i
                   "\x01\x02",          # int_return/i
                   [],
                   num_regs_i=3, num_regs_r=0, num_regs_f=0)
     pc = 1
     registers_i = [history.BoxInt(40), history.ConstInt(2), None]
Example #4
0
 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
Example #5
0
 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
Example #6
0
 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
Example #7
0
 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
Example #8
0
 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
Example #9
0
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)
Example #10
0
 def instanceof(box):
     obj = box.getref(ootype.ROOT)
     return history.BoxInt(ootype.instanceof(obj, TYPE))
Example #11
0
 def do_cast_ptr_to_int(self, ptrbox):
     return history.BoxInt(
         llimpl.cast_to_int(ptrbox.getref_base(), self.memo_cast))
Example #12
0
 def do_unicodegetitem(self, stringbox, indexbox):
     string = stringbox.getref_base()
     index = indexbox.getint()
     return history.BoxInt(llimpl.do_unicodegetitem(0, string, index))
Example #13
0
 def do_unicodelen(self, stringbox):
     string = stringbox.getref_base()
     return history.BoxInt(llimpl.do_unicodelen(0, string))
Example #14
0
 def do_arraylen_gc(self, arraybox, arraydescr):
     array = arraybox.getref_base()
     return history.BoxInt(llimpl.do_arraylen_gc(arraydescr, array))