01 / Prepare
Build the tools
Clone Ziran and build the tools. You need a C compiler and make. Go, Cargo, or Python 3.10 is needed only to run generated Go, Rust, or Python output. build/bin/ziran version prints the version you built; the latest release is v0.2.0.
git clone https://github.com/ziranlang/ziran.git
cd ziran
makemake builds in parallel on half of your cores at low priority, so the rest of the machine stays responsive. make install-user puts ziran in ~/.local/bin; the commands below use build/bin/ziran so they work without installing. To run the project’s tests, use make check. Prebuilt downloads are not available yet.
02 / Source
Write a module
Save this as hello.zi. A source file is a module named after its filename.
main :: () {
print("Hello, World!\n");
}print substitutes each % in its format with the next argument, so print("Hello, %!\n", name) greets any name. Write %% for a percent sign.
03 / Check and execute
Run the checked program
build/bin/ziran check --root . hello.zi
build/bin/ziran bundle --root . --entry hello:main -o hello.zib hello.zi
build/bin/ziran run hello.zibThe last command prints Hello, World!. To save checked IR, use build/bin/ziran ir --root . -o out hello.zi.
04 / Native output
Build a native program
The same checked source generates Rust, Go, Python, C, or C++. For Rust, Go, and Python, --exe with an entry writes a runnable program:
build/bin/ziran build --target=rust --exe --entry hello:main --root . -o out/rust hello.zi
cargo run --manifest-path out/rust/Cargo.toml
build/bin/ziran build --target=go --pkg main --exe --entry hello:main --root . -o out/go hello.zi
(cd out/go && go run .)
build/bin/ziran build --target=py --exe --entry hello:main --root . -o out/py hello.zi
python3 out/pyPython output is one file that needs only the Python standard library. C and C++ output is a module with a header that your program calls. Put #program_export on the line before main to make it a complete program:
build/bin/ziran build --target=c --root . -o out/c hello.zi
cc -std=c99 -Iout/c out/c/hello.c -o hello && ./helloUse --target=cpp for C++. --target=plan9-c writes experimental Plan 9 C. Every example on the examples page prints the same output on each of these targets.
Keep going
Follow the source contract
ziran.toml, dependencies, locks, and ziran install ↗Language directionSyntax, laws, evolution, and planned parallel execution ↗Implementation statusWhat the current compiler actually supports ↗