def entry_point(args): """Main entry point of the stand-alone executable: takes a list of strings and returns the exit code. """ # store args[0] in a place where the JIT log can find it (used by # viewcode.py to know the executable whose symbols it should display) highleveljitinfo.sys_executable = args.pop(0) if len(args) < 1: return help() if args[0] == '-j': if len(args) < 3: return help() try: set_user_param(tiny3.tinyjitdriver, args[1]) except ValueError: return help("Bad argument to -j.") args = args[2:] bytecode = [s for s in args[0].split(' ') if s != ''] real_args = [] for arg in args[1:]: try: real_args.append(tiny3.IntBox(int(arg))) except ValueError: real_args.append(tiny3.FloatBox(tiny3.myfloat(arg))) res = tiny3.interpret(bytecode, real_args) print tiny3.repr(res) return 0
def set_param(space, __args__): '''Configure the tunable JIT parameters. * set_param(name=value, ...) # as keyword arguments * set_param("name=value,name=value") # as a user-supplied string * set_param("off") # disable the jit * set_param("default") # restore all defaults ''' # XXXXXXXXX args_w, kwds_w = __args__.unpack() if len(args_w) > 1: raise oefmt(space.w_TypeError, "set_param() takes at most 1 non-keyword argument, %d " "given", len(args_w)) if len(args_w) == 1: text = space.str_w(args_w[0]) try: jit.set_user_param(None, text) except ValueError: raise OperationError(space.w_ValueError, space.wrap("error in JIT parameters string")) for key, w_value in kwds_w.items(): if key == 'enable_opts': jit.set_param(None, 'enable_opts', space.str_w(w_value)) else: intval = space.int_w(w_value) for name, _ in unroll_parameters: if name == key and name != 'enable_opts': jit.set_param(None, name, intval) break else: raise oefmt(space.w_TypeError, "no JIT parameter '%s'", key)
def entry_point(argv): # Pycket's params jit.set_param(None, 'trace_limit', 1000000) jit.set_param(None, 'threshold', 131) jit.set_param(None, 'trace_eagerness', 50) jit.set_param(None, 'max_unroll_loops', 15) # HT pyrolog for i in range(len(argv)): if argv[i] == '--jit': if len(argv) == i + 1: print 'missing argument after --jit' return 2 jitarg = argv[i + 1] del argv[i:i + 2] jit.set_user_param(None, jitarg) break if len(argv) > 1: print 'too many arguments' if we_are_translated(): from rpython.rlib import streamio from pycket import pycket_json stdin = streamio.fdopen_as_stream(0, "r") json = pycket_json.loads(stdin.readall()) return main(core.json_to_term(json)) else: import sys, json import pycket_json_adapter as pja adapted = pja.adapt(json.load(sys.stdin)) sys.exit(main(core.json_to_term(adapted)))
def set_param(space, __args__): '''Configure the tunable JIT parameters. * set_param(name=value, ...) # as keyword arguments * set_param("name=value,name=value") # as a user-supplied string * set_param("off") # disable the jit * set_param("default") # restore all defaults ''' # XXXXXXXXX args_w, kwds_w = __args__.unpack() if len(args_w) > 1: raise oefmt( space.w_TypeError, "set_param() takes at most 1 non-keyword argument, %d " "given", len(args_w)) if len(args_w) == 1: text = space.str_w(args_w[0]) try: jit.set_user_param(None, text) except ValueError: raise OperationError(space.w_ValueError, space.wrap("error in JIT parameters string")) for key, w_value in kwds_w.items(): if key == 'enable_opts': jit.set_param(None, 'enable_opts', space.str_w(w_value)) else: intval = space.int_w(w_value) for name, _ in unroll_parameters: if name == key and name != 'enable_opts': jit.set_param(None, name, intval) break else: raise oefmt(space.w_TypeError, "no JIT parameter '%s'", key)
def entry_point(argv): from rpython.rlib.jit import set_user_param jit_params = os.environ.get('PYPYJIT') if jit_params: set_user_param(None, jit_params) exe_dict = parse_executable(open(argv[1], 'rb').read()) bytecode = make_int_array(exe_dict['CODE']) prims = Prims(exe_dict['PRIM'].split('\0'), argv[2:]) global_data = unmarshal(exe_dict['DATA']).get_fields() Frame(prims, global_data).eval(bytecode, pc=0) return 0
def main(argv): printtime = False i = 0 while i < len(argv): if argv[i] == "--jit": jitarg = argv[i + 1] del argv[i:i + 2] print jitarg, argv jit.set_user_param(None, jitarg) if argv[i] == "--time": printtime = True i += 1 patternfilename = argv[1] inputfilename = argv[2] patternfile = open(patternfilename, "r") inputfile = open(inputfilename, "r") pattern = patternfile.read() patternfile.close() inputstring = inputfile.read() inputfile.close() inputstring = inputstring.strip() flags = Flags(optimize_char=True, optimize_testchar=True) if not flags.optimize_choicepoints: jit.set_param( None, "enable_opts", "intbounds:rewrite:virtualize:string:pure:earlyforce:heap") if we_are_translated(): gct1 = rgc.get_stats(rgc.TOTAL_GC_TIME) else: gct1 = 0 t1 = time.time() captures = runbypattern(pattern, inputstring, flags=flags).captures output = processcaptures(captures, inputstring) t2 = time.time() if we_are_translated(): gct2 = rgc.get_stats(rgc.TOTAL_GC_TIME) else: gct2 = 0 print output if printtime: print "time:", t2 - t1 print "gc time:", (gct2 - gct1) / 1000. return 0
def main(argv): ###### MAIN PROGRAM ###### # XXX crappy copy-pasted argument handling by cfbolz # https://bitbucket.org/cfbolz/pyrolog for i in range(len(argv)): if argv[i] == "--jit": if len(argv) == i + 1: print "missing argument after --jit" return 2 jitarg = argv[i + 1] #e.g. --jit off del argv[i:i+2] jit.set_user_param(jitdriver, jitarg) break if len(argv)<2: print "Error: Arglen <2 " print_usage() return 0 try: #if argv[1]=="-repl" or argv[1]=="-r": # run_repl() #elif argv[1]=="-check_solution" or argv[1]=="-c": # result = run_checking_mode() # print "Invariant:", result if argv[1]=="-model_checking" or argv[1]=="-mc": res = run_model_checking_mode(argv) return res #elif argv[1]=="-check_solution" or argv[1]=="-c": # res = run_checking_mode() # print "Invariant:", res # return res #elif sys.argv[1]=="-animate" or sys.argv[1]=="-a": # res = run_animation_mode(sys.argv) # return res else: print_usage() return 0 except Exception as e1: #print "\033[1m\033[91mError in PyB\033[00m:" #, type(e1), e1.args, e1 import traceback #print "Use PyB-Python version to get a detailed error message" #print "\033[1m\033[91mBugreports to [email protected]\033[00m:" #print "\033[1m\033[91mError message\033[00m:" #print traceback.format_exc() #print "\033[1m\033[91m End of error message\033[00m" return -1
def entry_point(args): for i in range(len(args)): if args[i] == "--jit": if len(args) == i + 1: print "missing argument after --jit" return 2 jitarg = args[i + 1] del args[i:i + 2] jit.set_user_param(None, jitarg) break if len(args) < 3: print "Usage: %s filename x" % (args[0], ) return 2 filename = args[1] x = int(args[2]) w_x = tla.W_IntObject(x) bytecode = load_bytecode(filename) w_res = tla.run(bytecode, w_x) print w_res.getrepr() return 0
def entry_point(argv): e.clocks.startup() # XXX crappy argument handling for i in range(len(argv)): if argv[i] == "--jit": if len(argv) == i + 1: print "missing argument after --jit" return 2 jitarg = argv[i + 1] del argv[i:i+2] jit.set_user_param(jitdriver, jitarg) break if len(argv) == 2: execute(e, argv[1]) if len(argv) > 2: print "too many arguments" return 2 try: repl(e) except SystemExit: return 1 return 0
def runTyphon(argv): # Start metrics. recorder = globalRecorder() recorder.start() # Initialize libsodium. if rsodium.init() < 0: print "Couldn't initialize libsodium!" return 1 config = Configuration(argv) if config.verbose: enableDebugPrint() config.enableLogging() if len(config.argv) < 2: print "No file provided?" return 1 # Pass user configuration to the JIT. set_user_param(None, config.jit) # Intialize our loop. uv_loop = ruv.alloc_loop() # Usurp SIGPIPE, as libuv does not handle it. rsignal.pypysig_ignore(rsignal.SIGPIPE) # Initialize our first vat. It shall be immortal. vatManager = VatManager() vat = Vat(vatManager, uv_loop, checkpoints=-1) vatManager.vats.append(vat) # Update loop timing information. Until the loop really gets going, we # have to do this ourselves in order to get the timing correct for early # timers. ruv.update_time(uv_loop) try: with scopedVat(vat) as vat: prelude = loadPrelude(config, recorder, vat) except LoadFailed as lf: print lf return 1 except CompilerFailed as cf: debug_print("Caught exception while importing prelude:", cf.formatError()) return 1 except UserException as ue: debug_print("Caught exception while importing prelude:", ue.formatError()) return 1 registerGlobals(prelude) scope = safeScope() scope.update(prelude) ss = scope.copy() reflectedSS = monteMap() for k, b in ss.iteritems(): reflectedSS[StrObject(u"&&" + k)] = b ss[u"safeScope"] = finalBinding(ConstMap(reflectedSS), deepFrozenGuard) reflectedSS[StrObject(u"&&safeScope")] = ss[u"safeScope"] scope[u"safeScope"] = ss[u"safeScope"] scope.update(unsafeScope(config)) # The initial vat is included as `currentVat` to the first level of # loading and such. scope[u"currentVat"] = finalBinding(vat, anyGuard) reflectedUnsafeScope = monteMap() unsafeScopeDict = {} for k, b in scope.iteritems(): reflectedUnsafeScope[StrObject(u"&&" + k)] = b unsafeScopeDict[k] = b rus = finalBinding(ConstMap(reflectedUnsafeScope), anyGuard) reflectedUnsafeScope[StrObject(u"&&unsafeScope")] = rus unsafeScopeDict[u"unsafeScope"] = rus try: module = obtainModule([""], recorder, config.argv[1]) except LoadFailed as lf: print lf return 1 if config.loadOnly: # We are finished. return 0 if not config.benchmark: benchmarkSettings.disable() with profiling("vmprof.log", config.profile): # Update loop timing information. ruv.update_time(uv_loop) debug_print("Taking initial turn in script...") result = NullObject try: with recorder.context("Time spent in vats"): with scopedVat(vat): result = module.eval(unsafeScopeDict)[0] if result is None: return 1 except UserException as ue: debug_print("Caught exception while taking initial turn:", ue.formatError()) return 1 # Exit status code. exitStatus = 0 # Update loop timing information. ruv.update_time(uv_loop) try: runUntilDone(vatManager, uv_loop, recorder) rv = resolution(result) if result is not None else NullObject if isinstance(rv, IntObject): exitStatus = rv.getInt() except SystemExit: pass # Huh, apparently this doesn't work. Wonder why/why not. # exitStatus = se.code finally: recorder.stop() recorder.printResults() # Clean up and exit. cleanUpEverything() return exitStatus
def parse_args(self, argv, skip_bad=False): idx = 1 while idx < len(argv): arg = argv[idx] idx += 1 # General if arg in ["-h", "--help"]: _usage(argv) raise error.CleanExit() elif arg in ["-v", "--version"]: print "RSqueakVM %s, built on %s" % (VERSION, BUILD_DATE) raise error.CleanExit() elif arg in ["--git-version"]: print GIT_VERSION raise error.CleanExit() elif arg == "--highdpi": self.space.highdpi.activate() elif arg == "--software-renderer": self.space.software_renderer.activate() # -nodisplay (Linux) and -headless (macOS) are used in Cog elif arg in ["--no-display", "-nodisplay", "-headless"]: self.space.no_display.activate() elif arg == "--silent": self.space.silent.activate() # Execution elif arg in ["-r", "--run"]: self.code, idx = get_parameter(argv, idx, arg) elif arg in ["-m", "--method"]: self.selector, idx = get_parameter(argv, idx, arg) elif arg in ["-n", "--number"]: self.number, idx = get_int_parameter(argv, idx, arg) self.have_number = True elif arg in ["-a", "--arg"]: self.stringarg, idx = get_parameter(argv, idx, arg) elif arg in ["-P", "--process"]: self.headless = False elif arg in ["-u", "--stop-ui"]: from rsqueakvm.plugins.vm_debugging import stop_ui_process stop_ui_process() elif arg == "--shell": self.shell = True elif arg in ["--simulate-numeric-primitives"]: self.space.simulate_numeric_primitives.activate() # Cog compatibility by skipping single dash args (e.g. -nosound) elif len(arg) > 2 and arg[0] == '-' and not arg.startswith('--'): pass # Other elif arg in ["-j", "--jit"]: jitarg, idx = get_parameter(argv, idx, arg) # Work around TraceLimitTooHigh by setting any trace_limit explicitly parts = jitarg.split(",") limitidx = -1 for i, s in enumerate(parts): if "trace_limit" in s: limitidx = i break if limitidx >= 0: limit = parts.pop(limitidx) jit.set_param(interpreter.Interpreter.jit_driver, "trace_limit", int(limit.split("=")[1])) if len(parts) > 0: jit.set_user_param(interpreter.Interpreter.jit_driver, ",".join(parts)) elif arg in ["-p", "--poll"]: self.poll = True elif arg in ["-i", "--no-interrupts"]: self.interrupts = False elif arg in ["-S", "--no-storage"]: self.space.strategy_factory.no_specialized_storage.activate() # Logging elif arg in ["-t", "--trace"]: self.trace = True elif arg in ["-T", "--trace-important"]: self.trace_important = True elif arg in ["-s", "--safe-trace"]: self.space.omit_printing_raw_bytes.activate() elif arg in ["-l", "--storage-log"]: self.space.strategy_factory.logger.activate() elif arg in ["-L", "--storage-log-aggregate"]: self.space.strategy_factory.logger.activate(aggregate=True) elif arg == "--log-image-loading": self.log_image_loading = True # Global elif arg in ["--ImageFile"]: self.path, idx = get_parameter(argv, idx, arg) elif arg in ["--WindowTitle"]: title, idx = get_parameter(argv, idx, arg) self.space.title.set(title) elif arg in ["--EnableAltF4Quit"]: self.space.altf4quit.activate() # Default elif arg in ["--"]: print "Image arguments: %s" % ", ".join(argv[idx:]) self.extra_arguments_idx = idx return elif not self.got_lone_path: self.path = arg self.got_lone_path = True # once we got an image argument, we stop processing and pass # everything on to the image if idx < len(argv): print "Image arguments: %s" % ", ".join(argv[idx:]) self.extra_arguments_idx = idx return else: _usage(argv) raise error.Exit("Invalid argument: %s" % arg)
def entry_point(argv): # == Main execution parameters path = None selector = None code = "" number = 0 have_number = False stringarg = None headless = True # == Other parameters poll = False interrupts = True trace = False trace_important = False space = prebuilt_space idx = 1 try: while idx < len(argv): arg = argv[idx] idx += 1 if arg in ["-h", "--help"]: _usage(argv) return 0 elif arg in ["-j", "--jit"]: jitarg, idx = get_parameter(argv, idx, arg) jit.set_user_param(interpreter.Interpreter.jit_driver, jitarg) elif arg in ["-n", "--number"]: number, idx = get_int_parameter(argv, idx, arg) have_number = True elif arg in ["-m", "--method"]: selector, idx = get_parameter(argv, idx, arg) elif arg in ["-t", "--trace"]: trace = True elif arg in ["-T"]: trace_important = True elif arg in ["-s", "--safe-trace"]: space.omit_printing_raw_bytes.activate() elif arg in ["-p", "--poll"]: poll = True elif arg in ["-a", "--arg"]: stringarg, idx = get_parameter(argv, idx, arg) elif arg in ["-r", "--run"]: code, idx = get_parameter(argv, idx, arg) elif arg in ["-i", "--no-interrupts"]: interrupts = False elif arg in ["-P", "--process"]: headless = False elif arg in ["--hacks"]: space.run_spy_hacks.activate() elif arg in ["-S"]: space.strategy_factory.no_specialized_storage.activate() elif arg in ["-u"]: from spyvm.plugins.vmdebugging import stop_ui_process stop_ui_process() elif arg in ["-l", "--storage-log"]: space.strategy_factory.logger.activate() elif arg in ["-L", "--storage-log-aggregate"]: space.strategy_factory.logger.activate(aggregate=True) elif path is None: path = arg else: _usage(argv) return -1 if path is None: path = "Squeak.image" if code and selector: raise error.Exit("Cannot handle both -r and -m.") except error.Exit as e: print_error("Parameter error: %s" % e.msg) return 1 path = rpath.rabspath(path) try: stream = squeakimage.Stream(filename=path) except OSError as e: print_error("%s -- %s (LoadError)" % (os.strerror(e.errno), path)) return 1 # Load & prepare image and environment image = squeakimage.ImageReader(space, stream).create_image() interp = interpreter.Interpreter(space, image, trace=trace, trace_important=trace_important, evented=not poll, interrupts=interrupts) space.runtime_setup(argv[0], path) print_error("") # Line break after image-loading characters # Create context to be executed if code or selector: if not have_number: w_receiver = space.w_nil else: w_receiver = space.wrap_int(number) if code: selector = compile_code(interp, w_receiver, code) s_frame = create_context(interp, w_receiver, selector, stringarg) if headless: space.headless.activate() context = s_frame else: create_process(interp, s_frame) context = active_context(space) else: context = active_context(space) w_result = execute_context(interp, context) print result_string(w_result) return 0
def runTyphon(argv): recorder = Recorder() recorder.start() # Initialize libsodium. if rsodium.init() < 0: print "Couldn't initialize libsodium!" return 1 config = Configuration(argv) if config.verbose: enableDebugPrint() config.enableLogging() if len(config.argv) < 2: print "No file provided?" return 1 # Pass user configuration to the JIT. set_user_param(None, config.jit) # Intialize our loop. uv_loop = ruv.alloc_loop() # Usurp SIGPIPE, as libuv does not handle it. rsignal.pypysig_ignore(rsignal.SIGPIPE) # Initialize our first vat. It shall be immortal. vatManager = VatManager() vat = Vat(vatManager, uv_loop, checkpoints=-1) vatManager.vats.append(vat) # Update loop timing information. Until the loop really gets going, we # have to do this ourselves in order to get the timing correct for early # timers. ruv.update_time(uv_loop) try: with scopedVat(vat) as vat: prelude = loadPrelude(config, recorder, vat) except LoadFailed as lf: print lf return 1 registerGlobals(prelude) scope = safeScope() scope.update(prelude) ss = scope.copy() reflectedSS = monteMap() for k, b in ss.iteritems(): reflectedSS[StrObject(u"&&" + k)] = b ss[u"safeScope"] = finalBinding(ConstMap(reflectedSS), deepFrozenGuard) reflectedSS[StrObject(u"&&safeScope")] = ss[u"safeScope"] scope[u"safeScope"] = ss[u"safeScope"] scope.update(unsafeScope(config)) reflectedUnsafeScope = monteMap() unsafeScopeDict = {} for k, b in scope.iteritems(): reflectedUnsafeScope[StrObject(u"&&" + k)] = b unsafeScopeDict[k] = b rus = finalBinding(ConstMap(reflectedUnsafeScope), anyGuard) reflectedUnsafeScope[StrObject(u"&&unsafeScope")] = rus unsafeScopeDict[u"unsafeScope"] = rus try: code = obtainModule([""], config.argv[1], recorder) except LoadFailed as lf: print lf return 1 if config.loadOnly: # We are finished. return 0 if not config.benchmark: benchmarkSettings.disable() with profiling("vmprof.log", config.profile): # Update loop timing information. ruv.update_time(uv_loop) debug_print("Taking initial turn in script...") result = NullObject with recorder.context("Time spent in vats"): with scopedVat(vat): result = evaluateTerms([code], unsafeScopeDict) if result is None: return 1 # Exit status code. exitStatus = 0 # Update loop timing information. ruv.update_time(uv_loop) try: runUntilDone(vatManager, uv_loop, recorder) rv = resolution(result) if result is not None else NullObject if isinstance(rv, IntObject): exitStatus = rv.getInt() except SystemExit: pass # Huh, apparently this doesn't work. Wonder why/why not. # exitStatus = se.code finally: recorder.stop() recorder.printResults() # Clean up and exit. cleanUpEverything() return exitStatus
def _entry_point(space, argv): try: ( flag_globals_w, do_loop, path, search_path, globalized_switches, exprs, reqs, load_path_entries, jit_params, syntax_check, argv_w ) = _parse_argv(space, argv) except ShortCircuitError as e: os.write(1, e.message) return 0 except CommandLineError as e: os.write(2, e.message) return 1 for path_entry in load_path_entries: space.send( space.w_load_path, "<<", [space.newstr_fromstr(path_entry)] ) for required_lib in reqs: space.send( space.w_kernel, "require", [space.newstr_fromstr(required_lib)] ) space.set_const(space.w_object, "ARGV", space.newarray(argv_w)) explicitly_verbose = space.is_true(flag_globals_w["$-v"]) if explicitly_verbose: os.write(1, "%s\n" % RUBY_DESCRIPTION) for varname, w_value in flag_globals_w.iteritems(): space.globals.set(space, varname, w_value) if exprs: source = "\n".join(exprs) path = "-e" elif path is not None: if search_path: for dirname in os.environ["PATH"].split(os.pathsep): candidate_path = os.sep.join([dirname, path]) if os.access(candidate_path, os.R_OK): path = candidate_path break try: f = open_file_as_stream(path, buffering=0) except OSError as e: os.write(2, "%s -- %s (LoadError)\n" % (os.strerror(e.errno), path)) return 1 try: source = f.readall() finally: f.close() elif explicitly_verbose: return 0 else: if IS_WINDOWS: source = WinStdinStream().readall() else: source = fdopen_as_stream(0, "r").readall() path = "-" for globalized_switch in globalized_switches: value = None if "=" in globalized_switch: globalized_switch, value = globalized_switch.split("=", 1) switch_global_var = "$%s" % globalized_switch[1:].replace("-", "_") if value is None: space.globals.set(space, switch_global_var, space.w_true) else: space.globals.set(space, switch_global_var, space.newstr_fromstr(value)) w_program_name = space.newstr_fromstr(path) space.globals.set(space, "$0", w_program_name) space.globals.set(space, "$PROGRAM_NAME", w_program_name) status = 0 w_exit_error = None explicit_status = False jit.set_param(None, "trace_limit", 16000) if jit_params: # Work around TraceLimitTooHigh by setting any trace_limit explicitly parts = jit_params.split(",") limitidx = -1 for i, s in enumerate(parts): if "trace_limit" in s: limitidx = i break if limitidx >= 0: limit = parts.pop(limitidx) jit.set_param(None, "trace_limit", int(limit.split("=")[1])) if len(parts) > 0: jit.set_user_param(None, ",".join(parts)) try: if do_loop: print_after = space.is_true(flag_globals_w["$-p"]) bc = space.compile(source, path) frame = space.create_frame(bc) while True: w_line = space.send(space.w_kernel, "gets") if w_line is space.w_nil: break with space.getexecutioncontext().visit_frame(frame): w_res = space.execute_frame(frame, bc) if print_after: space.send(space.w_kernel, "print", [w_res]) elif syntax_check: space.compile(source, path) else: space.execute(source, filepath=path) except RubyError as e: explicit_status = True w_exc = e.w_value if isinstance(w_exc, W_SystemExit): status = w_exc.status else: w_exit_error = w_exc status = 1 exit_handler_status = space.run_exit_handlers() if not explicit_status and exit_handler_status != -1: status = exit_handler_status if w_exit_error is not None: print_traceback(space, w_exit_error, path) return status
def parse_args(argv): config = { 'stdlib': False, # 'mcons': False, 'mode': _run, } names = { # 'file': "", # 'exprs': "", } args = [] retval = -1 i = 1 to = len(argv) while i < to: if False: pass elif argv[i] == "--jit": if to <= i + 1: print "missing argument after --jit" retval = 2 break i += 1 jitarg = argv[i] jit.set_user_param(None, jitarg) elif argv[i] in ["-h", "--help", "/?", "-?", "/h", "/help"]: print_help(argv) return (None, None, None, 0) elif argv[i] == "--": i += 1 break elif argv[i] == "--stdlib": config['stdlib'] = True i += 1 elif argv[i] == "-e": if to <= i + 1: print "missing argument after -e" retval = 5 break retval = 0 config['mode'] = _eval i += 1 names['exprs'] = argv[i] elif argv[i] in ["-u", "-t", "-l", "-p"]: arg = argv[i][1] stop = arg in ["u"] if to <= i + 1: print "missing argument after -%s" % arg retval = 5 break # if arg == "r": # suffix = "f" elif arg == "u": suffix = "t" else: suffix = arg i += 1 names['file'] = "%s.%s" % (argv[i], suffix) names['exprs'] = script_exprs(arg, argv[i]) config['mode'] = _eval retval = 0 if stop: i += 1 break elif argv[i] == "-c": arg = argv[i][1] if to < i + 1: print "missing argument after -%s" % arg retval = 5 break i += 1 names['multiple-modules'] = "%s" % (argv[i]) retval = 0 elif argv[i] == "-b": arg = argv[i][1] if to <= i + 1: print "missing argument after -%s" % arg retval = 5 break i += 1 names['byte-expand'] = "%s" % (argv[i]) retval = 0 elif argv[i] == '--save-callgraph': config['save-callgraph'] = True else: if 'file' in names: break names['file'] = argv[i] retval = 0 i += 1 if config['stdlib'] and (config['mode'] is not _eval): retval = -1 if retval == -1: print_help(argv) retval = 3 if i <= to: #pending args args = argv[i:to] return config, names, args, retval
def parse_args(argv): names = { # 'file': "", # 'exprs': "", } args = [] retval = INIT i = 1 to = len(argv) while i < to: if False: pass elif argv[i] in ["-e", "--eval"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "eval") add_name(names, 'load_arguments', argv[i]) retval = RETURN_OK elif argv[i] in ["-f", "--load", "-r", "--script"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "load") add_name(names, 'load_arguments', argv[i]) if argv[i-1] in ["-r", "--script"]: add_name(names, 'set-run-file', argv[i]) retval = RETURN_OK elif argv[i] in ["-t", "--require", "-u", "--require-script"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "file") add_name(names, 'load_arguments', argv[i]) if argv[i-1] in ["-u", "--require-script"]: add_name(names, 'set-run-file', argv[i]) config['no-lib'] = True retval = RETURN_OK elif argv[i] in ["-l", "--lib"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "lib") add_name(names, 'load_arguments', argv[i]) config['no-lib'] = True retval = RETURN_OK elif argv[i] in ["-p"]: add_name(names, 'not-implemented', argv[i]) i += 1 elif argv[i] in ["-k"]: add_name(names, 'not-implemented', argv[i]) i += 3 elif argv[i] in ["-m", "--main"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-g", "-gg", "--eval-json"]: if argv[i] == "-gg": config['stop'] = True if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'json-linklets', argv[i]) config['no-lib'] = True retval = RETURN_OK ######################### # Interaction Options ######################### elif argv[i] in ["-i", "--repl"]: config['repl'] = True config['version'] = True retval = RETURN_OK elif argv[i] in ["-n", "--no-lib"]: config['no-lib'] = True if retval == INIT: retval = JUST_EXIT elif argv[i] in ["-v", "--version"]: config['version'] = True ######################### # Configuration Options ######################### elif argv[i] in ["-c", "--no-compiled"]: config['use-compiled'] = False elif argv[i] in ["-M", "--compile-any"]: config['compile-machine-independent'] = True elif argv[i] in ["-q", "--no-init-file"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] == "-I": if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'init-lib', argv[i]) elif argv[i] in ["-X", "--collects"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-collects-dir', argv[i]) elif argv[i] in ["-G", "--config"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-config-dir', argv[i]) elif argv[i] in ["-A", "--addon"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-addon-dir', argv[i]) elif argv[i] in ["-U", "--no-user-path"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-R", "--compiled"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break add_name(names, 'not-implemented', argv[i]) i += 1 elif argv[i] in ["-C", "--cross"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-N", "--name"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-run-file', argv[i]) elif argv[i] in ["-j", "--no-jit"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-d", "--no-delay"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-b", "--binary"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-W", "--warn"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'stderr_level', argv[i]) elif argv[i] in ["-O", "--stdout"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'stdout_level', argv[i]) elif argv[i] in ["-L", "--syslog"]: if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'syslog_level', argv[i]) elif argv[i] == "--kernel": config['just_kernel'] = True config['no-lib'] = True retval = RETURN_OK elif argv[i] == '--save-callgraph': config['save-callgraph'] = True ######################### # Meta Options ######################### elif argv[i] == "--verbose": config['verbose'] = True if 'verbosity_level' not in names: add_name(names, 'verbosity_level', '-1') if to > i + 1 and not is_rkt_file(argv[i+1]) and argv[i+1] not in all_opts: vl = argv[i+1] if vl.isdigit() and int(vl) < 0: print("--verbose <level> can only be a positive number, given : %s" % vl) retval = MISSING_ARG break elif not vl.isdigit(): add_name(names, 'verbosity_keywords', vl) else: add_name(names, 'verbosity_level', vl, replace=True) i += 1 elif argv[i] == "--dev": config['dev-mode'] = True #retval = RETURN_OK elif argv[i] == "--eval-linklet": if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break config['dev-mode'] = True i += 1 add_name(names, 'eval-sexp', argv[i]) elif argv[i] == "--load-linklets": if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break if not argv[i+1].endswith(".linklet"): print "--load-linklets : expects files ending with .linklet, given : %s" % argv[i+1] retval = BAD_ARG break # eats up all the .linklets afterwards while(to > i+1 and argv[i+1] not in all_opts): if not argv[i+1].endswith(".linklet"): print "please provide files ending with .linklet, given : %s" % argv[i+1] retval = BAD_ARG break add_name(names, 'load-linklets', argv[i+1]) i += 1 if retval == BAD_ARG: break elif argv[i] == "--load-as-linklets": if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break if not argv[i+1].endswith(".rkt"): print "--load-as-linklets : expects files ending with .rkt, given : %s" % argv[i+1] retval = BAD_ARG break # eats up all the .rkt afterwards while(to > i+1 and argv[i+1] not in all_opts): if not argv[i+1].endswith(".rkt"): print "please provide files ending with .rkt, given : %s" % argv[i+1] retval = BAD_ARG break add_name(names, 'load-as-linklets', argv[i+1]) i += 1 if retval == BAD_ARG: break elif argv[i] == "--run-as-linklet": if to <= i + 1 or argv[i+1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break config['just-init'] = True config['dev-mode'] = True i += 1 add_name(names, 'run-as-linklet', argv[i]) elif argv[i] == "--load-regexp": config['load-regexp'] = True #retval = RETURN_OK elif argv[i] == "--make-linklet-zos": config['make-zos'] = True retval = RETURN_OK # elif argv[i] == "--expander-zo": # config['expander-zo'] = True # config['just-init'] = True # retval = RETURN_OK elif argv[i] == "--just-init": config['just-init'] = True retval = RETURN_OK elif argv[i] == "--jit": if to <= i + 1: print "missing argument after --jit" retval = RET_JIT break i += 1 jitarg = argv[i] jit.set_user_param(None, jitarg) elif argv[i] == "--": retval = RETURN_OK i += 1 break elif argv[i] in ["-h", "--help", "/?", "-?", "/h", "/help"]: print_help(argv) if retval == INIT: retval = JUST_EXIT elif argv[i] == '--linklets': # --used as a compile-time argument, so ignore = True else: if '.rkt' in argv[i]: add_name(names, 'loads', "file") add_name(names, 'load_arguments', argv[i]) config['no-lib'] = True retval = RETURN_OK else: print "Bad switch : %s" % argv[i] retval = MISSING_ARG i += 1 if retval == INIT: config['repl'] = True config['version'] = True retval = RETURN_OK if i <= to: #pending args args = argv[i:to] return config, names, args, retval
def entry_point(argv): i = 1 fname = None gcdump = None cgi = False fastcgi = False bench_mode = False bench_no = 0 debugger_pipes = (-1, -1) server_port = 9000 jit_param = None while i < len(argv): arg = argv[i] if arg.startswith('-'): if arg == '--gcdump': if i == len(argv) - 1: print "--gcdump requires an argument" return 1 i += 1 gcdump = argv[i] elif arg == '--cgi': cgi = True elif arg == '--server': if i == len(argv) - 1: print "--server requires an int" return 1 server_port = int(argv[i + 1]) i += 1 fastcgi = True elif arg == '--bench': bench_mode = True if i == len(argv) - 1: print "--bench requires an int" return 1 bench_no = int(argv[i + 1]) i += 1 elif arg == '--debugger_pipes': assert i + 2 < len(argv) debugger_pipes = (int(argv[i + 1]), int(argv[i + 2])) i += 2 elif arg == '--jit': if i == len(argv) - 1: print "--jit requires an argument" return 1 i += 1 jit_param = argv[i] else: print __doc__ print "Unknown parameter %s" % arg return 1 else: fname = arg break i += 1 if jit_param: from rpython.rlib.jit import set_user_param set_user_param(None, jit_param) if fastcgi: if bench_mode: print "can't specify --bench and --server" return 1 from hippy.hippyoption import is_optional_extension_enabled if not is_optional_extension_enabled("fastcgi"): print("No fastcgi support compiled in") return 1 else: return _run_fastcgi_server(server_port) rest_of_args = [] for k in range(i + 1, len(argv)): s = argv[k] assert s is not None rest_of_args.append(s) return main(fname, rest_of_args, cgi, gcdump, debugger_pipes, bench_mode, bench_no)
def parse_options(argv, config): filename = None args = [] ret = -1 i = 1 to = len(argv) while (i < to): if argv[i] == "--jit": if len(argv) == i + 1: print "missing argument after --jit" ret = 2 break i += 1 jitarg = argv[i] jit.set_user_param(None, jitarg) elif argv[i] in ["-h", "--help"]: # printing done by caller ret = 0 break elif argv[i] in ["-v", "--verbose"]: config["Verbose"] = True config["Print"] = True config["Stats"] = True CompoundShape._config.log_transformations = True elif argv[i] in ["-S", "--statistics"]: config["Stats"] = True elif argv[i] == "-E": config["Print"] = False elif argv[i] == "-R": config["ReadStatefile"] = False elif argv[i] == "-W": config["WriteStatefile"] = False elif argv[i] == "-s": if len(argv) == i + 1: print "missing argument after -s" ret = 2 break i += 1 s_t = int(argv[i]) if s_t <= 1: print "substitution threshold must be greater than 1" ret = 2 break CompoundShape._config.substitution_threshold = s_t elif argv[i] == "-w": if len(argv) == i + 1: print "missing argument after -w" ret = 2 break i += 1 CompoundShape._config.max_storage_width = int(argv[i]) elif argv[i] == "-d": if len(argv) == i + 1: print "missing argument after -d" ret = 2 break i += 1 CompoundShape._config.max_shape_depth = int(argv[i]) else: filename = argv[i] if len(argv) > i: args = argv[i+1:] break i += 1 return (filename, ret, args, config)
def parse_args(argv): names = { # 'file': "", # 'exprs': "", } args = [] retval = INIT i = 1 to = len(argv) while i < to: if False: pass elif argv[i] in ["-e", "--eval"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "eval") add_name(names, 'load_arguments', argv[i]) retval = RETURN_OK elif argv[i] in ["-f", "--load", "-r", "--script"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "load") add_name(names, 'load_arguments', argv[i]) if argv[i - 1] in ["-r", "--script"]: add_name(names, 'set-run-file', argv[i]) retval = RETURN_OK elif argv[i] in ["-t", "--require", "-u", "--require-script"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "file") add_name(names, 'load_arguments', argv[i]) if argv[i - 1] in ["-u", "--require-script"]: add_name(names, 'set-run-file', argv[i]) config['no-lib'] = True retval = RETURN_OK elif argv[i] in ["-l", "--lib"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "lib") add_name(names, 'load_arguments', argv[i]) config['no-lib'] = True retval = RETURN_OK elif argv[i] in ["-p"]: add_name(names, 'not-implemented', argv[i]) i += 1 elif argv[i] in ["-k"]: add_name(names, 'not-implemented', argv[i]) i += 3 elif argv[i] in ["-m", "--main"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-g", "-gg", "--eval-json"]: if argv[i] == "-gg": config['stop'] = True if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'json-linklets', argv[i]) config['no-lib'] = True retval = RETURN_OK ######################### # Interaction Options ######################### elif argv[i] in ["-i", "--repl"]: config['repl'] = True config['version'] = True retval = RETURN_OK elif argv[i] in ["-n", "--no-lib"]: config['no-lib'] = True if retval == INIT: retval = JUST_EXIT elif argv[i] in ["-v", "--version"]: config['version'] = True ######################### # Configuration Options ######################### elif argv[i] in ["-c", "--no-compiled"]: config['use-compiled'] = False elif argv[i] in ["-q", "--no-init-file"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] == "-I": if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'init-lib', argv[i]) elif argv[i] in ["-X", "--collects"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-collects-dir', argv[i]) elif argv[i] in ["-G", "--config"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-config-dir', argv[i]) elif argv[i] in ["-A", "--addon"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-addon-dir', argv[i]) elif argv[i] in ["-U", "--no-user-path"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-R", "--compiled"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break add_name(names, 'not-implemented', argv[i]) i += 1 elif argv[i] in ["-C", "--cross"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-N", "--name"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-run-file', argv[i]) elif argv[i] in ["-j", "--no-jit"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-d", "--no-delay"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-b", "--binary"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-W", "--warn"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'stderr_level', argv[i]) elif argv[i] in ["-O", "--stdout"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'stdout_level', argv[i]) elif argv[i] in ["-L", "--syslog"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'syslog_level', argv[i]) elif argv[i] == "--kernel": config['just_kernel'] = True config['no-lib'] = True retval = RETURN_OK elif argv[i] == '--save-callgraph': config['save-callgraph'] = True ######################### # Meta Options ######################### elif argv[i] == "--verbose": config['verbose'] = True add_name(names, 'verbosity_level', '0') if to > i + 1 and not is_rkt_file( argv[i + 1]) and argv[i + 1] not in all_opts: vl = argv[i + 1] if not vl.isdigit() or int(vl) < 0: print( "--verbose <level> can only be a natural number, given : %s" % vl) retval = MISSING_ARG break add_name(names, 'verbosity_level', vl, replace=True) i += 1 elif argv[i] == "--just-init": config['just-init'] = True retval = RETURN_OK elif argv[i] == "--jit": if to <= i + 1: print "missing argument after --jit" retval = RET_JIT break i += 1 jitarg = argv[i] jit.set_user_param(None, jitarg) elif argv[i] == "--": retval = RETURN_OK i += 1 break elif argv[i] in ["-h", "--help", "/?", "-?", "/h", "/help"]: print_help(argv) if retval == INIT: retval = JUST_EXIT else: if '.rkt' in argv[i]: add_name(names, 'loads', "file") add_name(names, 'load_arguments', argv[i]) config['no-lib'] = True retval = RETURN_OK else: print "Bad switch : %s" % argv[i] retval = MISSING_ARG i += 1 if retval == INIT: config['repl'] = True config['version'] = True retval = RETURN_OK if i <= to: #pending args args = argv[i:to] return config, names, args, retval
def entry_point(argv): jit.set_param(None, "trace_limit", 1000000) # == Main execution parameters path = None selector = None code = "" number = 0 have_number = False stringarg = None headless = True # == Other parameters poll = False interrupts = True trace = False trace_important = False space = prebuilt_space idx = 1 try: while idx < len(argv): arg = argv[idx] idx += 1 if arg in ["-h", "--help"]: _usage(argv) return 0 elif arg in ["-j", "--jit"]: jitarg, idx = get_parameter(argv, idx, arg) jit.set_user_param(interpreter.Interpreter.jit_driver, jitarg) elif arg in ["-n", "--number"]: number, idx = get_int_parameter(argv, idx, arg) have_number = True elif arg in ["-m", "--method"]: selector, idx = get_parameter(argv, idx, arg) elif arg in ["-t", "--trace"]: trace = True elif arg in ["-T"]: trace_important = True elif arg in ["-s", "--safe-trace"]: space.omit_printing_raw_bytes.activate() elif arg in ["-p", "--poll"]: poll = True elif arg in ["-a", "--arg"]: stringarg, idx = get_parameter(argv, idx, arg) elif arg in ["-r", "--run"]: code, idx = get_parameter(argv, idx, arg) elif arg in ["-i", "--no-interrupts"]: interrupts = False elif arg in ["-P", "--process"]: headless = False elif arg in ["--hacks"]: space.run_spy_hacks.activate() elif arg in ["--use-plugins"]: space.use_plugins.activate() elif arg in ["-S"]: space.strategy_factory.no_specialized_storage.activate() elif arg in ["-u"]: from spyvm.plugins.vmdebugging import stop_ui_process stop_ui_process() elif arg in ["-l", "--storage-log"]: space.strategy_factory.logger.activate() elif arg in ["-L"]: space.strategy_factory.logger.activate(aggregate=True) elif path is None: path = arg else: _usage(argv) return -1 if path is None: path = "Squeak.image" if code and selector: raise error.Exit("Cannot handle both -r and -m.") except error.Exit as e: print_error("Parameter error: %s" % e.msg) return 1 path = rpath.rabspath(path) try: stream = squeakimage.Stream(filename=path) except OSError as e: print_error("%s -- %s (LoadError)" % (os.strerror(e.errno), path)) return 1 # Load & prepare image and environment image = squeakimage.ImageReader(space, stream).create_image() interp = interpreter.Interpreter(space, image, trace=trace, trace_important=trace_important, evented=not poll, interrupts=interrupts) space.runtime_setup(argv[0], path) interp.populate_remaining_special_objects() print_error("") # Line break after image-loading characters # Create context to be executed if code or selector: if not have_number: w_receiver = space.w_nil else: w_receiver = space.wrap_int(number) if code: selector = compile_code(interp, w_receiver, code) s_frame = create_context(interp, w_receiver, selector, stringarg) if headless: space.headless.activate() context = s_frame else: create_process(interp, s_frame) context = active_context(space) else: context = active_context(space) w_result = execute_context(interp, context) print result_string(w_result) return 0
def entry_point(argv): idx = 1 path = None number = 0 benchmark = None trace = False evented = True stringarg = "" code = None as_benchmark = False while idx < len(argv): arg = argv[idx] if arg in ["-h", "--help"]: _usage(argv) return 0 elif arg in ["-j", "--jit"]: _arg_missing(argv, idx, arg) jitarg = argv[idx + 1] idx += 1 jit.set_user_param(interpreter.Interpreter.jit_driver, jitarg) elif arg in ["-n", "--number"]: _arg_missing(argv, idx, arg) number = int(argv[idx + 1]) idx += 1 elif arg in ["-m", "--method"]: _arg_missing(argv, idx, arg) benchmark = argv[idx + 1] idx += 1 elif arg in ["-t", "--trace"]: trace = True elif arg in ["-p", "--poll_events"]: evented = False elif arg in ["-a", "--arg"]: _arg_missing(argv, idx, arg) stringarg = argv[idx + 1] idx += 1 elif arg in ["-r", "--run"]: _arg_missing(argv, idx, arg) code = argv[idx + 1] as_benchmark = False idx += 1 elif arg in ["-b", "--benchmark"]: _arg_missing(argv, idx, arg) code = argv[idx + 1] as_benchmark = True idx += 1 elif path is None: path = argv[idx] else: _usage(argv) return -1 idx += 1 if path is None: path = "Squeak.image" path = rpath.rabspath(path) try: f = open_file_as_stream(path, mode="rb", buffering=0) except OSError as e: os.write(2, "%s -- %s (LoadError)\n" % (os.strerror(e.errno), path)) return 1 try: imagedata = f.readall() finally: f.close() image_reader = squeakimage.reader_for_image(space, squeakimage.Stream(data=imagedata)) image = create_image(space, image_reader) interp = interpreter.Interpreter(space, image, image_name=path, trace=trace, evented=evented) space.runtime_setup(argv[0]) if benchmark is not None: return _run_benchmark(interp, number, benchmark, stringarg) elif code is not None: return _run_code(interp, code, as_benchmark=as_benchmark) else: _run_image(interp) return 0
def parse_args(argv): config = { 'stdlib': False, # 'mcons': False, 'mode': _run, } names = { # 'file': "", # 'exprs': "", } args = [] retval = -1 i = 1 to = len(argv) while i < to: if False: pass elif argv[i] == "--jit": if to <= i + 1: print "missing argument after --jit" retval = 2 break i += 1 jitarg = argv[i] jit.set_user_param(None, jitarg) elif argv[i] in ["-h", "--help", "/?", "-?", "/h", "/help"]: print_help(argv) return (None, None, None, 0) elif argv[i] == "--": i += 1 break elif argv[i] == "--stdlib": config['stdlib'] = True i += 1 elif argv[i] == "-e": if to <= i + 1: print "missing argument after -e" retval = 5 break retval = 0 config['mode'] = _eval i += 1 names['exprs'] = argv[i] elif argv[i] in ["-u", "-t", "-l", "-p"]: arg = argv[i][1] stop = arg in ["u"] if to <= i + 1: print "missing argument after -%s" % arg retval = 5 break # if arg == "r": # suffix = "f" elif arg == "u": suffix = "t" else: suffix = arg i += 1 names['file'] = "%s.%s" % (argv[i], suffix) names['exprs'] = script_exprs(arg, argv[i]) config['mode'] = _eval retval = 0 if stop: i += 1 break elif argv[i] == "-b": arg = argv[i][1] if to <= i + 1: print "missing argument after -%s" % arg retval = 5 break i += 1 names['byte-expand'] = "%s" % (argv[i]) retval = 0 elif argv[i] == '--save-callgraph': config['save-callgraph'] = True else: if 'file' in names: break names['file'] = argv[i] retval = 0 i += 1 if config['stdlib'] and (config['mode'] is not _eval): retval = -1 if retval == -1: print_help(argv) retval = 3 if i <= to: #pending args args = argv[i:to] return config, names, args, retval
def get_printable_location(pc, prev_pc, fail, instructionlist, flags): instr = instructionlist[pc].name return "%s (%s)" % (pc, prev_pc) + " " + instr + " FAIL" * fail driver = jit.JitDriver( reds=["index", "inputstring", "choice_points", "captures"], greens=["pc", "prev_pc", "fail", "instructionlist", "flags"], get_printable_location=get_printable_location, is_recursive=True) if 0: jitoptions = environ.get("jitoptions", None) if jitoptions: jit.set_user_param(driver, jitoptions) class VMOutput(): def __init__(self, captures, fail, index): self.captures = captures self.fail = fail self.index = index def runbypattern(pattern, inputstring, index=0, flags=Flags()): bytecodestring = runpattern(pattern) instructionlist = parse(bytecodestring) instructionlist = relabel(instructionlist) return run(instructionlist, inputstring, index, flags)
def entry_point(argv): usageMsg = """\n Usage: For testing: ./target-c -t db_file query_file [query_results_file] For benchmarking: ./target-c -b [warm_up] db_file query_file """ disabled_opcodes = "" try: flag = argv[1] if flag == '--jit': jit.set_user_param(None, argv[2]) flag = argv[3] argv = [argv[0]] + argv[3:] if flag == '--disable-opcodes': disabled_opcodes = argv[2] flag = argv[3] argv = [argv[0]] + argv[3:] if flag == '-t': testingFlag = True warmup = 0 testdb = argv[2] queryPath = argv[3] elif flag == '-b': testingFlag = False warmup = 3 if len(argv) > 4: try: warmup = int(argv[2]) except ValueError: print "Error: '%s' is not a valid number for warm_up argument.%s" % (argv[2], usageMsg) return 1 testdb = argv[3] queryPath = argv[4] else: testdb = argv[2] queryPath = argv[3] else: print "Error: Unknown flag '%s'.%s" % (flag, usageMsg) return 1 except IndexError: print "Error: Not enough arguments.%s" % usageMsg return 1 if testdb != ':memory:': try: fp = os.open(testdb, os.O_RDONLY, 0777) os.close(fp) except OSError: print "Error: Can't open '%s' file provided for db_file argument.%s" % (testdb, usageMsg) return 1 try: fp = os.open(queryPath, os.O_RDONLY, 0777) queryStr = "" while True: read = os.read(fp, 4096) if len(read) == 0: break queryStr += read os.close(fp) except OSError: print "Error: Can't open '%s' file provided for query_file argument.%s" % (queryPath, usageMsg) return 1 queryRes = "" if flag == '-t' and len(argv) > 4: queryResPath = argv[4] try: fp = os.open(queryResPath, os.O_RDONLY, 0777) while True: read = os.read(fp, 4096) if len(read) == 0: break queryRes += read os.close(fp) except OSError: print "Error: Can't open '%s' file provided for query_results_file argument.%s" % (queryResPath, usageMsg) return 1 db = Sqlite3DB(testdb) query = db.execute(queryStr, use_flag_cache=not disabled_opcodes) if disabled_opcodes: query.use_translated.disable_from_cmdline(disabled_opcodes) if testingFlag: run(query, queryRes, True) else: for i in range(warmup): run(query, "", False) t1 = time.time() run(query, queryRes, False) t2 = time.time() print "%s" % (t2 - t1) return 0
def parse_args(argv): names = { # 'file': "", # 'exprs': "", } args = [] retval = INIT i = 1 to = len(argv) while i < to: if False: pass elif argv[i] in ["-e", "--eval"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "eval") add_name(names, 'load_arguments', argv[i]) retval = RETURN_OK elif argv[i] in ["-f", "--load", "-r", "--script"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "load") add_name(names, 'load_arguments', argv[i]) if argv[i - 1] in ["-r", "--script"]: add_name(names, 'set-run-file', argv[i]) retval = RETURN_OK elif argv[i] in ["-t", "--require", "-u", "--require-script"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "file") add_name(names, 'load_arguments', argv[i]) if argv[i - 1] in ["-u", "--require-script"]: add_name(names, 'set-run-file', argv[i]) config['no-lib'] = True retval = RETURN_OK elif argv[i] in ["-l", "--lib"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'loads', "lib") add_name(names, 'load_arguments', argv[i]) config['no-lib'] = True retval = RETURN_OK elif argv[i] in ["-p"]: add_name(names, 'not-implemented', argv[i]) i += 1 elif argv[i] in ["-k"]: add_name(names, 'not-implemented', argv[i]) i += 3 elif argv[i] in ["-m", "--main"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-g", "-gg", "--eval-json"]: if argv[i] == "-gg": config['stop'] = True if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'json-linklets', argv[i]) config['no-lib'] = True retval = RETURN_OK ######################### # Interaction Options ######################### elif argv[i] in ["-i", "--repl"]: config['repl'] = True config['version'] = True retval = RETURN_OK elif argv[i] in ["-n", "--no-lib"]: config['no-lib'] = True if retval == INIT: retval = JUST_EXIT elif argv[i] in ["-v", "--version"]: config['version'] = True ######################### # Configuration Options ######################### elif argv[i] in ["-c", "--no-compiled"]: config['use-compiled'] = False elif argv[i] in ["-M", "--compile-any"]: config['compile-machine-independent'] = True elif argv[i] in ["-q", "--no-init-file"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] == "-I": if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'init-lib', argv[i]) elif argv[i] in ["-X", "--collects"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-collects-dir', argv[i]) elif argv[i] in ["-G", "--config"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-config-dir', argv[i]) elif argv[i] in ["-A", "--addon"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-addon-dir', argv[i]) elif argv[i] in ["-U", "--no-user-path"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-R", "--compiled"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break add_name(names, 'not-implemented', argv[i]) i += 1 elif argv[i] in ["-C", "--cross"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-N", "--name"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'set-run-file', argv[i]) elif argv[i] in ["-j", "--no-jit"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-d", "--no-delay"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-b", "--binary"]: add_name(names, 'not-implemented', argv[i]) elif argv[i] in ["-W", "--warn"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'stderr_level', argv[i]) elif argv[i] in ["-O", "--stdout"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'stdout_level', argv[i]) elif argv[i] in ["-L", "--syslog"]: if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break i += 1 add_name(names, 'syslog_level', argv[i]) elif argv[i] == "--kernel": config['just_kernel'] = True config['no-lib'] = True retval = RETURN_OK elif argv[i] == '--save-callgraph': config['save-callgraph'] = True ######################### # Meta Options ######################### elif argv[i] == "--verbose": config['verbose'] = True if 'verbosity_level' not in names: add_name(names, 'verbosity_level', '-1') if to > i + 1 and not is_rkt_file( argv[i + 1]) and argv[i + 1] not in all_opts: vl = argv[i + 1] if vl.isdigit() and int(vl) < 0: print( "--verbose <level> can only be a positive number, given : %s" % vl) retval = MISSING_ARG break elif not vl.isdigit(): add_name(names, 'verbosity_keywords', vl) else: add_name(names, 'verbosity_level', vl, replace=True) i += 1 elif argv[i] == "--dev": config['dev-mode'] = True #retval = RETURN_OK elif argv[i] == "--racket-fasl": if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break config['racket-fasl'] = True i += 1 add_name(names, 'fasl-file', argv[i]) elif argv[i] == "--rpython-fasl": if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break config['rpython-fasl'] = True i += 1 add_name(names, 'fasl-file', argv[i]) elif argv[i] == "--eval-linklet": if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break config['dev-mode'] = True i += 1 add_name(names, 'eval-sexp', argv[i]) elif argv[i] == "--load-linklets": if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break if not argv[i + 1].endswith(".linklet"): print "--load-linklets : expects files ending with .linklet, given : %s" % argv[ i + 1] retval = BAD_ARG break # eats up all the .linklets afterwards while (to > i + 1 and argv[i + 1] not in all_opts): if not argv[i + 1].endswith(".linklet"): print "please provide files ending with .linklet, given : %s" % argv[ i + 1] retval = BAD_ARG break add_name(names, 'load-linklets', argv[i + 1]) i += 1 if retval == BAD_ARG: break elif argv[i] == "--load-as-linklets": if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break if not argv[i + 1].endswith(".rkt"): print "--load-as-linklets : expects files ending with .rkt, given : %s" % argv[ i + 1] retval = BAD_ARG break # eats up all the .rkt afterwards while (to > i + 1 and argv[i + 1] not in all_opts): if not argv[i + 1].endswith(".rkt"): print "please provide files ending with .rkt, given : %s" % argv[ i + 1] retval = BAD_ARG break add_name(names, 'load-as-linklets', argv[i + 1]) i += 1 if retval == BAD_ARG: break elif argv[i] == "--run-as-linklet": if to <= i + 1 or argv[i + 1] in all_opts: print "missing argument after %s" % argv[i] retval = MISSING_ARG break config['just-init'] = True config['dev-mode'] = True i += 1 add_name(names, 'run-as-linklet', argv[i]) elif argv[i] == "--load-regexp": config['load-regexp'] = True #retval = RETURN_OK elif argv[i] == "--make-linklet-zos": config['make-zos'] = True retval = RETURN_OK # elif argv[i] == "--expander-zo": # config['expander-zo'] = True # config['just-init'] = True # retval = RETURN_OK elif argv[i] == "--just-init": config['just-init'] = True retval = RETURN_OK elif argv[i] == "--jit": if to <= i + 1: print "missing argument after --jit" retval = RET_JIT break i += 1 jitarg = argv[i] jit.set_user_param(None, jitarg) elif argv[i] == "--": retval = RETURN_OK i += 1 break elif argv[i] in ["-h", "--help", "/?", "-?", "/h", "/help"]: print_help(argv) if retval == INIT: retval = JUST_EXIT elif argv[i] == '--linklets': # --used as a compile-time argument, so ignore = True else: if '.rkt' in argv[i]: add_name(names, 'loads', "file") add_name(names, 'load_arguments', argv[i]) config['no-lib'] = True retval = RETURN_OK else: print "Bad switch : %s" % argv[i] retval = MISSING_ARG i += 1 if retval == INIT: config['repl'] = True config['version'] = True retval = RETURN_OK if i <= to: #pending args args = argv[i:to] return config, names, args, retval
def loop(i, s): set_user_param(driver, "off") while i > s: driver.jit_merge_point(i=i, s=s) i -= 1
def parse_options(argv, config): fun_name = None ops = [] ret = -1 i = 1 to = len(argv) while (i < to): if argv[i] == "--jit": if len(argv) == i + 1: print "missing argument after --jit" ret = 2 break i += 1 jitarg = argv[i] jit.set_user_param(jitdriver, jitarg) elif argv[i] in ["-h", "--help"]: # printing done by caller ret = 0 break elif argv[i] in ["-v", "--verbose"]: config["Verbose"] = True config["Print"] = True config["Stats"] = True CompoundShape._config.log_transformations = True elif argv[i] in ["-S", "--statistics"]: config["Stats"] = True elif argv[i] == "-E": config["Print"] = False elif argv[i] == "-R": config["ReadStatefile"] = False elif argv[i] == "-W": config["WriteStatefile"] = False elif argv[i] == "-s": if len(argv) == i + 1: print "missing argument after -s" ret = 2 break i += 1 CompoundShape._config.substitution_threshold = int(argv[i]) elif argv[i] == "-w": if len(argv) == i + 1: print "missing argument after -w" ret = 2 break i += 1 CompoundShape._config.max_storage_width = int(argv[i]) elif argv[i] == "-d": if len(argv) == i + 1: print "missing argument after -d" ret = 2 break i += 1 CompoundShape._config.max_shape_depth = int(argv[i]) elif argv[i] == "-N": if len(argv) == i + 1: print "missing argument after -N" ret = 2 break i += 1 n = int(argv[i]) config["Nums"] = n if n > 0 else 1 else: fun_name = argv[i] if len(argv) > i: ops = argv[i + 1:] break i += 1 return (fun_name, ops, ret, config)
def entry_point(argv): idx = 1 path = None number = 0 benchmark = None trace = False evented = True stringarg = "" code = None as_benchmark = False while idx < len(argv): arg = argv[idx] if arg in ["-h", "--help"]: _usage(argv) return 0 elif arg in ["-j", "--jit"]: _arg_missing(argv, idx, arg) jitarg = argv[idx + 1] idx += 1 jit.set_user_param(interpreter.Interpreter.jit_driver, jitarg) elif arg in ["-n", "--number"]: _arg_missing(argv, idx, arg) number = int(argv[idx + 1]) idx += 1 elif arg in ["-m", "--method"]: _arg_missing(argv, idx, arg) benchmark = argv[idx + 1] idx += 1 elif arg in ["-t", "--trace"]: trace = True elif arg in ["-p", "--poll_events"]: evented = False elif arg in ["-a", "--arg"]: _arg_missing(argv, idx, arg) stringarg = argv[idx + 1] idx += 1 elif arg in ["-r", "--run"]: _arg_missing(argv, idx, arg) code = argv[idx + 1] as_benchmark = False idx += 1 elif arg in ["-b", "--benchmark"]: _arg_missing(argv, idx, arg) code = argv[idx + 1] as_benchmark = True idx += 1 elif path is None: path = argv[idx] else: _usage(argv) return -1 idx += 1 if path is None: path = "Squeak.image" path = rpath.rabspath(path) try: f = open_file_as_stream(path, mode="rb", buffering=0) except OSError as e: os.write(2, "%s -- %s (LoadError)\n" % (os.strerror(e.errno), path)) return 1 try: imagedata = f.readall() finally: f.close() image_reader = squeakimage.reader_for_image( space, squeakimage.Stream(data=imagedata)) image = create_image(space, image_reader) interp = interpreter.Interpreter(space, image, image_name=path, trace=trace, evented=evented) space.runtime_setup(argv[0]) if benchmark is not None: return _run_benchmark(interp, number, benchmark, stringarg) elif code is not None: return _run_code(interp, code, as_benchmark=as_benchmark) else: _run_image(interp) return 0