Skip to content

Commit

Permalink
remove redundant 'do' blocks in code generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Mar 21, 2024
1 parent 80b6552 commit 4a3cc26
Show file tree
Hide file tree
Showing 54 changed files with 4,095 additions and 4,616 deletions.
18 changes: 7 additions & 11 deletions spec/outputs/5.1/attrib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ end
do
local a = f()
local b, c, d
do
local _obj_0, _obj_1 = f1()
b, c = _obj_0[1], _obj_0[2]
d = _obj_1[1]
end
local _obj_0, _obj_1 = f1()
b, c = _obj_0[1], _obj_0[2]
d = _obj_1[1]
end
do
local a, b, c, d
do
local _obj_0, _obj_1, _obj_2 = f()
a = _obj_0
b, c = _obj_1[1], _obj_1[2]
d = _obj_2[1]
end
local _obj_0, _obj_1, _obj_2 = f()
a = _obj_0
b, c = _obj_1[1], _obj_1[2]
d = _obj_2[1]
end
do
local a, b
Expand Down
22 changes: 10 additions & 12 deletions spec/outputs/5.1/loops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,18 @@ do
local _cond_0 = false
local _continue_1 = false
repeat
do
local _with_0 = tb
if _with_0 ~= nil then
_with_0.a = 1
if _with_0.b then
_cond_0 = true
_continue_1 = true
local _with_0 = tb
if _with_0 ~= nil then
_with_0.a = 1
if _with_0.b then
_cond_0 = true
_continue_1 = true
break
end
do
if _with_0.c then
break
end
do
if _with_0.c then
break
end
end
end
end
_cond_0 = true
Expand Down
40 changes: 23 additions & 17 deletions spec/outputs/ambiguous.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ a, b = c, d;
(d(a))(c)
for i = 1, 10 do
a = function() end
(print)(1)
a = f;
(print)(2)
do
(print)(1)
end
a = f
do
(print)(2)
end
if cond then
(print)(3)
do
(print)(3)
end
end
::abc::;
(print)(4)
Expand All @@ -40,7 +46,9 @@ do
end)
end
do
print(123)
do
print(123)
end
end
do
f({
Expand Down Expand Up @@ -97,18 +105,16 @@ do
nums = _accum_0
end
local objects
do
local _accum_0 = { }
local _len_0 = 1
local _list_0 = items
for _index_0 = 1, #_list_0 do
local item = _list_0[_index_0]
_accum_0[_len_0] = {
name = item
}
_len_0 = _len_0 + 1
end
objects = _accum_0
local _accum_0 = { }
local _len_0 = 1
local _list_0 = items
for _index_0 = 1, #_list_0 do
local item = _list_0[_index_0]
_accum_0[_len_0] = {
name = item
}
_len_0 = _len_0 + 1
end
objects = _accum_0
end
return nil
52 changes: 19 additions & 33 deletions spec/outputs/assign.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,21 @@ return _(function()
do
local a
if x then
do
local _exp_0 = y
if 1 == _exp_0 then
do
local _obj_0, _obj_1 = f()
b[#b + 1] = _obj_1
a = _obj_0
end
end
local _exp_0 = y
if 1 == _exp_0 then
local _obj_0, _obj_1 = f()
b[#b + 1] = _obj_1
a = _obj_0
end
end
end
do
local a
local b
if x then
do
local _obj_0, _obj_1 = f()
a = _obj_0
b = _obj_1[1]
end
local _obj_0, _obj_1 = f()
a = _obj_0
b = _obj_1[1]
else
a = 123
b = tb[1]
Expand All @@ -101,33 +95,25 @@ return _(function()
do
local a, c
if x then
do
local _exp_0 = y
if 1 == _exp_0 then
do
local _obj_0, _obj_1, _obj_2, _obj_3 = f()
b[#b + 1] = _obj_1
a, c, getmetatable(d).__add = _obj_0, _obj_2, _obj_3
end
end
local _exp_0 = y
if 1 == _exp_0 then
local _obj_0, _obj_1, _obj_2, _obj_3 = f()
b[#b + 1] = _obj_1
a, c, getmetatable(d).__add = _obj_0, _obj_2, _obj_3
end
elseif x2 then
if y2 then
do
local _obj_0, _obj_1, _obj_2, _obj_3 = f1()
b[#b + 1] = _obj_1
a, c, getmetatable(d).__add = _obj_0, _obj_2, _obj_3
end
local _obj_0, _obj_1, _obj_2, _obj_3 = f1()
b[#b + 1] = _obj_1
a, c, getmetatable(d).__add = _obj_0, _obj_2, _obj_3
end
else
print("hello")
do
print(123)
do
local _obj_0, _obj_1, _obj_2 = f2()
b[#b + 1] = _obj_0
a, c, getmetatable(d).__add = 1, _obj_1, _obj_2
end
local _obj_0, _obj_1, _obj_2 = f2()
b[#b + 1] = _obj_0
a, c, getmetatable(d).__add = 1, _obj_1, _obj_2
end
end
end
Expand Down
18 changes: 7 additions & 11 deletions spec/outputs/attrib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ end
do
local a <const> = f()
local b, c, d
do
local _obj_0, _obj_1 = f1()
b, c = _obj_0[1], _obj_0[2]
d = _obj_1[1]
end
local _obj_0, _obj_1 = f1()
b, c = _obj_0[1], _obj_0[2]
d = _obj_1[1]
end
do
local a, b, c, d
do
local _obj_0, _obj_1, _obj_2 = f()
a = _obj_0
b, c = _obj_1[1], _obj_1[2]
d = _obj_2[1]
end
local _obj_0, _obj_1, _obj_2 = f()
a = _obj_0
b, c = _obj_1[1], _obj_1[2]
d = _obj_2[1]
end
do
local a, b
Expand Down
20 changes: 9 additions & 11 deletions spec/outputs/backcall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@ do
end)())
end
do
do
local _obj_0 = http
if _obj_0 ~= nil then
_obj_0.get("ajaxtest", function(data)
body[".result"]:html(data)
return http.post("ajaxprocess", data, function(processed)
body[".result"]:append(processed)
return setTimeout(1000, function()
return print("done")
end)
local _obj_0 = http
if _obj_0 ~= nil then
_obj_0.get("ajaxtest", function(data)
body[".result"]:html(data)
return http.post("ajaxprocess", data, function(processed)
body[".result"]:append(processed)
return setTimeout(1000, function()
return print("done")
end)
end)
end
end)
end
end
do
Expand Down
16 changes: 7 additions & 9 deletions spec/outputs/bubbling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ _ = function(...)
a = _accum_0
end
local b
do
local _accum_0 = { }
local _len_0 = 1
for i = 1, 10 do
_accum_0[_len_0] = function(...)
return print(...)
end
_len_0 = _len_0 + 1
local _accum_0 = { }
local _len_0 = 1
for i = 1, 10 do
_accum_0[_len_0] = function(...)
return print(...)
end
b = _accum_0
_len_0 = _len_0 + 1
end
b = _accum_0
end
44 changes: 21 additions & 23 deletions spec/outputs/class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -496,30 +496,28 @@ print("hello")
local yyy
yyy = function()
local Cool
do
local _class_0
local _base_0 = { }
if _base_0.__index == nil then
_base_0.__index = _base_0
end
_class_0 = setmetatable({
__init = function() end,
__base = _base_0,
__name = "Cool"
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({ }, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
local self = _class_0;
_ = nil
Cool = _class_0
return _class_0
local _class_0
local _base_0 = { }
if _base_0.__index == nil then
_base_0.__index = _base_0
end
_class_0 = setmetatable({
__init = function() end,
__base = _base_0,
__name = "Cool"
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({ }, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
local self = _class_0;
_ = nil
Cool = _class_0
return _class_0
end
do
local _class_0
Expand Down
Loading

0 comments on commit 4a3cc26

Please sign in to comment.