From 87a8eac61b005ffb8a0673c376d2544935ffd26f Mon Sep 17 00:00:00 2001 From: sofia Date: Thu, 24 Jul 2025 01:48:25 +0300 Subject: [PATCH] Fix for loops causing issues together --- examples/for_loops.reid | 6 ++++-- reid/src/ast/process.rs | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/examples/for_loops.reid b/examples/for_loops.reid index bac6d85..979194f 100644 --- a/examples/for_loops.reid +++ b/examples/for_loops.reid @@ -1,9 +1,11 @@ import std::print; +import std::from_str; + fn main() { for i in 0..1 { - print("Hello!"); + print(from_str("Hello!")); } for i in 0..1 { - print("World!"); + print(from_str("Hello!")); } } \ No newline at end of file diff --git a/reid/src/ast/process.rs b/reid/src/ast/process.rs index 355d323..8b19356 100644 --- a/reid/src/ast/process.rs +++ b/reid/src/ast/process.rs @@ -158,7 +158,6 @@ impl ast::Block { StmtKind::Let(counter_var.clone(), true, start.process(module_id)), counter_range.as_meta(module_id), ); - mir_statements.push(let_statement); let set_new = mir::Statement( StmtKind::Set( @@ -187,7 +186,7 @@ impl ast::Block { ); let mut block = block.into_mir(module_id); block.statements.push(set_new); - ( + let while_statement = mir::Statement( StmtKind::While(WhileStatement { condition: mir::Expression( mir::ExprKind::BinOp( @@ -203,8 +202,18 @@ impl ast::Block { block, meta: self.2.as_meta(module_id), }), - self.2, - ) + self.2.as_meta(module_id), + ); + + let inner_scope = StmtKind::Expression(mir::Expression( + mir::ExprKind::Block(mir::Block { + statements: vec![let_statement, while_statement], + return_expression: None, + meta: counter_range.as_meta(module_id) + end.1.as_meta(module_id), + }), + counter_range.as_meta(module_id) + end.1.as_meta(module_id), + )); + (inner_scope, self.2) } ast::BlockLevelStatement::WhileLoop(expression, block) => ( StmtKind::While(WhileStatement {