refactor(ty): call

This commit is contained in:
2025-07-17 10:00:42 +08:00
parent f6ae509c13
commit 2909483afb

View File

@@ -191,7 +191,7 @@ impl Value {
env.enter_args(std::mem::take(old_args));
let mut args = args.into_iter().peekable();
env.enter_arg(args.next().unwrap());
let (ret, cache) = env.with_cache(std::mem::take(cache), |env| {
let (mut ret, cache) = env.with_cache(std::mem::take(cache), |env| {
engine.eval_func_deps(idx, env)?;
let mut ret = engine.call_func(idx, env)?;
while args.peek().is_some() {
@@ -217,21 +217,20 @@ impl Value {
}
ret.ok()
});
let mut ret = ret?;
let args = env.pop_args(len);
if let Value::Func(idx) = ret {
ret = PartialFunc(self::PartialFunc::new(idx, args, cache).into());
} else if let Value::PartialFunc(func) = &mut ret {
if let Ok(Value::Func(idx)) = ret {
ret = PartialFunc(self::PartialFunc::new(idx, args, cache).into()).ok();
} else if let Ok(Value::PartialFunc(func)) = &mut ret {
Rc::make_mut(func).args.extend(args);
}
ret.ok()
ret
}
&mut Func(idx) => {
let len = args.len();
let mut args = args.into_iter().peekable();
env.reserve_args(len);
env.enter_arg(args.next().unwrap());
let (ret, cache) = env.with_new_cache(|env| {
let (mut ret, cache) = env.with_new_cache(|env| {
engine.eval_func_deps(idx, env)?;
let mut ret = engine.call_func(idx, env)?;
ret.force(engine, env)?;
@@ -258,14 +257,13 @@ impl Value {
}
ret.ok()
});
let mut ret = ret?;
let args = env.pop_args(len);
if let Value::Func(idx) = ret {
ret = Value::PartialFunc(self::PartialFunc::new(idx, args, cache).into())
} else if let Value::PartialFunc(func) = &mut ret {
if let Ok(Value::Func(idx)) = ret {
ret = Value::PartialFunc(self::PartialFunc::new(idx, args, cache).into()).ok()
} else if let Ok(Value::PartialFunc(func)) = &mut ret {
Rc::make_mut(func).args.extend(args);
}
ret.ok()
ret
}
Catchable(_) => return Ok(()),
other => todo!("{}", other.typename()),