Superficially Skulptify, but would prolly be nicer to reimpl in JS.
catseye
11 years ago
6 | 6 | import sys |
7 | 7 | |
8 | 8 | |
9 | # check if running under Skulpt, and if so, apply appropriate modifications | |
10 | if getattr(sys, 'resetTimeout', None) is not None: | |
11 | __name__ = '__skulpt__' | |
12 | ||
13 | ||
9 | 14 | class Program(object): |
10 | def __init__(self, program, debug=False, super_wimp_mode=False): | |
15 | def __init__(self, debug=False, super_wimp_mode=False): | |
11 | 16 | self.wheel = [ |
12 | 17 | 'left', |
13 | 18 | 'right', |
24 | 29 | self.insertpos = 'bottom' |
25 | 30 | self._debug = debug |
26 | 31 | self._super_wimp_mode = super_wimp_mode |
32 | self.maxx = 0 | |
33 | self.maxy = 0 | |
34 | self.x = 0 | |
35 | self.y = 0 | |
36 | self.dx = 1 | |
37 | self.dy = 0 | |
38 | ||
39 | def load_string(self, text): | |
27 | 40 | y = 0 |
28 | self.maxx = 0 | |
29 | for line in file: | |
41 | for line in text.split('\n'): | |
30 | 42 | line = line.rstrip('\r\n') |
31 | 43 | x = 0 |
32 | 44 | while x < len(line): |
36 | 48 | self.maxx = x |
37 | 49 | y += 1 |
38 | 50 | self.maxy = y |
39 | self.x = 0 | |
40 | self.y = 0 | |
41 | self.dx = 1 | |
42 | self.dy = 0 | |
51 | ||
52 | def load_file(self, filename): | |
53 | self.load_string(open(filename, 'r').read()) | |
43 | 54 | |
44 | 55 | ### helpers ### |
45 | 56 | |
188 | 199 | if sys.argv[1] == '--super-wimp-mode': |
189 | 200 | super_wimp_mode = True |
190 | 201 | sys.argv.pop(1) |
191 | with open(sys.argv[1]) as file: | |
192 | p = Program(file, debug=debug, super_wimp_mode=super_wimp_mode) | |
202 | p = Program(debug=debug, super_wimp_mode=super_wimp_mode) | |
203 | p.load_file(sys.argv[1]) | |
193 | 204 | p.dump() |
194 | 205 | p.run() |