feat: bumpalo

This commit is contained in:
2025-05-23 12:09:53 +08:00
parent 53cbb37b00
commit a47a08b051
12 changed files with 130 additions and 127 deletions

View File

@@ -1,5 +1,3 @@
use std::rc::Rc;
use inkwell::AddressSpace;
use inkwell::context::Context;
use inkwell::execution_engine::ExecutionEngine;
@@ -209,9 +207,8 @@ extern "C" fn helper_debug(value: JITValue) {
extern "C" fn helper_capture_env(thunk: JITValue, env: *const VmEnv) {
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);
let env = unsafe { env.as_ref() }.unwrap();
thunk.capture(env);
}
extern "C" fn helper_neg(rhs: JITValue, _env: *const VmEnv) -> JITValue {

View File

@@ -165,10 +165,10 @@ impl<'vm, 'ctx: 'vm> JITContext<'ctx> {
.unwrap()
}
pub fn compile_function(
pub fn compile_function<'bump>(
&self,
func: &Func,
vm: &'vm VM<'_>,
vm: &'vm VM<'ctx>,
) -> Result<JitFunction<'ctx, JITFunc<'ctx, 'vm>>> {
let mut stack = Stack::<_, STACK_SIZE>::new();
let mut iter = func.opcodes.iter().copied();

View File

@@ -2,6 +2,7 @@
extern crate test;
use bumpalo::Bump;
use hashbrown::{HashMap, HashSet};
use inkwell::context::Context;
@@ -30,11 +31,12 @@ fn test_expr(expr: &str, expected: Value) {
prog.symbols.into(),
prog.symmap.into(),
prog.consts,
Bump::new(),
jit,
);
let env = env(&vm);
let value = vm
.eval(prog.top_level.into_iter(), env.into())
.eval(prog.top_level.into_iter(), vm.bump.alloc(env))
.unwrap()
.to_public(&vm, &mut HashSet::new());
assert_eq!(value, expected);