From 0c517e3c1886d0ce65eaaaafc59bcf2b73dc7302 Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Sat, 4 Apr 2026 01:52:17 +0800 Subject: [PATCH] fix: nested return --- fix/src/runtime/vm.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fix/src/runtime/vm.rs b/fix/src/runtime/vm.rs index c8d9aed..eb01ee7 100644 --- a/fix/src/runtime/vm.rs +++ b/fix/src/runtime/vm.rs @@ -1166,11 +1166,11 @@ impl Runtime { pub(super) fn force_tos(&mut self) -> Action { 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 Some(thunk_state) = thunk.as_gc::() else { - return false; + return (false, 0); }; match *thunk_state.borrow() { ThunkState::Pending { ip, env } => { @@ -1182,12 +1182,12 @@ impl Runtime { .expect("call stack overflow"); self.pc = ip; root.current_env = Some(env); - true + (true, root.frames.len()) } ThunkState::Apply { .. } => todo!("force_tos"), ThunkState::Evaluated(val) => { *thunk = val; - false + (false, 0) } ThunkState::Blackhole => todo!("force_tos"), } @@ -1199,7 +1199,12 @@ impl Runtime { self.check_gc(); match self.execute_one() { 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 Action::Done(err @ Err(_)) => return Action::Done(err), Action::Done(Ok(_)) => unreachable!(),