-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleGenerator.py
More file actions
67 lines (55 loc) · 2.72 KB
/
exampleGenerator.py
File metadata and controls
67 lines (55 loc) · 2.72 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
def generate_example():
"""UTIL for generating example files"""
name = input("Enter the name of example: ")
os.system(f"mkdir examples/{name}")
with open("test.pop") as f:
code = f.read()
with open(f"examples/{name}/src.pop", "w") as f:
f.write(code)
os.system(f"cp test.txt examples/{name}/test.txt")
os.system(f"python pop.py examples/{name}/src.pop --output examples/{name}/tape.byte")
os.system(f"python pop.py examples/{name}/src.pop --optimalization --output examples/{name}/optimized_tape.byte")
print("running vm for tape:")
os.system(
f"python virtualMachine.py examples/{name}/tape.byte > examples/{name}/output.txt < examples/{name}/in.txt")
print("running vm for optimized tape:")
os.system(
f"python virtualMachine.py examples/{name}/optimized_tape.byte > examples/{name}/optimized_output.txt < examples/{name}/in.txt")
def regenerate_examples():
for folder in os.listdir("examples"):
os.system(f"python pop.py examples/{folder}/src.pop --output examples/{folder}/tape.byte")
os.system(
f"python pop.py examples/{folder}/src.pop --optimalization --output examples/{folder}/optimized_tape.byte")
os.system(
f"python virtualMachine.py examples/{folder}/tape.byte > examples/{folder}/output.txt < examples/{folder}/in.txt")
os.system(
f"python virtualMachine.py examples/{folder}/optimized_tape.byte > examples/{folder}/optimized_output.txt < examples/{folder}/in.txt")
def run_examples():
os.system("mkdir dist")
for folder in os.listdir("examples"):
os.system(f"mkdir dist/{folder}")
os.system(f"python pop.py examples/{folder}/src.pop --output dist/{folder}/tape.byte")
os.system(f"python pop.py examples/{folder}/src.pop --optimalization --output dist/{folder}/o_tape.byte")
os.system(
f"python virtualMachine.py dist/{folder}/tape.byte > dist/{folder}/output.txt < examples/{folder}/in.txt")
os.system(
f"python virtualMachine.py dist/{folder}/o_tape.byte > dist/{folder}/o_output.txt < examples/{folder}/in.txt")
os.system(f"diff dist/{folder}/output.txt examples/{folder}/output.txt")
print(f"Example {folder} passed")
print("All examples passed")
def test():
os.system("mkdir dist")
os.system("python pop.py test.pop --output dist/tape.byte")
os.system("python virtualMachine.py dist/tape.byte < test.txt")
def main():
choice = input("generate or run examples or test? (g/r/t): ")
if choice == "g":
generate_example()
elif choice == "r":
regenerate_examples()
run_examples()
elif choice == "t":
test()
if __name__ == '__main__':
main()