-
Notifications
You must be signed in to change notification settings - Fork 2
/
hsl
executable file
·48 lines (32 loc) · 907 Bytes
/
hsl
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import sys
import os.path
import tempfile
import signal
import subprocess
src = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'src')
hsl = src + '/Main.hs'
def main():
binary = os.path.join(tempfile.mkdtemp(), 'Main')
mainhs = binary + '.hs'
f = sys.argv[1:][-1]
inits = "\n\n".join(sys.argv[1:-1])
fh = open(mainhs, 'w')
fh.write(open(hsl).read() % (inits, f))
fh.close()
# TODO: set using a command-line flag
compile = False
if compile:
ghc = ['ghc', '-O2', '-i' + src, mainhs]
if subprocess.Popen(ghc, stdout=subprocess.PIPE).wait():
return
cmd = binary
else:
ghc = ['ghc', '-i' + src, mainhs, '-e', 'main']
cmd = ghc
p = subprocess.Popen(cmd)
try:
p.wait()
except (KeyboardInterrupt, IOError):
p.send_signal(signal.SIGTERM)
main()