feat(env): Rc

This commit is contained in:
2025-05-17 19:10:10 +08:00
parent ff9afd0cc1
commit fb14027845
6 changed files with 44 additions and 65 deletions

View File

@@ -1,6 +1,3 @@
use std::collections::HashMap;
use std::rc::Rc;
use derive_more::Constructor;
use itertools::Itertools;
@@ -46,7 +43,7 @@ pub type JITFunc<'vm> =
#[derive(Debug, Clone, Constructor)]
pub struct Func<'vm> {
pub func: &'vm BFunc,
pub env: Rc<Env<'vm>>,
pub env: Env<'vm>,
pub compiled: Option<JITFunc<'vm>>,
}
@@ -54,10 +51,10 @@ impl<'vm> Func<'vm> {
pub fn call(&self, vm: &'vm VM<'_>, arg: Value<'vm>) -> Result<Value<'vm>> {
use Param::*;
let env = Rc::new(self.env.as_ref().clone());
let mut env = self.env.clone();
match self.func.param.clone() {
Ident(ident) => env.enter([(ident.into(), arg)].into_iter()),
Ident(ident) => env = env.enter([(ident.into(), arg)].into_iter()),
Formals {
formals,
ellipsis,
@@ -88,7 +85,7 @@ impl<'vm> Func<'vm> {
if let Some(alias) = alias {
new.push((alias.clone().into(), Value::AttrSet(arg)));
}
env.enter(new.into_iter());
env = env.enter(new.into_iter());
}
}