def str_storage_getitem(self, TYPE, buf, offset): def f(): return str_storage_getitem(TYPE, buf, offset) res = self.interp_operations(f, [], supports_singlefloats=True) # kind = getkind(TYPE)[0] # 'i' or 'f' self.check_operations_history({'gc_load_indexed_%s' % kind: 1, 'finish': 1}) # if TYPE == lltype.SingleFloat: # interp_operations returns the int version of r_singlefloat, but # our tests expects to receive an r_singlefloat: let's convert it # back! return longlong.int2singlefloat(res) return res
def gc_load_from_string(self, TYPE, buf, offset): def f(offset): return str_gc_load(TYPE, buf, offset) res = self.interp_operations(f, [offset], supports_singlefloats=True) # kind = getkind(TYPE)[0] # 'i' or 'f' self.check_operations_history({ 'gc_load_indexed_%s' % kind: 1, 'finish': 1 }) # if TYPE == lltype.SingleFloat: # interp_operations returns the int version of r_singlefloat, but # our tests expects to receive an r_singlefloat: let's convert it # back! return longlong.int2singlefloat(res) return res
def specialize_value(TYPE, x): """'x' must be a Signed, a GCREF or a FLOATSTORAGE. This function casts it to a more specialized type, like Char or Ptr(..). """ INPUT = lltype.typeOf(x) if INPUT is lltype.Signed: if isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'raw': # non-gc pointer return rffi.cast(TYPE, x) elif TYPE is lltype.SingleFloat: return longlong.int2singlefloat(x) else: return lltype.cast_primitive(TYPE, x) elif INPUT is longlong.FLOATSTORAGE: if longlong.is_longlong(TYPE): return rffi.cast(TYPE, x) assert TYPE is lltype.Float return longlong.getrealfloat(x) else: return lltype.cast_opaque_ptr(TYPE, x)
def cast_from_int(TYPE, x): if isinstance(TYPE, lltype.Ptr): if isinstance(x, (int, long, llmemory.AddressAsInt)): x = llmemory.cast_int_to_adr(x) #if repr(x.ptr).startswith('<* <C object '): # pom pom pom # # assume that we want a "C-style" cast, without typechecking the value return rffi.cast(TYPE, x) #return llmemory.cast_adr_to_ptr(x, TYPE) elif TYPE == llmemory.Address: if isinstance(x, (int, long, llmemory.AddressAsInt)): x = llmemory.cast_int_to_adr(x) assert lltype.typeOf(x) == llmemory.Address return x elif TYPE is lltype.SingleFloat: assert lltype.typeOf(x) is lltype.Signed return longlong.int2singlefloat(x) else: if lltype.typeOf(x) == llmemory.Address: x = heaptracker.adr2int(x) return lltype.cast_primitive(TYPE, x)
def cast_from_int(TYPE, x): if isinstance(TYPE, lltype.Ptr): if isinstance(x, (int, long, llmemory.AddressAsInt)): x = llmemory.cast_int_to_adr(x) try: # pom pom pom return llmemory.cast_adr_to_ptr(x, TYPE) except Exception: # assume that we want a "C-style" cast, without typechecking the value return rffi.cast(TYPE, x) elif TYPE == llmemory.Address: if isinstance(x, (int, long, llmemory.AddressAsInt)): x = llmemory.cast_int_to_adr(x) assert lltype.typeOf(x) == llmemory.Address return x elif TYPE is lltype.SingleFloat: assert lltype.typeOf(x) is lltype.Signed return longlong.int2singlefloat(x) else: if lltype.typeOf(x) == llmemory.Address: x = heaptracker.adr2int(x) return lltype.cast_primitive(TYPE, x)
def bh_raw_store_i(self, struct, offset, newvalue, descr): ll_p = rffi.cast(rffi.CCHARP, struct) ll_p = rffi.cast(lltype.Ptr(descr.A), rffi.ptradd(ll_p, offset)) if descr.A.OF == lltype.SingleFloat: newvalue = longlong.int2singlefloat(newvalue) ll_p[0] = rffi.cast(descr.A.OF, newvalue)