feat: SCC analysis (WIP)

This commit is contained in:
2025-06-15 17:23:32 +08:00
parent 7b6db44207
commit b2d2490327
13 changed files with 842 additions and 352 deletions

View File

@@ -27,7 +27,7 @@ pub struct Engine {
pub fn eval(downgraded: Downgraded) -> Result<Value> {
let mut engine = Engine::new(downgraded.thunks, downgraded.func_offset);
engine
.eval(downgraded.top_level, &mut VmEnv::new())
.eval()
.map(|mut val| {
Ok(val
.force(&mut engine)?
@@ -38,15 +38,15 @@ pub fn eval(downgraded: Downgraded) -> Result<Value> {
impl Engine {
pub fn new(thunks: Box<[Ir]>, func_offset: usize) -> Self {
Self {
lru: LruCache::new(thunks.len().clamp(1, usize::MAX).try_into().unwrap()),
lru: LruCache::new(thunks.len().try_into().unwrap()),
thunks,
func_offset,
tasks: PriorityQueue::new(),
}
}
pub fn eval(&mut self, expr: Ir, env: &mut VmEnv) -> Result<i::Value> {
expr.eval(self, env)
pub fn eval(&mut self) -> Result<i::Value> {
self.thunks.last().unwrap().clone().eval(self, &mut VmEnv::new())
}
pub fn eval_thunk(&mut self, idx: usize, env: &mut VmEnv) -> Result<i::Value> {