cli: add supplied-buffer decimal integer formatting to std
This commit is contained in:
30 files changed
+3609
-11
No files matched your search
@@ -10,7 +10,7 @@ APIs SHOULD offer one canonical operation for a common need, small documentation
|
||||
|
||||
## 2. Bootstrap module registry
|
||||
|
||||
The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.math` and `std.utf8`. They are implemented in safe `.aji` with `effects []`; their stable source paths are `std/bytes.aji`, `std/encoding/base64.aji`, `std/encoding/hex.aji`, `std/math.aji` and `std/utf8.aji`, respectively. Spec 15 §13 defines imports; the reference API tables are in `reference/std.md`. All operations are deterministic in every profile, have no concurrency effects and allocate no heap memory. Ordinary interpreter fuel limits apply.
|
||||
The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.fmt`, `std.math` and `std.utf8`. They are implemented in safe `.aji` with `effects []`; their stable source paths are `std/bytes.aji`, `std/encoding/base64.aji`, `std/encoding/hex.aji`, `std/fmt.aji`, `std/math.aji` and `std/utf8.aji`, respectively. Spec 15 §13 defines imports; the reference API tables are in `reference/std.md`. All operations are deterministic in every profile, have no concurrency effects and allocate no heap memory. Ordinary interpreter fuel limits apply.
|
||||
|
||||
### 2.1 `std.math`
|
||||
|
||||
@@ -123,3 +123,17 @@ Decoding MUST accept only canonical standard Base64: input length divisible by f
|
||||
### 2.7 Text/encoding safety and compatibility
|
||||
|
||||
Sections 2.5/2.6 use safe source, ordinary calls, integer operations, slices, local fixed-size tables and enums. They declare `effects []`, allocate no heap, retain no borrow and consume no owner/resource. Work is O(input length) with constant auxiliary storage. The preserved invariant is shared-read/exclusive-write access within supplied initialized slices, no escaping borrow and no mutation on returned encoding errors. Existing verifier call/alias/lifetime/bounds/initialization/enum rules and deterministic interpreter behavior apply without a privilege, new transfer function, diagnostic, AIR feature or runtime primitive. Valid slices MUST NOT produce bounds, arithmetic, cast or shift traps; malformed bytes and capacity failure are results. Deterministic and hosted profiles behave identically. Existing APIs, source syntax and AIR format 0 retain their contracts.
|
||||
|
||||
### 2.8 Supplied-buffer integer formatting
|
||||
|
||||
`std.fmt` provides `write_u64`, `write_i64`, `write_usize` and `write_isize`. Each takes `(dst: slice_mut<u8>, value: T)` with the named integer type T, and returns `std.fmt.WriteResult`, an ordinary Copy enum:
|
||||
|
||||
```aji
|
||||
enum WriteResult { ok(usize), short_output }
|
||||
```
|
||||
|
||||
The functions MUST produce the exact ASCII decimal representation of value: `0` for zero, no leading zeroes otherwise, and a leading `-` exactly for negative signed values. No plus sign, whitespace, padding, locale transformation or terminator is written. `usize`/`isize` use the target pointer width (spec 09 §9); all values, including signed minima and unsigned maxima, MUST be supported.
|
||||
|
||||
When dst can hold the complete representation, the function MUST write exactly that prefix, preserve every remaining byte and return `ok(count)` with its length, including any sign. Otherwise it MUST return `short_output` and leave the entire destination unchanged. Empty output always fails, including for zero. Capacity MUST be checked before any write. To append, the caller passes a sub-slice at an explicit offset and advances it only after success; no implicit cursor, returned borrow, growable string or format-string language is introduced. Text copying uses `std.bytes.copy`; byte-to-hex encoding remains `std.encoding.hex`.
|
||||
|
||||
The preserved invariant is exclusive writes only within the supplied initialized slice, no escaping borrow, and no partial mutation on returned failure. Functions declare `effects []`, allocate no heap, use constant scalar auxiliary storage and O(decimal digit count) work. Existing call, initialization, alias, lifetime, bounds and enum verifier rules apply; conflicting live borrows MUST reject even on short output. No new verifier state, runtime rule, diagnostic, AIR feature or authority is added. Valid slices and every scalar value MUST NOT produce arithmetic, cast or bounds traps; interpreter fuel exhaustion remains an environment outcome and is outside the returned-error preservation guarantee. Behavior is identical in deterministic and hosted profiles. Existing APIs, source syntax and AIR format 0 retain their contracts.
|
||||
Reference in new issue
Block a user