feat(jit): support multiple arg function call

note: performance regression?
This commit is contained in:
2025-05-20 18:22:06 +08:00
parent 96fb6033a4
commit b4249ccd11
2 changed files with 40 additions and 12 deletions

View File

@@ -11,7 +11,7 @@ use crate::jit::JITValueData;
use crate::ty::internal::{Thunk, Value};
use crate::vm::{LetEnv, VM};
use super::{JITFunc, JITValue, ValueTag};
use super::{JITValue, ValueTag};
pub struct Helpers<'ctx> {
pub int_type: IntType<'ctx>,
@@ -93,7 +93,7 @@ impl<'ctx> Helpers<'ctx> {
let call = module.add_function(
"call",
value_type.fn_type(
&[value_type.into(), value_type.into(), ptr_type.into()],
&[value_type.into(), ptr_type.into(), ptr_int_type.into(), ptr_type.into()],
false,
),
None,
@@ -224,7 +224,13 @@ extern "C" fn helper_neg(rhs: JITValue, _env: *const LetEnv) -> JITValue {
int: -unsafe { rhs.data.int },
},
},
_ => todo!(),
Float => JITValue {
tag: Float,
data: JITValueData {
float: -unsafe { rhs.data.float },
},
},
_ => unreachable!(),
}
}
@@ -238,7 +244,7 @@ extern "C" fn helper_not(rhs: JITValue, _env: *const LetEnv) -> JITValue {
bool: !unsafe { rhs.data.bool },
},
},
_ => todo!(),
_ => unreachable!(),
}
}
@@ -317,14 +323,16 @@ extern "C" fn helper_or(lhs: JITValue, rhs: JITValue) -> JITValue {
#[unsafe(no_mangle)]
extern "C" fn helper_call<'jit, 'vm>(
func: JITValue,
arg: JITValue,
args: *mut JITValue,
arity: usize,
vm: *const VM<'jit>,
) -> JITValue {
use ValueTag::*;
let args = unsafe { Vec::from_raw_parts(args, arity, arity) }.into_iter().map(Value::from).collect();
match func.tag {
Function => {
let func: Value = func.into();
func.call(unsafe { vm.as_ref() }.unwrap(), vec![arg.into()])
func.call(unsafe { vm.as_ref() }.unwrap(), args)
.unwrap()
.into()
}