feat: gc-arena

finally...
This commit is contained in:
2025-05-28 21:52:13 +08:00
parent c3ace28af1
commit 99dce2e778
7 changed files with 98 additions and 99 deletions

View File

@@ -1,7 +1,7 @@
use std::cell::Cell;
use gc_arena::lock::{GcRefLock, RefLock};
use gc_arena::{Arena, Collect, Gc, Mutation, Rootable};
use gc_arena::{Collect, Gc, Mutation};
use hashbrown::HashMap;
use itertools::Itertools;
@@ -11,7 +11,7 @@ use crate::error::Result;
use crate::ir;
use crate::jit::JITFunc;
use crate::ty::internal::{Thunk, Value};
use crate::vm::{GcRoot, VM, eval};
use crate::vm::VM;
#[derive(Debug, Clone, Collect)]
#[collect(no_drop)]
@@ -44,7 +44,6 @@ impl From<ir::Param> for Param {
}
}
#[derive(Clone)]
pub struct Func<'gc> {
pub func: &'gc BFunc,
pub env: Gc<'gc, VmEnv<'gc>>,
@@ -70,15 +69,13 @@ impl<'gc> Func<'gc> {
}
}
pub fn call(
pub fn call_compile(
&self,
arg: Value<'gc>,
vm: &'gc VM<'gc>,
mc: &Mutation<'gc>,
arena: &Arena<impl for<'a> Rootable<'a, Root = GcRoot<'a>>>,
) -> Result<Value<'gc>> {
todo!()
/* use Param::*;
use Param::*;
let mut env = self.env;
env = match self.func.param.clone() {
@@ -117,17 +114,13 @@ impl<'gc> Func<'gc> {
}
};
let count = self.count.get();
self.count.replace(count + 1);
if count >= 1 {
let compiled = &mut *self.compiled.borrow_mut(mc);
let compiled = compiled.get_or_insert_with(|| vm.compile_func(self.func));
let ret = unsafe { compiled.call(env.as_ref() as *const VmEnv, mc as *const _) };
return Ok(ret.into());
}
eval(self.func.opcodes.iter().copied(), arena, |val, _| {
Ok(val)
}) */
let compiled = self
.compiled
.borrow_mut(mc)
.get_or_insert_with(|| vm.compile_func(self.func))
.clone();
let ret = unsafe { compiled.call(env.as_ref() as *const VmEnv, mc as *const _) };
Ok(ret.into())
}
}