feat: ir env (WIP)

This commit is contained in:
2025-05-30 18:29:04 +08:00
parent c548c4c6ac
commit 7d6168fdae
10 changed files with 500 additions and 164 deletions

View File

@@ -3,7 +3,7 @@ use std::hash::Hash;
use gc_arena::{Collect, Gc, Mutation};
use hashbrown::HashMap;
use crate::ty::internal::Value;
use crate::{ir::Ir, ty::internal::Value};
#[derive(Collect)]
#[collect(no_drop)]
@@ -21,6 +21,7 @@ pub struct LetEnv<'gc, K: Hash + Eq + Collect<'gc>, V: Collect<'gc>> {
}
pub type VmEnv<'gc> = Env<'gc, usize, Value<'gc>>;
pub type IrEnv<'gc> = Env<'gc, usize, Ir>;
#[derive(Default, Clone, Collect)]
#[collect(no_drop)]
@@ -62,13 +63,25 @@ impl<'gc, K: Hash + Eq + Clone + Collect<'gc>, V: Clone + Collect<'gc>> Env<'gc,
)
}
pub fn lookup(&self, symbol: &K) -> Option<&V> {
pub fn lookup_slow(&self, symbol: &K) -> Option<&V> {
if let Some(val) = self.let_.lookup(symbol) {
return Some(val);
}
self.with.lookup(symbol)
}
pub fn lookup_let(&self, symbol: &K) -> Option<&V> {
self.let_.lookup(symbol)
}
pub fn lookup_with(&self, symbol: &K) -> Option<&V> {
self.with.lookup(symbol)
}
pub fn has_with(&self) -> bool {
self.with.map.is_some()
}
pub fn enter_arg(self: Gc<'gc, Self>, ident: K, val: V, mc: &Mutation<'gc>) -> Gc<'gc, Self> {
Gc::new(
mc,