Fixed exponent expression not being in right-first order of operations

This commit is contained in:
2025-11-17 21:20:32 -07:00
parent f0a3bbe739
commit 5a78e25469
7 changed files with 297 additions and 8 deletions

View File

@@ -0,0 +1,67 @@
use super::v2::Compiler;
use crate::v2::CompilerConfig;
use indoc::indoc;
use parser::Parser;
use std::io::BufWriter;
use tokenizer::Tokenizer;
macro_rules! output {
($input:expr) => {
String::from_utf8($input.into_inner()?)?
};
}
macro_rules! compile {
($source:expr) => {{
let mut writer = BufWriter::new(Vec::new());
let compiler = Compiler::new(
Parser::new(Tokenizer::from(String::from($source))),
&mut writer,
None,
);
compiler.compile()?;
output!(writer)
}};
(debug $source:expr) => {{
let mut writer = BufWriter::new(Vec::new());
let compiler = Compiler::new(
Parser::new(Tokenizer::from(String::from($source))),
&mut writer,
Some(CompilerConfig {
debug: true,
..Default::default()
}),
);
compiler.compile()?;
output!(writer)
}};
}
#[test]
fn test_function_declaration_with_register_params() -> anyhow::Result<()> {
let compiled = compile!(debug r#"
// This is a test function declaration with no body
fn doSomething(arg1, arg2) {
};
"#);
assert_eq!(
compiled,
indoc! {"
j main
doSomething:
push ra
push r4
move r4 r0 #arg1
push r5
move r5 r1 #arg2
pop r5
pop r4
pop ra
j ra
"}
);
Ok(())
}