feat(jit): fix segfault
This commit is contained in:
@@ -4,28 +4,28 @@ use std::rc::Rc;
|
||||
use crate::ty::internal::{AttrSet, Value};
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Env<'vm> {
|
||||
last: Option<Rc<Env<'vm>>>,
|
||||
map: Rc<HashMap<usize, Value<'vm>>>,
|
||||
pub struct Env<'jit, 'vm> {
|
||||
last: Option<Rc<Env<'jit, 'vm>>>,
|
||||
map: Rc<HashMap<usize, Value<'jit, 'vm>>>,
|
||||
}
|
||||
|
||||
impl<'vm> Env<'vm> {
|
||||
impl<'jit, 'vm> Env<'jit, 'vm> {
|
||||
pub fn empty() -> Self {
|
||||
Env::default()
|
||||
}
|
||||
|
||||
pub fn lookup(&self, symbol: usize) -> Option<Value<'vm>> {
|
||||
pub fn lookup(&self, symbol: usize) -> Option<Value<'jit, 'vm>> {
|
||||
if let Some(val) = self.map.get(&symbol).cloned() {
|
||||
return Some(val);
|
||||
}
|
||||
self.last.as_ref().map(|env| env.lookup(symbol)).flatten()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, symbol: usize, value: Value<'vm>) {
|
||||
pub fn insert(&mut self, symbol: usize, value: Value<'jit, 'vm>) {
|
||||
Rc::make_mut(&mut self.map).insert(symbol, value);
|
||||
}
|
||||
|
||||
pub fn enter(self, new: impl Iterator<Item = (usize, Value<'vm>)>) -> Self {
|
||||
pub fn enter(self, new: impl Iterator<Item = (usize, Value<'jit, 'vm>)>) -> Self {
|
||||
let map = Rc::new(new.collect());
|
||||
let last = Some(
|
||||
Env {
|
||||
@@ -37,7 +37,7 @@ impl<'vm> Env<'vm> {
|
||||
Env { last, map }
|
||||
}
|
||||
|
||||
pub fn enter_with(self, new: Rc<AttrSet<'vm>>) -> Self {
|
||||
pub fn enter_with(self, new: Rc<AttrSet<'jit, 'vm>>) -> Self {
|
||||
let map = Rc::new(
|
||||
new.as_inner()
|
||||
.iter()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use inkwell::execution_engine::JitFunction;
|
||||
use std::cell::{Cell, OnceCell, RefCell};
|
||||
|
||||
use crate::builtins::env;
|
||||
@@ -81,8 +82,8 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
pub fn eval(
|
||||
&'vm self,
|
||||
opcodes: impl Iterator<Item = OpCode>,
|
||||
mut env: Env<'vm>,
|
||||
) -> Result<Value<'vm>> {
|
||||
mut env: Env<'jit, 'vm>,
|
||||
) -> Result<Value<'jit, 'vm>> {
|
||||
let mut stack = Stack::<_, STACK_SIZE>::new();
|
||||
let mut iter = opcodes.into_iter();
|
||||
while let Some(opcode) = iter.next() {
|
||||
@@ -101,8 +102,8 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
fn single_op<'s, const CAP: usize>(
|
||||
&'vm self,
|
||||
opcode: OpCode,
|
||||
stack: &'s mut Stack<Value<'vm>, CAP>,
|
||||
env: &mut Env<'vm>,
|
||||
stack: &'s mut Stack<Value<'jit, 'vm>, CAP>,
|
||||
env: &mut Env<'jit, 'vm>,
|
||||
) -> Result<usize> {
|
||||
match opcode {
|
||||
OpCode::Illegal => panic!("illegal opcode"),
|
||||
@@ -264,7 +265,7 @@ impl<'vm, 'jit: 'vm> VM<'jit> {
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
pub fn compile_func(&'vm self, func: &'vm F) -> &'vm JITFunc<'vm> {
|
||||
pub fn compile_func(&'vm self, func: &'vm F) -> JitFunction<'jit, JITFunc<'jit, 'vm>> {
|
||||
self.jit.compile_function(func, self).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user