feat: initial parallel impl

This commit is contained in:
2025-06-08 17:27:43 +08:00
parent 3797544fc2
commit 7293cb9f75
18 changed files with 529 additions and 934 deletions

View File

@@ -1,15 +1,15 @@
use std::hash::Hash;
use std::rc::Rc;
use ecow::EcoString;
use hashbrown::HashMap;
use crate::{ir::Ir, ty::internal::Value};
use crate::ty::internal::Value;
pub struct Env<K: Hash + Eq, V> {
let_: Rc<LetEnv<V>>,
with: Rc<With<K, V>>,
args: Rc<Vec<V>>,
last: Option<Rc<Env<K, V>>>,
}
pub struct LetEnv<V> {
@@ -17,8 +17,7 @@ pub struct LetEnv<V> {
last: Option<Rc<LetEnv<V>>>,
}
pub type VmEnv<'gc> = Env<usize, Value<'gc>>;
pub type IrEnv<'gc> = Env<usize, Ir>;
pub type VmEnv = Env<EcoString, Value>;
#[derive(Default, Clone)]
pub struct With<K: Hash + Eq, V> {
@@ -39,16 +38,15 @@ pub enum Type {
}
impl<K: Hash + Eq + Clone, V: Clone> Env<K, V> {
pub fn new(map: Vec<V>) -> Rc<Self> {
Rc::new(Self {
pub fn new(map: Vec<V>) -> Self {
Self {
let_: LetEnv::new(map),
with: With {
map: None,
last: None,
}.into(),
args: Vec::new().into(),
last: None,
})
}
}
pub fn lookup_arg(&self, level: usize) -> &V {
@@ -68,39 +66,32 @@ impl<K: Hash + Eq + Clone, V: Clone> Env<K, V> {
}
#[must_use]
pub fn enter_arg(self: Rc<Self>, val: V) -> Rc<Self> {
pub fn enter_arg(&self, val: V) -> Self {
let mut args = self.args.clone();
Rc::make_mut(&mut args).push(val);
Rc::new(Self {
Self {
let_: self.let_.clone(),
with: self.with.clone(),
last: Some(self),
args,
})
}
}
#[must_use]
pub fn enter_let(self: Rc<Self>, map: Vec<V>) -> Rc<Self> {
Rc::new(Self {
pub fn enter_let(&self, map: Vec<V>) -> Self {
Self {
let_: self.let_.clone().enter_let(map),
with: self.with.clone(),
args: self.args.clone(),
last: Some(self),
})
}
}
#[must_use]
pub fn enter_with(self: Rc<Self>, map: Rc<HashMap<K, V>>) -> Rc<Self> {
Rc::new(Self {
pub fn enter_with(&self, map: Rc<HashMap<K, V>>) -> Self {
Self {
let_: self.let_.clone(),
with: self.with.clone().enter(map),
args: self.args.clone(),
last: Some(self),
})
}
pub fn leave(&self) -> Rc<Self> {
self.last.clone().unwrap()
}
}
}