feat: initial parallel impl
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use std::ptr::NonNull;
|
||||
use std::rc::Rc;
|
||||
|
||||
use inkwell::AddressSpace;
|
||||
use inkwell::context::Context;
|
||||
@@ -10,7 +9,6 @@ use inkwell::values::{BasicValueEnum, FunctionValue};
|
||||
|
||||
use crate::env::VmEnv;
|
||||
use crate::eval::Engine;
|
||||
use crate::ty::internal::{Thunk, Value};
|
||||
|
||||
use super::{JITContext, JITValue, ValueTag, JITValueData};
|
||||
|
||||
@@ -228,11 +226,8 @@ extern "C" fn helper_debug(value: JITValue) {
|
||||
dbg!(value.tag);
|
||||
}
|
||||
|
||||
extern "C" fn helper_capture_env<'gc>(thunk: JITValue, env: *const VmEnv<'gc>) {
|
||||
let thunk = unsafe { (thunk.data.ptr as *const Thunk).as_ref().unwrap() };
|
||||
let env = unsafe { Rc::from_raw(env) };
|
||||
thunk.capture_env(env.clone());
|
||||
std::mem::forget(env);
|
||||
extern "C" fn helper_capture_env(thunk: JITValue, env: *const VmEnv) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
extern "C" fn helper_neg(rhs: JITValue, _env: *const VmEnv) -> JITValue {
|
||||
@@ -335,7 +330,7 @@ extern "C" fn helper_or(lhs: JITValue, rhs: JITValue) -> JITValue {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn helper_call<'gc>(func: JITValue, arg: JITValue, engine: *mut Engine) -> JITValue {
|
||||
extern "C" fn helper_call(func: JITValue, arg: JITValue, engine: *mut Engine) -> JITValue {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@@ -352,15 +347,13 @@ extern "C" fn helper_lookup_let(level: usize, idx: usize, env: *const VmEnv) ->
|
||||
}
|
||||
|
||||
extern "C" fn helper_lookup(sym: usize, env: *const VmEnv) -> JITValue {
|
||||
let env = unsafe { env.as_ref() }.unwrap();
|
||||
let val: JITValue = env.lookup_with(&sym).unwrap().clone().into();
|
||||
val
|
||||
todo!()
|
||||
}
|
||||
|
||||
extern "C" fn helper_force<'gc>(
|
||||
extern "C" fn helper_force(
|
||||
thunk: JITValue,
|
||||
vm: NonNull<Engine>,
|
||||
jit: *const JITContext<'gc>,
|
||||
jit: *const JITContext,
|
||||
) -> JITValue {
|
||||
if !matches!(thunk.tag, ValueTag::Thunk) {
|
||||
return thunk;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use inkwell::OptimizationLevel;
|
||||
@@ -9,7 +8,7 @@ use inkwell::execution_engine::ExecutionEngine;
|
||||
use inkwell::module::Module;
|
||||
|
||||
use crate::env::VmEnv;
|
||||
use crate::ty::internal::{Value, Thunk};
|
||||
use crate::ty::internal::Value;
|
||||
|
||||
mod helpers;
|
||||
mod compile;
|
||||
@@ -51,29 +50,29 @@ pub union JITValueData {
|
||||
ptr: *const (),
|
||||
}
|
||||
|
||||
impl<'gc> From<JITValue> for Value<'gc> {
|
||||
impl From<JITValue> for Value {
|
||||
fn from(value: JITValue) -> Self {
|
||||
use ValueTag::*;
|
||||
match value.tag {
|
||||
Int => Value::Int(unsafe { value.data.int }),
|
||||
Null => Value::Null,
|
||||
Function => Value::Func(unsafe { Rc::from_raw(value.data.ptr as *const _) }),
|
||||
/* Function => Value::Func(unsafe { Rc::from_raw(value.data.ptr as *const _) }),
|
||||
Thunk => Value::Thunk(self::Thunk {
|
||||
thunk: unsafe { Rc::from_raw(value.data.ptr as *const _) },
|
||||
}),
|
||||
}), */
|
||||
_ => todo!("not implemented for {:?}", value.tag),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Value<'_>> for JITValue {
|
||||
impl From<Value> for JITValue {
|
||||
fn from(value: Value) -> Self {
|
||||
match value {
|
||||
Value::Int(int) => JITValue {
|
||||
tag: ValueTag::Int,
|
||||
data: JITValueData { int },
|
||||
},
|
||||
Value::Func(func) => JITValue {
|
||||
/* Value::Func(func) => JITValue {
|
||||
tag: ValueTag::Function,
|
||||
data: JITValueData {
|
||||
ptr: Rc::into_raw(func) as *const _,
|
||||
@@ -84,23 +83,23 @@ impl From<Value<'_>> for JITValue {
|
||||
data: JITValueData {
|
||||
ptr: Rc::into_raw(thunk.thunk) as *const _,
|
||||
},
|
||||
},
|
||||
}, */
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct JITFunc<'gc>(F<'gc>, PhantomData<&'gc mut ()>);
|
||||
type F<'gc> = unsafe extern "C" fn(*const VmEnv<'gc>) -> JITValue;
|
||||
pub struct JITFunc<'ctx>(F, PhantomData<&'ctx mut ()>);
|
||||
type F = unsafe extern "C" fn(*const VmEnv) -> JITValue;
|
||||
|
||||
impl<'gc> From<F<'gc>> for JITFunc<'gc> {
|
||||
fn from(value: F<'gc>) -> Self {
|
||||
impl From<F> for JITFunc<'_> {
|
||||
fn from(value: F) -> Self {
|
||||
Self(value, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'gc> Deref for JITFunc<'gc> {
|
||||
type Target = F<'gc>;
|
||||
impl Deref for JITFunc<'_> {
|
||||
type Target = F;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user