Beispiel #1
0
    def wrap_stackless_function(self, fn):
        def entry_point(argv):
            os.write(1, str(fn())+"\n")
            return 0

        from pypy.config.pypyoption import get_pypy_config
        config = get_pypy_config(translating=True)
        config.translation.gc = self.gcpolicy
        config.translation.stackless = True
        if self.stacklessgc:
            config.translation.gcrootfinder = "stackless"
        t = TranslationContext(config=config)
        self.t = t
        t.buildannotator().build_types(entry_point, [s_list_of_strings])
        t.buildrtyper().specialize()
        if self.backendopt:
            backend_optimizations(t)

        from pypy.translator.transform import insert_ll_stackcheck
        insert_ll_stackcheck(t)

        cbuilder = CStandaloneBuilder(t, entry_point, config=config)
        cbuilder.stackless = True
        cbuilder.generate_source()
        cbuilder.compile()
        res = cbuilder.cmdexec('')
        return int(res.strip())
Beispiel #2
0
    def wrap_stackless_function(self, fn):
        def entry_point(argv):
            os.write(1, str(fn()) + "\n")
            return 0

        from pypy.config.pypyoption import get_pypy_config
        config = get_pypy_config(translating=True)
        config.translation.gc = self.gcpolicy
        config.translation.stackless = True
        if self.stacklessgc:
            config.translation.gcrootfinder = "stackless"
        t = TranslationContext(config=config)
        self.t = t
        t.buildannotator().build_types(entry_point, [s_list_of_strings])
        t.buildrtyper().specialize()
        if self.backendopt:
            backend_optimizations(t)

        from pypy.translator.transform import insert_ll_stackcheck
        insert_ll_stackcheck(t)

        cbuilder = CStandaloneBuilder(t, entry_point, config=config)
        cbuilder.stackless = True
        cbuilder.generate_source()
        cbuilder.compile()
        res = cbuilder.cmdexec('')
        return int(res.strip())
Beispiel #3
0
 def getcompiled(self, func, argtypes=None, view=False):
     from pypy.translator.transform import insert_ll_stackcheck
     t = self.annotatefunc(func, argtypes)
     self.process(t)
     if view or conftest.option.view:
         t.view()
     t.checkgraphs()
     insert_ll_stackcheck(t)
     return self.compilefunc(t, func)
Beispiel #4
0
 def getcompiled(self, func, argtypes=None, view=False):
     from pypy.translator.transform import insert_ll_stackcheck
     t = self.annotatefunc(func, argtypes)
     self.process(t)
     if view or conftest.option.view:
         t.view()
     t.checkgraphs()
     insert_ll_stackcheck(t)
     return self.compilefunc(t, func)
Beispiel #5
0
    def test_writes_recursive(self):
        from pypy.translator.transform import insert_ll_stackcheck
        def g(x):
            return f(x)

        def f(x):
            if x:
                return g(x - 1)
            return 1
        t, wa = self.translate(f, [int])
        insert_ll_stackcheck(t)
        ggraph = graphof(t, g)
        result = wa.analyze(ggraph.startblock.operations[-1])
        assert not result
Beispiel #6
0
    def test_writes_recursive(self):
        from pypy.translator.transform import insert_ll_stackcheck
        def g(x):
            return f(x)

        def f(x):
            if x:
                return g(x - 1)
            return 1
        t, wa = self.translate(f, [int])
        insert_ll_stackcheck(t)
        ggraph = graphof(t, g)
        result = wa.analyze(ggraph.startblock.operations[-1])
        assert not result
Beispiel #7
0
    def test_can_raise_recursive(self):
        from pypy.translator.transform import insert_ll_stackcheck
        def g(x):
            return f(x)

        def f(x):
            if x:
                return g(x - 1)
            return 1
        t, ra = self.translate(f, [int])
        insert_ll_stackcheck(t)
        ggraph = graphof(t, g)
        result = ra.can_raise(ggraph.startblock.operations[-1])
        assert result # due to stack check every recursive function can raise
Beispiel #8
0
def rtype_stackless_function(fn):
    t = TranslationContext()
    t.config.translation.stackless = True
    annotator = t.buildannotator()
    annotator.policy.allow_someobjects = False

    s_returnvar = annotator.build_types(fn, [s_list_of_strings])
    if not isinstance(s_returnvar, annmodel.SomeInteger):
        raise Exception, "this probably isn't going to work"
    t.buildrtyper().specialize()

    from pypy.translator.transform import insert_ll_stackcheck
    insert_ll_stackcheck(t)

    #    if conftest.option.view:
    #        t.view()
    return t
Beispiel #9
0
def rtype_stackless_function(fn):
    t = TranslationContext()
    t.config.translation.stackless = True
    annotator = t.buildannotator()
    annotator.policy.allow_someobjects = False

    s_returnvar = annotator.build_types(fn, [s_list_of_strings])
    if not isinstance(s_returnvar, annmodel.SomeInteger):
        raise Exception, "this probably isn't going to work"
    t.buildrtyper().specialize()

    from pypy.translator.transform import insert_ll_stackcheck

    insert_ll_stackcheck(t)

    #    if conftest.option.view:
    #        t.view()
    return t
Beispiel #10
0
    def compile(self, entry_point, debug=True, shared=False,
                stackcheck=False):
        t = TranslationContext(self.config)
        t.buildannotator().build_types(entry_point, [s_list_of_strings])
        t.buildrtyper().specialize()

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

        t.config.translation.shared = shared

        cbuilder = CStandaloneBuilder(t, entry_point, t.config)
        if debug:
            cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
        else:
            cbuilder.generate_source()
        cbuilder.compile()
        if option.view:
            t.view()
        return t, cbuilder
Beispiel #11
0
    def compile(self, entry_point, debug=True, shared=False,
                stackcheck=False):
        t = TranslationContext(self.config)
        t.buildannotator().build_types(entry_point, [s_list_of_strings])
        t.buildrtyper().specialize()

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

        t.config.translation.shared = shared

        cbuilder = CStandaloneBuilder(t, entry_point, t.config)
        if debug:
            cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
        else:
            cbuilder.generate_source()
        cbuilder.compile()
        if option.view:
            t.view()
        return t, cbuilder
Beispiel #12
0
def test_simple():
    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
    if conftest.option.view:
        t.view()
    check(graphof(t, f), 'f')
Beispiel #13
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
Beispiel #14
0
def test_simple():
    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
    if conftest.option.view:
        t.view()
    check(graphof(t, f), 'f')
Beispiel #15
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
Beispiel #16
0
 def task_stackcheckinsertion_lltype(self):
     from pypy.translator.transform import insert_ll_stackcheck
     count = insert_ll_stackcheck(self.translator)
     self.log.info("inserted %d stack checks." % (count,))
Beispiel #17
0
 def task_stackcheckinsertion_lltype(self):
     from pypy.translator.transform import insert_ll_stackcheck
     insert_ll_stackcheck(self.translator)
Beispiel #18
0
 def task_stackcheckinsertion_lltype(self):
     from pypy.translator.transform import insert_ll_stackcheck
     count = insert_ll_stackcheck(self.translator)
     self.log.info("inserted %d stack checks." % (count,))