-
Notifications
You must be signed in to change notification settings - Fork 701
Description
AstSemantics.md mentions that WebAssembly has two loop constructs: 'do_while', and 'forever'.
I note that there is no equivalent to 'while() { ... }'.
This may be because it is functionally equivalent [1] to
if (guard) {
do {
statements;
} while (guard);
}
Considering that there is also a 'break' expression, both can however also be expressed with just 'forever':
/* do { statements; } while (guard) */
forever {
statements;
if (!guard)
break;
}
/* while (guard) { statements; } */
forever {
if (!guard)
break;
statements;
}
I would suggest either removing 'do_while', or adding a 'while', depending on whether the design criteria favour either frugality and elegance, or ease of reading of the textual form. In the latter case, maybe there should be a construct for 'for' loops as well.
Either way, having 'do_while', but not 'while' seems inconsistent.
In case 'do_while' is eliminated, I would also suggest renaming 'forever' to just 'loop'; it is shorter, and in the presence of 'break', 'forever' is not really forever.
One could go even further, and combine 'block' and 'forever'.
Either by substituting 'block' by:
forever {
statements;
break;
}
Or, by substituting 'forever' by:
block {
statements;
continue;
}
The latter gets rid of another symmetry: right now 'break' can be used to jump to the end of a loop or block, while 'continue' can only be used to jump to the beginning of a loop (and not a block).
[1] Note however that the guard expression is duplicated here.