lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Nov 20, 2013, at 3:17 PM, Sean Conner <sean@conman.org> wrote:

> It was thus said that the Great Paige DePol once stated:
> 
>> The only reason the current version of my patch cascades is because a) it
>> worked, b) is as efficient (or a bit more so when using a global) as
>> existing if/elseif/else constructs and c) supporting a jump table is not
>> possible in vanilla Lua so far as I can tell at this time! :)
>> 
>> Yes, you could use Lua itself to create a jump table using a Lua table and
>> functions, but that is not a terribly nice looking construct, 
> 
>  Who says you have to see it?  It's the compiler doing the table/function
> construction, not the programmer (or the text editor).  

My misunderstanding, I was thinking we were comparing Lua code to the code generated by the compiler.


>> and I
>> believe my jump table opcode solution would still be more efficient than a
>> Lua based construct. 
> 
>  Here I would suggest you actually profile the results.  

Yes, I would be interested in seeing what the performance vs size of bytecode differences would be.


>> Also, switch case statements are easy to understand,
>> don't produce cluttered code and is much nicer to use than a
>> table/function system, imo. :)
> 
>  Yes, but I was talking about how your langauge converts the switch
> statement internally.

Yes, my misunderstanding. My latest thoughts on the switch statement is that I will probably turn the whole switch block into a closure.

This way I can patch the constant list generated for the closure so all the case constants are in order in the constant pool with no gaps, thus making the jump table as efficient as possible. This would also then allow nested cases should someone wish to do so.

~pmd~