示例#1
0
def main(filename, ticks, silent, debug, compat_debug, debug_lines,
         autostep_debug, head):
    global interpreter

    if autostep_debug is not False:
        autostep_debug = float(autostep_debug)

    if ticks is not False:
        ticks = int(ticks)

    head = int(head)

    io_callbacks = Default_IO_Callbacks(ticks, silent, debug, compat_debug,
                                        debug_lines, autostep_debug, head)

    file_path = sys.argv[1]

    program_dir = os.path.dirname(os.path.abspath(file_path))

    with open(file_path, 'r') as file:
        program = file.readlines()

    try:
        interpreter = AsciiDotsInterpreter(program, program_dir, io_callbacks)
        interpreter.run()
    except Exception as e:
        io_callbacks.on_finish()
        interpreter.terminate()
        raise e
示例#2
0
def check_output(name, input='', run_in_parallel=True):
    env = Env()
    env.io = KeepOutputIOCallbacks(env, input)

    with open('test/' + name + '.dots', encoding='utf-8') as file:
        program = file.read()
    print(program, '---', sep='' )   
    interpreter = AsciiDotsInterpreter(env, program, 'test', run_in_parallel)
    print(interpreter.env.world.map)
    try:
        interpreter.run()
    except DotsExit:
        pass

    return env.io.output
示例#3
0
def main(filename='--',
         ticks=False,
         silent=False,
         debug=False,
         compat_debug=False,
         debug_lines=default_debug_lines,
         autostep_debug=False,
         head=-1):
    global interpreter

    if autostep_debug is not False:
        autostep_debug = float(autostep_debug)

    if ticks is not False:
        ticks = int(ticks)

    head = int(head)

    io_callbacks = Default_IO_Callbacks(ticks, silent, debug, compat_debug,
                                        debug_lines, autostep_debug, head)

    program_dir = '.'

    program = []
    while True:
        line = input('$ ')
        if line.rstrip() == '%EOF':
            break
        else:
            program.append(line)

    # print(program, flush=True)

    try:
        interpreter = AsciiDotsInterpreter(program, program_dir, io_callbacks)
        interpreter.run()
    except Exception as e:
        io_callbacks.on_finish()
        interpreter.terminate()
        print(e)
示例#4
0
@click.option('--autostep_debug', '-a', default=False, help='The time between every tick')
@click.option('--output_limit', '-o', default=0, help='Terminate the program after N outputs.')
@click.option('--ticks', '-t', default=0, help='Terminate the program after N ticks.')
@click.option('--silent', '-s', is_flag=True, help='No printing, for benchmarking.')
@click.option('--compat_debug', '-w', is_flag=True, help='Force the debug rendering without ncurses.')
@click.option('--debug_lines', '-l', default=default_debug_lines, help='The size of the debug view.')
@click.option('--async', '-y', is_flag=True, help='Only one dot moves at a time. Easier to debug.')
def main(filename, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, output_limit, async):
    global interpreter

    if autostep_debug is not False:
        autostep_debug = float(autostep_debug)

    compat_debug = compat_debug or compat_debug_default

    run_in_parallel = not async

    env = Env()
    env.io = DefaultIOCallbacks(env, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, output_limit)

    program_dir = os.path.dirname(os.path.abspath(filename))
    with open(filename, encoding='utf-8') as file:
        program = file.read()

    interpreter = AsciiDotsInterpreter(env, program, program_dir, run_in_parallel)
    interpreter.run()


if __name__ == "__main__":
    main()