basic support for return values

This commit is contained in:
2025-11-22 20:53:49 -07:00
parent 4f837ee974
commit 1706698ffa
2 changed files with 38 additions and 1 deletions

View File

@@ -170,3 +170,40 @@ fn mixed_args() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[test]
fn with_return_statement() -> anyhow::Result<()> {
let compiled = compile! {
debug
"
fn doSomething(arg1) {
return 456;
};
let returned = doSomething(123);
"
};
assert_eq!(
compiled,
indoc! {
"
j main
doSomething:
pop r8 #arg1
push ra
move r15 456
sub r0 sp 1
get ra db r0
sub sp sp 1
j ra
main:
push 123
jal doSomething
move r8 r15 #returned
"
}
);
Ok(())
}

View File

@@ -310,7 +310,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
self.write_output(format!( self.write_output(format!(
"move r{} r{reg} {}", "move r{} r{reg} {}",
VariableScope::RETURN_REGISTER, VariableScope::RETURN_REGISTER,
debug!(self, "returnValue") debug!(self, "#returnValue")
))?; ))?;
} }
VariableLocation::Stack(offset) => { VariableLocation::Stack(offset) => {