minor code changes for codegen

This commit is contained in:
2026-02-02 11:15:45 +00:00
parent 8f7163c459
commit 5573c5a609
3 changed files with 4 additions and 11 deletions
+1 -3
View File
@@ -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;
}
+3 -6
View File
@@ -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<HashMap<&str, &str>> = 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(&param.name).unwrap();
let (reg, load_code) = self.allocator.alloc_var(&param.name).unwrap();
code.extend(load_code);
code.push(format!("\tldw bpr, {}, {}", reg, offset));
}
-2
View File
@@ -1,5 +1,3 @@
#![feature(hash_map_macro)]
use std::fmt;
use crate::{codegen::CodeGenerator, lexer::Lexer, parser::Parser};