feat: gc-arena (WIP, does not compile)

This commit is contained in:
2025-05-25 17:18:54 +08:00
parent b41fd38bcc
commit cc06369c5e
17 changed files with 882 additions and 585 deletions

View File

@@ -2,6 +2,7 @@ use hashbrown::HashSet;
use derive_more::Constructor;
use rpds::Vector;
use gc_arena::{Collect, Mutation};
use crate::error::Result;
use crate::ty::public as p;
@@ -9,38 +10,46 @@ use crate::vm::VM;
use super::Value;
#[derive(Debug, Constructor, Clone, PartialEq)]
pub struct List<'jit: 'vm, 'vm> {
data: Vector<Value<'jit, 'vm>>,
#[derive(Constructor, Clone, PartialEq)]
pub struct List<'gc> {
data: Vector<Value<'gc>>
}
impl<'jit: 'vm, 'vm> List<'jit, 'vm> {
unsafe impl Collect for List<'_> {
fn trace(&self, cc: &gc_arena::Collection) {
for v in self.data.iter() {
v.trace(cc);
}
}
}
impl<'gc> List<'gc> {
pub fn empty() -> Self {
List {
data: Vector::new(),
}
}
pub fn push(&mut self, elem: Value<'jit, 'vm>) {
pub fn push(&mut self, elem: Value<'gc>) {
self.data.push_back_mut(elem);
}
pub fn concat(&mut self, other: &List<'jit, 'vm>) {
pub fn concat(&mut self, other: &List<'gc>) {
for elem in other.data.iter() {
self.data.push_back_mut(elem.clone());
}
}
pub fn force_deep(&mut self, vm: &'vm VM<'jit>) -> Result<()> {
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)?;
v.force_deep(vm, mc)?;
}
self.data = vec.into_iter().collect();
Ok(())
}
pub fn to_public(&self, vm: &'vm VM, seen: &mut HashSet<Value<'jit, 'vm>>) -> p::Value {
pub fn to_public(&self, vm: &VM<'gc>, seen: &mut HashSet<Value<'gc>>) -> p::Value {
p::Value::List(p::List::new(
self.data
.iter()