Repository navigation
Stdlib and Capabilities
This document defines the MVP boundary between builtins and stdlib modules, and shows how capability-bearing APIs work without ambient authority (see Glossary).
- Keep the runtime minimal and deterministic.
- Preserve verification-first guarantees: no hidden effects.
- Require explicit capabilities for any I/O or system effects.
Builtins are minimal, hard-coded operations needed to bootstrap the language:
-
print(expr)(MVP builtin; see capability gating below) - string concatenation via
String + String - arithmetic ops (
+,-,*, comparisons)
Rules:
- Builtins must not have ambient authority. If a builtin triggers an effect (like stdout), the VM/runner enforces an explicit capability check.
- Builtins should be deterministic and side-effect free by default.
Stdlib modules are regular Curlee modules that expose APIs gated by capabilities.
Minimal v1 modules (defined):
-
std.mathfn add1(x: Int) -> Intfn sub1(x: Int) -> Int
-
std.iofn identity_int(value: Int, out: cap io.stdout) -> Int
Reference implementation lives under stdlib/v1/std/ in the repository.
Stdlib modules are loaded using the same deterministic import rules as user modules.
Any effectful API requires a capability value (opaque token) passed explicitly.
Example (v1 syntax):
fn main(out: cap io.stdout) -> Unit {
print("hello");
return;
}
Notes:
-
cap <name>is a capability type, where<name>is a dotted identifier path likeio.stdout. - Capability values are not constructible in user code.
- The host/runner supplies authority via CLI flags (
curlee run --cap ...).
Curlee uses explicit capability tokens to prevent ambient authority.
The v1-forbidden list contains exactly the Python-interop capabilities:
-
python.ffi(forbidden) -
python.sandbox(forbidden)
phys.mem is not v1-forbidden: it is a real freestanding capability granting Phys<T>
read()/write() MMIO access (used by the freestanding-c build target). It cannot be
executed by the VM (Phys is freestanding-only, so curlee run rejects such programs), but
that restriction is enforced by the front-end/emitter, not by the capability gate. Declaring
cap phys.mem in a bundle manifest is therefore allowed.
- Capability types are written as
cap <qualified-name>. - Qualified names are dotted identifiers (for example
io.stdout). - Whitespace is not allowed around dots in qualified names (e.g.
cap io. stdoutis rejected).
- Capability values are opaque and only flow via variables/parameters/returns.
- Effectful operations require a capability-typed value to be in scope:
-
print(expr)requires a value of typecap io.stdout.
-
- If a required capability value is not in scope, type checking fails with a precise-span error:
missing capability value '<cap>' (add a parameter of type cap <cap>)
- Capability values are represented as
Unitat runtime (they carry no data). - Runtime authority is enforced by the VM using the host capability set passed in from the CLI.
Entry points:
- The runnable entry point may take capability parameters.
-
mainparameters are restricted to capability types in runnable code; the runtime synthesizes default capability values for those parameters.
-
curlee run --cap <name>grants a host capability string exactly matching the capability type name (e.g.io.stdout). -
curlee runchecks required vs granted capabilities before execution and emits an error at the use site when a capability is not granted.
- Bundles declare required capabilities in the manifest (see Bundles).
- Bundle execution is rejected deterministically if a required capability is not granted.
- v1 guardrail: bundles that declare
python.ffiorpython.sandboxare rejected.
- The VM
Printinstruction is gated by theio.stdoutcapability. - The CLI/runner grants capabilities explicitly (e.g.
curlee run --cap io.stdout ...). -
print(expr)compiles toPrintand returnsUnit.
These signatures are part of the v1 baseline surface and should remain stable unless explicitly revised:
// std/math.curlee
fn add1(x: Int) -> Int
fn sub1(x: Int) -> Int
// std/io.curlee
fn identity_int(value: Int, out: cap io.stdout) -> Int
Safety constraints for these modules:
-
std.io.identity_intrequires explicitcap io.stdoutin its signature. - No ambient capabilities are introduced by stdlib imports.
Python interop is de-scoped from v1 surface and documented as future work in Python Interop (Future).
- Modules are resolved using
import(see Modules-and-Imports). - Deterministic, local-only resolution: imports resolve relative to the entry source file / entry directory (no implicit stdlib search path yet).
- Import cycles are rejected.
- No network access or dynamic resolution.
-
String + Stringis allowed and deterministic. -
String + Intis not allowed (no implicit conversion). - Formatting should go through explicit stdlib APIs (future).
- Implemented:
-
print(expr)as a builtin that emitsPrint(capability-gated byio.stdout). - string literals in the emitter (minimal escape decoding).
-
String + Stringconcatenation.
-