Commit 333a0df
Adds the raw binary I/O surface that estate ABI-test ports need
(`raze-tui`'s 16-byte `RazeEvent` record, future tree-sitter-k9 /
tree-sitter-a2ml grammar fixtures, half of bofig's contract tests).
Companion to the read-only `bytesLength` / `bytesByteAt` /
`bytesAsciiSlice` accessors shipped in affinescript#504 (STEP 3 /
standards#242). Together the two PRs give AffineScript first-class
binary-buffer support.
## What lands
### `stdlib/Deno.affine` (+10 externs)
| extern | lowers to | notes |
|---|---|---|
| `bytes_new(n) -> Bytes` | `new Uint8Array(n)` | zeroed |
| `bytes_fill(n, byte) -> Bytes` | `(new Uint8Array(n)).fill(byte &
0xFF)` | all-byte buffer |
| `bytes_set_u8(b, off, v) -> Int` | `… .setUint8(off, v & 0xFF), 0` |
returns 0 |
| `bytes_set_u16_le(b, off, v) -> Int` | `… .setUint16(off, v & 0xFFFF,
true), 0` | LE |
| `bytes_set_u32_le(b, off, v) -> Int` | `… .setUint32(off, v >>> 0,
true), 0` | LE |
| `bytes_set_i32_le(b, off, v) -> Int` | `… .setInt32(off, v \| 0,
true), 0` | LE |
| `bytes_get_u8(b, off) -> Int` | `… .getUint8(off)` | |
| `bytes_get_u16_le(b, off) -> Int` | `… .getUint16(off, true)` | LE |
| `bytes_get_u32_le(b, off) -> Int` | `… .getUint32(off, true)` | LE |
| `bytes_get_i32_le(b, off) -> Int` | `… .getInt32(off, true)` | LE |
All multi-byte integer variants are little-endian — the estate's C ABI
contracts (raze-tui `raze-events.ads`, Idris2 `Events.idr`) are
LE-pinned. Setters return `Int = 0` so they compose in an
expression-statement position; the caller is responsible for the
buffer-bounds invariant (an out-of-range offset throws `RangeError` at
the host boundary). Bounds-check via `bytesLength` from #504.
### Tests
`tests/codegen-deno/bytes_binary_io.{affine,deno.js,harness.mjs}` —
round-trips a raze-tui-shaped RazeEvent record (LE i32 + u32 + u8 + u16
× 2) with field-level equality, plus boundary cases:
- u32 max (`0xFFFFFFFF`) round-trips
- i32 -1 preserves sign
- LE byte order verified byte-by-byte via `DataView` (`0x12345678`
writes low byte at offset 4, high byte at offset 7)
- `bytes_fill` masks `256 → 0`, `-1 → 0xFF`, `0xFF → 0xFF`
- `bytes_new` produces a zero-initialised buffer
## Verification
| step | result |
|---|---|
| `dune build bin/main.exe` | ✅ |
| `dune runtest` | ✅ 353/353 |
| `./tools/run_codegen_deno_tests.sh` | ✅ all harnesses (incl. the new
one) |
## Out of scope
- **Big-endian variants** — not needed by any current estate ABI;
revisit if/when an external API forces BE.
- **64-bit getters/setters** (`*_i64_le`) — defer; current STEP 4
candidates max out at 32-bit.
## Relation to #504 (STEP 3)
Both this PR and #504 add externs to `stdlib/Deno.affine` and lowerings
to `lib/codegen_deno.ml`. The two sets are disjoint at the symbol level:
- #504: `statIsFile`, `statIsDirectory`, `bytesLength`, `bytesByteAt`,
`bytesAsciiSlice`, `importMetaUrl`, `pub fn ends_with`, wildcard-let
codegen fix.
- this PR: 10 binary I/O externs in a separate section.
The bytes test fixture uses uniquely-named `let _r0 = …`, `let _r4 = …`,
etc. instead of the `let _ = …` form so this PR is independently
mergeable from #504; once #504 lands, the fixture could be simplified to
use the wildcard pattern.
## Refs
- Closes standards#326
- Refs: standards#239 (umbrella), standards#242 / #504 (STEP 3
predecessor), standards#243 (STEP 4 per-repo unblock target)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 815af9f commit 333a0df
5 files changed
Lines changed: 516 additions & 0 deletions
File tree
- lib
- stdlib
- tests/codegen-deno
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
545 | 545 | | |
546 | 546 | | |
547 | 547 | | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
548 | 561 | | |
549 | 562 | | |
550 | 563 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
76 | 119 | | |
77 | 120 | | |
78 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
0 commit comments