]> Witch of Git - ivy/blob - tools/run.py
[Parser] Support code with trailing comments
[ivy] / tools / run.py
1 #!/usr/bin/env python3
2 import argparse
3 import subprocess
4 import tempfile
5 from pathlib import Path
6
7 import trace
8
9
10 root = Path(__file__).parent.parent
11 ivy = root / 'target' / 'release' / 'ivy'
12 library_path = root / 'rt' / 'target' / 'release'
13
14
15 def compile(source, output):
16 subprocess.run(
17 [ivy, source, '-o', output],
18 env={'LIBRARY_PATH': library_path},
19 check=True,
20 )
21
22
23 def run(script, only_debug=True):
24 with tempfile.TemporaryDirectory() as d:
25 binary = Path(d) / 'a.out'
26 compile(script, output=binary)
27 trace.trace(binary, only_debug)
28
29
30 def main():
31 parser = argparse.ArgumentParser()
32 parser.add_argument('script')
33 parser.add_argument('-v', '--verbose', action='store_true')
34 args = parser.parse_args()
35 run(args.script, not args.verbose)
36
37
38 if __name__ == '__main__':
39 main()