def annotation_to_lltype(s_val, info=None): if isinstance(s_val, SomeInteriorPtr): p = s_val.ll_ptrtype if 0 in p.offsets: assert list(p.offsets).count(0) == 1 return lltype.Ptr(lltype.Ptr(p.PARENTTYPE)._interior_ptr_type_with_index(p.TO)) else: return lltype.Ptr(p.PARENTTYPE) if isinstance(s_val, SomePtr): return s_val.ll_ptrtype if type(s_val) is SomeInteger: return lltype.build_number(None, s_val.knowntype) for witness, T in annotation_to_ll_map: if witness.contains(s_val): return T if info is None: info = '' else: info = '%s: ' % info raise ValueError("%sshould return a low-level type,\ngot instead %r" % ( info, s_val))
casted = rffi.cast(lltp, ptr) casted[0] = rffi.cast(llt, val.int_val()) def ffi_size(self): return rffi.sizeof(llt) def ffi_type(self): return ctype return GenericCInt() from rpython.rlib.rarithmetic import build_int for x in [8, 16, 32, 64]: for s in [True, False]: nm = "C" + ("" if s else "U") + "Int" + str(x) int_tp = lltype.build_number(None, build_int(nm, s, x)) ctype = clibffi.cast_type_to_ffitype(int_tp) make_itype(unicode("pixie.stdlib." + nm), ctype, int_tp) class Token(py_object): """ Tokens are returned by ffi_set_value and are called when ffi is ready to clean up resources """ def finalize_token(self): pass
casted[0] = rffi.cast(llt, val.int_val()) def ffi_size(self): return rffi.sizeof(llt) def ffi_type(self): return ctype return GenericCInt() from rpython.rlib.rarithmetic import build_int for x in [8, 16, 32, 64]: for s in [True, False]: nm = "C" + ("" if s else "U") + "Int" + str(x) int_tp = lltype.build_number(None, build_int(nm, s, x)) ctype = clibffi.cast_type_to_ffitype(int_tp) make_itype(unicode("pixie.stdlib." + nm), ctype, int_tp) class Token(py_object): """ Tokens are returned by ffi_set_value and are called when ffi is ready to clean up resources """ def finalize_token(self): pass class CInt(CType): def __init__(self): CType.__init__(self, u"pixie.stdlib.CInt")
""" names = populate_inttypes() result = [] for name in names: tp = platform.types[name.upper()] globals()['r_' + name] = platform.numbertype_to_rclass[tp] globals()[name.upper()] = tp tpp = lltype.Ptr(lltype.Array(tp, hints={'nolength': True})) globals()[name.upper()+'P'] = tpp result.append(tp) return result NUMBER_TYPES = setup() platform.numbertype_to_rclass[lltype.Signed] = int # avoid "r_long" for common cases r_int_real = rarithmetic.build_int("r_int_real", r_int.SIGN, r_int.BITS, True) INT_real = lltype.build_number("INT", r_int_real) platform.numbertype_to_rclass[INT_real] = r_int_real NUMBER_TYPES.append(INT_real) # ^^^ this creates at least the following names: # -------------------------------------------------------------------- # Type RPython integer class doing wrap-around # -------------------------------------------------------------------- # SIGNEDCHAR r_signedchar # UCHAR r_uchar # SHORT r_short # USHORT r_ushort # INT r_int # UINT r_uint # LONG r_long # ULONG r_ulong
def rtyper_makerepr(self, rtyper): lltype = build_number(None, self.knowntype) return getintegerrepr(lltype)
def _make_type(self, name, signed, size): inttype = rarithmetic.build_int('r_' + name, signed, size*8) tp = lltype.build_number(name, inttype) self.numbertype_to_rclass[tp] = inttype self.types[name] = tp return tp