diff --git a/src/command/build.rs b/src/command/build.rs index baea9cf..d54d6d1 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -45,7 +45,7 @@ pub fn build(in_file: &Path, out_file: &Path) -> Result<(), String> { Ok(()) } -fn build_stdlib() -> parser::node_type::Program { +fn build_stdlib() -> parser::node_type::Module { let stdlib_raw = Lib::get("stdio.sb").expect("Standard library not found. This should not occur."); let stblib_str = diff --git a/src/generator/c.rs b/src/generator/c.rs index 70097e1..2069623 100644 --- a/src/generator/c.rs +++ b/src/generator/c.rs @@ -20,7 +20,7 @@ use crate::util::Either; pub struct CGenerator; impl Generator for CGenerator { - fn generate(prog: Program) -> String { + fn generate(prog: Module) -> String { let mut code = String::new(); let raw_builtins = diff --git a/src/generator/js.rs b/src/generator/js.rs index 5c37a88..1652502 100644 --- a/src/generator/js.rs +++ b/src/generator/js.rs @@ -20,7 +20,7 @@ use std::collections::HashMap; pub struct JsGenerator; impl Generator for JsGenerator { - fn generate(prog: Program) -> String { + fn generate(prog: Module) -> String { let mut code = String::new(); let raw_builtins = diff --git a/src/generator/llvm.rs b/src/generator/llvm.rs index 8083225..cc8e743 100644 --- a/src/generator/llvm.rs +++ b/src/generator/llvm.rs @@ -16,16 +16,16 @@ use crate::generator::Generator; use crate::parser::node_type::*; use inkwell::context::Context; -use inkwell::module::Module; +use inkwell::module; use inkwell::types::*; pub struct LLVMGenerator<'ctx> { ctx: &'ctx Context, - module: Module<'ctx>, + module: module::Module<'ctx>, } impl<'ctx> Generator for LLVMGenerator<'ctx> { - fn generate(prog: Program) -> String { + fn generate(prog: Module) -> String { let ctx = Context::create(); let module = ctx.create_module("main"); let mut generator = LLVMGenerator { ctx: &ctx, module }; diff --git a/src/generator/mod.rs b/src/generator/mod.rs index e4061e1..43358ac 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -26,13 +26,13 @@ mod tests; pub mod x86; pub trait Generator { - fn generate(prog: Program) -> String; + fn generate(prog: Module) -> String; } // Since we're using multiple features, // "unreachable" statements are okay #[allow(unreachable_code)] -pub fn generate(prog: Program) -> String { +pub fn generate(prog: Module) -> String { #[cfg(feature = "backend_llvm")] return llvm::LLVMGenerator::generate(prog); #[cfg(feature = "backend_c")] diff --git a/src/generator/x86.rs b/src/generator/x86.rs index c44346c..89d7e7f 100644 --- a/src/generator/x86.rs +++ b/src/generator/x86.rs @@ -14,7 +14,7 @@ * limitations under the License. */ use crate::generator::Generator; -use crate::parser::node_type::{Function, Program, Statement}; +use crate::parser::node_type::{Function, Module, Statement}; struct Assembly { asm: Vec, @@ -45,7 +45,7 @@ impl Assembly { pub struct X86Generator; impl Generator for X86Generator { - fn generate(prog: Program) -> String { + fn generate(prog: Module) -> String { Self::new().gen_program(prog).build() } } @@ -55,9 +55,9 @@ impl X86Generator { X86Generator {} } - fn gen_program(&mut self, prog: Program) -> Assembly { + fn gen_program(&mut self, prog: Module) -> Assembly { let mut asm = Assembly::new(); - let Program { + let Module { func, globals, structs: _, diff --git a/src/parser/infer.rs b/src/parser/infer.rs index 294709c..677beb2 100644 --- a/src/parser/infer.rs +++ b/src/parser/infer.rs @@ -19,7 +19,7 @@ use super::node_type::*; /// /// TODO: Global symbol table is passed around randomly. /// This could probably be cleaned up. -pub(super) fn infer(program: &mut Program) { +pub(super) fn infer(program: &mut Module) { let table = &program.get_symbol_table(); // TODO: Fix aweful nesting for func in &mut program.func { diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 6e70a39..812411d 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -20,11 +20,11 @@ pub mod node_type; mod parser; mod rules; use crate::lexer::Token; -use node_type::Program; +use node_type::Module; #[cfg(test)] mod tests; -pub fn parse(tokens: Vec, raw: Option) -> Result { +pub fn parse(tokens: Vec, raw: Option) -> Result { let mut parser = parser::Parser::new(tokens, raw); parser.parse() } diff --git a/src/parser/node_type.rs b/src/parser/node_type.rs index 7a992e2..8f0a2c0 100644 --- a/src/parser/node_type.rs +++ b/src/parser/node_type.rs @@ -21,14 +21,14 @@ use std::collections::HashMap; pub type SymbolTable = HashMap>; #[derive(Debug)] -pub struct Program { +pub struct Module { pub func: Vec, pub structs: Vec, pub globals: Vec, } -impl Program { - pub fn merge_with(&mut self, mut other: Program) { +impl Module { + pub fn merge_with(&mut self, mut other: Module) { self.func.append(&mut other.func); self.globals.append(&mut other.globals) } diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 486ece5..622652b 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -46,8 +46,8 @@ impl Parser { } } - pub fn parse(&mut self) -> Result { - let mut program = self.parse_program()?; + pub fn parse(&mut self) -> Result { + let mut program = self.parse_module()?; // infer types infer(&mut program); diff --git a/src/parser/rules.rs b/src/parser/rules.rs index 95aeafb..6f94192 100644 --- a/src/parser/rules.rs +++ b/src/parser/rules.rs @@ -22,7 +22,7 @@ use std::collections::HashMap; use std::convert::TryFrom; impl Parser { - pub fn parse_program(&mut self) -> Result { + pub fn parse_module(&mut self) -> Result { let mut functions = Vec::new(); let mut structs = Vec::new(); let globals = Vec::new(); @@ -38,7 +38,7 @@ impl Parser { } } - Ok(Program { + Ok(Module { func: functions, structs, globals,