feat: no clone in JIT
IMPORTANT: should not drop or create values in JIT anymore
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::error::*;
|
||||
use crate::stack::Stack;
|
||||
use crate::ty::common::Const;
|
||||
use crate::ty::internal::{Thunk, Value};
|
||||
use crate::vm::{VmEnv, VM};
|
||||
use crate::vm::{VM, VmEnv};
|
||||
|
||||
mod helpers;
|
||||
|
||||
@@ -57,6 +57,12 @@ pub union JITValueData {
|
||||
impl<'jit: 'vm, 'vm> From<JITValue> for Value<'jit, 'vm> {
|
||||
fn from(value: JITValue) -> Self {
|
||||
use ValueTag::*;
|
||||
match value.tag {
|
||||
List | AttrSet | String | Function | Thunk | Path => unsafe {
|
||||
Rc::increment_strong_count(value.data.ptr);
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
match value.tag {
|
||||
Int => Value::Const(Const::Int(unsafe { value.data.int })),
|
||||
Null => Value::Const(Const::Null),
|
||||
@@ -67,6 +73,30 @@ impl<'jit: 'vm, 'vm> From<JITValue> for Value<'jit, 'vm> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Value<'_, '_>> for JITValue {
|
||||
fn from(value: &Value<'_, '_>) -> Self {
|
||||
match value {
|
||||
Value::Const(Const::Int(int)) => JITValue {
|
||||
tag: ValueTag::Int,
|
||||
data: JITValueData { int: *int },
|
||||
},
|
||||
Value::Func(func) => JITValue {
|
||||
tag: ValueTag::Function,
|
||||
data: JITValueData {
|
||||
ptr: Rc::as_ptr(func) as *const _,
|
||||
},
|
||||
},
|
||||
Value::Thunk(thunk) => JITValue {
|
||||
tag: ValueTag::Thunk,
|
||||
data: JITValueData {
|
||||
ptr: Rc::as_ptr(thunk) as *const _,
|
||||
},
|
||||
},
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Value<'_, '_>> for JITValue {
|
||||
fn from(value: Value<'_, '_>) -> Self {
|
||||
match value {
|
||||
@@ -144,14 +174,7 @@ impl<'vm, 'ctx: 'vm> JITContext<'ctx> {
|
||||
let env = func_.get_nth_param(1).unwrap().into_pointer_value();
|
||||
let entry = self.context.append_basic_block(func_, "entry");
|
||||
self.builder.position_at_end(entry);
|
||||
self.build_expr(
|
||||
&mut iter,
|
||||
vm,
|
||||
env,
|
||||
&mut stack,
|
||||
func_,
|
||||
func.opcodes.len(),
|
||||
)?;
|
||||
self.build_expr(&mut iter, vm, env, &mut stack, func_, func.opcodes.len())?;
|
||||
|
||||
assert_eq!(stack.len(), 1);
|
||||
let value = stack.pop();
|
||||
|
||||
Reference in New Issue
Block a user