From 501c90283dcc27caf89ad7d20caa78e559aff487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Thu, 9 May 2024 11:28:49 -0300 Subject: [PATCH] Add lower_constant implementation --- crates/concrete_ir/src/lowering.rs | 40 +++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/crates/concrete_ir/src/lowering.rs b/crates/concrete_ir/src/lowering.rs index ce5345d..e88f9c0 100644 --- a/crates/concrete_ir/src/lowering.rs +++ b/crates/concrete_ir/src/lowering.rs @@ -17,10 +17,10 @@ use concrete_ast::{ }; use crate::{ - AdtBody, BasicBlock, BinOp, ConstData, ConstKind, ConstValue, DefId, FloatTy, FnBody, IntTy, - Local, LocalKind, LogOp, Mutability, Operand, Place, PlaceElem, ProgramBody, Rvalue, Statement, - StatementKind, SwitchTargets, Terminator, TerminatorKind, Ty, TyKind, UintTy, ValueTree, - VariantDef, + AdtBody, BasicBlock, BinOp, ConstBody, ConstData, ConstKind, ConstValue, DefId, FloatTy, + FnBody, IntTy, Local, LocalKind, LogOp, Mutability, Operand, Place, PlaceElem, ProgramBody, + Rvalue, Statement, StatementKind, SwitchTargets, Terminator, TerminatorKind, Ty, TyKind, + UintTy, ValueTree, VariantDef, }; use self::errors::LoweringError; @@ -182,8 +182,36 @@ fn lower_module(mut ctx: BuildCtx, module: &Module, id: DefId) -> Result Result { - let _ = (ctx, info, id); +fn lower_constant( + mut ctx: BuildCtx, + info: &ConstantDef, + module_id: DefId, +) -> Result { + let name = info.decl.name.name.clone(); + + let id = { + let module = ctx + .body + .modules + .get(&module_id) + .expect("module should exist"); + *module + .symbols + .constants + .get(&name) + .expect("constant should exist") + }; + + let value = lower_constant_expression(&info.value)?; + + let body = ConstBody { id, name, value }; + + ctx.body.constants.insert(body.id, body); + + Ok(ctx) +} + +fn lower_constant_expression(value: &Expression) -> Result { todo!() }