feat(gc): WIP

This commit is contained in:
2025-06-02 12:00:38 +08:00
parent 20b2b6f1ef
commit d3442e87e7
7 changed files with 72 additions and 77 deletions

View File

@@ -56,7 +56,7 @@ impl<'ctx> Helpers<'ctx> {
let new_thunk = module.add_function(
"new_thunk",
value_type.fn_type(&[ptr_type.into(), ptr_type.into()], false),
value_type.fn_type(&[ptr_type.into(), ptr_type.into(), ptr_type.into()], false),
None,
);
let debug = module.add_function(
@@ -110,6 +110,7 @@ impl<'ctx> Helpers<'ctx> {
value_type.into(),
ptr_type.into(),
ptr_type.into(),
ptr_type.into(),
],
false,
),
@@ -350,6 +351,7 @@ extern "C" fn helper_call<'gc>(
func: JITValue,
arg: JITValue,
vm: *const VM<'gc>,
env: *mut VmEnv<'gc>,
mc: *const Mutation<'gc>,
) -> JITValue {
let vm = unsafe { vm.as_ref() }.unwrap();
@@ -358,7 +360,8 @@ extern "C" fn helper_call<'gc>(
match func.tag {
ValueTag::Function => {
let func = Value::from(func).unwrap_func();
func.call_compile(arg, vm, mc).unwrap().into()
let env = unsafe { &mut *env };
env.alloc_gc(func.call_compile(arg, vm, mc).unwrap(), mc).into()
}
_ => todo!(),
}
@@ -403,15 +406,17 @@ extern "C" fn helper_force<'gc>(
.unwrap()
.compile_seq(opcodes.iter().copied().rev(), vm)
.unwrap();
let val = unsafe { func.call(env.as_ref() as *const _, mc as *const _) };
let val = unsafe { func(env.as_ref() as *const _, mc as *const _) };
thunk.insert_value(val.into(), mc);
val
}
extern "C" fn helper_new_thunk(opcodes: *const OpCodes, mc: *const Mutation) -> JITValue {
Value::Thunk(Thunk::new(
extern "C" fn helper_new_thunk<'gc>(opcodes: *const OpCodes, env: *mut VmEnv<'gc>, mc: *const Mutation<'gc>) -> JITValue {
let mc = unsafe { &*mc };
let env = unsafe { &mut *env };
env.alloc_gc(Value::Thunk(Thunk::new(
unsafe { opcodes.as_ref() }.unwrap(),
unsafe { mc.as_ref() }.unwrap(),
))
mc
)), mc)
.into()
}