CLI Reference

The Zym CLI is a single binary that compiles, runs, and packages Zym programs. It is also a worked example of embedding the language, since every native it ships is registered through the same public C API any other host would use.

Quick Reference

CommandDescription
zym -v, --versionPrint the Zym version
zym -h, --helpPrint help
zym <file>Run a source, bytecode, or package file
zym <file.zym> -o <out.zbc>Compile source to bytecode or a package
zym <file.zbc> -o <out.zpk>Pack bytecode into a package
zym <file> -o <out>Pack to a standalone executable
zym <file> -o <out> -r <runtime>Use an explicit runtime for cross-platform packing

File Types

All three input forms are interchangeable at the command line: zym inspects what it was handed and does the right thing. The Pack module exposes the same packaging machinery to scripts.

Running Scripts

Write a file and run it directly. There is no build step for the common case.

hello.zym
print("Hello, Zym!")
terminal
zym hello.zym

Packaging

A script can be packed into a standalone executable that carries the runtime inside it. The result depends on nothing else being installed on the target machine.

pack, then distribute
zym main.zym -o my_app

# my_app has the runtime and your code inside
./my_app

Packing across platforms works by pointing at an alternate runtime:

cross-platform
zym main.zym -o my_app.exe -r windows

print

The one function the CLI registers directly into the global scope, rather than as a member of a module namespace. Everything else lives behind a namespace. See Conventions.

Writes to stdout, followed by a newline. Called with no arguments it prints an empty line. Called with exactly one argument it converts that value to a string and prints it, whatever its type. Called with two or more arguments the first must be a string, and is treated as a format string for the rest; passing a non-string first argument raises a runtime error.

the three forms
print()                            // empty line
print(42)                          // any single value, stringified
print("%s scored %n", name, score)  // format string + arguments

Format specifiers are type-checked: passing a value of the wrong kind raises a runtime error naming the specifier and the position, rather than printing something misleading.

SpecifierExpects
%vany value, stringified without a type check
%sstring
%nnumber
%bbool
%llist
%mmap
%tstruct
%eenum
Unknown specifiers raise. Anything outside the table above is a runtime error, not a literal, so a typo surfaces immediately instead of silently reaching output.

Native Modules

Each module is a single global identifier holding a namespace of methods. They are registered at VM startup through the public C API, which means the catalog below is not privileged. A host embedding zym_core registers its own natives exactly the same way.

The catalog is capability-gated. A parent VM decides which slice of it a child VM may use, and a child can only pass on what it was granted. It cannot widen its own authority. See Zym.