Added pipes to intcode

master
Tibor Bizjak 2023-03-14 12:44:43 +01:00
parent 0cd8fedcbf
commit 8b0cb8d9d7
1 changed files with 18 additions and 0 deletions

View File

@ -9,6 +9,9 @@ class WaitForInput(Exception):
class Halted(Exception):
pass
class PipeError(Exception):
pass
class defaultlist(list):
"""Default list class. Allows writing and reading out of bounds."""
def __init__(self, lst, val_factory):
@ -207,6 +210,21 @@ class Interpreter(object):
pass
return self.IO.flush()
def pipe_from(self, other):
class Output(Exception):
pass
def raise_output(o):
raise Output(o)
other.comp.out_f = raise_output
def get_input():
try:
other.run()
raise PipeError
except Output as o:
return int(str(o))
self.comp.in_f = get_input
self.IO.write = other.IO.write
def copy(self):
memory = self.memory.copy()