From eeaf8042a5fb49466cc8c15df8c84d01c1c2bb4a Mon Sep 17 00:00:00 2001 From: flameyosflow Date: Tue, 16 Dec 2025 00:15:13 +0200 Subject: [PATCH] Rename stuff --- .../declaration_transpiler.rs | 0 src/c_lowerer/mod.rs | 2 ++ .../statements_transpiler.rs | 0 src/codegen/mod.rs | 4 +-- src/codegen/transpiler.rs | 25 +++++++++---------- src/lib.rs | 1 + 6 files changed, 16 insertions(+), 16 deletions(-) rename src/{codegen => c_lowerer}/declaration_transpiler.rs (100%) create mode 100644 src/c_lowerer/mod.rs rename src/{codegen => c_lowerer}/statements_transpiler.rs (100%) diff --git a/src/codegen/declaration_transpiler.rs b/src/c_lowerer/declaration_transpiler.rs similarity index 100% rename from src/codegen/declaration_transpiler.rs rename to src/c_lowerer/declaration_transpiler.rs diff --git a/src/c_lowerer/mod.rs b/src/c_lowerer/mod.rs new file mode 100644 index 0000000..72605cf --- /dev/null +++ b/src/c_lowerer/mod.rs @@ -0,0 +1,2 @@ +pub mod declaration_transpiler; +pub mod statements_transpiler; \ No newline at end of file diff --git a/src/codegen/statements_transpiler.rs b/src/c_lowerer/statements_transpiler.rs similarity index 100% rename from src/codegen/statements_transpiler.rs rename to src/c_lowerer/statements_transpiler.rs diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 7014f92..ed9dfaf 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1,3 +1 @@ -pub mod declaration_transpiler; -pub mod statements_transpiler; -pub mod transpiler; +pub mod transpiler; \ No newline at end of file diff --git a/src/codegen/transpiler.rs b/src/codegen/transpiler.rs index 1804cfe..900959a 100644 --- a/src/codegen/transpiler.rs +++ b/src/codegen/transpiler.rs @@ -1,8 +1,8 @@ use crate::ast::*; use crate::c_ir::*; -use crate::codegen::declaration_transpiler::DeclarationTranspiler; -use crate::codegen::statements_transpiler::StatementsTranspiler; use std::collections::HashMap; +use crate::c_lowerer::declaration_transpiler::DeclarationTranspiler; +use crate::c_lowerer::statements_transpiler::StatementsTranspiler; pub struct Transpiler { structs: HashMap, @@ -24,13 +24,11 @@ impl Transpiler { } pub fn transpile_program(&mut self, nodes: &[TypedASTNode]) -> Result { - // First pass: collect declarations for node in nodes { - self.collect_declaration(node)?; + self.lower_declarations_to_c_ir(node)?; } - // Second pass: transpile function bodies - self.transpile_function_bodies(nodes)?; + self.lower_function_bodies_to_c_ir(nodes)?; // Generate C code let mut output = String::new(); @@ -39,12 +37,12 @@ impl Transpiler { output.push_str("#include \n"); output.push_str("#include \n"); output.push_str("#include \n"); - output.push_str("#include \n\n"); + output.push_str("#include \n"); // Generate struct declarations for struct_decl in self.structs.values() { output.push_str(&self.generate_struct_decl(struct_decl)); - output.push_str(";\n\n"); + output.push_str(";\n"); } // Generate function declarations (prototypes) @@ -70,7 +68,7 @@ impl Transpiler { Ok(output) } - fn collect_declaration(&mut self, node: &TypedASTNode) -> Result<(), String> { + fn lower_declarations_to_c_ir(&mut self, node: &TypedASTNode) -> Result<(), String> { match &node.kind { TypedASTNodeKind::Struct(s) => { let struct_decl = self.decl_transpiler.transpile_struct(s)?; @@ -92,14 +90,15 @@ impl Transpiler { // For externs, we might need to add function prototypes // But for now, skip as they're handled differently } - _ => { - // Other node types (traits, etc.) - handle later - } + TypedASTNodeKind::Load(_) => {} + TypedASTNodeKind::Impl(_) => {} + TypedASTNodeKind::Trait(_) => {} + TypedASTNodeKind::Use(_) => {} } Ok(()) } - fn transpile_function_bodies(&mut self, nodes: &[TypedASTNode]) -> Result<(), String> { + fn lower_function_bodies_to_c_ir(&mut self, nodes: &[TypedASTNode]) -> Result<(), String> { for node in nodes { if let TypedASTNodeKind::Function(f) = &node.kind { // Find the corresponding function declaration diff --git a/src/lib.rs b/src/lib.rs index dc1f045..8260c34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ pub const EXTENSION: &str = ".sui"; pub mod ast; pub mod c_ir; pub mod codegen; +pub mod c_lowerer; pub mod lambda_lower; pub mod lexer; pub mod monomorphize;