Exemplo n.º 1
0
def setup():
    space = objspace.ObjSpace()
    stream = squeakimage.Stream(filename=imagefile)
    image = squeakimage.ImageReader(space, stream).create_image()
    interp = interpreter.Interpreter(space, image)
    w_selector = interp.perform(space.wrap_string("loopTest"), "asSymbol")
    w_object = model.W_SmallInteger(0)
    s_class = w_object.class_shadow(space)
    w_method = s_class.lookup(w_selector)
    s_frame = w_method.create_frame(space, w_object)
    return interp, s_frame
Exemplo n.º 2
0
def imagestream_mock(string):
    import StringIO
    f = StringIO.StringIO(string)
    return squeakimage.Stream(f)
Exemplo n.º 3
0
def get_45image(space):
    return squeakimage.reader_for_image(space, squeakimage.Stream(s45_image.open(mode="rb")))
Exemplo n.º 4
0
def get_minitestimage(space):
    return squeakimage.reader_for_image(space, squeakimage.Stream(minitest_image.open(mode="rb")))
Exemplo n.º 5
0
def image_stream(imagefilename):
    return squeakimage.Stream(filename=image_path(imagefilename))
Exemplo n.º 6
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
Exemplo n.º 7
0
def imagestream_mock(string):
    f = StringIO.StringIO(string)
    return squeakimage.Stream(inputfile=f)
Exemplo n.º 8
0
def open_miniimage(space):
    return squeakimage.reader_for_image(
        space, squeakimage.Stream(mini_image.open(mode="rb")))
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