def test_set_pypy_opt_level(): conf = get_pypy_config() set_pypy_opt_level(conf, '2') assert conf.objspace.std.withshadowtracking conf = get_pypy_config() set_pypy_opt_level(conf, '0') assert not conf.objspace.std.newshortcut
def test_set_pypy_opt_level(): conf = get_pypy_config() set_pypy_opt_level(conf, '2') assert conf.objspace.std.intshortcut conf = get_pypy_config() set_pypy_opt_level(conf, '0') assert not conf.objspace.std.intshortcut
def test_set_pypy_opt_level(): conf = get_pypy_config() set_pypy_opt_level(conf, '2') assert conf.objspace.std.withmultidict conf = get_pypy_config() set_pypy_opt_level(conf, '0') assert not conf.objspace.std.withmultidict
def test_set_pypy_opt_level(): conf = get_pypy_config() set_pypy_opt_level(conf, '2') assert conf.objspace.std.getattributeshortcut conf = get_pypy_config() set_pypy_opt_level(conf, '0') assert not conf.objspace.std.getattributeshortcut
def test_stacklessgc_required(): conf = get_pypy_config() conf.translation.gcrootfinder = "stackless" assert conf.translation.stackless assert conf.translation.type_system == "lltype" assert conf.translation.gctransformer == "framework" assert conf.translation.gc == "generation" conf = get_pypy_config() conf.translation.gc = "boehm" py.test.raises(ValueError, "conf.translation.gcrootfinder = 'stackless'")
def test_required(): conf = get_pypy_config() assert not conf.translating assert conf.objspace.usemodules.gc conf.objspace.std.withmapdict = True assert conf.objspace.std.withmethodcache conf = get_pypy_config() conf.objspace.std.withmethodcache = False py.test.raises(ConfigError, "conf.objspace.std.withmapdict = True")
def test_required(): conf = get_pypy_config() assert not conf.translating assert conf.objspace.usemodules.gc conf.objspace.std.withsmallint = True assert not conf.objspace.std.withprebuiltint conf = get_pypy_config() conf.objspace.std.withprebuiltint = True py.test.raises(ValueError, "conf.objspace.std.withsmallint = True")
def test_required(): conf = get_pypy_config() assert not conf.translating assert conf.objspace.usemodules.gc conf.objspace.std.withmapdict = True assert conf.objspace.std.withtypeversion conf = get_pypy_config() conf.objspace.std.withtypeversion = False py.test.raises(ConfigError, "conf.objspace.std.withmapdict = True")
def test_set_opt_level(): conf = get_pypy_config() set_opt_level(conf, '0') assert conf.translation.gc == 'boehm' assert conf.translation.backendopt.none == True conf = get_pypy_config() set_opt_level(conf, '2') assert conf.translation.gc != 'boehm' assert not conf.translation.backendopt.none conf = get_pypy_config() set_opt_level(conf, 'mem') assert conf.translation.gcremovetypeptr assert not conf.translation.backendopt.none
def test_set_opt_level(): conf = get_pypy_config() set_opt_level(conf, '0') assert conf.translation.gc == 'boehm' assert conf.translation.backendopt.none == True conf = get_pypy_config() set_opt_level(conf, '2') assert conf.translation.gc != 'boehm' assert not conf.translation.backendopt.none conf = get_pypy_config() set_opt_level(conf, 'mem') assert conf.translation.gc == 'markcompact' assert not conf.translation.backendopt.none
def test_rweakref_required(): conf = get_pypy_config() conf.translation.rweakref = False set_pypy_opt_level(conf, '3') assert not conf.objspace.std.withtypeversion assert not conf.objspace.std.withmethodcache
def checkmodule(*modnames, **kwds): translate_startup = kwds.pop('translate_startup', True) ignore = set(kwds.pop('ignore', ())) assert not kwds config = get_pypy_config(translating=True) space = FakeObjSpace(config) seeobj_w = [] modules = [] for modname in modnames: mod = __import__('pypy.module.%s' % modname, None, None, ['__doc__']) # force computation and record what we wrap module = mod.Module(space, W_Root()) module.setup_after_space_initialization() module.init(space) modules.append(module) for name in module.loaders: if name in ignore: continue seeobj_w.append(module._load_lazily(space, name)) if hasattr(module, 'submodules'): for cls in module.submodules.itervalues(): submod = cls(space, W_Root()) for name in submod.loaders: seeobj_w.append(submod._load_lazily(space, name)) # def func(): for mod in modules: mod.startup(space) if not translate_startup: func() # call it now func = None space.translates(func, seeobj_w=seeobj_w, **{'translation.list_comprehension_operations': True})
def getcompiled(self, func, argstypelist=[], annotatorpolicy=None): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = self.gcpolicy config.translation.thread = self.use_threads config.translation.simplifying = True t = TranslationContext(config=config) self.t = t a = t.buildannotator(policy=annotatorpolicy) a.build_types(func, argstypelist) t.buildrtyper().specialize() t.checkgraphs() def compile(): cbuilder = CExtModuleBuilder(t, func, config=config) c_source_filename = cbuilder.generate_source( defines=cbuilder.DEBUG_DEFINES) if conftest.option.view: t.view() cbuilder.compile() self._cleanups.append( cbuilder.cleanup) # schedule cleanup after test return cbuilder.get_entry_point(isolated=True) return compile()
def __init__(self, config=None): "NOT_RPYTHON: Basic initialization of objects." self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config # import extra modules for side-effects import pypy.interpreter.nestedscope # register *_DEREF bytecodes self.interned_strings = {} self.actionflag = ActionFlag() # changed by the signal module self.user_del_action = UserDelAction(self) self.frame_trace_action = FrameTraceAction(self) self.actionflag.register_action(self.user_del_action) self.actionflag.register_action(self.frame_trace_action) from pypy.interpreter.pyframe import PyFrame self.FrameClass = PyFrame # can be overridden to a subclass # if self.config.objspace.logbytecodes: # self.bytecodecounts = {} self.initialize()
def __init__(self, config=None): "NOT_RPYTHON: Basic initialization of objects." self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config # import extra modules for side-effects import pypy.interpreter.nestedscope # register *_DEREF bytecodes self.interned_strings = {} self.actionflag = ActionFlag() # changed by the signal module self.user_del_action = UserDelAction(self) self.frame_trace_action = FrameTraceAction(self) self.actionflag.register_action(self.user_del_action) self.actionflag.register_action(self.frame_trace_action) from pypy.interpreter.pyframe import PyFrame self.FrameClass = PyFrame # can be overridden to a subclass if self.config.objspace.logbytecodes: self.bytecodecounts = [0] * 256 self.bytecodetransitioncount = {} if self.config.objspace.timing: self.timer = Timer() else: self.timer = DummyTimer() self.initialize()
def make_config(cls): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = cls.gcpolicy config.translation.gcrootfinder = "asmgcc" config.translation.taggedpointers = getattr(cls, "taggedpointers", False) return config
def setup_class(cls): from pypy.translator.platform.maemo import check_scratchbox check_scratchbox() from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.platform = 'maemo' cls.config = config
def checkmodule(*modnames, **kwds): translate_startup = kwds.pop('translate_startup', True) assert not kwds config = get_pypy_config(translating=True) space = FakeObjSpace(config) seeobj_w = [] modules = [] for modname in modnames: mod = __import__('pypy.module.%s' % modname, None, None, ['__doc__']) # force computation and record what we wrap module = mod.Module(space, W_Root()) module.setup_after_space_initialization() module.init(space) modules.append(module) for name in module.loaders: seeobj_w.append(module._load_lazily(space, name)) if hasattr(module, 'submodules'): for cls in module.submodules.itervalues(): submod = cls(space, W_Root()) for name in submod.loaders: seeobj_w.append(submod._load_lazily(space, name)) # def func(): for mod in modules: mod.startup(space) if not translate_startup: func() # call it now func = None space.translates(func, seeobj_w=seeobj_w, **{'translation.list_comprehension_operations': True})
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 __init__(self, cpu): self.cpu = cpu self.profiler = EmptyProfiler() self.options = Fake() self.globaldata = Fake() self.config = get_pypy_config(translating=True) self.config.translation.jit_ffi = True
def config_role(name, rawtext, text, lineno, inliner, options={}, content=[]): from docutils import nodes from pypy.config.pypyoption import get_pypy_config from pypy.config.makerestdoc import get_cmdline txt = docdir.join("config", text + ".rst") html = docdir.join("config", text + ".html") assert txt.check() assert name == "config" sourcedir = py.path.local(inliner.document.settings._source).dirpath() curr = sourcedir prefix = "" while 1: relative = str(html.relto(curr)) if relative: break curr = curr.dirpath() prefix += "../" config = get_pypy_config() # begin horror h, n = config._cfgimpl_get_home_by_path(text) opt = getattr(h._cfgimpl_descr, n) # end horror cmdline = get_cmdline(opt.cmdline, text) if cmdline is not None: shortest_long_option = 'X'*1000 for cmd in cmdline.split(): if cmd.startswith('--') and len(cmd) < len(shortest_long_option): shortest_long_option = cmd text = shortest_long_option target = prefix + relative reference_node = nodes.reference(rawtext, text, name=text, refuri=target) return [reference_node], []
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, argstypelist = [], annotatorpolicy=None): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = self.gcpolicy config.translation.thread = self.use_threads if self.stacklessgc: config.translation.gcrootfinder = "stackless" config.translation.simplifying = True t = TranslationContext(config=config) self.t = t a = t.buildannotator(policy=annotatorpolicy) a.build_types(func, argstypelist) t.buildrtyper().specialize() t.checkgraphs() def compile(): cbuilder = CExtModuleBuilder(t, func, config=config) c_source_filename = cbuilder.generate_source( defines = cbuilder.DEBUG_DEFINES) if conftest.option.view: t.view() cbuilder.compile() self._cleanups.append(cbuilder.cleanup) # schedule cleanup after test return cbuilder.get_entry_point(isolated=True) return compile()
def config_role(name, rawtext, text, lineno, inliner, options={}, content=[]): from docutils import nodes from pypy.config.pypyoption import get_pypy_config from pypy.config.makerestdoc import get_cmdline txt = docdir.join("config", text + ".rst") html = docdir.join("config", text + ".html") assert txt.check() assert name == "config" sourcedir = py.path.local(inliner.document.settings._source).dirpath() curr = sourcedir prefix = "" while 1: relative = str(html.relto(curr)) if relative: break curr = curr.dirpath() prefix += "../" config = get_pypy_config() # begin horror h, n = config._cfgimpl_get_home_by_path(text) opt = getattr(h._cfgimpl_descr, n) # end horror cmdline = get_cmdline(opt.cmdline, text) if cmdline is not None: shortest_long_option = "X" * 1000 for cmd in cmdline.split(): if cmd.startswith("--") and len(cmd) < len(shortest_long_option): shortest_long_option = cmd text = shortest_long_option target = prefix + relative reference_node = nodes.reference(rawtext, text, name=text, refuri=target) return [reference_node], []
def compile_func(fn, inputtypes, t=None, gcpolicy="ref"): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = gcpolicy config.translation.countmallocs = True if t is None: t = TranslationContext(config=config) if inputtypes is not None: t.buildannotator().build_types(fn, inputtypes) t.buildrtyper().specialize() builder = genc.CExtModuleBuilder(t, fn, config=config) builder.generate_source() builder.compile() if conftest.option.view: t.view() compiled_fn = builder.get_entry_point() malloc_counters = builder.get_malloc_counters() def checking_fn(*args, **kwds): try: return compiled_fn(*args, **kwds) finally: mallocs, frees = malloc_counters() assert mallocs == frees return checking_fn
def __init__(self, tmpdir, translator, entrypoint, config=None, exctrans=False): self.tmpdir = tmpdir self.translator = translator self.entrypoint = entrypoint self.db = self.Database(self) if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) self.config = config # XXX: move this option out of the 'cli' section exctrans = exctrans or translator.config.translation.cli.exception_transformer if exctrans: self.db.exceptiontransformer = translator.getexceptiontransformer() self.append_prebuilt_nodes() if exctrans: etrafo = self.db.exceptiontransformer for graph in translator.graphs: etrafo.create_exception_handling(graph) if translator.config.translation.backendopt.stack_optimization: self.stack_optimization()
def setup_class(cls): py.test.skip("TestMaemo: tests skipped for now") from pypy.translator.platform.maemo import check_scratchbox check_scratchbox() from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.platform = 'maemo' cls.config = config
def setup_class(cls): init_extmodule_code() conf = get_pypy_config() conf.objspace.extmodules = 'testext.extmod' old_sys_path[:] = sys.path[:] sys.path.insert(0, str(udir)) space = StdObjSpace(conf) cls.space = space
def test_rweakref_required(): conf = get_pypy_config() conf.translation.rweakref = False conf.objspace.std.allopts = True assert not conf.objspace.std.withtypeversion assert not conf.objspace.std.withmethodcache assert not conf.objspace.std.withshadowtracking
def __init__(self, tmpdir, translator, entrypoint, config=None): self.tmpdir = tmpdir self.translator = translator self.entrypoint = entrypoint self.db = self.Database(self) if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) self.config = config
def make_config(cmdlineopt, **kwds): """ make a config from cmdline options (which overrides everything) and kwds """ config = get_pypy_config(translating=False) for modname in kwds.pop("usemodules", []): setattr(config.objspace.usemodules, modname, True) config.set(**kwds) return config
def get_standard_options(): config = get_pypy_config() parser = to_optparse(config, useoptions=["objspace.*"], extra_useage=extra_useage) parser.add_option( '-H', action="callback", callback=run_tb_server, help="use web browser for traceback info") return config, parser
def new_pypy_objspace(): # This module is reloaded, but pypy_getudir has already been deleted from pypy.module import sys as pypy_sys reload(pypy_sys) # if 'pypy_getudir' not in Module.interpleveldefs: # Module.interpleveldefs['pypy_getudir'] = 'foo' from pypy.config.pypyoption import get_pypy_config, set_pypy_opt_level translating = sys.argv[0] == '.build/build.py' # make better pypy_config = get_pypy_config(translating=translating) # disable dispensable modules (to save compile time) pypy_config.objspace.usemodules.micronumpy = False pypy_config.objspace.usemodules._cppyy = False pypy_config.objspace.usemodules._vmprof = False # cpyext causes a lot of 'Undefined symbols for architecture x86_64' errors pypy_config.objspace.usemodules.cpyext = False # disabling cffi backend for now, it also causes an undefined symbol error pypy_config.objspace.usemodules._cffi_backend = False # disable to save compile time from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(pypy_config) from pypy.config.pypyoption import enable_translationmodules enable_translationmodules(pypy_config) # pypy_config.translation.check_str_without_nul = True # ensures pypy_hooks has a .space pypy_config.objspace.usemodules.pypyjit = True # rstacklets are required pypy_config.translation.continuation = True pypy_config.objspace.usemodules._continuation = True pypy_config.objspace.usemodules.thread = True # Enable more optimizations for PyPy's jit set_pypy_opt_level(pypy_config, 'jit') # Copy over some options that should be the same in both configs pypy_config.translation.make_jobs = system.translationconfig.make_jobs if system.translationconfig.output is not None: pypy_config.translation.output = system.translationconfig.output # merge_configs(config, pypy_config, 'RSqueak', 'PyPy') # PyPy needs threads pypy_config.translation.thread = True # Python objectspace ctor is not Rpython so create it here and # encapsulate it inside the entry point with a closure. from pypy.objspace.std import StdObjSpace as PyStdObjSpace return PyStdObjSpace(pypy_config)
def checkmodule(modname): config = get_pypy_config(translating=True) space = FakeObjSpace(config) mod = __import__('pypy.module.%s' % modname, None, None, ['__doc__']) # force computation and record what we wrap module = mod.Module(space, W_Root()) for name in module.loaders: module._load_lazily(space, name) # space.translates(**{'translation.list_comprehension_operations':True})
def make_config(cls): if _MSVC and _WIN64: py.test.skip("all asmgcroot tests disabled for MSVC X64") from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = cls.gcpolicy config.translation.gcrootfinder = "asmgcc" config.translation.taggedpointers = getattr(cls, "taggedpointers", False) return config
def _makefunc_str_int(cls, func): def main(argv): arg0 = argv[1] arg1 = int(argv[2]) try: res = func(arg0, arg1) except MemoryError: print 'Result: MemoryError' else: print 'Result: "%s"' % (res,) return 0 from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = cls.gcpolicy config.translation.gcrootfinder = "asmgcc" if sys.platform == 'win32': config.translation.cc = 'mingw32' t = TranslationContext(config=config) a = t.buildannotator() a.build_types(main, [s_list_of_strings]) t.buildrtyper().specialize() t.checkgraphs() cbuilder = CStandaloneBuilder(t, main, config=config) c_source_filename = cbuilder.generate_source( defines = cbuilder.DEBUG_DEFINES) cls._patch_makefile(cbuilder.targetdir) if conftest.option.view: t.view() exe_name = cbuilder.compile() def run(arg0, arg1): lines = [] print >> sys.stderr, 'RUN: starting', exe_name if sys.platform == 'win32': redirect = ' 2> NUL' else: redirect = '' g = os.popen('"%s" %s %d%s' % (exe_name, arg0, arg1, redirect), 'r') for line in g: print >> sys.stderr, 'RUN:', line.rstrip() lines.append(line) g.close() if not lines: py.test.fail("no output from subprocess") if not lines[-1].startswith('Result:'): py.test.fail("unexpected output from subprocess") result = lines[-1][len('Result:'):].strip() if result == 'MemoryError': raise MemoryError("subprocess got an RPython MemoryError") if result.startswith('"') and result.endswith('"'): return result[1:-1] else: return int(result) return run
def setup_method(self, meth): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True).translation self.stackroots = [] self.gc = self.GCClass(config, **self.GC_PARAMS) self.gc.DEBUG = True self.rootwalker = DirectRootWalker(self) self.gc.set_root_walker(self.rootwalker) self.layoutbuilder = TypeLayoutBuilder(self.GCClass, {}) self.get_type_id = self.layoutbuilder.get_type_id self.layoutbuilder.initialize_gc_query_function(self.gc) self.gc.setup()
def setup_method(self, meth): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True).translation self.stackroots = [] self.gc = self.GCClass(config, **self.GC_PARAMS) self.gc.DEBUG = True self.rootwalker = DirectRootWalker(self) self.gc.set_root_walker(self.rootwalker) self.layoutbuilder = TypeLayoutBuilder() self.get_type_id = self.layoutbuilder.get_type_id self.layoutbuilder.initialize_gc_query_function(self.gc) self.gc.setup()
class FakeMetaInterpStaticData(object): logger_noopt = FakeLogger() logger_ops = FakeLogger() config = get_pypy_config(translating=True) stats = Stats() profiler = jitprof.EmptyProfiler() warmrunnerdesc = None def log(self, msg, event_kind=None): pass
def annotatefunc(self, func, argtypes=None): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = "ref" config.translation.simplifying = True t = TranslationContext(config=config) if argtypes is None: argtypes = [] a = t.buildannotator() a.build_types(func, argtypes) a.simplify() return t
def setup_class(cls): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = cls.gc if cls.gcrootfinder is not None: config.translation.continuation = True config.translation.gcrootfinder = cls.gcrootfinder GCROOTFINDER = cls.gcrootfinder cls.config = config cls.old_values = Runner.config, Runner.STATUSMAX Runner.config = config Runner.STATUSMAX = 25000
def getcompiled(self, func): def main(argv): try: res = func() except MemoryError: print 'Result: MemoryError' else: if isinstance(res, int): print 'Result:', res else: print 'Result: "%s"' % (res,) return 0 from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = self.gcpolicy config.translation.gcrootfinder = "asmgcc" t = TranslationContext(config=config) self.t = t a = t.buildannotator() a.build_types(main, [s_list_of_strings]) t.buildrtyper().specialize() t.checkgraphs() cbuilder = CStandaloneBuilder(t, main, config=config) c_source_filename = cbuilder.generate_source( defines = cbuilder.DEBUG_DEFINES) self.patch_makefile(cbuilder.targetdir) if conftest.option.view: t.view() exe_name = cbuilder.compile() def run(): lines = [] print >> sys.stderr, 'RUN: starting', exe_name g = os.popen("'%s'" % (exe_name,), 'r') for line in g: print >> sys.stderr, 'RUN:', line.rstrip() lines.append(line) g.close() if not lines: py.test.fail("no output from subprocess") if not lines[-1].startswith('Result:'): py.test.fail("unexpected output from subprocess") result = lines[-1][len('Result:'):].strip() if result == 'MemoryError': raise MemoryError("subprocess got an RPython MemoryError") if result.startswith('"') and result.endswith('"'): return result[1:-1] else: return int(result) return run
def setup_class(cls): from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) config.translation.gc = cls.gc if cls.gcrootfinder is not None: config.translation.continuation = True config.translation.gcrootfinder = cls.gcrootfinder GCROOTFINDER = cls.gcrootfinder cls.config = config cls.old_values = Runner.config, Runner.STATUSMAX Runner.config = config Runner.STATUSMAX = 25000 if cls.gcrootfinder == "asmgcc" and sys.platform == "win32": py.test.skip("fails with asmgcc on win32")