minor code changes for codegen
This commit is contained in:
@@ -20,8 +20,6 @@ int greater(int a, int b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printnum(greater(5, add_(5, 5)));
|
printnum(-5);
|
||||||
|
|
||||||
printnum(factorial(5));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use std::sync::atomic::AtomicU32;
|
use std::sync::atomic::AtomicU32;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
|
||||||
|
|
||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
|
|
||||||
@@ -24,10 +24,7 @@ pub struct CodeGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GLOBAL_METHODS: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
|
static GLOBAL_METHODS: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
|
||||||
hash_map! {
|
HashMap::from([("print", "print::print"), ("printnum", "print::print_num")])
|
||||||
"print" => "print::print",
|
|
||||||
"printnum" => "print::print_num"
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
fn import(name: &str, path: &str) -> String {
|
fn import(name: &str, path: &str) -> String {
|
||||||
@@ -183,7 +180,7 @@ impl CodeGenerator {
|
|||||||
for (i, param) in params.iter().enumerate() {
|
for (i, param) in params.iter().enumerate() {
|
||||||
let offset = 8 + (i as i32 * 4); // Parameters start at bpr+8
|
let offset = 8 + (i as i32 * 4); // Parameters start at bpr+8
|
||||||
// Track that this parameter is at a stack location
|
// 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.extend(load_code);
|
||||||
code.push(format!("\tldw bpr, {}, {}", reg, offset));
|
code.push(format!("\tldw bpr, {}, {}", reg, offset));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#![feature(hash_map_macro)]
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::{codegen::CodeGenerator, lexer::Lexer, parser::Parser};
|
use crate::{codegen::CodeGenerator, lexer::Lexer, parser::Parser};
|
||||||
|
|||||||
Reference in New Issue
Block a user