Yuescript
Yuescript copied to clipboard
Refactor continue with gotos
trafficstars
YueScript currently emulates continue with a combination of if check and repeat. I propose refactoring the generated code with goto. This might save us from if checks and repeat loop.
Yue input:
numbers = { 1, 3, 5, 7, 9 }
for number in *numbers
if number > 3
continue
print number
current output:
local numbers = {
1,
3,
5,
7,
9
}
for _index_0 = 1, #numbers do
local number = numbers[_index_0]
local _continue_0 = false
repeat
if number <= 3 then
_continue_0 = true
break
end
print(number)
_continue_0 = true
until true
if not _continue_0 then
break
end
end
same logic with goto:
local numbers = {
1,
3,
5,
7,
9
}
for _index_0 = 1, #numbers do
local number = numbers[_index_0]
if number <= 3 then
goto _continue_0
end
print(number)
::_continue_0::
end
It makes sense to generate more cleaner codes. The problem is goto statement is only added since Lua 5.2. So we will need an extra Lua compatible option to generate different code for different Lua versions.
The lua compatibility option has been added.
And Lua version independent implementation for continue key word is now refactored.