feat: no clone in JIT
IMPORTANT: should not drop or create values in JIT anymore
This commit is contained in:
@@ -9,7 +9,7 @@ use inkwell::values::{BasicValueEnum, FunctionValue};
|
||||
|
||||
use crate::jit::JITValueData;
|
||||
use crate::ty::internal::{Thunk, Value};
|
||||
use crate::vm::{VmEnv, VM};
|
||||
use crate::vm::{VM, VmEnv};
|
||||
|
||||
use super::{JITValue, ValueTag};
|
||||
|
||||
@@ -204,20 +204,17 @@ impl<'ctx> Helpers<'ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_debug(value: JITValue) {
|
||||
dbg!(value.tag);
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_capture_env(thunk: JITValue, env: *const VmEnv) {
|
||||
let thunk: &Thunk = unsafe { std::mem::transmute(thunk.data.ptr.as_ref().unwrap()) };
|
||||
let thunk = unsafe { (thunk.data.ptr as *const Thunk).as_ref().unwrap() };
|
||||
let env = unsafe { Rc::from_raw(env) };
|
||||
thunk.capture(env.clone());
|
||||
std::mem::forget(env);
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_neg(rhs: JITValue, _env: *const VmEnv) -> JITValue {
|
||||
use ValueTag::*;
|
||||
match rhs.tag {
|
||||
@@ -237,7 +234,6 @@ extern "C" fn helper_neg(rhs: JITValue, _env: *const VmEnv) -> JITValue {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_not(rhs: JITValue, _env: *const VmEnv) -> JITValue {
|
||||
use ValueTag::*;
|
||||
match rhs.tag {
|
||||
@@ -251,7 +247,6 @@ extern "C" fn helper_not(rhs: JITValue, _env: *const VmEnv) -> JITValue {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_add(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
use ValueTag::*;
|
||||
match (lhs.tag, rhs.tag) {
|
||||
@@ -269,7 +264,6 @@ extern "C" fn helper_add(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_sub(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
use ValueTag::*;
|
||||
match (lhs.tag, rhs.tag) {
|
||||
@@ -287,7 +281,6 @@ extern "C" fn helper_sub(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_eq(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
use ValueTag::*;
|
||||
match (lhs.tag, rhs.tag) {
|
||||
@@ -305,7 +298,6 @@ extern "C" fn helper_eq(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_or(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
use ValueTag::*;
|
||||
match (lhs.tag, rhs.tag) {
|
||||
@@ -323,7 +315,6 @@ extern "C" fn helper_or(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_call<'jit>(
|
||||
func: JITValue,
|
||||
args: *mut JITValue,
|
||||
@@ -346,14 +337,12 @@ extern "C" fn helper_call<'jit>(
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_lookup<'jit, 'vm>(sym: usize, env: *const VmEnv<'jit, 'vm>) -> JITValue {
|
||||
let env = unsafe { env.as_ref() }.unwrap();
|
||||
let val = env.lookup(&sym);
|
||||
val.cloned().unwrap().into()
|
||||
let val: JITValue = env.lookup(&sym).unwrap().into();
|
||||
val
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn helper_force<'jit>(thunk: JITValue, vm: *const VM<'jit>) -> JITValue {
|
||||
let mut val = Value::from(thunk);
|
||||
val.force(unsafe { vm.as_ref() }.unwrap()).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user