def main(argv): config = get_combined_translation_config(pypy_optiondescription, overrides=OVERRIDES, translating=True) config.objspace.nofaking = True config.objspace.compiler = "ast" config.translating = True set_opt_level(config, '1') set_pypy_opt_level(config, '1') enable_allworkingmodules(config) space = make_objspace(config) ctx = JavaScriptContext(space) policy = PyPyAnnotatorPolicy(single_space = space) policy.allow_someobjects = False def interpret(source, context): source = charp2str(source) w_dict = space.newdict() ctx._ctx = context glob = ctx.globals() lst = ctx.propertylist(glob.js_val) for elem in lst: w_val = space.wrap(JSObject(ctx, ctx.get(glob.js_val, elem))) space.setitem(w_dict, space.wrap(elem), w_val) try: ec = space.getexecutioncontext() pycode = ec.compiler.compile(source, 'source', 'exec', 0) pycode.exec_code(space, w_dict, w_dict) except OperationError, e: print "OperationError:" print " operror-type: " + e.w_type.getname(space, '?') print " operror-value: " + space.str_w(space.str(e.w_value)) return 1 return 0
def main(argv): config = get_combined_translation_config(pypy_optiondescription, overrides=OVERRIDES, translating=True) config.objspace.nofaking = True config.objspace.compiler = "ast" config.translating = True set_opt_level(config, '1') set_pypy_opt_level(config, '1') enable_allworkingmodules(config) space = make_objspace(config) policy = PyPyAnnotatorPolicy(single_space=space) policy.allow_someobjects = False def interpret(source, context): source = charp2str(source) w_dict = space.newdict() try: ec = space.getexecutioncontext() pycode = ec.compiler.compile(source, 'source', 'exec', 0) pycode.exec_code(space, w_dict, w_dict) except OperationError, e: print "OperationError:" print " operror-type: " + e.w_type.getname(space, '?') print " operror-value: " + space.str_w( space.str(e.get_w_value(space))) return 1 return 0
def main(argv): config = get_combined_translation_config(pypy_optiondescription, overrides=OVERRIDES, translating=True) config.objspace.nofaking = True config.objspace.compiler = "ast" config.translating = True set_opt_level(config, '1') set_pypy_opt_level(config, '1') enable_allworkingmodules(config) space = make_objspace(config) policy = PyPyAnnotatorPolicy(single_space = space) policy.allow_someobjects = False def interpret(source, context): source = charp2str(source) w_dict = space.newdict() try: ec = space.getexecutioncontext() pycode = ec.compiler.compile(source, 'source', 'exec', 0) pycode.exec_code(space, w_dict, w_dict) except OperationError, e: print "OperationError:" print " operror-type: " + e.w_type.getname(space) print " operror-value: " + space.str_w(space.str(e.get_w_value(space))) return 1 return 0
def main(argv): config = get_combined_translation_config(pypy_optiondescription, overrides=OVERRIDES, translating=True) config.objspace.nofaking = True config.objspace.compiler = "ast" config.translating = True set_opt_level(config, '1') set_pypy_opt_level(config, '1') enable_allworkingmodules(config) space = make_objspace(config) ctx = JavaScriptContext(space) policy = PyPyAnnotatorPolicy(single_space=space) policy.allow_someobjects = False def interpret(source, context): source = charp2str(source) w_dict = space.newdict() ctx._ctx = context glob = ctx.globals() lst = ctx.propertylist(glob.js_val) for elem in lst: w_val = space.wrap(JSObject(ctx, ctx.get(glob.js_val, elem))) space.setitem(w_dict, space.wrap(elem), w_val) try: ec = space.getexecutioncontext() pycode = ec.compiler.compile(source, 'source', 'exec', 0) pycode.exec_code(space, w_dict, w_dict) except OperationError, e: print "OperationError:" print " operror-type: " + e.w_type.getname(space, '?') print " operror-value: " + space.str_w(space.str(e.w_value)) return 1 return 0
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 main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) def set_family_of_options(option, opt, value, parser): from pypy.config.pypyoption import set_pypy_opt_level set_pypy_opt_level(config, value) parser.add_option( '--cc', type=str, action="callback", callback=set_compiler, help="Compiler to use for compiling generated C") parser.add_option( '--opt', type=str, action="callback", callback=set_family_of_options, help="Set the family of options based on -opt=0,1,2,jit...") args = option.process_options(parser, argv[1:]) if interactiveconfig.verbose: error.RECORD_INTERPLEVEL_TRACEBACK = True # --allworkingmodules takes really long to start up, but can be forced on config.objspace.suggest(allworkingmodules=False) if config.objspace.allworkingmodules: pypyoption.enable_allworkingmodules(config) if config.objspace.usemodules._continuation: config.translation.continuation = True if config.objspace.usemodules.thread: config.translation.thread = True # create the object space space = option.make_objspace(config) space._starttime = starttime space.setitem(space.sys.w_dict, space.wrap('executable'), space.wrap(argv[0])) if interactiveconfig.optimize: #change the optimize flag's value and set __debug__ to False space.appexec([], """(): import sys flags = list(sys.flags) flags[6] = 2 sys.flags = type(sys.flags)(flags) import __pypy__ __pypy__.set_debug(False) """) # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and # sys.exec_prefix executable = argv[0] space.appexec([space.wrap(executable)], """(executable): import sys sys.pypy_find_stdlib(executable) """) # set warning control options (if any) warn_arg = interactiveconfig.warn if warn_arg is not None: space.appexec([space.wrap(warn_arg)], """(arg): import sys sys.warnoptions.append(arg)""") w_path = space.sys.get('path') path = os.getenv('PYTHONPATH') if path: path = path.split(os.pathsep) else: path = [] path.insert(0, '') for i, dir in enumerate(path): space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir)) # store the command-line arguments into sys.argv go_interactive = interactiveconfig.interactive banner = '' exit_status = 0 command = None if interactiveconfig.runcommand: command = args[0] args[0] = '-c' if interactiveconfig.runmodule: command = args.pop(0) for arg in args: space.call_method(space.sys.get('argv'), 'append', space.wrap_fsdecoded(arg)) # load the source of the program given as command-line argument if interactiveconfig.runcommand: def doit(): main.run_string(command, space=space) elif interactiveconfig.runmodule: def doit(): main.run_module(command, args, space=space) elif args: scriptdir = os.path.dirname(os.path.abspath(args[0])) space.call_method(space.sys.get('path'), 'insert', space.wrap(0), space.wrap(scriptdir)) def doit(): main.run_file(args[0], space=space) else: def doit(): pass space.call_method(space.sys.get('argv'), 'append', space.wrap('')) go_interactive = 1 banner = None try: def do_start(): space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, verbose=interactiveconfig.verbose): # compile and run it if not main.run_toplevel(space, doit, verbose=interactiveconfig.verbose): exit_status = 1 # start the interactive console if go_interactive or os.getenv('PYTHONINSPECT'): try: import readline except: pass con = interactive.PyPyConsole( space, verbose=interactiveconfig.verbose, completer=interactiveconfig.completer) if banner == '': banner = '%s / %s'%(con.__class__.__name__, repr(space)) con.interact(banner) exit_status = 0 finally: def doit(): space.finish() main.run_toplevel(space, doit, verbose=interactiveconfig.verbose) return exit_status
def target(self, driver, args): driver.exe_name = 'pypy-%(backend)s' config = driver.config parser = self.opt_parser(config) parser.parse_args(args) # expose the following variables to ease debugging global space, entry_point if config.objspace.allworkingmodules: from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(config) if config.objspace.translationmodules: from pypy.config.pypyoption import enable_translationmodules enable_translationmodules(config) config.translation.suggest(check_str_without_nul=True) config.translation.suggest(shared=True) config.translation.suggest(icon=os.path.join(this_dir, 'pypy.ico')) if config.translation.shared: if config.translation.output is not None: raise Exception("Cannot use the --output option with PyPy " "when --shared is on (it is by default). " "See issue #1971.") if config.translation.thread: config.objspace.usemodules.thread = True elif config.objspace.usemodules.thread: try: config.translation.thread = True except ConflictConfigError: # If --allworkingmodules is given, we reach this point # if threads cannot be enabled (e.g. they conflict with # something else). In this case, we can try setting the # usemodules.thread option to False again. It will # cleanly fail if that option was set to True by the # command-line directly instead of via --allworkingmodules. config.objspace.usemodules.thread = False if config.translation.continuation: config.objspace.usemodules._continuation = True elif config.objspace.usemodules._continuation: try: config.translation.continuation = True except ConflictConfigError: # Same as above: try to auto-disable the _continuation # module if translation.continuation cannot be enabled config.objspace.usemodules._continuation = False if not config.translation.rweakref: config.objspace.usemodules._weakref = False if config.translation.jit: config.objspace.usemodules.pypyjit = True elif config.objspace.usemodules.pypyjit: config.translation.jit = True if config.translation.sandbox: config.objspace.lonepycfiles = False config.objspace.usepycfiles = False config.translating = True import translate translate.log_config(config.objspace, "PyPy config object") # obscure hack to stuff the translation options into the translated PyPy import pypy.module.sys options = make_dict(config) wrapstr = 'space.wrap(%r)' % (options) pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr if config.objspace.usemodules._cffi_backend: self.hack_for_cffi_modules(driver) return self.get_entry_point(config)
def main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) parser.add_option('--cc', type=str, action="callback", callback=set_compiler, help="Compiler to use for compiling generated C") args = option.process_options(parser, argv[1:]) if interactiveconfig.verbose: error.RECORD_INTERPLEVEL_TRACEBACK = True # --allworkingmodules takes really long to start up, but can be forced on config.objspace.suggest(allworkingmodules=False) if config.objspace.allworkingmodules: pypyoption.enable_allworkingmodules(config) # create the object space space = option.make_objspace(config) space._starttime = starttime space.setitem(space.sys.w_dict, space.wrap('executable'), space.wrap(argv[0])) # set warning control options (if any) warn_arg = interactiveconfig.warn if warn_arg is not None: space.appexec([space.wrap(warn_arg)], """(arg): import sys sys.warnoptions.append(arg)""") w_path = space.sys.get('path') path = os.getenv('PYTHONPATH') if path: path = path.split(os.pathsep) else: path = [] path.insert(0, '') for i, dir in enumerate(path): space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir)) # store the command-line arguments into sys.argv go_interactive = interactiveconfig.interactive banner = '' exit_status = 0 if interactiveconfig.runcommand is not None: args = ['-c'] + args for arg in args: space.call_method(space.sys.get('argv'), 'append', space.wrap(arg)) # load the source of the program given as command-line argument if interactiveconfig.runcommand is not None: def doit(): main.run_string(interactiveconfig.runcommand, space=space) elif interactiveconfig.runmodule: def doit(): main.run_module(interactiveconfig.runmodule, args, space=space) elif args: scriptdir = os.path.dirname(os.path.abspath(args[0])) space.call_method(space.sys.get('path'), 'insert', space.wrap(0), space.wrap(scriptdir)) def doit(): main.run_file(args[0], space=space) else: def doit(): pass space.call_method(space.sys.get('argv'), 'append', space.wrap('')) go_interactive = 1 banner = None try: def do_start(): space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, verbose=interactiveconfig.verbose): # compile and run it if not main.run_toplevel( space, doit, verbose=interactiveconfig.verbose): exit_status = 1 # start the interactive console if go_interactive or os.getenv('PYTHONINSPECT'): try: import readline except: pass con = interactive.PyPyConsole( space, verbose=interactiveconfig.verbose, completer=interactiveconfig.completer) if banner == '': banner = '%s / %s' % (con.__class__.__name__, repr(space)) con.interact(banner) exit_status = 0 finally: def doit(): space.finish() main.run_toplevel(space, doit, verbose=interactiveconfig.verbose) return exit_status
def target(self, driver, args): driver.exe_name = 'pypy3-%(backend)s' config = driver.config parser = self.opt_parser(config) parser.parse_args(args) # expose the following variables to ease debugging global space, entry_point if config.objspace.allworkingmodules: from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(config) if config.objspace.translationmodules: from pypy.config.pypyoption import enable_translationmodules enable_translationmodules(config) config.translation.suggest(check_str_without_nul=True) config.translation.suggest(shared=True) config.translation.suggest(icon=os.path.join(this_dir, 'pypy.ico')) if config.translation.shared: if config.translation.output is not None: raise Exception("Cannot use the --output option with PyPy " "when --shared is on (it is by default). " "See issue #1971.") # if both profopt and profoptpath are specified then we keep them as they are with no other changes if config.translation.profopt: if config.translation.profoptargs is None: config.translation.profoptargs = "$(RPYDIR)/../lib-python/2.7/test/regrtest.py --pgo -x test_asyncore test_gdb test_multiprocessing test_subprocess || true" elif config.translation.profoptargs is not None: raise Exception( "Cannot use --profoptargs without specifying --profopt as well" ) if sys.platform == 'win32': libdir = thisdir.join('..', '..', 'libs') libdir.ensure(dir=1) pythonlib = "python{0[0]}{0[1]}.lib".format(CPYTHON_VERSION) config.translation.libname = str(libdir.join(pythonlib)) if config.translation.thread: config.objspace.usemodules.thread = True elif config.objspace.usemodules.thread: try: config.translation.thread = True except ConflictConfigError: # If --allworkingmodules is given, we reach this point # if threads cannot be enabled (e.g. they conflict with # something else). In this case, we can try setting the # usemodules.thread option to False again. It will # cleanly fail if that option was set to True by the # command-line directly instead of via --allworkingmodules. config.objspace.usemodules.thread = False if config.translation.continuation: config.objspace.usemodules._continuation = True elif config.objspace.usemodules._continuation: try: config.translation.continuation = True except ConflictConfigError: # Same as above: try to auto-disable the _continuation # module if translation.continuation cannot be enabled config.objspace.usemodules._continuation = False if not config.translation.rweakref: config.objspace.usemodules._weakref = False if config.translation.jit: config.objspace.usemodules.pypyjit = True elif config.objspace.usemodules.pypyjit: config.translation.jit = True if config.translation.sandbox: assert 0, ("--sandbox is not tested nor maintained. If you " "really want to try it anyway, remove this line in " "pypy/goal/targetpypystandalone.py.") if config.objspace.usemodules.cpyext: if config.translation.gc not in ('incminimark', 'boehm'): raise Exception( "The 'cpyext' module requires the 'incminimark'" " or 'boehm' GC. You need either 'targetpypystandalone.py" " --withoutmod-cpyext', or use one of these two GCs.") config.translating = True import translate translate.log_config(config.objspace, "PyPy config object") # obscure hack to stuff the translation options into the translated PyPy from pypy.module.sys.moduledef import Module as SysModule options = make_dict(config) wrapstr = 'space.wrap(%r)' % (options) # import time SysModule.interpleveldefs['pypy_translation_info'] = wrapstr if config.objspace.usemodules._cffi_backend: self.hack_for_cffi_modules(driver) return self.get_entry_point(config)
def target(self, driver, args): driver.exe_name = 'pypy-%(backend)s' config = driver.config parser = self.opt_parser(config) parser.parse_args(args) # expose the following variables to ease debugging global space, entry_point if config.objspace.allworkingmodules: from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(config) if config.translation.type_system == 'ootype': config.objspace.usemodules.suggest(rbench=True) if config.translation.thread: config.objspace.usemodules.thread = True elif config.objspace.usemodules.thread: try: config.translation.thread = True except ConflictConfigError: # If --allworkingmodules is given, we reach this point # if threads cannot be enabled (e.g. they conflict with # something else). In this case, we can try setting the # usemodules.thread option to False again. It will # cleanly fail if that option was set to True by the # command-line directly instead of via --allworkingmodules. config.objspace.usemodules.thread = False if config.translation.stackless: config.objspace.usemodules._stackless = True elif config.objspace.usemodules._stackless: try: config.translation.stackless = True except ConflictConfigError: raise ConflictConfigError("please use the --stackless option " "to translate.py instead of " "--withmod-_stackless directly") if not config.translation.rweakref: config.objspace.usemodules._weakref = False if config.translation.jit: config.objspace.usemodules.pypyjit = True elif config.objspace.usemodules.pypyjit: config.translation.jit = True if config.translation.backend == "cli": config.objspace.usemodules.clr = True # XXX did it ever work? #elif config.objspace.usemodules.clr: # config.translation.backend == "cli" config.objspace.nofaking = True config.objspace.compiler = "ast" config.translating = True import translate translate.log_config(config.objspace, "PyPy config object") # obscure hack to stuff the translation options into the translated PyPy import pypy.module.sys options = make_dict(config) wrapstr = 'space.wrap(%r)' % (options) pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr if config.translation.backend in ["cli", "jvm"] and sys.platform == "win32": # HACK: The ftruncate implementation in streamio.py which is used for the Win32 platform # is specific for the C backend and can't be generated on CLI or JVM. Because of that, # we have to patch it out. from pypy.rlib import streamio def ftruncate_win32_dummy(fd, size): pass def _setfd_binary_dummy(fd): pass streamio.ftruncate_win32 = ftruncate_win32_dummy streamio._setfd_binary = _setfd_binary_dummy return self.get_entry_point(config)
def target(self, driver, args): driver.exe_name = 'pypy-%(backend)s' config = driver.config parser = self.opt_parser(config) parser.parse_args(args) # expose the following variables to ease debugging global space, entry_point if config.objspace.allworkingmodules: from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(config) if config.objspace.translationmodules: from pypy.config.pypyoption import enable_translationmodules enable_translationmodules(config) config.translation.suggest(check_str_without_nul=True) config.translation.suggest(shared=True) config.translation.suggest(icon=os.path.join(this_dir, 'pypy.ico')) if config.translation.shared: if config.translation.output is not None: raise Exception("Cannot use the --output option with PyPy " "when --shared is on (it is by default). " "See issue #1971.") if sys.platform == 'win32': libdir = thisdir.join('..', '..', 'libs') libdir.ensure(dir=1) config.translation.libname = str(libdir.join('python27.lib')) if config.translation.thread: config.objspace.usemodules.thread = True elif config.objspace.usemodules.thread: try: config.translation.thread = True except ConflictConfigError: # If --allworkingmodules is given, we reach this point # if threads cannot be enabled (e.g. they conflict with # something else). In this case, we can try setting the # usemodules.thread option to False again. It will # cleanly fail if that option was set to True by the # command-line directly instead of via --allworkingmodules. config.objspace.usemodules.thread = False if config.translation.continuation: config.objspace.usemodules._continuation = True elif config.objspace.usemodules._continuation: try: config.translation.continuation = True except ConflictConfigError: # Same as above: try to auto-disable the _continuation # module if translation.continuation cannot be enabled config.objspace.usemodules._continuation = False if not config.translation.rweakref: config.objspace.usemodules._weakref = False if config.translation.jit: config.objspace.usemodules.pypyjit = True elif config.objspace.usemodules.pypyjit: config.translation.jit = True if config.translation.sandbox: config.objspace.lonepycfiles = False config.translating = True import translate translate.log_config(config.objspace, "PyPy config object") # obscure hack to stuff the translation options into the translated PyPy import pypy.module.sys options = make_dict(config) wrapstr = 'space.wrap(%r)' % (options) pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr if config.objspace.usemodules._cffi_backend: self.hack_for_cffi_modules(driver) return self.get_entry_point(config)
def target(self, driver, args): driver.exe_name = 'pypy-%(backend)s' config = driver.config parser = self.opt_parser(config) parser.parse_args(args) # expose the following variables to ease debugging global space, entry_point if config.objspace.allworkingmodules: from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(config) if config.translation.type_system == 'ootype': config.objspace.usemodules.suggest(rbench=True) if config.translation.thread: config.objspace.usemodules.thread = True elif config.objspace.usemodules.thread: try: config.translation.thread = True except ConflictConfigError: # If --allworkingmodules is given, we reach this point # if threads cannot be enabled (e.g. they conflict with # something else). In this case, we can try setting the # usemodules.thread option to False again. It will # cleanly fail if that option was set to True by the # command-line directly instead of via --allworkingmodules. config.objspace.usemodules.thread = False if config.translation.stackless: config.objspace.usemodules._stackless = True elif config.objspace.usemodules._stackless: try: config.translation.stackless = True except ConflictConfigError: raise ConflictConfigError("please use the --stackless option " "to translate.py instead of " "--withmod-_stackless directly") if not config.translation.rweakref: config.objspace.usemodules._weakref = False if config.translation.jit: config.objspace.usemodules.pypyjit = True elif config.objspace.usemodules.pypyjit: config.translation.jit = True if config.translation.backend == "cli": config.objspace.usemodules.clr = True # XXX did it ever work? #elif config.objspace.usemodules.clr: # config.translation.backend == "cli" config.objspace.nofaking = True config.objspace.compiler = "ast" config.translating = True import translate translate.log_config(config.objspace, "PyPy config object") # obscure hack to stuff the translation options into the translated PyPy import pypy.module.sys options = make_dict(config) wrapstr = 'space.wrap(%r)' % (options) pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr return self.get_entry_point(config)
def main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) parser.add_option( '--cc', type=str, action="callback", callback=set_compiler, help="Compiler to use for compiling generated C") args = option.process_options(parser, argv[1:]) if interactiveconfig.verbose: error.RECORD_INTERPLEVEL_TRACEBACK = True # --allworkingmodules takes really long to start up, but can be forced on config.objspace.suggest(allworkingmodules=False) if config.objspace.allworkingmodules: pypyoption.enable_allworkingmodules(config) # create the object space space = option.make_objspace(config) space._starttime = starttime space.setitem(space.sys.w_dict, space.wrap('executable'), space.wrap(argv[0])) # set warning control options (if any) warn_arg = interactiveconfig.warn if warn_arg is not None: space.appexec([space.wrap(warn_arg)], """(arg): import sys sys.warnoptions.append(arg)""") w_path = space.sys.get('path') path = os.getenv('PYTHONPATH') if path: path = path.split(os.pathsep) else: path = [] path.insert(0, '') for i, dir in enumerate(path): space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir)) # store the command-line arguments into sys.argv go_interactive = interactiveconfig.interactive banner = '' exit_status = 0 if interactiveconfig.runcommand is not None: args = ['-c'] + args for arg in args: space.call_method(space.sys.get('argv'), 'append', space.wrap(arg)) # load the source of the program given as command-line argument if interactiveconfig.runcommand is not None: def doit(): main.run_string(interactiveconfig.runcommand, space=space) elif interactiveconfig.runmodule: def doit(): main.run_module(interactiveconfig.runmodule, args, space=space) elif args: scriptdir = os.path.dirname(os.path.abspath(args[0])) space.call_method(space.sys.get('path'), 'insert', space.wrap(0), space.wrap(scriptdir)) def doit(): main.run_file(args[0], space=space) else: def doit(): pass space.call_method(space.sys.get('argv'), 'append', space.wrap('')) go_interactive = 1 banner = None try: def do_start(): space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, verbose=interactiveconfig.verbose): # compile and run it if not main.run_toplevel(space, doit, verbose=interactiveconfig.verbose): exit_status = 1 # start the interactive console if go_interactive or os.getenv('PYTHONINSPECT'): try: import readline except: pass con = interactive.PyPyConsole( space, verbose=interactiveconfig.verbose, completer=interactiveconfig.completer) if banner == '': banner = '%s / %s'%(con.__class__.__name__, repr(space)) con.interact(banner) exit_status = 0 finally: def doit(): space.finish() main.run_toplevel(space, doit, verbose=interactiveconfig.verbose) return exit_status
def target(self, driver, args): driver.exe_name = 'pypy-%(backend)s' config = driver.config parser = self.opt_parser(config) parser.parse_args(args) # expose the following variables to ease debugging global space, entry_point if config.objspace.allworkingmodules: from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(config) if config.objspace.translationmodules: from pypy.config.pypyoption import enable_translationmodules enable_translationmodules(config) config.translation.suggest(check_str_without_nul=True) config.translation.suggest(shared=True) if config.translation.thread: config.objspace.usemodules.thread = True elif config.objspace.usemodules.thread: try: config.translation.thread = True except ConflictConfigError: # If --allworkingmodules is given, we reach this point # if threads cannot be enabled (e.g. they conflict with # something else). In this case, we can try setting the # usemodules.thread option to False again. It will # cleanly fail if that option was set to True by the # command-line directly instead of via --allworkingmodules. config.objspace.usemodules.thread = False if config.translation.continuation: config.objspace.usemodules._continuation = True elif config.objspace.usemodules._continuation: try: config.translation.continuation = True except ConflictConfigError: # Same as above: try to auto-disable the _continuation # module if translation.continuation cannot be enabled config.objspace.usemodules._continuation = False if not config.translation.rweakref: config.objspace.usemodules._weakref = False if config.translation.jit: config.objspace.usemodules.pypyjit = True elif config.objspace.usemodules.pypyjit: config.translation.jit = True if config.translation.sandbox: config.objspace.lonepycfiles = False config.objspace.usepycfiles = False config.translating = True import translate translate.log_config(config.objspace, "PyPy config object") # obscure hack to stuff the translation options into the translated PyPy import pypy.module.sys options = make_dict(config) wrapstr = 'space.wrap(%r)' % (options) pypy.module.sys.Module.interpleveldefs[ 'pypy_translation_info'] = wrapstr return self.get_entry_point(config)
def main_(argv=None): starttime = time.time() config, parser = option.get_standard_options() interactiveconfig = Config(cmdline_optiondescr) to_optparse(interactiveconfig, parser=parser) def set_family_of_options(option, opt, value, parser): from pypy.config.pypyoption import set_pypy_opt_level set_pypy_opt_level(config, value) parser.add_option('--cc', type=str, action="callback", callback=set_compiler, help="Compiler to use for compiling generated C") parser.add_option( '--opt', type=str, action="callback", callback=set_family_of_options, help="Set the family of options based on -opt=0,1,2,jit...") args = option.process_options(parser, argv[1:]) if interactiveconfig.verbose: error.RECORD_INTERPLEVEL_TRACEBACK = True # --allworkingmodules takes really long to start up, but can be forced on config.objspace.suggest(allworkingmodules=False) config.objspace.usemodules.struct = True if config.objspace.allworkingmodules: pypyoption.enable_allworkingmodules(config) if config.objspace.usemodules._continuation: config.translation.continuation = True if config.objspace.usemodules.thread: config.translation.thread = True # create the object space space = option.make_objspace(config) space._starttime = starttime space.setitem(space.sys.w_dict, space.wrap('executable'), space.wrap(argv[0])) if interactiveconfig.optimize: #change the optimize flag's value and set __debug__ to False space.appexec([], """(): import sys flags = list(sys.flags) flags[3] = 2 sys.flags = type(sys.flags)(flags) __builtins__.__dict__['__debug__'] = False """) # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and # sys.exec_prefix executable = argv[0] space.appexec([space.wrap(executable)], """(executable): import sys sys.pypy_find_stdlib(executable) """) # set warning control options (if any) warn_arg = interactiveconfig.warn if warn_arg is not None: space.appexec([space.wrap(warn_arg)], """(arg): import sys sys.warnoptions.append(arg)""") w_path = space.sys.get('path') path = os.getenv('PYTHONPATH') if path: path = path.split(os.pathsep) else: path = [] path.insert(0, '') for i, dir in enumerate(path): space.call_method(w_path, 'insert', space.wrap(i), space.wrap(dir)) # store the command-line arguments into sys.argv go_interactive = interactiveconfig.interactive banner = '' exit_status = 0 command = None if interactiveconfig.runcommand: command = args[0] args[0] = '-c' if interactiveconfig.runmodule: command = args.pop(0) for arg in args: space.call_method(space.sys.get('argv'), 'append', space.newfilename(arg)) # load the source of the program given as command-line argument if interactiveconfig.runcommand: def doit(): main.run_string(command, space=space) elif interactiveconfig.runmodule: def doit(): main.run_module(command, args, space=space) elif args: scriptdir = os.path.dirname(os.path.abspath(args[0])) space.call_method(space.sys.get('path'), 'insert', space.wrap(0), space.wrap(scriptdir)) def doit(): main.run_file(args[0], space=space) else: def doit(): pass space.call_method(space.sys.get('argv'), 'append', space.wrap('')) go_interactive = 1 banner = None try: def do_start(): space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, verbose=interactiveconfig.verbose): # compile and run it if not main.run_toplevel( space, doit, verbose=interactiveconfig.verbose): exit_status = 1 # start the interactive console if go_interactive or os.getenv('PYTHONINSPECT'): try: import readline except: pass con = interactive.PyPyConsole( space, verbose=interactiveconfig.verbose, completer=interactiveconfig.completer) if banner == '': banner = '%s / %s' % (con.__class__.__name__, repr(space)) con.interact(banner) exit_status = 0 finally: def doit(): space.finish() main.run_toplevel(space, doit, verbose=interactiveconfig.verbose) return exit_status
def target(self, driver, args): driver.exe_name = 'pypy-%(backend)s' config = driver.config parser = self.opt_parser(config) parser.parse_args(args) # expose the following variables to ease debugging global space, entry_point if config.objspace.allworkingmodules: from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(config) if config.objspace.translationmodules: from pypy.config.pypyoption import enable_translationmodules enable_translationmodules(config) ## if config.translation.type_system == 'ootype': ## config.objspace.usemodules.suggest(rbench=True) config.translation.suggest(check_str_without_nul=True) if config.translation.thread: config.objspace.usemodules.thread = True elif config.objspace.usemodules.thread: try: config.translation.thread = True except ConflictConfigError: # If --allworkingmodules is given, we reach this point # if threads cannot be enabled (e.g. they conflict with # something else). In this case, we can try setting the # usemodules.thread option to False again. It will # cleanly fail if that option was set to True by the # command-line directly instead of via --allworkingmodules. config.objspace.usemodules.thread = False if config.translation.continuation: config.objspace.usemodules._continuation = True elif config.objspace.usemodules._continuation: try: config.translation.continuation = True except ConflictConfigError: # Same as above: try to auto-disable the _continuation # module if translation.continuation cannot be enabled config.objspace.usemodules._continuation = False if not config.translation.rweakref: config.objspace.usemodules._weakref = False if config.translation.jit: config.objspace.usemodules.pypyjit = True elif config.objspace.usemodules.pypyjit: config.translation.jit = True if config.translation.backend == "cli": config.objspace.usemodules.clr = True # XXX did it ever work? #elif config.objspace.usemodules.clr: # config.translation.backend == "cli" if config.translation.sandbox: config.objspace.lonepycfiles = False config.objspace.usepycfiles = False config.objspace.nofaking = True config.translating = True import translate translate.log_config(config.objspace, "PyPy config object") # obscure hack to stuff the translation options into the translated PyPy import pypy.module.sys options = make_dict(config) wrapstr = 'space.wrap(%r)' % (options) pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr if config.translation.backend in ["cli", "jvm"] and sys.platform == "win32": # HACK: The ftruncate implementation in streamio.py which is used for the Win32 platform # is specific for the C backend and can't be generated on CLI or JVM. Because of that, # we have to patch it out. from pypy.rlib import streamio def ftruncate_win32_dummy(fd, size): pass def _setfd_binary_dummy(fd): pass streamio.ftruncate_win32 = ftruncate_win32_dummy streamio._setfd_binary = _setfd_binary_dummy return self.get_entry_point(config)
def target(self, driver, args): driver.exe_name = 'pypy-%(backend)s' config = driver.config parser = self.opt_parser(config) parser.parse_args(args) # expose the following variables to ease debugging global space, entry_point if config.objspace.allworkingmodules: from pypy.config.pypyoption import enable_allworkingmodules enable_allworkingmodules(config) if config.translation.thread: config.objspace.usemodules.thread = True elif config.objspace.usemodules.thread: try: config.translation.thread = True except ConflictConfigError: # If --allworkingmodules is given, we reach this point # if threads cannot be enabled (e.g. they conflict with # something else). In this case, we can try setting the # usemodules.thread option to False again. It will # cleanly fail if that option was set to True by the # command-line directly instead of via --allworkingmodules. config.objspace.usemodules.thread = False if config.translation.stackless: config.objspace.usemodules._stackless = True elif config.objspace.usemodules._stackless: try: config.translation.stackless = True except ConflictConfigError: raise ConflictConfigError("please use the --stackless option " "to translate.py instead of " "--withmod-_stackless directly") if not config.translation.rweakref: config.objspace.usemodules._weakref = False if self.translateconfig.goal_options.jit: config.objspace.usemodules.pypyjit = True elif config.objspace.usemodules.pypyjit: self.translateconfig.goal_options.jit = True if config.translation.backend == "cli": config.objspace.usemodules.clr = True # XXX did it ever work? #elif config.objspace.usemodules.clr: # config.translation.backend == "cli" config.objspace.nofaking = True config.objspace.compiler = "ast" config.translating = True import translate translate.log_config(config.objspace, "PyPy config object") # obscure hack to stuff the translation options into the translated PyPy import pypy.module.sys options = make_dict(config) wrapstr = 'space.wrap(%r)' % (options) pypy.module.sys.Module.interpleveldefs[ 'pypy_translation_info'] = wrapstr return self.get_entry_point(config)