本文整理汇总了Python中pypy.jit.metainterp.warmstate.WarmEnterState._make_jitcell_getter_custom方法的典型用法代码示例。如果您正苦于以下问题:Python WarmEnterState._make_jitcell_getter_custom方法的具体用法?Python WarmEnterState._make_jitcell_getter_custom怎么用?Python WarmEnterState._make_jitcell_getter_custom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.jit.metainterp.warmstate.WarmEnterState
的用法示例。
在下文中一共展示了WarmEnterState._make_jitcell_getter_custom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_make_jitcell_getter_custom
# 需要导入模块: from pypy.jit.metainterp.warmstate import WarmEnterState [as 别名]
# 或者: from pypy.jit.metainterp.warmstate.WarmEnterState import _make_jitcell_getter_custom [as 别名]
def test_make_jitcell_getter_custom():
from pypy.rpython.typesystem import LowLevelTypeSystem
class FakeRTyper:
type_system = LowLevelTypeSystem.instance
class FakeJitCell(BaseJitCell):
pass
celldict = {}
def getter(x, y):
return celldict.get((x, y))
def setter(newcell, x, y):
newcell.x = x
newcell.y = y
celldict[x, y] = newcell
GETTER = lltype.Ptr(lltype.FuncType([lltype.Signed, lltype.Float],
llmemory.GCREF))
SETTER = lltype.Ptr(lltype.FuncType([llmemory.GCREF, lltype.Signed,
lltype.Float], lltype.Void))
class FakeWarmRunnerDesc:
rtyper = FakeRTyper()
cpu = None
get_jitcell_at_ptr = llhelper(GETTER, getter)
set_jitcell_at_ptr = llhelper(SETTER, setter)
#
state = WarmEnterState(FakeWarmRunnerDesc())
get_jitcell = state._make_jitcell_getter_custom(FakeJitCell)
cell1 = get_jitcell(5, 42.5)
assert isinstance(cell1, FakeJitCell)
assert cell1.x == 5
assert cell1.y == 42.5
cell2 = get_jitcell(5, 42.5)
assert cell2 is cell1
cell3 = get_jitcell(41, 42.5)
cell4 = get_jitcell(42, 0.25)
assert cell1 is not cell3 is not cell4 is not cell1