Files
R8Forge/TODO.md
T
dsh b873d71082 calc: stage 2 verified -- the digit window and clb_undigits
drv/calc_num.r8asm reads 6 characters, shifts digits into a four cell ASCII
window (D3 D2 D1 D0, most significant first) and converts it with clb_undigits
whenever a non digit arrives, then resets the window to "0000".

    in  12 34      out  12 34        tape 88413, 78908 steps
    in  0 7        out  0 7 0 0      (each EOF read is a terminator too)
    in  2047       out  2047 0
    in  9999       out  1807 0       (9999 wraps mod 2048, as the machine does)
    in  1234/0007  out  1234 0 / 7 0  (leading zeros work)

tape_run and derive agree on every case.

One deliberate departure from docs/calc.md: the digit branch copies the character
itself into the window instead of C - 48.  clb_undigits xors each cell with 48 on
the way in, so the window has to hold ASCII -- storing the numeric value paid the
xor twice (first version: "12 34" -> 540 562, e.g. 49^48=1 but 1^48=49 then * 10 +
... lands at 540).  So cell 2 (the 48 constant) and the sub_nc call are unused;
the file says so.

The window shift goes high to low (D3 <- D2 <- D1 <- D0) which is the order that
does not clobber unshifted digits; each copy is preceded by an erase of the
buffer even though this build's copy turns out to clean it itself.
2026-11-11 10:22:58 +08:00

3.5 KiB
Raw Blame History

TODO

"还没做"的事都收在这一个文件里,别散在 README/AGENTS/docs 中。每条写清楚为什么值得做和 从哪开始;做完就删掉(历史在 git log 里)。SPEC.md §12 那张"已经确认走不通"的表是 结论,不是待办,别混进来。

交互式计算

  • 桌上计算器(examples/calc.r8asm):输入 12+34= 输出 46,支持 + - * /。 条件已经齐了:inp 在三个 VM 里都有实现、tape_run/derive 能用 -i 脚本化喂输入、 例程头部能声明 ; in ...;数字用 clb_undigits 攒、回打用 clb_digits、 四则用 clb_add_nc / clb_mul / clb_divmod(都穷举验证过)。 要设计的是字符分派:'0'..'9'(0x30..0x39)bit4 是 1,'*' '+' '-' '/' (0x2A..0x2F)bit4 是 0 —— 一次 ror + biz 就能分开;运算符再按 t = C - 0x2A 的小整数链式比较。先写 drv/calc_lex.r8asm 单点验证分派,再拼整机。

工具

  • r8forge --opt:纸带级窥孔优化(收益面最大):><、<>、--、11 个 ++、 重复清位…… 要能重算跳转偏移。配套 r8forge_tape_diff(比较两条纸带的 OUT 流和步数) 证明等价 —— 一次改动全库受益。
  • --profile:统计每段宏/每个 cell 的步数占比和 .tp 行走距离,用数据决定下一步优化谁 (现在".tp 行走占七成"还是估的)。
  • %synth --verify:把 .r8forge_cache/ 里每条结果按对应表的所有输入重跑一遍, 给"缓存已入库"兜底 —— 一条坏条目会让每次构建静默用错块。
  • CI:暂时不做。本地的 ctest --test-dir build -j 4 已经接好(8 条,9 秒),但 act_runner 的 镜像里没有 cmake,装包(哪怕换了国内源)也跑不通,先本地跑。 ROT-8-viz 仍然零测试:串行默认 / -n / 几何 / 7E1 全靠手测,而它是权威虚拟机 —— 哪天要补测试,先补它。
  • src/r8asm.cc:154 有个上游留下的 // TODO: FILL THE BLANK(ROT8_NODE 宏的 children 是空的)。那是继承来的实现,先记着,别顺手改。

文本与画面

  • clb_puts + 迷你 printf:现在只能一个 cell 一个字符地打,缺"把一段 cell 当字符串 打出来"和 %d/%c/%s 的格式化,例程就能打印整句话而不是光秃秃的数字。
  • 把 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:还是全展开的,可以想压缩的办法。