[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Predefined labels (Inspired by discussion on: Why do we have ipairs?)
- From: Paige DePol <lual@...>
- Date: Fri, 27 Jun 2014 05:30:58 -0500
On Jun 27, 2014, at 4:41 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2014-06-27 11:27 GMT+02:00 Paige DePol <lual@serfnet.org>:
>> On Jun 27, 2014, at 4:15 AM, Sean Conner <sean@conman.org> wrote:
>>
>>> If you are serious about this, you can remove "while", "repeat", "until",
>>> "else", "break" and "for" and replace them all with just "if" and "goto".
>>
>> Indeed you *could*, however, I can't imagine why anyone would *want*
>> to do such a thing.
>>
>> In my view the whole point about adding extra loop controls (ie: continue)
>> is to make the code look cleaner and to reduce possible errors... which
>> is why I added both the `continue` keyword and the shortcut if style
>> statement to my Lua variant.
>
> Please, I was not arguing in favour of doing everything in terms of
> "if" and "goto". I was
Didn't say you were serious, I was just commenting on the "if you are serious about this" part of your previous post! ;)
> - pointing out that "break" is merely a short spelling of "goto break",
Indeed it is.
> - and that it would be possible use the same mechanism to add the
> constructions "continue", "resume" and "restart" to loops, although
> spelling them "goto continue", "goto resume" and "goto restart",
I get `continue` and `restart`, but what would `resume` do?
> - and begging for help in doing so from people that understand the
> logic of lparser.c.
You are close, the issue you have is trying to define continue in terms of where break is defined, which will not always work. You need to add the continue label in different spots for repeat/while loops for it to work correctly.
In my "jump table/if-shortcut/continue" patch[1] I changed the `breaklabel` function to `addlabel`, then created two macros `breaklabel` and `continuelabel` which use this new function. If you apply my patch and then search lparser.c for `continuelabel` you will see how I implemented the `continue` keyword for all loop types.
You could easily create a new macro for your new loop control types, then you would just need to figure out where to create the labels to achieve the effect you desire. Let me know if you need any assistance with this, I would be happy to help! :)
Thanks to this discussion I did find a small bug with my patch, the `continuelabel` macro was in the wrong spot for while loops. I have since updated the patch file so if you have an earlier version you will want to get the latest version. My new patch files also include the SVN revision number and date of release in the header to make it easier to tell when patch files are out of date and need updating.
~pmd
[1] https://github.com/FizzyPop/lua-patches/tree/master/joint-patches/jump-table%2Bif-shct%2Bcont-loop