lua-users home
lua-l archive

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


if op == OP_TAILCALL then
   ...
   goto fallsto_call;
elseif op == OP_CALL then
  fallsto_call:
   ...
end

Yes it's better (the compiler will manage itself to reorganize the jumps to implement fallsthrough it it wishes, depending on how it compiles the conditional jumps for if/elseif-tests which may contain "and/or" expressions that also frequently generate branches if there's no simple bitmasking expressions to reduce them without branches), just like it can swap branches if it helps it to use short relative jumps in less instructions, depending also on branch prediction (if the compiler has profiling data).

But for the source language, I still think that a switch is still simpler to read, even with a "fallthrough" comment (or directive for linters).

switch (op)
case OP_TAILCALL:
   ...
   // fallthru
case OP_CALL:
   ...
  break
end

And if we have a switch without break (all branches are breaking implicity, then yes we need a goto or a fallthru statement (not just a directive for linters or comment for programmers). Most programmers are aware of the syntax of switches, and they are usually cleander, faster to type; the only caveat is that fallthrough are traps which do not allow easy refactoring (e.g. adding cases, commenting out some of them: so an explicit fallthru statement is certainly better if it is labelled.

Le lun. 23 déc. 2019 à 20:51, Egor Skriptunoff <egor.skriptunoff@gmail.com> a écrit :
On Mon, Dec 23, 2019 at 5:30 PM Soni "They/Them" L. wrote:
if op == OP_TAILCALL then
   ...
   -- fallthrough
orif op == OP_CALL then
   ...
end

because it looks nicer this way I guess.



The meaning of "orif" keyword is not intuitive-clear to a reader.
I would prefer to use explicit "goto" in case I need to implement fallthrough.