本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.cast_primitive函数的典型用法代码示例。如果您正苦于以下问题:Python cast_primitive函数的具体用法?Python cast_primitive怎么用?Python cast_primitive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast_primitive函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: f
def f(x):
x = cast_primitive(UnsignedLongLong, x)
x <<= 60
x /= 3
x <<= 1
x = cast_primitive(SignedLongLong, x)
x >>= 32
return cast_primitive(Signed, x)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:cast.py
示例2: boxresult
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))
开发者ID:ieure,项目名称:pypy,代码行数:7,代码来源:runner.py
示例3: revealconst
def revealconst(self, T):
if isinstance(T, lltype.Ptr):
return lltype.cast_int_to_ptr(T, self.get_integer_value())
elif T is llmemory.Address:
return llmemory.cast_int_to_adr(self.get_integer_value())
else:
return lltype.cast_primitive(T, self.get_integer_value())
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:genvarorconst.py
示例4: cast_whatever_to_int
def cast_whatever_to_int(T, value):
if isinstance(T, lltype.Ptr):
return lltype.cast_ptr_to_int(value)
elif T is llmemory.Address:
return llmemory.cast_adr_to_int(value)
else:
return lltype.cast_primitive(lltype.Signed, value)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:rgenop.py
示例5: cast_int_to_whatever
def cast_int_to_whatever(T, value):
if isinstance(T, lltype.Ptr):
return lltype.cast_int_to_ptr(T, value)
elif T is llmemory.Address:
return llmemory.cast_int_to_adr(value)
else:
return lltype.cast_primitive(T, value)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:7,代码来源:rgenop.py
示例6: convert_const
def convert_const(self, value):
if isinstance(value, objectmodel.Symbolic):
return value
T = typeOf(value)
if isinstance(T, Number) or T is Bool:
return cast_primitive(self.lowleveltype, value)
raise TyperError("not an integer: %r" % (value,))
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:rint.py
示例7: ll_array_set
def ll_array_set(ITEM, it0, it1):
if it0.size == 0:
return # empty LHS..
ll_assert(it0.size == it1.size, "it0.size == it1.size")
while it0.index < it0.size:
it0.dataptr[0] = cast_primitive(ITEM, it1.dataptr[0])
it0.ll_next()
it1.ll_next()
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:rarray.py
示例8: ll_str2unicode
def ll_str2unicode(str):
lgt = len(str.chars)
s = mallocunicode(lgt)
for i in range(lgt):
if ord(str.chars[i]) > 127:
raise UnicodeDecodeError
s.chars[i] = cast_primitive(UniChar, str.chars[i])
return s
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:rstr.py
示例9: os_open_lltypeimpl
def os_open_lltypeimpl(path, flags, mode):
l_path = rffi.str2charp(path)
mode = lltype.cast_primitive(mode_t, mode)
result = os_open(l_path, flags, mode)
rffi.free_charp(l_path)
if result == -1:
raise OSError(rffi.c_errno, "os_open failed")
return result
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:ll_os.py
示例10: ll_encode_latin1
def ll_encode_latin1(self, s):
length = len(s.chars)
result = mallocstr(length)
for i in range(length):
c = s.chars[i]
if ord(c) > 255:
raise UnicodeEncodeError("character not in latin1 range")
result.chars[i] = cast_primitive(Char, c)
return result
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:rstr.py
示例11: ll_str
def ll_str(self, value):
sb = ootype.new(ootype.StringBuilder)
lgt = value.ll_strlen()
sb.ll_allocate(lgt)
for i in range(lgt):
c = value.ll_stritem_nonneg(i)
if ord(c) > 127:
raise UnicodeEncodeError("%d > 127, not ascii" % ord(c))
sb.ll_append_char(cast_primitive(Char, c))
return sb.ll_build()
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:rstr.py
示例12: unwrap
def unwrap(TYPE, box):
if TYPE is lltype.Void:
return None
if isinstance(TYPE, lltype.Ptr):
return box.getref(TYPE)
if isinstance(TYPE, ootype.OOType):
return box.getref(TYPE)
if TYPE == lltype.Float:
return box.getfloat()
else:
return lltype.cast_primitive(TYPE, box.getint())
开发者ID:enyst,项目名称:plexnet,代码行数:11,代码来源:warmstate.py
示例13: set_future_value
def set_future_value(cpu, j, value, typecode):
if typecode == 'ref':
refvalue = cpu.ts.cast_to_ref(value)
cpu.set_future_value_ref(j, refvalue)
elif typecode == 'int':
intvalue = lltype.cast_primitive(lltype.Signed, value)
cpu.set_future_value_int(j, intvalue)
elif typecode == 'float':
assert isinstance(value, float)
cpu.set_future_value_float(j, value)
else:
assert False
开发者ID:enyst,项目名称:plexnet,代码行数:12,代码来源:warmstate.py
示例14: genconst
def genconst(self, llvalue):
T = lltype.typeOf(llvalue)
if T is llmemory.Address:
return AddrConst(llvalue)
elif isinstance(T, lltype.Primitive):
return IntConst(lltype.cast_primitive(lltype.Signed, llvalue))
elif isinstance(T, lltype.Ptr):
lladdr = llmemory.cast_ptr_to_adr(llvalue)
if T.TO._gckind == 'gc':
self.keepalive_gc_refs.append(lltype.cast_opaque_ptr(llmemory.GCREF, llvalue))
return AddrConst(lladdr)
else:
assert 0, "XXX not implemented"
开发者ID:antoine1fr,项目名称:pygirl,代码行数:13,代码来源:rgenop.py
示例15: get_string
def get_string(self, builder, r):
current = getattr(builder, self.builder_cache)
if current and r.random() < .8:
v_string = r.choice(current)
string = v_string.getref(self.ptr)
else:
string = self.alloc(builder.get_index(500, r).getint())
v_string = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, string))
current.append(v_string)
for i in range(len(string.chars)):
char = r.random_integer() % self.max
string.chars[i] = lltype.cast_primitive(self.primitive, char)
return v_string
开发者ID:alkorzt,项目名称:pypy,代码行数:13,代码来源:test_ll_random.py
示例16: _generalcast
def _generalcast(T, value):
if isinstance(T, lltype.Ptr):
return lltype.cast_pointer(T, value)
elif T == llmemory.Address:
return llmemory.cast_ptr_to_adr(value)
else:
T1 = lltype.typeOf(value)
if T1 is llmemory.Address:
value = llmemory.cast_adr_to_int(value)
elif isinstance(T1, lltype.Ptr):
value = lltype.cast_ptr_to_int(value)
else:
value = value
return lltype.cast_primitive(T, value)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:14,代码来源:llimpl.py
示例17: _new
def _new(x, cpu):
"NOT_RPYTHON"
kind = getkind(lltype.typeOf(x))
if kind == "int":
intval = lltype.cast_primitive(lltype.Signed, x)
return BoxInt(intval)
elif kind == "ref":
# XXX add ootype support?
ptrval = lltype.cast_opaque_ptr(llmemory.GCREF, x)
return BoxPtr(ptrval)
elif kind == "float":
return BoxFloat(x)
else:
raise NotImplementedError(kind)
开发者ID:jerroldgao,项目名称:pypy,代码行数:14,代码来源:history.py
示例18: genconst
def genconst(self, llvalue):
T = lltype.typeOf(llvalue)
if T is llmemory.Address:
return AddrConst(llvalue)
elif T is lltype.Bool:
return BoolConst(lltype.cast_primitive(lltype.Bool, llvalue))
elif T is lltype.Char:
return CharConst(lltype.cast_primitive(lltype.Char, llvalue))
elif T is lltype.Unsigned:
return UIntConst(lltype.cast_primitive(lltype.Unsigned, llvalue))
elif T is lltype.Float:
return FloatConst(lltype.cast_primitive(lltype.Float, llvalue))
elif isinstance(T, lltype.Primitive):
return IntConst(lltype.cast_primitive(lltype.Signed, llvalue))
elif isinstance(T, lltype.Ptr):
lladdr = llmemory.cast_ptr_to_adr(llvalue)
#if T.TO._gckind == 'gc':
# self.keepalive_gc_refs.append(lltype.cast_opaque_ptr(llmemory.GCREF, llvalue))
return AddrConst(lladdr)
else:
msg = 'XXX not implemented'
logger.dump(msg)
assert 0, msg
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:23,代码来源:rgenop.py
示例19: PyMember_GetOne
def PyMember_GetOne(space, obj, w_member):
addr = rffi.cast(ADDR, obj)
addr += w_member.c_offset
member_type = rffi.cast(lltype.Signed, w_member.c_type)
for converter in integer_converters:
typ, lltyp, _ = converter
if typ == member_type:
result = rffi.cast(rffi.CArrayPtr(lltyp), addr)
if lltyp is rffi.FLOAT:
w_result = space.wrap(lltype.cast_primitive(lltype.Float,
result[0]))
elif typ == T_BOOL:
x = rffi.cast(lltype.Signed, result[0])
w_result = space.wrap(x != 0)
else:
w_result = space.wrap(result[0])
return w_result
if member_type == T_STRING:
result = rffi.cast(rffi.CCHARPP, addr)
if result[0]:
w_result = PyString_FromString(space, result[0])
else:
w_result = space.w_None
elif member_type == T_STRING_INPLACE:
result = rffi.cast(rffi.CCHARP, addr)
w_result = PyString_FromString(space, result)
elif member_type == T_CHAR:
result = rffi.cast(rffi.CCHARP, addr)
w_result = space.wrap(result[0])
elif member_type == T_OBJECT:
obj_ptr = rffi.cast(PyObjectP, addr)
if obj_ptr[0]:
w_result = from_ref(space, obj_ptr[0])
else:
w_result = space.w_None
elif member_type == T_OBJECT_EX:
obj_ptr = rffi.cast(PyObjectP, addr)
if obj_ptr[0]:
w_result = from_ref(space, obj_ptr[0])
else:
w_name = space.wrap(rffi.charp2str(w_member.c_name))
raise OperationError(space.w_AttributeError, w_name)
else:
raise OperationError(space.w_SystemError,
space.wrap("bad memberdescr type"))
return w_result
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:48,代码来源:structmember.py
示例20: convert_const
def convert_const(self, value):
if value is None:
return nullptr(self.lowleveltype.TO)
#value = getattr(value, '__self__', value) # for bound string methods
if not isinstance(value, self.basetype):
raise TyperError("not a str: %r" % (value,))
try:
return self.CACHE[value]
except KeyError:
p = self.malloc(len(value))
for i in range(len(value)):
p.chars[i] = cast_primitive(self.base, value[i])
p.hash = 0
self.ll.ll_strhash(p) # precompute the hash
self.CACHE[value] = p
return p
开发者ID:alkorzt,项目名称:pypy,代码行数:16,代码来源:rstr.py
注:本文中的pypy.rpython.lltypesystem.lltype.cast_primitive函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论