Embed std.deque with eleven generic operations implemented entirely in safe Aji over initialized Option<T> buffer slots. Bounded pushes and moving pops work at both ends; full pushes, out-of-bounds replacements and nonempty free return ownership to the caller. Explicit reserve preserves order and all state on allocation failure, charges the old and new slot capacities at the allocation peak, and rotates whole values after successful growth. No AIR, verifier or runtime change. Specify the visible representation invariant, tag-inclusive allocation accounting and empty-only cleanup. Add RFC 0025, a runnable owning example, source/CLI conformance and CI coverage. Complete STD-6c; HashMap, HashSet and BinaryHeap remain STD-6d. Validation: unit tests and 785 full conformance cases; 28 deque fixtures; focused collection after every instruction and 12 schedule seeds over four quanta; 136 source/package/hosted CLI checks; an independent Python deque oracle for 128 operations and 71 small growth configurations; 93/93 source coverage; Zig formatting, staged whitespace and bundles. Reference cost: full source excluding AIR grows 52,384 -> 53,993 cl100k tokens (+3.1%); Quick Reference 7,667 -> 7,747 (+1.0%). AIR stays at 175,736 bytes. Construction/growth still incur interpreter prefix-copy overhead; no native performance or empirical MCC benefit is claimed.
4.8 KiB
Aji standard library
Implementation in ordinary safe .aji: bytes, math, UTF-8, hex, Base64 and integer formatting, with 39 monomorphic functions, 14 monomorphic result enums and option/result templates with two Copy classification helpers. They are embedded with the compiler and compiled through the normal frontend/verifier when imported. They are library modules, not standalone main programs.
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 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 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 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 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, 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 · Specification · Plan · Import RFC · Endian RFC · Bounded operations RFC · Text RFC
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 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 content. STD-6a/b adds initialized buffer 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 and RFC 0024.
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 and include its tag in the charge. Users drain/consume their elements before free. Deque example and RFC 0025.