Files
aji/tools/deque_vectors.py
T
dev 93405f69ce cli: add safe owning deque standard module
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.
2026-10-07 00:08:42 +03:00

61 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Check the public Deque fixture's byte vectors against Python's deque oracle."""
from collections import deque
from pathlib import Path
import re
FIXTURE = Path(__file__).resolve().parents[1] / "tests/conformance/source/deque/model.aji"
SEEDS = (3, 19, 42, 91)
def vectors(operations, values, indices):
queue = deque()
capacity = 3
result = [list(operations), list(values), list(indices), [], [], [], []]
for operation, value, index in zip(operations, values, indices):
assert operation < 6 and value in range(1, 64) and index < 9
failed = 0
returned = 0
if operation in (0, 1):
if len(queue) == capacity:
failed = 1
elif operation == 0:
queue.append(value)
else:
queue.appendleft(value)
elif operation in (2, 3):
if not queue:
failed = 1
elif operation == 2:
returned = queue.popleft()
else:
returned = queue.pop()
elif operation == 4:
capacity = max(capacity, index)
else:
if index >= len(queue):
failed = 1
else:
returned = queue[index]
queue[index] = value
result[3].append(failed)
result[4].append(returned)
result[5].append(len(queue))
result[6].extend(list(queue) + [0] * (8 - len(queue)))
return [bytes(values) for values in result]
def main():
calls = re.findall(r' trace\(heap, (.*?)\);', FIXTURE.read_text())
assert len(calls) == len(SEEDS), len(calls)
for seed, call in zip(SEEDS, calls):
strings = re.findall(r'ref b"((?:\\x[0-9a-f]{2})*)"', call)
actual = [bytes.fromhex(value.replace("\\x", "")) for value in strings]
assert len(actual) == 7 and all(len(row) == 32 for row in actual[:6]), seed
assert actual == vectors(*actual[:3]), f"fixture disagrees with Python deque for seed {seed}"
print(f"deque oracle vectors passed ({len(SEEDS)} seeds, {len(SEEDS) * 32} operations)")
if __name__ == "__main__":
main()