Started implementing an operation queue.

This commit is contained in:
Goren Barak 2023-12-01 18:55:35 -05:00
parent dd1bc0b478
commit fba9dded42

View file

@ -1,16 +1,19 @@
use std::rc::Rc;
use crate::parse::ast::*;
use skylang::temp;
const REGISTERS: [&str; 9] = ["r10", "r11", "r12", "r13", "r14", "r15", "rax", "rdi", "rsi"];
pub struct FasmCodegen {
register_counter: usize
register_counter: usize,
operation_queue: Vec<String>
}
impl FasmCodegen {
pub fn new() -> Self {
FasmCodegen {
register_counter: 0,
operation_queue: Vec::new()
}
}
@ -54,6 +57,10 @@ impl FasmCodegen {
match expr {
// If the expression is a math expression.
Expr::MathExpr(e) => {
if let Expr::MathExpr(m) = e.right.as_ref() {
let codegen = fasm_codegen!(fun: &vec![Expr::MathExpr(m.clone())]);
self.operation_queue.push(codegen);
}
unwrap!(e.left);
self.register_counter += 1;
asm_start.push_str(format!("\tmov {}, rax\n", REGISTERS[self.register_counter]).as_str());