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)
|