refactor with

This commit is contained in:
2026-05-04 15:43:35 +08:00
parent fca00b04ba
commit b3e6591809
13 changed files with 162 additions and 344 deletions
-14
View File
@@ -29,10 +29,8 @@ impl<'gc> crate::Vm<'gc> {
self.push(arg);
self.call_stack.push(CallFrame {
pc: resume_pc,
stack_depth: 0,
thunk: None,
env: self.env,
with_env: self.with_env,
});
reader.set_pc(PrimOpPhase::CallPattern.ip() as usize);
return Step::Continue(());
@@ -44,10 +42,8 @@ impl<'gc> crate::Vm<'gc> {
let new_env = Gc::new(mc, RefLock::new(Env::with_arg(arg, n_locals, env)));
self.call_stack.push(CallFrame {
pc: resume_pc,
stack_depth: 0,
thunk: None,
env: self.env,
with_env: self.with_env,
});
reader.set_pc(ip as usize);
self.env = new_env;
@@ -56,10 +52,8 @@ impl<'gc> crate::Vm<'gc> {
self.push(arg);
self.call_stack.push(CallFrame {
pc: resume_pc,
stack_depth: 0,
thunk: None,
env: self.env,
with_env: self.with_env,
});
reader.set_pc(primop.dispatch_ip as usize)
} else {
@@ -78,10 +72,8 @@ impl<'gc> crate::Vm<'gc> {
self.push(arg);
self.call_stack.push(CallFrame {
pc: resume_pc,
stack_depth: 0,
thunk: None,
env: self.env,
with_env: self.with_env,
});
reader.set_pc(app.primop.dispatch_ip as usize)
} else {
@@ -121,10 +113,8 @@ impl<'gc> crate::Vm<'gc> {
let val = self.force_and_retry::<StrictValue>(reader, mc)?;
let Some(CallFrame {
pc: ret_pc,
stack_depth,
thunk,
env,
with_env,
}) = self.call_stack.pop()
else {
match self.force_mode {
@@ -139,10 +129,8 @@ impl<'gc> crate::Vm<'gc> {
self.push(val.relax());
self.call_stack.push(CallFrame {
pc: PrimOpPhase::ForceResultDeepFinish.ip() as usize,
stack_depth: 0,
thunk: None,
env: self.env,
with_env: self.with_env,
});
self.call_depth += 1;
reader.set_pc(PrimOpPhase::DeepSeq.ip() as usize);
@@ -153,13 +141,11 @@ impl<'gc> crate::Vm<'gc> {
reader.set_pc(ret_pc);
if let Some(outer_thunk) = thunk {
*outer_thunk.borrow_mut(mc) = ThunkState::Evaluated(val);
self.replace(stack_depth, val.relax());
} else {
self.call_depth -= 1;
self.push(val.relax())
}
self.env = env;
self.with_env = with_env;
Step::Continue(())
}
}