run vs build
En esta página
Zolo ofrece dos modos principales de ejecución. zolo run interpreta el
programa directamente en la VM — ideal para scripts, iteración rápida y para
funcionalidades que dependen del preludio de la VM (signals, schemas, effects,
channels, máquinas de estado). zolo build compila vía Cranelift y produce
un ejecutable nativo real para la plataforma del host; no hay Lua ni VM en el
binario de salida.
El mismo programa funciona en ambos backends, siempre que no use funcionalidades exclusivas de la VM:
zolo run interpreta; zolo build emite un binario nativo. Salida idéntica en ambos.
// 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
Requiere la CLI o el host de Zolo; ábrelo en el playground o ejecútalo localmente.
Atención: el backend nativo no carga el preludio de la VM. Globales como
signal,schema,effect,machineysend/recvno existen en el ejecutable nativo — llamarlos retornaríanilen silencio. Usazolo rundurante el desarrollo yzolo buildpara distribuir el binario final.
Desafío
Agrega una llamada a signal(0) al ejemplo e intenta zolo build. ¿Qué
ocurre? Elimínala y repite el build — observa la diferencia.
Consulta también