Example #1
0
def transform_stackless_function(fn, callback_for_transform=None):
    def wrapper(argv):
        return fn()
    t = rtype_stackless_function(wrapper)
    if callback_for_transform:
        callback_for_transform(t)
    if conftest.option.view:
        t.view()
    st = StacklessTransformer(t, wrapper, False)
    st.transform_all()
Example #2
0
def transform_stackless_function(fn, callback_for_transform=None):
    def wrapper(argv):
        return fn()

    t = rtype_stackless_function(wrapper)
    if callback_for_transform:
        callback_for_transform(t)
    if conftest.option.view:
        t.view()
    st = StacklessTransformer(t, wrapper, False)
    st.transform_all()
Example #3
0
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
Example #4
0
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
Example #5
0
def llinterp_stackless_function(fn, returntranslator=False, assert_unwind=True):
    def wrapper(argv):
        return fn()

    t = rtype_stackless_function(wrapper)
    st = StacklessTransformer(t, wrapper, assert_unwind=assert_unwind)
    st.transform_all()
    if conftest.option.view:
        t.view()

    graph = graphof(t, st.slp_entry_point)
    r_list_of_strings = t.rtyper.getrepr(t.annotator.binding(graph.startblock.inputargs[0]))
    ll_list = r_list_of_strings.convert_const([""])
    interp = llinterp.LLInterpreter(t.rtyper)
    res = interp.eval_graph(graph, [ll_list])
    if returntranslator:
        return res, t
    else:
        return res
Example #6
0
def llinterp_stackless_function(fn,
                                returntranslator=False,
                                assert_unwind=True):
    def wrapper(argv):
        return fn()

    t = rtype_stackless_function(wrapper)
    st = StacklessTransformer(t, wrapper, assert_unwind=assert_unwind)
    st.transform_all()
    if conftest.option.view:
        t.view()

    graph = graphof(t, st.slp_entry_point)
    r_list_of_strings = t.rtyper.getrepr(
        t.annotator.binding(graph.startblock.inputargs[0]))
    ll_list = r_list_of_strings.convert_const([''])
    interp = llinterp.LLInterpreter(t.rtyper)
    res = interp.eval_graph(graph, [ll_list])
    if returntranslator:
        return res, t
    else:
        return res
Example #7
0
    def build_database(self):
        translator = self.translator

        gcpolicyclass = self.get_gcpolicyclass()

        if self.config.translation.gcrootfinder == "asmgcc":
            if not self.standalone:
                raise NotImplementedError(
                    "--gcrootfinder=asmgcc requires standalone")

        if self.config.translation.stackless:
            if not self.standalone:
                raise Exception("stackless: only for stand-alone builds")

            from pypy.translator.stackless.transform import StacklessTransformer
            stacklesstransformer = StacklessTransformer(
                translator,
                self.originalentrypoint,
                stackless_gc=gcpolicyclass.requires_stackless)
            self.entrypoint = stacklesstransformer.slp_entry_point
        else:
            stacklesstransformer = None

        db = LowLevelDatabase(translator,
                              standalone=self.standalone,
                              gcpolicyclass=gcpolicyclass,
                              stacklesstransformer=stacklesstransformer,
                              thread_enabled=self.config.translation.thread,
                              sandbox=self.config.translation.sandbox)
        self.db = db

        # give the gc a chance to register interest in the start-up functions it
        # need (we call this for its side-effects of db.get())
        list(db.gcpolicy.gc_startup_code())

        # build entrypoint and eventually other things to expose
        pf = self.getentrypointptr()
        if isinstance(pf, list):
            for one_pf in pf:
                db.get(one_pf)
            self.c_entrypoint_name = None
        else:
            pfname = db.get(pf)
            self.c_entrypoint_name = pfname
        db.complete()

        self.collect_compilation_info(db)
        return db