步骤4:用例 21_var_temp(VAR_TEMP 每周期重置语义)+ 文档更新 + 修复 store_target STORE 缺 func 隐藏 bug

This commit is contained in:
2026-08-26 18:01:08 +08:00
parent 536ad1a96b
commit 92e91350cc
12 changed files with 80 additions and 7 deletions
+1
View File
@@ -65,6 +65,7 @@ namespace {
{"18_tof_ctu", Outcome::Ok, ""},
{"19_recursive_call", Outcome::CompileError, "recursive call"},
{"20_line1", Outcome::Ok, ""},
{"21_var_temp", Outcome::Ok, ""},
};
bool run_case(const char* dir, Outcome want, const char* keyword) {
+1 -1
View File
@@ -202,7 +202,7 @@ static bool test_all_cases() {
}
++n;
}
CHECK(n == 20);
CHECK(n == 21);
return true;
}
+19 -2
View File
@@ -37,11 +37,19 @@ static int g_checks = 0;
// ---- 数据区槽访问 ----
/// 槽宽 = 与下一槽 addr 的差(紧凑布局下按实际宽读写,避免覆盖相邻槽)
/// 槽宽 = 与下一槽 addr 的差(紧凑布局下按实际宽读写,避免覆盖相邻槽)
/// 最后一槽(下一槽越界返回 0)按值区剩余字节兜底。
static uint32_t slot_width(const vm::Machine& m, int s) {
const uint32_t a = m.slot_addr(static_cast<uint32_t>(s));
const uint32_t b = m.slot_addr(static_cast<uint32_t>(s + 1));
return (b > a && b - a < 8) ? (b - a) : 8;
if (b > a && b - a < 8) {
return b - a;
}
if (b == 0) {
const uint32_t rem = static_cast<uint32_t>(m.data_len()) - a;
return rem < 8 ? rem : 8;
}
return 8;
}
static int64_t slot(const vm::Machine& m, int s) {
@@ -357,6 +365,15 @@ static bool test_cases_positive() {
CHECK(make_machine("tests/cases/18_tof_ctu", &m, &err));
CHECK(m.run_cycle() == vm::Fault::None);
// 21 VAR_TEMPtmp/t 每周期重置,persist 累积 → a = 10107/10108/10109
CHECK(make_machine("tests/cases/21_var_temp", &m, &err));
m.run_cycle();
CHECK(slot(m, 0) == 10107);
m.run_cycle();
CHECK(slot(m, 0) == 10108);
CHECK(m.run_cycle() == vm::Fault::None);
CHECK(slot(m, 0) == 10109);
// 20 line1I 组合 → Q0_0 真值表(槽 0=急停 1=I0_0 2=I0_1 3=Q0_0
CHECK(make_machine("tests/cases/20_line1", &m, &err));
struct {