File tree 1 file changed +14
-6
lines changed
1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -46,33 +46,41 @@ def c_3e0(self):
46
46
sys .stdout .write (chr (v ))
47
47
48
48
def loadSource ():
49
- text = sys .stdin .read ().splitlines ()
49
+ texts = sys .stdin .read ()
50
+ text = texts .splitlines ()
50
51
if len (text ) < 3 :
51
52
raise Exception ('improper script invocation' )
52
53
inputCount = int (text [0 ].strip ())
53
54
return (text [inputCount + 1 :], text [1 : inputCount + 1 ])
54
55
55
56
def main ():
57
+ from StringIO import StringIO
58
+ import sys
56
59
print ("Content-Type: text/plain" )
57
- headerSent = False
58
60
59
61
try :
60
62
src , inputData = loadSource ()
61
63
prg = translator .translate (src )
62
64
print ("Program-Size: " + str (prg ['_top' ]))
63
- print ('' )
64
- headerSent = True
65
65
cpu = EnhancedExecutor ()
66
66
if len (inputData ) == 1 :
67
67
if cpu .fetchState (inputData [0 ]):
68
68
inputData = []
69
69
cpu .inputData = '\n ' .join (inputData )
70
+ old_stdout = sys .stdout
71
+ my_stdout = StringIO ()
72
+ sys .stdout = my_stdout
70
73
cpu .run (prg )
74
+ sys .stdout = old_stdout
75
+ print ("Program-Cycles: " + str (cpu .cycles ))
76
+ print ('' )
77
+ result = my_stdout .getvalue ()
78
+ sys .stdout .write (result )
71
79
if len (inputData ) == 0 :
72
80
cpu .printRegs ()
73
81
except Exception as e :
74
- if not headerSent :
75
- print ('' )
82
+ sys . stdout = old_stdout
83
+ print ('' )
76
84
print ("Error: %s\n " % e )
77
85
78
86
main ()
You can’t perform that action at this time.
0 commit comments