当前位置: 首页>>代码示例>>Python>>正文


Python TranslationContext.getexceptiontransformer方法代码示例

本文整理汇总了Python中pypy.translator.translator.TranslationContext.getexceptiontransformer方法的典型用法代码示例。如果您正苦于以下问题:Python TranslationContext.getexceptiontransformer方法的具体用法?Python TranslationContext.getexceptiontransformer怎么用?Python TranslationContext.getexceptiontransformer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pypy.translator.translator.TranslationContext的用法示例。


在下文中一共展示了TranslationContext.getexceptiontransformer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_stackless

# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import getexceptiontransformer [as 别名]
def test_stackless():
    t = TranslationContext()
    a = t.buildannotator()
    a.build_types(g, [int])
    a.simplify()
    t.buildrtyper().specialize()        
    backend_optimizations(t)
    t.checkgraphs()
    n = insert_ll_stackcheck(t)
    t.checkgraphs()
    assert n == 1

    t.config.translation.stackless = True
    stacklesstransf = StacklessTransformer(t, g)
        
    f_graph = graphof(t, f)
    stacklesstransf.transform_graph(f_graph)
    if conftest.option.view:
        f_graph.show()

    exctransf = t.getexceptiontransformer()
    exctransf.create_exception_handling(f_graph)
    if conftest.option.view:
        f_graph.show()
    check(f_graph, 'f', 'fetch_retval_void')    

    class GCTransform(framework.FrameworkGCTransformer):
        from pypy.rpython.memory.gc.generation import GenerationGC as \
                                                          GCClass
        GC_PARAMS = {}

    gctransf = GCTransform(t)
    gctransf.transform_graph(f_graph)
    if conftest.option.view:
        f_graph.show()
    relevant = check(f_graph, 'f', 'fetch_retval_void')
    for p in relevant:
        in_between = False
        reload = 0
        for spaceop in p:
            if spaceop.opname == 'direct_call':
                target = direct_target(spaceop)
                if target == 'f':
                    in_between = False
                elif target == 'stack_check___':
                    in_between = True
            if in_between and spaceop.opname == 'gc_reload_possibly_moved':
                reload += 1
                
        assert reload == 1
开发者ID:alkorzt,项目名称:pypy,代码行数:52,代码来源:test_stackcheck.py

示例2: test_secondary_backendopt

# 需要导入模块: from pypy.translator.translator import TranslationContext [as 别名]
# 或者: from pypy.translator.translator.TranslationContext import getexceptiontransformer [as 别名]
    def test_secondary_backendopt(self):
        # checks an issue with a newly added graph that calls an
        # already-exception-transformed graph.  This can occur e.g.
        # from a late-seen destructor added by the GC transformer
        # which ends up calling existing code.
        def common(n):
            if n > 5:
                raise ValueError

        def main(n):
            common(n)

        def later(n):
            try:
                common(n)
                return 0
            except ValueError:
                return 1

        t = TranslationContext()
        t.buildannotator().build_types(main, [int])
        t.buildrtyper(type_system="lltype").specialize()
        exctransformer = t.getexceptiontransformer()
        exctransformer.create_exception_handling(graphof(t, common))
        from pypy.annotation import model as annmodel
        from pypy.rpython.annlowlevel import MixLevelHelperAnnotator

        annhelper = MixLevelHelperAnnotator(t.rtyper)
        later_graph = annhelper.getgraph(later, [annmodel.SomeInteger()], annmodel.SomeInteger())
        annhelper.finish()
        annhelper.backend_optimize()
        # ^^^ as the inliner can't handle exception-transformed graphs,
        # this should *not* inline common() into later().
        if conftest.option.view:
            later_graph.show()
        common_graph = graphof(t, common)
        found = False
        for block in later_graph.iterblocks():
            for op in block.operations:
                if op.opname == "direct_call" and op.args[0].value._obj.graph is common_graph:
                    found = True
        assert found, "cannot find the call (buggily inlined?)"
        from pypy.rpython.llinterp import LLInterpreter

        llinterp = LLInterpreter(t.rtyper)
        res = llinterp.eval_graph(later_graph, [10])
        assert res == 1
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:49,代码来源:test_all.py


注:本文中的pypy.translator.translator.TranslationContext.getexceptiontransformer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。