本文整理汇总了Python中pypy.rpython.ootypesystem.ootype.cast_to_object函数的典型用法代码示例。如果您正苦于以下问题:Python cast_to_object函数的具体用法?Python cast_to_object怎么用?Python cast_to_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast_to_object函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: fn_null
def fn_null():
a = ootype.null(A)
b = ootype.null(B)
obj1 = ootype.cast_to_object(a)
obj2 = ootype.cast_to_object(b)
assert obj1 == obj2
assert ootype.cast_from_object(A, obj1) == a
assert ootype.cast_from_object(B, obj2) == b
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_rclass.py
示例2: get_exception
def get_exception(self):
exc_value = self.get_inputargs().get_exc_value()
if exc_value:
exc_obj = dotnet.cast_from_native_object(exc_value)
exc_inst = ootype.cast_from_object(ootype.ROOT, exc_obj)
cls = ootype.classof(exc_value)
return ootype.cast_to_object(cls)
return ootype.cast_to_object(ootype.nullruntimeclass)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:runner.py
示例3: test_unwrap_object
def test_unwrap_object(self):
A = ootype.Instance("A", ootype.ROOT, {})
a1 = ootype.new(A)
a2 = ootype.new(A)
obj1 = ootype.cast_to_object(a1)
obj2 = ootype.cast_to_object(a2)
def fn(flag):
if flag:
obj = obj1
else:
obj = obj2
a3 = ootype.cast_from_object(A, obj)
return a3 is a1
res = self.interpret(fn, [True], backendopt=False)
assert res is True
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:15,代码来源:constant.py
示例4: wrap
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)
开发者ID:enyst,项目名称:plexnet,代码行数:29,代码来源:warmstate.py
示例5: fn_mix_null
def fn_mix_null(flag):
a = ootype.new(A)
obj = ootype.cast_to_object(a)
if flag:
return obj
else:
return ootype.NULL
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py
示例6: 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
示例7: fn_is_true
def fn_is_true(flag):
if flag:
a = ootype.new(A)
else:
a = ootype.null(A)
obj = ootype.cast_to_object(a)
return bool(obj)
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py
示例8: constant
def constant(value):
if isinstance(lltype.typeOf(value), lltype.Ptr):
return ConstPtr(value)
elif isinstance(ootype.typeOf(value), ootype.OOType):
return ConstObj(ootype.cast_to_object(value))
else:
return ConstInt(value)
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_optimizefindnode.py
示例9: fn_record
def fn_record():
b = ootype.new(B)
b.x = 42
obj = ootype.cast_to_object(b)
b2 = ootype.cast_from_object(B, obj)
assert b2.x == 42
assert b is b2
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py
示例10: fn_instance
def fn_instance():
a = ootype.new(A)
obj = ootype.cast_to_object(a)
a2 = ootype.cast_from_object(A, obj)
a3 = ootype.cast_from_object(ootype.ROOT, obj)
assert a is a2
assert a is a3
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py
示例11: wrap
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):
value = longlong.getfloatstorage(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)
else:
value = intmask(value)
if in_const_box:
return history.ConstInt(value)
else:
return history.BoxInt(value)
开发者ID:ieure,项目名称:pypy,代码行数:33,代码来源:warmstate.py
示例12: test_convert_string_to_object
def test_convert_string_to_object(self):
s = self.string_to_ll("hello world")
obj = ootype.cast_to_object(s)
def fn():
s1 = ootype.cast_from_object(ootype.String, obj)
return s1
res = self.interpret(fn, [], backendopt=False)
assert res == 'hello world'
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:constant.py
示例13: fn
def fn():
a = ootype.new(A)
ahash = ootype.identityhash(a)
obj = ootype.cast_to_object(a)
native = cast_to_native_object(obj)
name = native.GetType().get_Name()
obj2 = cast_from_native_object(native)
a2 = ootype.cast_from_object(A, obj2)
a2hash = ootype.identityhash(a2)
return name, ahash == a2hash
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:test_dotnet.py
示例14: __init__
def __init__(self, cpu, cliloop):
self.setoptions()
self.cpu = cpu
self.name = cliloop.get_fresh_cli_name()
self.cliloop = cliloop
self.boxes = {} # box --> local var
self.branches = []
self.branchlabels = []
self.consts = {} # object --> index
self.meth_wrapper = self._get_meth_wrapper()
self.il = self.meth_wrapper.get_il_generator()
self.av_consts = MethodArgument(0, System.Type.GetType("System.Object[]"))
t_InputArgs = dotnet.typeof(InputArgs)
self.av_inputargs = MethodArgument(1,t_InputArgs )
self.av_ovf_flag = BoxInt()
self.exc_value_field = t_InputArgs.GetField('exc_value')
if cpu.rtyper:
self.av_OverflowError = ConstObj(ootype.cast_to_object(cpu.ll_ovf_exc))
self.av_ZeroDivisionError = ConstObj(ootype.cast_to_object(cpu.ll_zero_exc))
else:
self.av_OverflowError = None
self.av_ZeroDivisionError = None
self.box2type = {}
开发者ID:alkorzt,项目名称:pypy,代码行数:23,代码来源:method.py
示例15: get_const
def get_const(self, name, typ):
if self._consts is None:
return name
obj = self._consts[name]
if self.type_system == 'lltype':
if typ == 'ptr':
return ConstPtr(obj)
else:
assert typ == 'class'
return ConstAddr(llmemory.cast_ptr_to_adr(obj),
self.cpu)
else:
if typ == 'ptr':
return ConstObj(obj)
else:
assert typ == 'class'
return ConstObj(ootype.cast_to_object(obj))
开发者ID:enyst,项目名称:plexnet,代码行数:17,代码来源:oparser.py
示例16: do_runtimenew
def do_runtimenew(self, classbox):
classobj = classbox.getref(ootype.Class)
res = ootype.runtimenew(classobj)
return BoxObj(ootype.cast_to_object(res))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:4,代码来源:runner.py
示例17: get_overflow_error
def get_overflow_error(self):
exc_type = ootype.cast_to_object(ootype.classof(self.ll_ovf_exc))
exc_value = ootype.cast_to_object(self.ll_ovf_exc)
return exc_type, exc_value
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:4,代码来源:runner.py
示例18: constclass
def constclass(cls_vtable):
if self.type_system == 'lltype':
return ConstAddr(llmemory.cast_ptr_to_adr(cls_vtable),
self.cpu)
else:
return ConstObj(ootype.cast_to_object(cls_vtable))
开发者ID:alkorzt,项目名称:pypy,代码行数:6,代码来源:test_optimizefindnode.py
示例19: set_overflow_error
def set_overflow_error(self):
exc_obj = ootype.cast_to_object(self.ll_ovf_exc)
exc_value = dotnet.cast_to_native_object(exc_obj)
self.get_inputargs().set_exc_value(exc_value)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:4,代码来源:runner.py
示例20: typedescr2classbox
def typedescr2classbox(self, descr):
assert isinstance(descr, TypeDescr)
return ConstObj(ootype.cast_to_object(descr.ooclass))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:3,代码来源:runner.py
注:本文中的pypy.rpython.ootypesystem.ootype.cast_to_object函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论