11use astoir_hir:: nodes:: { HIRNode , HIRNodeKind } ;
2- use astoir_mir:: { blocks:: { refer:: MIRBlockReference } , builder:: { build_float_add, build_float_div, build_float_mul, build_float_sub, build_int_add, build_int_div, build_int_mul, build_int_sub} , vals:: base:: BaseMIRValue } ;
2+ use astoir_mir:: { blocks:: refer:: MIRBlockReference , builder:: { build_float_add, build_float_div, build_float_mul, build_float_sub, build_int_add, build_int_div, build_int_mul, build_int_sub, build_shift_left , build_shift_right } , vals:: base:: BaseMIRValue } ;
33use compiler_typing:: raw:: RawType ;
44use compiler_utils:: operators:: { MathOperator , MathOperatorType } ;
5- use diagnostics:: { DiagnosticResult , builders:: make_math_operation_req_assign, unsure_panic} ;
5+ use diagnostics:: { DiagnosticResult , builders:: { make_math_operation_req_assign, make_req_type_kind } , unsure_panic} ;
66
77use crate :: { MIRLoweringContext , values:: lower_hir_value, vars:: lower_hir_variable_reference} ;
88
@@ -26,7 +26,7 @@ pub fn lower_hir_math_operation(block: MIRBlockReference, node: Box<HIRNode>, ct
2626
2727 let val = match left_val. vtype . get_generic ( & ctx. hir_ctx . type_storage ) {
2828 RawType :: Integer ( _, _) | RawType :: FixedPoint ( _, _, _) => lower_hir_math_operation_int ( left_val, right_val, operation. clone ( ) , ctx) ?,
29- RawType :: Floating ( _, _) => lower_hir_math_operation_float ( left_val, right_val, operation. clone ( ) , ctx) ?,
29+ RawType :: Floating ( _, _) => lower_hir_math_operation_float ( left_val, right_val, operation. clone ( ) , ctx, & * node ) ?,
3030
3131 _ => unsure_panic ! ( "Cannot use lower_hir_math_operator on this given value kind!" )
3232 } ;
@@ -54,12 +54,14 @@ pub fn lower_hir_math_operation_int(left: BaseMIRValue, right: BaseMIRValue, ope
5454 MathOperatorType :: Subtract => build_int_sub ( & mut ctx. mir_ctx , left, right, signed) ?,
5555 MathOperatorType :: Multiply => build_int_mul ( & mut ctx. mir_ctx , left, right, signed) ?,
5656 MathOperatorType :: Divide => build_int_div ( & mut ctx. mir_ctx , left, right, signed) ?,
57+ MathOperatorType :: ShiftLeft => build_shift_left ( & mut ctx. mir_ctx , left, right) ?,
58+ MathOperatorType :: ShiftRight => build_shift_right ( & mut ctx. mir_ctx , left, right) ?
5759 } ;
5860
5961 return Ok ( res. into ( ) ) ;
6062}
6163
62- pub fn lower_hir_math_operation_float ( left : BaseMIRValue , right : BaseMIRValue , operator : MathOperator , ctx : & mut MIRLoweringContext ) -> DiagnosticResult < BaseMIRValue > {
64+ pub fn lower_hir_math_operation_float ( left : BaseMIRValue , right : BaseMIRValue , operator : MathOperator , ctx : & mut MIRLoweringContext , node : & HIRNode ) -> DiagnosticResult < BaseMIRValue > {
6365 let left = left. as_float ( ) ?;
6466 let right = right. as_float ( ) ?;
6567
@@ -69,7 +71,9 @@ pub fn lower_hir_math_operation_float(left: BaseMIRValue, right: BaseMIRValue, o
6971 MathOperatorType :: Add => build_float_add ( & mut ctx. mir_ctx , left, right, signed) ?,
7072 MathOperatorType :: Subtract => build_float_sub ( & mut ctx. mir_ctx , left, right, signed) ?,
7173 MathOperatorType :: Multiply => build_float_mul ( & mut ctx. mir_ctx , left, right, signed) ?,
72- MathOperatorType :: Divide => build_float_div ( & mut ctx. mir_ctx , left, right, signed) ?
74+ MathOperatorType :: Divide => build_float_div ( & mut ctx. mir_ctx , left, right, signed) ?,
75+
76+ _ => return Err ( make_req_type_kind ( node, & "integer" . to_string ( ) ) . into ( ) )
7377 } ;
7478
7579 return Ok ( res. into ( ) ) ;
0 commit comments