pytunium 0.1__py3-none-any.whl
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/__init__.py +17 -0
- pytunium/__main__.py +43 -0
- pytunium/examples/Hello.jas +17 -0
- pytunium/examples/Primes.jas +90 -0
- pytunium/examples/Sum.jas +42 -0
- pytunium/gui.py +1031 -0
- pytunium/loader.py +48 -0
- pytunium/machine.py +878 -0
- pytunium/program.py +807 -0
- pytunium/values.py +183 -0
- pytunium-0.1.dist-info/METADATA +166 -0
- pytunium-0.1.dist-info/RECORD +16 -0
- pytunium-0.1.dist-info/WHEEL +5 -0
- pytunium-0.1.dist-info/entry_points.txt +2 -0
- pytunium-0.1.dist-info/licenses/LICENSE.txt +29 -0
- pytunium-0.1.dist-info/top_level.txt +1 -0
pytunium/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pytunium: a simulator for programs written in the assembler language of pytunia.
|
|
3
|
+
|
|
4
|
+
The simulator shows the program, the stack of the Java virtual machine, and a
|
|
5
|
+
working area where the computation of every instruction is displayed.
|
|
6
|
+
|
|
7
|
+
python3 -m pytunium Sum.jas
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1"
|
|
11
|
+
|
|
12
|
+
from .program import parse, Program, Method, Instruction, SourceError
|
|
13
|
+
from .machine import Machine, MachineError, Event
|
|
14
|
+
from .loader import load_program
|
|
15
|
+
|
|
16
|
+
__all__ = ["parse", "Program", "Method", "Instruction", "SourceError",
|
|
17
|
+
"Machine", "MachineError", "Event", "load_program", "__version__"]
|
pytunium/__main__.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The command line: python3 -m pytunium [file.jas] [--font-size N] [--speed N]
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
EXAMPLES = os.path.join(os.path.dirname(os.path.abspath(__file__)), "examples")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main(argv=None):
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
prog="pytunium",
|
|
15
|
+
description="A simulator for programs written in the assembler language "
|
|
16
|
+
"of pytunia.")
|
|
17
|
+
parser.add_argument("file", nargs="?",
|
|
18
|
+
help="the assembler program (default: the example Sum.jas)")
|
|
19
|
+
parser.add_argument("--font-size", type=int, default=14, metavar="N",
|
|
20
|
+
help="the size of the fonts (default: 14)")
|
|
21
|
+
parser.add_argument("--speed", type=int, default=5, choices=range(1, 11),
|
|
22
|
+
metavar="N", help="the speed of Play, 1 (slow) to 10 "
|
|
23
|
+
"(no animation); default: 5")
|
|
24
|
+
args = parser.parse_args(argv)
|
|
25
|
+
path = args.file
|
|
26
|
+
note = None
|
|
27
|
+
if path is None:
|
|
28
|
+
path = os.path.join(EXAMPLES, "Sum.jas")
|
|
29
|
+
note = ("No file was given, so the example Sum.jas is shown. "
|
|
30
|
+
"Use Open… to load another program.")
|
|
31
|
+
elif not os.path.isfile(path):
|
|
32
|
+
parser.error("cannot find the file %s" % path)
|
|
33
|
+
try:
|
|
34
|
+
from .gui import run
|
|
35
|
+
except ImportError as e:
|
|
36
|
+
sys.exit("pytunium needs Tkinter, which is not available: %s\n"
|
|
37
|
+
"On macOS with Homebrew: brew install python-tk; "
|
|
38
|
+
"on Debian/Ubuntu: sudo apt install python3-tk" % e)
|
|
39
|
+
run(path, font_size=args.font_size, speed=args.speed, note=note)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
main()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.class public Hello
|
|
2
|
+
.super java.lang.Object
|
|
3
|
+
|
|
4
|
+
.method public <init>() void
|
|
5
|
+
aload 0
|
|
6
|
+
invokenonvirtual java.lang.Object.<init>() void
|
|
7
|
+
return
|
|
8
|
+
.end method
|
|
9
|
+
|
|
10
|
+
.method public static main(java.lang.String[]) void
|
|
11
|
+
.limit locals 1
|
|
12
|
+
.limit stack 2
|
|
13
|
+
getstatic java.lang.System.out java.io.PrintStream
|
|
14
|
+
ldc "Hello World!"
|
|
15
|
+
invokevirtual java.io.PrintStream.println(java.lang.String) void
|
|
16
|
+
return
|
|
17
|
+
.end method
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
.class public Primes
|
|
2
|
+
.super java.lang.Object
|
|
3
|
+
|
|
4
|
+
.method public <init>() void
|
|
5
|
+
aload 0
|
|
6
|
+
invokenonvirtual java.lang.Object.<init>() void
|
|
7
|
+
return
|
|
8
|
+
.end method
|
|
9
|
+
|
|
10
|
+
.method public static is_prime(int) int
|
|
11
|
+
.limit locals 2
|
|
12
|
+
.limit stack 2
|
|
13
|
+
ldc 2
|
|
14
|
+
istore 1
|
|
15
|
+
l6:
|
|
16
|
+
iload 1
|
|
17
|
+
iload 0
|
|
18
|
+
if_icmplt l1
|
|
19
|
+
bipush 0
|
|
20
|
+
goto l2
|
|
21
|
+
l1:
|
|
22
|
+
bipush 1
|
|
23
|
+
l2:
|
|
24
|
+
ifeq l7
|
|
25
|
+
iload 0
|
|
26
|
+
iload 1
|
|
27
|
+
irem
|
|
28
|
+
ldc 0
|
|
29
|
+
if_icmpeq l3
|
|
30
|
+
bipush 0
|
|
31
|
+
goto l4
|
|
32
|
+
l3:
|
|
33
|
+
bipush 1
|
|
34
|
+
l4:
|
|
35
|
+
ifeq l5
|
|
36
|
+
ldc 0
|
|
37
|
+
ireturn
|
|
38
|
+
l5:
|
|
39
|
+
iload 1
|
|
40
|
+
ldc 1
|
|
41
|
+
iadd
|
|
42
|
+
istore 1
|
|
43
|
+
goto l6
|
|
44
|
+
l7:
|
|
45
|
+
iload 0
|
|
46
|
+
ireturn
|
|
47
|
+
.end method
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
.method public static main(java.lang.String[]) void
|
|
51
|
+
.limit locals 2
|
|
52
|
+
.limit stack 2
|
|
53
|
+
ldc 2
|
|
54
|
+
istore 0
|
|
55
|
+
l6:
|
|
56
|
+
iload 0
|
|
57
|
+
ldc 100
|
|
58
|
+
if_icmple l1
|
|
59
|
+
bipush 0
|
|
60
|
+
goto l2
|
|
61
|
+
l1:
|
|
62
|
+
bipush 1
|
|
63
|
+
l2:
|
|
64
|
+
ifeq l7
|
|
65
|
+
iload 0
|
|
66
|
+
invokestatic Primes.is_prime(int) int
|
|
67
|
+
istore 1
|
|
68
|
+
iload 1
|
|
69
|
+
ldc 0
|
|
70
|
+
if_icmpgt l3
|
|
71
|
+
bipush 0
|
|
72
|
+
goto l4
|
|
73
|
+
l3:
|
|
74
|
+
bipush 1
|
|
75
|
+
l4:
|
|
76
|
+
ifeq l5
|
|
77
|
+
getstatic java.lang.System.out java.io.PrintStream
|
|
78
|
+
iload 1
|
|
79
|
+
invokevirtual java.io.PrintStream.println(int) void
|
|
80
|
+
l5:
|
|
81
|
+
iload 0
|
|
82
|
+
ldc 1
|
|
83
|
+
iadd
|
|
84
|
+
istore 0
|
|
85
|
+
goto l6
|
|
86
|
+
l7:
|
|
87
|
+
return
|
|
88
|
+
.end method
|
|
89
|
+
|
|
90
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.class public Sum
|
|
2
|
+
.super java.lang.Object
|
|
3
|
+
|
|
4
|
+
.method public <init>() void
|
|
5
|
+
aload 0
|
|
6
|
+
invokenonvirtual java.lang.Object.<init>() void
|
|
7
|
+
return
|
|
8
|
+
.end method
|
|
9
|
+
|
|
10
|
+
.method public static main(java.lang.String[]) void
|
|
11
|
+
.limit locals 1
|
|
12
|
+
.limit stack 3
|
|
13
|
+
getstatic java.lang.System.out java.io.PrintStream
|
|
14
|
+
ldc 6
|
|
15
|
+
dup
|
|
16
|
+
imul
|
|
17
|
+
invokestatic Sum.sum(int) int
|
|
18
|
+
invokevirtual java.io.PrintStream.println(int) void
|
|
19
|
+
return
|
|
20
|
+
.end method
|
|
21
|
+
|
|
22
|
+
.method public static sum(int) int
|
|
23
|
+
.limit locals 2
|
|
24
|
+
.limit stack 2
|
|
25
|
+
ldc 0
|
|
26
|
+
istore 1 ; s = 0;
|
|
27
|
+
loop:
|
|
28
|
+
iload 0 ; load n
|
|
29
|
+
ifeq finish ; if (n == 0) goto finish;
|
|
30
|
+
iload 1 ; load s
|
|
31
|
+
iload 0 ; load n
|
|
32
|
+
iadd
|
|
33
|
+
istore 1 ; s = s + n;
|
|
34
|
+
iload 0 ; load n
|
|
35
|
+
ldc 1
|
|
36
|
+
isub
|
|
37
|
+
istore 0 ; n = n - 1;
|
|
38
|
+
goto loop
|
|
39
|
+
finish:
|
|
40
|
+
iload 1
|
|
41
|
+
ireturn ; return s;
|
|
42
|
+
.end method
|