diff --git a/c_compiler/example.dsc b/c_compiler/example.dsc index 1582321..232535d 100644 --- a/c_compiler/example.dsc +++ b/c_compiler/example.dsc @@ -20,8 +20,6 @@ int greater(int a, int b) { } int main() { - printnum(greater(5, add_(5, 5))); - - printnum(factorial(5)); + printnum(-5); return 0; } diff --git a/c_compiler/src/codegen.rs b/c_compiler/src/codegen.rs index d5bbb66..ee3a598 100644 --- a/c_compiler/src/codegen.rs +++ b/c_compiler/src/codegen.rs @@ -1,8 +1,8 @@ +use std::collections::HashMap; use std::hash::Hash; use std::sync::LazyLock; use std::sync::atomic::AtomicU32; use std::time::SystemTime; -use std::{collections::HashMap, path::PathBuf}; use chrono::{DateTime, Local}; @@ -24,10 +24,7 @@ pub struct CodeGenerator { } static GLOBAL_METHODS: LazyLock> = LazyLock::new(|| { - hash_map! { - "print" => "print::print", - "printnum" => "print::print_num" - } + HashMap::from([("print", "print::print"), ("printnum", "print::print_num")]) }); fn import(name: &str, path: &str) -> String { @@ -183,7 +180,7 @@ impl CodeGenerator { for (i, param) in params.iter().enumerate() { let offset = 8 + (i as i32 * 4); // Parameters start at bpr+8 // Track that this parameter is at a stack location - let (reg, mut load_code) = self.allocator.alloc_var(¶m.name).unwrap(); + let (reg, load_code) = self.allocator.alloc_var(¶m.name).unwrap(); code.extend(load_code); code.push(format!("\tldw bpr, {}, {}", reg, offset)); } diff --git a/c_compiler/src/main.rs b/c_compiler/src/main.rs index eae157b..06cbfed 100644 --- a/c_compiler/src/main.rs +++ b/c_compiler/src/main.rs @@ -1,5 +1,3 @@ -#![feature(hash_map_macro)] - use std::fmt; use crate::{codegen::CodeGenerator, lexer::Lexer, parser::Parser};