本文整理汇总了Python中pypy.rpython.lltypesystem.lltype.cast_opaque_ptr函数的典型用法代码示例。如果您正苦于以下问题:Python cast_opaque_ptr函数的具体用法?Python cast_opaque_ptr怎么用?Python cast_opaque_ptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast_opaque_ptr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: do_call
def do_call(result, path, index, remaining_depth):
# clone the while path
clonedata.gcobjectptr = lltype.cast_opaque_ptr(llmemory.GCREF,
path)
clonedata.pool = lltype.nullptr(X_POOL)
llop.gc_x_clone(lltype.Void, clonedata)
# install the new pool as the current one
parentpool = llop.gc_x_swap_pool(X_POOL_PTR, clonedata.pool)
path = lltype.cast_opaque_ptr(lltype.Ptr(NODE),
clonedata.gcobjectptr)
# The above should have the same effect as:
# path = clone(path)
# bump all the path node counters by one
p = path
while p:
p.counter += 1
p = p.next
if remaining_depth == 0:
llop.debug_print(lltype.Void, "setting", index, "with", path)
result[index] = path # leaf
else:
node = lltype.malloc(NODE)
node.index = index * 2
node.counter = 0
node.next = path
do_call(result, node, index * 2, remaining_depth - 1)
node.index += 1 # mutation!
do_call(result, node, index * 2 + 1, remaining_depth - 1)
# restore the parent pool
llop.gc_x_swap_pool(X_POOL_PTR, parentpool)
开发者ID:alkorzt,项目名称:pypy,代码行数:34,代码来源:test_transformed_gc.py
示例2: continue_tracing
def continue_tracing(self, gcref, real_object):
if not self.is_virtual_ref(gcref):
return
assert real_object
vref = lltype.cast_opaque_ptr(lltype.Ptr(self.JIT_VIRTUAL_REF), gcref)
assert vref.virtual_token != self.TOKEN_TRACING_RESCALL
vref.virtual_token = self.TOKEN_NONE
vref.forced = lltype.cast_opaque_ptr(rclass.OBJECTPTR, real_object)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:virtualref.py
示例3: virtual_ref_during_tracing
def virtual_ref_during_tracing(self, real_object):
assert real_object
vref = lltype.malloc(self.JIT_VIRTUAL_REF)
p = lltype.cast_pointer(rclass.OBJECTPTR, vref)
p.typeptr = self.jit_virtual_ref_vtable
vref.virtual_token = self.TOKEN_NONE
vref.forced = lltype.cast_opaque_ptr(rclass.OBJECTPTR, real_object)
return lltype.cast_opaque_ptr(llmemory.GCREF, vref)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:virtualref.py
示例4: test_compile_tmp_callback
def test_compile_tmp_callback():
from pypy.jit.codewriter import heaptracker
from pypy.jit.backend.llgraph import runner
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.annlowlevel import llhelper
from pypy.rpython.llinterp import LLException
#
cpu = runner.LLtypeCPU(None)
FUNC = lltype.FuncType([lltype.Signed]*4, lltype.Signed)
def ll_portal_runner(g1, g2, r3, r4):
assert (g1, g2, r3, r4) == (12, 34, -156, -178)
if raiseme:
raise raiseme
else:
return 54321
#
class FakeJitDriverSD:
portal_runner_ptr = llhelper(lltype.Ptr(FUNC), ll_portal_runner)
portal_runner_adr = llmemory.cast_ptr_to_adr(portal_runner_ptr)
portal_calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT)
portal_finishtoken = compile.DoneWithThisFrameDescrInt()
num_red_args = 2
result_type = INT
#
loop_token = compile_tmp_callback(cpu, FakeJitDriverSD(),
[ConstInt(12), ConstInt(34)],
[BoxInt(56), ConstInt(78), BoxInt(90)])
#
raiseme = None
cpu.set_future_value_int(0, -156)
cpu.set_future_value_int(1, -178)
cpu.set_future_value_int(2, -190) # passed in, but dropped
fail_descr = cpu.execute_token(loop_token)
assert fail_descr is FakeJitDriverSD().portal_finishtoken
#
EXC = lltype.GcStruct('EXC')
llexc = lltype.malloc(EXC)
raiseme = LLException("exception class", llexc)
cpu.set_future_value_int(0, -156)
cpu.set_future_value_int(1, -178)
cpu.set_future_value_int(2, -190)
fail_descr = cpu.execute_token(loop_token)
assert isinstance(fail_descr, compile.PropagateExceptionDescr)
got = cpu.grab_exc_value()
assert lltype.cast_opaque_ptr(lltype.Ptr(EXC), got) == llexc
#
class FakeMetaInterpSD:
class ExitFrameWithExceptionRef(Exception):
pass
FakeMetaInterpSD.cpu = cpu
cpu.set_future_value_int(0, -156)
cpu.set_future_value_int(1, -178)
cpu.set_future_value_int(2, -190)
fail_descr = cpu.execute_token(loop_token)
try:
fail_descr.handle_fail(FakeMetaInterpSD(), None)
except FakeMetaInterpSD.ExitFrameWithExceptionRef, e:
assert lltype.cast_opaque_ptr(lltype.Ptr(EXC), e.args[1]) == llexc
开发者ID:gorakhargosh,项目名称:pypy,代码行数:58,代码来源:test_compile.py
示例5: g
def g(s):
lst = rgc.get_rpy_roots()
found = False
for x in lst:
if x == lltype.cast_opaque_ptr(llmemory.GCREF, s):
found = True
if x == lltype.cast_opaque_ptr(llmemory.GCREF, s.u):
os.write(2, "s.u should not be found!\n")
assert False
return found == 1
开发者ID:pombredanne,项目名称:pypy,代码行数:10,代码来源:test_newgc.py
示例6: fn
def fn():
s = lltype.malloc(S)
s.u = lltype.malloc(U)
gcref1 = lltype.cast_opaque_ptr(llmemory.GCREF, s)
gcref2 = lltype.cast_opaque_ptr(llmemory.GCREF, s.u)
lst = rgc.get_rpy_referents(gcref1)
assert gcref2 in lst
assert gcref1 not in lst
s.u.x = 42
return 0
开发者ID:pombredanne,项目名称:pypy,代码行数:10,代码来源:test_newgc.py
示例7: test_extract_runtime_data_4
def test_extract_runtime_data_4():
struct = lltype.malloc(LLtypeMixin.S)
struct.a = 123
struct.b = lltype.malloc(LLtypeMixin.NODE)
structbox = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, struct))
sspecnode = _get_sspecnode()
res = []
sspecnode.extract_runtime_data(LLtypeMixin.cpu, structbox, res)
assert len(res) == 2
assert res[0].value == 123
assert (lltype.cast_opaque_ptr(lltype.Ptr(LLtypeMixin.NODE), res[1].value)
== struct.b)
开发者ID:alkorzt,项目名称:pypy,代码行数:12,代码来源:test_specnode.py
示例8: test_repr
def test_repr():
S = lltype.GcStruct('S')
T = lltype.GcStruct('T', ('header', S))
t = lltype.malloc(T)
s = lltype.cast_pointer(lltype.Ptr(S), t)
const = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, s))
assert const._getrepr_() == "*T"
开发者ID:enyst,项目名称:plexnet,代码行数:7,代码来源:test_history.py
示例9: test_rewrite_assembler_1
def test_rewrite_assembler_1(self):
# check rewriting of ConstPtrs
class MyFakeCPU:
def cast_adr_to_int(self, adr):
stored_addr = adr.address[0]
assert stored_addr == llmemory.cast_ptr_to_adr(s_gcref)
return 43
S = lltype.GcStruct('S')
s = lltype.malloc(S)
s_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
v_random_box = BoxPtr()
v_result = BoxInt()
operations = [
ResOperation(rop.OOIS, [v_random_box, ConstPtr(s_gcref)],
v_result),
]
gc_ll_descr = self.gc_ll_descr
gc_ll_descr.rewrite_assembler(MyFakeCPU(), operations)
assert len(operations) == 2
assert operations[0].opnum == rop.GETFIELD_RAW
assert operations[0].args == [ConstInt(43)]
assert operations[0].descr == gc_ll_descr.single_gcref_descr
v_box = operations[0].result
assert isinstance(v_box, BoxPtr)
assert operations[1].opnum == rop.OOIS
assert operations[1].args == [v_random_box, v_box]
assert operations[1].result == v_result
开发者ID:enyst,项目名称:plexnet,代码行数:27,代码来源:test_gc.py
示例10: setup_class
def setup_class(cls):
if option.runappdirect:
py.test.skip("Can't run this test with -A")
space = gettestobjspace(usemodules=('pypyjit',))
cls.space = space
w_f = space.appexec([], """():
def f():
pass
return f
""")
cls.w_f = w_f
ll_code = cast_instance_to_base_ptr(w_f.code)
code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code)
logger = Logger(MockSD())
oplist = parse("""
[i1, i2]
i3 = int_add(i1, i2)
debug_merge_point(0, 0, 0, 0, ConstPtr(ptr0))
guard_true(i3) []
""", namespace={'ptr0': code_gcref}).operations
def interp_on_compile():
pypyjitdriver.on_compile(logger, LoopToken(), oplist, 'loop',
0, False, ll_code)
def interp_on_compile_bridge():
pypyjitdriver.on_compile_bridge(logger, LoopToken(), oplist, 0)
cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:31,代码来源:test_jit_hook.py
示例11: test_record_constptrs
def test_record_constptrs(self):
class MyFakeCPU(object):
def cast_adr_to_int(self, adr):
assert adr == "some fake address"
return 43
class MyFakeGCRefList(object):
def get_address_of_gcref(self, s_gcref1):
assert s_gcref1 == s_gcref
return "some fake address"
S = lltype.GcStruct('S')
s = lltype.malloc(S)
s_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
v_random_box = BoxPtr()
v_result = BoxInt()
operations = [
ResOperation(rop.PTR_EQ, [v_random_box, ConstPtr(s_gcref)],
v_result),
]
gc_ll_descr = self.gc_ll_descr
gc_ll_descr.gcrefs = MyFakeGCRefList()
gcrefs = []
operations = get_deep_immutable_oplist(operations)
operations2 = gc_ll_descr.rewrite_assembler(MyFakeCPU(), operations,
gcrefs)
assert operations2 == operations
assert gcrefs == [s_gcref]
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:26,代码来源:test_gc.py
示例12: 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
示例13: test_call_stubs
def test_call_stubs():
c0 = GcCache(False)
ARGS = [lltype.Char, lltype.Signed]
RES = lltype.Char
descr1 = get_call_descr(c0, ARGS, RES)
def f(a, b):
return 'c'
call_stub = descr1.call_stub
fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
res = call_stub(rffi.cast(lltype.Signed, fnptr), [1, 2], None, None)
assert res == ord('c')
ARRAY = lltype.GcArray(lltype.Signed)
ARGS = [lltype.Float, lltype.Ptr(ARRAY)]
RES = lltype.Float
def f(a, b):
return float(b[0]) + a
fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
descr2 = get_call_descr(c0, ARGS, RES)
a = lltype.malloc(ARRAY, 3)
opaquea = lltype.cast_opaque_ptr(llmemory.GCREF, a)
a[0] = 1
res = descr2.call_stub(rffi.cast(lltype.Signed, fnptr),
[], [opaquea], [longlong.getfloatstorage(3.5)])
assert longlong.getrealfloat(res) == 4.5
开发者ID:ieure,项目名称:pypy,代码行数:29,代码来源:test_descr.py
示例14: test_nullity_with_guard
def test_nullity_with_guard(self):
allops = [rop.INT_IS_TRUE]
guards = [rop.GUARD_TRUE, rop.GUARD_FALSE]
p = lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(lltype.GcStruct("x")))
nullptr = lltype.nullptr(llmemory.GCREF.TO)
f = BoxInt()
for op in allops:
for guard in guards:
if op == rop.INT_IS_TRUE:
bp = BoxInt(1)
n = BoxInt(0)
else:
bp = BoxPtr(p)
n = BoxPtr(nullptr)
for b in (bp, n):
i1 = BoxInt(1)
ops = [
ResOperation(rop.SAME_AS, [ConstInt(1)], i1),
ResOperation(op, [b], f),
ResOperation(guard, [f], None, descr=BasicFailDescr()),
ResOperation(rop.FINISH, [ConstInt(0)], None, descr=BasicFailDescr()),
]
ops[-2].setfailargs([i1])
looptoken = JitCellToken()
self.cpu.compile_loop([b], ops, looptoken)
self.cpu.execute_token(looptoken, b.value)
result = self.cpu.get_latest_value_int(0)
if guard == rop.GUARD_FALSE:
assert result == execute(self.cpu, None, op, None, b).value
else:
assert result != execute(self.cpu, None, op, None, b).value
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:31,代码来源:test_runner.py
示例15: getvar
def getvar(self, arg):
if not arg:
return ConstInt(0)
try:
return ConstInt(int(arg))
except ValueError:
if self.is_float(arg):
return ConstFloat(float(arg))
if arg.startswith('"') or arg.startswith("'"):
# XXX ootype
info = arg.strip("'\"")
return ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF,
llstr(info)))
if arg.startswith('ConstClass('):
name = arg[len('ConstClass('):-1]
return self.get_const(name, 'class')
elif arg == 'None':
return None
elif arg == 'NULL':
if self.type_system == 'lltype':
return ConstPtr(ConstPtr.value)
else:
return ConstObj(ConstObj.value)
elif arg.startswith('ConstPtr('):
name = arg[len('ConstPtr('):-1]
return self.get_const(name, 'ptr')
return self.vars[arg]
开发者ID:enyst,项目名称:plexnet,代码行数:27,代码来源:oparser.py
示例16: test_assemble_cast_consts
def test_assemble_cast_consts():
ssarepr = SSARepr("test")
S = lltype.GcStruct('S')
s = lltype.malloc(S)
F = lltype.FuncType([], lltype.Signed)
f = lltype.functionptr(F, 'f')
ssarepr.insns = [
('int_return', Constant('X', lltype.Char)),
('int_return', Constant(unichr(0x1234), lltype.UniChar)),
('int_return', Constant(f, lltype.Ptr(F))),
('ref_return', Constant(s, lltype.Ptr(S))),
]
assembler = Assembler()
jitcode = assembler.assemble(ssarepr)
assert jitcode.code == ("\x00\x58"
"\x01\xFF"
"\x01\xFE"
"\x02\xFF")
assert assembler.insns == {'int_return/c': 0,
'int_return/i': 1,
'ref_return/r': 2}
f_int = heaptracker.adr2int(llmemory.cast_ptr_to_adr(f))
assert jitcode.constants_i == [0x1234, f_int]
s_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
assert jitcode.constants_r == [s_gcref]
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:test_assembler.py
示例17: 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
示例18: get_structptr_var
def get_structptr_var(self, r, must_have_vtable=False, type=lltype.Struct):
while True:
ptrvars = [(v, S) for (v, S) in self.ptrvars
if isinstance(S, type)]
if ptrvars and r.random() < 0.8:
v, S = r.choice(ptrvars)
else:
prebuilt_ptr_consts = [(v, S)
for (v, S, _) in self.prebuilt_ptr_consts
if isinstance(S, type)]
if prebuilt_ptr_consts and r.random() < 0.7:
v, S = r.choice(prebuilt_ptr_consts)
else:
if type is lltype.Struct:
# create a new constant structure
must_have_vtable = must_have_vtable or r.random() < 0.5
p = self.get_random_structure(r,
has_vtable=must_have_vtable)
else:
# create a new constant array
p = self.get_random_array(r)
S = lltype.typeOf(p).TO
v = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, p))
self.prebuilt_ptr_consts.append((v, S,
self.field_values(p)))
if not (must_have_vtable and S._names[0] != 'parent'):
break
return v, S
开发者ID:alkorzt,项目名称:pypy,代码行数:28,代码来源:test_ll_random.py
示例19: test_wrap
def test_wrap():
def _is(box1, box2):
return box1.__class__ == box2.__class__ and box1.value == box2.value
p = lltype.malloc(lltype.GcStruct("S"))
po = lltype.cast_opaque_ptr(llmemory.GCREF, p)
assert _is(wrap(None, 42), BoxInt(42))
assert _is(wrap(None, 42.5), boxfloat(42.5))
assert _is(wrap(None, p), BoxPtr(po))
assert _is(wrap(None, 42, in_const_box=True), ConstInt(42))
assert _is(wrap(None, 42.5, in_const_box=True), constfloat(42.5))
assert _is(wrap(None, p, in_const_box=True), ConstPtr(po))
if longlong.supports_longlong:
import sys
from pypy.rlib.rarithmetic import r_longlong, r_ulonglong
value = r_longlong(-sys.maxint * 17)
assert _is(wrap(None, value), BoxFloat(value))
assert _is(wrap(None, value, in_const_box=True), ConstFloat(value))
value_unsigned = r_ulonglong(-sys.maxint * 17)
assert _is(wrap(None, value_unsigned), BoxFloat(value))
sfval = r_singlefloat(42.5)
ival = longlong.singlefloat2int(sfval)
assert _is(wrap(None, sfval), BoxInt(ival))
assert _is(wrap(None, sfval, in_const_box=True), ConstInt(ival))
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:25,代码来源:test_warmstate.py
示例20: func
def func():
oldpool = llop.gc_x_swap_pool(X_POOL_PTR, lltype.nullptr(X_POOL))
a2 = make(22)
newpool = llop.gc_x_swap_pool(X_POOL_PTR, oldpool)
# clone a2
a2ref = lltype.cast_opaque_ptr(llmemory.GCREF, a2)
clonedata = lltype.malloc(X_CLONE)
clonedata.gcobjectptr = a2ref
clonedata.pool = newpool
llop.gc_x_clone(lltype.Void, clonedata)
a2copyref = clonedata.gcobjectptr
a2copy = lltype.cast_opaque_ptr(lltype.Ptr(A), a2copyref)
a2copy.b.x = 44
a2copy.more[0].x = 440
a2copy.more[1].x = 441
return a2.b.x * 1000000 + a2.more[0].x * 1000 + a2.more[1].x
开发者ID:alkorzt,项目名称:pypy,代码行数:16,代码来源:test_transformed_gc.py
注:本文中的pypy.rpython.lltypesystem.lltype.cast_opaque_ptr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论