The JVM
zyn build compiles a program to JVM bytecode, in a jar that runs anywhere Java 17 or newer does. Compiled programs are much faster than interpreted ones, about as fast as the same program in Java or Kotlin, and they can use any Java library.
#Building a jar
zyn build app.zyn
java -jar app.jarThe jar has Zyn's small runtime inside (plain Java, no Kotlin), so it needs nothing else. Arguments work as usual: java -jar app.jar one two.
| Option | What it does |
|---|---|
-o out/tool.jar | Where to write the jar |
--no-runtime | Leave the runtime out (when something else puts it on the classpath) |
--classpath libs/* | Compile against Java libraries. They aren't copied into the jar |
In a project, zyn build needs no file and builds build/<name>-<version>.jar, with the project's implementation libraries inside, so java -jar runs it with nothing else.
To compile and run in one step, without keeping a jar: zyn run --jvm app.zyn. zyn test --jvm app.zyn runs the tests compiled.
#Resources
Files in a resources/ folder next to the program are copied into the jar as they are, keeping their folders: configuration files, templates, images, or a plugin's plugin.yml.
app.zyn
resources/
├── config.yml → config.yml in the jar
└── images/logo.png → images/logo.png in the jar#How fast
Running fib(27) and a 3-million-step loop:
| Way of running | Time |
|---|---|
zyn run (interpreter) | 1.37 s |
zyn build, then java -jar | 0.08 s |
| The same program in Java | 0.06 s |
zyn build --native | 0.01 s |
The interpreter starts at once and is best for trying things; compile anything that does real work.
#How Zyn maps to the JVM
Knowing this helps when Java code uses Zyn classes, as a plugin's server does.
| Zyn | JVM |
|---|---|
A file app.zyn | A class AppZyn; utils/text.zyn becomes utils.TextZyn |
| Top-level functions | Static methods of the file's class |
Top-level let and var | Static fields, set up the first time the file is used |
class Dog in app.zyn | A class Dog, with public fields; in utils/text.zyn it's utils.Dog |
| A project's classes | All of the above in the package zynproject.<project>: zynproject.hello_zyn.utils.Dog |
Int, Float, Bool, Char | long, double, boolean, char |
String | java.lang.String |
List, Map | java.util.List, java.util.Map |
| Lambdas | Objects of a small class; they also become Java interfaces like Runnable where those are expected |
data types and enum cases | Objects of zyn.runtime.Record |
| Generics | Erased to Object, as in Java |
The bytecode targets Java 17.