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 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 test_wrap_GetSetProperty(): see, check = make_checker() def foobar(w_obj, space): is_root(w_obj) see() return space.w_None space = FakeObjSpace() space.wrap(GetSetProperty(foobar)) space.translates() assert check
def test_wrap_interp2app(): see, check = make_checker() space = FakeObjSpace() assert len(space._seen_extras) == 1 assert len(check) == 0 space.wrap(interp2app(lambda space: see())) assert len(space._seen_extras) == 2 assert len(check) == 0 space.translates() assert len(check) == 1
def test_wrap_interp2app(): see, check = make_checker() space = FakeObjSpace() assert len(space._seen_extras) == 0 assert len(check) == 0 space.wrap(interp2app(lambda space: see())) assert len(space._seen_extras) == 1 assert len(check) == 0 space.translates() assert len(check) == 1
def test_wrap_GetSetProperty(): see, check = make_checker() def foobar(w_obj, space): is_root(w_obj) see() return space.w_None space = FakeObjSpace() space.wrap(GetSetProperty(foobar)) space.translates() assert check
def test_wrap_interp2app_int(): see, check = make_checker() def foobar(space, x, w_y, z): is_root(w_y) see() return space.wrap(x - z) space = FakeObjSpace() space.wrap(interp2app(foobar, unwrap_spec=[ObjSpace, int, W_Root, int])) space.translates() assert check
def test_wrap_interp2app_int(): see, check = make_checker() def foobar(space, x, w_y, z): is_root(w_y) see() return space.newint(x - z) space = FakeObjSpace() space.wrap(interp2app(foobar, unwrap_spec=[ObjSpace, int, W_Root, int])) space.translates() assert check
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 test_gettypefor_untranslated(): see, check = make_checker() class W_Foo(Wrappable): def do_it(self, space, w_x): is_root(w_x) see() return W_Root() W_Foo.typedef = TypeDef("foo", __module__="barmod", do_it=interp2app(W_Foo.do_it)) space = FakeObjSpace() space.gettypefor(W_Foo) assert not check space.translates() assert check
def test_wrap_interp2app_later(): see, check = make_checker() # @specialize.memo() def hithere(space): space.wrap(interp2app(foobar2)) # def foobar(space): hithere(space) def foobar2(space): see() space = FakeObjSpace() space.wrap(interp2app(foobar)) space.translates() assert check
def test_wrap_interp2app_later(): see, check = make_checker() # @specialize.memo() def hithere(space): space.wrap(interp2app(foobar2)) # def foobar(space): hithere(space) def foobar2(space): see() space = FakeObjSpace() space.wrap(interp2app(foobar)) space.translates() assert check
def test_gettypefor_untranslated(): see, check = make_checker() class W_Foo(W_Root): def do_it(self, space, w_x): is_root(w_x) see() return W_Root() W_Foo.typedef = TypeDef('foo', __module__ = 'barmod', do_it = interp2app(W_Foo.do_it)) space = FakeObjSpace() space.gettypefor(W_Foo) assert not check space.translates() assert check
def checkmodule(*modnames): config = get_pypy_config(translating=True) space = FakeObjSpace(config) seeobj_w = [] 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()) 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)) # space.translates(seeobj_w=seeobj_w, **{'translation.list_comprehension_operations': True})
def test_see_objects(): see, check = make_checker() class W_Foo(W_Root): def __init__(self, x): self.x = x def do_it(self): if self.x == 42: return see() def f(): W_Foo(42).do_it() # space = FakeObjSpace() space.translates(f) assert not check # space = FakeObjSpace() space.translates(f, seeobj_w=[W_Foo(15)]) assert check
def checkmodule(*modnames): config = get_pypy_config(translating=True) space = FakeObjSpace(config) seeobj_w = [] 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.startup(space) 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)) # space.translates(seeobj_w=seeobj_w, **{'translation.list_comprehension_operations': True})
def test_see_objects(): see, check = make_checker() class W_Foo(W_Root): def __init__(self, x): self.x = x def do_it(self): if self.x == 42: return see() def f(): W_Foo(42).do_it() # space = FakeObjSpace() space.translates(f) assert not check # space = FakeObjSpace() space.translates(f, seeobj_w=[W_Foo(15)]) assert check
def checkmodule(modname, translate_startup=True, ignore=(), c_compile=False, extra_func=None, rpython_opts=None, pypy_opts=None, show_pdbplus=False): """ Check that the module 'modname' translates. Options: translate_startup: TODO, document me ignore: list of module interpleveldefs/appleveldefs to ignore c_compile: determine whether to inokve the C compiler after rtyping extra_func: extra function which will be annotated and called. It takes a single "space" argment rpython_opts: dictionariy containing extra configuration options pypy_opts: dictionariy containing extra configuration options show_pdbplus: show Pdb+ prompt on error. Useful for pdb commands such as flowg, callg, etc. """ config = get_pypy_config(translating=True) if pypy_opts: config.set(**pypy_opts) space = FakeObjSpace(config) seeobj_w = [] modules = [] modnames = [modname] for modname in modnames: mod = __import__('pypy.module.%s.moduledef' % 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 opts = {'translation.list_comprehension_operations': True} if rpython_opts: opts.update(rpython_opts) try: space.translates(func, seeobj_w=seeobj_w, c_compile=c_compile, extra_func=extra_func, **opts) except: if not show_pdbplus: raise print exc, val, tb = sys.exc_info() traceback.print_exc() sys.pdbplus = p = PdbPlusShow(space.t) p.start(tb) else: if show_pdbplus: sys.pdbplus = p = PdbPlusShow(space.t) p.start(None)