示例#1
0
def load_compiled_chunk(filename):
    vm = VM()
    open_lib(vm)
    stream = open_file_as_stream(filename, 'r')
    w_skel = chunkio.load(stream)
    stream.close()
    vm.bootstrap(w_skel)
    vm.run()
示例#2
0
def repl():
    stdin = fdopen_as_stream(0, 'r')
    stdout = fdopen_as_stream(1, 'a')
    vm = VM()
    open_lib(vm)

    while True:
        if we_are_translated():
            # RPython -- cannot use readline
            stdout.write('> ')
            stdout.flush()
            raw_line_of_code = stdin.readline()
        else:
            # CPython -- use readline
            try:
                raw_line_of_code = raw_input('> ')
            except (EOFError, KeyboardInterrupt):
                raw_line_of_code = ''

        if not raw_line_of_code:
            break # handle EOF

        raw_line_of_code = raw_line_of_code.strip('\n') # RPy
        if not raw_line_of_code:
            continue # handle plain ENTER

        expr_list = parse_string(raw_line_of_code)
        if not expr_list:
            continue # handle whitespace in RPy

        w_skel = compile_list_of_expr(expr_list)
        # some hack so as to not return the vm?

        # to view code
        if DEBUG:
            print w_skel

        # to view code
        if DEBUG:
            continue

        vm.bootstrap(w_skel)
        vm.run()
        w_result = vm.exit_value
        if w_result is not w_unspecified:
            print w_result.to_string()
示例#3
0
def run_file(filename):
    vm = VM()
    open_lib(vm)
    vm.bootstrap(compile_list_of_expr(filename_to_expr_list(filename)))
    vm.run()