It compiles! Runs the examples! Passes half the tests...
Chris Pressey
7 years ago
6 | 6 |
#
|
7 | 7 |
|
8 | 8 |
import sys
|
|
9 |
import os
|
9 | 10 |
|
10 | 11 |
|
11 | 12 |
def input():
|
|
380 | 381 |
|
381 | 382 |
|
382 | 383 |
def rpython_input():
|
383 | |
import os
|
384 | 384 |
s = os.read(1, 1)
|
385 | 385 |
if not s:
|
386 | 386 |
return 0
|
387 | |
return ord(s)
|
|
387 |
return ord(s[0])
|
|
388 |
|
388 | 389 |
|
389 | 390 |
def rpython_output(code):
|
390 | |
import os
|
391 | 391 |
os.write(0, unichr(code).encode('utf-8'))
|
392 | 392 |
|
393 | 393 |
|
|
394 |
def rpython_load(filename):
|
|
395 |
fd = os.open(filename, os.O_RDONLY, 0644)
|
|
396 |
text = ''
|
|
397 |
chunk = os.read(fd, 1024)
|
|
398 |
text += chunk
|
|
399 |
while len(chunk) == 1024:
|
|
400 |
chunk = os.read(fd, 1024)
|
|
401 |
text += chunk
|
|
402 |
os.close(fd)
|
|
403 |
return text
|
|
404 |
|
|
405 |
|
394 | 406 |
def rpython_main(argv):
|
395 | |
# EXPERIMENTAL!
|
396 | |
print "hi there"
|
397 | 407 |
p = Processor()
|
398 | |
p.load_string("""
|
399 | |
MOV R10, 90 ; initially it's "Z"
|
400 | |
MOV R1, R1 ; BEGIN TRANSACTION for "REPEAT"
|
401 | |
MOV R0, R10 ; output character
|
402 | |
MOV R8, R10 ; decrement character
|
403 | |
MOV R5, 1
|
404 | |
MOV R10, R8
|
405 | |
MOV R8, R10 ; test if character is above "@"
|
406 | |
MOV R5, 64
|
407 | |
MOV R3, R8 ; COMMIT AND REPEAT if non-zero
|
408 | |
""")
|
|
408 |
program = rpython_load(argv[1])
|
|
409 |
p.load_string(program)
|
409 | 410 |
p.run()
|
410 | 411 |
return 0
|
411 | 412 |
|
5 | 5 |
-> Functionality "Interpret ZOWIE Program" is implemented by
|
6 | 6 |
-> shell command
|
7 | 7 |
-> "python src/zowie.py %(test-body-file)"
|
|
8 |
|
|
9 |
-> Functionality "Interpret ZOWIE Program" is implemented by
|
|
10 |
-> shell command
|
|
11 |
-> "./zowie-c %(test-body-file)"
|
8 | 12 |
|
9 | 13 |
Display the Roman alphabet in reverse.
|
10 | 14 |
|