fix: 复合语句域收敛真实完成值,空体物化 undefined 不沿用前值

This commit is contained in:
2026-09-14 22:51:29 +00:00
parent 92df76565b
commit c50eb9e566
10 changed files with 141 additions and 31 deletions
+8 -5
View File
@@ -19,16 +19,19 @@ impl Emitter {
&self, stmt: &oxide_parser::LabeledStatement, ctx: &mut CompileCtx,
) -> Result<Option<u32>, String> {
let name = stmt.label.name.as_str();
if Self::is_iteration_statement(&stmt.body) {
// 标签语句完成值 = 体完成值(透传):迭代体返回其循环值,块/表达式体返回其
// 收敛值;标签本身不改变完成值。
let body_result = if Self::is_iteration_statement(&stmt.body) {
ctx.queue_loop_label(name)?;
self.emit_statement(&stmt.body, ctx)?;
self.emit_statement(&stmt.body, ctx)?
} else {
let id = ctx.next_label_id();
ctx.push_label_scope(name, id, None)?;
self.emit_statement(&stmt.body, ctx)?;
let r = self.emit_statement(&stmt.body, ctx)?;
ctx.labels.set_label_pos(id, ctx.insts.len());
ctx.pop_label_scope();
}
Ok(None)
r
};
Ok(body_result)
}
}