[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Has Lua reached perfection?
- From: Paige DePol <lual@...>
- Date: Sun, 28 Jan 2018 10:48:30 -0600
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
- References:
- Has Lua reached perfection?, Dibyendu Majumdar
- Re: Has Lua reached perfection?, Coda Highland
- Re: Has Lua reached perfection?, KHMan
- Re: Has Lua reached perfection?, Paige DePol
- Re: Has Lua reached perfection?, KHMan
- Re: Has Lua reached perfection?, Sean Conner
- Re: Has Lua reached perfection?, KHMan
- Re: Has Lua reached perfection?, Dirk Laurie
- Re: Has Lua reached perfection?, Paige DePol
- Re: Has Lua reached perfection?, Soni "They/Them" L.
- Re: Has Lua reached perfection?, Paige DePol
- Re: Has Lua reached perfection?, Soni "They/Them" L.
- Re: Has Lua reached perfection?, Paige DePol
- Re: Has Lua reached perfection?, Soni "They/Them" L.
- Re: Has Lua reached perfection?, Paige DePol
- Re: Has Lua reached perfection?, Soni "They/Them" L.
- Re: Has Lua reached perfection?, Paige DePol
- Re: Has Lua reached perfection?, Soni "They/Them" L.