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