pytunium 0.1__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.
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Karl Stroetmann
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pytunium-0.1/PKG-INFO ADDED
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytunium
3
+ Version: 0.1
4
+ Summary: A simulator for programs written in the JVM assembler language of pytunia
5
+ Author: Karl Stroetmann
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/karlstroetmann/pytunium
8
+ Project-URL: Source, https://github.com/karlstroetmann/pytunium
9
+ Project-URL: Issues, https://github.com/karlstroetmann/pytunium/issues
10
+ Project-URL: pytunia, https://github.com/karlstroetmann/pytunia
11
+ Keywords: jvm,assembler,simulator,stack machine,education,pytunia,jasmin,bytecode
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: X11 Applications
14
+ Classifier: Environment :: MacOS X
15
+ Classifier: Environment :: Win32 (MS Windows)
16
+ Classifier: Intended Audience :: Education
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Programming Language :: Python :: 3.15
23
+ Classifier: Topic :: Education
24
+ Classifier: Topic :: Software Development :: Assemblers
25
+ Requires-Python: >=3.12
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE.txt
28
+ Requires-Dist: pytunia>=0.5
29
+ Dynamic: license-file
30
+
31
+ # pytunium
32
+
33
+ A simulator for programs written in the assembler language of
34
+ [pytunia](https://github.com/karlstroetmann/pytunia), the JVM assembler of the
35
+ lecture *Formal Languages and Their Applications* (Chapter 12).
36
+
37
+ The window has three columns:
38
+
39
+ 1. **Program**: the assembler program. The next instruction is highlighted
40
+ in yellow, the instruction executed before in blue.
41
+ 2. **Stack**: the stack of the JVM. The cell that `SP` points to (the top of
42
+ the stack) is orange, the cell that `LV` points to (the first argument of
43
+ the current method) is blue. Each frame is marked with the name of its
44
+ method.
45
+ 3. **Working area**: what the current instruction does. For `iadd`, the two
46
+ operands move from the stack into the working area, the sum appears, and
47
+ the sum moves back onto the stack.
48
+
49
+ Below the columns, the output area shows what the program prints, and the
50
+ warnings and errors of the simulator.
51
+
52
+ ## Installation and start
53
+
54
+ pip install pytunium # installs pytunia, too
55
+ pytunium Sum.jas # or: python3 -m pytunium Sum.jas
56
+
57
+ Without a file, the example `Sum.jas` from Chapter 12 is shown. The examples
58
+ `Sum.jas`, `Hello.jas` and `Primes.jas` (generated by the compiler of
59
+ Chapter 13) are in `pytunium/examples`.
60
+
61
+ Options: `--font-size N` (default 14) and `--speed N` (1 = slow, 10 = no
62
+ animation).
63
+
64
+ pytunium needs Python 3.12 or newer with Tkinter. The installers from
65
+ python.org and Anaconda contain Tkinter; with Homebrew, install it with
66
+ `brew install python-tk`, on Debian/Ubuntu with `sudo apt install python3-tk`.
67
+ pytunia checks the syntax of the program first, so the error messages are the
68
+ same as when assembling.
69
+
70
+ ## Controls
71
+
72
+ | Button / key | Effect |
73
+ |---------------------------|----------------------------------------------------------|
74
+ | **Play** / Return | runs the program, animated with the chosen speed |
75
+ | **Step** / Space, → | executes one instruction |
76
+ | **Stop** / Return, Esc | stops Play |
77
+ | **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
78
+ | **Open…** / ⌘O (Ctrl+O) | loads another program |
79
+ | Speed | 1 (slow) … 9 (fast), 10 = no animation |
80
+ | click on a line number | sets or removes a breakpoint (Play stops before it) |
81
+ | ⌘+ / ⌘− / ⌘0 | larger / smaller / normal font (useful for a projector) |
82
+ | mouse wheel on the stack | scrolls the stack |
83
+
84
+ Reset reads the file again, so you can edit the program in an editor and
85
+ press Reset to simulate the new version.
86
+
87
+ ## The memory model
88
+
89
+ As in Chapter 12, there is a single stack. A method call does not copy its
90
+ arguments: the arguments on top of the caller's operand stack become the first
91
+ local variables of the new frame, and `LV` points to the first of them. A
92
+ frame with `L` local variables (`.limit locals L`) looks like this:
93
+
94
+ LV+L+2 … operand stack of the method
95
+ LV+L+1 saved LV: the value of LV in the calling method
96
+ LV+L return address: where the caller continues
97
+ LV+n … LV+L-1 the other local variables (shown as ? until assigned)
98
+ LV+0 … LV+n-1 the n arguments
99
+
100
+ The two grey cells are the bookkeeping cells. `ireturn` removes the frame,
101
+ puts the result where the arguments were, and restores `LV` from the saved
102
+ value. Cells above `SP` keep their old values (shown faintly), since `pop`
103
+ only decrements `SP`.
104
+
105
+ ## What is simulated
106
+
107
+ * int arithmetic with the semantics of Java: overflow wraps around, `idiv`
108
+ rounds towards 0, the remainder of `irem` has the sign of the dividend, the
109
+ shifts use the lowest 5 bits of the shift distance:
110
+ `iadd isub imul idiv irem ineg iand ior ixor ishl ishr iushr iinc`
111
+ * constants and the stack: `iconst_<n> bipush sipush ldc aconst_null dup pop swap nop`
112
+ * local variables: `iload istore aload astore` (also `iload_<n>` etc.)
113
+ * jumps: `goto if<cond> if_icmp<cond> if_acmpeq if_acmpne ifnull ifnonnull`
114
+ * static methods of the same class: `invokestatic ireturn areturn return`
115
+ * printing: `getstatic java.lang.System.out java.io.PrintStream` (or `err`) and
116
+ `invokevirtual java.io.PrintStream.print(…)` / `println(…)` with an `int`,
117
+ `char`, `boolean`, `java.lang.String` or `java.lang.Object` argument.
118
+
119
+ Other instructions (objects, arrays, `long`, `float`, `double`, …) are
120
+ reported when the program is loaded and stop the simulation when they are
121
+ reached. Constructors (`<init>`) are not executed: the simulation starts with
122
+ `main`.
123
+
124
+ ## Checks
125
+
126
+ The simulator stops with an explanation when something happens that the JVM
127
+ would reject or that ends the program:
128
+
129
+ * the operand stack grows beyond `.limit stack` (a warning the first time this
130
+ happens in a method, and Play stops; the cells beyond the limit are always
131
+ marked red),
132
+ * a local variable beyond `.limit locals` is used, or one is read before a
133
+ value has been stored in it,
134
+ * an instruction finds too few values or values of the wrong type on the stack,
135
+ * a method runs past its last instruction,
136
+ * a division by zero (`java.lang.ArithmeticException`).
137
+
138
+ When the program ends, the output area lists for every method the largest
139
+ number of values its operand stack has held, compared with `.limit stack`.
140
+
141
+ ## Development
142
+
143
+ pip install -e . # in a clone of the repository
144
+ python3 -m unittest discover -s tests
145
+
146
+ A release on GitHub with the tag `v` + version (e.g. `v0.1`, the version is
147
+ `__version__` in `pytunium/__init__.py`) publishes the package on PyPI (see
148
+ `.github/workflows/publish.yml`).
149
+
150
+ The machine (`pytunium/machine.py`) does not depend on the user interface:
151
+ every call of `Machine.step()` returns an `Event` that describes which cells
152
+ were taken from the stack, which cells were written and the formula of the
153
+ working area. The user interface (`pytunium/gui.py`) animates these events.
154
+
155
+ pytunium/
156
+ program.py parser for pytunia programs (Java notation and descriptors)
157
+ loader.py checks the syntax with pytunia, then parses
158
+ machine.py the simulated JVM; one Event per instruction
159
+ values.py values in the cells, Java int arithmetic
160
+ gui.py Tkinter user interface
161
+ examples/ Sum.jas, Hello.jas, Primes.jas
162
+ tests/ unit tests (no window is opened)
163
+
164
+ ## License
165
+
166
+ BSD 3-Clause, see `LICENSE.txt`.
pytunium-0.1/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # pytunium
2
+
3
+ A simulator for programs written in the assembler language of
4
+ [pytunia](https://github.com/karlstroetmann/pytunia), the JVM assembler of the
5
+ lecture *Formal Languages and Their Applications* (Chapter 12).
6
+
7
+ The window has three columns:
8
+
9
+ 1. **Program**: the assembler program. The next instruction is highlighted
10
+ in yellow, the instruction executed before in blue.
11
+ 2. **Stack**: the stack of the JVM. The cell that `SP` points to (the top of
12
+ the stack) is orange, the cell that `LV` points to (the first argument of
13
+ the current method) is blue. Each frame is marked with the name of its
14
+ method.
15
+ 3. **Working area**: what the current instruction does. For `iadd`, the two
16
+ operands move from the stack into the working area, the sum appears, and
17
+ the sum moves back onto the stack.
18
+
19
+ Below the columns, the output area shows what the program prints, and the
20
+ warnings and errors of the simulator.
21
+
22
+ ## Installation and start
23
+
24
+ pip install pytunium # installs pytunia, too
25
+ pytunium Sum.jas # or: python3 -m pytunium Sum.jas
26
+
27
+ Without a file, the example `Sum.jas` from Chapter 12 is shown. The examples
28
+ `Sum.jas`, `Hello.jas` and `Primes.jas` (generated by the compiler of
29
+ Chapter 13) are in `pytunium/examples`.
30
+
31
+ Options: `--font-size N` (default 14) and `--speed N` (1 = slow, 10 = no
32
+ animation).
33
+
34
+ pytunium needs Python 3.12 or newer with Tkinter. The installers from
35
+ python.org and Anaconda contain Tkinter; with Homebrew, install it with
36
+ `brew install python-tk`, on Debian/Ubuntu with `sudo apt install python3-tk`.
37
+ pytunia checks the syntax of the program first, so the error messages are the
38
+ same as when assembling.
39
+
40
+ ## Controls
41
+
42
+ | Button / key | Effect |
43
+ |---------------------------|----------------------------------------------------------|
44
+ | **Play** / Return | runs the program, animated with the chosen speed |
45
+ | **Step** / Space, → | executes one instruction |
46
+ | **Stop** / Return, Esc | stops Play |
47
+ | **Reset** / ⌘R (Ctrl+R) | reloads the file from disk and starts again |
48
+ | **Open…** / ⌘O (Ctrl+O) | loads another program |
49
+ | Speed | 1 (slow) … 9 (fast), 10 = no animation |
50
+ | click on a line number | sets or removes a breakpoint (Play stops before it) |
51
+ | ⌘+ / ⌘− / ⌘0 | larger / smaller / normal font (useful for a projector) |
52
+ | mouse wheel on the stack | scrolls the stack |
53
+
54
+ Reset reads the file again, so you can edit the program in an editor and
55
+ press Reset to simulate the new version.
56
+
57
+ ## The memory model
58
+
59
+ As in Chapter 12, there is a single stack. A method call does not copy its
60
+ arguments: the arguments on top of the caller's operand stack become the first
61
+ local variables of the new frame, and `LV` points to the first of them. A
62
+ frame with `L` local variables (`.limit locals L`) looks like this:
63
+
64
+ LV+L+2 … operand stack of the method
65
+ LV+L+1 saved LV: the value of LV in the calling method
66
+ LV+L return address: where the caller continues
67
+ LV+n … LV+L-1 the other local variables (shown as ? until assigned)
68
+ LV+0 … LV+n-1 the n arguments
69
+
70
+ The two grey cells are the bookkeeping cells. `ireturn` removes the frame,
71
+ puts the result where the arguments were, and restores `LV` from the saved
72
+ value. Cells above `SP` keep their old values (shown faintly), since `pop`
73
+ only decrements `SP`.
74
+
75
+ ## What is simulated
76
+
77
+ * int arithmetic with the semantics of Java: overflow wraps around, `idiv`
78
+ rounds towards 0, the remainder of `irem` has the sign of the dividend, the
79
+ shifts use the lowest 5 bits of the shift distance:
80
+ `iadd isub imul idiv irem ineg iand ior ixor ishl ishr iushr iinc`
81
+ * constants and the stack: `iconst_<n> bipush sipush ldc aconst_null dup pop swap nop`
82
+ * local variables: `iload istore aload astore` (also `iload_<n>` etc.)
83
+ * jumps: `goto if<cond> if_icmp<cond> if_acmpeq if_acmpne ifnull ifnonnull`
84
+ * static methods of the same class: `invokestatic ireturn areturn return`
85
+ * printing: `getstatic java.lang.System.out java.io.PrintStream` (or `err`) and
86
+ `invokevirtual java.io.PrintStream.print(…)` / `println(…)` with an `int`,
87
+ `char`, `boolean`, `java.lang.String` or `java.lang.Object` argument.
88
+
89
+ Other instructions (objects, arrays, `long`, `float`, `double`, …) are
90
+ reported when the program is loaded and stop the simulation when they are
91
+ reached. Constructors (`<init>`) are not executed: the simulation starts with
92
+ `main`.
93
+
94
+ ## Checks
95
+
96
+ The simulator stops with an explanation when something happens that the JVM
97
+ would reject or that ends the program:
98
+
99
+ * the operand stack grows beyond `.limit stack` (a warning the first time this
100
+ happens in a method, and Play stops; the cells beyond the limit are always
101
+ marked red),
102
+ * a local variable beyond `.limit locals` is used, or one is read before a
103
+ value has been stored in it,
104
+ * an instruction finds too few values or values of the wrong type on the stack,
105
+ * a method runs past its last instruction,
106
+ * a division by zero (`java.lang.ArithmeticException`).
107
+
108
+ When the program ends, the output area lists for every method the largest
109
+ number of values its operand stack has held, compared with `.limit stack`.
110
+
111
+ ## Development
112
+
113
+ pip install -e . # in a clone of the repository
114
+ python3 -m unittest discover -s tests
115
+
116
+ A release on GitHub with the tag `v` + version (e.g. `v0.1`, the version is
117
+ `__version__` in `pytunium/__init__.py`) publishes the package on PyPI (see
118
+ `.github/workflows/publish.yml`).
119
+
120
+ The machine (`pytunium/machine.py`) does not depend on the user interface:
121
+ every call of `Machine.step()` returns an `Event` that describes which cells
122
+ were taken from the stack, which cells were written and the formula of the
123
+ working area. The user interface (`pytunium/gui.py`) animates these events.
124
+
125
+ pytunium/
126
+ program.py parser for pytunia programs (Java notation and descriptors)
127
+ loader.py checks the syntax with pytunia, then parses
128
+ machine.py the simulated JVM; one Event per instruction
129
+ values.py values in the cells, Java int arithmetic
130
+ gui.py Tkinter user interface
131
+ examples/ Sum.jas, Hello.jas, Primes.jas
132
+ tests/ unit tests (no window is opened)
133
+
134
+ ## License
135
+
136
+ BSD 3-Clause, see `LICENSE.txt`.
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pytunium"
7
+ dynamic = ["version"]
8
+ description = "A simulator for programs written in the JVM assembler language of pytunia"
9
+ readme = "README.md"
10
+ # pytunia, which checks the syntax of the programs, needs Python 3.12
11
+ requires-python = ">=3.12"
12
+ dependencies = ["pytunia>=0.5"]
13
+ license = "BSD-3-Clause"
14
+ license-files = ["LICENSE.txt"]
15
+ authors = [{name = "Karl Stroetmann"}]
16
+ keywords = ["jvm", "assembler", "simulator", "stack machine", "education", "pytunia",
17
+ "jasmin", "bytecode"]
18
+ classifiers = [
19
+ "Development Status :: 3 - Alpha",
20
+ "Environment :: X11 Applications",
21
+ "Environment :: MacOS X",
22
+ "Environment :: Win32 (MS Windows)",
23
+ "Intended Audience :: Education",
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python :: 3 :: Only",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Programming Language :: Python :: 3.14",
29
+ "Programming Language :: Python :: 3.15",
30
+ "Topic :: Education",
31
+ "Topic :: Software Development :: Assemblers",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/karlstroetmann/pytunium"
36
+ Source = "https://github.com/karlstroetmann/pytunium"
37
+ Issues = "https://github.com/karlstroetmann/pytunium/issues"
38
+ pytunia = "https://github.com/karlstroetmann/pytunia"
39
+
40
+ [project.scripts]
41
+ pytunium = "pytunium.__main__:main"
42
+
43
+ [tool.setuptools]
44
+ packages = ["pytunium", "pytunium.examples"]
45
+
46
+ [tool.setuptools.package-data]
47
+ "pytunium.examples" = ["*.jas"]
48
+
49
+ [tool.setuptools.dynamic]
50
+ version = {attr = "pytunium.__version__"}
@@ -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__"]
@@ -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