Install Zero
You can try every part of Zero in this site's playground and tutorial: the compiler runs in your browser. To compile programs on your own machine, build the compiler from source.
Build the compiler
Zero is written in C++20 and has no dependencies besides CMake 3.20 or newer and a C++20 compiler: Clang, MSVC, or GCC. On Windows, the Visual Studio developer tools provide everything; Ninja is recommended everywhere.
-
Configure and build
From a checkout of the Zero repository:
cmake -S . -B build/native -DCMAKE_BUILD_TYPE=Release cmake --build build/native --config Release --target zeroThe compiler is
build/native/bin/zero(orbuild/native/bin/Release/zerowith a multi-configuration generator). -
Run a program
Save this as
hello.zero:fun main() let answer = 6 * 7 assert answer == 42 endzero hello.zeroThe program runs in the interpreter. It exits with status 0 when every assertion holds, and prints a diagnostic otherwise.
-
Run the tests (optional)
ctest --test-dir build/native -C Release --output-on-failure
Choose how a program runs
| Command | What it does |
|---|---|
zero app.zero | Checks the program and runs it in the interpreter. |
zero --stop-after check app.zero | Only checks it: syntax, types, and every other compile-time rule. |
zero --jit app.zero | Compiles to native x64 or ARM64 code and runs it in the same process. |
zero --compile-native app.exe app.zero | Writes a standalone native executable. |
zero --compile-cpp app app.zero | Generates C++20 and compiles it with your C++ compiler. |
zero --emit-cpp app.cpp app.zero | Writes the generated C++20 source. |
Run zero --help for every option, and read
The Toolchain for details.
Editor support
The compiler is also a language server (zero --lsp) and a debug adapter
(zero --dap). The repository's vscode/ folder contains a Visual
Studio Code extension that uses both: package it with npx vsce package and
install the resulting .vsix with code --install-extension.
The compiler in the browser
This site runs the same compiler and interpreter, built for WebAssembly with Emscripten. It
checks and runs programs, and answers the editor's questions (completion, hover, go to
definition). It cannot generate native code or load native libraries; programs that print
use the browser's zero.console library instead.