From fba9dded4230db552fcd1a5d87b62796d8aa83c7 Mon Sep 17 00:00:00 2001 From: Goren Barak Date: Fri, 1 Dec 2023 18:55:35 -0500 Subject: [PATCH] Started implementing an operation queue. --- src/codegen/fasm.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/codegen/fasm.rs b/src/codegen/fasm.rs index 1cb96f1..69c7aa2 100644 --- a/src/codegen/fasm.rs +++ b/src/codegen/fasm.rs @@ -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 } 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());