feat: migrate to cranelift (WIP)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::cell::OnceCell;
|
||||
use core::mem::MaybeUninit;
|
||||
use std::rc::Rc;
|
||||
|
||||
use hashbrown::HashSet;
|
||||
@@ -7,7 +8,7 @@ use priority_queue::PriorityQueue;
|
||||
|
||||
use crate::env::Env;
|
||||
use crate::error::Result;
|
||||
use crate::eval::jit::{JITContext, JITFunc};
|
||||
use crate::eval::jit::{JITContext, JITFunc, JITValue};
|
||||
use crate::eval::Evaluate;
|
||||
use crate::ir::{Dep, Downgraded, Ir, SccNode};
|
||||
use crate::ty::internal as i;
|
||||
@@ -19,12 +20,12 @@ mod test;
|
||||
type ThunkIdx = usize;
|
||||
type EnvIdx = usize;
|
||||
|
||||
pub struct Engine<'ctx: 'exec, 'exec> {
|
||||
pub struct Engine<'exec> {
|
||||
pub thunks: Box<[Ir]>,
|
||||
pub func_offset: usize,
|
||||
pub func_deps: Vec<HashSet<Dep>>,
|
||||
jit: &'exec JITContext<'ctx>,
|
||||
compiled: Box<[OnceCell<JITFunc<'ctx, 'exec>>]>,
|
||||
jit: &'exec JITContext,
|
||||
compiled: Box<[OnceCell<JITFunc<'exec>>]>,
|
||||
tasks: PriorityQueue<CompileTask, usize>,
|
||||
}
|
||||
|
||||
@@ -79,8 +80,12 @@ impl<'ctx, 'exec> Engine<'ctx, 'exec> {
|
||||
}
|
||||
|
||||
pub fn eval_thunk(&mut self, idx: usize, env: &mut Env) -> Result<i::Value> {
|
||||
let func = self.compiled[idx].get_or_init(|| self.jit.compile(&self.thunks[idx]));
|
||||
Ok(unsafe { func(self as *const Engine, env as *const Env).into() })
|
||||
let func = self.compiled[idx].get_or_init(|| self.jit.compile(&self.thunks[idx], idx));
|
||||
let mut ret: MaybeUninit<JITValue> = MaybeUninit::uninit();
|
||||
unsafe {
|
||||
func(self as *const Engine, env as *const Env, core::mem::transmute::<*mut MaybeUninit<JITValue>, *mut JITValue>(&mut ret as *mut _));
|
||||
Ok(ret.assume_init().into())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eval_func_deps(&mut self, idx: usize, env: &mut Env) -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user