mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-20 10:16:37 +00:00
Rework loop compilation / flows (#644)
This commit is contained in:
83
tests/compiler/loop-flow.ts
Normal file
83
tests/compiler/loop-flow.ts
Normal file
@ -0,0 +1,83 @@
|
||||
export function whileReturn(): i32 {
|
||||
while (true) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
assert(whileReturn() == 1);
|
||||
|
||||
export function whileThrow(): i32 {
|
||||
while (true) {
|
||||
throw new Error("term");
|
||||
}
|
||||
}
|
||||
|
||||
export function whileContinue(): i32 {
|
||||
while (true) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
export function whileAny(a: i32): i32 {
|
||||
while (true) {
|
||||
if (a == 1) return 1;
|
||||
else if (a == 2) throw new Error("term");
|
||||
else continue;
|
||||
}
|
||||
}
|
||||
|
||||
assert(whileAny(1) == 1);
|
||||
|
||||
export function forReturn(): i32 {
|
||||
for (;;) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
assert(forReturn() == 1);
|
||||
|
||||
export function forThrow(): i32 {
|
||||
for (;;) {
|
||||
throw new Error("term");
|
||||
}
|
||||
}
|
||||
|
||||
export function forContinue(): i32 {
|
||||
for (;;) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
export function forAny(a: i32): i32 {
|
||||
for (;;) {
|
||||
if (a == 1) return 1;
|
||||
else if (a == 2) throw new Error("term");
|
||||
else continue;
|
||||
}
|
||||
}
|
||||
|
||||
assert(forAny(1) == 1);
|
||||
|
||||
export function doReturn(): i32 {
|
||||
do {
|
||||
return 1;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
assert(doReturn() == 1);
|
||||
|
||||
export function doThrow(): i32 {
|
||||
do {
|
||||
throw new Error("term");
|
||||
} while (true);
|
||||
}
|
||||
|
||||
export function doAny(a: i32): i32 {
|
||||
do {
|
||||
if (a == 1) return 1;
|
||||
else if (a == 2) throw new Error("term");
|
||||
else continue;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
assert(doAny(1) == 1);
|
Reference in New Issue
Block a user