feat: ref
This commit is contained in:
@@ -7,12 +7,12 @@ use crate::ty::common::Symbol;
|
||||
use crate::ty::internal::Value;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Env {
|
||||
last: RefCell<Option<Arc<Env>>>,
|
||||
map: Arc<RefCell<HashTrieMapSync<Symbol, Value>>>,
|
||||
pub struct Env<'vm> {
|
||||
last: RefCell<Option<Arc<Env<'vm>>>>,
|
||||
map: Arc<RefCell<HashTrieMapSync<Symbol, Value<'vm>>>>,
|
||||
}
|
||||
|
||||
impl Clone for Env {
|
||||
impl Clone for Env<'_> {
|
||||
fn clone(&self) -> Self {
|
||||
Env {
|
||||
last: RefCell::new(
|
||||
@@ -27,24 +27,24 @@ impl Clone for Env {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CapturedEnv {
|
||||
env: Arc<Env>,
|
||||
pub struct CapturedEnv<'vm> {
|
||||
env: Arc<Env<'vm>>,
|
||||
}
|
||||
|
||||
impl Env {
|
||||
pub fn empty() -> Env {
|
||||
impl<'vm> Env<'vm> {
|
||||
pub fn empty() -> Self {
|
||||
Env::default()
|
||||
}
|
||||
|
||||
pub fn lookup(&self, symbol: Symbol) -> Option<Value> {
|
||||
pub fn lookup(&self, symbol: Symbol) -> Option<Value<'vm>> {
|
||||
self.map.borrow().get(&symbol).cloned()
|
||||
}
|
||||
|
||||
pub fn insert(&self, symbol: Symbol, value: Value) {
|
||||
pub fn insert(&self, symbol: Symbol, value: Value<'vm>) {
|
||||
self.map.borrow_mut().insert_mut(symbol, value);
|
||||
}
|
||||
|
||||
pub fn enter(&self, new: HashTrieMapSync<Symbol, Value>) {
|
||||
pub fn enter(&self, new: HashTrieMapSync<Symbol, Value<'vm>>) {
|
||||
let mut map = self.map.borrow().clone();
|
||||
for (k, v) in new.iter() {
|
||||
map.insert_mut(k.clone(), v.clone());
|
||||
@@ -57,7 +57,7 @@ impl Env {
|
||||
*self.map.borrow_mut() = map;
|
||||
}
|
||||
|
||||
pub fn enter_rec(&self) -> Arc<RefCell<HashTrieMapSync<Symbol, Value>>> {
|
||||
pub fn enter_rec(&self) -> Arc<RefCell<HashTrieMapSync<Symbol, Value<'vm>>>> {
|
||||
let last = Env {
|
||||
last: self.last.clone(),
|
||||
map: self.map.clone(),
|
||||
@@ -73,17 +73,17 @@ impl Env {
|
||||
*self.map.borrow_mut() = map;
|
||||
}
|
||||
|
||||
pub fn captured(self: Arc<Self>) -> CapturedEnv {
|
||||
pub fn captured(self: Arc<Self>) -> CapturedEnv<'vm> {
|
||||
CapturedEnv { env: self }
|
||||
}
|
||||
}
|
||||
|
||||
impl CapturedEnv {
|
||||
pub fn lookup(&self, symbol: Symbol) -> Option<Value> {
|
||||
impl<'vm> CapturedEnv<'vm> {
|
||||
pub fn lookup(&self, symbol: Symbol) -> Option<Value<'vm>> {
|
||||
self.env.lookup(symbol)
|
||||
}
|
||||
|
||||
pub fn released(self) -> Arc<Env> {
|
||||
pub fn released(self) -> Arc<Env<'vm>> {
|
||||
Arc::new(self.env.as_ref().clone())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user