def exitFromHeadlessExecution(self, selector="", w_message=None): if not objectmodel.we_are_translated(): if getattr(self.space, "testing", False): return # During Testing do_exit = True import pdb pdb.set_trace() if not do_exit: # during debugging, we can change do_exit and go on return print "== Receiver: %s" % self.w_receiver().as_repr_string() if isinstance(w_message, W_PointersObject): fields = w_message.fetch_all(self.space) if len(fields) >= 1: print "== Selector: %s" % fields[0].selector_string() if len(fields) >= 2: w_args = fields[1] if isinstance(w_args, W_PointersObject): arg_strings = [ w_arg.selector_string() for w_arg in w_args.fetch_all(self.space) ] if len(arg_strings) > 0: print "== Arguments: %s" % ', '.join(arg_strings) print "== Smalltalk Stack:%s" % self.print_stack() if selector == "": selector = self.w_method().lookup_selector raise error.Exit("Unhandled %s in headless mode." % selector)
def init_from_ini(self): exedir = self.get_exedir() if not exedir: return inifile = rpath.rjoin(exedir, "rsqueak.ini") if os.path.exists(inifile): f = streamio.open_file_as_stream(inifile, mode="r", buffering=0) try: argini = [""] line = f.readline().strip() while len(line) > 0: if line.startswith("[") or line.startswith(";"): pass elif "=" in line: option, param = line.split("=", 1) option = option.strip() param = param.strip() param = param.strip("\"'") if param == "1": argini += ["--%s" % option] elif param == "0": pass else: argini += ["--%s" % option, param] else: raise error.Exit("Invalid line in INI file: %s" % line) line = f.readline().strip() self.parse_args(argini) finally: f.close()
def _sendSpecialSelector(self, interp, receiver, special_selector, w_args=[]): space = jit.promote(self.space) w_special_selector = getattr(space, "w_" + special_selector) s_class = receiver.class_shadow(space) w_method = s_class.lookup(w_special_selector) if w_method is None: w_method = s_class.lookup(space.w_doesNotUnderstand) self.push(receiver) # need to put receiver back on stack if w_method is None: s_class = receiver.class_shadow(self.space) assert isinstance(s_class, ClassShadow) raise error.Exit( "Missing doesNotUnderstand in hierarchy of %s" % s_class.getname()) elif w_args: self.push_all(w_args) # the arguments will be popped again in doesNotUnderstand but # jit compilation should be able to remove those operations return self._doesNotUnderstand(w_special_selector, len(w_args), interp, receiver) if not isinstance(w_method, W_CompiledMethod): raise Exception("SpecialSelector can't be an Object") s_frame = w_method.create_frame(interp.space, receiver, w_args) # ###################################################################### if interp.is_tracing(): interp.print_padded('-> %s %s' % (special_selector, s_frame.short_str())) return interp.stack_frame(s_frame, self, True)
def compile_code(interp, w_receiver, code, isclass=False, make_selector=True): if make_selector: selector = "DoIt%d\r\n" % int(time.time()) else: selector = "" space = interp.space if isclass: w_receiver_class = w_receiver else: w_receiver_class = w_receiver.getclass(space) # The suppress_process_switch flag is a hack/workaround to enable compiling code # before having initialized the image cleanly. The problem is that the TimingSemaphore is not yet # registered (primitive 136 not called), so the idle process will never be left once it is entered. # TODO - Find a way to cleanly initialize the image, without executing the active_context of the image. # Instead, we want to execute our own context. Then remove this flag (and all references to it) space.suppress_process_switch.activate() with objspace.ForceHeadless(space): if interp.image.version.is_modern: w_result = interp.perform( w_receiver_class, "compile:classified:withStamp:notifying:logSource:", w_arguments=[ space.wrap_string("".join([selector, code])), space.wrap_string("spy-run-code"), space.w_nil, space.w_nil, space.w_false ]) else: w_result = interp.perform( w_receiver_class, "compile:classified:notifying:", w_arguments=[ space.wrap_string("".join([selector, code])), space.wrap_string("spy-run-code"), space.w_nil ]) # TODO - is this expected in every image? if not isinstance(w_result, W_BytesObject): raise error.Exit( "Unexpected compilation result (probably failed to compile): %s" % result_string(w_result)) space.suppress_process_switch.deactivate() w_receiver_class.as_class_get_shadow( space).s_methoddict().sync_method_cache() return selector.strip()
def sanitize(self): self.ensure_path() if self.code and self.selector: raise error.Exit("Cannot handle both -r and -m.")
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 get_int_parameter(argv, idx, arg): param, idx = get_parameter(argv, idx, arg) try: result = int(param) except ValueError, e: raise error.Exit("Non-int argument after %s" % arg)
def get_parameter(argv, idx, arg): if len(argv) < idx + 1: raise error.Exit("Missing argument after %s" % arg) return argv[idx], idx + 1