Command line
Everything the zyn command does. zyn --help prints a summary.
#Commands
| Command | What it does |
|---|---|
zyn run app.zyn [args...] | Checks and runs a program. What comes after the file goes to the program |
zyn app.zyn [args...] | The same as zyn run |
zyn test app.zyn | Runs the program's test blocks |
zyn build app.zyn | Compiles the program to app.jar |
zyn build --native app.zyn | Compiles the program to an executable that needs no Java |
zyn init [name] | Makes a project: a build.zyn and src/main.zyn |
zyn deps | In a project: resolves its dependencies and shows them as a tree |
zyn repl | Type Zyn and see results at once |
zyn lsp | Runs the language server, for editors (over stdin and stdout) |
zyn --version | Shows Zyn's version |
#Running programs
zyn run app.zyn
zyn run --jvm app.zyn # compile to JVM bytecode first, then run (faster for long programs)
zyn run --native app.zyn # compile to a native executable first, then runOptions go before the file: everything after the file is the program's.
In a project, leave out the file: zyn run, zyn test and zyn build work on the project, from any folder inside it, with its dependencies. There, zyn run a b passes a b to the program, and zyn run -- --verbose passes arguments that look like options.
| Option | For | What it does |
|---|---|---|
--jvm | run, test | Compile to JVM bytecode and run that, instead of interpreting |
--native | run, test, build | Compile to a native executable (Zig is downloaded if needed, see Native programs) |
--classpath <jars> | run, test, build | Java libraries to use, separated by : (; on Windows). libs/* means every jar in libs, libs/** also those in its subfolders |
-o <file> | build | Where to write the jar or executable (by default next to the .zyn file) |
--no-runtime | build | Leave Zyn's runtime out of the jar (for when something else provides it) |
--target <system> | build --native | Build for another system: linux, windows, macos, linux-arm or macos-arm |
--offline | run, test, build, deps | In a project: don't download anything, use what's already there |
--update | deps | Check the repositories for newer snapshots |
Programs that use Java classes always run through the JVM compiler, also with a plain zyn run.
#Program arguments
The arguments come after the file. fn main(args: List<String>) gets them, and args() returns them anywhere in the program:
fn main(args: List<String>) {
if args.isEmpty() {
println("Usage: app <file> [--verbose]")
return
}
let verbose = args.contains("--verbose")
println("Reading {args[0]}, verbose: {verbose}")
}$ zyn run main.zyn report.txt --verboseReading report.txt, verbose: true
// A script: args() works without main too
let numbers = args().map { it.toIntOrNull() ?? 0 }
println("The sum is {numbers.sum()}")$ zyn run main.zyn 1 2 3The sum is 6
Built programs get theirs the usual way: java -jar app.jar a b and ./app a b.
#Exit codes
| Code | Meaning |
|---|---|
| 0 | Everything went well |
| 1 | zyn test: some tests failed |
| 64 | The command was used wrongly |
| 65 | The program (or build.zyn) has errors, found before it ran |
| 69 | A project's dependencies couldn't be downloaded |
| 70 | The program stopped with an error while running (panic, a failed assert, an index out of bounds, ...) |
| 71 | A bug in Zyn itself |
Programs see these too: a program that panics ends with 70, whether interpreted, a jar or native.
#Where imports are found
import utils.text loads utils/text.zyn from the folder of the file you run, from whichever file the import is in. In a project, imports start from the folder of its main file (src/). import java.util.UUID, when there is no java/util/UUID.zyn, imports a Java class. See Modules.
#Building
zyn build app.zyn # app.jar, run with: java -jar app.jar
zyn build -o dist/tool.jar app.zyn
zyn build --native app.zyn # app (app.exe on Windows)
zyn build --native --target windows app.zynA resources/ folder next to the program is copied into the jar as it is (configuration files, images, a plugin's plugin.yml). See The JVM and Native programs.
#Environment variables
| Variable | What it does |
|---|---|
ZYN_ZIG | The zig program to use for native builds |
ZYN_HOME | Where Zyn keeps what it downloads: Zig, and projects' Maven libraries (by default ~/.zyn) |
ZYN_NO_ZIG_DOWNLOAD=1 | Never download Zig; native builds need one installed |
ZYN_GC_STATS=1 | Native programs print what their garbage collector did |
ZYN_GC_THRESHOLD=<bytes> | Native programs collect garbage after this many bytes (for testing) |