[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Switch/Case with Fallthrough
- From: Paige DePol <lual@...>
- Date: Thu, 21 Nov 2013 15:09:43 -0600
On Nov 21, 2013, at 2:52 PM, Tom N Harris <telliamed@whoopdedo.org> wrote:
> Now, if Lua had a computed goto, that would make this more interesting.
>
> What would be the roadblocks to implementing that? Each function would need a
> table of names to instruction pointers. And maybe that's all?
>
> goto [value] -- cast value to string and jump
>
> What happens with an invalid label? A runtime error, I suppose.
I think, in a way, what I am in the process of implementing is a sort of computed goto. I lookup the constant offset for the value used in the switch statement and then use a table to get a jump offset to jump to the appropriate case. This requires me to patch the constant table to ensure that all the constants used by the case statements are in sequential order though.
I don't think it would be very hard to add a computed goto to Lua, though it would require a patched Lua and would not work with the vanilla virtual machine.
~pmd~