pytunium 0.2__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.2/pytunium.egg-info → pytunium-0.4}/PKG-INFO +19 -1
- {pytunium-0.2 → pytunium-0.4}/README.md +18 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium/__init__.py +1 -1
- {pytunium-0.2 → pytunium-0.4}/pytunium/gui.py +97 -5
- {pytunium-0.2 → pytunium-0.4}/pytunium/machine.py +1 -2
- {pytunium-0.2 → pytunium-0.4/pytunium.egg-info}/PKG-INFO +19 -1
- {pytunium-0.2 → pytunium-0.4}/tests/test_machine.py +1 -0
- {pytunium-0.2 → pytunium-0.4}/LICENSE.txt +0 -0
- {pytunium-0.2 → pytunium-0.4}/pyproject.toml +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium/__main__.py +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium/examples/Hello.jas +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium/examples/Primes.jas +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium/examples/Sum.jas +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium/loader.py +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium/program.py +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium/values.py +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium.egg-info/SOURCES.txt +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium.egg-info/dependency_links.txt +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium.egg-info/entry_points.txt +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium.egg-info/requires.txt +0 -0
- {pytunium-0.2 → pytunium-0.4}/pytunium.egg-info/top_level.txt +0 -0
- {pytunium-0.2 → pytunium-0.4}/setup.cfg +0 -0
- {pytunium-0.2 → 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
|
|
@@ -98,6 +98,8 @@ animation).
|
|
|
98
98
|
|---------------------------|----------------------------------------------------------|
|
|
99
99
|
| **Play** / Return | runs the program, animated with the chosen speed |
|
|
100
100
|
| **Step** / Space, → | executes one instruction |
|
|
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) |
|
|
101
103
|
| **Stop** / Return, Esc | stops Play |
|
|
102
104
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
103
105
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -109,6 +111,22 @@ animation).
|
|
|
109
111
|
Reset reads the file again, so you can edit the program in an editor and
|
|
110
112
|
press Reset to simulate the new version.
|
|
111
113
|
|
|
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.
|
|
129
|
+
|
|
112
130
|
## The memory model
|
|
113
131
|
|
|
114
132
|
As in Chapter 12, there is a single stack. A method call does not copy its
|
|
@@ -68,6 +68,8 @@ animation).
|
|
|
68
68
|
|---------------------------|----------------------------------------------------------|
|
|
69
69
|
| **Play** / Return | runs the program, animated with the chosen speed |
|
|
70
70
|
| **Step** / Space, → | executes one instruction |
|
|
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) |
|
|
71
73
|
| **Stop** / Return, Esc | stops Play |
|
|
72
74
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
73
75
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -79,6 +81,22 @@ animation).
|
|
|
79
81
|
Reset reads the file again, so you can edit the program in an editor and
|
|
80
82
|
press Reset to simulate the new version.
|
|
81
83
|
|
|
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.
|
|
99
|
+
|
|
82
100
|
## The memory model
|
|
83
101
|
|
|
84
102
|
As in Chapter 12, there is a single stack. A method call does not copy its
|
|
@@ -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
|
|
@@ -38,6 +38,7 @@ SPEED_MS = {1: 2600, 2: 1900, 3: 1400, 4: 1000, 5: 750, 6: 520, 7: 350,
|
|
|
38
38
|
|
|
39
39
|
GUTTER = 7 # width of the gutter of the source: "● 1234 "
|
|
40
40
|
STALE_SHOWN = 2 # number of cells above SP that are drawn
|
|
41
|
+
RETURNS = ("ireturn", "areturn", "return")
|
|
41
42
|
|
|
42
43
|
C = dict(
|
|
43
44
|
bg="#ffffff", src_bg="#fbfaf6", text="#1d1d1f", dim="#8a8a8e",
|
|
@@ -176,6 +177,13 @@ class App:
|
|
|
176
177
|
self.event = None # the last Event
|
|
177
178
|
self.anim = None # the running Animation
|
|
178
179
|
self.playing = False
|
|
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
|
|
179
187
|
self.play_job = None
|
|
180
188
|
self.breakpoints = set()
|
|
181
189
|
self.view_base = 0 # the lowest address that is visible
|
|
@@ -237,9 +245,14 @@ class App:
|
|
|
237
245
|
bar.pack(side="top", fill="x")
|
|
238
246
|
self.b_play = ttk.Button(bar, text="▶ Play", command=self.play, takefocus=0)
|
|
239
247
|
self.b_step = ttk.Button(bar, text="→ Step", command=self.step, takefocus=0)
|
|
248
|
+
self.b_over = ttk.Button(bar, text="↷ Step Over", command=self.step_over,
|
|
249
|
+
takefocus=0)
|
|
250
|
+
self.b_out = ttk.Button(bar, text="↑ Step Out", command=self.step_out,
|
|
251
|
+
takefocus=0)
|
|
240
252
|
self.b_stop = ttk.Button(bar, text="■ Stop", command=self.stop, takefocus=0)
|
|
241
253
|
self.b_reset = ttk.Button(bar, text="↺ Reset", command=self.reset, takefocus=0)
|
|
242
|
-
for b in (self.b_play, self.b_step, self.
|
|
254
|
+
for b in (self.b_play, self.b_step, self.b_over, self.b_out, self.b_stop,
|
|
255
|
+
self.b_reset):
|
|
243
256
|
b.pack(side="left", padx=(0, 6))
|
|
244
257
|
ttk.Separator(bar, orient="vertical").pack(side="left", fill="y", padx=10)
|
|
245
258
|
ttk.Label(bar, text="Speed").pack(side="left")
|
|
@@ -328,6 +341,9 @@ class App:
|
|
|
328
341
|
mod = "Command" if sys.platform == "darwin" else "Control"
|
|
329
342
|
r.bind("<space>", lambda e: self.step())
|
|
330
343
|
r.bind("<Right>", lambda e: self.step())
|
|
344
|
+
r.bind("<Shift-space>", lambda e: self.step_over())
|
|
345
|
+
r.bind("<Shift-Right>", lambda e: self.step_over())
|
|
346
|
+
r.bind("<Up>", lambda e: self.step_out())
|
|
331
347
|
r.bind("<Return>", lambda e: self.stop() if self.playing else self.play())
|
|
332
348
|
r.bind("<Escape>", lambda e: self.stop())
|
|
333
349
|
r.bind("<%s-r>" % mod, lambda e: self.reset())
|
|
@@ -384,8 +400,9 @@ class App:
|
|
|
384
400
|
if not result.checked_by_pytunia:
|
|
385
401
|
self.message("pytunia is not installed, so the syntax has not been checked "
|
|
386
402
|
"by the assembler (pip install pytunia).", "info")
|
|
387
|
-
self.message("Space = Step,
|
|
388
|
-
"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")
|
|
389
406
|
self.view_base = 0
|
|
390
407
|
self._auto_view(None)
|
|
391
408
|
self._highlight_lines()
|
|
@@ -508,6 +525,9 @@ class App:
|
|
|
508
525
|
running = m is not None and m.state == "running"
|
|
509
526
|
self.b_play.state(["!disabled"] if running and not self.playing else ["disabled"])
|
|
510
527
|
self.b_step.state(["!disabled"] if running else ["disabled"])
|
|
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"])
|
|
511
531
|
self.b_stop.state(["!disabled"] if self.playing else ["disabled"])
|
|
512
532
|
self.b_reset.state(["!disabled"] if self.path else ["disabled"])
|
|
513
533
|
if m is None:
|
|
@@ -515,7 +535,8 @@ class App:
|
|
|
515
535
|
else:
|
|
516
536
|
line = m.current_line()
|
|
517
537
|
where = ("%s · line %d" % (m.method.name, line)) if line else ""
|
|
518
|
-
|
|
538
|
+
playing = self.call_status if self.mode == "call" else "playing"
|
|
539
|
+
state = {"running": playing if self.playing else "ready",
|
|
519
540
|
"finished": "finished", "error": "stopped by an error"}[m.state]
|
|
520
541
|
status = " ".join(s for s in (where, "step %d" % m.steps, state) if s)
|
|
521
542
|
self.l_status.configure(text=status)
|
|
@@ -523,6 +544,7 @@ class App:
|
|
|
523
544
|
def _halt(self):
|
|
524
545
|
"""Stops playing and throws away a running animation."""
|
|
525
546
|
self.playing = False
|
|
547
|
+
self.mode = None
|
|
526
548
|
if self.play_job is not None:
|
|
527
549
|
self.root.after_cancel(self.play_job)
|
|
528
550
|
self.play_job = None
|
|
@@ -536,6 +558,7 @@ class App:
|
|
|
536
558
|
|
|
537
559
|
def stop(self):
|
|
538
560
|
self.playing = False
|
|
561
|
+
self.mode = None
|
|
539
562
|
if self.play_job is not None:
|
|
540
563
|
self.root.after_cancel(self.play_job)
|
|
541
564
|
self.play_job = None
|
|
@@ -546,10 +569,66 @@ class App:
|
|
|
546
569
|
self.stop()
|
|
547
570
|
self._step(None)
|
|
548
571
|
|
|
572
|
+
def step_over(self):
|
|
573
|
+
"""Executes the next instruction. If it calls a method, the whole
|
|
574
|
+
call is executed: the call and the return are animated, the body of
|
|
575
|
+
the method runs without animation, and the simulation stops after
|
|
576
|
+
the call (or earlier at a breakpoint, a warning or an error)."""
|
|
577
|
+
if self.playing:
|
|
578
|
+
self.stop()
|
|
579
|
+
if self.anim is not None and not self.anim.done:
|
|
580
|
+
self.anim.finish()
|
|
581
|
+
m = self.machine
|
|
582
|
+
if m is None or m.state != "running":
|
|
583
|
+
return
|
|
584
|
+
insn = m.current_instruction()
|
|
585
|
+
if insn is None or insn.op != "invokestatic" or not insn.supported:
|
|
586
|
+
self._step(None)
|
|
587
|
+
return
|
|
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
|
|
613
|
+
self.playing = True
|
|
614
|
+
self._update_controls()
|
|
615
|
+
|
|
616
|
+
def _at_end_of_call(self):
|
|
617
|
+
"""True if the next instruction returns from the call that Step Over
|
|
618
|
+
or Step Out executes."""
|
|
619
|
+
m = self.machine
|
|
620
|
+
insn = m.current_instruction()
|
|
621
|
+
return (len(m.frames) == self.call_depth + 1 and insn is not None
|
|
622
|
+
and insn.op in RETURNS)
|
|
623
|
+
|
|
624
|
+
def _end_call(self, ev):
|
|
625
|
+
self.stop()
|
|
626
|
+
|
|
549
627
|
def play(self):
|
|
550
628
|
m = self.machine
|
|
551
629
|
if m is None or m.state != "running" or self.playing:
|
|
552
630
|
return
|
|
631
|
+
self.mode = "play"
|
|
553
632
|
self.playing = True
|
|
554
633
|
self._update_controls()
|
|
555
634
|
self._play_tick()
|
|
@@ -571,6 +650,12 @@ class App:
|
|
|
571
650
|
if m is None or m.state != "running":
|
|
572
651
|
return
|
|
573
652
|
ev = m.step()
|
|
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"))
|
|
574
659
|
self.event = ev
|
|
575
660
|
self._auto_view(ev)
|
|
576
661
|
duration = self._duration()
|
|
@@ -598,7 +683,12 @@ class App:
|
|
|
598
683
|
if self.machine is None or self.machine.state != "running":
|
|
599
684
|
self.stop()
|
|
600
685
|
return
|
|
601
|
-
if self.
|
|
686
|
+
if self.mode == "call":
|
|
687
|
+
if self._at_end_of_call():
|
|
688
|
+
self._step(self._end_call) # the return, animated
|
|
689
|
+
else:
|
|
690
|
+
self._turbo() # the body of the method
|
|
691
|
+
elif self._duration() == 0:
|
|
602
692
|
self._turbo()
|
|
603
693
|
else:
|
|
604
694
|
self._step(self._after_play_step)
|
|
@@ -627,6 +717,8 @@ class App:
|
|
|
627
717
|
stop = False
|
|
628
718
|
ev = None
|
|
629
719
|
while m.state == "running":
|
|
720
|
+
if self.mode == "call" and self._at_end_of_call():
|
|
721
|
+
break # _play_tick animates the return
|
|
630
722
|
ev = m.step()
|
|
631
723
|
self._report(ev)
|
|
632
724
|
if self._stops_play(ev):
|
|
@@ -813,8 +813,7 @@ class Machine:
|
|
|
813
813
|
self._formula([T("return "), S("$0"), T(" from "), T(m.name, "label")],
|
|
814
814
|
[T("continue at "), S("$%d" % first)],
|
|
815
815
|
[T("LV := "), S("$%d" % (first + 1))])
|
|
816
|
-
self._note("The frame of %s is removed: SP = %d, LV = %d."
|
|
817
|
-
% (m.name, self.sp + (kind != "void"), self.lv))
|
|
816
|
+
self._note("The frame of %s is removed: SP = %d, LV = %d." % (m.name, self.sp, self.lv))
|
|
818
817
|
|
|
819
818
|
def _op_ireturn(self, insn):
|
|
820
819
|
self._return(insn, "int")
|
|
@@ -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
|
|
@@ -98,6 +98,8 @@ animation).
|
|
|
98
98
|
|---------------------------|----------------------------------------------------------|
|
|
99
99
|
| **Play** / Return | runs the program, animated with the chosen speed |
|
|
100
100
|
| **Step** / Space, → | executes one instruction |
|
|
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) |
|
|
101
103
|
| **Stop** / Return, Esc | stops Play |
|
|
102
104
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
103
105
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -109,6 +111,22 @@ animation).
|
|
|
109
111
|
Reset reads the file again, so you can edit the program in an editor and
|
|
110
112
|
press Reset to simulate the new version.
|
|
111
113
|
|
|
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.
|
|
129
|
+
|
|
112
130
|
## The memory model
|
|
113
131
|
|
|
114
132
|
As in Chapter 12, there is a single stack. A method call does not copy its
|
|
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
|