feat: ref

This commit is contained in:
2025-05-11 10:19:55 +08:00
parent cbb29276d8
commit 7cbb082dc4
12 changed files with 180 additions and 165 deletions

View File

@@ -41,14 +41,14 @@ impl From<ir::Param> for Param {
}
#[derive(Debug, Clone)]
pub struct Func {
pub env: OnceCell<CapturedEnv>,
pub struct Func<'vm> {
pub env: OnceCell<CapturedEnv<'vm>>,
pub param: Param,
pub opcodes: OpCodes,
}
impl Func {
pub fn call(&self, vm: &VM, arg: Value) -> Result<Value> {
impl<'vm> Func<'vm> {
pub fn call(&'vm self, vm: &VM<'vm>, arg: Value<'vm>) -> Result<Value<'vm>> {
use Param::*;
let env = self.env.get().unwrap().clone().released();
@@ -75,7 +75,7 @@ impl Func {
for (formal, default) in formals {
let arg = arg
.select(formal.clone().into())
.or_else(|| default.map(Value::ThunkRef))
.or_else(|| default.map(|idx| Value::ThunkRef(vm.get_thunk(idx))))
.unwrap();
new.insert_mut(formal.clone().into(), arg);
}
@@ -90,7 +90,7 @@ impl Func {
}
}
impl PartialEq for Func {
impl PartialEq for Func<'_> {
fn eq(&self, _: &Self) -> bool {
false
}