11use zyntax_compiler:: cranelift_backend:: CraneliftBackend ;
22use zyntax_compiler:: hir:: {
3- HirConstant , HirFunction , HirFunctionSignature , HirId , HirInstruction , HirParam ,
4- HirTerminator , HirType , HirValueKind , ParamAttributes ,
3+ HirConstant , HirFunction , HirFunctionSignature , HirId , HirInstruction , HirParam , HirTerminator ,
4+ HirType , HirValueKind , ParamAttributes ,
55} ;
6- use zyntax_typed_ast:: { InternedString , arena:: AstArena } ;
6+ use zyntax_typed_ast:: { arena:: AstArena , InternedString } ;
77
88/// Helper to create an interned string for tests
99fn create_test_string ( s : & str ) -> InternedString {
@@ -14,13 +14,14 @@ fn create_test_string(s: &str) -> InternedString {
1414/// Compile a HIR function and return the backend + function pointer
1515fn compile_and_get_ptr ( func : HirFunction ) -> ( CraneliftBackend , Option < * const u8 > ) {
1616 let func_id = func. id ;
17- let mut backend = CraneliftBackend :: new ( )
18- . expect ( "Failed to create Cranelift backend" ) ;
19- backend . compile_function ( func_id, & func)
17+ let mut backend = CraneliftBackend :: new ( ) . expect ( "Failed to create Cranelift backend" ) ;
18+ backend
19+ . compile_function ( func_id, & func)
2020 . expect ( "Failed to compile function" ) ;
2121
2222 // Manually finalize and get function pointer
23- backend. finalize_definitions ( )
23+ backend
24+ . finalize_definitions ( )
2425 . expect ( "Failed to finalize definitions" ) ;
2526
2627 let func_ptr = backend. get_function_ptr ( func_id) ;
@@ -60,7 +61,10 @@ fn test_memory_roundtrip_execution() {
6061 let param_x = func. create_value ( HirType :: I32 , HirValueKind :: Parameter ( 0 ) ) ;
6162
6263 // Alloca i32
63- let ptr = func. create_value ( HirType :: Ptr ( Box :: new ( HirType :: I32 ) ) , HirValueKind :: Instruction ) ;
64+ let ptr = func. create_value (
65+ HirType :: Ptr ( Box :: new ( HirType :: I32 ) ) ,
66+ HirValueKind :: Instruction ,
67+ ) ;
6468 let alloca = HirInstruction :: Alloca {
6569 result : ptr,
6670 ty : HirType :: I32 ,
@@ -90,7 +94,9 @@ fn test_memory_roundtrip_execution() {
9094 block. add_instruction ( alloca) ;
9195 block. add_instruction ( store) ;
9296 block. add_instruction ( load) ;
93- block. set_terminator ( HirTerminator :: Return { values : vec ! [ result] } ) ;
97+ block. set_terminator ( HirTerminator :: Return {
98+ values : vec ! [ result] ,
99+ } ) ;
94100
95101 let ( _backend, func_ptr) = compile_and_get_ptr ( func) ;
96102 let func_ptr = func_ptr. expect ( "Failed to get function pointer" ) ;
@@ -139,7 +145,10 @@ fn test_memory_i64_execution() {
139145 let param_x = func. create_value ( HirType :: I64 , HirValueKind :: Parameter ( 0 ) ) ;
140146
141147 // Alloca i64
142- let ptr = func. create_value ( HirType :: Ptr ( Box :: new ( HirType :: I64 ) ) , HirValueKind :: Instruction ) ;
148+ let ptr = func. create_value (
149+ HirType :: Ptr ( Box :: new ( HirType :: I64 ) ) ,
150+ HirValueKind :: Instruction ,
151+ ) ;
143152 let alloca = HirInstruction :: Alloca {
144153 result : ptr,
145154 ty : HirType :: I64 ,
@@ -169,7 +178,9 @@ fn test_memory_i64_execution() {
169178 block. add_instruction ( alloca) ;
170179 block. add_instruction ( store) ;
171180 block. add_instruction ( load) ;
172- block. set_terminator ( HirTerminator :: Return { values : vec ! [ result] } ) ;
181+ block. set_terminator ( HirTerminator :: Return {
182+ values : vec ! [ result] ,
183+ } ) ;
173184
174185 let ( _backend, func_ptr) = compile_and_get_ptr ( func) ;
175186 let func_ptr = func_ptr. expect ( "Failed to get function pointer" ) ;
@@ -218,7 +229,10 @@ fn test_memory_f64_execution() {
218229 let param_x = func. create_value ( HirType :: F64 , HirValueKind :: Parameter ( 0 ) ) ;
219230
220231 // Alloca f64
221- let ptr = func. create_value ( HirType :: Ptr ( Box :: new ( HirType :: F64 ) ) , HirValueKind :: Instruction ) ;
232+ let ptr = func. create_value (
233+ HirType :: Ptr ( Box :: new ( HirType :: F64 ) ) ,
234+ HirValueKind :: Instruction ,
235+ ) ;
222236 let alloca = HirInstruction :: Alloca {
223237 result : ptr,
224238 ty : HirType :: F64 ,
@@ -248,7 +262,9 @@ fn test_memory_f64_execution() {
248262 block. add_instruction ( alloca) ;
249263 block. add_instruction ( store) ;
250264 block. add_instruction ( load) ;
251- block. set_terminator ( HirTerminator :: Return { values : vec ! [ result] } ) ;
265+ block. set_terminator ( HirTerminator :: Return {
266+ values : vec ! [ result] ,
267+ } ) ;
252268
253269 let ( _backend, func_ptr) = compile_and_get_ptr ( func) ;
254270 let func_ptr = func_ptr. expect ( "Failed to get function pointer" ) ;
@@ -257,7 +273,7 @@ fn test_memory_f64_execution() {
257273 let func_typed: extern "C" fn ( f64 ) -> f64 = unsafe { std:: mem:: transmute ( func_ptr) } ;
258274
259275 // Test with various values
260- assert_eq ! ( func_typed( 3.14159 ) , 3.14159 ) ;
276+ assert_eq ! ( func_typed( std :: f64 :: consts :: PI ) , std :: f64 :: consts :: PI ) ;
261277 assert_eq ! ( func_typed( 0.0 ) , 0.0 ) ;
262278 assert_eq ! ( func_typed( -123.456 ) , -123.456 ) ;
263279 assert_eq ! ( func_typed( f64 :: MAX ) , f64 :: MAX ) ;
@@ -309,7 +325,10 @@ fn test_multiple_allocations_execution() {
309325 let param_b = func. create_value ( HirType :: I32 , HirValueKind :: Parameter ( 1 ) ) ;
310326
311327 // Alloca for a
312- let ptr_a = func. create_value ( HirType :: Ptr ( Box :: new ( HirType :: I32 ) ) , HirValueKind :: Instruction ) ;
328+ let ptr_a = func. create_value (
329+ HirType :: Ptr ( Box :: new ( HirType :: I32 ) ) ,
330+ HirValueKind :: Instruction ,
331+ ) ;
313332 let alloca_a = HirInstruction :: Alloca {
314333 result : ptr_a,
315334 ty : HirType :: I32 ,
@@ -318,7 +337,10 @@ fn test_multiple_allocations_execution() {
318337 } ;
319338
320339 // Alloca for b
321- let ptr_b = func. create_value ( HirType :: Ptr ( Box :: new ( HirType :: I32 ) ) , HirValueKind :: Instruction ) ;
340+ let ptr_b = func. create_value (
341+ HirType :: Ptr ( Box :: new ( HirType :: I32 ) ) ,
342+ HirValueKind :: Instruction ,
343+ ) ;
322344 let alloca_b = HirInstruction :: Alloca {
323345 result : ptr_b,
324346 ty : HirType :: I32 ,
@@ -431,7 +453,10 @@ fn test_memory_update_execution() {
431453 let param_x = func. create_value ( HirType :: I32 , HirValueKind :: Parameter ( 0 ) ) ;
432454
433455 // Alloca i32
434- let ptr = func. create_value ( HirType :: Ptr ( Box :: new ( HirType :: I32 ) ) , HirValueKind :: Instruction ) ;
456+ let ptr = func. create_value (
457+ HirType :: Ptr ( Box :: new ( HirType :: I32 ) ) ,
458+ HirValueKind :: Instruction ,
459+ ) ;
435460 let alloca = HirInstruction :: Alloca {
436461 result : ptr,
437462 ty : HirType :: I32 ,
@@ -493,7 +518,9 @@ fn test_memory_update_execution() {
493518 block. add_instruction ( add) ;
494519 block. add_instruction ( store2) ;
495520 block. add_instruction ( load2) ;
496- block. set_terminator ( HirTerminator :: Return { values : vec ! [ result] } ) ;
521+ block. set_terminator ( HirTerminator :: Return {
522+ values : vec ! [ result] ,
523+ } ) ;
497524
498525 let ( _backend, func_ptr) = compile_and_get_ptr ( func) ;
499526 let func_ptr = func_ptr. expect ( "Failed to get function pointer" ) ;
0 commit comments