Skip to content

enable — Activating Optional Features

enable instructs the compiler to accept language constructs that are disabled by default. Without the directive, the parser rejects the block at compile time — not at runtime.

Common feature flags: simd (native/wasm backends), signals (vm/native), unsafe_blocks, inline_assembly, and experimental.* prefixes. Enabling a feature that the active backend does not support is a fatal error (E_FeatureNotAvailable). Unknown features only emit a warning, preserving forward compatibility when new versions of Zolo add flags you do not yet know.

The example below enables signals to register a SIGINT handler. Without the enable, the on signal block would be rejected by the parser on backends where signal handling does not exist (such as wasm):

enable signals unlocks on signal SIGINT { ... } for the entire module.

03-enable-feature.zolo
Playground
// Feature: opt into language features via `enable <feature>`.
//
// `enable` activates features the parser/lowering otherwise rejects.
// Unknown features emit a warning (forward-compat); enabling a feature
// that the active backend doesn't support is a hard error.
//
// Common feature flags (see specs/enable-requires-directives.md):
//   enable simd                 // SIMD intrinsics — native/wasm backends
//   enable signals              // `on signal SIGINT { ... }` — vm/native
//   enable unsafe_blocks        // raw memory + FFI escape hatch
//   enable experimental.tracing // forward-looking, subject to change

enable signals

use std::process

on signal SIGINT {
  print("Ctrl+C — graceful shutdown")
  process.exit(0)
}

print("press Ctrl+C to test the signal handler")

// Without `enable signals`, the `on signal SIGINT` block above would
// be rejected at parse time on backends where signal handlers aren't
// available (e.g. wasm). Putting the flag at the top of the file is
// the single source of truth for "this module wants signals".

Challenge

Remove the enable signals line from the file and try to compile. What error is reported? Now try replacing enable signals with enable unsafe_blocks — what changes in the message?

enespt-br