From ced6e79bcc986d049db0d216e0faa554553345e9 Mon Sep 17 00:00:00 2001 From: Sofia Date: Fri, 20 Mar 2026 18:04:35 +0200 Subject: [PATCH] Add block statements --- src/ast.rs | 6 ++++++ src/compile.rs | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index 27707de..d7b2be6 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -279,6 +279,7 @@ pub enum Statement { Label(Node), GoTo(Node), Empty, + Block(Block), } impl Parse for Statement { @@ -455,6 +456,11 @@ impl Parse for Statement { } else if let Some(Token::Symbol(';')) = stream.peek() { stream.next(); Ok(Self::Empty) + } else if let Some(Token::Keyword(Keyword::Do)) = stream.peek() { + stream.next(); + let block = stream.parse()?; + stream.expect(Token::Keyword(Keyword::End))?; + Ok(Self::Block(block)) } else { Err(stream.expecting_err("statement")) } diff --git a/src/compile.rs b/src/compile.rs index cc14492..f5acc95 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -246,6 +246,11 @@ impl Statement { Statement::Label(_) => HashSet::new(), Statement::GoTo(_) => HashSet::new(), Statement::Empty => HashSet::new(), + Statement::Block(block) => { + let mut constants = HashSet::new(); + constants.extend(block.find_constants(scope, Vec::new())); + constants + } } } @@ -654,6 +659,10 @@ impl Statement { Statement::Label(node) => instructions.push(PreInstr::Label(node.kind.clone())), Statement::GoTo(node) => instructions.push(PreInstr::GoTo(node.kind.clone())), Statement::Empty => {} + Statement::Block(block) => { + let mut inner_scope = scope.clone(); + instructions.extend(block.compile(state, &mut inner_scope)); + } } for reg in 0..scope.register_counter.0 {