git @ Cat's Eye Technologies ZOWIE / 18117da
Begin RPython-izing; start trying to take out use of re module. Chris Pressey 7 years ago
6 changed file(s) with 58 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
0 *.pyc
1 zowie-c
0 syntax: glob
1
2 *.pyc
3 zowie-c
8484 There are five instruction forms. The first register is the destination
8585 register, and is written to; the second register (or immediate value) is
8686 read from. As in SMITH, square brackets indicate indirect register
87 access.
87 access. All instruction forms are case-sensitive; they must be given
88 using capital letters.
8889
8990 MOV register, immediate e.g. MOV R8, 141
9091 MOV register, register MOV R8, R9
198198 self.destination_is_indirect = False
199199
200200 def parse(self, line):
201 m = re.match(r'^\s*(\;.*)?$', line, re.IGNORECASE)
202 if m is not None:
201 line = line.strip()
202 if not line or line[0] == ';':
203203 return False
204204
205 m = re.match(r'^\s*MOV\s+R(\d+)\s*,\s*(\d+)\s*(\;.*)?$',
206 line, re.IGNORECASE)
205 if len(line) < 3 or line[0:3] != 'MOV':
206 raise SyntaxError("Could not parse line '%s'" % line)
207
208 line = line[3:].strip()
209
210 m = re.match(r'^R(\d+)\s*,\s*(\d+)\s*(\;.*)?$', line)
207211 if m is not None:
208212 self.source_is_immediate = True
209213 dest_reg = m.group(1)
215219 # We actually implement a syntactic superset of ZOWIE here -- the
216220 # closing bracket is just sugar which may be omitted or included
217221 # without changing the meaning (only the opening bracket counts!)
218 m = re.match(r'^\s*MOV\s+R(\[R)?(\d+)\]?\s*,\s*R(\[R)?(\d+)\]?'
219 r'\s*(\;.*)?$', line, re.IGNORECASE)
222 m = re.match(r'^R(\[R)?(\d+)\]?\s*,\s*R(\[R)?(\d+)\]?'
223 r'\s*(\;.*)?$', line)
220224 if m is not None:
221225 dest_ind = m.group(1)
222226 dest_reg = m.group(2)
275279 return s
276280
277281 def load(self, filename):
278 file = open(filename, 'r')
279 for line in file:
282 f = open(filename, 'r')
283 for line in f:
280284 i = Instruction()
281285 if i.parse(line):
282286 self.program.append(i)
287 f.close()
283288
284289 def load_string(self, text):
285290 for line in text.split("\n"):
326331 p.run()
327332
328333
334 def rpython_main(argv):
335 # EXPERIMENTAL!
336 print "hi there"
337 p = Processor()
338 p.load_string("""
339 MOV R10, 90 ; initially it's "Z"
340 MOV R1, R1 ; BEGIN TRANSACTION for "REPEAT"
341 MOV R0, R10 ; output character
342 MOV R8, R10 ; decrement character
343 MOV R5, 1
344 MOV R10, R8
345 MOV R8, R10 ; test if character is above "@"
346 MOV R5, 64
347 MOV R3, R8 ; COMMIT AND REPEAT if non-zero
348 """)
349 p.run()
350 return 0
351
352
353 def target(*args):
354 return rpython_main, None
355
356
329357 if __name__ == "__main__":
330358 main(sys.argv)
00 #!/bin/sh
11
2 falderal tests/ZOWIE.markdown
2 falderal --substring-error tests/ZOWIE.markdown
4545 |
4646 | MOV R0, R10 ; output accumulator (as single Unicode character)
4747 = x
48
49 The only command in the language is `MOV` and it must be in uppercase.
50
51 | cmp R11, 5
52 ?
53
54 | mov R11, 5
55 ?
56
57 Register names must be uppercase, too.
58
59 | MOV r11, 5
60 ?