pytunium 0.3__tar.gz → 0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytunium-0.3/pytunium.egg-info → pytunium-0.4}/PKG-INFO +17 -9
- {pytunium-0.3 → pytunium-0.4}/README.md +16 -8
- {pytunium-0.3 → pytunium-0.4}/pytunium/__init__.py +1 -1
- {pytunium-0.3 → pytunium-0.4}/pytunium/gui.py +55 -21
- {pytunium-0.3 → pytunium-0.4/pytunium.egg-info}/PKG-INFO +17 -9
- {pytunium-0.3 → pytunium-0.4}/LICENSE.txt +0 -0
- {pytunium-0.3 → pytunium-0.4}/pyproject.toml +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium/__main__.py +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium/examples/Hello.jas +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium/examples/Primes.jas +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium/examples/Sum.jas +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium/loader.py +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium/machine.py +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium/program.py +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium/values.py +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium.egg-info/SOURCES.txt +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium.egg-info/dependency_links.txt +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium.egg-info/entry_points.txt +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium.egg-info/requires.txt +0 -0
- {pytunium-0.3 → pytunium-0.4}/pytunium.egg-info/top_level.txt +0 -0
- {pytunium-0.3 → pytunium-0.4}/setup.cfg +0 -0
- {pytunium-0.3 → pytunium-0.4}/tests/test_machine.py +0 -0
- {pytunium-0.3 → pytunium-0.4}/tests/test_program.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytunium
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4
|
|
4
4
|
Summary: A simulator for programs written in the JVM assembler language of pytunia
|
|
5
5
|
Author: Karl Stroetmann
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -99,6 +99,7 @@ animation).
|
|
|
99
99
|
| **Play** / Return | runs the program, animated with the chosen speed |
|
|
100
100
|
| **Step** / Space, → | executes one instruction |
|
|
101
101
|
| **Step Over** / ⇧Space, ⇧→ | like Step, but a method call is executed completely (see below) |
|
|
102
|
+
| **Step Out** / ↑ | executes the rest of the current method (see below) |
|
|
102
103
|
| **Stop** / Return, Esc | stops Play |
|
|
103
104
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
104
105
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -110,14 +111,21 @@ animation).
|
|
|
110
111
|
Reset reads the file again, so you can edit the program in an editor and
|
|
111
112
|
press Reset to simulate the new version.
|
|
112
113
|
|
|
113
|
-
**Step Over**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
**Step Over** and **Step Out** are named after the buttons of the same names in
|
|
115
|
+
debuggers.
|
|
116
|
+
|
|
117
|
+
* **Step Over**: if the next instruction is `invokestatic`, the whole call is
|
|
118
|
+
executed, including all the calls made inside it, and the simulation stops
|
|
119
|
+
at the instruction after the call. The call and the return are animated;
|
|
120
|
+
the body of the method runs without animation. For any other instruction,
|
|
121
|
+
Step Over does the same as Step, so pressing Step Over repeatedly walks
|
|
122
|
+
through `main` without descending into the methods it calls.
|
|
123
|
+
* **Step Out** executes the rest of the current method and stops in the
|
|
124
|
+
calling method, at the instruction after the call. The return is animated.
|
|
125
|
+
In a recursive method, Step Out leaves only the current call. In `main`,
|
|
126
|
+
which has no caller, the button is disabled.
|
|
127
|
+
|
|
128
|
+
A breakpoint, a warning or an error stops both earlier, and so does Stop.
|
|
121
129
|
|
|
122
130
|
## The memory model
|
|
123
131
|
|
|
@@ -69,6 +69,7 @@ animation).
|
|
|
69
69
|
| **Play** / Return | runs the program, animated with the chosen speed |
|
|
70
70
|
| **Step** / Space, → | executes one instruction |
|
|
71
71
|
| **Step Over** / ⇧Space, ⇧→ | like Step, but a method call is executed completely (see below) |
|
|
72
|
+
| **Step Out** / ↑ | executes the rest of the current method (see below) |
|
|
72
73
|
| **Stop** / Return, Esc | stops Play |
|
|
73
74
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
74
75
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -80,14 +81,21 @@ animation).
|
|
|
80
81
|
Reset reads the file again, so you can edit the program in an editor and
|
|
81
82
|
press Reset to simulate the new version.
|
|
82
83
|
|
|
83
|
-
**Step Over**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
**Step Over** and **Step Out** are named after the buttons of the same names in
|
|
85
|
+
debuggers.
|
|
86
|
+
|
|
87
|
+
* **Step Over**: if the next instruction is `invokestatic`, the whole call is
|
|
88
|
+
executed, including all the calls made inside it, and the simulation stops
|
|
89
|
+
at the instruction after the call. The call and the return are animated;
|
|
90
|
+
the body of the method runs without animation. For any other instruction,
|
|
91
|
+
Step Over does the same as Step, so pressing Step Over repeatedly walks
|
|
92
|
+
through `main` without descending into the methods it calls.
|
|
93
|
+
* **Step Out** executes the rest of the current method and stops in the
|
|
94
|
+
calling method, at the instruction after the call. The return is animated.
|
|
95
|
+
In a recursive method, Step Out leaves only the current call. In `main`,
|
|
96
|
+
which has no caller, the button is disabled.
|
|
97
|
+
|
|
98
|
+
A breakpoint, a warning or an error stops both earlier, and so does Stop.
|
|
91
99
|
|
|
92
100
|
## The memory model
|
|
93
101
|
|
|
@@ -7,7 +7,7 @@ working area where the computation of every instruction is displayed.
|
|
|
7
7
|
python3 -m pytunium Sum.jas
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
__version__ = "0.
|
|
10
|
+
__version__ = "0.4"
|
|
11
11
|
|
|
12
12
|
from .program import parse, Program, Method, Instruction, SourceError
|
|
13
13
|
from .machine import Machine, MachineError, Event
|
|
@@ -177,9 +177,13 @@ class App:
|
|
|
177
177
|
self.event = None # the last Event
|
|
178
178
|
self.anim = None # the running Animation
|
|
179
179
|
self.playing = False
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
self.
|
|
180
|
+
# mode is "play", or "call" while Step Over or Step Out runs until the
|
|
181
|
+
# frame above call_depth frames returns
|
|
182
|
+
self.mode = None
|
|
183
|
+
self.call_depth = None # number of frames after that return
|
|
184
|
+
self.call_start = None # number of steps when the button was pressed
|
|
185
|
+
self.call_button = None # "Step Over" or "Step Out"
|
|
186
|
+
self.call_status = None # what the status line shows meanwhile
|
|
183
187
|
self.play_job = None
|
|
184
188
|
self.breakpoints = set()
|
|
185
189
|
self.view_base = 0 # the lowest address that is visible
|
|
@@ -243,9 +247,12 @@ class App:
|
|
|
243
247
|
self.b_step = ttk.Button(bar, text="→ Step", command=self.step, takefocus=0)
|
|
244
248
|
self.b_over = ttk.Button(bar, text="↷ Step Over", command=self.step_over,
|
|
245
249
|
takefocus=0)
|
|
250
|
+
self.b_out = ttk.Button(bar, text="↑ Step Out", command=self.step_out,
|
|
251
|
+
takefocus=0)
|
|
246
252
|
self.b_stop = ttk.Button(bar, text="■ Stop", command=self.stop, takefocus=0)
|
|
247
253
|
self.b_reset = ttk.Button(bar, text="↺ Reset", command=self.reset, takefocus=0)
|
|
248
|
-
for b in (self.b_play, self.b_step, self.b_over, self.
|
|
254
|
+
for b in (self.b_play, self.b_step, self.b_over, self.b_out, self.b_stop,
|
|
255
|
+
self.b_reset):
|
|
249
256
|
b.pack(side="left", padx=(0, 6))
|
|
250
257
|
ttk.Separator(bar, orient="vertical").pack(side="left", fill="y", padx=10)
|
|
251
258
|
ttk.Label(bar, text="Speed").pack(side="left")
|
|
@@ -336,6 +343,7 @@ class App:
|
|
|
336
343
|
r.bind("<Right>", lambda e: self.step())
|
|
337
344
|
r.bind("<Shift-space>", lambda e: self.step_over())
|
|
338
345
|
r.bind("<Shift-Right>", lambda e: self.step_over())
|
|
346
|
+
r.bind("<Up>", lambda e: self.step_out())
|
|
339
347
|
r.bind("<Return>", lambda e: self.stop() if self.playing else self.play())
|
|
340
348
|
r.bind("<Escape>", lambda e: self.stop())
|
|
341
349
|
r.bind("<%s-r>" % mod, lambda e: self.reset())
|
|
@@ -392,8 +400,9 @@ class App:
|
|
|
392
400
|
if not result.checked_by_pytunia:
|
|
393
401
|
self.message("pytunia is not installed, so the syntax has not been checked "
|
|
394
402
|
"by the assembler (pip install pytunia).", "info")
|
|
395
|
-
self.message("Space = Step, Shift+Space = Step Over,
|
|
396
|
-
"Click a line number to set a breakpoint.",
|
|
403
|
+
self.message("Space = Step, Shift+Space = Step Over, ↑ = Step Out, "
|
|
404
|
+
"Return = Play/Stop. Click a line number to set a breakpoint.",
|
|
405
|
+
"info")
|
|
397
406
|
self.view_base = 0
|
|
398
407
|
self._auto_view(None)
|
|
399
408
|
self._highlight_lines()
|
|
@@ -517,6 +526,8 @@ class App:
|
|
|
517
526
|
self.b_play.state(["!disabled"] if running and not self.playing else ["disabled"])
|
|
518
527
|
self.b_step.state(["!disabled"] if running else ["disabled"])
|
|
519
528
|
self.b_over.state(["!disabled"] if running else ["disabled"])
|
|
529
|
+
# main has no caller to return to
|
|
530
|
+
self.b_out.state(["!disabled"] if running and len(m.frames) > 1 else ["disabled"])
|
|
520
531
|
self.b_stop.state(["!disabled"] if self.playing else ["disabled"])
|
|
521
532
|
self.b_reset.state(["!disabled"] if self.path else ["disabled"])
|
|
522
533
|
if m is None:
|
|
@@ -524,7 +535,7 @@ class App:
|
|
|
524
535
|
else:
|
|
525
536
|
line = m.current_line()
|
|
526
537
|
where = ("%s · line %d" % (m.method.name, line)) if line else ""
|
|
527
|
-
playing =
|
|
538
|
+
playing = self.call_status if self.mode == "call" else "playing"
|
|
528
539
|
state = {"running": playing if self.playing else "ready",
|
|
529
540
|
"finished": "finished", "error": "stopped by an error"}[m.state]
|
|
530
541
|
status = " ".join(s for s in (where, "step %d" % m.steps, state) if s)
|
|
@@ -574,22 +585,43 @@ class App:
|
|
|
574
585
|
if insn is None or insn.op != "invokestatic" or not insn.supported:
|
|
575
586
|
self._step(None)
|
|
576
587
|
return
|
|
577
|
-
self.
|
|
578
|
-
|
|
579
|
-
self.
|
|
588
|
+
self._start_call("Step Over", len(m.frames),
|
|
589
|
+
"executing the call of %s" % insn.args[0].name)
|
|
590
|
+
self._step(self._after_play_step) # the call, animated
|
|
591
|
+
|
|
592
|
+
def step_out(self):
|
|
593
|
+
"""Executes the rest of the current method: the simulation stops in
|
|
594
|
+
the calling method, after the call (or earlier at a breakpoint, a
|
|
595
|
+
warning or an error). The return is animated."""
|
|
596
|
+
if self.playing:
|
|
597
|
+
self.stop()
|
|
598
|
+
if self.anim is not None and not self.anim.done:
|
|
599
|
+
self.anim.finish()
|
|
600
|
+
m = self.machine
|
|
601
|
+
if m is None or m.state != "running" or len(m.frames) < 2:
|
|
602
|
+
return # main has no caller
|
|
603
|
+
self._start_call("Step Out", len(m.frames) - 1, "finishing %s" % m.method.name)
|
|
604
|
+
self._play_tick()
|
|
605
|
+
|
|
606
|
+
def _start_call(self, button, depth, status):
|
|
607
|
+
m = self.machine
|
|
608
|
+
self.mode = "call"
|
|
609
|
+
self.call_button = button
|
|
610
|
+
self.call_depth = depth
|
|
611
|
+
self.call_start = m.steps
|
|
612
|
+
self.call_status = status
|
|
580
613
|
self.playing = True
|
|
581
614
|
self._update_controls()
|
|
582
|
-
self._step(self._after_play_step) # the call, animated
|
|
583
615
|
|
|
584
616
|
def _at_end_of_call(self):
|
|
585
617
|
"""True if the next instruction returns from the call that Step Over
|
|
586
|
-
executes."""
|
|
618
|
+
or Step Out executes."""
|
|
587
619
|
m = self.machine
|
|
588
620
|
insn = m.current_instruction()
|
|
589
|
-
return (len(m.frames) == self.
|
|
621
|
+
return (len(m.frames) == self.call_depth + 1 and insn is not None
|
|
590
622
|
and insn.op in RETURNS)
|
|
591
623
|
|
|
592
|
-
def
|
|
624
|
+
def _end_call(self, ev):
|
|
593
625
|
self.stop()
|
|
594
626
|
|
|
595
627
|
def play(self):
|
|
@@ -618,10 +650,12 @@ class App:
|
|
|
618
650
|
if m is None or m.state != "running":
|
|
619
651
|
return
|
|
620
652
|
ev = m.step()
|
|
621
|
-
if (self.mode == "
|
|
622
|
-
and not ev.error and len(m.frames) == self.
|
|
623
|
-
|
|
624
|
-
|
|
653
|
+
if (self.mode == "call" and ev.insn is not None and ev.insn.op in RETURNS
|
|
654
|
+
and not ev.error and len(m.frames) == self.call_depth):
|
|
655
|
+
what = ("the call completely" if self.call_button == "Step Over" else
|
|
656
|
+
"the rest of %s" % ev.method.name)
|
|
657
|
+
ev.notes.append(("%s has executed %s: %d instructions."
|
|
658
|
+
% (self.call_button, what, m.steps - self.call_start), "note"))
|
|
625
659
|
self.event = ev
|
|
626
660
|
self._auto_view(ev)
|
|
627
661
|
duration = self._duration()
|
|
@@ -649,9 +683,9 @@ class App:
|
|
|
649
683
|
if self.machine is None or self.machine.state != "running":
|
|
650
684
|
self.stop()
|
|
651
685
|
return
|
|
652
|
-
if self.mode == "
|
|
686
|
+
if self.mode == "call":
|
|
653
687
|
if self._at_end_of_call():
|
|
654
|
-
self._step(self.
|
|
688
|
+
self._step(self._end_call) # the return, animated
|
|
655
689
|
else:
|
|
656
690
|
self._turbo() # the body of the method
|
|
657
691
|
elif self._duration() == 0:
|
|
@@ -683,7 +717,7 @@ class App:
|
|
|
683
717
|
stop = False
|
|
684
718
|
ev = None
|
|
685
719
|
while m.state == "running":
|
|
686
|
-
if self.mode == "
|
|
720
|
+
if self.mode == "call" and self._at_end_of_call():
|
|
687
721
|
break # _play_tick animates the return
|
|
688
722
|
ev = m.step()
|
|
689
723
|
self._report(ev)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytunium
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4
|
|
4
4
|
Summary: A simulator for programs written in the JVM assembler language of pytunia
|
|
5
5
|
Author: Karl Stroetmann
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -99,6 +99,7 @@ animation).
|
|
|
99
99
|
| **Play** / Return | runs the program, animated with the chosen speed |
|
|
100
100
|
| **Step** / Space, → | executes one instruction |
|
|
101
101
|
| **Step Over** / ⇧Space, ⇧→ | like Step, but a method call is executed completely (see below) |
|
|
102
|
+
| **Step Out** / ↑ | executes the rest of the current method (see below) |
|
|
102
103
|
| **Stop** / Return, Esc | stops Play |
|
|
103
104
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
104
105
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -110,14 +111,21 @@ animation).
|
|
|
110
111
|
Reset reads the file again, so you can edit the program in an editor and
|
|
111
112
|
press Reset to simulate the new version.
|
|
112
113
|
|
|
113
|
-
**Step Over**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
**Step Over** and **Step Out** are named after the buttons of the same names in
|
|
115
|
+
debuggers.
|
|
116
|
+
|
|
117
|
+
* **Step Over**: if the next instruction is `invokestatic`, the whole call is
|
|
118
|
+
executed, including all the calls made inside it, and the simulation stops
|
|
119
|
+
at the instruction after the call. The call and the return are animated;
|
|
120
|
+
the body of the method runs without animation. For any other instruction,
|
|
121
|
+
Step Over does the same as Step, so pressing Step Over repeatedly walks
|
|
122
|
+
through `main` without descending into the methods it calls.
|
|
123
|
+
* **Step Out** executes the rest of the current method and stops in the
|
|
124
|
+
calling method, at the instruction after the call. The return is animated.
|
|
125
|
+
In a recursive method, Step Out leaves only the current call. In `main`,
|
|
126
|
+
which has no caller, the button is disabled.
|
|
127
|
+
|
|
128
|
+
A breakpoint, a warning or an error stops both earlier, and so does Stop.
|
|
121
129
|
|
|
122
130
|
## The memory model
|
|
123
131
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|