Add README.md

This commit is contained in:
2025-11-22 17:54:06 -07:00
parent 4703f9d24a
commit fd9964ea5a
5 changed files with 129 additions and 14 deletions

View File

@@ -88,3 +88,85 @@ fn incorrect_args_count() -> anyhow::Result<()> {
Ok(())
}
#[test]
fn inline_literal_args() -> anyhow::Result<()> {
let compiled = compile! {
debug
"
fn doSomething(arg1, arg2) {};
let thisVariableShouldStayInPlace = 123;
let returnedValue = doSomething(12, 34);
"
};
assert_eq!(
compiled,
indoc! {
"
j main
doSomething:
pop r8 #arg2
pop r9 #arg1
push ra
sub r0 sp 1
get ra db r0
sub sp sp 1
j ra
main:
move r8 123 #thisVariableShouldStayInPlace
push r8
push 12
push 34
jal doSomething
sub r0 sp 1
get r8 db r0
sub sp sp 1
move r9 r15 #returnedValue
"
}
);
Ok(())
}
#[test]
fn mixed_args() -> anyhow::Result<()> {
let compiled = compile! {
debug
"
let arg1 = 123;
let returnValue = doSomething(arg1, 456);
fn doSomething(arg1, arg2) {};
"
};
assert_eq!(
compiled,
indoc! {
"
j main
doSomething:
pop r8 #arg2
pop r9 #arg1
push ra
sub r0 sp 1
get ra db r0
sub sp sp 1
j ra
main:
move r8 123 #arg1
push r8
push r8
push 456
jal doSomething
sub r0 sp 1
get r8 db r0
sub sp sp 1
move r9 r15 #returnValue
"
}
);
Ok(())
}

View File

@@ -25,7 +25,9 @@ fn variable_declaration_numeric_literal() -> anyhow::Result<()> {
#[test]
fn variable_declaration_numeric_literal_stack_spillover() -> anyhow::Result<()> {
let compiled = compile! {debug r#"
let compiled = compile! {
debug
r#"
let a = 0;
let b = 1;
let c = 2;

View File

@@ -53,6 +53,7 @@ quick_error! {
}
#[derive(Default)]
#[repr(C)]
pub struct CompilerConfig {
pub debug: bool,
}