From 0fde11a2bf5cf508031e8f0909f7c0ed8e43fd32 Mon Sep 17 00:00:00 2001 From: Devin Bidwell Date: Tue, 9 Dec 2025 23:57:19 -0700 Subject: [PATCH] Added support for syscalls with assignment expressions --- .../libs/compiler/src/test/math_syscall.rs | 18 ++++++++++++++---- rust_compiler/libs/parser/src/lib.rs | 10 +++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/rust_compiler/libs/compiler/src/test/math_syscall.rs b/rust_compiler/libs/compiler/src/test/math_syscall.rs index 7eefafa..51ee680 100644 --- a/rust_compiler/libs/compiler/src/test/math_syscall.rs +++ b/rust_compiler/libs/compiler/src/test/math_syscall.rs @@ -243,18 +243,28 @@ fn test_max() -> Result<()> { Ok(()) } -// #[test] +#[test] fn test_max_from_game() -> Result<()> { let compiled = compile! { - result + debug r#" let item = 0; item = max(1, 2); "# }; - println!("{compiled:?}"); - assert!(compiled.is_empty()); + assert_eq!( + compiled, + indoc! { + " + j main + main: + move r8 0 #item + max r15 1 2 + move r8 r15 #item + " + } + ); Ok(()) } diff --git a/rust_compiler/libs/parser/src/lib.rs b/rust_compiler/libs/parser/src/lib.rs index 663e2fe..e07f69f 100644 --- a/rust_compiler/libs/parser/src/lib.rs +++ b/rust_compiler/libs/parser/src/lib.rs @@ -295,7 +295,6 @@ impl<'a> Parser<'a> { self, TokenType::Symbol(s) if s.is_operator() || s.is_comparison() || s.is_logical() || matches!(s, Symbol::Assign) ) { - println!("{lhs}"); return Ok(Some(self.infix(lhs)?)); } else if self_matches_current!( self, @@ -646,6 +645,15 @@ impl<'a> Parser<'a> { .node .ok_or(Error::UnexpectedEOF)?, + TokenType::Identifier(ref id) if SysCall::is_syscall(id) => { + let spanned_call = self.spanned(|p| p.syscall())?; + + Spanned { + span: spanned_call.span, + node: Expression::Syscall(spanned_call), + } + } + TokenType::Identifier(_) if self_matches_peek!(self, TokenType::Symbol(Symbol::LParen)) => {