git @ Cat's Eye Technologies ZOWIE / 012b1ab
Package up the RPython bits into the target function. Chris Pressey 10 years ago
1 changed file(s) with 33 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
66 #
77
88 import sys
9 import os
109
1110
1211 def input():
380379 p.run()
381380
382381
383 def rpython_input():
384 s = os.read(1, 1)
385 if not s:
386 return 0
387 return ord(s[0])
388
389
390 def rpython_output(code):
391 os.write(0, unichr(code).encode('utf-8'))
392
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:
382 def target(*args):
383 global input, output
384
385 import os
386
387 def rpython_input():
388 s = os.read(1, 1)
389 if not s:
390 return 0
391 return ord(s[0])
392
393
394 def rpython_output(code):
395 os.write(0, unichr(code).encode('utf-8'))
396
397
398 def rpython_load(filename):
399 fd = os.open(filename, os.O_RDONLY, 0644)
400 text = ''
400401 chunk = os.read(fd, 1024)
401402 text += chunk
402 os.close(fd)
403 return text
404
405
406 def rpython_main(argv):
407 p = Processor()
408 program = rpython_load(argv[1])
409 p.load_string(program)
410 p.run()
411 return 0
412
413
414 def target(*args):
415 global input, output
403 while len(chunk) == 1024:
404 chunk = os.read(fd, 1024)
405 text += chunk
406 os.close(fd)
407 return text
408
409
410 def rpython_main(argv):
411 p = Processor()
412 program = rpython_load(argv[1])
413 p.load_string(program)
414 p.run()
415 return 0
416
416417 input = rpython_input
417418 output = rpython_output
418419 return rpython_main, None