Browse Source

chore: rename program -> module

modules
Garrit Franke 3 years ago
parent
commit
87607e4c4c
  1. 2
      src/command/build.rs
  2. 2
      src/generator/c.rs
  3. 2
      src/generator/js.rs
  4. 6
      src/generator/llvm.rs
  5. 4
      src/generator/mod.rs
  6. 8
      src/generator/x86.rs
  7. 2
      src/parser/infer.rs
  8. 4
      src/parser/mod.rs
  9. 6
      src/parser/node_type.rs
  10. 4
      src/parser/parser.rs
  11. 4
      src/parser/rules.rs

2
src/command/build.rs

@ -45,7 +45,7 @@ pub fn build(in_file: &Path, out_file: &Path) -> Result<(), String> {
Ok(()) Ok(())
} }
fn build_stdlib() -> parser::node_type::Program { fn build_stdlib() -> parser::node_type::Module {
let stdlib_raw = let stdlib_raw =
Lib::get("stdio.sb").expect("Standard library not found. This should not occur."); Lib::get("stdio.sb").expect("Standard library not found. This should not occur.");
let stblib_str = let stblib_str =

2
src/generator/c.rs

@ -20,7 +20,7 @@ use crate::util::Either;
pub struct CGenerator; pub struct CGenerator;
impl Generator for CGenerator { impl Generator for CGenerator {
fn generate(prog: Program) -> String { fn generate(prog: Module) -> String {
let mut code = String::new(); let mut code = String::new();
let raw_builtins = let raw_builtins =

2
src/generator/js.rs

@ -20,7 +20,7 @@ use std::collections::HashMap;
pub struct JsGenerator; pub struct JsGenerator;
impl Generator for JsGenerator { impl Generator for JsGenerator {
fn generate(prog: Program) -> String { fn generate(prog: Module) -> String {
let mut code = String::new(); let mut code = String::new();
let raw_builtins = let raw_builtins =

6
src/generator/llvm.rs

@ -16,16 +16,16 @@
use crate::generator::Generator; use crate::generator::Generator;
use crate::parser::node_type::*; use crate::parser::node_type::*;
use inkwell::context::Context; use inkwell::context::Context;
use inkwell::module::Module; use inkwell::module;
use inkwell::types::*; use inkwell::types::*;
pub struct LLVMGenerator<'ctx> { pub struct LLVMGenerator<'ctx> {
ctx: &'ctx Context, ctx: &'ctx Context,
module: Module<'ctx>, module: module::Module<'ctx>,
} }
impl<'ctx> Generator for LLVMGenerator<'ctx> { impl<'ctx> Generator for LLVMGenerator<'ctx> {
fn generate(prog: Program) -> String { fn generate(prog: Module) -> String {
let ctx = Context::create(); let ctx = Context::create();
let module = ctx.create_module("main"); let module = ctx.create_module("main");
let mut generator = LLVMGenerator { ctx: &ctx, module }; let mut generator = LLVMGenerator { ctx: &ctx, module };

4
src/generator/mod.rs

@ -26,13 +26,13 @@ mod tests;
pub mod x86; pub mod x86;
pub trait Generator { pub trait Generator {
fn generate(prog: Program) -> String; fn generate(prog: Module) -> String;
} }
// Since we're using multiple features, // Since we're using multiple features,
// "unreachable" statements are okay // "unreachable" statements are okay
#[allow(unreachable_code)] #[allow(unreachable_code)]
pub fn generate(prog: Program) -> String { pub fn generate(prog: Module) -> String {
#[cfg(feature = "backend_llvm")] #[cfg(feature = "backend_llvm")]
return llvm::LLVMGenerator::generate(prog); return llvm::LLVMGenerator::generate(prog);
#[cfg(feature = "backend_c")] #[cfg(feature = "backend_c")]

8
src/generator/x86.rs

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
use crate::generator::Generator; use crate::generator::Generator;
use crate::parser::node_type::{Function, Program, Statement}; use crate::parser::node_type::{Function, Module, Statement};
struct Assembly { struct Assembly {
asm: Vec<String>, asm: Vec<String>,
@ -45,7 +45,7 @@ impl Assembly {
pub struct X86Generator; pub struct X86Generator;
impl Generator for X86Generator { impl Generator for X86Generator {
fn generate(prog: Program) -> String { fn generate(prog: Module) -> String {
Self::new().gen_program(prog).build() Self::new().gen_program(prog).build()
} }
} }
@ -55,9 +55,9 @@ impl X86Generator {
X86Generator {} X86Generator {}
} }
fn gen_program(&mut self, prog: Program) -> Assembly { fn gen_program(&mut self, prog: Module) -> Assembly {
let mut asm = Assembly::new(); let mut asm = Assembly::new();
let Program { let Module {
func, func,
globals, globals,
structs: _, structs: _,

2
src/parser/infer.rs

@ -19,7 +19,7 @@ use super::node_type::*;
/// ///
/// TODO: Global symbol table is passed around randomly. /// TODO: Global symbol table is passed around randomly.
/// This could probably be cleaned up. /// 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(); let table = &program.get_symbol_table();
// TODO: Fix aweful nesting // TODO: Fix aweful nesting
for func in &mut program.func { for func in &mut program.func {

4
src/parser/mod.rs

@ -20,11 +20,11 @@ pub mod node_type;
mod parser; mod parser;
mod rules; mod rules;
use crate::lexer::Token; use crate::lexer::Token;
use node_type::Program; use node_type::Module;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
pub fn parse(tokens: Vec<Token>, raw: Option<String>) -> Result<Program, String> { pub fn parse(tokens: Vec<Token>, raw: Option<String>) -> Result<Module, String> {
let mut parser = parser::Parser::new(tokens, raw); let mut parser = parser::Parser::new(tokens, raw);
parser.parse() parser.parse()
} }

6
src/parser/node_type.rs

@ -21,14 +21,14 @@ use std::collections::HashMap;
pub type SymbolTable = HashMap<String, Option<Type>>; pub type SymbolTable = HashMap<String, Option<Type>>;
#[derive(Debug)] #[derive(Debug)]
pub struct Program { pub struct Module {
pub func: Vec<Function>, pub func: Vec<Function>,
pub structs: Vec<StructDef>, pub structs: Vec<StructDef>,
pub globals: Vec<String>, pub globals: Vec<String>,
} }
impl Program { impl Module {
pub fn merge_with(&mut self, mut other: Program) { pub fn merge_with(&mut self, mut other: Module) {
self.func.append(&mut other.func); self.func.append(&mut other.func);
self.globals.append(&mut other.globals) self.globals.append(&mut other.globals)
} }

4
src/parser/parser.rs

@ -46,8 +46,8 @@ impl Parser {
} }
} }
pub fn parse(&mut self) -> Result<Program, String> { pub fn parse(&mut self) -> Result<Module, String> {
let mut program = self.parse_program()?; let mut program = self.parse_module()?;
// infer types // infer types
infer(&mut program); infer(&mut program);

4
src/parser/rules.rs

@ -22,7 +22,7 @@ use std::collections::HashMap;
use std::convert::TryFrom; use std::convert::TryFrom;
impl Parser { impl Parser {
pub fn parse_program(&mut self) -> Result<Program, String> { pub fn parse_module(&mut self) -> Result<Module, String> {
let mut functions = Vec::new(); let mut functions = Vec::new();
let mut structs = Vec::new(); let mut structs = Vec::new();
let globals = Vec::new(); let globals = Vec::new();
@ -38,7 +38,7 @@ impl Parser {
} }
} }
Ok(Program { Ok(Module {
func: functions, func: functions,
structs, structs,
globals, globals,

Loading…
Cancel
Save