yield and sleep

This commit is contained in:
2025-11-25 02:27:28 -07:00
parent 9bc5cac2c2
commit 68e56af987
4 changed files with 102 additions and 4 deletions

View File

@@ -111,7 +111,7 @@ fn test_while_loop() -> anyhow::Result<()> {
fn test_loop_continue() -> anyhow::Result<()> {
let compiled = compile! {
debug
"
r#"
let a = 0;
loop {
a = a + 1;
@@ -120,7 +120,7 @@ fn test_loop_continue() -> anyhow::Result<()> {
}
break;
}
"
"#
};
// Labels: L1 (start), L2 (end), L3 (if end)

View File

@@ -47,3 +47,4 @@ mod declaration_literal;
mod function_declaration;
mod logic_expression;
mod loops;
mod syscall;

View File

@@ -0,0 +1,53 @@
use crate::compile;
use indoc::indoc;
use pretty_assertions::assert_eq;
#[test]
fn test_yield_syscall() -> anyhow::Result<()> {
let compiled = compile! {
debug
"
yield();
"
};
assert_eq!(
compiled,
indoc! {
"
j main
main:
yield
"
}
);
Ok(())
}
#[test]
fn test_sleep_syscall() -> anyhow::Result<()> {
let compiled = compile! {
debug
"
sleep(3);
let sleepAmount = 15;
sleep(sleepAmount);
"
};
assert_eq!(
compiled,
indoc! {
"
j main
main:
sleep 3
move r8 15 #sleepAmount
sleep r8
"
}
);
Ok(())
}