git @ Cat's Eye Technologies Jolverine / 6469027
pyflakes and pep8 fixes. catseye 10 years ago
1 changed file(s) with 12 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
44 # This program is in the public domain -- see the file UNLICENSE.
55
66 import sys
7
78
89 class Program(object):
910 def __init__(self, program, debug=False, super_wimp_mode=False):
4142 self.dy = 0
4243
4344 ### helpers ###
44
45
4546 def limit(self, x):
4647 if x == 2:
4748 return -1
5051 return x
5152
5253 ### instructions ###
53
54
5455 def left(self):
5556 self.head -= 1
5657
8586 def output(self):
8687 val = self.tape.get(self.head, 0)
8788 if val == 1:
88 c = sys.stdout.write('1')
89 sys.stdout.write('1')
8990 sys.stdout.flush()
9091 elif val == 0:
91 c = sys.stdout.write('0')
92 sys.stdout.write('0')
9293 sys.stdout.flush()
9394 else:
9495 raise ValueError("Illegal binary output value '%d'" % val)
101102
102103 def execute(self):
103104 name = self.wheel[self.index]
104 self.debug("* EXECUTING %s @ (%d,%d)" % (name, self.x, self.y))
105 indent = ' ' * 20
106 self.debug("*%sEXECUTING %s @ (%d,%d)" %
107 (indent, name, self.x, self.y))
105108 command = getattr(self, name)
106109 command()
107110 self.wheel.pop(self.index)
139142 instr = self.playfield.get((self.x, self.y), ' ')
140143 name = table.get(instr, None)
141144 if name is not None:
142 self.debug("* WIMPZECUTING %s @ (%d,%d)" % (name, self.x, self.y))
145 indent = ' ' * 20
146 self.debug("*%sWIMPZECUTING %s @ (%d,%d)" %
147 (indent, name, self.x, self.y))
143148 command = getattr(self, name)
144149 command()
145150 self.x += self.dx
150155 break
151156
152157 ### debugging ###
153
158
154159 def dump(self):
155160 if not self._debug:
156161 return
170175 i += 1
171176 print "------------"
172177
173
174178 def debug(self, msg):
175179 if self._debug:
176180 print msg