Skip to content

Running Programs

w4ffl35 edited this page Aug 24, 2026 · 13 revisions

Running Programs

Curlee’s execution model is:

  1. curlee check (static pipeline + verification)
  2. curlee run (only if check passes)

Freestanding target (curlee build)

For the freestanding surface (Phys<T>, extern fn, see Language Syntax), execution is not through the VM. The freestanding execution path is:

  • curlee build <entry.curlee> — verify, then emit freestanding C (default out.c).
  • curlee build --target freestanding-c <entry.curlee> — the only supported target (the default); the flag exists for explicitness and forward-compat.
  • curlee build --link -o kernel.elf <entry.curlee> — emit C, compile it with gcc -ffreestanding -fno-builtin -nostdlib -c, assemble runtime/crt0.S, and link with runtime/linker.ld into a bootable x86-64 multiboot2 kernel ELF.
  • -o - writes the C to stdout (not valid with --link).

Verification gate:

  • curlee build runs the full pipeline first (lex → parse → resolve → type-check → verify).
  • No proof, no build: on verification or codegen failure, nothing is emitted and the exit code is non-zero.

phys.mem capability:

  • phys.mem is a real freestanding capability granting Phys<T> read()/write() MMIO access under unsafe. It is not v1-forbidden (it is not a Python-interop capability).
  • The VM never runs freestanding programs: curlee run rejects Phys/extern bodies (the front-end emits Phys is freestanding-only and not supported in the VM). Use curlee build for the freestanding execution path.

qemu boot steps (hello-kernel):

./build/linux-debug/curlee build --link -o kernel.elf tests/codegen/kernel_hello.curlee
qemu-system-x86_64 -kernel kernel.elf
  • The image carries a multiboot2 header (for GRUB) and a PVH ELF note (XEN_ELFNOTE_PHYS32_ENTRY in .note.Xen, for QEMU). QEMU's -kernel loader does not support multiboot2; the PVH note is what makes qemu -kernel boot the uncompressed 64-bit ELF. Both are emitted by runtime/crt0.S and kept by runtime/linker.ld.
  • kernel_hello prints Hi via the runtime's weak curlee_putc and halts deterministically via curlee_halt.
  • The qemu smoke (CI freestanding job / scripts/freestanding_ci.sh) links a smoke-only driver that overrides the weak curlee_putc/curlee_halt to write to COM1 and QEMU's isa-debug-exit device, so a successful boot is asserted by exit status 3.

Bundle workflow (v1):

  • curlee bundle build ... <entry.curlee> <out.bundle> produces a proof-carrying bundle artifact.
  • curlee bundle verify <out.bundle> validates integrity.
  • curlee run --bundle <out.bundle> <entry.curlee> executes bundled bytecode deterministically.

Determinism

Curlee’s VM is designed to be deterministic (see Glossary): given the same bytecode and inputs, it produces the same results.

Seeded RNG is deterministic when both bytecode and seed are fixed:

  • __rng_next_int(max_exclusive, rng) requires capability rng.seeded.
  • curlee run --seed <n> ... provides deterministic RNG state for that run.
  • Missing --seed with rng.seeded usage fails deterministically with a runtime error.
  • max_exclusive must be > 0; otherwise runtime fails deterministically.

Resource bounds (fuel)

Execution is resource-bounded via a fuel budget (see Glossary). When fuel is exhausted, the VM halts deterministically.

By default, the CLI uses a fixed deterministic fuel budget (10000) when running bytecode.

You can override it:

curlee run --fuel <n> <file.curlee>

You can also pass deterministic RNG seed material:

curlee run --seed <n> <file.curlee>

If fuel is exhausted, curlee run fails with a runtime error message that includes out of fuel.

Runtime errors and spans

Runtime failures include an error message and (when available) a source span (see Glossary) derived from opcode span mapping.

Interactive reads are capability-gated:

  • __read_line(...) requires io.stdin.
  • Missing grants fail deterministically with a runtime capability error.
  • std.io.read_line(...) is the stdlib API wrapper over __read_line(...).
  • EOF is deterministic and returns empty string ("").
  • Over-limit lines fail deterministically with stdin line too long.

Terminal control is also capability-gated:

  • __tty_clear(...), __tty_write_at(...), and __tty_flush(...) require io.tty.
  • Missing io.tty grant fails deterministically with a capability error.
  • __tty_write_at(row, col, text, ...) uses zero-based coordinates and enforces deterministic bounds (0..999 for each axis).
  • TTY output ordering is deterministic: entries are buffered in execution order and emitted only at __tty_flush(...).

Filesystem effects are capability-gated:

  • __fs_read_text(path, ...) requires fs.read.
  • __fs_write_text(path, content, ...) requires fs.write.
  • Path validation is deterministic and rejects invalid paths (absolute paths, traversal via .., and invalid/empty paths).
  • Deterministic failure modes include:
    • fs file not found
    • fs access denied
    • fs file too large
    • fs content too large

Experimental graphics backend (Linux)

Curlee supports an experimental Linux window backend in run mode:

  • curlee run --graphics=window --cap gfx.window <file.curlee>

Rules:

  • The backend is opt-in via --graphics=window.
  • You must explicitly grant gfx.window; missing grant fails with a deterministic capability diagnostic.
  • Runtime backend failures (init/present) are surfaced as deterministic runtime diagnostics.
  • Bundled runs use the same capability gate:
    • curlee run --graphics=window --cap gfx.window --bundle <file.bundle> <entry.curlee>

Deterministic playback:

  • For the same bytecode + inputs + capability set, graphics command playback is deterministic.
  • The experimental backend emits a stable command stream (init then present) on successful runs.

Structured diagnostics (v1)

Curlee supports structured diagnostic output for incident tooling:

curlee <lex|parse|check|run> --diag-format <text|json> ...

When --diag-format json is selected, each diagnostic is emitted as a single JSON object with stable fields:

  • kind (always diagnostic)
  • severity (error, warning, note)
  • message
  • file
  • span (null or { "start": <byte>, "end": <byte> })
  • notes (array of { "message", "span" })

This format is intended for log aggregation and deterministic post-processing.

Profiling runbook (v1)

Curlee supports deterministic runtime profiling telemetry for run paths:

  • curlee run --profile ...
  • curlee run --profile-format <text|json> ...

Profile payload fields:

  • steps
  • fuel_limit
  • fuel_used
  • fuel_remaining
  • rng_seed (null/none if unset)
  • ok

Notes:

  • Profile output is bounded and deterministic (no wall-clock timing fields).
  • Profiling output is emitted for both success and runtime-failure outcomes.
  • In text mode, profile records are emitted as curlee profile: ... lines.
  • In JSON mode, profile records are emitted as a single {"kind":"profile", ...} object.

Interop safety (Python)

Python interop is not part of the Curlee v1 surface.

  • Source usage of python_ffi.* is rejected at compile/check time with a deterministic diagnostic.
  • There is no supported curlee run path for Python execution in v1.
  • Bundle/runtime enforcement also rejects:
    • bundle manifests that declare python.ffi / python.sandbox,
    • bundle bytecode containing the PythonCall opcode.

Design notes and post-v1 direction remain documented in Python Interop (Future).

Notes

  • Verification is separate from execution: a program that cannot be proven within the supported fragment is rejected.
  • Capabilities (see Glossary) are part of the long-term model; see Stdlib and Capabilities.
  • Versioning/deprecation guarantees for CLI/runtime behavior are defined in Release Checklist and Versioning.

Clone this wiki locally