Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# NOW -- Port scripts/gen_w660.py (Python, 3 functions) to specs/port/scripts/gen_w660.t27 (published 2026-10-10)

## A bee's work on #8127, published from `queen-8127` (Closes #8127)

- The branch changes 1 file(s): `specs/port/scripts/gen_w660.t27`.
- `git diff --stat origin/master...queen-8127` reads: 1 file changed, 78 insertions(+)
- This entry is written by the publisher, not by the bee. A pull request must
add exactly one `docs/now/` entry and a bee has no way to know that: its brief
names a boundary file and acceptance criteria, and `docs/now/` is neither.
- What this entry does NOT establish: that the work is correct. The gates on the
pull request judge that, and they are the same gates every other change meets.
106 changes: 106 additions & 0 deletions specs/port/scripts/gen_w660.t27
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// SPDX-License-Identifier: Apache-2.0
// Port of scripts/gen_w660.py (issue #8127).
// The original writes the spec w660_bench_module_139x2p6_aos_var_call_write.t27: a
// [139][2][2][2][2][2][2]Pt grid literal whose points are numbered in row-major order.
// The decisions in it are the indent width, the coordinate of each point (2e + offset,
// wrapped at 32768) and the row-major point numbering build_tree's recursion threads
// through the shape. Building the text and writing the file are plumbing.
module gen_w660 {
const WRAP: u32 = 32768;
const INDENT_UNIT: u32 = 4;

// indent(level): the number of spaces for one indent level (" " * level).
fn indent(level: u32) -> u32 {
return INDENT_UNIT * level;
}

// coordinate(e, offset, step): x is step 0, y is step 1 -> (2e + offset + step) % 32768.
fn coordinate(e: u32, offset: u32, step: u32) -> u32 {
return (2 * e + offset + step) % WRAP;
}

// SHAPE: the grid's dims, one outer [139] and six [2]s. build_tree walks
// exactly this, one level per dimension, the way the original slices
// shape[1:] on every recursive call.
const SHAPE: [7]u32 = [139, 2, 2, 2, 2, 2, 2];

// build_tree(shape, depth, base): the original's recursion, one dimension
// per level. A leaf row (the last dimension) lays out n single points and
// returns base + n; above it, n subtrees of the remaining shape run one
// after another, each starting from the base the previous sibling ended on.
// The original's third argument, offset, feeds only the leaf coordinates --
// coordinate()'s decision here -- so it is not threaded; the literal text
// it joins from these calls is plumbing. The point numbering the base
// threading computes (e at index path [i0]..[ik] is base + i0*d1*..*dk +
// ... + ik) is the decision, and the next base is what this returns, the
// second slot of the original's tuple.
fn build_tree(shape: [7]u32, depth: u32, base: u32) -> u32 {
if (depth == 6) {
return base + shape[depth];
}
var b: u32 = base;
var i: u32 = 0;
while (i < shape[depth]) {
b = build_tree(shape, depth + 1, b);
i = i + 1;
}
return b;
}

// Plumbing: assembles the text and writes the .t27 file; no test calls it.
fn generate() -> u32 {
undefined;
}

test indent_is_four_spaces_per_level {
assert(indent(0) == 0);
assert(indent(1) == 4);
assert(indent(2) == 8);
}

test first_point_is_zero_one {
assert(coordinate(0, 0, 0) == 0);
assert(coordinate(0, 0, 1) == 1);
}

test last_point_matches_the_generated_expectations {
// 139 * 64 = 8896 points, the last has e = 8895: x = 17790, y = 17791.
assert(coordinate(8895, 0, 0) == 17790);
assert(coordinate(8895, 0, 1) == 17791);
// The point at dst[69][1][0][0][0][0][0] has e = 69 * 64 + 32 = 4448.
assert(coordinate(4448, 0, 0) == 8896);
assert(coordinate(4448, 0, 1) == 8897);
}

test offset_32768_wraps_back {
assert(coordinate(0, 32768, 0) == 0);
assert(coordinate(0, 32768, 1) == 1);
assert(coordinate(8895, 32768, 0) == 17790);
assert(coordinate(8895, 32768, 1) == 17791);
}

test build_tree_walks_one_dimension_per_level {
// a leaf row (the last [2]) lays out two single points from base 7
assert(build_tree(SHAPE, 6, 7) == 9);
// one inner subtree: the six [2]s under a single outer entry hold 64
// points, so from base 10 the subtree ends at 74
assert(build_tree(SHAPE, 1, 10) == 74);
}

test base_threading_numbers_points_row_major {
// dst[69][1][0][0][0][0][0] is element 69*64 + 32 = 4448: the first
// 69 outer entries consume 69*64 points -- the base handed to the
// next outer subtree -- then one [2]-subtree consumes 32 more before
// the point's own leaf row
var head: [7]u32 = [69, 2, 2, 2, 2, 2, 2];
assert(build_tree(head, 0, 0) == 69 * 64);
assert(build_tree(head, 0, 0) + 32 == 4448);
}

test whole_grid_has_8896_points {
// the full recursion over all seven dimensions: 139 outer entries of
// 64 points each, the base threaded through every subtree -- the count
// the original's generated literal embodies
assert(build_tree(SHAPE, 0, 0) == 8896);
}
}
Loading