Finish homework
This commit is contained in:
@@ -62,7 +62,18 @@ if __name__ == "__main__":
|
||||
|
||||
# Load machine
|
||||
machine = MaMa(prog, [4, 6])
|
||||
journal = machine.run()
|
||||
|
||||
with open("run.txt", "w") as f:
|
||||
i = 1
|
||||
for step in journal:
|
||||
s = step["p_stack"]
|
||||
p = step["p_prog"]
|
||||
S = tuple(step["stack"].values())
|
||||
f.write(f"{i}: ({s},{p},{S})\n")
|
||||
i += 1
|
||||
|
||||
# Visualize finished execution using journal
|
||||
machine = MaMa(prog, [4, 6])
|
||||
gui = MaMaGUI(machine)
|
||||
gui.display()
|
||||
|
||||
43
Uebung-01/run.txt
Normal file
43
Uebung-01/run.txt
Normal file
@@ -0,0 +1,43 @@
|
||||
1: (1,0,(4, 6))
|
||||
2: (2,1,(4, 6, 4))
|
||||
3: (3,2,(4, 6, 4, 6))
|
||||
4: (1,3,(4, 6, 4, 6))
|
||||
5: (2,4,(4, 6, 6, 6))
|
||||
6: (3,5,(4, 6, 6, 4))
|
||||
7: (1,6,(4, 6, 6, 4))
|
||||
8: (2,7,(4, 6, 6, 4))
|
||||
9: (3,8,(4, 6, 6, 4))
|
||||
10: (2,9,(4, 6, 2, 4))
|
||||
11: (1,10,(4, 2, 2, 4))
|
||||
12: (1,15,(4, 2, 2, 4))
|
||||
13: (2,16,(4, 2, 4, 4))
|
||||
14: (3,17,(4, 2, 4, 0))
|
||||
15: (1,18,(4, 2, 4, 0))
|
||||
16: (1,3,(4, 2, 4, 0))
|
||||
17: (2,4,(4, 2, 2, 0))
|
||||
18: (3,5,(4, 2, 2, 4))
|
||||
19: (1,11,(4, 2, 2, 4))
|
||||
20: (2,12,(4, 2, 4, 4))
|
||||
21: (3,13,(4, 2, 4, 2))
|
||||
22: (2,14,(4, 2, 2, 2))
|
||||
23: (1,15,(2, 2, 2, 2))
|
||||
24: (2,16,(2, 2, 2, 2))
|
||||
25: (3,17,(2, 2, 2, 0))
|
||||
26: (1,18,(2, 2, 2, 0))
|
||||
27: (1,3,(2, 2, 2, 0))
|
||||
28: (2,4,(2, 2, 2, 0))
|
||||
29: (3,5,(2, 2, 2, 2))
|
||||
30: (1,11,(2, 2, 2, 2))
|
||||
31: (2,12,(2, 2, 2, 2))
|
||||
32: (3,13,(2, 2, 2, 2))
|
||||
33: (2,14,(2, 2, 0, 2))
|
||||
34: (1,15,(0, 2, 0, 2))
|
||||
35: (2,16,(0, 2, 0, 2))
|
||||
36: (3,17,(0, 2, 0, 0))
|
||||
37: (1,19,(0, 2, 0, 0))
|
||||
38: (2,20,(0, 2, 0, 0))
|
||||
39: (3,21,(0, 2, 0, 2))
|
||||
40: (2,22,(2, 2, 0, 2))
|
||||
41: (1,23,(2, 0, 0, 2))
|
||||
42: (0,24,(2, 0, 0, 2))
|
||||
43: (0,24,(2, 0, 0, 2))
|
||||
@@ -1,31 +0,0 @@
|
||||
from MaMaGUI import MaMaGUI
|
||||
from MaMaMa import MaMaMa # ← use macro-capable class
|
||||
|
||||
if __name__ == "__main__":
|
||||
prog = {
|
||||
0: 'outer',
|
||||
1: 'stop'
|
||||
}
|
||||
|
||||
# use MaMaMa instead of MaMa
|
||||
machine = MaMaMa(prog, [4, 6])
|
||||
|
||||
inner_prog = [
|
||||
'push(1)',
|
||||
'push(2)',
|
||||
'add',
|
||||
'stop'
|
||||
]
|
||||
|
||||
outer_prog = [
|
||||
'push(10)',
|
||||
'inner',
|
||||
'mult',
|
||||
'stop'
|
||||
]
|
||||
|
||||
machine.add_macro("inner", inner_prog, [])
|
||||
machine.add_macro("outer", outer_prog, [])
|
||||
|
||||
gui = MaMaGUI(machine)
|
||||
gui.display()
|
||||
Reference in New Issue
Block a user