Added once blocks

This commit is contained in:
2024-05-11 01:24:41 -05:00
parent f19736cb8a
commit 3b7ce3eb26
12 changed files with 132 additions and 28 deletions
+21
View File
@@ -231,6 +231,27 @@ fn static2_test() {
);
}
#[test]
fn once_test() {
// A once block.
// We pass a pointer in, it increments the var, but only the first time.
let src = "
fn foo(n) {
once {
*n = *n + 1;
}
}
fn main() {
var n = 0;
foo(&n); foo(&n); foo(&n);
return n;
}";
assert_eq!(
main_return(src),
1
);
}
//#[test]
// This is no longer cursed, or a test. The revised calling convention with the pool pointer makes
// it now perfectly sane. Left here for posterity.