Soni They/Them L. <fakedme@gmail.com> wrote:
On 2018-01-28 01:58 PM, Paige DePol wrote:
I suppose one fix to the issue would be to simply disallow fallthrough and
force a break for switch constructs that have non-constant case values.
Can you use goto across elseif yet?
if x then
goto ::y::
elseif y then
::y::
end
If not, that could be an interesting syntax extension. Only across a single elseif tho.
No, and this would potentially be quite a bit harder to implement with Lua's
single pass compiler. I assume you mention this as a way of implementing a
fallthrough for non-constant case blocks.
However, in a switch/case with a mix of constant and non-constant case blocks
the constant ones would be checked first via lookup table, and if that failed
then the non-constant blocks would be checked via if/else, and if all blocks
failed the 'else' block would be executed.
Forbidding fallthrough in switch/case constructs with non-constant case blocks
would be the easiest implementation, simply because the bytecode could wind up
being out-of-order from how the source code was written and jumping into an
elseif/else block via goto is currently not supported.
However, the PC of each case or if block could be recorded at compile time
and direct OP_JMPs could be added to jump around to support fallthrough.
This would effectively give the ability to "goto" into an else block, albeit
only when compiling switch/case blocks and not via a 'goto' statement.
~Paige