本文整理汇总了Python中pypy.rpython.ootypesystem.ootype.cast_to_object函数的典型用法代码示例。如果您正苦于以下问题:Python cast_to_object函数的具体用法?Python cast_to_object怎么用?Python cast_to_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast_to_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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
示例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)
示例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
示例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))
示例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)
示例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)
示例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
示例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
示例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)
示例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'
示例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
示例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 = {}
示例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))