flat-ROT8 不变量 + mixed codeblock 位置依赖金丝雀(暴露 .anchor 键写错 bug,待核心修复后重标数字)
This commit is contained in:
1 parent
8afc74da34
commit
6c74a1de4f
1 file changed
+30
-1
+30
-1
@@ -24,6 +24,22 @@ int main() {
|
||||
#include "macros_gen.inc"
|
||||
|
||||
int fail = 0;
|
||||
// 不变量:expand_node_to_ins 的输出必须是纯 ROT8 平铺指令流
|
||||
// (CODEBLOCK 的 children 里每个节点都必须是叶子 ROT8,不能有嵌套结构)
|
||||
auto check_flat_rot8 = [&](const ast_node &cb, const char *name) -> int {
|
||||
int bad = 0;
|
||||
for (const auto &n : cb.children) {
|
||||
if (n.type != ast_node_t::ROT8) {
|
||||
std::cout << " " << name << ": NON-ROT8 child (type "
|
||||
<< static_cast<int>(n.type) << ")\n";
|
||||
bad++;
|
||||
} else if (!n.children.empty()) {
|
||||
std::cout << " " << name << ": ROT8 leaf with children\n";
|
||||
bad++;
|
||||
}
|
||||
}
|
||||
return bad;
|
||||
};
|
||||
auto test = [&](const char *name, ast_node call, size_t expect_len,
|
||||
bool conserve, int32_t expect_dp_delta = 0) {
|
||||
uint32_t dp0 = a.dataptr;
|
||||
@@ -33,12 +49,15 @@ int main() {
|
||||
bool len_ok = (expect_len == 0) ? (n > 0) : (n == expect_len);
|
||||
bool dp_ok = conserve ? (a.dataptr == dp0)
|
||||
: (a.dataptr == dp0 + expect_dp_delta);
|
||||
int flat_bad = check_flat_rot8(out, name);
|
||||
std::cout << name << ": " << n << " ins, dataptr " << dp0 << " -> "
|
||||
<< a.dataptr << (len_ok ? "" : " FAIL(len)");
|
||||
if (!dp_ok)
|
||||
std::cout << " FAIL(dp)";
|
||||
if (flat_bad)
|
||||
std::cout << " FAIL(flat)";
|
||||
std::cout << "\n";
|
||||
if (!len_ok || !dp_ok)
|
||||
if (!len_ok || !dp_ok || flat_bad)
|
||||
fail++;
|
||||
} catch (const std::exception &e) {
|
||||
std::cout << name << ": EXCEPTION: " << e.what() << "\n";
|
||||
@@ -53,6 +72,16 @@ int main() {
|
||||
test("step 2", mcall("step", {cst(2)}), 4, false, 4);
|
||||
test("back 2", mcall("back", {cst(2)}), 4, false, -4);
|
||||
test("clb_bit_mov 5", mcall("clb_bit_mov", {cst(5)}), 27, true);
|
||||
// 顶层 CODEBLOCK 混合展开:ROT8 + MACROCALL + REPEAT 一起,验证平铺
|
||||
test("mixed codeblock",
|
||||
ast_node{ast_node_t::CODEBLOCK, "",
|
||||
{{ast_node_t::ROT8, "rot8_stp", {}},
|
||||
mcall("set_0", {}),
|
||||
{ast_node_t::REPEAT, "",
|
||||
{cst(2),
|
||||
{ast_node_t::CODEBLOCK, "",
|
||||
{{ast_node_t::ROT8, "rot8_stp", {}}}}}}}},
|
||||
6, false, 3);
|
||||
// nested macros: assert non-empty + dataptr conserved, print actual length
|
||||
test("bit_copy 3 5", mcall("bit_copy", {cst(3), cst(5)}), 0, true);
|
||||
test("copy 3 5", mcall("copy", {cst(3), cst(5)}), 0, true);
|
||||
|
||||
Reference in new issue
Block a user