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())
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())
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)
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
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
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
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
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')
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
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,))
def task_stackcheckinsertion_lltype(self): from pypy.translator.transform import insert_ll_stackcheck insert_ll_stackcheck(self.translator)