-
Notifications
You must be signed in to change notification settings - Fork 0
/
jcc.py
38 lines (32 loc) · 1.01 KB
/
jcc.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
29
30
31
32
33
34
35
36
37
38
"""
Compile .jack file into binary codes.
"""
# %% import libs
from pathlib import Path
from argparse import ArgumentParser
import subprocess
# %% main program
def _main():
# CLI args
parser = ArgumentParser()
parser.add_argument("jack_files", help="Jack file(s) path.", type=str)
args = parser.parse_args()
# software paths
p_hack = Path(__file__).parent
compiler = p_hack / "Compiler/JackCompiler.py"
vm_translator = p_hack / "VMTranslator/VMTranslator.py"
assembler = p_hack / "Assembler/x64/Release/Assembler.exe"
# file paths
f_jack = Path(args.jack_files)
if f_jack.is_dir():
f_vm = f_jack
f_asm = f_jack / f"{f_jack.name}.asm"
else:
f_vm = f_jack.with_suffix(".vm")
f_asm = f_jack.with_suffix(".asm")
# software calls
subprocess.run(["python", compiler, f_jack], check=True)
subprocess.run(["python", vm_translator, f_vm], check=True)
subprocess.run([assembler, f_asm], check=True)
if __name__ == "__main__":
_main()