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());