ForceMode

This commit is contained in:
2026-04-26 14:51:34 +08:00
parent ac76d4a9e4
commit bc16596dd3
5 changed files with 175 additions and 35 deletions
+25 -2
View File
@@ -1,9 +1,11 @@
use fix_builtins::PrimOpPhase;
use fix_error::Error;
use gc_arena::{Gc, Mutation, RefLock};
use crate::value::*;
use crate::{
BytecodeReader, CallFrame, Closure, Env, Step, ThunkState, VmRuntimeCtx, VmRuntimeCtxExt,
BytecodeReader, CallFrame, Closure, Env, ForceMode, Step, ThunkState, VmRuntimeCtx,
VmRuntimeCtxExt,
};
impl<'gc> crate::Vm<'gc> {
@@ -112,7 +114,28 @@ impl<'gc> crate::Vm<'gc> {
with_env,
}) = self.call_stack.pop()
else {
return self.finish_ok(ctx.convert_value(val.relax()));
match self.force_mode {
ForceMode::AsIs => return self.finish_ok(ctx.convert_value(val.relax())),
ForceMode::Shallow => {
self.push(val.relax());
reader.set_pc(PrimOpPhase::ForceResultShallow.ip() as usize);
return Step::Continue(());
}
ForceMode::Deep => {
self.push(val.relax());
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);
return Step::Continue(());
}
}
};
reader.set_pc(ret_pc);
if let Some(outer_thunk) = thunk {