Exemplo n.º 1
0
def entry_point(argv):
    rsignal.pypysig_setflag(rsignal.SIGINT)
    rsocket.rsocket_startup()

    constructor = bytecode.constructor.BytecodeConstructor()

    if len(argv) < 3:
        print_usage(argv[0])
        return 1

    trace_fd = None
    mode = argv[1]
    if mode == 'exec':
        program = argv[2]
        argv = argv[2:]
        sys_caller = sys_calls.Perform(program)
    elif mode == 'trace' and len(argv) >= 4:
        program = argv[3]
        trace_fd = open(argv[2], 'w')
        argv = argv[3:]
        sys_caller = sys_calls.TraceProxy(sys_calls.Perform(program), trace_fd)
    elif mode == 'replay' and len(argv) >= 4:
        program = argv[3]
        argv = argv[3:]
        trace_fd = open(argv[2], 'r')
        sys_caller = sys_calls.Replay(trace_fd)
    else:
        print_usage(argv[0])
        return 1

    with open(program, 'r') as fd:
        bytecode.read.read_bytecode(fd, constructor)

    arguments = [operators.list.DList([data.ByteString(arg) for arg in argv])]

    try:
        ex = executor.execute(sys_caller, constructor.get_program(), arguments)
    finally:
        if trace_fd:
            trace_fd.close()

    return 0
Exemplo n.º 2
0
    import bytecode.writer
    import load_imports

    lib_dir = os.path.join(os.path.dirname(__file__), 'lib')

    entry_module, modules = load_imports.load_imports(lib_dir, sys.argv[1])

    module_interfaces = {}
    for module_name, module in modules:
        type_checking.type_check_module(module_interfaces, module_name, module)

    modules = dict(modules)
    constructor = bytecode.constructor.BytecodeConstructor()
    with constructor as writer:
        for module in modules.itervalues():
            code_generation.generate_module(writer, module)

        entry_service = evaluation.evaluate_entry_block(modules, entry_module)
        code_generation.generate_entry(writer, entry_service, modules)

    with open(sys.argv[2], 'w') as fd:
        writer = bytecode.writer.BytecodeWriter(fd)
        bytecode.serialize.serialize_program(writer, constructor.get_program())
except:
    import traceback
    import pdb
    traceback.print_exc()
    print ''
    pdb.post_mortem()
    sys.exit(1)