diff --git a/src/codegen/fasm.rs b/src/codegen/fasm.rs index 03f8839..a89cb11 100644 --- a/src/codegen/fasm.rs +++ b/src/codegen/fasm.rs @@ -1,13 +1,14 @@ use crate::parse::ast::*; - +#[macro_export] macro_rules! fasm_codegen { + // Macro to make calling fasm_codegen function easier. ($exprs:expr) => { - fasm_codegen($exprs, false) + fasm_codegen(&$exprs, true) }; (function: $exprs:expr) => { - fasm_codegen($exprs, true) + fasm_codegen($exprs, false) } } @@ -177,5 +178,6 @@ pub fn fasm_codegen(exprs: &Vec, not_a_function: bool) -> String { // Get the final `asm` string derived from all of the other strings that we have manipulated (finally!). let asm = format!("{}{}{}", asm_start, asm_func, asm_data); // Return the final `asm` string. + asm } diff --git a/src/main.rs b/src/main.rs index 36dd435..41153fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,37 +7,37 @@ use crate::parse::ast::*; pub mod parse; fn main() { - let fc = fasm_codegen(& - vec![ - Expr::VarDefinition(VarDefinition {name: "goren", value: Value::Number(10)}), - Expr::MathExpr(Math { - left: &Value::Var(VarReference { name: "goren"}), - right: &Value::Number(17), - operator: MathOperator::OP_MULT - } - ), - Expr::FunDefinition(FunDefinition { - name: "adder", contents: vec![ - Expr::MathExpr( - Math { - left: &Value::Param(ParamReference {param_number: 0}), - right: &Value::Param(ParamReference {param_number: 1}), - operator: MathOperator::OP_ADD - } - ) - ] - }), + let fc = fasm_codegen!( + vec![ + Expr::VarDefinition(VarDefinition {name: "goren", value: Value::Number(10)}), + Expr::MathExpr(Math { + left: &Value::Var(VarReference { name: "goren"}), + right: &Value::Number(17), + operator: MathOperator::OP_MULT + } + ), + Expr::FunDefinition(FunDefinition { + name: "adder", contents: vec![ + Expr::MathExpr( + Math { + left: &Value::Param(ParamReference {param_number: 0}), + right: &Value::Param(ParamReference {param_number: 1}), + operator: MathOperator::OP_ADD + } + ) + ] + }), - Expr::FunCall( - FunCall { - name: "adder", - params: vec![Value::Var(VarReference {name: "goren"}), Value::Number(6)] - } - ), - - Expr::Breakpoint - ], - true + Expr::FunCall( + FunCall { + name: "adder", + params: vec![Value::Var(VarReference {name: "goren"}), Value::Number(6)] + } + ), + + Expr::Breakpoint + ] ); + println!("{}", fc); }