) parser.add_argument("program", help="program to run") args = parser.parse_args() vm = Vm(open(args.program).read()) for pos, val in args.tape: vm.set_tape(pos, val) log = open(args.log, "w") if args.log else None while True: halted = vm.run() output = vm.drain_output() if args.raw: # In raw mode we might get no output, no point printing nothing. if output: print(" ".join(map(str, output))) else: print("".join(map(try_chr, output)), end="") if halted: break data = input() if args.inputs is None else args.inputs.pop(0) if log: log.write(data + "\n") if args.raw: vm.input(int(data)) else: vm.input_line(data) print() # Make sure we end on a newline.
def run(program): droid = Vm(data(21).read()) for line in program.strip().splitlines(): droid.input_line(line) print(droid.complete()[-1])