-
Notifications
You must be signed in to change notification settings - Fork 3
/
graph.py
executable file
·28 lines (26 loc) · 906 Bytes
/
graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python
from subprocess import Popen
from external import optfunc
# enumerate smartly & print out context graph
@optfunc.main
def main(fn):
"""Usage: %prog <file>"""
# read fn
expr = open(fn).read()
# write temporary file that will pretty-print cc-converted file
cc_generator = open("cc-wrapper.ss").read() % { "expr" : expr }
f = open("cc.gen", "w")
f.write(cc_generator)
f.close()
# run temporary file, get output
p = Popen("ikarus --r6rs-script ./cc.gen > ./cc.tmp", shell=True)
p.communicate()
cc_code = open("cc.tmp").read()
# read wrapper template & fill in cc-converted code & write to file
graph_generator = open("graph-wrapper.ss").read() % { "cc_code" : cc_code }
f = open("cc.out", "w")
f.write(graph_generator)
f.close()
# run
p = Popen("ikarus --r6rs-script ./cc.out", shell=True)
p.communicate()