def checkmodule(modname, backend, interactive=False, basepath='pypy.module'): "Compile a fake PyPy module." from pypy.objspace.fake.objspace import FakeObjSpace, W_Object from pypy.translator.driver import TranslationDriver space = FakeObjSpace() space.config.translating = True ModuleClass = __import__(basepath + '.%s' % modname, None, None, ['Module']).Module module = ModuleClass(space, space.wrap(modname)) w_moduledict = module.getdict(space) gateways = find_gateways(modname, basepath, module) functions = [gw.__spacebind__(space) for gw in gateways] arguments = Arguments.frompacked(space, W_Object(), W_Object()) dummy_function = copy(functions[0]) def main(argv): # use the standalone mode not to allow SomeObject dummy_rpython(dummy_function) for func in functions: func.call_args(arguments) return 0 patch_pypy() driver = TranslationDriver() driver.setup(main, None) try: driver.proceed(['compile_' + backend]) except SystemExit: raise except: if not interactive: raise debug(driver) raise SystemExit(1)
def checkmodule(modname, backend, interactive=False, basepath='pypy.module'): "Compile a fake PyPy module." from pypy.objspace.fake.objspace import FakeObjSpace, W_Object from pypy.translator.driver import TranslationDriver space = FakeObjSpace() space.config.translating = True ModuleClass = __import__(basepath + '.%s' % modname, None, None, ['Module']).Module module = ModuleClass(space, space.wrap(modname)) w_moduledict = module.getdict() gateways = find_gateways(modname, basepath, module) functions = [gw.__spacebind__(space) for gw in gateways] arguments = AbstractArguments.frompacked(space, W_Object(), W_Object()) dummy_function = copy(functions[0]) def main(argv): # use the standalone mode not to allow SomeObject dummy_rpython(dummy_function) for func in functions: func.call_args(arguments) return 0 patch_pypy() driver = TranslationDriver() driver.setup(main, None) try: driver.proceed(['compile_' + backend]) except SystemExit: raise except: if not interactive: raise debug(driver) raise SystemExit(1)
def rpython2javascript(mod, function_names, jsconfig=None, use_pdb=True): if isinstance(function_names, str): function_names = [function_names] # avoid confusion if mod is None: # this means actual module, which is quite hairy to get in python, # so we cheat import sys mod = sys.modules[sys._getframe(1).f_globals['__name__']] if jsconfig is None: jsconfig = Config(js_optiondescr) if use_pdb: jsconfig.use_pdb = True module_name = mod.__name__ if not function_names and 'main' in mod.__dict__: function_names.append('main') for func_name in function_names: if func_name not in mod.__dict__: raise FunctionNotFound("function %r was not found in module %r" % (func_name, module_name)) func_code = mod.__dict__[func_name] if func_code.func_defaults: lgt = len(func_code.func_defaults) else: lgt = 0 if func_code.func_code.co_argcount > 0 and func_code.func_code. \ co_argcount != lgt: raise BadSignature("Function %s does not have default arguments" % func_name) source_ssf = get_source_ssf(mod, module_name, function_names) exec(source_ssf) in globals() # now we gonna just cut off not needed function # XXX: Really do that #options = optparse.Values(defaults=DEFAULT_OPTIONS) from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=True) driver = TranslationDriver(config=config) try: driver.setup(some_strange_function_which_will_never_be_called, [], policy = JsPolicy()) driver.proceed(["compile_js"]) if jsconfig.view: driver.translator.view() return driver.gen.tmpfile.open().read() # XXX: Add some possibility to write down selected file except Exception, e: # do something nice with it debug(driver, use_pdb)
def genllvm_compile( function, annotation, gcpolicy='boehm', # debug options debug=False, logging=False, isolate=True, # pass to compile exe_name=None, optimize=True, extra_opts={}): """ helper for genllvm """ from pypy.translator.driver import TranslationDriver from pypy.config.pypyoption import get_pypy_config config = get_pypy_config({}, translating=True) options = { 'translation.backend': 'llvm', 'translation.llvm.debug': debug, 'translation.llvm.logging': logging, 'translation.llvm.isolate': isolate, 'translation.backendopt.none': not optimize, 'translation.gc': gcpolicy, 'translation.llvm_via_c': not native_llvm_backend } options.update(extra_opts) config.set(**options) driver = TranslationDriver(config=config, exe_name=exe_name) driver.setup(function, annotation) driver.annotate() if conftest.option.view: driver.translator.view() driver.rtype() if conftest.option.view: driver.translator.view() driver.compile() if conftest.option.view: driver.translator.view() return driver
def genllvm_compile(function, annotation, gcpolicy='boehm', # debug options debug=False, logging=False, isolate=True, # pass to compile exe_name=None, optimize=True, extra_opts={}): """ helper for genllvm """ from pypy.translator.driver import TranslationDriver from pypy.config.pypyoption import get_pypy_config config = get_pypy_config({}, translating=True) options = { 'translation.backend': 'llvm', 'translation.llvm.debug': debug, 'translation.llvm.logging': logging, 'translation.llvm.isolate': isolate, 'translation.backendopt.none': not optimize, 'translation.gc': gcpolicy, 'translation.llvm_via_c' : not native_llvm_backend } options.update(extra_opts) config.set(**options) driver = TranslationDriver(config=config, exe_name=exe_name) driver.setup(function, annotation) driver.annotate() if conftest.option.view: driver.translator.view() driver.rtype() if conftest.option.view: driver.translator.view() driver.compile() if conftest.option.view: driver.translator.view() return driver
w_key = space.wrap(key) try: w1 = space.getitem(w_old, w_key) except OperationError: pass else: space.setitem(w_moddict, w_key, w1) space.call_method(w_moddict, 'update', w_moduledict) except OperationError, e: reraise(e) __init__.allow_someobjects = True driver = TranslationDriver(extmod_name=modname) driver.setup(__init__, [object], policy=CPyAnnotatorPolicy(space)) try: driver.proceed(['compile_c']) except SystemExit: raise except: if not interactive: raise debug(driver) raise SystemExit(1) return driver.cbuilder.c_ext_module def main(argv): usage = """usage: %prog [options] MODULENAME Compiles a PyPy extension module