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 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 loop2(g, r): set_param(None, 'function_threshold', 0) while r > 0: myjitdriver2.can_enter_jit(g=g, r=r) myjitdriver2.jit_merge_point(g=g, r=r) r += loop1(r, g) - 1 return r
def f(nval, threshold): set_param(myjitdriver, 'threshold', threshold) i, j, x = A(0), A(0), A(0) n = A(nval) pos = 0 op = '-' while pos < len(bytecode): myjitdriver.jit_merge_point(pos=pos, i=i, j=j, n=n, x=x) op = bytecode[pos] if op == 'z': j = A(0) elif op == 'i': i = i.add(1) pos = 0 myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x) continue elif op == 'j': j = j.add(1) pos = 2 myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x) continue elif op == 'I': if not (i.val < n.val): pos = 5 elif op == 'J': if not (j.val <= i.val): pos = 4 elif op == 'x': x = x.add(i.val & j.val) pos += 1 return x.val
def f(n, threshold): set_param(myjitdriver, 'threshold', threshold) i = j = x = 0 pos = 0 op = '-' while pos < len(bytecode): myjitdriver.jit_merge_point(pos=pos, i=i, j=j, n=n, x=x) op = bytecode[pos] if op == 'z': j = 0 elif op == 'i': i += 1 pos = 0 myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x) continue elif op == 'j': j += 1 pos = 2 myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x) continue elif op == 'I': if not (i < n): pos = 5 elif op == 'J': if not (j <= i): pos = 4 elif op == 'x': x = x + (i & j) pos += 1 return x
def f(n, threshold): set_param(myjitdriver, 'threshold', threshold) i = j = x = 0 pos = 0 op = '-' while pos < len(bytecode): myjitdriver.jit_merge_point(pos=pos, i=i, j=j, n=n, x=x) op = bytecode[pos] if op == 'z': j = 0 elif op == 'i': i += 1 pos = 0 myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x) continue elif op == 'j': j += 1 pos = 2 myjitdriver.can_enter_jit(pos=pos, i=i, j=j, n=n, x=x) continue elif op == 'I': if not (i < n): pos = 5 elif op == 'J': if not (j <= i): pos = 4 elif op == 'x': x = x + (i&j) pos += 1 return x
def g(m): set_param(None, 'inlining', True) set_param(None, 'trace_limit', 40) if m > 1000000: f('', 0) result = 0 for i in range(m): result += f('-' * 50 + '-c-l-', i + 100)
def g(m): set_param(None, 'inlining', True) set_param(None, 'trace_limit', 40) if m > 1000000: f('', 0) result = 0 s = '~l-' for i in range(m): result += f(s, i + 100)
def main(promoteint): set_param(None, 'retrace_limit', 0) set_param(None, 'threshold', 8) List().content1 = WNone() # ensure annotator doesn't think the fields are constants Cell().value = None List().content2 = Int() f(l, f1, c_w_none, promoteint) print "==================================================================" f(l + [l1, l2], f2, c_int, promoteint)
def loop(n): set_param(myjitdriver, "threshold", 10) pc = 0 while n: myjitdriver.can_enter_jit(n=n) myjitdriver.jit_merge_point(n=n) n = recursive(n) n -= 1 return n
def settrace(self, w_func): """Set the global trace function.""" if self.space.is_w(w_func, self.space.w_None): self.w_tracefunc = None else: self.force_all_frames() self.w_tracefunc = w_func # Increase the JIT's trace_limit when we have a tracefunc, it # generates a ton of extra ops. jit.set_param(None, 'trace_limit', 10000)
def g(m): set_param(None, 'inlining', True) # carefully chosen threshold to make sure that the inner function # cannot be inlined, but the inner function on its own is small # enough set_param(None, 'trace_limit', 40) if m > 1000000: f('', 0) result = 0 for i in range(m): result += f('-c-----------l-', i+100)
def f(x, y): set_param(myjitdriver, 'max_unroll_loops', 5) if x & 1: w = w1 else: w = w2 while y > 0: myjitdriver.can_enter_jit(x=x, y=y, w=w) myjitdriver.jit_merge_point(x=x, y=y, w=w) w = w.incr() y -= 1 return w.getvalue()
def loop(n): set_param(None, "threshold", 4) set_param(None, "trace_eagerness", 2) while n: myjitdriver.can_enter_jit(n=n) myjitdriver.jit_merge_point(n=n) if n % 5 == 0: n -= 1 if n < 50: n = recursive(n) n -= 1 return n
def interp_w(switch): jit.set_param(None, "disable_unrolling", 5000) if switch: # hack to make arguments nicht constant x = instructionlist y = input fl = flagsobj else: x = [] y = "" fl = Flags() run(x, y, flags=fl)
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 actual_entry(argv): 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) config, names, args, retval = parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String.fromstr_utf8(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) entry_flag = 'byte-expand' in names reader = JsonLoader(bytecode_expand=entry_flag) if json_ast is None: ast = reader.expand_to_ast(module_name) else: ast = reader.load_json_ast_rpython(module_name, json_ast) env = ToplevelEnv(pycketconfig) env.globalconfig.load(ast) env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) try: val = interpret_module(ast, env) finally: from pycket.prims.input_output import shutdown for callback in POST_RUN_CALLBACKS: callback(config, env) shutdown(env) return 0
def actual_entry(argv): 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", 10) config, names, args, retval = parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String.fromstr_utf8(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) entry_flag = 'byte-expand' in names reader = JsonLoader(bytecode_expand=entry_flag) if json_ast is None: ast = reader.expand_to_ast(module_name) else: ast = reader.load_json_ast_rpython(module_name, json_ast) env = ToplevelEnv(pycketconfig) env.globalconfig.load(ast) env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) try: val = interpret_module(ast, env) finally: from pycket.prims.input_output import shutdown for callback in POST_RUN_CALLBACKS: callback(config, env) shutdown(env) return 0
def main(inline): set_param(None, "threshold", 10) set_param(None, 'function_threshold', 60) if inline: set_param(None, 'inlining', True) else: set_param(None, 'inlining', False) return loop(100)
def f(): set_param(None, 'retrace_limit', -1) set_param(None, 'threshold', 1) i = 0 v1 = X(0) v2 = X(0) const.v = X(0) while i < 17: driver.jit_merge_point(i=i, v1=v1, v2=v2) driver.can_enter_jit(i=i, v1=v1, v2=v2) if i & 1 == 0: v1 = const.v v2 = X(i) else: v1 = v2 = X(i) i += 1 return None
def myportal(i): set_param(jitdriver, "threshold", 3) set_param(jitdriver, "trace_eagerness", 2) total = 0 n = i while True: jitdriver.can_enter_jit(n=n, total=total) jitdriver.jit_merge_point(n=n, total=total) try: total += f(n, total) except ValueError: total += 1 try: total += g(n) except ValueError: total -= 1 n -= h(n).meth() # this is to force a GUARD_CLASS
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 actual_entry(argv): jit.set_param(None, "trace_limit", 20000) config, names, args, retval = parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) if json_ast is None: ast = expand_to_ast(module_name) else: ast = load_json_ast_rpython(json_ast) GlobalConfig.load(ast) env = ToplevelEnv() env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) val = interpret_module(ast, env) return 0
def actual_entry(argv): 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) from pycket.env import w_global_config w_global_config.set_pycketconfig(pycketconfig) config, names, args, retval = parse_args(argv) if config['verbose']: level = int(names['verbosity_level'][0]) w_global_config.set_config_val('verbose', level) if 'verbosity_keywords' in names: w_global_config.set_verbose_keywords( names['verbosity_keywords']) if 'not-implemented' in names: print("These flags are not implemented yet : %s" % names['not-implemented']) if retval == MISSING_ARG: print("Bad switch, or missing argument in : %s" % argv[1:]) return 1 if retval == JUST_EXIT or config is None: return RETURN_OK # exit normally if 'stdout_level' in names: # -O from pycket.prims.logging import w_main_logger w_main_logger.set_stdout_level(names['stdout_level'][0]) if 'stderr_level' in names: # -W from pycket.prims.logging import w_main_logger w_main_logger.set_stderr_level(names['stderr_level'][0]) if 'syslog_level' in names: # -L from pycket.prims.logging import w_main_logger w_main_logger.set_syslog_level(names['syslog_level'][0]) current_cmd_args = [W_String.fromstr_utf8(arg) for arg in args] if 'json-linklets' in names: for linkl_json in names['json-linklets']: vvv = config['verbose'] load_inst_linklet(linkl_json, debug=vvv) try: if not config['stop']: racket_entry(names, config, current_cmd_args) except ExitException, e: pass
def f(): # Prevent all retracing of side exits. Ensures that the unroll # optimizer will attempt to jump to either the preamble or loop. set_param(driver, 'retrace_limit', -1) set_param(driver, 'threshold', 1) val = X(0) i = 0 const.unbox = X(5) while i < 17: driver.can_enter_jit(i=i, val=val) driver.jit_merge_point(i=i, val=val) # Logical & rather than comparison to confuse range analysis. # Test only succeeds on the first 2 iterations if i & -2 == 0: val = const.unbox else: val = X(i) i += 1 return 0
def f(i, j): for param, _ in unroll_parameters: defl = PARAMETERS[param] set_param(jitdriver, param, defl) set_param(jitdriver, "threshold", 3) set_param(jitdriver, "trace_eagerness", 2) total = 0 frame = Frame(i) j = float(j) prev_s = rstr.mallocstr(16) while frame.i > 3: jitdriver.can_enter_jit(frame=frame, total=total, j=j, prev_s=prev_s) jitdriver.jit_merge_point(frame=frame, total=total, j=j, prev_s=prev_s) _get_virtualizable_token(frame) total += frame.i if frame.i >= 20: frame.i -= 2 frame.i -= 1 j *= -0.712 if j + (-j): raise ValueError j += frame.i k = myabs1(myabs2(j)) if k - abs(j): raise ValueError if k - abs(-j): raise ValueError s = rstr.mallocstr(16) rgc.ll_write_final_null_char(s) rgc.ll_write_final_null_char(prev_s) if (frame.i & 3) == 0: prev_s = s return chr(total % 253)
def actual_entry(argv): jit.set_param(None, "trace_limit", 1000000) jit.set_param(None, "threshold", 131) jit.set_param(None, "trace_eagerness", 50) config, names, args, retval = parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String.fromstr_utf8(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) entry_flag = 'byte-expand' in names reader = JsonLoader(bytecode_expand=entry_flag) if json_ast is None: ast = reader.expand_to_ast(module_name) else: ast = reader.load_json_ast_rpython(module_name, json_ast) env = ToplevelEnv(pycketconfig) env.globalconfig.load(ast) env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) try: val = interpret_module(ast, env) finally: from pycket.prims.input_output import shutdown if config.get('save-callgraph', False): with open('callgraph.dot', 'w') as outfile: env.callgraph.write_dot_file(outfile) shutdown(env) return 0
def actual_entry(argv): jit.set_param(None, "trace_limit", 1000000) jit.set_param(None, "threshold", 131) jit.set_param(None, "trace_eagerness", 50) if NonConstant(False): # Hack to give os.open() the correct annotation os.open("foo", 1, 1) config, names, args, retval = parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String.fromstr_utf8(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) modtable = ModTable() modtable.enter_module(module_name) if json_ast is None: ast = expand_to_ast(module_name, modtable) else: ast = load_json_ast_rpython(json_ast, modtable) modtable.exit_module(module_name, ast) env = ToplevelEnv(pycketconfig) env.globalconfig.load(ast) env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) try: val = interpret_module(ast, env) finally: from pycket.prims.input_output import shutdown shutdown(env) return 0
def actual_entry(argv): jit.set_param(None, "trace_limit", 1000000) jit.set_param(None, "threshold", 131) jit.set_param(None, "trace_eagerness", 50) config, names, args, retval = parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String.fromstr_utf8(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) modtable = ModTable() if json_ast is None: ast = expand_to_ast(module_name, modtable) else: ast = load_json_ast_rpython(json_ast, modtable) env = ToplevelEnv(pycketconfig) env.globalconfig.load(ast) env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) try: val = interpret_module(ast, env) finally: from pycket.prims.input_output import shutdown shutdown(env) return 0
def f(i, j): for param, _ in unroll_parameters: defl = PARAMETERS[param] set_param(jitdriver, param, defl) set_param(jitdriver, "threshold", 3) set_param(jitdriver, "trace_eagerness", 2) total = 0 frame = Frame(i) j = float(j) while frame.i > 3: jitdriver.can_enter_jit(frame=frame, total=total, j=j) jitdriver.jit_merge_point(frame=frame, total=total, j=j) total += frame.i if frame.i >= 20: frame.i -= 2 frame.i -= 1 j *= -0.712 if j + (-j): raise ValueError k = myabs(j) if k - abs(j): raise ValueError if k - abs(-j): raise ValueError return chr(total % 253)
def actual_entry(argv): jit.set_param(None, "trace_limit", 1000000) config, names, args, retval = parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String.fromstr_utf8(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) modtable = ModTable() if json_ast is None: ast = expand_to_ast(module_name, modtable) else: ast = load_json_ast_rpython(json_ast, modtable) env = ToplevelEnv(pycketconfig) env.globalconfig.load(ast) env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) try: val = interpret_module(ast, env) finally: from pycket.prims.input_output import shutdown shutdown(env) return 0
def old_pycket_actual_entry(argv): 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) config, names, args, retval = old_pycket_parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String.fromstr_utf8(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) from pycket.env import w_global_config from pycket.prims.general import make_stub_predicates_no_linklet w_global_config.set_linklet_mode_off() entry_flag = 'byte-expand' in names multi_mod_flag = 'multiple-modules' in names multi_mod_map = ModuleMap(json_ast) if multi_mod_flag else None reader = JsonLoader(bytecode_expand=entry_flag, multiple_modules=multi_mod_flag, module_mapper=multi_mod_map) if json_ast is None: ast = reader.expand_to_ast(module_name) else: ast = reader.load_json_ast_rpython(module_name, json_ast) env = ToplevelEnv(pycketconfig) env.globalconfig.load(ast) env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) try: val = interpret_module(ast, env) finally: from pycket.prims.input_output import shutdown for callback in POST_RUN_CALLBACKS: callback(config, env) shutdown(env) return 0
def f(i, j): for param, _ in unroll_parameters: defl = PARAMETERS[param] set_param(jitdriver, param, defl) set_param(jitdriver, "threshold", 3) set_param(jitdriver, "trace_eagerness", 2) total = 0 frame = Frame(i) j = float(j) while frame.i > 3: jitdriver.can_enter_jit(frame=frame, total=total, j=j) jitdriver.jit_merge_point(frame=frame, total=total, j=j) total += frame.i if frame.i >= 20: frame.i -= 2 frame.i -= 1 j *= -0.712 if j + (-j): raise ValueError k = myabs1(myabs2(j)) if k - abs(j): raise ValueError if k - abs(-j): raise ValueError return chr(total % 253)
def actual_entry(argv): jit.set_param(None, "trace_limit", 1000000) jit.set_param(None, "threshold", 131) jit.set_param(None, "trace_eagerness", 50) if NonConstant(False): # Hack to give os.open() the correct annotation os.open('foo', 1, 1) config, names, args, retval = parse_args(argv) if retval != 0 or config is None: return retval args_w = [W_String.fromstr_utf8(arg) for arg in args] module_name, json_ast = ensure_json_ast(config, names) modtable = ModTable() modtable.enter_module(module_name) if json_ast is None: ast = expand_to_ast(module_name, modtable) else: ast = load_json_ast_rpython(json_ast, modtable) modtable.exit_module(module_name, ast) env = ToplevelEnv(pycketconfig) env.globalconfig.load(ast) env.commandline_arguments = args_w env.module_env.add_module(module_name, ast) try: val = interpret_module(ast, env) finally: from pycket.prims.input_output import shutdown if config.get('save-callgraph', False): with open('callgraph.dot', 'w') as outfile: env.callgraph.write_dot_file(outfile) shutdown(env) return 0
def f(argv): jit.set_param(jitdriver, "inlining", 0) code1 = MyCode() rvmprof.register_code(code1, "foo") mainloop(code1, 2, 0) return 0
def main(n): set_param(None, 'threshold', 3) set_param(None, 'trace_eagerness', 5) return f("c-l", n)
def main(c, i, _set_param, v): if _set_param: set_param(driver, 'function_threshold', 0) portal(c, i, v)
def f(): set_param(driver, "max_unroll_recursion", 10)
def f(n, enable_opts): set_param(None, 'enable_opts', hlstr(enable_opts)) return g(n)
def main(args): jit.set_param(None, 'trace_limit', 15000) u = _current u.interpret(args[1:]) u.exit(0)
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): jit.set_param(None, "trace_limit", 1000000) jit.set_param(None, "threshold", 8209) # just above 2**!3, prime jit.set_param(None, "function_threshold", 9221) # slightly more than above, also prime # == Main execution parameters space = prebuilt_space cfg = Config(space, argv) try: cfg.init_from_ini() cfg.init_from_arguments() cfg.sanitize() except error.CleanExit as e: return 0 except error.Exit as e: print_error(e.msg) return 1 try: stream = squeakimage.Stream(filename=cfg.path) except OSError as e: print_error("%s -- %s (LoadError)" % (os.strerror(e.errno), cfg.path)) return 1 if cfg.code or cfg.selector or cfg.shell: # Mark headless mode when running code or selector argv.append('-headless') # Load & prepare image and environment image = squeakimage.ImageReader(space, stream, cfg.log_image_loading).create_image() interp = interpreter.Interpreter(space, image, trace=cfg.trace, trace_important=cfg.trace_important, evented=not cfg.poll, interrupts=cfg.interrupts) space.runtime_setup(interp, cfg.exepath, argv, cfg.path, cfg.extra_arguments_idx) print_error("") # Line break after image-loading characters # Create context to be executed if cfg.shell: from rsqueakvm.util.shell import Shell code = cfg.code cfg = None Shell(interp, space, code=code).run() return 0 elif cfg.code or cfg.selector: if not cfg.have_number: w_receiver = space.w_nil else: w_receiver = space.wrap_int(cfg.number) if cfg.code: cfg.selector = compile_code(interp, w_receiver, cfg.code) s_frame = create_context(interp, w_receiver, cfg.selector, cfg.stringarg) if cfg.headless: space.headless.activate() context = s_frame else: create_process(interp, s_frame) context = active_context(space) else: context = active_context(space) cfg = None # make sure we free this w_result = execute_context(interp, context) print result_string(w_result) return 0
def _entry_point(space, argv): if IS_WINDOWS: system = "Windows" cpu = "x86_64" if IS_64BIT else "i686" else: system, _, _, _, cpu = os.uname() platform = "%s-%s" % (cpu, system.lower()) engine = "topaz" version = "1.9.3" patchlevel = 125 description = "%s (ruby-%sp%d) (git rev %s) [%s]" % (engine, version, patchlevel, RUBY_REVISION, platform) space.set_const(space.w_object, "RUBY_ENGINE", space.newstr_fromstr(engine)) space.set_const(space.w_object, "RUBY_VERSION", space.newstr_fromstr(version)) space.set_const(space.w_object, "RUBY_PATCHLEVEL", space.newint(patchlevel)) space.set_const(space.w_object, "RUBY_PLATFORM", space.newstr_fromstr(platform)) space.set_const(space.w_object, "RUBY_DESCRIPTION", space.newstr_fromstr(description)) space.set_const(space.w_object, "RUBY_REVISION", space.newstr_fromstr(RUBY_REVISION)) try: ( flag_globals_w, do_loop, path, search_path, globalized_switches, exprs, reqs, load_path_entries, 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.newsymbol("<<"), [space.newstr_fromstr(path_entry)]) for required_lib in reqs: space.send(space.w_kernel, space.newsymbol("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" % 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: raise NotImplementedError("executing from stdin on Windows") 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", 10000) 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, space.newsymbol("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, space.newsymbol("print"), [w_res]) 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
import sys from rpython import conftest class o: view = False viewloops = True conftest.option = o from rpython.rlib import jit from rpython.jit.metainterp.test.test_ajit import LLJitMixin from spyvm.test.util import import_bytecodes, read_image from spyvm import model, storage_contexts import targetrsqueak as rsqueak sys.setrecursionlimit(10000000) jit.set_param(None, "trace_limit", 1000000) import_bytecodes(__name__) test_jit = LLJitMixin() def print_result(res): if res is not None: print "Result: %r" % res # Pass a function inside here to meta-interpret it and show all encountered loops. def meta_interp(func): return test_jit.meta_interp(func, [], listcomp=True, listops=True, backendopt=True, inline=True) def load(imagename, space=None): _, interp, _, _ = read_image(imagename, space=space)