feat: less gc (WIP)

This commit is contained in:
2025-06-02 14:18:59 +08:00
parent d3442e87e7
commit 51f8df9cca
11 changed files with 125 additions and 179 deletions

View File

@@ -1,4 +1,5 @@
use std::marker::PhantomData;
use std::rc::Rc;
use std::ops::Deref;
use gc_arena::{Collect, Gc, Mutation};
@@ -63,7 +64,7 @@ impl<'gc> From<JITValue> for Value<'gc> {
match value.tag {
Int => Value::Int(unsafe { value.data.int }),
Null => Value::Null,
Function => Value::Func(unsafe { Gc::from_ptr(value.data.ptr as *const _) }),
Function => Value::Func(unsafe { Rc::from_raw(value.data.ptr as *const _) }),
Thunk => Value::Thunk(self::Thunk {
thunk: unsafe { Gc::from_ptr(value.data.ptr as *const _) },
}),
@@ -72,19 +73,21 @@ impl<'gc> From<JITValue> for Value<'gc> {
}
}
impl From<&Value<'_>> for JITValue {
fn from(value: &Value) -> Self {
impl From<Value<'_>> for JITValue {
fn from(value: Value) -> Self {
match value {
&Value::Int(int) => JITValue {
Value::Int(int) => JITValue {
tag: ValueTag::Int,
data: JITValueData { int },
},
&Value::Func(func) => JITValue {
tag: ValueTag::Function,
data: JITValueData {
ptr: Gc::as_ptr(func) as *const _,
},
},
Value::Func(func) => {
JITValue {
tag: ValueTag::Function,
data: JITValueData {
ptr: Rc::into_raw(func) as *const _,
},
}
}
Value::Thunk(thunk) => JITValue {
tag: ValueTag::Thunk,
data: JITValueData {