本文整理匯總了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