Files
aji/docs/reference/intrinsics.md
T
dev 571cc6e362 spec: accept RFC 0007 and integrate I/O and linear resources
- spec 06 §6-§7: feature resources, consumption and verifier rules,
  io_error
- spec 05 §11.1 fallible intrinsic form; spec 07 §8.7 frozen built-in
  enum variants, §8.9 resource types; spec 07a resources and run record
  fields; spec 11 §8 execution profiles, blocked outcome, result channel
- reference/intrinsics.md: formal catalogue; capabilities.md: io_error
  and fs prefix narrowing
- features: resources published, linear_aggregates reserved
2026-10-04 13:52:26 +03:00

69 lines
3.7 KiB
Markdown

# 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<io.write>`, `bytes: slice<u8>` | — | `io.write` |
| `io.stderr_write` | `c: cap<io.write>`, `bytes: slice<u8>` | — | `io.write` |
| `io.stdin_read` | `c: cap<io.read>`, `buf: slice_mut<u8>` | `n: usize` (0 = end of input) | `io.read` |
Writes are all-or-error: on `@ok` every byte was written.
### Files (`fs.*`)
Paths are `slice<u8>` 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<fs.read>`, `path` | `f: file<read>` | `fs.read` |
| `fs.create` | `c: cap<fs.write>`, `path` | `f: file<write>` (truncated or new) | `fs.write` |
| `fs.open_append` | `c: cap<fs.write>`, `path` | `f: file<append>` (created if missing) | `fs.write` |
| `fs.read` | `b: mut<file<read>>`, `buf: slice_mut<u8>` | `n: usize` (0 = end of file) | `fs.read` |
| `fs.write_all` | `b: mut<file<write>>` or `mut<file<append>>`, `bytes: slice<u8>` | — | `fs.write` |
| `fs.sync` | `b: mut<file<write>>` or `mut<file<append>>` | — | `fs.write` |
| `fs.close` | `f: file<M>` 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<u8>` text `host:port` with a numeric IPv4 host (format 0).
| Intrinsic | Operands | `@ok` | Effect |
|---|---|---|---|
| `net.listen` | `c: cap<net.listen>`, `addr` | `l: listener` | `net.listen` |
| `net.accept` | `b: mut<listener>` | `s: stream` | `net.listen` |
| `net.connect` | `c: cap<net.connect>`, `addr` | `s: stream` | `net.connect` |
| `net.recv` | `b: mut<stream>`, `buf: slice_mut<u8>` | `n: usize` (0 = peer closed) | `net.read` |
| `net.send_all` | `b: mut<stream>`, `bytes: slice<u8>` | — | `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<clock.read>` | `u64` nanoseconds | `clock.read` |
| `random.fill` | `c: cap<random.read>`, `buf: slice_mut<u8>` | — | `random.read` |
### Narrowing forms
| Kind | Form | Argument | Result |
|---|---|---|---|
| `fs.read`, `fs.write` | `prefix` | `path: slice<u8>`, 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.