chore: cargo fmt

This commit is contained in:
2025-05-19 11:33:18 +08:00
parent e17c48f2d9
commit 6d26716412
14 changed files with 209 additions and 79 deletions

View File

@@ -9,9 +9,9 @@ use inkwell::values::{BasicValueEnum, FunctionValue};
use crate::jit::JITValueData;
use crate::ty::internal::Thunk;
use crate::vm::{VM, Env};
use crate::vm::{Env, VM};
use super::{JITValue, ValueTag, JITFunc};
use super::{JITFunc, JITValue, ValueTag};
pub struct Helpers<'ctx> {
pub int_type: IntType<'ctx>,
@@ -43,52 +43,54 @@ impl<'ctx> Helpers<'ctx> {
let ptr_int_type = context.ptr_sized_int_type(execution_engine.get_target_data(), None);
let ptr_type = context.ptr_type(AddressSpace::default());
let value_type = context.struct_type(&[int_type.into(), int_type.into()], false);
let func_type = value_type.fn_type(
&[ptr_type.into(), ptr_type.into()],
false,
);
let func_type = value_type.fn_type(&[ptr_type.into(), ptr_type.into()], false);
let debug = module.add_function(
"debug",
context
.void_type()
.fn_type(&[value_type.into()], false),
None
context.void_type().fn_type(&[value_type.into()], false),
None,
);
let capture_env = module.add_function(
"capture_env",
context
.void_type()
.fn_type(&[value_type.into(), ptr_type.into()], false),
None
None,
);
let neg = module.add_function(
"neg",
value_type.fn_type(&[value_type.into(), ptr_type.into()], false),
None
None,
);
let add = module.add_function(
"add",
value_type.fn_type(&[value_type.into(), value_type.into()], false),
None
None,
);
let sub = module.add_function(
"sub",
value_type.fn_type(&[value_type.into(), value_type.into()], false),
None
None,
);
// Assuming a single argument for now based on the test case
let call = module.add_function(
"call",
value_type.fn_type(&[ptr_type.into(), ptr_type.into(), ptr_type.into(), value_type.into()], false),
None
value_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
ptr_type.into(),
value_type.into(),
],
false,
),
None,
);
let lookup = module.add_function(
"lookup",
value_type.fn_type(&[ptr_int_type.into(), ptr_type.into()], false),
None
None,
);
execution_engine.add_global_mapping(&debug, helper_debug as _);
execution_engine.add_global_mapping(&capture_env, helper_capture_env as _);
execution_engine.add_global_mapping(&neg, helper_neg as _);
@@ -97,7 +99,6 @@ impl<'ctx> Helpers<'ctx> {
execution_engine.add_global_mapping(&call, helper_call as _);
execution_engine.add_global_mapping(&lookup, helper_lookup as _);
Helpers {
int_type,
float_type,
@@ -207,7 +208,11 @@ extern "C" fn helper_add(lhs: JITValue, rhs: JITValue) -> JITValue {
int: unsafe { lhs.data.int + rhs.data.int },
},
},
_ => todo!("Addition not implemented for {:?} and {:?}", lhs.tag, rhs.tag),
_ => todo!(
"Addition not implemented for {:?} and {:?}",
lhs.tag,
rhs.tag
),
}
}
@@ -221,17 +226,24 @@ extern "C" fn helper_sub(lhs: JITValue, rhs: JITValue) -> JITValue {
int: unsafe { lhs.data.int - rhs.data.int },
},
},
_ => todo!("Substruction not implemented for {:?} and {:?}", lhs.tag, rhs.tag),
_ => todo!(
"Substruction not implemented for {:?} and {:?}",
lhs.tag,
rhs.tag
),
}
}
#[unsafe(no_mangle)]
extern "C" fn helper_call<'jit, 'vm>(vm: *const VM<'jit>, env: *const Env<'jit, 'vm>, func_ptr: *const (), arg: JITValue) -> JITValue {
extern "C" fn helper_call<'jit, 'vm>(
vm: *const VM<'jit>,
env: *const Env<'jit, 'vm>,
func_ptr: *const (),
arg: JITValue,
) -> JITValue {
let func: JITFunc = unsafe { std::mem::transmute(func_ptr) };
todo!();
unsafe {
func(vm, env)
}
unsafe { func(vm, env) }
}
#[unsafe(no_mangle)]