Files
ziran/README.md
T
waoziandClaude Opus 5.5 9ad5f481ef Name the tools by what they turn into what, and run verified ZX natively
The tools are renamed after their input and output: zi2zx lowers source
or ZIR to executable ZX, zx2native turns ZX into a native ELF, zx2wasm
into a wasm32 module, and zi2c, zi2go and zi2zir keep their roles under
cmd/ folders of the same names. zi2asm and the cmd/zir-* folders are
gone, and tests/tool_names.sh keeps the old names out. zx2native keeps
the direct encoder as its default; the machine pipeline replaces it once
it reaches parity.

The embedding API can run a verified bundle as x86-64 machine code in
memory. Code is written to RW pages, relocated, then switched to RX,
never RWX, and each instance gets its own data
(cmd/zir/zir_native_memory.c, zir_host_native.c). Backend selection is
BundleBackendPolicy: Engine and Native are strict, and Auto chooses by
platform only, never by whether one program fits. A native gap is a
named error, never a switch to the engine. Desktop x86-64 Auto stays on
the engine until the native backend is complete.

cmd/compiler_machine_image.zi adds the target-neutral machine image
contract. The machine verifiers reject unknown relocation kinds,
out-of-range symbols and addends, non-host external calls, native-width
mismatches and missing stack or fuel facts. The machine pipeline lowers
and encodes more of LIR. Docs, site pages, Kryon's build references and
the benchmarks use the new names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 22:07:42 -03:00

6.2 KiB

Ziran

Ziran is a general-purpose language with generated C and Go targets and a portable executable format. The toolchain checks source, saves checked modules, and builds portable programs you can run without a platform compiler.

Website & playground · Compiler guide · Implementation status

The compiler and portable runner are under active development. Language coverage and target limits are listed in the implementation status.

Try it

main :: () {
    print("Hello, World!\n");
}

Edit and run this example in the browser playground.

Quick start

You need Make, a C11 compiler, and GNU binutils. From the repository root:

make
build/bin/ziran run examples/hello.zi

This prints Hello, World!. To install the ziran command for your user, run make install-user and add ~/.local/bin to your PATH. Then start a project from a template and run it:

ziran new hello          # or --template lib, or a package's template
cd hello
ziran run -- Ada         # Hello, Ada!

See packages and projects for templates, dependencies, and ziran build/install.

Tools and formats

Use build/bin/ziran from the checkout, or ziran after installation.

Command Purpose
check Validate source and imports.
build Generate C or Go output.
ir / inspect Save checked modules and read their contents.
bundle / run Build and run portable programs; run --target=c FILE.zi -- ARGS runs C-generated scripts.
fmt Format source files.
guide / features / capabilities Explore syntax, support, and target limits.
api Query public declarations as JSON.

Source files use .zi, checked modules use .zir, and portable programs use .zx. Direct-native targets and the portable runner have different limits.

The experimental direct pipeline is source → .zir → linked LIR → verification → LIR optimization → portable .zx. Those verified ZX bytes run in the portable interpreter or, on an explicitly supported direct target, lower to machine code and a platform binary. That direct-native route is experimental and incomplete; its current gaps are tracked in the assembly plan. Generated C and generated Go are separate routes that also produce platform binaries after their own downstream toolchains run. “Native” in the assembly documentation means verified ZX instructions lowered directly to machine code, not a C- or Go-generated binary. zx2wasm (and ziran build --target=wasm) lowers the same verified ZX to a wasm32 module, and the bundle Wasm tier runs bundles in the browser through it; see ZX status.

The opt-in Linux x86-64 zx2native path now has a first console veneer: its static ELF owns _start, retries partial or interrupted write syscalls, and exits the process with exit_group. It links no libc or CRT. Literal print formats cover byte strings/text views, bools, every fixed signed and unsigned integer width, and %%; floats and unavailable platform services are named hard gaps. This implemented slice does not make the wider direct-native target matrix complete.

Host capabilities describe portable, typed services a program requires. Platform bindings implement those services for a host; they are separate from CPU instruction lowering and from each target's calling convention or syscall veneer.

Run source as a C-generated script with ziran task.zi arguments. Executable Unix scripts can start with #!/usr/bin/env ziran; after chmod +x task.zi, run them as ./task.zi arguments. See C-generated scripts.

Standard library

The library includes text and UTF-8 helpers, generic values, sorting, queues, JSON scanning, ZIP archives, and explicit HTTP and process capabilities. Native Linux adapters provide file, socket, timer, and other system operations.

See the standard library reference and compiler guide for imports and platform limits.

Documentation

Start here What it covers
Compiler guide Commands, imports, foreign functions, and standard modules.
Examples Small programs with source and output.
Implementation status Supported features and remaining work.
Architecture Compiler, runtime, and library boundaries.
Language direction Language design and tooling goals.
Jai parity roadmap Planned language work.
Benchmarks Compiler and runtime measurements.
Migration Repository migration details.

Kryon is a separate UI library that applications import explicitly.

Development

Run make check for the complete lean language, backend, and portable runtime suite. Pruning removed 263 redundant check scripts and their unused helpers. Workers follow the build queue's allocation; set CHECK_JOBS=1 to run serially. The check controller and its regression tests are written in Ziran.

The native command and formatter are written in Ziran. Compiler scanners, declaration, foreign binding, and using modifier syntax, enum validation and evaluation, type spelling and field parsing, expression and nested initializer grammar, statement expression extraction, loop headers, optional then, and compile-time branch syntax are also written in Ziran. Ziran also parses multiple results and bindings, normalizes procedure-type parameters, expands formatted builder statements, and rewrites symmetric operators, procedure-name expressions, and local procedure names. The rest of the compiler is still being migrated from C. A fresh build uses the generated modules in bootstrap/ to build a bootstrap compiler, then compiles their maintained cmd/compiler_*.zi sources for the ordinary tools. Run make check-bootstrap to verify that the generated seed matches the source. After changing a compiler module, use make update-bootstrap to refresh its seed.