Ejemplo n.º 1
0
def compile_code(interp, w_receiver, code):
    selector = "DoIt%d" % int(time.time())
    space = interp.space
    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()
    
    w_result = interp.perform(
        w_receiver_class,
        "compile:classified:notifying:",
        w_arguments = [space.wrap_string("%s\r\n%s" % (selector, code)),
        space.wrap_string("spy-run-code"),
        space.w_nil]
    )
    # TODO - is this expected in every image?
    if not isinstance(w_result, model.W_BytesObject) or w_result.as_string() != selector:
        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
Ejemplo n.º 2
0
    def _doesNotUnderstand(self, w_selector, argcount, interp, receiver):
        arguments = self.pop_and_return_n(argcount)
        w_message_class = self.space.classtable["w_Message"]
        assert isinstance(w_message_class, model.W_PointersObject)
        s_message_class = w_message_class.as_class_get_shadow(self.space)
        w_message = s_message_class.new()
        w_message.store(self.space, 0, w_selector)
        w_message.store(self.space, 1, self.space.wrap_list(arguments))
        self.pop()  # The receiver, already known.

        try:
            if interp.space.headless.is_set():
                primitives.exitFromHeadlessExecution(self,
                                                     "doesNotUnderstand:",
                                                     w_message)
            return self._sendSpecialSelector(interp, receiver,
                                             "doesNotUnderstand", [w_message])
        except error.MethodNotFound:
            s_class = receiver.class_shadow(self.space)
            assert isinstance(s_class, ClassShadow)
            raise error.Exit("Missing doesNotUnderstand in hierarchy of %s" %
                             s_class.getname())
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def get_parameter(argv, idx, arg):
    if len(argv) < idx + 1:
        raise error.Exit("Missing argument after %s" % arg)
    return argv[idx], idx + 1