git @ Cat's Eye Technologies
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).
 0 *.pyc 1 zowie-c
 0 syntax: glob 1 2 *.pyc 3 zowie-c
 84 84 There are five instruction forms. The first register is the destination 85 85 register, and is written to; the second register (or immediate value) is 86 86 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. 88 89 89 90 MOV register, immediate e.g. MOV R8, 141 90 91 MOV register, register MOV R8, R9
 198 198 self.destination_is_indirect = False 199 199 200 200 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] == ';': 203 203 return False 204 204 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) 207 211 if m is not None: 208 212 self.source_is_immediate = True 209 213 dest_reg = m.group(1) 215 219 # We actually implement a syntactic superset of ZOWIE here -- the 216 220 # closing bracket is just sugar which may be omitted or included 217 221 # 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) 220 224 if m is not None: 221 225 dest_ind = m.group(1) 222 226 dest_reg = m.group(2) 275 279 return s 276 280 277 281 def load(self, filename): 278 file = open(filename, 'r') 279 for line in file: 282 f = open(filename, 'r') 283 for line in f: 280 284 i = Instruction() 281 285 if i.parse(line): 282 286 self.program.append(i) 287 f.close() 283 288 284 289 def load_string(self, text): 285 290 for line in text.split("\n"): 326 331 p.run() 327 332 328 333 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 329 357 if __name__ == "__main__": 330 358 main(sys.argv)
+1
-1
test.sh
 0 0 #!/bin/sh 1 1 2 falderal tests/ZOWIE.markdown 2 falderal --substring-error tests/ZOWIE.markdown
 45 45 | 46 46 | MOV R0, R10 ; output accumulator (as single Unicode character) 47 47 = 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 ?