implement pattern calling

This commit is contained in:
2026-04-27 18:17:19 +08:00
parent a28dfada30
commit fe96f6d9c5
4 changed files with 77 additions and 10 deletions
+20 -9
View File
@@ -23,13 +23,10 @@ impl<'gc> crate::Vm<'gc> {
}
self.call_depth += 1;
if let Some(closure) = func.as_gc::<Closure>() {
let ip = closure.ip;
let n_locals = closure.n_locals;
let env = closure.env;
if let Some(ref _pattern) = closure.pattern {
todo!("pattern call")
} else {
let new_env = Gc::new(mc, RefLock::new(Env::with_arg(arg, n_locals, env)));
if closure.pattern.is_some() {
// FIXME: better DX...
self.push(func.relax());
self.push(arg);
self.call_stack.push(CallFrame {
pc: resume_pc,
stack_depth: 0,
@@ -37,9 +34,23 @@ impl<'gc> crate::Vm<'gc> {
env: self.env,
with_env: self.with_env,
});
reader.set_pc(ip as usize);
self.env = new_env;
reader.set_pc(PrimOpPhase::CallPattern.ip() as usize);
return Step::Continue(());
}
let ip = closure.ip;
let n_locals = closure.n_locals;
let env = closure.env;
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;
} else if let Some(primop) = func.as_inline::<PrimOp>() {
if primop.arity == 1 {
self.push(arg);