示例#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 entry_point(argv):
    if len(argv) == 1:
        repl()
        return 0
    elif len(argv) == 2:
        run_file(argv[1])
        return 0
    else:
        # more utilties for both RPython and CPython
        op = argv[1]
        fname = argv[2]
        if op == '-c': # compile the code and dump to another file
            outfname = argv[3]
            compile_file(fname, outfname)
            return 0
        elif op == '-r': # run compiled chunk
            load_compiled_chunk(fname)
            return 0

    # end of RPython-compatible functionalities
    if not we_are_translated():
        op = argv[1]
        fname = argv[2]
        if op == '-d': # disassemble
            disassemble_file(fname)
        elif op == '-g': # generate .hpp instruction definations
            generate_header(fname)
        elif op == '-v': # view compiled chunk
            stream = open_file_as_stream(fname, 'r')
            w_skel = chunkio.load(stream)
            stream.close()
            print w_skel
        elif op == '-t': # do cps transform
            from sanya.transform import transform_list_of_expr
            expr_list = filename_to_expr_list(fname)
            print transform_list_of_expr(expr_list)

        else:
            print 'what do you want to do?'
        return

    print 'usage:'
    print '  %s to start repl' % argv[0]
    print '  %s [filename] to run file' % argv[0]
    print '  %s -c [filename] [output] to compile file' % argv[0]
    print '  %s -r [filename] to run compiled file' % argv[0]
    return 0