Fixed issue with macro (basically I wrote false when I needed to write true and vice versa)

This commit is contained in:
Goren Barak 2023-11-23 22:01:38 -05:00
parent 1a6089b2a9
commit 325ae07f1c
2 changed files with 35 additions and 33 deletions

View file

@ -1,13 +1,14 @@
use crate::parse::ast::*; use crate::parse::ast::*;
#[macro_export]
macro_rules! fasm_codegen { macro_rules! fasm_codegen {
// Macro to make calling fasm_codegen function easier.
($exprs:expr) => { ($exprs:expr) => {
fasm_codegen($exprs, false) fasm_codegen(&$exprs, true)
}; };
(function: $exprs:expr) => { (function: $exprs:expr) => {
fasm_codegen($exprs, true) fasm_codegen($exprs, false)
} }
} }
@ -177,5 +178,6 @@ pub fn fasm_codegen(exprs: &Vec<Expr>, not_a_function: bool) -> String {
// Get the final `asm` string derived from all of the other strings that we have manipulated (finally!). // 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); let asm = format!("{}{}{}", asm_start, asm_func, asm_data);
// Return the final `asm` string. // Return the final `asm` string.
asm asm
} }

View file

@ -7,37 +7,37 @@ use crate::parse::ast::*;
pub mod parse; pub mod parse;
fn main() { fn main() {
let fc = fasm_codegen(& let fc = fasm_codegen!(
vec![ vec![
Expr::VarDefinition(VarDefinition {name: "goren", value: Value::Number(10)}), Expr::VarDefinition(VarDefinition {name: "goren", value: Value::Number(10)}),
Expr::MathExpr(Math { Expr::MathExpr(Math {
left: &Value::Var(VarReference { name: "goren"}), left: &Value::Var(VarReference { name: "goren"}),
right: &Value::Number(17), right: &Value::Number(17),
operator: MathOperator::OP_MULT operator: MathOperator::OP_MULT
} }
), ),
Expr::FunDefinition(FunDefinition { Expr::FunDefinition(FunDefinition {
name: "adder", contents: vec![ name: "adder", contents: vec![
Expr::MathExpr( Expr::MathExpr(
Math { Math {
left: &Value::Param(ParamReference {param_number: 0}), left: &Value::Param(ParamReference {param_number: 0}),
right: &Value::Param(ParamReference {param_number: 1}), right: &Value::Param(ParamReference {param_number: 1}),
operator: MathOperator::OP_ADD operator: MathOperator::OP_ADD
} }
) )
] ]
}), }),
Expr::FunCall( Expr::FunCall(
FunCall { FunCall {
name: "adder", name: "adder",
params: vec![Value::Var(VarReference {name: "goren"}), Value::Number(6)] params: vec![Value::Var(VarReference {name: "goren"}), Value::Number(6)]
} }
), ),
Expr::Breakpoint Expr::Breakpoint
], ]
true
); );
println!("{}", fc); println!("{}", fc);
} }