# Intrinsic Registry Normative catalogue of intrinsics for AIR format 0 (spec 05 §11). Each entry fixes operand types, results, effect, capability, consumption and failure model; behavior per profile is in spec 11 §8. Using an intrinsic needs the feature `capabilities`; intrinsics that mention resource types also need `resources`. Notation: `c` capability operand, `b` borrowed resource operand. Fallible intrinsics are terminators: results are the parameters of `@ok`, and `@err` receives one `io_error` (spec 06 §7). `c` = capability operand, `b` = borrowed resource operand, results are `@ok` parameters. ### Console (`io.*`) | Intrinsic | Operands | `@ok` | Effect | |---|---|---|---| | `io.stdout_write` | `c: cap`, `bytes: slice` | — | `io.write` | | `io.stderr_write` | `c: cap`, `bytes: slice` | — | `io.write` | | `io.stdin_read` | `c: cap`, `buf: slice_mut` | `n: usize` (0 = end of input) | `io.read` | Writes are all-or-error: on `@ok` every byte was written. ### Files (`fs.*`) Paths are `slice` holding an absolute path whose components are not empty, `.` or `..` (otherwise `invalid_input`). A path outside the capability's scope is `permission_denied`. | Intrinsic | Operands | `@ok` | Effect | |---|---|---|---| | `fs.open_read` | `c: cap`, `path` | `f: file` | `fs.read` | | `fs.create` | `c: cap`, `path` | `f: file` (truncated or new) | `fs.write` | | `fs.open_append` | `c: cap`, `path` | `f: file` (created if missing) | `fs.write` | | `fs.read` | `b: mut>`, `buf: slice_mut` | `n: usize` (0 = end of file) | `fs.read` | | `fs.write_all` | `b: mut>` or `mut>`, `bytes: slice` | — | `fs.write` | | `fs.sync` | `b: mut>` or `mut>` | — | `fs.write` | | `fs.close` | `f: file` for any mode (consumed on both edges) | — | — | An error from `fs.close` reports a failed final flush; the file is closed either way. ### TCP (`net.*`) Addresses are `slice` text `host:port` with a numeric IPv4 host (format 0). | Intrinsic | Operands | `@ok` | Effect | |---|---|---|---| | `net.listen` | `c: cap`, `addr` | `l: listener` | `net.listen` | | `net.accept` | `b: mut` | `s: stream` | `net.listen` | | `net.connect` | `c: cap`, `addr` | `s: stream` | `net.connect` | | `net.recv` | `b: mut`, `buf: slice_mut` | `n: usize` (0 = peer closed) | `net.read` | | `net.send_all` | `b: mut`, `bytes: slice` | — | `net.write` | | `net.close_stream` | `s: stream` (consumed) | — | — | | `net.close_listener` | `l: listener` (consumed) | — | — | All network operations block the calling execution unit (Phase 3 adds `thread.block` handling and task-aware I/O). ### Clock and random (infallible) | Intrinsic | Operands | Result | Effect | |---|---|---|---| | `clock.monotonic` | `c: cap` | `u64` nanoseconds | `clock.read` | | `random.fill` | `c: cap`, `buf: slice_mut` | — | `random.read` | ### Narrowing forms | Kind | Form | Argument | Result | |---|---|---|---| | `fs.read`, `fs.write` | `prefix` | `path: slice`, absolute | `ok`: same kind scoped to `path`; `err`: `invalid_restriction` if `path` is malformed, `not_subset` if it is not inside the current scope | ## Registry rules - An unknown name is `E0004`; operands of the wrong type `E1001`; a capability of the wrong kind `E3201`; an effect missing from the caller `E3101`. - Using the fallible form for an infallible intrinsic, or the reverse, is `E1001`; wrong `@ok`/`@err` parameter counts are `E5002`. - Resource operands marked "consumed" are consumed on both edges.