From 1706698ffaee4cf78210094506593f01685c103d Mon Sep 17 00:00:00 2001 From: Devin Bidwell Date: Sat, 22 Nov 2025 20:53:49 -0700 Subject: [PATCH] basic support for return values --- .../test/declaration_function_invocation.rs | 37 +++++++++++++++++++ libs/compiler/src/v2.rs | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/libs/compiler/src/test/declaration_function_invocation.rs b/libs/compiler/src/test/declaration_function_invocation.rs index 02302a1..8be25cb 100644 --- a/libs/compiler/src/test/declaration_function_invocation.rs +++ b/libs/compiler/src/test/declaration_function_invocation.rs @@ -170,3 +170,40 @@ fn mixed_args() -> anyhow::Result<()> { 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(()) +} diff --git a/libs/compiler/src/v2.rs b/libs/compiler/src/v2.rs index 2f41ccd..19fdc15 100644 --- a/libs/compiler/src/v2.rs +++ b/libs/compiler/src/v2.rs @@ -310,7 +310,7 @@ impl<'a, W: std::io::Write> Compiler<'a, W> { self.write_output(format!( "move r{} r{reg} {}", VariableScope::RETURN_REGISTER, - debug!(self, "returnValue") + debug!(self, "#returnValue") ))?; } VariableLocation::Stack(offset) => {