fix: nested return

This commit is contained in:
2026-04-04 01:52:17 +08:00
parent 310f4acc89
commit 0c517e3c18
+10 -5
View File
@@ -1166,11 +1166,11 @@ impl Runtime {
pub(super) fn force_tos(&mut self) -> Action { pub(super) fn force_tos(&mut self) -> Action {
loop { loop {
let run = self.arena.mutate_root(|_mc, root| { let (run, target_depth) = self.arena.mutate_root(|_mc, root| {
let thunk = root.stack.tos_mut().expect("stack underflow"); let thunk = root.stack.tos_mut().expect("stack underflow");
let Some(thunk_state) = thunk.as_gc::<Thunk>() else { let Some(thunk_state) = thunk.as_gc::<Thunk>() else {
return false; return (false, 0);
}; };
match *thunk_state.borrow() { match *thunk_state.borrow() {
ThunkState::Pending { ip, env } => { ThunkState::Pending { ip, env } => {
@@ -1182,12 +1182,12 @@ impl Runtime {
.expect("call stack overflow"); .expect("call stack overflow");
self.pc = ip; self.pc = ip;
root.current_env = Some(env); root.current_env = Some(env);
true (true, root.frames.len())
} }
ThunkState::Apply { .. } => todo!("force_tos"), ThunkState::Apply { .. } => todo!("force_tos"),
ThunkState::Evaluated(val) => { ThunkState::Evaluated(val) => {
*thunk = val; *thunk = val;
false (false, 0)
} }
ThunkState::Blackhole => todo!("force_tos"), ThunkState::Blackhole => todo!("force_tos"),
} }
@@ -1199,7 +1199,12 @@ impl Runtime {
self.check_gc(); self.check_gc();
match self.execute_one() { match self.execute_one() {
Action::Continue => (), Action::Continue => (),
Action::Return => break, Action::Return => {
let current_depth = self.arena.mutate_root(|_, root| root.frames.len());
if current_depth < target_depth {
break;
}
}
// FIXME: poison thunk // FIXME: poison thunk
Action::Done(err @ Err(_)) => return Action::Done(err), Action::Done(err @ Err(_)) => return Action::Done(err),
Action::Done(Ok(_)) => unreachable!(), Action::Done(Ok(_)) => unreachable!(),