From ba0aafd146c72215f6d8bf281c8541364a6f32c2 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Thu, 16 Nov 2023 15:59:01 -0700 Subject: [PATCH] Ast: trait objects on blocks --- src/ast.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index fd4f39a..de220e6 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -41,12 +41,30 @@ impl ToString for BaseType { } } -#[derive(Builder)] -pub struct Block { - statements: Vec, +#[derive(Default)] +pub struct GlobalBlock { + statements: Vec>, } -impl ToString for Block { +impl ToString for GlobalBlock { + fn to_string(&self) -> String { + let mut s = String::new(); + + for stat in &self.statements { + s.push_str(&stat.to_string()); + s.push(' '); + } + + s.push('\n'); + s + } +} + +pub struct Block { + statements: Vec>, +} + +impl ToString for Block { fn to_string(&self) -> String { let mut s = String::from("{ "); @@ -60,9 +78,9 @@ impl ToString for Block { } } -impl AstNode for Block {} +impl AstNode for Block {} -impl Statement for Block {} +impl Statement for Block {} pub enum Literal { Int(i32),