Zyn0.1.0

Command line

Everything the zyn command does. zyn --help prints a summary.

#Commands

CommandWhat 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.zynRuns the program's test blocks
zyn build app.zynCompiles the program to app.jar
zyn build --native app.zynCompiles the program to an executable that needs no Java
zyn init [name]Makes a project: a build.zyn and src/main.zyn
zyn depsIn a project: resolves its dependencies and shows them as a tree
zyn replType Zyn and see results at once
zyn lspRuns the language server, for editors (over stdin and stdout)
zyn --versionShows 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 run

Options 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.

OptionForWhat it does
--jvmrun, testCompile to JVM bytecode and run that, instead of interpreting
--nativerun, test, buildCompile to a native executable (Zig is downloaded if needed, see Native programs)
--classpath <jars>run, test, buildJava libraries to use, separated by : (; on Windows). libs/* means every jar in libs, libs/** also those in its subfolders
-o <file>buildWhere to write the jar or executable (by default next to the .zyn file)
--no-runtimebuildLeave Zyn's runtime out of the jar (for when something else provides it)
--target <system>build --nativeBuild for another system: linux, windows, macos, linux-arm or macos-arm
--offlinerun, test, build, depsIn a project: don't download anything, use what's already there
--updatedepsCheck 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}")
}
Output$ zyn run main.zyn report.txt --verbose
Reading report.txt, verbose: true
// A script: args() works without main too
let numbers = args().map { it.toIntOrNull() ?? 0 }
println("The sum is {numbers.sum()}")
Output$ zyn run main.zyn 1 2 3
The sum is 6

Built programs get theirs the usual way: java -jar app.jar a b and ./app a b.

#Exit codes

CodeMeaning
0Everything went well
1zyn test: some tests failed
64The command was used wrongly
65The program (or build.zyn) has errors, found before it ran
69A project's dependencies couldn't be downloaded
70The program stopped with an error while running (panic, a failed assert, an index out of bounds, ...)
71A 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.zyn

A 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

VariableWhat it does
ZYN_ZIGThe zig program to use for native builds
ZYN_HOMEWhere Zyn keeps what it downloads: Zig, and projects' Maven libraries (by default ~/.zyn)
ZYN_NO_ZIG_DOWNLOAD=1Never download Zig; native builds need one installed
ZYN_GC_STATS=1Native programs print what their garbage collector did
ZYN_GC_THRESHOLD=<bytes>Native programs collect garbage after this many bytes (for testing)