feat: lookup at downgrade time

works, but leaks memory
This commit is contained in:
2025-06-01 09:20:04 +08:00
parent 7d6168fdae
commit 20b2b6f1ef
20 changed files with 762 additions and 651 deletions

View File

@@ -1,17 +1,15 @@
use hashbrown::HashSet;
use derive_more::Constructor;
use gc_arena::Collect;
use rpds::Vector;
use gc_arena::{Collect, Gc, Mutation};
use crate::ty::public as p;
use crate::vm::VM;
use crate::env::VmEnv;
use super::Value;
#[derive(Constructor, Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub struct List<'gc> {
data: Vector<Value<'gc>>,
data: Vec<Value<'gc>>,
}
unsafe impl<'gc> Collect<'gc> for List<'gc> {
@@ -23,22 +21,40 @@ unsafe impl<'gc> Collect<'gc> for List<'gc> {
}
impl<'gc> List<'gc> {
pub fn empty() -> Self {
pub fn new() -> Self {
List {
data: Vector::new(),
data: Vec::new(),
}
}
pub fn with_capacity(cap: usize) -> Self {
List {
data: Vec::with_capacity(cap),
}
}
pub fn push(&mut self, elem: Value<'gc>) {
self.data.push_back_mut(elem);
self.data.push(elem);
}
pub fn concat(&mut self, other: &List<'gc>) {
for elem in other.data.iter() {
self.data.push_back_mut(elem.clone());
self.data.push(elem.clone());
}
}
pub fn capture(&mut self, env: Gc<'gc, VmEnv<'gc>>, mc: &Mutation<'gc>) {
self.data.iter().for_each(|v| {
if let Value::Thunk(ref thunk) = v.clone() {
thunk.capture_env(env, mc);
}
})
}
pub fn into_inner(self) -> Vec<Value<'gc>> {
self.data
}
pub fn to_public(&self, vm: &VM<'gc>, seen: &mut HashSet<Value<'gc>>) -> p::Value {
p::Value::List(p::List::new(
self.data