r8forge_tape_opt rewrites a tape with three run-local rules: > < a maximal run of pointer moves becomes its net displacement + a run becomes (length % _CELL_SIZE), a whole turn is a no-op - a run becomes (length % 2), two flips cancel The nice part is what it does NOT do: it never looks at brackets. '[' and ']' are not in any of the three character classes, so they always end a run, and within a run only the net matters (the pointer moves are pure additions and nothing in between is observable). Keeping every run's net keeps the pointer identical at every surviving character, brackets included, so the pairing that the machine finds by scanning cannot change; and since bracket characters are never added or removed, a run can never be merged across one. No stack, no offset table, one linear pass. Measured, with tape_run's out stream compared before and after (and the reference machine on the flagship's -n stream, same 93 values): asm/test.r8asm 64513 -> 58060 (-6453, 10.0%) examples/calc.r8asm 62585 -> 54863 (-7722, 12.3%) "12 34 + ." identical examples/term.r8asm 3467 -> 3402 ( -65, 1.9%) "hi" identical Step counts unchanged (the removed instructions did nothing). Not yet wired into `r8forge` itself: the pipeline is `r8forge f.r8asm > t.rot8 && r8forge_tape_opt t.rot8 t2.rot8`, and a --opt flag can wrap that later.
4.2 KiB
4.2 KiB
TODO
"还没做"的事都收在这一个文件里,别散在 README/AGENTS/docs 中。每条写清楚为什么值得做和
从哪开始;做完就删掉(历史在 git log 里)。SPEC.md §12 那张"已经确认走不通"的表是
结论,不是待办,别混进来。
已经做完、从这份清单里移出去的:桌上计算器(examples/calc.r8asm,11 位 62585 字符、三方
一致、位宽矩阵见 tests/widths.ps1)、INP 整格写入的语义修正、参考虚拟机支持 >64k 纸带。
交互计算(下一步)
- RPN 栈:现在的计算器是两寄存器(
A累加器 +P待结算操作数),没有栈。.tp是汇编期常量,所以只能做"固定 N 格 + 整体挪位"的假栈:每次 push ≈ N 个copy(约 500 字符/格)。65536 的纸带预算下 16 深可行(~12k 字符),4 深最划算;理论上 259 格内存能到 200 层,但一次 push 要 10 万字符,不现实。起点:把calc.r8asm的A/P换成 4 格窗口先跑通,再看要不要 16。 - 终端纸带:提示符 + 逐字符回显 + 行编辑(退格打印
\b \b)+ 命令分派。零件都在drv/calc_*(分派、数字攒取、显示、四则)——缺的是"长驻循环 + 落行 + 会话结束"。 验收用头部; in喂一整段会话,examples_test会自动跑。 - 迷你
printf:clb_puts和load已经有了(examples/hello.r8asm能打一整句),还缺%d/%c/%s的格式化 —— 那需要"格式串 + 参数表"的约定,比 puts 复杂一档。
工具
已实现为r8forge --optr8forge_tape_opt(见下),原条目保留说明:><、<>、--、11 个++、 重复清位…… 要能重算跳转偏移。配套r8forge_tape_diff(比较两条纸带的 OUT 流和步数) 证明等价 —— 一次改动全库受益。--profile:统计每段宏/每个 cell 的步数占比和.tp行走距离,用数据决定下一步优化谁 (现在".tp行走占七成"还是估的)。%synth --verify:把.r8forge_cache/里每条结果按对应表的所有输入重跑一遍, 给"缓存已入库"兜底 —— 一条坏条目会让每次构建静默用错块。- CI:暂时不做。本地
ctest --test-dir build -j 4(8 条,9 秒)和tests/widths.ps1(位宽矩阵,约 20 分钟)都能手动跑;act_runner 的镜像装不出 cmake,先放着。 ROT-8-viz 仍然零测试:串行默认 /-n/ 几何 / 7E1 全靠手测 —— 哪天真要接 CI,先补它。 src/r8asm.cc:154有个上游留下的// TODO: FILL THE BLANK(ROT8_NODE宏的 children 是空的)。那是继承来的实现,先记着,别顺手改。
画面
- 把 259 格当帧缓冲:串行下
\r(0x0D)能原地重绘,1 bit/cell 的 16×16 位图或 8×8 生命游戏都能塞进纸带,rot8_test --live里直接看它动。
要重新量的一条
copy的脏缓冲:SPEC §7.7 写着"缓冲格必须干净,脏了拷贝结果是 0",但 stage 2 的探针 (缓冲 2040、源 4)里copy结果是对的、缓冲也自己归零了。要么那条结论当初量的是别的路径 (比如clb_digits里连着用的写法),要么它已经不成立 —— 写清楚之前别把两种说法都留着。 顺便:clb_bit_mov的「吃源」契约也值得一起复验。
想清楚但没做的优化
clb_divmod预计算~D:单轮 2019 → 973 步,估计 28.6k → 17.6k 步,纸带净 −76; 没换是因为当时指名用raw_sub。细节和注意事项见docs/divmod.md第 6 节。clb_digits的布局:13 格草稿跨得很开,.tp行走占了纸带的大头;重排草稿格应该能 明显缩短(未实测)。clb_divmod里那个 495 字符的提交copy:还是全展开的,可以想压缩的办法。
顺手清掉的小尾巴
- viz 的
read_tape(固定缓冲那版)在vm_test.c改用read_tape_alloc之后应该没人用了: 要么删掉,要么在头注释里标 deprecated。 - viz 的
INS_SIZE现在只是历史常量(真正的上限是ROT8_MAX_TAPE= 16 M 条指令), README 里可以说明一句。