runtime, vm: write thunk results back to the forcing stack slot

This commit is contained in:
2026-08-22 19:05:13 +08:00
parent 0c0e1849ae
commit 5a06fb4c1e
8 changed files with 43 additions and 17 deletions
+10
View File
@@ -34,6 +34,7 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
pc: resume_pc,
thunk: None,
env: m.env(),
depth: None,
});
reader.set_pc(Continuation::CallPattern.ip() as usize);
return Step::Continue(());
@@ -47,6 +48,7 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
pc: resume_pc,
thunk: None,
env: m.env(),
depth: None,
});
reader.set_pc(ip as usize);
m.set_env(new_env);
@@ -57,6 +59,7 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
pc: resume_pc,
thunk: None,
env: m.env(),
depth: None,
});
reader.set_pc(primop.dispatch_ip as usize)
} else {
@@ -77,6 +80,7 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
pc: resume_pc,
thunk: None,
env: m.env(),
depth: None,
});
reader.set_pc(app.primop.dispatch_ip as usize)
} else {
@@ -101,6 +105,7 @@ pub(crate) fn call<'gc, M: Machine<'gc>>(
pc: resume_pc,
thunk: None,
env: m.env(),
depth: None,
});
m.push(arg);
m.push(func.relax());
@@ -140,6 +145,7 @@ pub(crate) fn op_return<'gc, M: Machine<'gc>>(
pc: ret_pc,
thunk,
env,
depth,
}) = m.pop_call_frame()
else {
match m.force_mode() {
@@ -156,6 +162,7 @@ pub(crate) fn op_return<'gc, M: Machine<'gc>>(
pc: Continuation::ForceResultDeepFinish.ip() as usize,
thunk: None,
env: m.env(),
depth: None,
});
m.inc_call_depth();
reader.set_pc(Continuation::PDeepSeq.ip() as usize);
@@ -166,6 +173,9 @@ pub(crate) fn op_return<'gc, M: Machine<'gc>>(
reader.set_pc(ret_pc);
if let Some(outer_thunk) = thunk {
*outer_thunk.borrow_mut(mc) = ThunkState::Evaluated(val);
if let Some(depth) = depth {
m.replace(depth, val.relax());
}
} else {
m.dec_call_depth();
m.push(val.relax())
+2
View File
@@ -41,6 +41,7 @@ pub(crate) fn op_lookup_with<'gc, M: Machine<'gc>>(
thunk: Some(thunk),
pc: resume_pc,
env: m.env(),
depth: None,
});
m.set_env(env);
reader.set_pc(ip);
@@ -52,6 +53,7 @@ pub(crate) fn op_lookup_with<'gc, M: Machine<'gc>>(
thunk: Some(thunk),
pc: resume_pc,
env: m.env(),
depth: None,
});
m.push(func);
return m.call(reader, mc, arg, resume_pc);
+2
View File
@@ -211,6 +211,7 @@ impl<'gc> Machine<'gc> for Vm<'gc> {
thunk: Some(thunk),
pc: resume_pc,
env: self.env,
depth: Some(depth),
});
self.env = env;
reader.set_pc(ip);
@@ -225,6 +226,7 @@ impl<'gc> Machine<'gc> for Vm<'gc> {
thunk: Some(thunk),
pc: resume_pc,
env: self.env,
depth: Some(depth),
});
self.push(func);
self.call(reader, mc, arg, resume_pc)
+1
View File
@@ -166,6 +166,7 @@ fn enter_eq_machine<'gc, M: Machine<'gc>>(
pc: resume_pc,
thunk: None,
env: m.env(),
depth: None,
});
m.inc_call_depth();
m.push(Value::new(negate));
+3
View File
@@ -46,6 +46,7 @@ pub fn import<'gc, M: Machine<'gc>>(
pc: Continuation::PImportFinalize.ip() as usize,
thunk: None,
env,
depth: None,
});
m.set_pending_load(PendingLoad {
@@ -79,6 +80,7 @@ pub fn import_finalize<'gc, M: Machine<'gc>>(
pc: ret_pc,
thunk: _,
env,
depth: None,
}) = m.pop_call_frame()
else {
unreachable!()
@@ -120,6 +122,7 @@ pub fn scoped_import<'gc, M: Machine<'gc>>(
pc: Continuation::PScopedImportFinalize.ip() as usize,
thunk: None,
env,
depth: None,
});
m.set_pending_load(PendingLoad {