Added support for syscalls with assignment expressions

This commit is contained in:
2025-12-09 23:57:19 -07:00
parent b21d6cc73e
commit 0fde11a2bf
2 changed files with 23 additions and 5 deletions

View File

@@ -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(())
}

View File

@@ -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)) =>
{