feat: gc (does compile, but WIP)

This commit is contained in:
2025-05-27 21:08:59 +08:00
parent 319c12c1f4
commit c3ace28af1
20 changed files with 696 additions and 575 deletions

View File

@@ -1,22 +1,22 @@
use hashbrown::HashSet;
use derive_more::Constructor;
use gc_arena::{Arena, Collect, Rootable};
use rpds::Vector;
use gc_arena::{Collect, Mutation};
use crate::error::Result;
use crate::ty::public as p;
use crate::vm::VM;
use crate::vm::{GcRoot, VM};
use super::Value;
#[derive(Constructor, Clone, PartialEq)]
pub struct List<'gc> {
data: Vector<Value<'gc>>
data: Vector<Value<'gc>>,
}
unsafe impl Collect for List<'_> {
fn trace(&self, cc: &gc_arena::Collection) {
unsafe impl<'gc> Collect<'gc> for List<'gc> {
fn trace<Tr: gc_arena::collect::Trace<'gc>>(&self, cc: &mut Tr) {
for v in self.data.iter() {
v.trace(cc);
}
@@ -40,15 +40,6 @@ impl<'gc> List<'gc> {
}
}
pub fn force_deep(&mut self, vm: &VM, mc: &Mutation<'gc>) -> Result<()> {
let mut vec: Vec<_> = self.data.iter().cloned().collect();
for v in vec.iter_mut() {
v.force_deep(vm, mc)?;
}
self.data = vec.into_iter().collect();
Ok(())
}
pub fn to_public(&self, vm: &VM<'gc>, seen: &mut HashSet<Value<'gc>>) -> p::Value {
p::Value::List(p::List::new(
self.data