[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [PATCH] Jump Tables for Switch/Case and Computed Goto
- From: Paige DePol <lual@...>
- Date: Tue, 6 May 2014 02:04:04 -0500
On May 6, 2014, at 12:58 AM, Karel Tuma <kat@lua.cz> wrote:
> Excerpts from Paige DePol's message of 2014-05-06 07:21:47 +0200:
>> What? I have no idea what you mean by that? It is not something I said.
>> Essentially I did make addressable identifiers, that can be any constant value.
>
> In 1.5k LOC patch. All I am saying it might be worth it to think about
> in terms of doing more in less.
I have added an entirely new feature to Lua, while adhering to the same coding style as the original source. I believe I have done so in as many lines as were required, with as little waste as possible. If you can make the code smaller and/or better please share the patch, I am always looking for opportunities to learn!
>
>> You can jump when there is a sub-scope. You can jump over it, just not into it.
>> Why would we need to do that, we know at compile time if all jumpto statements can reach all jump points without violating local scope.
>
> I suppose code will explain better:
>
> -- no jumping to outside scope
> do
> local x = 1
> do
> jumpto x -- should jump to 1 ...
> :|2|: -- to satisfy static scoping check
> end
> :|1|:
> os.exit()
> jumpto x -- to satisfy static scoping check
> end
> -- lua equivalent:
> -- jumping to outside scope
> do
> do
> goto out
> end
> ::out::
> end
>
>
> -- no jumping into scope of local variable
> do
> local x = 1
> jumpto x
> :|1|:
>
> local b = 2
> :|2|:
> jumpto b
> end
>
> -- no lua equivalent because lua uses static check
> -- too (but for static gotos)
>
> Doing dynamic gotos with static scoping is rather um ... unorthodox.
> Common usage is to err ... jump to outside scope I guess?
>
>> Thank you for your feedback, though I have to be honest, I did not understand half of it! :(
>
> No worries, thats what they call code talks, bullshit walks.
The code examples you gave are essentially comparing `goto` with `jumpto`, and while they both achieve a similar goal they do so quite differently.
The `goto` statement requires you to know the label you wish to jump to at compile time, while the `jumpto` statement resolves the jump destination at run time using a jump table.
http://en.wikipedia.org/wiki/Goto#Computed_GOTO
That is what I have implemented, albeit currently with a restriction to the block scope. Remember though, this is only version 1 of the patch, and the initial goal was simply switch/case, computed goto syntax was a nice bonus! :)
~pmd~