pytunium 0.2__tar.gz → 0.3__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.3}/PKG-INFO +11 -1
- {pytunium-0.2 → pytunium-0.3}/README.md +10 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium/__init__.py +1 -1
- {pytunium-0.2 → pytunium-0.3}/pytunium/gui.py +63 -5
- {pytunium-0.2 → pytunium-0.3}/pytunium/machine.py +1 -2
- {pytunium-0.2 → pytunium-0.3/pytunium.egg-info}/PKG-INFO +11 -1
- {pytunium-0.2 → pytunium-0.3}/tests/test_machine.py +1 -0
- {pytunium-0.2 → pytunium-0.3}/LICENSE.txt +0 -0
- {pytunium-0.2 → pytunium-0.3}/pyproject.toml +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium/__main__.py +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium/examples/Hello.jas +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium/examples/Primes.jas +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium/examples/Sum.jas +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium/loader.py +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium/program.py +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium/values.py +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium.egg-info/SOURCES.txt +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium.egg-info/dependency_links.txt +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium.egg-info/entry_points.txt +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium.egg-info/requires.txt +0 -0
- {pytunium-0.2 → pytunium-0.3}/pytunium.egg-info/top_level.txt +0 -0
- {pytunium-0.2 → pytunium-0.3}/setup.cfg +0 -0
- {pytunium-0.2 → pytunium-0.3}/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.3
|
|
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,7 @@ 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) |
|
|
101
102
|
| **Stop** / Return, Esc | stops Play |
|
|
102
103
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
103
104
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -109,6 +110,15 @@ animation).
|
|
|
109
110
|
Reset reads the file again, so you can edit the program in an editor and
|
|
110
111
|
press Reset to simulate the new version.
|
|
111
112
|
|
|
113
|
+
**Step Over** is named after the button of the same name in debuggers. If the
|
|
114
|
+
next instruction is `invokestatic`, the whole call is executed, including all
|
|
115
|
+
the calls made inside it, and the simulation stops at the instruction after
|
|
116
|
+
the call. The call and the return are animated; the body of the method runs
|
|
117
|
+
without animation. A breakpoint, a warning or an error inside the call stops
|
|
118
|
+
it earlier, and so does Stop. For any other instruction, Step Over does the
|
|
119
|
+
same as Step, so pressing Step Over repeatedly walks through `main` without
|
|
120
|
+
descending into the methods it calls.
|
|
121
|
+
|
|
112
122
|
## The memory model
|
|
113
123
|
|
|
114
124
|
As in Chapter 12, there is a single stack. A method call does not copy its
|
|
@@ -68,6 +68,7 @@ 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) |
|
|
71
72
|
| **Stop** / Return, Esc | stops Play |
|
|
72
73
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
73
74
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -79,6 +80,15 @@ animation).
|
|
|
79
80
|
Reset reads the file again, so you can edit the program in an editor and
|
|
80
81
|
press Reset to simulate the new version.
|
|
81
82
|
|
|
83
|
+
**Step Over** is named after the button of the same name in debuggers. If the
|
|
84
|
+
next instruction is `invokestatic`, the whole call is executed, including all
|
|
85
|
+
the calls made inside it, and the simulation stops at the instruction after
|
|
86
|
+
the call. The call and the return are animated; the body of the method runs
|
|
87
|
+
without animation. A breakpoint, a warning or an error inside the call stops
|
|
88
|
+
it earlier, and so does Stop. For any other instruction, Step Over does the
|
|
89
|
+
same as Step, so pressing Step Over repeatedly walks through `main` without
|
|
90
|
+
descending into the methods it calls.
|
|
91
|
+
|
|
82
92
|
## The memory model
|
|
83
93
|
|
|
84
94
|
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.3"
|
|
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,9 @@ class App:
|
|
|
176
177
|
self.event = None # the last Event
|
|
177
178
|
self.anim = None # the running Animation
|
|
178
179
|
self.playing = False
|
|
180
|
+
self.mode = None # "play", or "over" while Step Over runs a call
|
|
181
|
+
self.over_depth = None # number of frames when Step Over started
|
|
182
|
+
self.over_start = None # number of steps when Step Over started
|
|
179
183
|
self.play_job = None
|
|
180
184
|
self.breakpoints = set()
|
|
181
185
|
self.view_base = 0 # the lowest address that is visible
|
|
@@ -237,9 +241,11 @@ class App:
|
|
|
237
241
|
bar.pack(side="top", fill="x")
|
|
238
242
|
self.b_play = ttk.Button(bar, text="▶ Play", command=self.play, takefocus=0)
|
|
239
243
|
self.b_step = ttk.Button(bar, text="→ Step", command=self.step, takefocus=0)
|
|
244
|
+
self.b_over = ttk.Button(bar, text="↷ Step Over", command=self.step_over,
|
|
245
|
+
takefocus=0)
|
|
240
246
|
self.b_stop = ttk.Button(bar, text="■ Stop", command=self.stop, takefocus=0)
|
|
241
247
|
self.b_reset = ttk.Button(bar, text="↺ Reset", command=self.reset, takefocus=0)
|
|
242
|
-
for b in (self.b_play, self.b_step, self.b_stop, self.b_reset):
|
|
248
|
+
for b in (self.b_play, self.b_step, self.b_over, self.b_stop, self.b_reset):
|
|
243
249
|
b.pack(side="left", padx=(0, 6))
|
|
244
250
|
ttk.Separator(bar, orient="vertical").pack(side="left", fill="y", padx=10)
|
|
245
251
|
ttk.Label(bar, text="Speed").pack(side="left")
|
|
@@ -328,6 +334,8 @@ class App:
|
|
|
328
334
|
mod = "Command" if sys.platform == "darwin" else "Control"
|
|
329
335
|
r.bind("<space>", lambda e: self.step())
|
|
330
336
|
r.bind("<Right>", lambda e: self.step())
|
|
337
|
+
r.bind("<Shift-space>", lambda e: self.step_over())
|
|
338
|
+
r.bind("<Shift-Right>", lambda e: self.step_over())
|
|
331
339
|
r.bind("<Return>", lambda e: self.stop() if self.playing else self.play())
|
|
332
340
|
r.bind("<Escape>", lambda e: self.stop())
|
|
333
341
|
r.bind("<%s-r>" % mod, lambda e: self.reset())
|
|
@@ -384,8 +392,8 @@ class App:
|
|
|
384
392
|
if not result.checked_by_pytunia:
|
|
385
393
|
self.message("pytunia is not installed, so the syntax has not been checked "
|
|
386
394
|
"by the assembler (pip install pytunia).", "info")
|
|
387
|
-
self.message("Space = Step, Return = Play/Stop.
|
|
388
|
-
"a breakpoint.", "info")
|
|
395
|
+
self.message("Space = Step, Shift+Space = Step Over, Return = Play/Stop. "
|
|
396
|
+
"Click a line number to set a breakpoint.", "info")
|
|
389
397
|
self.view_base = 0
|
|
390
398
|
self._auto_view(None)
|
|
391
399
|
self._highlight_lines()
|
|
@@ -508,6 +516,7 @@ class App:
|
|
|
508
516
|
running = m is not None and m.state == "running"
|
|
509
517
|
self.b_play.state(["!disabled"] if running and not self.playing else ["disabled"])
|
|
510
518
|
self.b_step.state(["!disabled"] if running else ["disabled"])
|
|
519
|
+
self.b_over.state(["!disabled"] if running else ["disabled"])
|
|
511
520
|
self.b_stop.state(["!disabled"] if self.playing else ["disabled"])
|
|
512
521
|
self.b_reset.state(["!disabled"] if self.path else ["disabled"])
|
|
513
522
|
if m is None:
|
|
@@ -515,7 +524,8 @@ class App:
|
|
|
515
524
|
else:
|
|
516
525
|
line = m.current_line()
|
|
517
526
|
where = ("%s · line %d" % (m.method.name, line)) if line else ""
|
|
518
|
-
|
|
527
|
+
playing = "executing the call" if self.mode == "over" else "playing"
|
|
528
|
+
state = {"running": playing if self.playing else "ready",
|
|
519
529
|
"finished": "finished", "error": "stopped by an error"}[m.state]
|
|
520
530
|
status = " ".join(s for s in (where, "step %d" % m.steps, state) if s)
|
|
521
531
|
self.l_status.configure(text=status)
|
|
@@ -523,6 +533,7 @@ class App:
|
|
|
523
533
|
def _halt(self):
|
|
524
534
|
"""Stops playing and throws away a running animation."""
|
|
525
535
|
self.playing = False
|
|
536
|
+
self.mode = None
|
|
526
537
|
if self.play_job is not None:
|
|
527
538
|
self.root.after_cancel(self.play_job)
|
|
528
539
|
self.play_job = None
|
|
@@ -536,6 +547,7 @@ class App:
|
|
|
536
547
|
|
|
537
548
|
def stop(self):
|
|
538
549
|
self.playing = False
|
|
550
|
+
self.mode = None
|
|
539
551
|
if self.play_job is not None:
|
|
540
552
|
self.root.after_cancel(self.play_job)
|
|
541
553
|
self.play_job = None
|
|
@@ -546,10 +558,45 @@ class App:
|
|
|
546
558
|
self.stop()
|
|
547
559
|
self._step(None)
|
|
548
560
|
|
|
561
|
+
def step_over(self):
|
|
562
|
+
"""Executes the next instruction. If it calls a method, the whole
|
|
563
|
+
call is executed: the call and the return are animated, the body of
|
|
564
|
+
the method runs without animation, and the simulation stops after
|
|
565
|
+
the call (or earlier at a breakpoint, a warning or an error)."""
|
|
566
|
+
if self.playing:
|
|
567
|
+
self.stop()
|
|
568
|
+
if self.anim is not None and not self.anim.done:
|
|
569
|
+
self.anim.finish()
|
|
570
|
+
m = self.machine
|
|
571
|
+
if m is None or m.state != "running":
|
|
572
|
+
return
|
|
573
|
+
insn = m.current_instruction()
|
|
574
|
+
if insn is None or insn.op != "invokestatic" or not insn.supported:
|
|
575
|
+
self._step(None)
|
|
576
|
+
return
|
|
577
|
+
self.mode = "over"
|
|
578
|
+
self.over_depth = len(m.frames)
|
|
579
|
+
self.over_start = m.steps
|
|
580
|
+
self.playing = True
|
|
581
|
+
self._update_controls()
|
|
582
|
+
self._step(self._after_play_step) # the call, animated
|
|
583
|
+
|
|
584
|
+
def _at_end_of_call(self):
|
|
585
|
+
"""True if the next instruction returns from the call that Step Over
|
|
586
|
+
executes."""
|
|
587
|
+
m = self.machine
|
|
588
|
+
insn = m.current_instruction()
|
|
589
|
+
return (len(m.frames) == self.over_depth + 1 and insn is not None
|
|
590
|
+
and insn.op in RETURNS)
|
|
591
|
+
|
|
592
|
+
def _end_over(self, ev):
|
|
593
|
+
self.stop()
|
|
594
|
+
|
|
549
595
|
def play(self):
|
|
550
596
|
m = self.machine
|
|
551
597
|
if m is None or m.state != "running" or self.playing:
|
|
552
598
|
return
|
|
599
|
+
self.mode = "play"
|
|
553
600
|
self.playing = True
|
|
554
601
|
self._update_controls()
|
|
555
602
|
self._play_tick()
|
|
@@ -571,6 +618,10 @@ class App:
|
|
|
571
618
|
if m is None or m.state != "running":
|
|
572
619
|
return
|
|
573
620
|
ev = m.step()
|
|
621
|
+
if (self.mode == "over" and ev.insn is not None and ev.insn.op in RETURNS
|
|
622
|
+
and not ev.error and len(m.frames) == self.over_depth):
|
|
623
|
+
ev.notes.append(("Step Over has executed the call completely: %d instructions."
|
|
624
|
+
% (m.steps - self.over_start), "note"))
|
|
574
625
|
self.event = ev
|
|
575
626
|
self._auto_view(ev)
|
|
576
627
|
duration = self._duration()
|
|
@@ -598,7 +649,12 @@ class App:
|
|
|
598
649
|
if self.machine is None or self.machine.state != "running":
|
|
599
650
|
self.stop()
|
|
600
651
|
return
|
|
601
|
-
if self.
|
|
652
|
+
if self.mode == "over":
|
|
653
|
+
if self._at_end_of_call():
|
|
654
|
+
self._step(self._end_over) # the return, animated
|
|
655
|
+
else:
|
|
656
|
+
self._turbo() # the body of the method
|
|
657
|
+
elif self._duration() == 0:
|
|
602
658
|
self._turbo()
|
|
603
659
|
else:
|
|
604
660
|
self._step(self._after_play_step)
|
|
@@ -627,6 +683,8 @@ class App:
|
|
|
627
683
|
stop = False
|
|
628
684
|
ev = None
|
|
629
685
|
while m.state == "running":
|
|
686
|
+
if self.mode == "over" and self._at_end_of_call():
|
|
687
|
+
break # _play_tick animates the return
|
|
630
688
|
ev = m.step()
|
|
631
689
|
self._report(ev)
|
|
632
690
|
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.3
|
|
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,7 @@ 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) |
|
|
101
102
|
| **Stop** / Return, Esc | stops Play |
|
|
102
103
|
| **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
|
|
103
104
|
| **Open…** / ⌘O (Ctrl+O) | loads another program |
|
|
@@ -109,6 +110,15 @@ animation).
|
|
|
109
110
|
Reset reads the file again, so you can edit the program in an editor and
|
|
110
111
|
press Reset to simulate the new version.
|
|
111
112
|
|
|
113
|
+
**Step Over** is named after the button of the same name in debuggers. If the
|
|
114
|
+
next instruction is `invokestatic`, the whole call is executed, including all
|
|
115
|
+
the calls made inside it, and the simulation stops at the instruction after
|
|
116
|
+
the call. The call and the return are animated; the body of the method runs
|
|
117
|
+
without animation. A breakpoint, a warning or an error inside the call stops
|
|
118
|
+
it earlier, and so does Stop. For any other instruction, Step Over does the
|
|
119
|
+
same as Step, so pressing Step Over repeatedly walks through `main` without
|
|
120
|
+
descending into the methods it calls.
|
|
121
|
+
|
|
112
122
|
## The memory model
|
|
113
123
|
|
|
114
124
|
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
|