diff --git a/crates/concrete_ir/src/lowering.rs b/crates/concrete_ir/src/lowering.rs index e88f9c0..3410c6b 100644 --- a/crates/concrete_ir/src/lowering.rs +++ b/crates/concrete_ir/src/lowering.rs @@ -202,7 +202,9 @@ fn lower_constant( .expect("constant should exist") }; - let value = lower_constant_expression(&info.value)?; + let value_ty = lower_type(&ctx, &info.decl.r#type, module_id)?; + + let value = lower_constant_expression(&info.value, value_ty)?; let body = ConstBody { id, name, value }; @@ -211,8 +213,31 @@ fn lower_constant( Ok(ctx) } -fn lower_constant_expression(value: &Expression) -> Result { - todo!() +fn lower_constant_expression( + expression: &Expression, + type_hint: Ty, +) -> Result { + match expression { + Expression::Value(value, _) => match value { + ValueExpr::ConstInt(int, _) => match type_hint.kind { + TyKind::Int(int_ty) => match int_ty { + int_ty @ IntTy::I32 => Ok(ConstData { + ty: Ty { + span: None, + kind: TyKind::Int(int_ty), + }, + data: ConstKind::Value(ValueTree::Leaf(ConstValue::I32( + (*int).try_into().expect("value out of range"), + ))), + }), + _ => unimplemented!(), + }, + _ => unimplemented!(), + }, + _ => unimplemented!(), + }, + _ => unimplemented!(), + } } fn lower_struct(