Files
dev 8edec5b831 cli: add caller-buffer lexical path APIs
Add pure std.path queries and failure-preserving normalization/join using
safe reverse measurement/emission and caller-provided output storage.
Component queries return explicit Copy ranges; filesystem authority is
checked independently. Complete the STD-7 implementation gate.

Validation: 1079 conformance cases, 18 path cases with per-step collection
and 12-seed schedule stress, independent 132-path/49-join capacity oracle,
68 CLI checks, fourteen previous source/std CLI suites, unit/Quick Reference,
formatting, hosted smoke, 117/117 source coverage and reference budgets.
2026-10-07 13:41:45 +03:00

58 lines
6.7 KiB
Markdown

# Aji standard library
Nineteen compiler-pinned modules implemented in ordinary safe `.aji`. Imports compile through the normal frontend and verifier. Modules are embedded with the compiler; an installed compiler needs no runtime std search path.
| Modules | Purpose |
|---|---|
| `std.math`, `std.bytes`, `std.hash` | checked arithmetic, byte operations, endian reads/writes, non-cryptographic hashes |
| `std.utf8`, `std.encoding.hex`, `std.encoding.base64`, `std.fmt` | validation, caller-buffer encoding and decimal formatting |
| `std.option`, `std.result` | explicit generic result values |
| `std.vec`, `std.deque`, `std.map`, `std.hashmap`, `std.hashset`, `std.heap` | owning collections with explicit allocation, growth and draining |
| `std.io`, `std.io.reader`, `std.io.writer` | bounded I/O and owning buffered file adapters |
| `std.path` | pure lexical paths and caller-buffer normalization/join |
Owning collections support resources such as files and channel endpoints. Allocation requires explicit authority; resources must be consumed explicitly. Importing a module grants no capabilities. STD-0..7 is the intermediate foundation; remaining Std 0.1 system APIs and integration examples are tracked in the [plan](../docs/plan/standard-library.md).
```aji
module example
import std.bytes;
import std.math;
fn main() -> u64
effects []
{
var data: [u8; 4] = zero;
std.bytes.fill(mut data, 65);
assert(std.bytes.equal(ref data, b"AAAA"));
return std.math.min_u64(42, 100);
}
```
Run `zig build`, then `zig-out/bin/aji run --fuel 1000000 examples/std/bytes.aji`. No grants are needed for the pure modules. `zig build conformance -- --filter source/std` exercises the library; the full suite also checks the Quick Reference example.
Endian APIs read/write u16/u32/u64 in LE/BE order. Reads return `std.bytes.ReadU16`, `ReadU32` or `ReadU64` (`ok(value)` / `short_input`); writes return `std.bytes.WriteResult` (`ok` / `short_output`). A short write leaves the entire destination unchanged. Pass a sub-slice for an offset. [Endian example](../examples/std/endian.aji) returns 305419896 and needs no grants.
`std.bytes.copy` reuses `WriteResult` and preserves the whole destination on short output. `find_slice` returns `FindResult::found(index)` / `not_found`; explicit slices compose a split without returned borrows. `std.math.checked_add/sub/mul_u64` and the `_usize` forms return typed `ok(value)` / `overflow` enums; wrapping stays with `+%`, `-%`, `*%`. The [bounded example](../examples/std/bounded.aji) returns 10 without grants.
`std.utf8.next/validate` use Unicode scalar values and explicit byte offsets. `std.encoding.hex` and `std.encoding.base64` encode/decode into caller-provided buffers; malformed input and short capacity are enum results, with no destination mutation on returned errors. Hex emits lowercase and accepts mixed case. Base64 is canonical, padded and uses the standard alphabet. The [text example](../examples/std/text.aji) returns 8364 without grants.
`std.fmt.write_u64/i64/usize/isize` write decimal ASCII into supplied buffers with `WriteResult::ok(count)` / `short_output`. Counts include a negative sign; short output stays unchanged, suffixes stay unchanged on success and no terminator is written. The [formatting example](../examples/std/format.aji) composes `value=-42 count=7` with explicit offsets and returns 17 without grants.
The compiler uses its embedded copy, so rebuild after editing these files. An installed compiler needs neither this checkout nor a runtime std search path. Standard enum types use fully qualified names in signatures, constructors and matches. Package imports and imported struct literals use explicit manifest mappings ([example](../examples/modules/aji.toml), spec 15 §14). Explicit generics and whole-value owning option/result templates are implemented; std.vec uses the initialized buffer contract with explicit reserve, bounded push and empty-only free.
[API reference](../docs/reference/std.md) · [Specification](../docs/spec/16-standard-library.md) · [Plan](../docs/plan/standard-library.md) · [Import RFC](../docs/rfcs/0016-standard-library-bootstrap.md) · [Endian RFC](../docs/rfcs/0017-standard-endian-results.md) · [Bounded operations RFC](../docs/rfcs/0018-bounded-standard-operations.md) · [Text RFC](../docs/rfcs/0019-standard-text-encodings.md)
[Formatting RFC](../docs/rfcs/0020-supplied-buffer-integer-formatting.md)
`std.option.Option<T>` and `std.result.Result<T, E>` use explicit specialization and ordinary exhaustive enum matching. `is_some::<T>`/`is_ok::<T,E>` classify variants without allocation. [Generic example](../examples/std/generics.aji) returns 42; owners/resources are supported by linear_aggregates with exhaustive `match move`; borrows remain invalid members. The classification helpers keep Copy constraints.
STD-5 supports whole-value owning structs/enums/fixed arrays and individual own<T> content. STD-6a/b adds initialized buffer<T> and std.vec; no bulk operation hides nested cleanup.
`std.vec` provides nine generic functions over Copy/owning values, including files and channel endpoints. Explicit new/reserve require allocation authority; push never grows, free requires empty contents. [Vector example](../examples/std/vector.aji) and [RFC 0024](../docs/rfcs/0024-linear-buffers-and-vectors.md).
`std.deque` provides eleven generic functions for a bounded owning ring, including push/pop at both ends. Allocation is explicit in new/reserve; failed growth, full push and nonempty free preserve the queue. Slots hold Option<T> and include its tag in the charge. Users drain/consume their elements before free. [Deque example](../examples/std/deque.aji) and [RFC 0025](../docs/rfcs/0025-owning-deque.md).
`std.hash` provides FNV-1a 64 and Castagnoli CRC-32C, with one fresh and one continuation function per algorithm. It reads byte slices with effects [], no allocation or authority; numeric results and chunking are deterministic. These are non-cryptographic algorithms and hashes never establish key equality. [Hash example](../examples/std/hash.aji) returns 42 without grants. `std.map` supports numeric keys; `std.hashmap` and `std.hashset` use explicit static hash/equality operations, and `std.heap` uses an explicit static order. Complete ownership, failure and cleanup contracts are in the [API reference](../docs/reference/std.md).
`std.io` composes exact/bounded reads and limited copies into caller storage. `std.io.reader`/`std.io.writer` own a file and a fixed buffer, with explicit finish/discard; a failed writer preserves its first error and never retries. `std.path` uses slash-separated bytes in every profile; lexical success grants no filesystem authority. [Path example](../examples/std/path.aji) returns 42 without grants.