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


Python TranslationContext.buildrtyper方法代码示例

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


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

示例1: test_dont_remove_with__del__

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
    def test_dont_remove_with__del__(self):
        import os
        delcalls = [0]
        class A(object):
            nextid = 0
            def __init__(self):
                self.id = self.nextid
                self.nextid += 1

            def __del__(self):
                delcalls[0] += 1
                #os.write(1, "__del__\n")

        def f(x=int):
            a = A()
            i = 0
            while i < x:
                a = A()
                os.write(1, str(delcalls[0]) + "\n")
                i += 1
            return 1
        t = TranslationContext()
        t.buildannotator().build_types(f, [int])
        t.buildrtyper().specialize()
        graph = graphof(t, f)
        backend_optimizations(t)
        op = graph.startblock.exits[0].target.exits[1].target.operations[0]
        assert op.opname == "malloc"
开发者ID:abhinavthomas,项目名称:pypy,代码行数:30,代码来源:test_malloc.py

示例2: translates

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
 def translates(self, func=None, argtypes=None, seeobj_w=[], **kwds):
     config = make_config(None, **kwds)
     if func is not None:
         if argtypes is None:
             nb_args = func.func_code.co_argcount
             argtypes = [W_Root] * nb_args
     #
     t = TranslationContext(config=config)
     self.t = t     # for debugging
     ann = t.buildannotator()
     def _do_startup():
         self.threadlocals.enter_thread(self)
     ann.build_types(_do_startup, [], complete_now=False)
     if func is not None:
         ann.build_types(func, argtypes, complete_now=False)
     if seeobj_w:
         def seeme(n):
             return seeobj_w[n]
         ann.build_types(seeme, [int], complete_now=False)
     #
     # annotate all _seen_extras, knowing that annotating some may
     # grow the list
     done = 0
     while done < len(self._seen_extras):
         #print self._seen_extras
         ann.build_types(self._seen_extras[done], [],
                         complete_now=False)
         ann.complete_pending_blocks()
         done += 1
     ann.complete()
     assert done == len(self._seen_extras)
     #t.viewcg()
     t.buildrtyper().specialize()
     t.checkgraphs()
开发者ID:mozillazg,项目名称:pypy,代码行数:36,代码来源:objspace.py

示例3: translate

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
def translate(func, argtypes, backendopt=False):
    t = TranslationContext()
    t.buildannotator().build_types(func, argtypes)
    t.buildrtyper(type_system='ootype').specialize()

    if backendopt: backend_optimizations(t, merge_if_blocks=True)
    return t
开发者ID:sota,项目名称:pypy,代码行数:9,代码来源:test_treebuilder.py

示例4: test_lookup_graphs_abstract

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
def test_lookup_graphs_abstract():
    from rpython.translator.translator import TranslationContext, graphof
    class A:
        pass
    class B(A):
        def foo(self):
            pass
    class C(A):
        def foo(self):
            pass

    def fn(flag):
        obj = flag and B() or C()
        obj.foo()
        return obj

    t = TranslationContext()
    t.buildannotator().build_types(fn, [int])
    t.buildrtyper(type_system='ootype').specialize()
    graph = graphof(t, fn)
    TYPE_A = graph.getreturnvar().concretetype
    TYPE_B = TYPE_A._subclasses[0]
    TYPE_C = TYPE_A._subclasses[1]
    assert len(TYPE_A._lookup_graphs('ofoo')) == 2
    assert len(TYPE_B._lookup_graphs('ofoo')) == 1
    assert len(TYPE_C._lookup_graphs('ofoo')) == 1
开发者ID:sota,项目名称:pypy,代码行数:28,代码来源:test_ootype.py

示例5: translate

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
 def translate(self, func, sig):
     t = TranslationContext()
     t.buildannotator().build_types(func, sig)
     t.buildrtyper().specialize()
     if option.view:
         t.view()
     return t, self.Analyzer(t)
开发者ID:Darriall,项目名称:pypy,代码行数:9,代码来源:test_writeanalyze.py

示例6: test_counters

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
    def test_counters(self):
        from rpython.rtyper.lltypesystem import lltype
        from rpython.rtyper.lltypesystem.lloperation import llop
        def entry_point(argv):
            llop.instrument_count(lltype.Void, 'test', 2)
            llop.instrument_count(lltype.Void, 'test', 1)
            llop.instrument_count(lltype.Void, 'test', 1)
            llop.instrument_count(lltype.Void, 'test', 2)
            llop.instrument_count(lltype.Void, 'test', 1)
            return 0
        t = TranslationContext(self.config)
        t.config.translation.instrument = True
        t.buildannotator().build_types(entry_point, [s_list_of_strings])
        t.buildrtyper().specialize()

        cbuilder = CStandaloneBuilder(t, entry_point, config=t.config) # xxx
        cbuilder.generate_source()
        cbuilder.compile()

        counters_fname = udir.join("_counters_")
        os.environ['PYPY_INSTRUMENT_COUNTERS'] = str(counters_fname)
        try:
            data = cbuilder.cmdexec()
        finally:
            del os.environ['PYPY_INSTRUMENT_COUNTERS']

        f = counters_fname.open('rb')
        counters_data = f.read()
        f.close()

        import struct
        counters = struct.unpack("LLL", counters_data)

        assert counters == (0,3,2)
开发者ID:bukzor,项目名称:pypy,代码行数:36,代码来源:test_standalone.py

示例7: test_remove_same_as

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
def test_remove_same_as():
    def nothing(x):
        return x

    def f():
        nothing(False)
        if nothing(True):
            return 42
        else:
            return 666

    t = TranslationContext()
    t.buildannotator().build_types(f, [])
    t.buildrtyper().specialize()
    # now we make the 'if True' appear
    f_graph = graphof(t, f)
    simple_inline_function(t, nothing, f_graph)
    # here, the graph looks like  v21=same_as(True);  exitswitch: v21
    remove_same_as(f_graph)
    t.checkgraphs()
    # only one path should be left
    for block in f_graph.iterblocks():
        assert len(block.exits) <= 1

    interp = LLInterpreter(t.rtyper)
    result = interp.eval_graph(f_graph, [])
    assert result == 42
开发者ID:cimarieta,项目名称:usp,代码行数:29,代码来源:test_removenoops.py

示例8: compile

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
    def compile(self, entry_point, debug=True, shared=False,
                stackcheck=False, entrypoints=None):
        t = TranslationContext(self.config)
        ann = t.buildannotator()
        ann.build_types(entry_point, [s_list_of_strings])
        if entrypoints is not None:
            anns = {}
            for func, annotation in secondary_entrypoints['test']:
                anns[func] = annotation
            for item in entrypoints:
                ann.build_types(item, anns[item])
        t.buildrtyper().specialize()

        if stackcheck:
            from rpython.translator.transform import insert_ll_stackcheck
            insert_ll_stackcheck(t)

        t.config.translation.shared = shared

        if entrypoints is not None:
            kwds = {'secondary_entrypoints': [(i, None) for i in entrypoints]}
        else:
            kwds = {}
        cbuilder = CStandaloneBuilder(t, entry_point, t.config, **kwds)
        if debug:
            cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
        else:
            cbuilder.generate_source()
        cbuilder.compile()
        if option is not None and option.view:
            t.view()
        return t, cbuilder
开发者ID:bukzor,项目名称:pypy,代码行数:34,代码来源:test_standalone.py

示例9: makegraph

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
def makegraph(func, argtypes):
    t = TranslationContext()
    t.buildannotator().build_types(func, [int])
    t.buildrtyper().specialize()
    bk = t.annotator.bookkeeper
    graph = bk.getdesc(func).getuniquegraph()
    return t, graph
开发者ID:abhinavthomas,项目名称:pypy,代码行数:9,代码来源:test_database.py

示例10: generate_source_for_function

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
def generate_source_for_function(func, annotation, backendopt=False):

    """
    Given a Python function and some hints about its argument types,
    generates JVM sources that call it and print the result.  Returns
    the JvmGeneratedSource object.
    """

    if hasattr(func, "im_func"):
        func = func.im_func
    t = TranslationContext()
    ann = t.buildannotator()
    ann.build_types(func, annotation)
    t.buildrtyper(type_system="ootype").specialize()
    if backendopt:
        check_virtual_methods(ootype.ROOT)
        backend_optimizations(t)
    main_graph = t.graphs[0]
    if getoption("view"):
        t.view()
    if getoption("wd"):
        tmpdir = py.path.local(".")
    else:
        tmpdir = udir
    jvm = GenJvm(tmpdir, t, EntryPoint(main_graph, True, True))
    return jvm.generate_source()
开发者ID:sota,项目名称:pypy,代码行数:28,代码来源:genjvm.py

示例11: test_remove_same_as_nonconst

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
def test_remove_same_as_nonconst():
    from rpython.rlib.nonconst import NonConstant
    from rpython.rtyper.lltypesystem.lloperation import llop
    from rpython.rtyper.lltypesystem import lltype

    def f():
        if NonConstant(False):
            x = llop.same_as(lltype.Signed, 666)
        return 42

    t = TranslationContext()
    t.buildannotator().build_types(f, [])
    t.buildrtyper().specialize()
    f_graph = graphof(t, f)
    # simple_inline_function(t, nothing, f_graph)
    # here, the graph looks like  v21=same_as(True);  exitswitch: v21
    remove_same_as(f_graph)
    t.checkgraphs()
    # only one path should be left
    for block in f_graph.iterblocks():
        assert len(block.exits) <= 1

    for block in t.annotator.annotated:
        assert None not in block.operations

    interp = LLInterpreter(t.rtyper)
    result = interp.eval_graph(f_graph, [])
    assert result == 42
开发者ID:cimarieta,项目名称:usp,代码行数:30,代码来源:test_removenoops.py

示例12: compile

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
def compile(f, gc, **kwds):
    from rpython.annotator.listdef import s_list_of_strings
    from rpython.translator.translator import TranslationContext
    from rpython.jit.metainterp.warmspot import apply_jit
    from rpython.translator.c import genc
    #
    config = get_combined_translation_config(translating=True)
    config.translation.gc = gc
    if gc != 'boehm':
        config.translation.gcremovetypeptr = True
    for name, value in kwds.items():
        setattr(config.translation, name, value)
    t = TranslationContext(config)
    ann = t.buildannotator()
    ann.build_types(f, [s_list_of_strings], main_entry_point=True)
    t.buildrtyper().specialize()

    if kwds['jit']:
        patch = get_functions_to_patch()
        old_value = {}
        try:
            for (obj, attr), value in patch.items():
                old_value[obj, attr] = getattr(obj, attr)
                setattr(obj, attr, value)
            #
            apply_jit(t)
            #
        finally:
            for (obj, attr), oldvalue in old_value.items():
                setattr(obj, attr, oldvalue)

    cbuilder = genc.CStandaloneBuilder(t, f, t.config)
    cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
    cbuilder.compile()
    return cbuilder
开发者ID:charred,项目名称:pypy,代码行数:37,代码来源:zrpy_gc_test.py

示例13: check

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
 def check(self, fn, signature, args, expected_result, expected_mallocs=0, expected_calls=0):
     t = TranslationContext()
     self.translator = t
     t.buildannotator().build_types(fn, signature)
     t.buildrtyper().specialize()
     graph = graphof(t, fn)
     if option.view:
         t.view()
     self.original_graph_count = len(t.graphs)
     # to detect broken intermediate graphs,
     # we do the loop ourselves instead of calling remove_simple_mallocs()
     maxiter = 100
     mallocv = MallocVirtualizer(t.graphs, t.rtyper, verbose=True)
     while True:
         progress = mallocv.remove_mallocs_once()
         if progress and option.view:
             t.view()
         t.checkgraphs()
         if expected_result is not DONT_CHECK_RESULT:
             interp = LLInterpreter(t.rtyper)
             if not isinstance(expected_result, CHECK_RAISES):
                 res = interp.eval_graph(graph, args)
                 assert res == expected_result
             else:
                 excinfo = py.test.raises(LLException, interp.eval_graph, graph, args)
                 assert expected_result.excname in str(excinfo.value)
         if not progress:
             break
         maxiter -= 1
         assert maxiter > 0, "infinite loop?"
     self.check_malloc_removed(graph, expected_mallocs, expected_calls)
     return graph
开发者ID:cimarieta,项目名称:usp,代码行数:34,代码来源:test_mallocv.py

示例14: test_find_loop_blocks3

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
def test_find_loop_blocks3():
    import os

    def ps(loops):
        return 42.0, 42.1

    def f(loops):
        benchtime, stones = ps(abs(loops))
        s = ""  # annotator happiness
        if loops >= 0:
            s = (
                "RPystone(%s) time for %d passes = %f" % (23, loops, benchtime)
                + "\n"
                + ("This machine benchmarks at %f pystones/second" % stones)
            )
        os.write(1, s)
        if loops == 12345:
            f(loops - 1)

    t = TranslationContext()
    t.buildannotator().build_types(f, [int])
    t.buildrtyper().specialize()
    graph = graphof(t, f)
    backedges = find_backedges(graph)
    assert backedges == []
    loop_blocks = find_loop_blocks(graph)
    assert len(loop_blocks) == 0
开发者ID:cimarieta,项目名称:usp,代码行数:29,代码来源:test_support.py

示例15: check

# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import buildrtyper [as 别名]
 def check(self, fn, signature, args, expected_result, must_be_removed=True,
           inline=None):
     remover = self.MallocRemover()
     t = TranslationContext()
     t.buildannotator().build_types(fn, signature)
     t.buildrtyper().specialize()
     graph = graphof(t, fn)
     if inline is not None:
         from rpython.translator.backendopt.inline import auto_inline_graphs
         auto_inline_graphs(t, t.graphs, inline)
     if option.view:
         t.view()
     # to detect broken intermediate graphs,
     # we do the loop ourselves instead of calling remove_simple_mallocs()
     while True:
         progress = remover.remove_mallocs_once(graph)
         simplify.transform_dead_op_vars_in_blocks(list(graph.iterblocks()),
                                                   [graph])
         if progress and option.view:
             t.view()
         if expected_result is not Ellipsis:
             interp = LLInterpreter(t.rtyper)
             res = interp.eval_graph(graph, args)
             assert res == expected_result
         if not progress:
             break
     if must_be_removed:
         self.check_malloc_removed(graph)
     return graph
开发者ID:abhinavthomas,项目名称:pypy,代码行数:31,代码来源:test_malloc.py


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