fix: 修复 switch case 标签冲突与大 switch 寄存器回绕

This commit is contained in:
爱特每羊队
2026-06-08 23:45:00 +08:00
parent afcc76a222
commit bf75fcd0c9
5 changed files with 50 additions and 3 deletions
+9 -1
View File
@@ -45,7 +45,7 @@ pub(crate) enum Label {
ForInStart(u32),
ForInEnd(u32),
SwitchEnd(u32),
SwitchCase(u32),
SwitchCase(u32, u32),
CatchBody(u32),
FinallyBody(u32),
TryEnd(u32),
@@ -111,6 +111,14 @@ impl CompileCtx {
self.label_counter = 0;
}
pub(crate) fn reg_checkpoint(&self) -> u8 {
self.next_reg
}
pub(crate) fn restore_reg_checkpoint(&mut self, checkpoint: u8) {
self.next_reg = checkpoint;
}
pub(crate) fn add_constant(&mut self, c: Constant) -> u16 {
if let Some(idx) = self.constants.iter().position(|x| x == &c) {
return idx as u16;