cli: bootstrap verified std bytes and math with source imports
This commit is contained in:
52 files changed
+1000
-22
No files matched your search
@@ -58,6 +58,7 @@ effects [io.read, io.write]
|
||||
```
|
||||
|
||||
- A file holds one module: `module <dotted.path>`, then type and function declarations in any order.
|
||||
- Between the module header and declarations, `import <dotted.path>;` imports a built-in standard module (§13). `import` is contextual at this position; it remains an ordinary identifier elsewhere.
|
||||
- `//` starts a line comment.
|
||||
- Function `f` lowers to `@f`; type `T` to `@T`.
|
||||
- **Signature.** `fn name(params) -> type`, then optionally `from p` for a borrow return (spec 08 §11.3), then the line `effects [...]`, then the body block.
|
||||
@@ -466,3 +467,17 @@ Other rules:
|
||||
|
||||
- `*c` and any other ordinary read of a cell is `E4202`.
|
||||
- Effects are declared by the programmer (spec 05 §13).
|
||||
|
||||
## 13. Built-in standard modules
|
||||
|
||||
The compiler MUST provide the standard modules listed in spec 16 §2, pinned to its own version. An import MUST resolve only against that closed registry: no file-system search, environment variable, network fetch, package manifest, or build extension participates. Unknown modules are `E7002`; duplicate imports are `E7006`. Imports MUST precede declarations; a misplaced import or missing semicolon is `E7001`.
|
||||
|
||||
An imported function is called by its full path, for example `std.bytes.equal(ref a, ref b)`. An unknown member or a call without the corresponding import is `E7002`. Importing a module MUST NOT introduce unqualified names or aliases. Qualified standard calls MUST NOT resolve through a local binding named `std`. User functions with the same short name remain independent. Standard functions are ordinary function calls: their argument types, borrows, moves, effects and failure contracts follow the existing rules. Type arguments on these monomorphic functions are outside the grammar (`E7001`).
|
||||
|
||||
Lowering MUST append the complete function declarations of the imported modules after the program's declarations, in lexicographic module order and source declaration order within each module. For function `f` in module `m`, the AIR name starts as `__aji_` plus `m` with dots replaced by underscores, then `_f`. If that name collides with a program type/function or a previously linked standard function, the compiler MUST append the smallest positive decimal suffix `_1`, `_2`, … that is unused. Qualified source calls MUST use the resulting AIR name. This is name mangling, not an extension to the format-0 identifier grammar. The imported source is parsed and lowered as ordinary safe `.aji` and the combined AIR MUST pass the same verifier. No runtime dispatch or new AIR instruction is introduced. The feature header is the dependency closure of the combined module, including unused imported functions.
|
||||
|
||||
Imports grant no authority, perform no runtime initialization and allocate no program heap memory. Merely importing a module does not add effects to the caller's contract; calling an effectful function would require its declared effects under the usual call rule.
|
||||
|
||||
Canonical AIR MUST be independent of import order, working directory and execution profile for a fixed compiler and program. Source diagnostics and traps inside a standard function MUST identify its stable repository-relative source path (`std/math.aji` or `std/bytes.aji`) and its original line/column, rather than the program's path. `aji lower --annotate` MUST include that path on annotations for imported instructions. AIR locations remain available as in §10.
|
||||
|
||||
This increment exposes functions with built-in parameter/result types only. General user modules, dependency resolution, aliases, imported type names and generics require separate specifications.
|
||||
@@ -0,0 +1,33 @@
|
||||
# 16. Standard Library
|
||||
|
||||
## 1. Contract
|
||||
|
||||
The standard library SHOULD make CLI programs, storage components, network services and structured concurrent programs possible without external source dependencies. Scope and sequencing are tracked in `docs/plan/standard-library.md`; that roadmap does not imply that unimplemented APIs are available.
|
||||
|
||||
Standard APIs MUST expose allocation, authority, effects, ownership transfer and recoverable failure in their public contracts. Safe library source MUST pass the ordinary verifier. Unsafe or foreign implementations MUST use an explicit audited trusted boundary under spec 13; they MUST NOT masquerade as verified source. The library MUST NOT obtain ambient host authority.
|
||||
|
||||
APIs SHOULD offer one canonical operation for a common need, small documentation requirements, bounded memory behavior and stable repair guidance (spec 14 §8). Resource cleanup remains explicit. Pure byte/path transformations do not grant authority over files or sockets.
|
||||
|
||||
## 2. Bootstrap module registry
|
||||
|
||||
The built-in registry contains `std.math` and `std.bytes`. Both are implemented in safe `.aji` with `effects []`. 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`
|
||||
|
||||
- `min_u64(a: u64, b: u64) -> u64` returns the smaller operand.
|
||||
- `max_u64(a: u64, b: u64) -> u64` returns the larger operand.
|
||||
- `clamp_u64(value: u64, lower: u64, upper: u64) -> u64` returns `lower` below the range, `upper` above it, or `value` inside it. The inclusive range MUST satisfy `lower <= upper`; violation traps `T0002` before returning a value.
|
||||
|
||||
These are monomorphic functions, not a generic arithmetic facility. Checked/wrapping operators retain their existing semantics (spec 02); importing this module does not alter them.
|
||||
|
||||
### 2.2 `std.bytes`
|
||||
|
||||
Inputs are byte slices, not encoded text. No UTF-8 validation or locale interpretation occurs. Read-only parameters are `slice<u8>`.
|
||||
|
||||
- `equal(a, b) -> bool`: true exactly when lengths and all bytes agree.
|
||||
- `compare(a, b) -> i8`: unsigned-byte lexicographic comparison; returns exactly `-1`, `0` or `1`. The shorter of two matching prefixes sorts first.
|
||||
- `find(data, byte: u8) -> usize`: index of the first occurrence; `data.len` when absent. A found index is valid only for the searched slice and exactly when the result is less than its length. Indexing retains the ordinary bounds-check rules (`T0008` for an absent result used as an index).
|
||||
- `starts_with(data, prefix) -> bool`, `ends_with(data, suffix) -> bool`: true for matching prefixes/suffixes, including empty ones; false when the candidate is longer than `data`.
|
||||
- `fill(dst: slice_mut<u8>, byte: u8) -> void`: writes every byte of `dst`, including zero writes for an empty slice.
|
||||
|
||||
The library MUST NOT read or write outside a passed slice and MUST NOT retain or return any borrow. The verifier enforces existing shared/exclusive borrowing, lifetime and bounds rules; there is no library privilege or new transfer function. Read-only functions only read their slices; `fill` writes only its exclusive slice. None consumes an owner or resource. These operations MUST NOT trap for valid byte slices and scalar operands, apart from the execution environment's fuel limit.
|
||||
@@ -25,6 +25,7 @@ The specification is split by semantic domain. Rationale for major decisions liv
|
||||
| [13-contracts-and-unsafe.md](13-contracts-and-unsafe.md) | Normative draft | Contracts, proof status and unsafe boundaries |
|
||||
| [14-agent-efficiency.md](14-agent-efficiency.md) | Normative draft (design objectives) | Agent efficiency, Model Capability Compression, design review requirement |
|
||||
| [15-source-language.md](15-source-language.md) | Normative draft | The agent-facing source language `.aji` 0.1 (Phase 6A), lowering to AIR |
|
||||
| [16-standard-library.md](16-standard-library.md) | Normative draft | Standard library contracts and built-in pure modules |
|
||||
|
||||
## Reading order
|
||||
|
||||
|
||||
Reference in new issue
Block a user