pyflakes and pep8 fixes.
catseye
10 years ago
4 | 4 | # This program is in the public domain -- see the file UNLICENSE. |
5 | 5 | |
6 | 6 | import sys |
7 | ||
7 | 8 | |
8 | 9 | class Program(object): |
9 | 10 | def __init__(self, program, debug=False, super_wimp_mode=False): |
41 | 42 | self.dy = 0 |
42 | 43 | |
43 | 44 | ### helpers ### |
44 | ||
45 | ||
45 | 46 | def limit(self, x): |
46 | 47 | if x == 2: |
47 | 48 | return -1 |
50 | 51 | return x |
51 | 52 | |
52 | 53 | ### instructions ### |
53 | ||
54 | ||
54 | 55 | def left(self): |
55 | 56 | self.head -= 1 |
56 | 57 | |
85 | 86 | def output(self): |
86 | 87 | val = self.tape.get(self.head, 0) |
87 | 88 | if val == 1: |
88 | c = sys.stdout.write('1') | |
89 | sys.stdout.write('1') | |
89 | 90 | sys.stdout.flush() |
90 | 91 | elif val == 0: |
91 | c = sys.stdout.write('0') | |
92 | sys.stdout.write('0') | |
92 | 93 | sys.stdout.flush() |
93 | 94 | else: |
94 | 95 | raise ValueError("Illegal binary output value '%d'" % val) |
101 | 102 | |
102 | 103 | def execute(self): |
103 | 104 | 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)) | |
105 | 108 | command = getattr(self, name) |
106 | 109 | command() |
107 | 110 | self.wheel.pop(self.index) |
139 | 142 | instr = self.playfield.get((self.x, self.y), ' ') |
140 | 143 | name = table.get(instr, None) |
141 | 144 | 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)) | |
143 | 148 | command = getattr(self, name) |
144 | 149 | command() |
145 | 150 | self.x += self.dx |
150 | 155 | break |
151 | 156 | |
152 | 157 | ### debugging ### |
153 | ||
158 | ||
154 | 159 | def dump(self): |
155 | 160 | if not self._debug: |
156 | 161 | return |
170 | 175 | i += 1 |
171 | 176 | print "------------" |
172 | 177 | |
173 | ||
174 | 178 | def debug(self, msg): |
175 | 179 | if self._debug: |
176 | 180 | print msg |