git @ Cat's Eye Technologies Beatnik / 826f20b
Add the 0-255 restrict, and fix the jump-back commands (I hope.) Chris Pressey 8 years ago
2 changed file(s) with 22 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
2626 Don't expect this interpreter to work on the example programs supplied with
2727 the specification.
2828
29 There are two bugs/shortcomings that should really be fixed someday:
30
31 * Integers on the stack can be any value supported by Python, rather
32 than limited to the range 0-255.
33 * The instructions that skip back, probably skip back the wrong amount.
34
35 Other than those two things, this interpreter seems to have the same behaviour
36 as Catatonic Porpoise's interpreter. Could use some test cases, though.
29 This interpreter seems to have the same behaviour as
30 [Catatonic Porpoise's Beatnik interpreter][]. This repository could stand
31 to contain some test cases, though.
3732
3833 `beatnik.py` also takes a `--debug` flag, which dumps some internal state
3934 to standard error as the program is run.
112107
113108 [Beatnik]: http://esolangs.org/wiki/Beatnik
114109 [wimpmode]: http://esolangs.org/wiki/Wimpmode
110 [Catatonic Porpoise's Beatnik interpreter]: http://esoteric.voxelperfect.net/files/beatnik/impl/BEATNIK.c
6262 sys.stderr.write("\n")
6363
6464
65 class Stack(object):
66 def __init__(self):
67 self._stack = []
68
69 def push(self, value):
70 self._stack.append(value % 256)
71
72 def append(self, value):
73 """for backwards compatibility"""
74 self.push(value)
75
76 def pop(self):
77 return self._stack.pop()
78
79
6580 def main(args):
6681 global DEBUG
6782 tokenize = False
98113
99114 words.append('FOXY') # stop if you get to the end
100115
101 stack = []
116 stack = Stack()
102117 pc = 0
103118 done = False
104119
150165 pc += dist
151166 elif value == 15:
152167 a = stack.pop()
153 pc += 1
154 dist = scrabble(words[pc])
168 dist = scrabble(words[pc + 1])
155169 if a == 0:
156170 pc -= dist
157171 elif value == 16:
158172 a = stack.pop()
159 pc += 1
160 dist = scrabble(words[pc])
173 dist = scrabble(words[pc + 1])
161174 if a != 0:
162175 pc -= dist
163176 elif value == 17: