本文整理匯總了Python中rpython.rtyper.annlowlevel.MixLevelHelperAnnotator.constfunc方法的典型用法代碼示例。如果您正苦於以下問題:Python MixLevelHelperAnnotator.constfunc方法的具體用法?Python MixLevelHelperAnnotator.constfunc怎麽用?Python MixLevelHelperAnnotator.constfunc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rpython.rtyper.annlowlevel.MixLevelHelperAnnotator
的用法示例。
在下文中一共展示了MixLevelHelperAnnotator.constfunc方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: call_final_function
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import constfunc [as 別名]
def call_final_function(translator, final_func, annhelper=None):
"""When the program finishes normally, call 'final_func()'."""
from rpython.annotator import model as annmodel
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
own_annhelper = (annhelper is None)
if own_annhelper:
annhelper = MixLevelHelperAnnotator(translator.rtyper)
c_final_func = annhelper.constfunc(final_func, [], annmodel.s_None)
if own_annhelper:
annhelper.finish()
entry_point = translator.entry_point_graph
v = copyvar(translator.annotator, entry_point.getreturnvar())
extrablock = Block([v])
v_none = varoftype(lltype.Void)
newop = SpaceOperation('direct_call', [c_final_func], v_none)
extrablock.operations = [newop]
extrablock.closeblock(Link([v], entry_point.returnblock))
for block in entry_point.iterblocks():
if block is not extrablock:
for link in block.exits:
if link.target is entry_point.returnblock:
link.target = extrablock
checkgraph(entry_point)
示例2: builtin_func_for_spec
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import constfunc [as 別名]
def builtin_func_for_spec(rtyper, oopspec_name, ll_args, ll_res,
extra=None, extrakey=None):
assert (extra is None) == (extrakey is None)
key = (oopspec_name, tuple(ll_args), ll_res, extrakey)
try:
return rtyper._builtin_func_for_spec_cache[key]
except (KeyError, AttributeError):
pass
args_s = [lltype_to_annotation(v) for v in ll_args]
if '.' not in oopspec_name: # 'newxxx' operations
LIST_OR_DICT = ll_res
else:
LIST_OR_DICT = ll_args[0]
s_result = lltype_to_annotation(ll_res)
impl = setup_extra_builtin(rtyper, oopspec_name, len(args_s), extra)
if getattr(impl, 'need_result_type', False):
bk = rtyper.annotator.bookkeeper
args_s.insert(0, annmodel.SomePBC([bk.getdesc(deref(ll_res))]))
#
if hasattr(rtyper, 'annotator'): # regular case
mixlevelann = MixLevelHelperAnnotator(rtyper)
c_func = mixlevelann.constfunc(impl, args_s, s_result)
mixlevelann.finish()
else:
# for testing only
c_func = Constant(oopspec_name,
lltype.Ptr(lltype.FuncType(ll_args, ll_res)))
#
if not hasattr(rtyper, '_builtin_func_for_spec_cache'):
rtyper._builtin_func_for_spec_cache = {}
rtyper._builtin_func_for_spec_cache[key] = (c_func, LIST_OR_DICT)
#
return c_func, LIST_OR_DICT
示例3: test_delayed_fnptr
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import constfunc [as 別名]
def test_delayed_fnptr():
from rpython.flowspace.model import SpaceOperation
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
from rpython.translator.translator import TranslationContext
t = TranslationContext()
t.buildannotator()
t.buildrtyper()
annhelper = MixLevelHelperAnnotator(t.rtyper)
def f():
pass
c_f = annhelper.constfunc(f, [], None)
op = SpaceOperation('direct_call', [c_f], None)
analyzer = BoolGraphAnalyzer(t)
assert analyzer.analyze(op)
示例4: call_initial_function
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import constfunc [as 別名]
def call_initial_function(translator, initial_func, annhelper=None):
"""Before the program starts, call 'initial_func()'."""
from rpython.annotator import model as annmodel
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
own_annhelper = (annhelper is None)
if own_annhelper:
annhelper = MixLevelHelperAnnotator(translator.rtyper)
c_initial_func = annhelper.constfunc(initial_func, [], annmodel.s_None)
if own_annhelper:
annhelper.finish()
entry_point = translator.entry_point_graph
args = [copyvar(translator.annotator, v) for v in entry_point.getargs()]
extrablock = Block(args)
v_none = varoftype(lltype.Void)
newop = SpaceOperation('direct_call', [c_initial_func], v_none)
extrablock.operations = [newop]
extrablock.closeblock(Link(args, entry_point.startblock))
entry_point.startblock = extrablock
checkgraph(entry_point)