Added support for syscalls with assignment expressions
This commit is contained in:
@@ -243,18 +243,28 @@ fn test_max() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
fn test_max_from_game() -> Result<()> {
|
fn test_max_from_game() -> Result<()> {
|
||||||
let compiled = compile! {
|
let compiled = compile! {
|
||||||
result
|
debug
|
||||||
r#"
|
r#"
|
||||||
let item = 0;
|
let item = 0;
|
||||||
item = max(1, 2);
|
item = max(1, 2);
|
||||||
"#
|
"#
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{compiled:?}");
|
assert_eq!(
|
||||||
assert!(compiled.is_empty());
|
compiled,
|
||||||
|
indoc! {
|
||||||
|
"
|
||||||
|
j main
|
||||||
|
main:
|
||||||
|
move r8 0 #item
|
||||||
|
max r15 1 2
|
||||||
|
move r8 r15 #item
|
||||||
|
"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,7 +295,6 @@ impl<'a> Parser<'a> {
|
|||||||
self,
|
self,
|
||||||
TokenType::Symbol(s) if s.is_operator() || s.is_comparison() || s.is_logical() || matches!(s, Symbol::Assign)
|
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)?));
|
return Ok(Some(self.infix(lhs)?));
|
||||||
} else if self_matches_current!(
|
} else if self_matches_current!(
|
||||||
self,
|
self,
|
||||||
@@ -646,6 +645,15 @@ impl<'a> Parser<'a> {
|
|||||||
.node
|
.node
|
||||||
.ok_or(Error::UnexpectedEOF)?,
|
.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(_)
|
TokenType::Identifier(_)
|
||||||
if self_matches_peek!(self, TokenType::Symbol(Symbol::LParen)) =>
|
if self_matches_peek!(self, TokenType::Symbol(Symbol::LParen)) =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user