lua-users home
lua-l archive

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

On Thu, Jun 16, 2011 at 11:58 AM, Edgar Toernig <> wrote:
> In my experience, it helps reading and understanding code if the
> jump-statement gives a hint about the direction the jump takes,
> forward or backward.

Mike Pall's dynasm does that [1].  Labels are numeric (1: to 9:) and
can be reused.  Forward (>) or backward (<) modifiers in the jump
opcodes disambiguate.  When I first saw this syntax, it's purpose
wasn't immediately obvious to me.

An explicit forward/backward modifier in Lua goto would resolve the
lookup ambiguity I discussed in [2], but that can also be resolved
just by wrapping each for loop in a do/end block.  Moreover, I'm not
sure the added noise is worth it.  We don't have forward/backward
direction modifiers in function calls either:

   function f() >g() end; function g() <f() end

If all gotos to a label are only above or below it, then you can name
the label in a way that will indicate the jump direction (which will
be obvious *both* on reading the goto or the label):

  @ redo for x=1,10 do for y=1,10 do
    if not f(x,y) then goto skip end
    if not g(x,y) then goto redo end
  end end @ skip