Skip to content

run vs build

Zolo offers two main execution modes. zolo run interprets the program directly on the VM — ideal for scripts, rapid iteration, and features that depend on the VM prelude (signals, schemas, effects, channels, state machines). zolo build compiles via Cranelift and produces a real native executable for the host platform; there is no Lua or VM in the output binary.

The same program works on both backends, as long as it does not use VM-exclusive features:

zolo run interprets; zolo build emits a native binary. Identical output on both.

01-run-vs-build.zolo
// Feature: the two backends — VM (`zolo run`) vs native (`zolo build`)
// Syntax: `zolo run file.zolo`  |  `zolo build file.zolo`
// When to use: `run` for scripts, REPL-speed iteration, and VM-only
//   features (signals, schemas, effects, comptime-emit, channels,
//   machines). `build` for a standalone native executable.

// This program runs identically on both backends:
//
//   zolo run  30-compilation/01-run-vs-build.zolo   # interpreted (VM)
//   zolo build 30-compilation/01-run-vs-build.zolo  # native binary (Cranelift)
//   ./01-run-vs-build                               # then run the binary
//
// `zolo build` with no `--emit` defaults to a NATIVE executable compiled
// through Cranelift. There is no Lua/VM in the output — it is a real
// machine-code binary linked for the host platform.

let answer = 6 * 7
print("the answer is", answer)

// Gotcha: the native backend has no VM prelude. Globals the VM installs
// (signals, schemas, effects, channels, `machine`) are NOT available when
// you `zolo build`. Use `zolo run` for those. See the README capability
// matrix for the full VM-only list.
//
// expected (either backend):
//   the answer is	42

Requires the Zolo CLI/host — open in the playground or run locally.

Warning: the native backend does not load the VM prelude. Globals such as signal, schema, effect, machine, and send/recv do not exist in the native executable — calling them would silently return nil. Use zolo run during development and zolo build to distribute the final binary.

Challenge

Add a call to signal(0) to the example and try zolo build. What happens? Remove it and repeat the build — observe the difference.

See also

enespt-br