class BrainFuckShitStack: def __init__(self, script, in_fd=sys.stdin, out_fd=sys.stdout): self.out_fd = out_fd self.in_fd = in_fd self.script = script self.cell = Cell() self.stack = Stack() self.code = CodeFeeder(script, {'[':']', ']':'['}) self.opcodes = { ">": self.cell.right, "<": self.cell.left, "+": self.cell.inc, "-": self.cell.dec, ".": self.print_char, ",": self.read_char, "[": self.jz, "]": self.jnz, "\\": self.push, "/": self.pop, "!": self.pvt } def run(self): for op in self.code: self.opcodes.get(op, lambda: None)() def print_char(self): self.out_fd.write(self.cell.read()) self.out_fd.flush() def read_char(self): self.cell.write(ord(self.in_fd.read(1))) def jz(self): if not self.cell: self.code.jump_ahead() def jnz(self): if self.cell: self.code.jump_back() def push(self): pushed = self.cell.read() self.stack.push(pushed) def pop(self): popped = ord(self.stack.pop()) self.cell.write(popped) def pvt(self): old_stack = str(self.stack) old_code = str(self.code) self.stack = Stack(old_code) self.code.build_from(old_stack[::-1]) self.code.loc_pointer -= 1 #inc after yield, need to fix
class BrainFuckShitStack: def __init__(self, script, in_fd=sys.stdin, out_fd=sys.stdout): self.out_fd = out_fd self.in_fd = in_fd self.script = script self.cell = Cell() self.stack = Stack() self.code = CodeFeeder(script, {'[': ']', ']': '['}) self.opcodes = { ">": self.cell.right, "<": self.cell.left, "+": self.cell.inc, "-": self.cell.dec, ".": self.print_char, ",": self.read_char, "[": self.jz, "]": self.jnz, "\\": self.push, "/": self.pop, "!": self.pvt } def run(self): for op in self.code: self.opcodes.get(op, lambda: None)() def print_char(self): self.out_fd.write(self.cell.read()) self.out_fd.flush() def read_char(self): self.cell.write(ord(self.in_fd.read(1))) def jz(self): if not self.cell: self.code.jump_ahead() def jnz(self): if self.cell: self.code.jump_back() def push(self): pushed = self.cell.read() self.stack.push(pushed) def pop(self): popped = ord(self.stack.pop()) self.cell.write(popped) def pvt(self): old_stack = str(self.stack) old_code = str(self.code) self.stack = Stack(old_code) self.code.build_from(old_stack[::-1]) self.code.loc_pointer -= 1 #inc after yield, need to fix
def __init__(self, script, in_fd=sys.stdin, out_fd=sys.stdout): self.out_fd = out_fd self.in_fd = in_fd self.script = script self.cell = Cell() self.stack = Stack() self.code = CodeFeeder(script, {'[': ']', ']': '['}) self.opcodes = { ">": self.cell.right, "<": self.cell.left, "+": self.cell.inc, "-": self.cell.dec, ".": self.print_char, ",": self.read_char, "[": self.jz, "]": self.jnz, "\\": self.push, "/": self.pop, "!": self.pvt }
def __init__(self, script, in_fd=sys.stdin, out_fd=sys.stdout): self.out_fd = out_fd self.in_fd = in_fd self.script = script self.cell = Cell() self.stack = Stack() self.code = CodeFeeder(script, {'[':']', ']':'['}) self.opcodes = { ">": self.cell.right, "<": self.cell.left, "+": self.cell.inc, "-": self.cell.dec, ".": self.print_char, ",": self.read_char, "[": self.jz, "]": self.jnz, "\\": self.push, "/": self.pop, "!": self.pvt }
def pvt(self): old_stack = str(self.stack) old_code = str(self.code) self.stack = Stack(old_code) self.code.build_from(old_stack[::-1]) self.code.loc_pointer -= 1 #inc after yield, need to fix