feat: gc-arena
finally...
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::jit::JITValueData;
|
||||
use crate::ty::internal::{Thunk, Value};
|
||||
use crate::vm::VM;
|
||||
|
||||
use super::{JITValue, ValueTag};
|
||||
use super::{JITContext, JITValue, ValueTag};
|
||||
|
||||
pub struct Helpers<'ctx> {
|
||||
pub int_type: IntType<'ctx>,
|
||||
@@ -103,7 +103,7 @@ impl<'ctx> Helpers<'ctx> {
|
||||
let call = module.add_function(
|
||||
"call",
|
||||
value_type.fn_type(
|
||||
&[value_type.into(), value_type.into(), ptr_type.into()],
|
||||
&[value_type.into(), value_type.into(), ptr_type.into(), ptr_type.into()],
|
||||
false,
|
||||
),
|
||||
None,
|
||||
@@ -115,7 +115,7 @@ impl<'ctx> Helpers<'ctx> {
|
||||
);
|
||||
let force = module.add_function(
|
||||
"force",
|
||||
value_type.fn_type(&[value_type.into(), ptr_type.into()], false),
|
||||
value_type.fn_type(&[value_type.into(), ptr_type.into(), ptr_type.into(), ptr_type.into()], false),
|
||||
None,
|
||||
);
|
||||
|
||||
@@ -310,30 +310,26 @@ extern "C" fn helper_or(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
},
|
||||
},
|
||||
_ => todo!(
|
||||
"Substruction not implemented for {:?} and {:?}",
|
||||
"Substraction not implemented for {:?} and {:?}",
|
||||
lhs.tag,
|
||||
rhs.tag
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn helper_call(
|
||||
extern "C" fn helper_call<'gc>(
|
||||
func: JITValue,
|
||||
arg: JITValue,
|
||||
vm: *const VM,
|
||||
mc: *const Mutation,
|
||||
vm: *const VM<'gc>,
|
||||
mc: *const Mutation<'gc>,
|
||||
) -> JITValue {
|
||||
use ValueTag::*;
|
||||
let vm = unsafe { vm.as_ref() }.unwrap();
|
||||
let mc = unsafe { mc.as_ref() }.unwrap();
|
||||
let arg = Value::from(arg);
|
||||
match func.tag {
|
||||
Function => {
|
||||
let mut func: Value = func.into();
|
||||
func.call(
|
||||
arg.into(),
|
||||
unsafe { vm.as_ref() }.unwrap(),
|
||||
unsafe { mc.as_ref() }.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
func.into()
|
||||
ValueTag::Function => {
|
||||
let func = Value::from(func).unwrap_func();
|
||||
func.call_compile(arg, vm, mc).unwrap().into()
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
@@ -345,15 +341,22 @@ extern "C" fn helper_lookup(sym: usize, env: *const VmEnv) -> JITValue {
|
||||
val
|
||||
}
|
||||
|
||||
extern "C" fn helper_force(thunk: JITValue, vm: *const VM, mc: *const Mutation) -> JITValue {
|
||||
todo!()
|
||||
/* let mut val = Value::from(thunk);
|
||||
val.force(
|
||||
unsafe { vm.as_ref() }.unwrap(),
|
||||
unsafe { mc.as_ref() }.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
val.into() */
|
||||
extern "C" fn helper_force<'gc>(thunk: JITValue, vm: *const VM<'gc>, mc: *const Mutation<'gc>, jit: *const JITContext<'gc>) -> JITValue {
|
||||
if !matches!(thunk.tag, ValueTag::Thunk) {
|
||||
return thunk;
|
||||
}
|
||||
|
||||
let vm = unsafe { vm.as_ref() }.unwrap();
|
||||
let mc = unsafe { mc.as_ref() }.unwrap();
|
||||
let thunk = Value::from(thunk).unwrap_thunk();
|
||||
if let Some(val) = thunk.get_value() {
|
||||
return val.into()
|
||||
}
|
||||
let (opcodes, env) = thunk.suspend(mc).unwrap();
|
||||
let func = unsafe { jit.as_ref() }.unwrap().compile_seq(opcodes.iter().copied(), vm).unwrap();
|
||||
let val = unsafe { func.call(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 {
|
||||
|
||||
Reference in New Issue
Block a user