feat: JIT (unusable, segfault)

This commit is contained in:
2025-05-18 15:01:19 +08:00
parent 29e959894d
commit f98d623c13
8 changed files with 326 additions and 122 deletions

View File

@@ -44,17 +44,19 @@ impl From<ir::Param> for Param {
pub struct Func<'vm> {
pub func: &'vm BFunc,
pub env: Env<'vm>,
pub compiled: OnceCell<JITFunc>,
pub compiled: OnceCell<&'vm JITFunc<'vm>>,
pub count: Cell<usize>
}
impl<'vm> Func<'vm> {
pub fn call(&self, vm: &'vm VM<'_>, arg: Value<'vm>) -> Result<Value<'vm>> {
impl<'vm, 'jit: 'vm> Func<'vm> {
pub fn call(&self, vm: &'vm VM<'jit>, arg: Value<'vm>) -> Result<Value<'vm>> {
use Param::*;
let count = self.count.get();
if count >= 1 {
let compiled = self.compiled.get_or_init(|| vm.compile_func(self));
let compiled = self.compiled.get_or_init(|| vm.compile_func(self.func));
let ret = compiled(vm as _, &self.env as _, arg.into());
return Ok(ret.into())
}
self.count.replace(count + 1);
let mut env = self.env.clone();