feat: lookup at downgrade time
works, but leaks memory
This commit is contained in:
@@ -34,6 +34,8 @@ pub struct Helpers<'ctx> {
|
||||
pub eq: FunctionValue<'ctx>,
|
||||
pub or: FunctionValue<'ctx>,
|
||||
pub call: FunctionValue<'ctx>,
|
||||
pub arg: FunctionValue<'ctx>,
|
||||
pub lookup_let: FunctionValue<'ctx>,
|
||||
pub lookup: FunctionValue<'ctx>,
|
||||
pub force: FunctionValue<'ctx>,
|
||||
}
|
||||
@@ -113,6 +115,16 @@ impl<'ctx> Helpers<'ctx> {
|
||||
),
|
||||
None,
|
||||
);
|
||||
let arg = module.add_function(
|
||||
"arg",
|
||||
value_type.fn_type(&[ptr_int_type.into(), ptr_type.into()], false),
|
||||
None,
|
||||
);
|
||||
let lookup_let = module.add_function(
|
||||
"lookup_let",
|
||||
value_type.fn_type(&[ptr_int_type.into(), ptr_int_type.into(), ptr_type.into()], false),
|
||||
None,
|
||||
);
|
||||
let lookup = module.add_function(
|
||||
"lookup",
|
||||
value_type.fn_type(&[ptr_int_type.into(), ptr_type.into()], false),
|
||||
@@ -142,6 +154,8 @@ impl<'ctx> Helpers<'ctx> {
|
||||
execution_engine.add_global_mapping(&eq, helper_eq as _);
|
||||
execution_engine.add_global_mapping(&or, helper_or as _);
|
||||
execution_engine.add_global_mapping(&call, helper_call as _);
|
||||
execution_engine.add_global_mapping(&arg, helper_arg as _);
|
||||
execution_engine.add_global_mapping(&lookup_let, helper_lookup_let as _);
|
||||
execution_engine.add_global_mapping(&lookup, helper_lookup as _);
|
||||
execution_engine.add_global_mapping(&force, helper_force as _);
|
||||
|
||||
@@ -165,6 +179,8 @@ impl<'ctx> Helpers<'ctx> {
|
||||
eq,
|
||||
or,
|
||||
call,
|
||||
arg,
|
||||
lookup_let,
|
||||
lookup,
|
||||
force,
|
||||
}
|
||||
@@ -348,9 +364,21 @@ extern "C" fn helper_call<'gc>(
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn helper_arg(idx: usize, env: *const VmEnv) -> JITValue {
|
||||
let env = unsafe { env.as_ref() }.unwrap();
|
||||
let val: JITValue = env.lookup_arg(idx).into();
|
||||
val
|
||||
}
|
||||
|
||||
extern "C" fn helper_lookup_let(level: usize, idx: usize, env: *const VmEnv) -> JITValue {
|
||||
let env = unsafe { env.as_ref() }.unwrap();
|
||||
let val: JITValue = env.lookup_let(level, idx).into();
|
||||
val
|
||||
}
|
||||
|
||||
extern "C" fn helper_lookup(sym: usize, env: *const VmEnv) -> JITValue {
|
||||
let env = unsafe { env.as_ref() }.unwrap();
|
||||
let val: JITValue = env.lookup_slow(&sym).unwrap().into();
|
||||
let val: JITValue = env.lookup_with(&sym).unwrap().into();
|
||||
val
|
||||
}
|
||||
|
||||
@@ -373,7 +401,7 @@ extern "C" fn helper_force<'gc>(
|
||||
let (opcodes, env) = thunk.suspend(mc).unwrap();
|
||||
let func = unsafe { jit.as_ref() }
|
||||
.unwrap()
|
||||
.compile_seq(opcodes.iter().copied(), vm)
|
||||
.compile_seq(opcodes.iter().copied().rev(), vm)
|
||||
.unwrap();
|
||||
let val = unsafe { func.call(env.as_ref() as *const _, mc as *const _) };
|
||||
thunk.insert_value(val.into(), mc);
|
||||
|
||||
Reference in New Issue
Block a user