From 2e339368423d6508b73d68160ab7b3294414f76c Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Sun, 8 Mar 2026 13:16:04 -0500 Subject: [PATCH] Complete forgotten todo. --- dmc-lib/src/ir/ir_expression.rs | 5 +++-- dmc-lib/src/ir/ir_return.rs | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dmc-lib/src/ir/ir_expression.rs b/dmc-lib/src/ir/ir_expression.rs index a5d976b..a9bf074 100644 --- a/dmc-lib/src/ir/ir_expression.rs +++ b/dmc-lib/src/ir/ir_expression.rs @@ -105,7 +105,7 @@ impl IrExpression { } } - pub fn return_operand(&self) -> ReturnOperand { + pub fn return_operand(&self, constants_table: &mut ConstantsTable) -> ReturnOperand { match self { IrExpression::Parameter(ir_parameter) => { ReturnOperand::Location(Location::StackFrameOffset(ir_parameter.stack_offset())) @@ -122,7 +122,8 @@ impl IrExpression { }, IrExpression::Int(i) => ReturnOperand::Int(*i), IrExpression::String(s) => { - todo!("String constants") + let constant_name = constants_table.get_or_insert(s); + ReturnOperand::String(constant_name) } } } diff --git a/dmc-lib/src/ir/ir_return.rs b/dmc-lib/src/ir/ir_return.rs index c58eeef..907602f 100644 --- a/dmc-lib/src/ir/ir_return.rs +++ b/dmc-lib/src/ir/ir_return.rs @@ -51,9 +51,11 @@ impl VrUser for IrReturn { } impl Assemble for IrReturn { - fn assemble(&self, builder: &mut InstructionsBuilder, _constants_table: &mut ConstantsTable) { + fn assemble(&self, builder: &mut InstructionsBuilder, constants_table: &mut ConstantsTable) { if let Some(ir_expression) = self.value.as_ref() { - builder.push(Instruction::SetReturnValue(ir_expression.return_operand())); + builder.push(Instruction::SetReturnValue( + ir_expression.return_operand(constants_table), + )); } builder.push(Instruction::Return); }