From 4a3cc26c6dfd74e61c8b6480038d6a292ea86e47 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 21 Mar 2024 09:14:34 +0800 Subject: [PATCH] remove redundant 'do' blocks in code generation. --- spec/outputs/5.1/attrib.lua | 18 +- spec/outputs/5.1/loops.lua | 22 +- spec/outputs/ambiguous.lua | 40 +- spec/outputs/assign.lua | 52 +- spec/outputs/attrib.lua | 18 +- spec/outputs/backcall.lua | 20 +- spec/outputs/bubbling.lua | 16 +- spec/outputs/class.lua | 44 +- spec/outputs/codes_from_doc.lua | 2332 ++++++++++------------ spec/outputs/codes_from_doc_zh.lua | 2332 ++++++++++------------ spec/outputs/compile_doc.lua | 40 +- spec/outputs/cond.lua | 64 +- spec/outputs/destructure.lua | 136 +- spec/outputs/funcs.lua | 38 +- spec/outputs/global.lua | 42 +- spec/outputs/import.lua | 54 +- spec/outputs/local.lua | 80 +- spec/outputs/loops.lua | 20 +- spec/outputs/macro.lua | 214 +- spec/outputs/metatable.lua | 22 +- spec/outputs/multiline_chain.lua | 14 +- spec/outputs/nil_coalescing.lua | 96 +- spec/outputs/stub.lua | 10 +- spec/outputs/switch.lua | 420 ++-- spec/outputs/syntax.lua | 14 +- spec/outputs/tables.lua | 246 ++- spec/outputs/test/format_spec.lua | 16 +- spec/outputs/unicode/ambiguous.lua | 40 +- spec/outputs/unicode/assign.lua | 86 +- spec/outputs/unicode/attrib.lua | 18 +- spec/outputs/unicode/backcall.lua | 24 +- spec/outputs/unicode/bubbling.lua | 16 +- spec/outputs/unicode/class.lua | 44 +- spec/outputs/unicode/cond.lua | 68 +- spec/outputs/unicode/destructure.lua | 136 +- spec/outputs/unicode/global.lua | 42 +- spec/outputs/unicode/import.lua | 18 +- spec/outputs/unicode/in_expression.lua | 6 +- spec/outputs/unicode/local.lua | 80 +- spec/outputs/unicode/loops.lua | 20 +- spec/outputs/unicode/macro.lua | 262 +-- spec/outputs/unicode/metatable.lua | 22 +- spec/outputs/unicode/multiline_chain.lua | 16 +- spec/outputs/unicode/nil_coalescing.lua | 96 +- spec/outputs/unicode/stub.lua | 10 +- spec/outputs/unicode/switch.lua | 366 ++-- spec/outputs/unicode/syntax.lua | 14 +- spec/outputs/unicode/tables.lua | 8 +- spec/outputs/unicode/vararg.lua | 88 +- spec/outputs/unicode/with.lua | 182 +- spec/outputs/upvalue_func.lua | 40 +- spec/outputs/vararg.lua | 88 +- spec/outputs/with.lua | 176 +- src/yuescript/yue_compiler.cpp | 325 +-- 54 files changed, 4095 insertions(+), 4616 deletions(-) diff --git a/spec/outputs/5.1/attrib.lua b/spec/outputs/5.1/attrib.lua index a9f12e3..af3f6cc 100644 --- a/spec/outputs/5.1/attrib.lua +++ b/spec/outputs/5.1/attrib.lua @@ -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 diff --git a/spec/outputs/5.1/loops.lua b/spec/outputs/5.1/loops.lua index 6f0d072..cc019e0 100644 --- a/spec/outputs/5.1/loops.lua +++ b/spec/outputs/5.1/loops.lua @@ -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 diff --git a/spec/outputs/ambiguous.lua b/spec/outputs/ambiguous.lua index 3da6f14..3c82a03 100644 --- a/spec/outputs/ambiguous.lua +++ b/spec/outputs/ambiguous.lua @@ -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) @@ -40,7 +46,9 @@ do end) end do - print(123) + do + print(123) + end end do f({ @@ -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 diff --git a/spec/outputs/assign.lua b/spec/outputs/assign.lua index 8bf7b35..61b0843 100644 --- a/spec/outputs/assign.lua +++ b/spec/outputs/assign.lua @@ -72,15 +72,11 @@ 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 @@ -88,11 +84,9 @@ return _(function() 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] @@ -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 diff --git a/spec/outputs/attrib.lua b/spec/outputs/attrib.lua index 07fc165..f6b0784 100644 --- a/spec/outputs/attrib.lua +++ b/spec/outputs/attrib.lua @@ -14,20 +14,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 diff --git a/spec/outputs/backcall.lua b/spec/outputs/backcall.lua index b065388..38e5754 100644 --- a/spec/outputs/backcall.lua +++ b/spec/outputs/backcall.lua @@ -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 diff --git a/spec/outputs/bubbling.lua b/spec/outputs/bubbling.lua index 7cb93c7..69f5f6b 100644 --- a/spec/outputs/bubbling.lua +++ b/spec/outputs/bubbling.lua @@ -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 diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua index d13b738..442ff4b 100644 --- a/spec/outputs/class.lua +++ b/spec/outputs/class.lua @@ -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 diff --git a/spec/outputs/codes_from_doc.lua b/spec/outputs/codes_from_doc.lua index 1bcc587..1f593db 100644 --- a/spec/outputs/codes_from_doc.lua +++ b/spec/outputs/codes_from_doc.lua @@ -46,13 +46,18 @@ _module_0["🌛"] = _ud83c_udf1b return _module_0 local area = 6.2831853071796 * 5 print('hello world') -assert(item ~= nil) +do + assert(item ~= nil) +end local value = item if (f1() and f2() and f3()) then print("OK") end +do + local funcA + funcA = function() end +end local funcA -funcA = function() end funcA = function() return "assign the Yue defined variable" end @@ -146,28 +151,26 @@ local b = { y = 1 } local merge -do - local _tab_0 = { } - local _idx_0 = 1 - for _key_0, _value_0 in pairs(a) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end +local _tab_0 = { } +local _idx_0 = 1 +for _key_0, _value_0 in pairs(a) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 end - local _idx_1 = 1 - for _key_0, _value_0 in pairs(b) do - if _idx_1 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_1 = _idx_1 + 1 - else - _tab_0[_key_0] = _value_0 - end +end +local _idx_1 = 1 +for _key_0, _value_0 in pairs(b) do + if _idx_1 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_1 = _idx_1 + 1 + else + _tab_0[_key_0] = _value_0 end - merge = _tab_0 end +merge = _tab_0 local mt = { } local add add = function(self, right) @@ -259,12 +262,10 @@ end if print and (x ~= nil) then print(x) end -do - local _with_0 = io.open("test.txt", "w") - if _with_0 ~= nil then - _with_0:write("hello") - _with_0:close() - end +local _with_0 = io.open("test.txt", "w") +if _with_0 ~= nil then + _with_0:write("hello") + _with_0:close() end print("hello") print(1, 2) @@ -341,10 +342,8 @@ do x, y, z = _obj_0.x, _obj_0.y, _obj_0.z end local a, b, c - do - local _obj_0 = require('module') - a, b, c = _obj_0.a, _obj_0.b, _obj_0.c - end + local _obj_0 = require('module') + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c end do local module = require('module') @@ -383,29 +382,27 @@ y = function() end _module_0["y"] = y local Something -do - local _class_0 - local _base_0 = { - umm = "cool" - } - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 +local _class_0 +local _base_0 = { + umm = "cool" +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" +}, { + __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 +Something = _class_0 _module_0["Something"] = Something return _module_0 local _module_0 = { } @@ -436,11 +433,9 @@ if this then else _module_0[#_module_0 + 1] = 456 end -do - local _with_0 = tmp - local j = 2000 - _module_0[#_module_0 + 1] = _with_0 -end +local _with_0 = tmp +local j = 2000 +_module_0[#_module_0 + 1] = _with_0 return _module_0 local _module_0 = nil _module_0 = function() @@ -577,25 +572,19 @@ for _index_0 = 1, #tuples do local left, right = _des_0[1], _des_0[2] print(left, right) end -do - local user = database.find_user("moon") - if user then - print(user.name) - end +local user = database.find_user("moon") +if user then + print(user.name) end -do - local hello = os.getenv("hello") - if hello then - print("You have hello", hello) +local hello = os.getenv("hello") +if hello then + print("You have hello", hello) +else + local world = os.getenv("world") + if world then + print("you have world", world) else - do - local world = os.getenv("world") - if world then - print("you have world", world) - else - print("nothing :(") - end - end + print("nothing :(") end end do @@ -858,40 +847,34 @@ local items = { 4 } local doubled -do - local _accum_0 = { } - local _len_0 = 1 - for i, item in ipairs(items) do - _accum_0[_len_0] = item * 2 - _len_0 = _len_0 + 1 - end - doubled = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +for i, item in ipairs(items) do + _accum_0[_len_0] = item * 2 + _len_0 = _len_0 + 1 end +doubled = _accum_0 local iter = ipairs(items) local slice -do - local _accum_0 = { } - local _len_0 = 1 - for i, item in iter do - if i > 1 and i < 3 then - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for i, item in iter do + if i > 1 and i < 3 then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end - slice = _accum_0 end +slice = _accum_0 local doubled -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] = item * 2 - _len_0 = _len_0 + 1 - end - doubled = _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] = item * 2 + _len_0 = _len_0 + 1 end +doubled = _accum_0 local x_coords = { 4, 5, @@ -904,57 +887,49 @@ local y_coords = { 3 } local points -do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #x_coords do - local x = x_coords[_index_0] - for _index_1 = 1, #y_coords do - local y = y_coords[_index_1] - _accum_0[_len_0] = { - x, - y - } - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #x_coords do + local x = x_coords[_index_0] + for _index_1 = 1, #y_coords do + local y = y_coords[_index_1] + _accum_0[_len_0] = { + x, + y + } + _len_0 = _len_0 + 1 end - points = _accum_0 end +points = _accum_0 local evens -do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 100 do - if i % 2 == 0 then - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 100 do + if i % 2 == 0 then + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 end - evens = _accum_0 end +evens = _accum_0 local thing = { color = "red", name = "fast", width = 123 } local thing_copy -do - local _tbl_0 = { } - for k, v in pairs(thing) do - _tbl_0[k] = v - end - thing_copy = _tbl_0 +local _tbl_0 = { } +for k, v in pairs(thing) do + _tbl_0[k] = v end +thing_copy = _tbl_0 local no_color -do - local _tbl_0 = { } - for k, v in pairs(thing) do - if k ~= "color" then - _tbl_0[k] = v - end +local _tbl_0 = { } +for k, v in pairs(thing) do + if k ~= "color" then + _tbl_0[k] = v end - no_color = _tbl_0 end +no_color = _tbl_0 local numbers = { 1, 2, @@ -962,14 +937,12 @@ local numbers = { 4 } local sqrts -do - local _tbl_0 = { } - for _index_0 = 1, #numbers do - local i = numbers[_index_0] - _tbl_0[i] = math.sqrt(i) - end - sqrts = _tbl_0 +local _tbl_0 = { } +for _index_0 = 1, #numbers do + local i = numbers[_index_0] + _tbl_0[i] = math.sqrt(i) end +sqrts = _tbl_0 local tuples = { { "hello", @@ -981,52 +954,44 @@ local tuples = { } } local tbl -do - local _tbl_0 = { } - for _index_0 = 1, #tuples do - local tuple = tuples[_index_0] - local _key_0, _val_0 = unpack(tuple) - _tbl_0[_key_0] = _val_0 - end - tbl = _tbl_0 +local _tbl_0 = { } +for _index_0 = 1, #tuples do + local tuple = tuples[_index_0] + local _key_0, _val_0 = unpack(tuple) + _tbl_0[_key_0] = _val_0 end +tbl = _tbl_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - local _max_0 = 5 - for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _max_0 = 5 +for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - for _index_0 = 2, #_list_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 2, #_list_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - for _index_0 = 1, #_list_0, 2 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 1, #_list_0, 2 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 for i = 10, 20 do print(i) end @@ -1036,13 +1001,11 @@ end for key, value in pairs(object) do print(key, value) end -do - local _list_0 = items - local _max_0 = 4 - for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do - local item = _list_0[_index_0] - print(item) - end +local _list_0 = items +local _max_0 = 4 +for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do + local item = _list_0[_index_0] + print(item) end local _list_0 = items for _index_0 = 1, #_list_0 do @@ -1053,19 +1016,17 @@ for j = 1, 10, 3 do print(j) end local doubled_evens -do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 20 do - if i % 2 == 0 then - _accum_0[_len_0] = i * 2 - else - _accum_0[_len_0] = i - end - _len_0 = _len_0 + 1 +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 20 do + if i % 2 == 0 then + _accum_0[_len_0] = i * 2 + else + _accum_0[_len_0] = i end - doubled_evens = _accum_0 + _len_0 = _len_0 + 1 end +doubled_evens = _accum_0 local func_a func_a = function() for i = 1, 10 do @@ -1123,20 +1084,18 @@ local my_numbers = { 6 } local odds -do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #my_numbers do - local x = my_numbers[_index_0] - if x % 2 == 1 then - goto _continue_0 - end - _accum_0[_len_0] = x - _len_0 = _len_0 + 1 - ::_continue_0:: +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #my_numbers do + local x = my_numbers[_index_0] + if x % 2 == 1 then + goto _continue_0 end - odds = _accum_0 + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + ::_continue_0:: end +odds = _accum_0 local have_coins = false if have_coins then print("Got coins") @@ -1228,15 +1187,13 @@ else next_number = error("can't count that high!") end local msg -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - msg = "you are lucky" - elseif 2 == _exp_0 then - msg = "you are almost lucky" - else - msg = "not so lucky" - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + msg = "you are lucky" +elseif 2 == _exp_0 then + msg = "you are almost lucky" +else + msg = "not so lucky" end do local _exp_0 = math.random(1, 5) @@ -1246,13 +1203,11 @@ do print("not so lucky") end end -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - print("you are lucky") - else - print("not so lucky") - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + print("you are lucky") +else + print("not so lucky") end local items = { { @@ -1266,25 +1221,23 @@ local items = { } for _index_0 = 1, #items do local item = items[_index_0] - do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local x = item.x - local y = item.y - if x ~= nil and y ~= nil then - _match_0 = true - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) - end + local _type_0 = type(item) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = item.x + local y = item.y + if x ~= nil and y ~= nil then + _match_0 = true + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end - if not _match_0 then - if _tab_0 then - local width = item.width - local height = item.height - if width ~= nil and height ~= nil then - print("size " .. tostring(width) .. ", " .. tostring(height)) - end + end + if not _match_0 then + if _tab_0 then + local width = item.width + local height = item.height + if width ~= nil and height ~= nil then + print("size " .. tostring(width) .. ", " .. tostring(height)) end end end @@ -1297,66 +1250,62 @@ end if y == nil then y = 200 end -do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - x = _obj_0.x - end - end - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - y = _obj_0.y - end - end - if x == nil then - x = 50 +local _type_0 = type(item) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + x = _obj_0.x end - if y == nil then - y = 200 + end + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + y = _obj_0.y end - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end + if x == nil then + x = 50 + end + if y == nil then + y = 200 + end + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end local Inventory -do - local _class_0 - local _base_0 = { - add_item = function(self, name) - if self.items[name] then - local _obj_0 = self.items - _obj_0[name] = _obj_0[name] + 1 - else - self.items[name] = 1 - end +local _class_0 +local _base_0 = { + add_item = function(self, name) + if self.items[name] then + local _obj_0 = self.items + _obj_0[name] = _obj_0[name] + 1 + else + self.items[name] = 1 end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 end - _class_0 = setmetatable({ - __init = function(self) - self.items = { } - end, - __base = _base_0, - __name = "Inventory" - }, { - __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 - Inventory = _class_0 +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function(self) + self.items = { } + end, + __base = _base_0, + __name = "Inventory" +}, { + __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 +Inventory = _class_0 local inv = Inventory() inv:add_item("t-shirt") inv:add_item("pants") @@ -1397,6 +1346,79 @@ for _index_0 = 1, #_list_0 do print(item) end local Person +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self) + self.clothes = { } + end, + __base = _base_0, + __name = "Person" +}, { + __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 +Person = _class_0 +local BackPack +local _class_0 +local _parent_0 = Inventory +local _base_0 = { + size = 10, + add_item = function(self, name) + if #self.items > size then + error("backpack is full") + end + return _class_0.__parent.__base.add_item(self, name) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "BackPack", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) +end +BackPack = _class_0 +local Shelf do local _class_0 local _base_0 = { } @@ -1404,11 +1426,9 @@ do _base_0.__index = _base_0 end _class_0 = setmetatable({ - __init = function(self) - self.clothes = { } - end, + __init = function() end, __base = _base_0, - __name = "Person" + __name = "Shelf" }, { __index = _base_0, __call = function(cls, ...) @@ -1418,184 +1438,105 @@ do end }) _base_0.__class = _class_0 - Person = _class_0 + local self = _class_0; + self.__inherited = function(self, child) + return print(self.__name, "was inherited by", child.__name) + end + Shelf = _class_0 end -local BackPack -do - local _class_0 - local _parent_0 = Inventory - local _base_0 = { - size = 10, - add_item = function(self, name) - if #self.items > size then - error("backpack is full") +local Cupboard +local _class_0 +local _parent_0 = Shelf +local _base_0 = { } +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Cupboard", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] end - return _class_0.__parent.__base.add_item(self, name) - end - } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 + else + return val end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "BackPack", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val - end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) - end - BackPack = _class_0 -end -local Shelf -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 = "Shelf" - }, { - __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; - self.__inherited = function(self, child) - return print(self.__name, "was inherited by", child.__name) - end - Shelf = _class_0 -end -local Cupboard -do - local _class_0 - local _parent_0 = Shelf - local _base_0 = { } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "Cupboard", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val - end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) - end - Cupboard = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +Cupboard = _class_0 local MyClass -do - local _class_0 - local _parent_0 = ParentClass - local _base_0 = { - a_method = function(self) - _class_0.__parent.__base.a_method(self, "hello", "world") - _class_0.__parent.a_method(self, "hello", "world") - _class_0.__parent.a_method(self, "hello", "world") - return assert(_class_0.__parent == ParentClass) - end - } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "MyClass", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val +local _class_0 +local _parent_0 = ParentClass +local _base_0 = { + a_method = function(self) + _class_0.__parent.__base.a_method(self, "hello", "world") + _class_0.__parent.a_method(self, "hello", "world") + _class_0.__parent.a_method(self, "hello", "world") + return assert(_class_0.__parent == ParentClass) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "MyClass", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 + else + return val end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - MyClass = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +MyClass = _class_0 local b = BackPack() assert(b.__class == BackPack) print(BackPack.size) @@ -1659,61 +1600,57 @@ Counter() print(Counter.count) self.__class:hello(1, 2, 3, 4) local Things -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "Things" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Things" - }, { - __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; - self.class_var = "hello world" - Things = _class_0 -end +}) +_base_0.__class = _class_0 +local self = _class_0; +self.class_var = "hello world" +Things = _class_0 local MoreThings -do - local _class_0 - local secret, log - local _base_0 = { - some_method = function(self) - return log("hello world: " .. secret) - end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local secret, log +local _base_0 = { + some_method = function(self) + return log("hello world: " .. secret) end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "MoreThings" - }, { - __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; - secret = 123 - log = function(msg) - return print("LOG:", msg) +} +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "MoreThings" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - MoreThings = _class_0 +}) +_base_0.__class = _class_0 +local self = _class_0; +secret = 123 +log = function(msg) + return print("LOG:", msg) end +MoreThings = _class_0 assert(self == self) assert(self.__class == self.__class) local some_instance_method @@ -1747,32 +1684,30 @@ do _base_0.__class = _class_0 Something = _class_0 end -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self, foo, bar, biz, baz) + self.foo = foo + self.bar = bar + self.__class.biz = biz + self.__class.baz = baz + end, + __base = _base_0, + __name = "Something" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function(self, foo, bar, biz, baz) - self.foo = foo - self.bar = bar - self.__class.biz = biz - self.__class.baz = baz - end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 -end +}) +_base_0.__class = _class_0 +Something = _class_0 local new new = function(self, fieldA, fieldB) self.fieldA = fieldA @@ -1783,33 +1718,31 @@ local obj = new({ }, 123, "abc") print(obj) local x local Bucket -do - local _class_0 - local _base_0 = { - drops = 0, - add_drop = function(self) - self.drops = self.drops + 1 - end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local _base_0 = { + drops = 0, + add_drop = function(self) + self.drops = self.drops + 1 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Bucket" - }, { - __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 - Bucket = _class_0 - x = _class_0 +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Bucket" +}, { + __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 +Bucket = _class_0 +x = _class_0 local BigBucket do local _class_0 @@ -1861,27 +1794,25 @@ do end assert(Bucket.__name == "BigBucket") local x -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "x" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "x" - }, { - __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 - x = _class_0 -end +}) +_base_0.__class = _class_0 +x = _class_0 local MyIndex = { __index = { var = 1 @@ -1964,19 +1895,15 @@ end local y = Y() y:func() assert(y.__class.__parent ~= X) -do - local _with_0 = Person() - _with_0.name = "Oswald" - _with_0:add_relative(my_dad) - _with_0:save() - print(_with_0.name) -end +local _with_0 = Person() +_with_0.name = "Oswald" +_with_0:add_relative(my_dad) +_with_0:save() +print(_with_0.name) local file -do - local _with_0 = File("favorite_foods.txt") - _with_0:set_encoding("utf8") - file = _with_0 -end +local _with_0 = File("favorite_foods.txt") +_with_0:set_encoding("utf8") +file = _with_0 local create_person create_person = function(name, relatives) local _with_0 = Person() @@ -1992,22 +1919,18 @@ local me = create_person("Leaf", { mother, sister }) +local str = "Hello" +print("original:", str) +print("upper:", str:upper()) +local _with_0 = tb +_with_0[1] = 1 +print(_with_0[2]) do - local str = "Hello" - print("original:", str) - print("upper:", str:upper()) -end -do - local _with_0 = tb - _with_0[1] = 1 - print(_with_0[2]) - do - local _with_1 = _with_0[abc] - _with_1[3] = _with_1[2]:func() - _with_1["key-name"] = value - end - _with_0[#_with_0 + 1] = "abc" + local _with_1 = _with_0[abc] + _with_1[3] = _with_1[2]:func() + _with_1["key-name"] = value end +_with_0[#_with_0 + 1] = "abc" do local var = "hello" print(var) @@ -2124,13 +2047,18 @@ _module_0["🌛"] = _ud83c_udf1b return _module_0 local area = 6.2831853071796 * 5 print('hello world') -assert(item ~= nil) +do + assert(item ~= nil) +end local value = item if (f1() and f2() and f3()) then print("OK") end +do + local funcA + funcA = function() end +end local funcA -funcA = function() end funcA = function() return "assign the Yue defined variable" end @@ -2224,28 +2152,26 @@ local b = { y = 1 } local merge -do - local _tab_0 = { } - local _idx_0 = 1 - for _key_0, _value_0 in pairs(a) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end +local _tab_0 = { } +local _idx_0 = 1 +for _key_0, _value_0 in pairs(a) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 end - local _idx_1 = 1 - for _key_0, _value_0 in pairs(b) do - if _idx_1 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_1 = _idx_1 + 1 - else - _tab_0[_key_0] = _value_0 - end +end +local _idx_1 = 1 +for _key_0, _value_0 in pairs(b) do + if _idx_1 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_1 = _idx_1 + 1 + else + _tab_0[_key_0] = _value_0 end - merge = _tab_0 end +merge = _tab_0 local mt = { } local add add = function(self, right) @@ -2337,12 +2263,10 @@ end if print and (x ~= nil) then print(x) end -do - local _with_0 = io.open("test.txt", "w") - if _with_0 ~= nil then - _with_0:write("hello") - _with_0:close() - end +local _with_0 = io.open("test.txt", "w") +if _with_0 ~= nil then + _with_0:write("hello") + _with_0:close() end print("hello") print(1, 2) @@ -2419,10 +2343,8 @@ do x, y, z = _obj_0.x, _obj_0.y, _obj_0.z end local a, b, c - do - local _obj_0 = require('module') - a, b, c = _obj_0.a, _obj_0.b, _obj_0.c - end + local _obj_0 = require('module') + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c end do local module = require('module') @@ -2461,29 +2383,27 @@ y = function() end _module_0["y"] = y local Something -do - local _class_0 - local _base_0 = { - umm = "cool" - } - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 +local _class_0 +local _base_0 = { + umm = "cool" +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" +}, { + __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 +Something = _class_0 _module_0["Something"] = Something return _module_0 local _module_0 = { } @@ -2514,11 +2434,9 @@ if this then else _module_0[#_module_0 + 1] = 456 end -do - local _with_0 = tmp - local j = 2000 - _module_0[#_module_0 + 1] = _with_0 -end +local _with_0 = tmp +local j = 2000 +_module_0[#_module_0 + 1] = _with_0 return _module_0 local _module_0 = nil _module_0 = function() @@ -2655,25 +2573,19 @@ for _index_0 = 1, #tuples do local left, right = _des_0[1], _des_0[2] print(left, right) end -do - local user = database.find_user("moon") - if user then - print(user.name) - end +local user = database.find_user("moon") +if user then + print(user.name) end -do - local hello = os.getenv("hello") - if hello then - print("You have hello", hello) +local hello = os.getenv("hello") +if hello then + print("You have hello", hello) +else + local world = os.getenv("world") + if world then + print("you have world", world) else - do - local world = os.getenv("world") - if world then - print("you have world", world) - else - print("nothing :(") - end - end + print("nothing :(") end end do @@ -2936,40 +2848,34 @@ local items = { 4 } local doubled -do - local _accum_0 = { } - local _len_0 = 1 - for i, item in ipairs(items) do - _accum_0[_len_0] = item * 2 - _len_0 = _len_0 + 1 - end - doubled = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +for i, item in ipairs(items) do + _accum_0[_len_0] = item * 2 + _len_0 = _len_0 + 1 end +doubled = _accum_0 local iter = ipairs(items) local slice -do - local _accum_0 = { } - local _len_0 = 1 - for i, item in iter do - if i > 1 and i < 3 then - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for i, item in iter do + if i > 1 and i < 3 then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end - slice = _accum_0 end +slice = _accum_0 local doubled -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] = item * 2 - _len_0 = _len_0 + 1 - end - doubled = _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] = item * 2 + _len_0 = _len_0 + 1 end +doubled = _accum_0 local x_coords = { 4, 5, @@ -2982,57 +2888,49 @@ local y_coords = { 3 } local points -do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #x_coords do - local x = x_coords[_index_0] - for _index_1 = 1, #y_coords do - local y = y_coords[_index_1] - _accum_0[_len_0] = { - x, - y - } - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #x_coords do + local x = x_coords[_index_0] + for _index_1 = 1, #y_coords do + local y = y_coords[_index_1] + _accum_0[_len_0] = { + x, + y + } + _len_0 = _len_0 + 1 end - points = _accum_0 end +points = _accum_0 local evens -do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 100 do - if i % 2 == 0 then - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 100 do + if i % 2 == 0 then + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 end - evens = _accum_0 end +evens = _accum_0 local thing = { color = "red", name = "fast", width = 123 } local thing_copy -do - local _tbl_0 = { } - for k, v in pairs(thing) do - _tbl_0[k] = v - end - thing_copy = _tbl_0 +local _tbl_0 = { } +for k, v in pairs(thing) do + _tbl_0[k] = v end +thing_copy = _tbl_0 local no_color -do - local _tbl_0 = { } - for k, v in pairs(thing) do - if k ~= "color" then - _tbl_0[k] = v - end +local _tbl_0 = { } +for k, v in pairs(thing) do + if k ~= "color" then + _tbl_0[k] = v end - no_color = _tbl_0 end +no_color = _tbl_0 local numbers = { 1, 2, @@ -3040,14 +2938,12 @@ local numbers = { 4 } local sqrts -do - local _tbl_0 = { } - for _index_0 = 1, #numbers do - local i = numbers[_index_0] - _tbl_0[i] = math.sqrt(i) - end - sqrts = _tbl_0 +local _tbl_0 = { } +for _index_0 = 1, #numbers do + local i = numbers[_index_0] + _tbl_0[i] = math.sqrt(i) end +sqrts = _tbl_0 local tuples = { { "hello", @@ -3059,52 +2955,44 @@ local tuples = { } } local tbl -do - local _tbl_0 = { } - for _index_0 = 1, #tuples do - local tuple = tuples[_index_0] - local _key_0, _val_0 = unpack(tuple) - _tbl_0[_key_0] = _val_0 - end - tbl = _tbl_0 +local _tbl_0 = { } +for _index_0 = 1, #tuples do + local tuple = tuples[_index_0] + local _key_0, _val_0 = unpack(tuple) + _tbl_0[_key_0] = _val_0 end +tbl = _tbl_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - local _max_0 = 5 - for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _max_0 = 5 +for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - for _index_0 = 2, #_list_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 2, #_list_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - for _index_0 = 1, #_list_0, 2 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 1, #_list_0, 2 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 for i = 10, 20 do print(i) end @@ -3114,13 +3002,11 @@ end for key, value in pairs(object) do print(key, value) end -do - local _list_0 = items - local _max_0 = 4 - for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do - local item = _list_0[_index_0] - print(item) - end +local _list_0 = items +local _max_0 = 4 +for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do + local item = _list_0[_index_0] + print(item) end local _list_0 = items for _index_0 = 1, #_list_0 do @@ -3131,19 +3017,17 @@ for j = 1, 10, 3 do print(j) end local doubled_evens -do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 20 do - if i % 2 == 0 then - _accum_0[_len_0] = i * 2 - else - _accum_0[_len_0] = i - end - _len_0 = _len_0 + 1 +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 20 do + if i % 2 == 0 then + _accum_0[_len_0] = i * 2 + else + _accum_0[_len_0] = i end - doubled_evens = _accum_0 + _len_0 = _len_0 + 1 end +doubled_evens = _accum_0 local func_a func_a = function() for i = 1, 10 do @@ -3201,20 +3085,18 @@ local my_numbers = { 6 } local odds -do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #my_numbers do - local x = my_numbers[_index_0] - if x % 2 == 1 then - goto _continue_0 - end - _accum_0[_len_0] = x - _len_0 = _len_0 + 1 - ::_continue_0:: +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #my_numbers do + local x = my_numbers[_index_0] + if x % 2 == 1 then + goto _continue_0 end - odds = _accum_0 + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + ::_continue_0:: end +odds = _accum_0 local have_coins = false if have_coins then print("Got coins") @@ -3306,15 +3188,13 @@ else next_number = error("can't count that high!") end local msg -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - msg = "you are lucky" - elseif 2 == _exp_0 then - msg = "you are almost lucky" - else - msg = "not so lucky" - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + msg = "you are lucky" +elseif 2 == _exp_0 then + msg = "you are almost lucky" +else + msg = "not so lucky" end do local _exp_0 = math.random(1, 5) @@ -3324,13 +3204,11 @@ do print("not so lucky") end end -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - print("you are lucky") - else - print("not so lucky") - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + print("you are lucky") +else + print("not so lucky") end local items = { { @@ -3344,25 +3222,23 @@ local items = { } for _index_0 = 1, #items do local item = items[_index_0] - do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local x = item.x - local y = item.y - if x ~= nil and y ~= nil then - _match_0 = true - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) - end + local _type_0 = type(item) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = item.x + local y = item.y + if x ~= nil and y ~= nil then + _match_0 = true + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end - if not _match_0 then - if _tab_0 then - local width = item.width - local height = item.height - if width ~= nil and height ~= nil then - print("size " .. tostring(width) .. ", " .. tostring(height)) - end + end + if not _match_0 then + if _tab_0 then + local width = item.width + local height = item.height + if width ~= nil and height ~= nil then + print("size " .. tostring(width) .. ", " .. tostring(height)) end end end @@ -3375,66 +3251,62 @@ end if y == nil then y = 200 end -do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - x = _obj_0.x - end - end - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - y = _obj_0.y - end - end - if x == nil then - x = 50 +local _type_0 = type(item) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + x = _obj_0.x end - if y == nil then - y = 200 + end + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + y = _obj_0.y end - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end + if x == nil then + x = 50 + end + if y == nil then + y = 200 + end + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end local Inventory -do - local _class_0 - local _base_0 = { - add_item = function(self, name) - if self.items[name] then - local _obj_0 = self.items - _obj_0[name] = _obj_0[name] + 1 - else - self.items[name] = 1 - end +local _class_0 +local _base_0 = { + add_item = function(self, name) + if self.items[name] then + local _obj_0 = self.items + _obj_0[name] = _obj_0[name] + 1 + else + self.items[name] = 1 end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 end - _class_0 = setmetatable({ - __init = function(self) - self.items = { } - end, - __base = _base_0, - __name = "Inventory" - }, { - __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 - Inventory = _class_0 +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function(self) + self.items = { } + end, + __base = _base_0, + __name = "Inventory" +}, { + __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 +Inventory = _class_0 local inv = Inventory() inv:add_item("t-shirt") inv:add_item("pants") @@ -3450,95 +3322,12 @@ do if _base_0.__index == nil then _base_0.__index = _base_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Person" - }, { - __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 - Person = _class_0 -end -local a = Person() -local b = Person() -a:give_item("pants") -b:give_item("shirt") -local _list_0 = a.clothes -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - print(item) -end -local Person -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function(self) - self.clothes = { } - end, - __base = _base_0, - __name = "Person" - }, { - __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 - Person = _class_0 -end -local BackPack -do - local _class_0 - local _parent_0 = Inventory - local _base_0 = { - size = 10, - add_item = function(self, name) - if #self.items > size then - error("backpack is full") - end - return _class_0.__parent.__base.add_item(self, name) - end - } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, + _class_0 = setmetatable({ + __init = function() end, __base = _base_0, - __name = "BackPack", - __parent = _parent_0 + __name = "Person" }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val - end - end, + __index = _base_0, __call = function(cls, ...) local _self_0 = setmetatable({ }, _base_0) cls.__init(_self_0, ...) @@ -3546,11 +3335,90 @@ do end }) _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) + Person = _class_0 +end +local a = Person() +local b = Person() +a:give_item("pants") +b:give_item("shirt") +local _list_0 = a.clothes +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + print(item) +end +local Person +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self) + self.clothes = { } + end, + __base = _base_0, + __name = "Person" +}, { + __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 +Person = _class_0 +local BackPack +local _class_0 +local _parent_0 = Inventory +local _base_0 = { + size = 10, + add_item = function(self, name) + if #self.items > size then + error("backpack is full") + end + return _class_0.__parent.__base.add_item(self, name) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "BackPack", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - BackPack = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +BackPack = _class_0 local Shelf do local _class_0 @@ -3578,102 +3446,98 @@ do Shelf = _class_0 end local Cupboard -do - local _class_0 - local _parent_0 = Shelf - local _base_0 = { } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "Cupboard", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val +local _class_0 +local _parent_0 = Shelf +local _base_0 = { } +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Cupboard", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 + else + return val end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - Cupboard = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +Cupboard = _class_0 local MyClass -do - local _class_0 - local _parent_0 = ParentClass - local _base_0 = { - a_method = function(self) - _class_0.__parent.__base.a_method(self, "hello", "world") - _class_0.__parent.a_method(self, "hello", "world") - _class_0.__parent.a_method(self, "hello", "world") - return assert(_class_0.__parent == ParentClass) - end - } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "MyClass", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val +local _class_0 +local _parent_0 = ParentClass +local _base_0 = { + a_method = function(self) + _class_0.__parent.__base.a_method(self, "hello", "world") + _class_0.__parent.a_method(self, "hello", "world") + _class_0.__parent.a_method(self, "hello", "world") + return assert(_class_0.__parent == ParentClass) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "MyClass", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 + else + return val end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - MyClass = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +MyClass = _class_0 local b = BackPack() assert(b.__class == BackPack) print(BackPack.size) @@ -3737,61 +3601,57 @@ Counter() print(Counter.count) self.__class:hello(1, 2, 3, 4) local Things -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "Things" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Things" - }, { - __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; - self.class_var = "hello world" - Things = _class_0 -end +}) +_base_0.__class = _class_0 +local self = _class_0; +self.class_var = "hello world" +Things = _class_0 local MoreThings -do - local _class_0 - local secret, log - local _base_0 = { - some_method = function(self) - return log("hello world: " .. secret) - end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local secret, log +local _base_0 = { + some_method = function(self) + return log("hello world: " .. secret) end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "MoreThings" - }, { - __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; - secret = 123 - log = function(msg) - return print("LOG:", msg) +} +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "MoreThings" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - MoreThings = _class_0 +}) +_base_0.__class = _class_0 +local self = _class_0; +secret = 123 +log = function(msg) + return print("LOG:", msg) end +MoreThings = _class_0 assert(self == self) assert(self.__class == self.__class) local some_instance_method @@ -3825,32 +3685,30 @@ do _base_0.__class = _class_0 Something = _class_0 end -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self, foo, bar, biz, baz) + self.foo = foo + self.bar = bar + self.__class.biz = biz + self.__class.baz = baz + end, + __base = _base_0, + __name = "Something" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function(self, foo, bar, biz, baz) - self.foo = foo - self.bar = bar - self.__class.biz = biz - self.__class.baz = baz - end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 -end +}) +_base_0.__class = _class_0 +Something = _class_0 local new new = function(self, fieldA, fieldB) self.fieldA = fieldA @@ -3861,33 +3719,31 @@ local obj = new({ }, 123, "abc") print(obj) local x local Bucket -do - local _class_0 - local _base_0 = { - drops = 0, - add_drop = function(self) - self.drops = self.drops + 1 - end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local _base_0 = { + drops = 0, + add_drop = function(self) + self.drops = self.drops + 1 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Bucket" - }, { - __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 - Bucket = _class_0 - x = _class_0 +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Bucket" +}, { + __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 +Bucket = _class_0 +x = _class_0 local BigBucket do local _class_0 @@ -3939,27 +3795,25 @@ do end assert(Bucket.__name == "BigBucket") local x -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "x" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "x" - }, { - __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 - x = _class_0 -end +}) +_base_0.__class = _class_0 +x = _class_0 local MyIndex = { __index = { var = 1 @@ -4042,19 +3896,15 @@ end local y = Y() y:func() assert(y.__class.__parent ~= X) -do - local _with_0 = Person() - _with_0.name = "Oswald" - _with_0:add_relative(my_dad) - _with_0:save() - print(_with_0.name) -end +local _with_0 = Person() +_with_0.name = "Oswald" +_with_0:add_relative(my_dad) +_with_0:save() +print(_with_0.name) local file -do - local _with_0 = File("favorite_foods.txt") - _with_0:set_encoding("utf8") - file = _with_0 -end +local _with_0 = File("favorite_foods.txt") +_with_0:set_encoding("utf8") +file = _with_0 local create_person create_person = function(name, relatives) local _with_0 = Person() @@ -4070,22 +3920,18 @@ local me = create_person("Leaf", { mother, sister }) -do - local str = "Hello" - print("original:", str) - print("upper:", str:upper()) -end -do - local _with_0 = tb - _with_0[1] = 1 - print(_with_0[2]) - do - local _with_1 = _with_0[abc] - _with_1[3] = _with_1[2]:func() - _with_1["key-name"] = value - end - _with_0[#_with_0 + 1] = "abc" -end +local str = "Hello" +print("original:", str) +print("upper:", str:upper()) +local _with_0 = tb +_with_0[1] = 1 +print(_with_0[2]) +do + local _with_1 = _with_0[abc] + _with_1[3] = _with_1[2]:func() + _with_1["key-name"] = value +end +_with_0[#_with_0 + 1] = "abc" do local var = "hello" print(var) diff --git a/spec/outputs/codes_from_doc_zh.lua b/spec/outputs/codes_from_doc_zh.lua index 15647b2..fff0bdd 100644 --- a/spec/outputs/codes_from_doc_zh.lua +++ b/spec/outputs/codes_from_doc_zh.lua @@ -46,13 +46,18 @@ _module_0["🌛"] = _ud83c_udf1b return _module_0 local area = 6.2831853071796 * 5 print('你好 世界') -assert(item ~= nil) +do + assert(item ~= nil) +end local value = item if (f1() and f2() and f3()) then print("OK") end +do + local funcA + funcA = function() end +end local funcA -funcA = function() end funcA = function() return "访问月之脚本定义的变量" end @@ -146,28 +151,26 @@ local b = { y = 1 } local merge -do - local _tab_0 = { } - local _idx_0 = 1 - for _key_0, _value_0 in pairs(a) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end +local _tab_0 = { } +local _idx_0 = 1 +for _key_0, _value_0 in pairs(a) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 end - local _idx_1 = 1 - for _key_0, _value_0 in pairs(b) do - if _idx_1 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_1 = _idx_1 + 1 - else - _tab_0[_key_0] = _value_0 - end +end +local _idx_1 = 1 +for _key_0, _value_0 in pairs(b) do + if _idx_1 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_1 = _idx_1 + 1 + else + _tab_0[_key_0] = _value_0 end - merge = _tab_0 end +merge = _tab_0 local mt = { } local add add = function(self, right) @@ -259,12 +262,10 @@ end if print and (x ~= nil) then print(x) end -do - local _with_0 = io.open("test.txt", "w") - if _with_0 ~= nil then - _with_0:write("你好") - _with_0:close() - end +local _with_0 = io.open("test.txt", "w") +if _with_0 ~= nil then + _with_0:write("你好") + _with_0:close() end print("你好") print(1, 2) @@ -341,10 +342,8 @@ do x, y, z = _obj_0.x, _obj_0.y, _obj_0.z end local a, b, c - do - local _obj_0 = require('module') - a, b, c = _obj_0.a, _obj_0.b, _obj_0.c - end + local _obj_0 = require('module') + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c end do local module = require('module') @@ -383,29 +382,27 @@ y = function() end _module_0["y"] = y local Something -do - local _class_0 - local _base_0 = { - umm = "cool" - } - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 +local _class_0 +local _base_0 = { + umm = "cool" +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" +}, { + __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 +Something = _class_0 _module_0["Something"] = Something return _module_0 local _module_0 = { } @@ -436,11 +433,9 @@ if this then else _module_0[#_module_0 + 1] = 456 end -do - local _with_0 = tmp - local j = 2000 - _module_0[#_module_0 + 1] = _with_0 -end +local _with_0 = tmp +local j = 2000 +_module_0[#_module_0 + 1] = _with_0 return _module_0 local _module_0 = nil _module_0 = function() @@ -577,25 +572,19 @@ for _index_0 = 1, #tuples do local left, right = _des_0[1], _des_0[2] print(left, right) end -do - local user = database.find_user("moon") - if user then - print(user.name) - end +local user = database.find_user("moon") +if user then + print(user.name) end -do - local hello = os.getenv("hello") - if hello then - print("你有 hello", hello) +local hello = os.getenv("hello") +if hello then + print("你有 hello", hello) +else + local world = os.getenv("world") + if world then + print("你有 world", world) else - do - local world = os.getenv("world") - if world then - print("你有 world", world) - else - print("什么都没有 :(") - end - end + print("什么都没有 :(") end end do @@ -852,40 +841,34 @@ local items = { 4 } local doubled -do - local _accum_0 = { } - local _len_0 = 1 - for i, item in ipairs(items) do - _accum_0[_len_0] = item * 2 - _len_0 = _len_0 + 1 - end - doubled = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +for i, item in ipairs(items) do + _accum_0[_len_0] = item * 2 + _len_0 = _len_0 + 1 end +doubled = _accum_0 local iter = ipairs(items) local slice -do - local _accum_0 = { } - local _len_0 = 1 - for i, item in iter do - if i > 1 and i < 3 then - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for i, item in iter do + if i > 1 and i < 3 then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end - slice = _accum_0 end +slice = _accum_0 local doubled -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] = item * 2 - _len_0 = _len_0 + 1 - end - doubled = _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] = item * 2 + _len_0 = _len_0 + 1 end +doubled = _accum_0 local x_coords = { 4, 5, @@ -898,57 +881,49 @@ local y_coords = { 3 } local points -do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #x_coords do - local x = x_coords[_index_0] - for _index_1 = 1, #y_coords do - local y = y_coords[_index_1] - _accum_0[_len_0] = { - x, - y - } - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #x_coords do + local x = x_coords[_index_0] + for _index_1 = 1, #y_coords do + local y = y_coords[_index_1] + _accum_0[_len_0] = { + x, + y + } + _len_0 = _len_0 + 1 end - points = _accum_0 end +points = _accum_0 local evens -do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 100 do - if i % 2 == 0 then - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 100 do + if i % 2 == 0 then + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 end - evens = _accum_0 end +evens = _accum_0 local thing = { color = "red", name = "fast", width = 123 } local thing_copy -do - local _tbl_0 = { } - for k, v in pairs(thing) do - _tbl_0[k] = v - end - thing_copy = _tbl_0 +local _tbl_0 = { } +for k, v in pairs(thing) do + _tbl_0[k] = v end +thing_copy = _tbl_0 local no_color -do - local _tbl_0 = { } - for k, v in pairs(thing) do - if k ~= "color" then - _tbl_0[k] = v - end +local _tbl_0 = { } +for k, v in pairs(thing) do + if k ~= "color" then + _tbl_0[k] = v end - no_color = _tbl_0 end +no_color = _tbl_0 local numbers = { 1, 2, @@ -956,14 +931,12 @@ local numbers = { 4 } local sqrts -do - local _tbl_0 = { } - for _index_0 = 1, #numbers do - local i = numbers[_index_0] - _tbl_0[i] = math.sqrt(i) - end - sqrts = _tbl_0 +local _tbl_0 = { } +for _index_0 = 1, #numbers do + local i = numbers[_index_0] + _tbl_0[i] = math.sqrt(i) end +sqrts = _tbl_0 local tuples = { { "hello", @@ -975,52 +948,44 @@ local tuples = { } } local tbl -do - local _tbl_0 = { } - for _index_0 = 1, #tuples do - local tuple = tuples[_index_0] - local _key_0, _val_0 = unpack(tuple) - _tbl_0[_key_0] = _val_0 - end - tbl = _tbl_0 +local _tbl_0 = { } +for _index_0 = 1, #tuples do + local tuple = tuples[_index_0] + local _key_0, _val_0 = unpack(tuple) + _tbl_0[_key_0] = _val_0 end +tbl = _tbl_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - local _max_0 = 5 - for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _max_0 = 5 +for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - for _index_0 = 2, #_list_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 2, #_list_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - for _index_0 = 1, #_list_0, 2 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 1, #_list_0, 2 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 for i = 10, 20 do print(i) end @@ -1030,13 +995,11 @@ end for key, value in pairs(object) do print(key, value) end -do - local _list_0 = items - local _max_0 = 4 - for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do - local item = _list_0[_index_0] - print(item) - end +local _list_0 = items +local _max_0 = 4 +for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do + local item = _list_0[_index_0] + print(item) end local _list_0 = items for _index_0 = 1, #_list_0 do @@ -1047,19 +1010,17 @@ for j = 1, 10, 3 do print(j) end local doubled_evens -do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 20 do - if i % 2 == 0 then - _accum_0[_len_0] = i * 2 - else - _accum_0[_len_0] = i - end - _len_0 = _len_0 + 1 +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 20 do + if i % 2 == 0 then + _accum_0[_len_0] = i * 2 + else + _accum_0[_len_0] = i end - doubled_evens = _accum_0 + _len_0 = _len_0 + 1 end +doubled_evens = _accum_0 local func_a func_a = function() for i = 1, 10 do @@ -1117,20 +1078,18 @@ local my_numbers = { 6 } local odds -do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #my_numbers do - local x = my_numbers[_index_0] - if x % 2 == 1 then - goto _continue_0 - end - _accum_0[_len_0] = x - _len_0 = _len_0 + 1 - ::_continue_0:: +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #my_numbers do + local x = my_numbers[_index_0] + if x % 2 == 1 then + goto _continue_0 end - odds = _accum_0 + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + ::_continue_0:: end +odds = _accum_0 local have_coins = false if have_coins then print("有硬币") @@ -1222,15 +1181,13 @@ else next_number = error("数字数得太大了!") end local msg -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - msg = "你很幸运" - elseif 2 == _exp_0 then - msg = "你差点很幸运" - else - msg = "不太幸运" - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + msg = "你很幸运" +elseif 2 == _exp_0 then + msg = "你差点很幸运" +else + msg = "不太幸运" end do local _exp_0 = math.random(1, 5) @@ -1240,13 +1197,11 @@ do print("不太幸运") end end -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - print("你很幸运") - else - print("不太幸运") - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + print("你很幸运") +else + print("不太幸运") end local items = { { @@ -1260,25 +1215,23 @@ local items = { } for _index_0 = 1, #items do local item = items[_index_0] - do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local x = item.x - local y = item.y - if x ~= nil and y ~= nil then - _match_0 = true - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) - end + local _type_0 = type(item) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = item.x + local y = item.y + if x ~= nil and y ~= nil then + _match_0 = true + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end - if not _match_0 then - if _tab_0 then - local width = item.width - local height = item.height - if width ~= nil and height ~= nil then - print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) - end + end + if not _match_0 then + if _tab_0 then + local width = item.width + local height = item.height + if width ~= nil and height ~= nil then + print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) end end end @@ -1291,66 +1244,62 @@ end if y == nil then y = 200 end -do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - x = _obj_0.x - end - end - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - y = _obj_0.y - end - end - if x == nil then - x = 50 +local _type_0 = type(item) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + x = _obj_0.x end - if y == nil then - y = 200 + end + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + y = _obj_0.y end - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end + if x == nil then + x = 50 + end + if y == nil then + y = 200 + end + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end local Inventory -do - local _class_0 - local _base_0 = { - add_item = function(self, name) - if self.items[name] then - local _obj_0 = self.items - _obj_0[name] = _obj_0[name] + 1 - else - self.items[name] = 1 - end +local _class_0 +local _base_0 = { + add_item = function(self, name) + if self.items[name] then + local _obj_0 = self.items + _obj_0[name] = _obj_0[name] + 1 + else + self.items[name] = 1 end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 end - _class_0 = setmetatable({ - __init = function(self) - self.items = { } - end, - __base = _base_0, - __name = "Inventory" - }, { - __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 - Inventory = _class_0 +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function(self) + self.items = { } + end, + __base = _base_0, + __name = "Inventory" +}, { + __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 +Inventory = _class_0 local inv = Inventory() inv:add_item("t-shirt") inv:add_item("pants") @@ -1391,6 +1340,79 @@ for _index_0 = 1, #_list_0 do print(item) end local Person +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self) + self.clothes = { } + end, + __base = _base_0, + __name = "Person" +}, { + __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 +Person = _class_0 +local BackPack +local _class_0 +local _parent_0 = Inventory +local _base_0 = { + size = 10, + add_item = function(self, name) + if #self.items > size then + error("背包已满") + end + return _class_0.__parent.__base.add_item(self, name) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "BackPack", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 + end +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) +end +BackPack = _class_0 +local Shelf do local _class_0 local _base_0 = { } @@ -1398,11 +1420,9 @@ do _base_0.__index = _base_0 end _class_0 = setmetatable({ - __init = function(self) - self.clothes = { } - end, + __init = function() end, __base = _base_0, - __name = "Person" + __name = "Shelf" }, { __index = _base_0, __call = function(cls, ...) @@ -1412,184 +1432,105 @@ do end }) _base_0.__class = _class_0 - Person = _class_0 + local self = _class_0; + self.__inherited = function(self, child) + return print(self.__name, "被", child.__name, "继承") + end + Shelf = _class_0 end -local BackPack -do - local _class_0 - local _parent_0 = Inventory - local _base_0 = { - size = 10, - add_item = function(self, name) - if #self.items > size then - error("背包已满") +local Cupboard +local _class_0 +local _parent_0 = Shelf +local _base_0 = { } +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Cupboard", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] end - return _class_0.__parent.__base.add_item(self, name) - end - } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 + else + return val end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "BackPack", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val - end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) - end - BackPack = _class_0 -end -local Shelf -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 = "Shelf" - }, { - __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; - self.__inherited = function(self, child) - return print(self.__name, "被", child.__name, "继承") - end - Shelf = _class_0 -end -local Cupboard -do - local _class_0 - local _parent_0 = Shelf - local _base_0 = { } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "Cupboard", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val - end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) - end - Cupboard = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +Cupboard = _class_0 local MyClass -do - local _class_0 - local _parent_0 = ParentClass - local _base_0 = { - a_method = function(self) - _class_0.__parent.__base.a_method(self, "你好", "世界") - _class_0.__parent.a_method(self, "你好", "世界") - _class_0.__parent.a_method(self, "你好", "世界") - return assert(_class_0.__parent == ParentClass) - end - } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "MyClass", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val +local _class_0 +local _parent_0 = ParentClass +local _base_0 = { + a_method = function(self) + _class_0.__parent.__base.a_method(self, "你好", "世界") + _class_0.__parent.a_method(self, "你好", "世界") + _class_0.__parent.a_method(self, "你好", "世界") + return assert(_class_0.__parent == ParentClass) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "MyClass", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 + else + return val end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - MyClass = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +MyClass = _class_0 local b = BackPack() assert(b.__class == BackPack) print(BackPack.size) @@ -1653,61 +1594,57 @@ Counter() print(Counter.count) self.__class:hello(1, 2, 3, 4) local Things -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "Things" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Things" - }, { - __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; - self.class_var = "hello world" - Things = _class_0 -end +}) +_base_0.__class = _class_0 +local self = _class_0; +self.class_var = "hello world" +Things = _class_0 local MoreThings -do - local _class_0 - local secret, log - local _base_0 = { - some_method = function(self) - return log("hello world: " .. secret) - end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local secret, log +local _base_0 = { + some_method = function(self) + return log("hello world: " .. secret) end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "MoreThings" - }, { - __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; - secret = 123 - log = function(msg) - return print("LOG:", msg) +} +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "MoreThings" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - MoreThings = _class_0 +}) +_base_0.__class = _class_0 +local self = _class_0; +secret = 123 +log = function(msg) + return print("LOG:", msg) end +MoreThings = _class_0 assert(self == self) assert(self.__class == self.__class) local some_instance_method @@ -1741,32 +1678,30 @@ do _base_0.__class = _class_0 Something = _class_0 end -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self, foo, bar, biz, baz) + self.foo = foo + self.bar = bar + self.__class.biz = biz + self.__class.baz = baz + end, + __base = _base_0, + __name = "Something" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function(self, foo, bar, biz, baz) - self.foo = foo - self.bar = bar - self.__class.biz = biz - self.__class.baz = baz - end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 -end +}) +_base_0.__class = _class_0 +Something = _class_0 local new new = function(self, fieldA, fieldB) self.fieldA = fieldA @@ -1777,33 +1712,31 @@ local obj = new({ }, 123, "abc") print(obj) local x local Bucket -do - local _class_0 - local _base_0 = { - drops = 0, - add_drop = function(self) - self.drops = self.drops + 1 - end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local _base_0 = { + drops = 0, + add_drop = function(self) + self.drops = self.drops + 1 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Bucket" - }, { - __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 - Bucket = _class_0 - x = _class_0 +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Bucket" +}, { + __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 +Bucket = _class_0 +x = _class_0 local BigBucket do local _class_0 @@ -1855,27 +1788,25 @@ do end assert(Bucket.__name == "BigBucket") local x -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "x" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "x" - }, { - __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 - x = _class_0 -end +}) +_base_0.__class = _class_0 +x = _class_0 local MyIndex = { __index = { var = 1 @@ -1958,19 +1889,15 @@ end local y = Y() y:func() assert(y.__class.__parent ~= X) -do - local _with_0 = Person() - _with_0.name = "Oswald" - _with_0:add_relative(my_dad) - _with_0:save() - print(_with_0.name) -end +local _with_0 = Person() +_with_0.name = "Oswald" +_with_0:add_relative(my_dad) +_with_0:save() +print(_with_0.name) local file -do - local _with_0 = File("favorite_foods.txt") - _with_0:set_encoding("utf8") - file = _with_0 -end +local _with_0 = File("favorite_foods.txt") +_with_0:set_encoding("utf8") +file = _with_0 local create_person create_person = function(name, relatives) local _with_0 = Person() @@ -1986,22 +1913,18 @@ local me = create_person("Leaf", { mother, sister }) +local str = "你好" +print("原始:", str) +print("大写:", str:upper()) +local _with_0 = tb +_with_0[1] = 1 +print(_with_0[2]) do - local str = "你好" - print("原始:", str) - print("大写:", str:upper()) -end -do - local _with_0 = tb - _with_0[1] = 1 - print(_with_0[2]) - do - local _with_1 = _with_0[abc] - _with_1[3] = _with_1[2]:func() - _with_1["key-name"] = value - end - _with_0[#_with_0 + 1] = "abc" + local _with_1 = _with_0[abc] + _with_1[3] = _with_1[2]:func() + _with_1["key-name"] = value end +_with_0[#_with_0 + 1] = "abc" do local var = "hello" print(var) @@ -2118,13 +2041,18 @@ _module_0["🌛"] = _ud83c_udf1b return _module_0 local area = 6.2831853071796 * 5 print('你好 世界') -assert(item ~= nil) +do + assert(item ~= nil) +end local value = item if (f1() and f2() and f3()) then print("OK") end +do + local funcA + funcA = function() end +end local funcA -funcA = function() end funcA = function() return "访问月之脚本定义的变量" end @@ -2218,28 +2146,26 @@ local b = { y = 1 } local merge -do - local _tab_0 = { } - local _idx_0 = 1 - for _key_0, _value_0 in pairs(a) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end +local _tab_0 = { } +local _idx_0 = 1 +for _key_0, _value_0 in pairs(a) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 end - local _idx_1 = 1 - for _key_0, _value_0 in pairs(b) do - if _idx_1 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_1 = _idx_1 + 1 - else - _tab_0[_key_0] = _value_0 - end +end +local _idx_1 = 1 +for _key_0, _value_0 in pairs(b) do + if _idx_1 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_1 = _idx_1 + 1 + else + _tab_0[_key_0] = _value_0 end - merge = _tab_0 end +merge = _tab_0 local mt = { } local add add = function(self, right) @@ -2331,12 +2257,10 @@ end if print and (x ~= nil) then print(x) end -do - local _with_0 = io.open("test.txt", "w") - if _with_0 ~= nil then - _with_0:write("你好") - _with_0:close() - end +local _with_0 = io.open("test.txt", "w") +if _with_0 ~= nil then + _with_0:write("你好") + _with_0:close() end print("你好") print(1, 2) @@ -2413,10 +2337,8 @@ do x, y, z = _obj_0.x, _obj_0.y, _obj_0.z end local a, b, c - do - local _obj_0 = require('module') - a, b, c = _obj_0.a, _obj_0.b, _obj_0.c - end + local _obj_0 = require('module') + a, b, c = _obj_0.a, _obj_0.b, _obj_0.c end do local module = require('module') @@ -2455,29 +2377,27 @@ y = function() end _module_0["y"] = y local Something -do - local _class_0 - local _base_0 = { - umm = "cool" - } - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 +local _class_0 +local _base_0 = { + umm = "cool" +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" +}, { + __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 +Something = _class_0 _module_0["Something"] = Something return _module_0 local _module_0 = { } @@ -2508,11 +2428,9 @@ if this then else _module_0[#_module_0 + 1] = 456 end -do - local _with_0 = tmp - local j = 2000 - _module_0[#_module_0 + 1] = _with_0 -end +local _with_0 = tmp +local j = 2000 +_module_0[#_module_0 + 1] = _with_0 return _module_0 local _module_0 = nil _module_0 = function() @@ -2649,25 +2567,19 @@ for _index_0 = 1, #tuples do local left, right = _des_0[1], _des_0[2] print(left, right) end -do - local user = database.find_user("moon") - if user then - print(user.name) - end +local user = database.find_user("moon") +if user then + print(user.name) end -do - local hello = os.getenv("hello") - if hello then - print("你有 hello", hello) +local hello = os.getenv("hello") +if hello then + print("你有 hello", hello) +else + local world = os.getenv("world") + if world then + print("你有 world", world) else - do - local world = os.getenv("world") - if world then - print("你有 world", world) - else - print("什么都没有 :(") - end - end + print("什么都没有 :(") end end do @@ -2924,40 +2836,34 @@ local items = { 4 } local doubled -do - local _accum_0 = { } - local _len_0 = 1 - for i, item in ipairs(items) do - _accum_0[_len_0] = item * 2 - _len_0 = _len_0 + 1 - end - doubled = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +for i, item in ipairs(items) do + _accum_0[_len_0] = item * 2 + _len_0 = _len_0 + 1 end +doubled = _accum_0 local iter = ipairs(items) local slice -do - local _accum_0 = { } - local _len_0 = 1 - for i, item in iter do - if i > 1 and i < 3 then - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for i, item in iter do + if i > 1 and i < 3 then + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end - slice = _accum_0 end +slice = _accum_0 local doubled -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] = item * 2 - _len_0 = _len_0 + 1 - end - doubled = _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] = item * 2 + _len_0 = _len_0 + 1 end +doubled = _accum_0 local x_coords = { 4, 5, @@ -2970,57 +2876,49 @@ local y_coords = { 3 } local points -do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #x_coords do - local x = x_coords[_index_0] - for _index_1 = 1, #y_coords do - local y = y_coords[_index_1] - _accum_0[_len_0] = { - x, - y - } - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #x_coords do + local x = x_coords[_index_0] + for _index_1 = 1, #y_coords do + local y = y_coords[_index_1] + _accum_0[_len_0] = { + x, + y + } + _len_0 = _len_0 + 1 end - points = _accum_0 end +points = _accum_0 local evens -do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 100 do - if i % 2 == 0 then - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 100 do + if i % 2 == 0 then + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 end - evens = _accum_0 end +evens = _accum_0 local thing = { color = "red", name = "fast", width = 123 } local thing_copy -do - local _tbl_0 = { } - for k, v in pairs(thing) do - _tbl_0[k] = v - end - thing_copy = _tbl_0 +local _tbl_0 = { } +for k, v in pairs(thing) do + _tbl_0[k] = v end +thing_copy = _tbl_0 local no_color -do - local _tbl_0 = { } - for k, v in pairs(thing) do - if k ~= "color" then - _tbl_0[k] = v - end +local _tbl_0 = { } +for k, v in pairs(thing) do + if k ~= "color" then + _tbl_0[k] = v end - no_color = _tbl_0 end +no_color = _tbl_0 local numbers = { 1, 2, @@ -3028,14 +2926,12 @@ local numbers = { 4 } local sqrts -do - local _tbl_0 = { } - for _index_0 = 1, #numbers do - local i = numbers[_index_0] - _tbl_0[i] = math.sqrt(i) - end - sqrts = _tbl_0 +local _tbl_0 = { } +for _index_0 = 1, #numbers do + local i = numbers[_index_0] + _tbl_0[i] = math.sqrt(i) end +sqrts = _tbl_0 local tuples = { { "hello", @@ -3047,52 +2943,44 @@ local tuples = { } } local tbl -do - local _tbl_0 = { } - for _index_0 = 1, #tuples do - local tuple = tuples[_index_0] - local _key_0, _val_0 = unpack(tuple) - _tbl_0[_key_0] = _val_0 - end - tbl = _tbl_0 +local _tbl_0 = { } +for _index_0 = 1, #tuples do + local tuple = tuples[_index_0] + local _key_0, _val_0 = unpack(tuple) + _tbl_0[_key_0] = _val_0 end +tbl = _tbl_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - local _max_0 = 5 - for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +local _max_0 = 5 +for _index_0 = 1, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - for _index_0 = 2, #_list_0 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 2, #_list_0 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 local slice -do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = items - for _index_0 = 1, #_list_0, 2 do - local item = _list_0[_index_0] - _accum_0[_len_0] = item - _len_0 = _len_0 + 1 - end - slice = _accum_0 +local _accum_0 = { } +local _len_0 = 1 +local _list_0 = items +for _index_0 = 1, #_list_0, 2 do + local item = _list_0[_index_0] + _accum_0[_len_0] = item + _len_0 = _len_0 + 1 end +slice = _accum_0 for i = 10, 20 do print(i) end @@ -3102,13 +2990,11 @@ end for key, value in pairs(object) do print(key, value) end -do - local _list_0 = items - local _max_0 = 4 - for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do - local item = _list_0[_index_0] - print(item) - end +local _list_0 = items +local _max_0 = 4 +for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0 do + local item = _list_0[_index_0] + print(item) end local _list_0 = items for _index_0 = 1, #_list_0 do @@ -3119,19 +3005,17 @@ for j = 1, 10, 3 do print(j) end local doubled_evens -do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 20 do - if i % 2 == 0 then - _accum_0[_len_0] = i * 2 - else - _accum_0[_len_0] = i - end - _len_0 = _len_0 + 1 +local _accum_0 = { } +local _len_0 = 1 +for i = 1, 20 do + if i % 2 == 0 then + _accum_0[_len_0] = i * 2 + else + _accum_0[_len_0] = i end - doubled_evens = _accum_0 + _len_0 = _len_0 + 1 end +doubled_evens = _accum_0 local func_a func_a = function() for i = 1, 10 do @@ -3189,20 +3073,18 @@ local my_numbers = { 6 } local odds -do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #my_numbers do - local x = my_numbers[_index_0] - if x % 2 == 1 then - goto _continue_0 - end - _accum_0[_len_0] = x - _len_0 = _len_0 + 1 - ::_continue_0:: +local _accum_0 = { } +local _len_0 = 1 +for _index_0 = 1, #my_numbers do + local x = my_numbers[_index_0] + if x % 2 == 1 then + goto _continue_0 end - odds = _accum_0 + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + ::_continue_0:: end +odds = _accum_0 local have_coins = false if have_coins then print("有硬币") @@ -3294,15 +3176,13 @@ else next_number = error("数字数得太大了!") end local msg -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - msg = "你很幸运" - elseif 2 == _exp_0 then - msg = "你差点很幸运" - else - msg = "不太幸运" - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + msg = "你很幸运" +elseif 2 == _exp_0 then + msg = "你差点很幸运" +else + msg = "不太幸运" end do local _exp_0 = math.random(1, 5) @@ -3312,13 +3192,11 @@ do print("不太幸运") end end -do - local _exp_0 = math.random(1, 5) - if 1 == _exp_0 then - print("你很幸运") - else - print("不太幸运") - end +local _exp_0 = math.random(1, 5) +if 1 == _exp_0 then + print("你很幸运") +else + print("不太幸运") end local items = { { @@ -3332,25 +3210,23 @@ local items = { } for _index_0 = 1, #items do local item = items[_index_0] - do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local x = item.x - local y = item.y - if x ~= nil and y ~= nil then - _match_0 = true - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) - end + local _type_0 = type(item) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = item.x + local y = item.y + if x ~= nil and y ~= nil then + _match_0 = true + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end - if not _match_0 then - if _tab_0 then - local width = item.width - local height = item.height - if width ~= nil and height ~= nil then - print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) - end + end + if not _match_0 then + if _tab_0 then + local width = item.width + local height = item.height + if width ~= nil and height ~= nil then + print("尺寸 " .. tostring(width) .. ", " .. tostring(height)) end end end @@ -3363,66 +3239,62 @@ end if y == nil then y = 200 end -do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - x = _obj_0.x - end - end - do - local _obj_0 = item.pos - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - y = _obj_0.y - end - end - if x == nil then - x = 50 +local _type_0 = type(item) +local _tab_0 = "table" == _type_0 or "userdata" == _type_0 +if _tab_0 then + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + x = _obj_0.x end - if y == nil then - y = 200 + end + do + local _obj_0 = item.pos + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + y = _obj_0.y end - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end + if x == nil then + x = 50 + end + if y == nil then + y = 200 + end + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) end local Inventory -do - local _class_0 - local _base_0 = { - add_item = function(self, name) - if self.items[name] then - local _obj_0 = self.items - _obj_0[name] = _obj_0[name] + 1 - else - self.items[name] = 1 - end +local _class_0 +local _base_0 = { + add_item = function(self, name) + if self.items[name] then + local _obj_0 = self.items + _obj_0[name] = _obj_0[name] + 1 + else + self.items[name] = 1 end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 end - _class_0 = setmetatable({ - __init = function(self) - self.items = { } - end, - __base = _base_0, - __name = "Inventory" - }, { - __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 - Inventory = _class_0 +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function(self) + self.items = { } + end, + __base = _base_0, + __name = "Inventory" +}, { + __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 +Inventory = _class_0 local inv = Inventory() inv:add_item("t-shirt") inv:add_item("pants") @@ -3438,95 +3310,12 @@ do if _base_0.__index == nil then _base_0.__index = _base_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Person" - }, { - __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 - Person = _class_0 -end -local a = Person() -local b = Person() -a:give_item("pants") -b:give_item("shirt") -local _list_0 = a.clothes -for _index_0 = 1, #_list_0 do - local item = _list_0[_index_0] - print(item) -end -local Person -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function(self) - self.clothes = { } - end, - __base = _base_0, - __name = "Person" - }, { - __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 - Person = _class_0 -end -local BackPack -do - local _class_0 - local _parent_0 = Inventory - local _base_0 = { - size = 10, - add_item = function(self, name) - if #self.items > size then - error("背包已满") - end - return _class_0.__parent.__base.add_item(self, name) - end - } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, + _class_0 = setmetatable({ + __init = function() end, __base = _base_0, - __name = "BackPack", - __parent = _parent_0 + __name = "Person" }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val - end - end, + __index = _base_0, __call = function(cls, ...) local _self_0 = setmetatable({ }, _base_0) cls.__init(_self_0, ...) @@ -3534,11 +3323,90 @@ do end }) _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) + Person = _class_0 +end +local a = Person() +local b = Person() +a:give_item("pants") +b:give_item("shirt") +local _list_0 = a.clothes +for _index_0 = 1, #_list_0 do + local item = _list_0[_index_0] + print(item) +end +local Person +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self) + self.clothes = { } + end, + __base = _base_0, + __name = "Person" +}, { + __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 +Person = _class_0 +local BackPack +local _class_0 +local _parent_0 = Inventory +local _base_0 = { + size = 10, + add_item = function(self, name) + if #self.items > size then + error("背包已满") + end + return _class_0.__parent.__base.add_item(self, name) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "BackPack", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] + end + else + return val + end + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - BackPack = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +BackPack = _class_0 local Shelf do local _class_0 @@ -3566,102 +3434,98 @@ do Shelf = _class_0 end local Cupboard -do - local _class_0 - local _parent_0 = Shelf - local _base_0 = { } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "Cupboard", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val +local _class_0 +local _parent_0 = Shelf +local _base_0 = { } +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "Cupboard", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 + else + return val end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - Cupboard = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +Cupboard = _class_0 local MyClass -do - local _class_0 - local _parent_0 = ParentClass - local _base_0 = { - a_method = function(self) - _class_0.__parent.__base.a_method(self, "你好", "世界") - _class_0.__parent.a_method(self, "你好", "世界") - _class_0.__parent.a_method(self, "你好", "世界") - return assert(_class_0.__parent == ParentClass) - end - } - for _key_0, _val_0 in pairs(_parent_0.__base) do - if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then - _base_0[_key_0] = _val_0 - end - end - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - setmetatable(_base_0, _parent_0.__base) - _class_0 = setmetatable({ - __init = function(self, ...) - return _class_0.__parent.__init(self, ...) - end, - __base = _base_0, - __name = "MyClass", - __parent = _parent_0 - }, { - __index = function(cls, name) - local val = rawget(_base_0, name) - if val == nil then - local parent = rawget(cls, "__parent") - if parent then - return parent[name] - end - else - return val +local _class_0 +local _parent_0 = ParentClass +local _base_0 = { + a_method = function(self) + _class_0.__parent.__base.a_method(self, "你好", "世界") + _class_0.__parent.a_method(self, "你好", "世界") + _class_0.__parent.a_method(self, "你好", "世界") + return assert(_class_0.__parent == ParentClass) + end +} +for _key_0, _val_0 in pairs(_parent_0.__base) do + if _base_0[_key_0] == nil and _key_0:match("^__") and not (_key_0 == "__index" and _val_0 == _parent_0.__base) then + _base_0[_key_0] = _val_0 + end +end +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +setmetatable(_base_0, _parent_0.__base) +_class_0 = setmetatable({ + __init = function(self, ...) + return _class_0.__parent.__init(self, ...) + end, + __base = _base_0, + __name = "MyClass", + __parent = _parent_0 +}, { + __index = function(cls, name) + local val = rawget(_base_0, name) + if val == nil then + local parent = rawget(cls, "__parent") + if parent then + return parent[name] end - end, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_0) - cls.__init(_self_0, ...) - return _self_0 + else + return val end - }) - _base_0.__class = _class_0 - if _parent_0.__inherited then - _parent_0.__inherited(_parent_0, _class_0) + end, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - MyClass = _class_0 +}) +_base_0.__class = _class_0 +if _parent_0.__inherited then + _parent_0.__inherited(_parent_0, _class_0) end +MyClass = _class_0 local b = BackPack() assert(b.__class == BackPack) print(BackPack.size) @@ -3725,61 +3589,57 @@ Counter() print(Counter.count) self.__class:hello(1, 2, 3, 4) local Things -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "Things" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Things" - }, { - __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; - self.class_var = "hello world" - Things = _class_0 -end +}) +_base_0.__class = _class_0 +local self = _class_0; +self.class_var = "hello world" +Things = _class_0 local MoreThings -do - local _class_0 - local secret, log - local _base_0 = { - some_method = function(self) - return log("hello world: " .. secret) - end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local secret, log +local _base_0 = { + some_method = function(self) + return log("hello world: " .. secret) end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "MoreThings" - }, { - __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; - secret = 123 - log = function(msg) - return print("LOG:", msg) +} +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "MoreThings" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - MoreThings = _class_0 +}) +_base_0.__class = _class_0 +local self = _class_0; +secret = 123 +log = function(msg) + return print("LOG:", msg) end +MoreThings = _class_0 assert(self == self) assert(self.__class == self.__class) local some_instance_method @@ -3813,32 +3673,30 @@ do _base_0.__class = _class_0 Something = _class_0 end -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local _base_0 = { } +if _base_0.__index == nil then + _base_0.__index = _base_0 +end +_class_0 = setmetatable({ + __init = function(self, foo, bar, biz, baz) + self.foo = foo + self.bar = bar + self.__class.biz = biz + self.__class.baz = baz + end, + __base = _base_0, + __name = "Something" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function(self, foo, bar, biz, baz) - self.foo = foo - self.bar = bar - self.__class.biz = biz - self.__class.baz = baz - end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 -end +}) +_base_0.__class = _class_0 +Something = _class_0 local new new = function(self, fieldA, fieldB) self.fieldA = fieldA @@ -3849,33 +3707,31 @@ local obj = new({ }, 123, "abc") print(obj) local x local Bucket -do - local _class_0 - local _base_0 = { - drops = 0, - add_drop = function(self) - self.drops = self.drops + 1 - end - } - if _base_0.__index == nil then - _base_0.__index = _base_0 +local _class_0 +local _base_0 = { + drops = 0, + add_drop = function(self) + self.drops = self.drops + 1 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Bucket" - }, { - __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 - Bucket = _class_0 - x = _class_0 +} +if _base_0.__index == nil then + _base_0.__index = _base_0 end +_class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Bucket" +}, { + __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 +Bucket = _class_0 +x = _class_0 local BigBucket do local _class_0 @@ -3927,27 +3783,25 @@ do end assert(Bucket.__name == "BigBucket") local x -do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "x" +}, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "x" - }, { - __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 - x = _class_0 -end +}) +_base_0.__class = _class_0 +x = _class_0 local MyIndex = { __index = { var = 1 @@ -4030,19 +3884,15 @@ end local y = Y() y:func() assert(y.__class.__parent ~= X) -do - local _with_0 = Person() - _with_0.name = "Oswald" - _with_0:add_relative(my_dad) - _with_0:save() - print(_with_0.name) -end +local _with_0 = Person() +_with_0.name = "Oswald" +_with_0:add_relative(my_dad) +_with_0:save() +print(_with_0.name) local file -do - local _with_0 = File("favorite_foods.txt") - _with_0:set_encoding("utf8") - file = _with_0 -end +local _with_0 = File("favorite_foods.txt") +_with_0:set_encoding("utf8") +file = _with_0 local create_person create_person = function(name, relatives) local _with_0 = Person() @@ -4058,22 +3908,18 @@ local me = create_person("Leaf", { mother, sister }) -do - local str = "你好" - print("原始:", str) - print("大写:", str:upper()) -end -do - local _with_0 = tb - _with_0[1] = 1 - print(_with_0[2]) - do - local _with_1 = _with_0[abc] - _with_1[3] = _with_1[2]:func() - _with_1["key-name"] = value - end - _with_0[#_with_0 + 1] = "abc" -end +local str = "你好" +print("原始:", str) +print("大写:", str:upper()) +local _with_0 = tb +_with_0[1] = 1 +print(_with_0[2]) +do + local _with_1 = _with_0[abc] + _with_1[3] = _with_1[2]:func() + _with_1["key-name"] = value +end +_with_0[#_with_0 + 1] = "abc" do local var = "hello" print(var) diff --git a/spec/outputs/compile_doc.lua b/spec/outputs/compile_doc.lua index 7597cb8..29f4aeb 100644 --- a/spec/outputs/compile_doc.lua +++ b/spec/outputs/compile_doc.lua @@ -19,31 +19,27 @@ for _index_0 = 1, #_list_0 do local text = _with_0:read("*a") local codes = { } for code in text:gmatch("```moonscript(.-)```") do - do - local result, err = to_lua(code, { - implicit_return_root = false, - reserve_line_number = false - }) - if result then - codes[#codes + 1] = result - elseif not err:match("macro exporting module only accepts macro definition") then - print(err) - os.exit(1) - end + local result, err = to_lua(code, { + implicit_return_root = false, + reserve_line_number = false + }) + if result then + codes[#codes + 1] = result + elseif not err:match("macro exporting module only accepts macro definition") then + print(err) + os.exit(1) end end for code in text:gmatch("
(.-)
") do - do - local result, err = to_lua(code:gsub("<", "<"):gsub(">", ">"), { - implicit_return_root = false, - reserve_line_number = false - }) - if result then - codes[#codes + 1] = result - else - print(err) - os.exit(1) - end + local result, err = to_lua(code:gsub("<", "<"):gsub(">", ">"), { + implicit_return_root = false, + reserve_line_number = false + }) + if result then + codes[#codes + 1] = result + else + print(err) + os.exit(1) end end local output = (function() diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua index acbf644..5a5aae5 100644 --- a/spec/outputs/cond.lua +++ b/spec/outputs/cond.lua @@ -113,17 +113,15 @@ local z = false if false then _ = one else - do - local x = true - if x then - _ = two + local x = true + if x then + _ = two + else + z = true + if z then + _ = three else - z = true - if z then - _ = three - else - _ = four - end + _ = four end end end @@ -131,33 +129,27 @@ local out if false then out = one else - do - local x = true - if x then - out = two + local x = true + if x then + out = two + else + z = true + if z then + out = three else - z = true - if z then - out = three - else - out = four - end + out = four end end end local kzy kzy = function() - do - local something = true - if something then - return 1 - else - do - local another = false - if another then - return 2 - end - end + local something = true + if something then + return 1 + else + local another = false + if another then + return 2 end end end @@ -314,12 +306,10 @@ do end end do - do - local _M = { } - if _M then - local Thing = _M.Thing - a, b = _M.a, _M.b - end + local _M = { } + if _M then + local Thing = _M.Thing + a, b = _M.a, _M.b end end do diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index 38f21ff..224ed2d 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua @@ -131,11 +131,9 @@ do end end do - do - local _with_0 = thing - local a, b = _with_0[1], _with_0[2] - print(a, b) - end + local _with_0 = thing + local a, b = _with_0[1], _with_0[2] + print(a, b) end do local thing = nil @@ -314,11 +312,9 @@ do _tmp_0 = _obj_0.func end if _tmp_0 == nil then - do - local _obj_0 = item - if _obj_0 ~= nil then - _tmp_0 = _obj_0.defVal - end + local _obj_0 = item + if _obj_0 ~= nil then + _tmp_0 = _obj_0.defVal end end a.b(function() @@ -449,11 +445,9 @@ do end local y1, y4 local y2, y3 - do - local _obj_0, _obj_1 = f2() - y1, y4 = f1(), _obj_1 - y2, y3 = _obj_0.y2, _obj_0.y3 - end + local _obj_0, _obj_1 = f2() + y1, y4 = f1(), _obj_1 + y2, y3 = _obj_0.y2, _obj_0.y3 end do local v1, v2, v3, v4 @@ -483,11 +477,9 @@ do end do local value, value_meta - do - local _obj_0 = tb - value = _obj_0[name] - value_meta = getmetatable(_obj_0)[name] - end + local _obj_0 = tb + value = _obj_0[name] + value_meta = getmetatable(_obj_0)[name] end do local tostring, add @@ -500,24 +492,22 @@ do end) end end - do - local _exp_0 = tb - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - local name, meta_field - do - local _obj_0 = getmetatable(_exp_0) - name = _obj_0.__name - meta_field = _obj_0["123"] - if name == nil then - name = "item" - end - end - if meta_field ~= nil then - print(name, meta_field) + local _exp_0 = tb + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + local name, meta_field + do + local _obj_0 = getmetatable(_exp_0) + name = _obj_0.__name + meta_field = _obj_0["123"] + if name == nil then + name = "item" end end + if meta_field ~= nil then + print(name, meta_field) + end end end do @@ -599,52 +589,50 @@ do print(add, field) end end - do - local _exp_0 = tb - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - do - local _obj_0 = _exp_0.c - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - do - local _obj_1 = getmetatable(_obj_0) - local _type_2 = type(_obj_1) - if "table" == _type_2 or "userdata" == _type_2 then - meta_field = _obj_1["abc"] - end + local _exp_0 = tb + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + do + local _obj_0 = _exp_0.c + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + do + local _obj_1 = getmetatable(_obj_0) + local _type_2 = type(_obj_1) + if "table" == _type_2 or "userdata" == _type_2 then + meta_field = _obj_1["abc"] end end end - if meta_field == nil then - meta_field = "def" - end + end + if meta_field == nil then + meta_field = "def" + end + do + local _obj_0 = getmetatable(_exp_0) do - local _obj_0 = getmetatable(_exp_0) - do - local _obj_1 = _obj_0[ [[any string]]] - local _type_1 = type(_obj_1) - if "table" == _type_1 or "userdata" == _type_1 then - abc = _obj_1.d - end - end - do - local _obj_1 = _obj_0['str'] - local _type_1 = type(_obj_1) - if "table" == _type_1 or "userdata" == _type_1 then - def = _obj_1.e - end - end - if abc == nil then - abc = 123 + local _obj_1 = _obj_0[ [[any string]]] + local _type_1 = type(_obj_1) + if "table" == _type_1 or "userdata" == _type_1 then + abc = _obj_1.d end - if def == nil then - def = { } + end + do + local _obj_1 = _obj_0['str'] + local _type_1 = type(_obj_1) + if "table" == _type_1 or "userdata" == _type_1 then + def = _obj_1.e end end - print(meta_field, abc, def) + if abc == nil then + abc = 123 + end + if def == nil then + def = { } + end end + print(meta_field, abc, def) end end return nil diff --git a/spec/outputs/funcs.lua b/spec/outputs/funcs.lua index c07989e..c1735c4 100644 --- a/spec/outputs/funcs.lua +++ b/spec/outputs/funcs.lua @@ -224,13 +224,11 @@ do if item.field then local value = item.field.get("abc") if value then - do - local _exp_0 = value:get() - if 123 == _exp_0 then - return false - elseif 456 == _exp_0 then - handle(item) - end + local _exp_0 = value:get() + if 123 == _exp_0 then + return false + elseif 456 == _exp_0 then + handle(item) end end end @@ -240,13 +238,11 @@ do if item.field then local value = item.field.get("abc") if value then - do - local _exp_0 = value:get() - if 123 == _exp_0 then - return false - elseif 456 == _exp_0 then - handle(item) - end + local _exp_0 = value:get() + if 123 == _exp_0 then + return false + elseif 456 == _exp_0 then + handle(item) end end end @@ -261,14 +257,12 @@ do local pwd = req.pwd if name ~= nil and pwd ~= nil then if name ~= "" then - do - local user = DB:queryUser(name, pwd) - if user then - if user.status == "available" then - return { - success = true - } - end + local user = DB:queryUser(name, pwd) + if user then + if user.status == "available" then + return { + success = true + } end end end diff --git a/spec/outputs/global.lua b/spec/outputs/global.lua index 930ecf6..7e74387 100644 --- a/spec/outputs/global.lua +++ b/spec/outputs/global.lua @@ -3,29 +3,27 @@ do cool = "dad" end do - do - local _class_0 - local _base_0 = { - umm = "cool" - } - if _base_0.__index == nil then - _base_0.__index = _base_0 - end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "Something" - }, { - __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 - Something = _class_0 + local _class_0 + local _base_0 = { + umm = "cool" + } + if _base_0.__index == nil then + _base_0.__index = _base_0 end + _class_0 = setmetatable({ + __init = function() end, + __base = _base_0, + __name = "Something" + }, { + __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 + Something = _class_0 end do local d diff --git a/spec/outputs/import.lua b/spec/outputs/import.lua index 270c7b7..ffe688b 100644 --- a/spec/outputs/import.lua +++ b/spec/outputs/import.lua @@ -30,16 +30,14 @@ do end if indent then local okay, well - do - local _obj_1 = tables[100] - okay, well = _obj_1.okay, (function() - local _base_0 = _obj_1 - local _fn_0 = _base_0.well - return _fn_0 and function(...) - return _fn_0(_base_0, ...) - end - end)() - end + local _obj_1 = tables[100] + okay, well = _obj_1.okay, (function() + local _base_0 = _obj_1 + local _fn_0 = _base_0.well + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end)() end do local a, b, c = z.a, z.b, z.c @@ -68,16 +66,14 @@ do item = _obj_1.item end local x1, y1, z1 - do - local _obj_1 = require("mymodule") - x1, y1, z1 = _obj_1.x1, _obj_1.y1, (function() - local _base_0 = _obj_1 - local _fn_0 = _base_0.z1 - return _fn_0 and function(...) - return _fn_0(_base_0, ...) - end - end)() - end + local _obj_1 = require("mymodule") + x1, y1, z1 = _obj_1.x1, _obj_1.y1, (function() + local _base_0 = _obj_1 + local _fn_0 = _base_0.z1 + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end)() end do local p @@ -86,16 +82,14 @@ do p = _obj_1.p end local x1, y1, z1 - do - local _obj_1 = require('mymodule') - x1, y1, z1 = _obj_1.x1, _obj_1.y1, (function() - local _base_0 = _obj_1 - local _fn_0 = _base_0.z1 - return _fn_0 and function(...) - return _fn_0(_base_0, ...) - end - end)() - end + local _obj_1 = require('mymodule') + x1, y1, z1 = _obj_1.x1, _obj_1.y1, (function() + local _base_0 = _obj_1 + local _fn_0 = _base_0.z1 + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end)() end do local a, b, c = z.a, z.b, z.c diff --git a/spec/outputs/local.lua b/spec/outputs/local.lua index 5004e75..5d215e0 100644 --- a/spec/outputs/local.lua +++ b/spec/outputs/local.lua @@ -98,50 +98,46 @@ do Five = 6 One = _class_0 end - do - local _class_0 - local No - 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 = "Two" - }, { - __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; - do - local _class_1 - local _base_1 = { } - if _base_1.__index == nil then - _base_1.__index = _base_1 - end - _class_1 = setmetatable({ - __init = function() end, - __base = _base_1, - __name = "No" - }, { - __index = _base_1, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_1) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_1.__class = _class_1 - No = _class_1 + local _class_0 + local No + 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 = "Two" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - Two = _class_0 + }) + _base_0.__class = _class_0 + local self = _class_0; + local _class_1 + local _base_1 = { } + if _base_1.__index == nil then + _base_1.__index = _base_1 end + _class_1 = setmetatable({ + __init = function() end, + __base = _base_1, + __name = "No" + }, { + __index = _base_1, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_1) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_1.__class = _class_1 + No = _class_1 + Two = _class_0 end do local _list_0 = { } diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua index 79ef789..40e27b9 100644 --- a/spec/outputs/loops.lua +++ b/spec/outputs/loops.lua @@ -297,17 +297,15 @@ end do for i = 1, 10 do repeat - do - local _with_0 = tb - if _with_0 ~= nil then - _with_0.a = 1 - if _with_0.b then - goto _continue_12 - end - do - if _with_0.c then - break - end + local _with_0 = tb + if _with_0 ~= nil then + _with_0.a = 1 + if _with_0.b then + goto _continue_12 + end + do + if _with_0.c then + break end end end diff --git a/spec/outputs/macro.lua b/spec/outputs/macro.lua index f18baed..2ee3e0a 100644 --- a/spec/outputs/macro.lua +++ b/spec/outputs/macro.lua @@ -1,4 +1,6 @@ -assert(item == nil) +do + assert(item == nil) +end local v = (item == nil) if f1() then print("OK") @@ -9,86 +11,86 @@ end local item do local _src_, _dst_ - do - _dst_ = { - pos = { }, - flags = flags:tonumber() - } - do - _src_ = self - _dst_.id = _src_.id - _dst_.connections = _src_.connections - _dst_.pos.x = _src_.pos.x - _dst_.pos.y = _src_.pos.y - _dst_.pos.z = _src_.pos.z - end - item = _dst_ - end + _dst_ = { + pos = { }, + flags = flags:tonumber() + } + _src_ = self + _dst_.id = _src_.id + _dst_.connections = _src_.connections + _dst_.pos.x = _src_.pos.x + _dst_.pos.y = _src_.pos.y + _dst_.pos.z = _src_.pos.z + item = _dst_ end if (x == "Apple" or x == "Pig" or x == "Dog") then print("exist") end -local _list_0 = (function() - local _accum_0 = { } - local _len_0 = 1 +do local _list_0 = (function() - local _accum_1 = { } - local _len_1 = 1 - local _list_0 = { - 1, - 2, - 3 - } + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = (function() + local _accum_1 = { } + local _len_1 = 1 + local _list_0 = { + 1, + 2, + 3 + } + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + _accum_1[_len_1] = _ * 2 + _len_1 = _len_1 + 1 + end + return _accum_1 + end)() for _index_0 = 1, #_list_0 do local _ = _list_0[_index_0] - _accum_1[_len_1] = _ * 2 - _len_1 = _len_1 + 1 + if _ > 4 then + _accum_0[_len_0] = _ + _len_0 = _len_0 + 1 + end end - return _accum_1 + return _accum_0 end)() for _index_0 = 1, #_list_0 do local _ = _list_0[_index_0] - if _ > 4 then - _accum_0[_len_0] = _ - _len_0 = _len_0 + 1 - end + print(_) end - return _accum_0 -end)() -for _index_0 = 1, #_list_0 do - local _ = _list_0[_index_0] - print(_) end -local _list_1 = (function() - local _accum_0 = { } - local _len_0 = 1 - local _list_1 = (function() - local _accum_1 = { } - local _len_1 = 1 - local _list_1 = { - 1, - 2, - 3 - } - for _index_0 = 1, #_list_1 do - local _ = _list_1[_index_0] - _accum_1[_len_1] = _ * 2 - _len_1 = _len_1 + 1 +do + local _list_0 = (function() + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = (function() + local _accum_1 = { } + local _len_1 = 1 + local _list_0 = { + 1, + 2, + 3 + } + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + _accum_1[_len_1] = _ * 2 + _len_1 = _len_1 + 1 + end + return _accum_1 + end)() + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + if _ > 4 then + _accum_0[_len_0] = _ + _len_0 = _len_0 + 1 + end end - return _accum_1 + return _accum_0 end)() - for _index_0 = 1, #_list_1 do - local _ = _list_1[_index_0] - if _ > 4 then - _accum_0[_len_0] = _ - _len_0 = _len_0 + 1 - end + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + print(_) end - return _accum_0 -end)() -for _index_0 = 1, #_list_1 do - local _ = _list_1[_index_0] - print(_) end local val do @@ -96,13 +98,13 @@ do do local _accum_0 = { } local _len_0 = 1 - local _list_2 = { + local _list_0 = { 1, 2, 3 } - for _index_0 = 1, #_list_2 do - local _ = _list_2[_index_0] + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] _accum_0[_len_0] = _ * 2 _len_0 = _len_0 + 1 end @@ -134,7 +136,9 @@ do end val = _4 end -(1 + 2):call(123) +do + (1 + 2):call(123) +end local res = (1 + 2) local f f = function(x) @@ -210,40 +214,44 @@ local a = ((((_({ return self * 2 end)):filter(function(self) return self > 3 -end)):value(); -((((_({ - 1, - 2, - 3, - 4, - -2, - 3 -})):chain()):map(function(self) - return self * 2 -end)):filter(function(self) - return self > 3 -end)):each(function(self) - return print(self) -end) +end)):value() +do + ((((_({ + 1, + 2, + 3, + 4, + -2, + 3 + })):chain()):map(function(self) + return self * 2 + end)):filter(function(self) + return self > 3 + end)):each(function(self) + return print(self) + end) +end local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()):SelectEnable()):SelectVisible()):TagEqual("fx")):Where(function(x) return x.name:EndsWith("(Clone)") end)):Destroy() do - local _1 - _1 = origin.transform.root.gameObject:Parents() - local _2 - _2 = _1:Descendants() - local _3 - _3 = _2:SelectEnable() - local _4 - _4 = _3:SelectVisible() - local _5 - _5 = _4:TagEqual("fx") - local _6 - _6 = _5:Where(function(x) - return x.name:EndsWith("(Clone)") - end) - _6:Destroy() + do + local _1 + _1 = origin.transform.root.gameObject:Parents() + local _2 + _2 = _1:Descendants() + local _3 + _3 = _2:SelectEnable() + local _4 + _4 = _3:SelectVisible() + local _5 + _5 = _4:TagEqual("fx") + local _6 + _6 = _5:Where(function(x) + return x.name:EndsWith("(Clone)") + end) + _6:Destroy() + end end origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) return x.name:EndsWith("(Clone)") @@ -278,7 +286,9 @@ print((setmetatable({ end })) print("current line: " .. tostring(268)) +do -- TODO +end do print(1) end @@ -293,5 +303,7 @@ _1 = function() end return _accum_0 end -print('abc') -return 123 +do + print('abc') + return 123 +end diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua index 9f95787..78de433 100644 --- a/spec/outputs/metatable.lua +++ b/spec/outputs/metatable.lua @@ -48,19 +48,17 @@ do end do local x, new, var, close, closeA, num, add, sub + local _obj_0, _obj_1 + x, _obj_0, _obj_1 = 123, a.b.c, func() + new, var = _obj_0.new, _obj_0.var do - local _obj_0, _obj_1 - x, _obj_0, _obj_1 = 123, a.b.c, func() - new, var = _obj_0.new, _obj_0.var - do - local _obj_2 = getmetatable(_obj_0) - close, closeA = _obj_2.__close, _obj_2.__close - end - num = _obj_1.num - do - local _obj_2 = getmetatable(_obj_1) - add, sub = _obj_2.__add, _obj_2.__sub - end + local _obj_2 = getmetatable(_obj_0) + close, closeA = _obj_2.__close, _obj_2.__close + end + num = _obj_1.num + do + local _obj_2 = getmetatable(_obj_1) + add, sub = _obj_2.__add, _obj_2.__sub end end setmetatable(a.b, { }) diff --git a/spec/outputs/multiline_chain.lua b/spec/outputs/multiline_chain.lua index 5edad88..ef64906 100644 --- a/spec/outputs/multiline_chain.lua +++ b/spec/outputs/multiline_chain.lua @@ -82,15 +82,13 @@ do _with_0:itemMethodC(i) end if not _with_0.b then - do - local _accum_0 = { } - local _len_0 = 1 - while _with_0.itemFieldD do - _accum_0[_len_0] = _with_0:itemNext():get() - _len_0 = _len_0 + 1 - end - _with_0.c = _accum_0 + local _accum_0 = { } + local _len_0 = 1 + while _with_0.itemFieldD do + _accum_0[_len_0] = _with_0:itemNext():get() + _len_0 = _len_0 + 1 end + _with_0.c = _accum_0 end end return nil diff --git a/spec/outputs/nil_coalescing.lua b/spec/outputs/nil_coalescing.lua index e1547df..2279853 100644 --- a/spec/outputs/nil_coalescing.lua +++ b/spec/outputs/nil_coalescing.lua @@ -1,23 +1,19 @@ do local a - do - local _exp_0 = b - if _exp_0 ~= nil then - a = _exp_0 - else - a = c - end + local _exp_0 = b + if _exp_0 ~= nil then + a = _exp_0 + else + a = c end end do local a - do - local _exp_0 = b - if _exp_0 ~= nil then - a = _exp_0.a - else - a = c.a - end + local _exp_0 = b + if _exp_0 ~= nil then + a = _exp_0.a + else + a = c.a end end do @@ -50,23 +46,21 @@ do end do local a - do - local _exp_0 = b - if _exp_0 ~= nil then - a = _exp_0 - else - do - local _exp_1 = c - if _exp_1 ~= nil then - a = _exp_1 - else - do - local _exp_2 = d - if _exp_2 ~= nil then - a = _exp_2 - else - a = e - end + local _exp_0 = b + if _exp_0 ~= nil then + a = _exp_0 + else + do + local _exp_1 = c + if _exp_1 ~= nil then + a = _exp_1 + else + do + local _exp_2 = d + if _exp_2 ~= nil then + a = _exp_2 + else + a = e end end end @@ -84,18 +78,14 @@ do end)()) end do - do - local _with_0 - do - local _exp_0 = funcA() - if _exp_0 ~= nil then - _with_0 = _exp_0 - else - _with_0 = funcB() - end - end - print(_with_0.field) + local _with_0 + local _exp_0 = funcA() + if _exp_0 ~= nil then + _with_0 = _exp_0 + else + _with_0 = funcB() end + print(_with_0.field) end do local a = 1 + 2 + (function() @@ -137,18 +127,16 @@ do end do local a - do - local _exp_0 = 1 - if _exp_0 ~= nil then - a = _exp_0 - else - do - local _exp_1 = 2 - if _exp_1 ~= nil then - a = _exp_1 - else - a = 3 - end + local _exp_0 = 1 + if _exp_0 ~= nil then + a = _exp_0 + else + do + local _exp_1 = 2 + if _exp_1 ~= nil then + a = _exp_1 + else + a = 3 end end end diff --git a/spec/outputs/stub.lua b/spec/outputs/stub.lua index ff867ba..a3a27e3 100644 --- a/spec/outputs/stub.lua +++ b/spec/outputs/stub.lua @@ -15,12 +15,10 @@ end print(fn()) print(x:val()); (function(...) - do - local _base_0 = hello(...) - local _fn_0 = _base_0.world - x = _fn_0 and function(...) - return _fn_0(_base_0, ...) - end + local _base_0 = hello(...) + local _fn_0 = _base_0.world + x = _fn_0 and function(...) + return _fn_0(_base_0, ...) end end)() return nil diff --git a/spec/outputs/switch.lua b/spec/outputs/switch.lua index bbdf794..e4dedc9 100644 --- a/spec/outputs/switch.lua +++ b/spec/outputs/switch.lua @@ -45,13 +45,11 @@ do end do local _with_0 = something - do - local _exp_0 = _with_0:value() - if _with_0.okay == _exp_0 then - local _ = "world" - else - local _ = "yesh" - end + local _exp_0 = _with_0:value() + if _with_0.okay == _exp_0 then + local _ = "world" + else + local _ = "yesh" end end fix(this) @@ -106,66 +104,64 @@ do } } } - do - local _type_0 = type(dict) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - local first = dict[1] - local one - do - local _obj_0 = dict[2] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - one = _obj_0[1] - end + local _type_0 = type(dict) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + local first = dict[1] + local one + do + local _obj_0 = dict[2] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + one = _obj_0[1] end - local two - do - local _obj_0 = dict[2] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - two = _obj_0[2] - end + end + local two + do + local _obj_0 = dict[2] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + two = _obj_0[2] end - local three - do - local _obj_0 = dict[2] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - three = _obj_0[3] - end + end + local three + do + local _obj_0 = dict[2] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + three = _obj_0[3] end - local c - do - local _obj_0 = dict.a - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - do - local _obj_1 = _obj_0.b - local _type_2 = type(_obj_1) - if "table" == _type_2 or "userdata" == _type_2 then - c = _obj_1.c - end + end + local c + do + local _obj_0 = dict.a + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + do + local _obj_1 = _obj_0.b + local _type_2 = type(_obj_1) + if "table" == _type_2 or "userdata" == _type_2 then + c = _obj_1.c end end end - local z - do - local _obj_0 = dict.x - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - do - local _obj_1 = _obj_0.y - local _type_2 = type(_obj_1) - if "table" == _type_2 or "userdata" == _type_2 then - z = _obj_1.z - end + end + local z + do + local _obj_0 = dict.x + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + do + local _obj_1 = _obj_0.y + local _type_2 = type(_obj_1) + if "table" == _type_2 or "userdata" == _type_2 then + z = _obj_1.z end end end - if first ~= nil and one ~= nil and two ~= nil and three ~= nil and c ~= nil and z ~= nil then - print(first, one, two, three, c, z) - end + end + if first ~= nil and one ~= nil and two ~= nil and three ~= nil and c ~= nil and z ~= nil then + print(first, one, two, three, c, z) end end end @@ -183,56 +179,54 @@ do } for _index_0 = 1, #items do local item = items[_index_0] - do - local _type_0 = type(item) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false + local _type_0 = type(item) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = item.x + local y = item.y + if x ~= nil and y ~= nil then + _match_0 = true + print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) + end + end + if not _match_0 then + local _match_1 = false if _tab_0 then - local x = item.x - local y = item.y - if x ~= nil and y ~= nil then - _match_0 = true - print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) + local width = item.width + local height = item.height + if width ~= nil and height ~= nil then + _match_1 = true + print("Size " .. tostring(width) .. ", " .. tostring(height)) end end - if not _match_0 then - local _match_1 = false - if _tab_0 then - local width = item.width - local height = item.height - if width ~= nil and height ~= nil then - _match_1 = true - print("Size " .. tostring(width) .. ", " .. tostring(height)) + if not _match_1 then + if false == item then + print("None") + else + local _match_2 = false + if _tab_0 then + local cls = item.__class + if cls ~= nil then + _match_2 = true + if ClassA == cls then + print("Object A") + elseif ClassB == cls then + print("Object B") + end + end end - end - if not _match_1 then - if false == item then - print("None") - else - local _match_2 = false + if not _match_2 then + local _match_3 = false if _tab_0 then - local cls = item.__class - if cls ~= nil then - _match_2 = true - if ClassA == cls then - print("Object A") - elseif ClassB == cls then - print("Object B") - end + local mt = getmetatable(item) + if mt ~= nil then + _match_3 = true + print("A table with metatable") end end - if not _match_2 then - local _match_3 = false - if _tab_0 then - local mt = getmetatable(item) - if mt ~= nil then - _match_3 = true - print("A table with metatable") - end - end - if not _match_3 then - print("item not accepted!") - end + if not _match_3 then + print("item not accepted!") end end end @@ -271,72 +265,66 @@ do end end end - do - local _type_0 = type(tb) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local a = tb.a - local b = tb.b - if a ~= nil and b ~= nil then - _match_0 = true - print(a, b) - end - end - if not _match_0 then - print("not matched") + local _type_0 = type(tb) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local a = tb.a + local b = tb.b + if a ~= nil and b ~= nil then + _match_0 = true + print(a, b) end end + if not _match_0 then + print("not matched") + end end do local tb = { x = "abc" } - do - local _type_0 = type(tb) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false + local _type_0 = type(tb) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = tb.x + local y = tb.y + if x ~= nil and y ~= nil then + _match_0 = true + print("x: " .. tostring(x) .. " with y: " .. tostring(y)) + end + end + if not _match_0 then if _tab_0 then local x = tb.x - local y = tb.y - if x ~= nil and y ~= nil then - _match_0 = true - print("x: " .. tostring(x) .. " with y: " .. tostring(y)) - end - end - if not _match_0 then - if _tab_0 then - local x = tb.x - if x ~= nil then - print("x: " .. tostring(x) .. " only") - end + if x ~= nil then + print("x: " .. tostring(x) .. " only") end end end end do local matched - do - local _exp_0 = tb - if 1 == _exp_0 then - matched = "1" - else - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local x = _exp_0.x - if x ~= nil then - _match_0 = true - matched = x - end + local _exp_0 = tb + if 1 == _exp_0 then + matched = "1" + else + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local x = _exp_0.x + if x ~= nil then + _match_0 = true + matched = x end - if not _match_0 then - if false == _exp_0 then - matched = "false" - else - matched = nil - end + end + if not _match_0 then + if false == _exp_0 then + matched = "false" + else + matched = nil end end end @@ -346,90 +334,84 @@ do if nil == _exp_0 then return "invalid" else - do - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local a = _exp_0.a - local b = _exp_0.b - if a ~= nil and b ~= nil then - _match_0 = true - return tostring(a + b) - end + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local a = _exp_0.a + local b = _exp_0.b + if a ~= nil and b ~= nil then + _match_0 = true + return tostring(a + b) end - if not _match_0 then - if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 or 4 == _exp_0 or 5 == _exp_0 then - return "number 1 - 5" - else - local _match_1 = false - if _tab_0 then - local matchAnyTable = _exp_0.matchAnyTable - if matchAnyTable == nil then - matchAnyTable = "fallback" - end - _match_1 = true - return matchAnyTable - end - if not _match_1 then - return "should not reach here unless it is not a table" + end + if not _match_0 then + if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 or 4 == _exp_0 or 5 == _exp_0 then + return "number 1 - 5" + else + local _match_1 = false + if _tab_0 then + local matchAnyTable = _exp_0.matchAnyTable + if matchAnyTable == nil then + matchAnyTable = "fallback" end + _match_1 = true + return matchAnyTable + end + if not _match_1 then + return "should not reach here unless it is not a table" end end end end end do - do - local _exp_0 = y - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - local mt = (function() - local _obj_0 = _exp_0.x - if _obj_0 ~= nil then - return getmetatable(_obj_0) - end - return nil - end)() - if mt ~= nil then - print(mt) + local _exp_0 = y + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + local mt = (function() + local _obj_0 = _exp_0.x + if _obj_0 ~= nil then + return getmetatable(_obj_0) end + return nil + end)() + if mt ~= nil then + print(mt) end end end do - do - local _exp_0 = tb - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local item - do - local _obj_0 = _exp_0[1] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - item = _obj_0[1] - end - end - if item ~= nil then - _match_0 = true - print(item) + local _exp_0 = tb + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local item + do + local _obj_0 = _exp_0[1] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + item = _obj_0[1] end end - if not _match_0 then - if _tab_0 then - local a = _exp_0[1] - local b = _exp_0[2] - if a == nil then - a = 1 - end - if b == nil then - b = "abc" - end - print(a, b) + if item ~= nil then + _match_0 = true + print(item) + end + end + if not _match_0 then + if _tab_0 then + local a = _exp_0[1] + local b = _exp_0[2] + if a == nil then + a = 1 + end + if b == nil then + b = "abc" end + print(a, b) end end end diff --git a/spec/outputs/syntax.lua b/spec/outputs/syntax.lua index 20b8469..cfe63eb 100644 --- a/spec/outputs/syntax.lua +++ b/spec/outputs/syntax.lua @@ -217,15 +217,11 @@ else end do local _with_0 = tb - do - local _obj_2 = _with_0.b.c - do - local _with_1 = vec - _with_1.x = 1 - _with_1.y = 2 - _obj_2[#_obj_2 + 1] = _with_1 - end - end + local _obj_2 = _with_0.b.c + local _with_1 = vec + _with_1.x = 1 + _with_1.y = 2 + _obj_2[#_obj_2 + 1] = _with_1 end do local _obj_2 = a.b.c.d:f().g diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua index 911f677..f358811 100644 --- a/spec/outputs/tables.lua +++ b/spec/outputs/tables.lua @@ -430,157 +430,141 @@ do end do local tbMixA - do - local _tab_0 = { } - local _obj_0 - do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 10 do - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end - _obj_0 = _accum_0 - end - local _idx_0 = 1 - for _key_0, _value_0 in pairs(_obj_0) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end + local _tab_0 = { } + local _obj_0 + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + _obj_0 = _accum_0 + local _idx_0 = 1 + for _key_0, _value_0 in pairs(_obj_0) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 end - _tab_0[#_tab_0 + 1] = 11 - tbMixA = _tab_0 end + _tab_0[#_tab_0 + 1] = 11 + tbMixA = _tab_0 end do local tbMixA - do - local _tab_0 = { } - local _obj_0 - do - local _accum_0 = { } - local _len_0 = 1 - for i = 1, 10 do - _accum_0[_len_0] = i - _len_0 = _len_0 + 1 - end - _obj_0 = _accum_0 - end - local _idx_0 = #_tab_0 + 1 - for _index_0 = 1, #_obj_0 do - local _value_0 = _obj_0[_index_0] - _tab_0[_idx_0] = _value_0 - _idx_0 = _idx_0 + 1 - end - _tab_0[#_tab_0 + 1] = 11 - tbMixA = _tab_0 + local _tab_0 = { } + local _obj_0 + local _accum_0 = { } + local _len_0 = 1 + for i = 1, 10 do + _accum_0[_len_0] = i + _len_0 = _len_0 + 1 + end + _obj_0 = _accum_0 + local _idx_0 = #_tab_0 + 1 + for _index_0 = 1, #_obj_0 do + local _value_0 = _obj_0[_index_0] + _tab_0[_idx_0] = _value_0 + _idx_0 = _idx_0 + 1 end + _tab_0[#_tab_0 + 1] = 11 + tbMixA = _tab_0 end do local tbMixB - do - local _tab_0 = { } - local _obj_0 = ... - local _idx_0 = 1 - for _key_0, _value_0 in pairs(_obj_0) do - if _idx_0 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_0 = _idx_0 + 1 - else - _tab_0[_key_0] = _value_0 - end + local _tab_0 = { } + local _obj_0 = ... + local _idx_0 = 1 + for _key_0, _value_0 in pairs(_obj_0) do + if _idx_0 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_0 = _idx_0 + 1 + else + _tab_0[_key_0] = _value_0 end - local _obj_1 = { - ... - } - local _idx_1 = 1 - for _key_0, _value_0 in pairs(_obj_1) do - if _idx_1 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_1 = _idx_1 + 1 - else - _tab_0[_key_0] = _value_0 - end + end + local _obj_1 = { + ... + } + local _idx_1 = 1 + for _key_0, _value_0 in pairs(_obj_1) do + if _idx_1 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_1 = _idx_1 + 1 + else + _tab_0[_key_0] = _value_0 end - local _obj_2 - do - local _tab_1 = { } - local _obj_3 = ... - local _idx_2 = 1 - for _key_0, _value_0 in pairs(_obj_3) do - if _idx_2 == _key_0 then - _tab_1[#_tab_1 + 1] = _value_0 - _idx_2 = _idx_2 + 1 - else - _tab_1[_key_0] = _value_0 - end - end - _obj_2 = _tab_1 + end + local _obj_2 + local _tab_1 = { } + local _obj_3 = ... + local _idx_2 = 1 + for _key_0, _value_0 in pairs(_obj_3) do + if _idx_2 == _key_0 then + _tab_1[#_tab_1 + 1] = _value_0 + _idx_2 = _idx_2 + 1 + else + _tab_1[_key_0] = _value_0 end - local _idx_2 = 1 - for _key_0, _value_0 in pairs(_obj_2) do - if _idx_2 == _key_0 then - _tab_0[#_tab_0 + 1] = _value_0 - _idx_2 = _idx_2 + 1 - else - _tab_0[_key_0] = _value_0 - end + end + _obj_2 = _tab_1 + local _idx_2 = 1 + for _key_0, _value_0 in pairs(_obj_2) do + if _idx_2 == _key_0 then + _tab_0[#_tab_0 + 1] = _value_0 + _idx_2 = _idx_2 + 1 + else + _tab_0[_key_0] = _value_0 end - _tab_0[#_tab_0 + 1] = 1 - _tab_0[#_tab_0 + 1] = 2 - _tab_0[#_tab_0 + 1] = 3 - tbMixB = _tab_0 end + _tab_0[#_tab_0 + 1] = 1 + _tab_0[#_tab_0 + 1] = 2 + _tab_0[#_tab_0 + 1] = 3 + tbMixB = _tab_0 end do local tbMixB - do - local _tab_0 = { } - local _obj_0 = ... - local _idx_0 = #_tab_0 + 1 - for _index_0 = 1, #_obj_0 do - local _value_0 = _obj_0[_index_0] - _tab_0[_idx_0] = _value_0 - _idx_0 = _idx_0 + 1 - end - local _obj_1 = { - ... - } - local _idx_1 = #_tab_0 + 1 - for _index_0 = 1, #_obj_1 do - local _value_0 = _obj_1[_index_0] - _tab_0[_idx_1] = _value_0 - _idx_1 = _idx_1 + 1 - end - local _obj_2 - do - local _tab_1 = { } - local _obj_3 = ... - local _idx_2 = 1 - for _key_0, _value_0 in pairs(_obj_3) do - if _idx_2 == _key_0 then - _tab_1[#_tab_1 + 1] = _value_0 - _idx_2 = _idx_2 + 1 - else - _tab_1[_key_0] = _value_0 - end - end - _obj_2 = _tab_1 - end - local _idx_2 = #_tab_0 + 1 - for _index_0 = 1, #_obj_2 do - local _value_0 = _obj_2[_index_0] - _tab_0[_idx_2] = _value_0 + local _tab_0 = { } + local _obj_0 = ... + local _idx_0 = #_tab_0 + 1 + for _index_0 = 1, #_obj_0 do + local _value_0 = _obj_0[_index_0] + _tab_0[_idx_0] = _value_0 + _idx_0 = _idx_0 + 1 + end + local _obj_1 = { + ... + } + local _idx_1 = #_tab_0 + 1 + for _index_0 = 1, #_obj_1 do + local _value_0 = _obj_1[_index_0] + _tab_0[_idx_1] = _value_0 + _idx_1 = _idx_1 + 1 + end + local _obj_2 + local _tab_1 = { } + local _obj_3 = ... + local _idx_2 = 1 + for _key_0, _value_0 in pairs(_obj_3) do + if _idx_2 == _key_0 then + _tab_1[#_tab_1 + 1] = _value_0 _idx_2 = _idx_2 + 1 + else + _tab_1[_key_0] = _value_0 end - _tab_0[#_tab_0 + 1] = 1 - _tab_0[#_tab_0 + 1] = 2 - _tab_0[#_tab_0 + 1] = 3 - tbMixB = _tab_0 end + _obj_2 = _tab_1 + local _idx_2 = #_tab_0 + 1 + for _index_0 = 1, #_obj_2 do + local _value_0 = _obj_2[_index_0] + _tab_0[_idx_2] = _value_0 + _idx_2 = _idx_2 + 1 + end + _tab_0[#_tab_0 + 1] = 1 + _tab_0[#_tab_0 + 1] = 2 + _tab_0[#_tab_0 + 1] = 3 + tbMixB = _tab_0 end local template = { foo = "Hello", diff --git a/spec/outputs/test/format_spec.lua b/spec/outputs/test/format_spec.lua index 33a85f2..ed0fbee 100644 --- a/spec/outputs/test/format_spec.lua +++ b/spec/outputs/test/format_spec.lua @@ -101,16 +101,14 @@ rewriteLineCol = function(item) item[2] = 0 item[3] = 0 for i = 4, #item do - do - local _exp_0 = type(item[i]) - if "table" == _exp_0 then - if item[i][1] == "comment" then - table.remove(item, i) - rewriteLineCol(item) - return - end - rewriteLineCol(item[i]) + local _exp_0 = type(item[i]) + if "table" == _exp_0 then + if item[i][1] == "comment" then + table.remove(item, i) + rewriteLineCol(item) + return end + rewriteLineCol(item[i]) end end end diff --git a/spec/outputs/unicode/ambiguous.lua b/spec/outputs/unicode/ambiguous.lua index 3783026..ac90016 100644 --- a/spec/outputs/unicode/ambiguous.lua +++ b/spec/outputs/unicode/ambiguous.lua @@ -13,11 +13,17 @@ _u53d8_u91cfa, _u53d8_u91cfb = _u53d8_u91cfc, _u53d8_u91cfd; (_u53d8_u91cfd(_u53d8_u91cfa))(_u53d8_u91cfc) for _u8ba1_u6570 = 1, 10 do _u53d8_u91cfa = function() end - (_u6253_u5370)(1) - _u53d8_u91cfa = _u53d8_u91cff; - (_u6253_u5370)(2) + do + (_u6253_u5370)(1) + end + _u53d8_u91cfa = _u53d8_u91cff + do + (_u6253_u5370)(2) + end if _u6761_u4ef6 then - (_u6253_u5370)(3) + do + (_u6253_u5370)(3) + end end ::_u8df3_u8f6c_u4f4d_u7f6e::; (_u6253_u5370)(4) @@ -40,7 +46,9 @@ do end) end do - _u6253_u5370(123) + do + _u6253_u5370(123) + end end do _u51fd_u6570f({ @@ -97,18 +105,16 @@ do _u6570_u5b57_u6570_u7ec4 = _accum_0 end local _u5bf9_u8c61_u6570_u7ec4 - do - local _accum_0 = { } - local _len_0 = 1 - local _list_0 = _u7269_u4ef6_u6570_u7ec4 - for _index_0 = 1, #_list_0 do - local _u7269_u4ef6 = _list_0[_index_0] - _accum_0[_len_0] = { - ["名称"] = _u7269_u4ef6 - } - _len_0 = _len_0 + 1 - end - _u5bf9_u8c61_u6570_u7ec4 = _accum_0 + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = _u7269_u4ef6_u6570_u7ec4 + for _index_0 = 1, #_list_0 do + local _u7269_u4ef6 = _list_0[_index_0] + _accum_0[_len_0] = { + ["名称"] = _u7269_u4ef6 + } + _len_0 = _len_0 + 1 end + _u5bf9_u8c61_u6570_u7ec4 = _accum_0 end return nil diff --git a/spec/outputs/unicode/assign.lua b/spec/outputs/unicode/assign.lua index 290b248..16ece1a 100644 --- a/spec/outputs/unicode/assign.lua +++ b/spec/outputs/unicode/assign.lua @@ -52,18 +52,16 @@ return __u65e0_u6548_u53d8_u91cf(function() setmetatable(a_u53d8_u91cf, _anon_func_0(_u6253_u5370)) do local _u5143_u7d20a, _u5143_u7d20b - do - local _exp_0 = _u5bf9_u8c61c - if "a" == _exp_0 then - do - local _obj_0 = _u5b57_u5178 - _u5143_u7d20a, _u5143_u7d20b = _obj_0[1], _obj_0[2] - end - elseif "b" == _exp_0 then - do - local _obj_0 = _u51fd_u6570() - _u5143_u7d20a, _u5143_u7d20b = _obj_0[1], _obj_0[2] - end + local _exp_0 = _u5bf9_u8c61c + if "a" == _exp_0 then + do + local _obj_0 = _u5b57_u5178 + _u5143_u7d20a, _u5143_u7d20b = _obj_0[1], _obj_0[2] + end + elseif "b" == _exp_0 then + do + local _obj_0 = _u51fd_u6570() + _u5143_u7d20a, _u5143_u7d20b = _obj_0[1], _obj_0[2] end end end @@ -78,15 +76,11 @@ return __u65e0_u6548_u53d8_u91cf(function() do local _u53d8_u91cfa if x_u6761_u4ef6 then - do - local _exp_0 = _u5bf9_u8c61y - if 1 == _exp_0 then - do - local _obj_0, _obj_1 = _u51fd_u6570() - _u53d8_u91cfb[#_u53d8_u91cfb + 1] = _obj_1 - _u53d8_u91cfa = _obj_0 - end - end + local _exp_0 = _u5bf9_u8c61y + if 1 == _exp_0 then + local _obj_0, _obj_1 = _u51fd_u6570() + _u53d8_u91cfb[#_u53d8_u91cfb + 1] = _obj_1 + _u53d8_u91cfa = _obj_0 end end end @@ -94,11 +88,9 @@ return __u65e0_u6548_u53d8_u91cf(function() local _u53d8_u91cfa local _u5143_u7d20b if x_u6761_u4ef6 then - do - local _obj_0, _obj_1 = _u51fd_u6570() - _u53d8_u91cfa = _obj_0 - _u5143_u7d20b = _obj_1[1] - end + local _obj_0, _obj_1 = _u51fd_u6570() + _u53d8_u91cfa = _obj_0 + _u5143_u7d20b = _obj_1[1] else _u53d8_u91cfa = 123 _u5143_u7d20b = _u8868[1] @@ -107,42 +99,28 @@ return __u65e0_u6548_u53d8_u91cf(function() do local _u53d8_u91cfa, _u5bf9_u8c61c if _u6761_u4ef6x then - do - local _exp_0 = _u5bf9_u8c61y - if 1 == _exp_0 then - do - local _obj_0, _obj_1, _obj_2, _obj_3 = _u51fd_u6570() - do - local _obj_4 = _u6570_u7ec4b - _obj_4[#_obj_4 + 1] = _obj_1 - end - _u53d8_u91cfa, _u5bf9_u8c61c, getmetatable(_u5bf9_u8c61d).__add = _obj_0, _obj_2, _obj_3 - end - end + local _exp_0 = _u5bf9_u8c61y + if 1 == _exp_0 then + local _obj_0, _obj_1, _obj_2, _obj_3 = _u51fd_u6570() + local _obj_4 = _u6570_u7ec4b + _obj_4[#_obj_4 + 1] = _obj_1 + _u53d8_u91cfa, _u5bf9_u8c61c, getmetatable(_u5bf9_u8c61d).__add = _obj_0, _obj_2, _obj_3 end elseif _u6761_u4ef6x2 then if _u6761_u4ef6y2 then - do - local _obj_0, _obj_1, _obj_2, _obj_3 = _u51fd_u65701() - do - local _obj_4 = _u6570_u7ec4b - _obj_4[#_obj_4 + 1] = _obj_1 - end - _u53d8_u91cfa, _u5bf9_u8c61c, getmetatable(_u5bf9_u8c61d).__add = _obj_0, _obj_2, _obj_3 - end + local _obj_0, _obj_1, _obj_2, _obj_3 = _u51fd_u65701() + local _obj_4 = _u6570_u7ec4b + _obj_4[#_obj_4 + 1] = _obj_1 + _u53d8_u91cfa, _u5bf9_u8c61c, getmetatable(_u5bf9_u8c61d).__add = _obj_0, _obj_2, _obj_3 end else _u6253_u5370("hello") do _u6253_u5370(123) - do - local _obj_0, _obj_1, _obj_2 = _u51fd_u65702() - do - local _obj_3 = _u6570_u7ec4b - _obj_3[#_obj_3 + 1] = _obj_0 - end - _u53d8_u91cfa, _u5bf9_u8c61c, getmetatable(_u5bf9_u8c61d).__add = 1, _obj_1, _obj_2 - end + local _obj_0, _obj_1, _obj_2 = _u51fd_u65702() + local _obj_3 = _u6570_u7ec4b + _obj_3[#_obj_3 + 1] = _obj_0 + _u53d8_u91cfa, _u5bf9_u8c61c, getmetatable(_u5bf9_u8c61d).__add = 1, _obj_1, _obj_2 end end end diff --git a/spec/outputs/unicode/attrib.lua b/spec/outputs/unicode/attrib.lua index 0f60451..58ad4b2 100644 --- a/spec/outputs/unicode/attrib.lua +++ b/spec/outputs/unicode/attrib.lua @@ -14,20 +14,16 @@ end do local _u5e38_u91cfa = _u51fd_u6570() local _u5143_u7d20b, _u5143_u7d20c, _u5143_u7d20d - do - local _obj_0, _obj_1 = _u51fd_u65701() - _u5143_u7d20b, _u5143_u7d20c = _obj_0[1], _obj_0[2] - _u5143_u7d20d = _obj_1[1] - end + local _obj_0, _obj_1 = _u51fd_u65701() + _u5143_u7d20b, _u5143_u7d20c = _obj_0[1], _obj_0[2] + _u5143_u7d20d = _obj_1[1] end do local _u5e38_u91cfa, _u5143_u7d20b, _u5143_u7d20c, _u5143_u7d20d - do - local _obj_0, _obj_1, _obj_2 = _u51fd_u6570() - _u5e38_u91cfa = _obj_0 - _u5143_u7d20b, _u5143_u7d20c = _obj_1[1], _obj_1[2] - _u5143_u7d20d = _obj_2[1] - end + local _obj_0, _obj_1, _obj_2 = _u51fd_u6570() + _u5e38_u91cfa = _obj_0 + _u5143_u7d20b, _u5143_u7d20c = _obj_1[1], _obj_1[2] + _u5143_u7d20d = _obj_2[1] end do local _u5173_u95ed_u53d8_u91cfv = (function() diff --git a/spec/outputs/unicode/backcall.lua b/spec/outputs/unicode/backcall.lua index 91dfdff..f4bd5a3 100644 --- a/spec/outputs/unicode/backcall.lua +++ b/spec/outputs/unicode/backcall.lua @@ -31,21 +31,19 @@ do end)()) end do - do - local _obj_0 = _u7f51_u7edc - if _obj_0 ~= nil then - _obj_0["获取"]("测试地址", function(_u6570_u636e) - local _call_0 = _u7f51_u9875_u4f53[".结果"] - _call_0["网页"](_call_0, _u6570_u636e) - return _u7f51_u7edc["请求"]("测试地址", _u6570_u636e, function(_u662f_u5426_u5904_u7406_u6210_u529f) - local _call_1 = _u7f51_u9875_u4f53[".结果"] - _call_1["添加"](_call_1, _u662f_u5426_u5904_u7406_u6210_u679c) - return _u8bbe_u7f6e_u8d85_u65f6_u56de_u8c03(1000, function() - return _u6253_u5370("完成") - end) + local _obj_0 = _u7f51_u7edc + if _obj_0 ~= nil then + _obj_0["获取"]("测试地址", function(_u6570_u636e) + local _call_0 = _u7f51_u9875_u4f53[".结果"] + _call_0["网页"](_call_0, _u6570_u636e) + return _u7f51_u7edc["请求"]("测试地址", _u6570_u636e, function(_u662f_u5426_u5904_u7406_u6210_u529f) + local _call_1 = _u7f51_u9875_u4f53[".结果"] + _call_1["添加"](_call_1, _u662f_u5426_u5904_u7406_u6210_u679c) + return _u8bbe_u7f6e_u8d85_u65f6_u56de_u8c03(1000, function() + return _u6253_u5370("完成") end) end) - end + end) end end do diff --git a/spec/outputs/unicode/bubbling.lua b/spec/outputs/unicode/bubbling.lua index cb8750d..55666ba 100644 --- a/spec/outputs/unicode/bubbling.lua +++ b/spec/outputs/unicode/bubbling.lua @@ -109,15 +109,13 @@ __u65e0_u6548_u53d8_u91cf = function(...) _u6570_u7ec4a = _accum_0 end local _u6570_u7ec4b - do - local _accum_0 = { } - local _len_0 = 1 - for _u8ba1_u6570 = 1, 10 do - _accum_0[_len_0] = function(...) - return _u6253_u5370(...) - end - _len_0 = _len_0 + 1 + local _accum_0 = { } + local _len_0 = 1 + for _u8ba1_u6570 = 1, 10 do + _accum_0[_len_0] = function(...) + return _u6253_u5370(...) end - _u6570_u7ec4b = _accum_0 + _len_0 = _len_0 + 1 end + _u6570_u7ec4b = _accum_0 end diff --git a/spec/outputs/unicode/class.lua b/spec/outputs/unicode/class.lua index 4d309e3..23fc8f4 100644 --- a/spec/outputs/unicode/class.lua +++ b/spec/outputs/unicode/class.lua @@ -497,30 +497,28 @@ _u6253_u5370("你好") local _u53d8_u91cfyyy _u53d8_u91cfyyy = function() local _u9177 - 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 = "酷" - }, { - __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 - _u9177 = _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 = "酷" + }, { + __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 + _u9177 = _class_0 + return _class_0 end do local _class_0 diff --git a/spec/outputs/unicode/cond.lua b/spec/outputs/unicode/cond.lua index ed5d274..2b5af8a 100644 --- a/spec/outputs/unicode/cond.lua +++ b/spec/outputs/unicode/cond.lua @@ -113,19 +113,15 @@ local z_u53d8_u91cf = false if false then __u65e0_u6548_u53d8_u91cf = _u4e00 else - do - local _u6761_u4ef6x = true - if _u6761_u4ef6x then - __u65e0_u6548_u53d8_u91cf = _u4e8c + local _u6761_u4ef6x = true + if _u6761_u4ef6x then + __u65e0_u6548_u53d8_u91cf = _u4e8c + else + local _u6761_u4ef6z = true + if _u6761_u4ef6z then + __u65e0_u6548_u53d8_u91cf = _u4e09 else - do - local _u6761_u4ef6z = true - if _u6761_u4ef6z then - __u65e0_u6548_u53d8_u91cf = _u4e09 - else - __u65e0_u6548_u53d8_u91cf = _u56db - end - end + __u65e0_u6548_u53d8_u91cf = _u56db end end end @@ -133,35 +129,27 @@ local _u8f93_u51fa if false then _u8f93_u51fa = _u4e00 else - do - local _u6761_u4ef6x = true - if _u6761_u4ef6x then - _u8f93_u51fa = _u4e8c + local _u6761_u4ef6x = true + if _u6761_u4ef6x then + _u8f93_u51fa = _u4e8c + else + local _u6761_u4ef6z = true + if _u6761_u4ef6z then + _u8f93_u51fa = _u4e09 else - do - local _u6761_u4ef6z = true - if _u6761_u4ef6z then - _u8f93_u51fa = _u4e09 - else - _u8f93_u51fa = _u56db - end - end + _u8f93_u51fa = _u56db end end end local _u53d8_u91cf _u53d8_u91cf = function() - do - local _u67d0_u4e1c_u897f = true - if _u67d0_u4e1c_u897f then - return 1 - else - do - local _u53e6_u4e00_u4e2a = false - if _u53e6_u4e00_u4e2a then - return 2 - end - end + local _u67d0_u4e1c_u897f = true + if _u67d0_u4e1c_u897f then + return 1 + else + local _u53e6_u4e00_u4e2a = false + if _u53e6_u4e00_u4e2a then + return 2 end end end @@ -319,12 +307,10 @@ do end end do - do - local __u6a21_u5757 = { } - if __u6a21_u5757 then - local _u4e1c_u897f = __u6a21_u5757["东西"] - local a_u529f_u80fd, b_u529f_u80fd = __u6a21_u5757["a功能"], __u6a21_u5757["b功能"] - end + local __u6a21_u5757 = { } + if __u6a21_u5757 then + local _u4e1c_u897f = __u6a21_u5757["东西"] + local a_u529f_u80fd, b_u529f_u80fd = __u6a21_u5757["a功能"], __u6a21_u5757["b功能"] end end do diff --git a/spec/outputs/unicode/destructure.lua b/spec/outputs/unicode/destructure.lua index 002c4b0..7263d49 100644 --- a/spec/outputs/unicode/destructure.lua +++ b/spec/outputs/unicode/destructure.lua @@ -127,11 +127,9 @@ do end end do - do - local _with_0 = _u4e1c_u897f - local _u5143_u7d20a, _u5143_u7d20b = _with_0[1], _with_0[2] - _u6253_u5370(_u5143_u7d20a, _u5143_u7d20b) - end + local _with_0 = _u4e1c_u897f + local _u5143_u7d20a, _u5143_u7d20b = _with_0[1], _with_0[2] + _u6253_u5370(_u5143_u7d20a, _u5143_u7d20b) end do local _u4e1c_u897f = nil @@ -320,11 +318,9 @@ do _tmp_0 = _obj_0["函数"] end if _tmp_0 == nil then - do - local _obj_0 = _u9879_u76ee - if _obj_0 ~= nil then - _tmp_0 = _obj_0["默认值"] - end + local _obj_0 = _u9879_u76ee + if _obj_0 ~= nil then + _tmp_0 = _obj_0["默认值"] end end a_u5bf9_u8c61["b字段"](function() @@ -436,11 +432,9 @@ do end local _u53d8_u91cfy1, _u53d8_u91cfy4 local _u5b57_u6bb5y2, _u5b57_u6bb5y3 - do - local _obj_0, _obj_1 = _u51fd_u65702() - _u53d8_u91cfy1, _u53d8_u91cfy4 = _u51fd_u65701(), _obj_1 - _u5b57_u6bb5y2, _u5b57_u6bb5y3 = _obj_0["字段y2"], _obj_0["字段y3"] - end + local _obj_0, _obj_1 = _u51fd_u65702() + _u53d8_u91cfy1, _u53d8_u91cfy4 = _u51fd_u65701(), _obj_1 + _u5b57_u6bb5y2, _u5b57_u6bb5y3 = _obj_0["字段y2"], _obj_0["字段y3"] end do local _u53d8_u91cfv1, _u53d8_u91cfv2, _u53d8_u91cfv3, _u53d8_u91cfv4 @@ -470,11 +464,9 @@ do end do local _u503c, _u5143_u503c - do - local _obj_0 = _u5bf9_u8c61tb - _u503c = _obj_0[_u540d_u79f0] - _u5143_u503c = getmetatable(_obj_0)[_u540d_u79f0] - end + local _obj_0 = _u5bf9_u8c61tb + _u503c = _obj_0[_u540d_u79f0] + _u5143_u503c = getmetatable(_obj_0)[_u540d_u79f0] end do local tostring, add @@ -487,24 +479,22 @@ do end) end end - do - local _exp_0 = _u5bf9_u8c61tb - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - local name, _u5143_u5b57_u6bb5 - do - local _obj_0 = getmetatable(_exp_0) - name = _obj_0.__name - _u5143_u5b57_u6bb5 = _obj_0["123"] - if name == nil then - name = "项目" - end - end - if _u5143_u5b57_u6bb5 ~= nil then - _u6253_u5370(name, _u5143_u5b57_u6bb5) + local _exp_0 = _u5bf9_u8c61tb + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + local name, _u5143_u5b57_u6bb5 + do + local _obj_0 = getmetatable(_exp_0) + name = _obj_0.__name + _u5143_u5b57_u6bb5 = _obj_0["123"] + if name == nil then + name = "项目" end end + if _u5143_u5b57_u6bb5 ~= nil then + _u6253_u5370(name, _u5143_u5b57_u6bb5) + end end end do @@ -586,52 +576,50 @@ do _u6253_u5370(add, _u5b57_u6bb5) end end - do - local _exp_0 = tb - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - do - local _obj_0 = _exp_0["字段c"] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - do - local _obj_1 = getmetatable(_obj_0) - local _type_2 = type(_obj_1) - if "table" == _type_2 or "userdata" == _type_2 then - _u5143_u5b57_u6bb5 = _obj_1["字段abc"] - end + local _exp_0 = tb + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + do + local _obj_0 = _exp_0["字段c"] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + do + local _obj_1 = getmetatable(_obj_0) + local _type_2 = type(_obj_1) + if "table" == _type_2 or "userdata" == _type_2 then + _u5143_u5b57_u6bb5 = _obj_1["字段abc"] end end end - if _u5143_u5b57_u6bb5 == nil then - _u5143_u5b57_u6bb5 = "默认值" - end + end + if _u5143_u5b57_u6bb5 == nil then + _u5143_u5b57_u6bb5 = "默认值" + end + do + local _obj_0 = getmetatable(_exp_0) do - local _obj_0 = getmetatable(_exp_0) - do - local _obj_1 = _obj_0[ [[any string]]] - local _type_1 = type(_obj_1) - if "table" == _type_1 or "userdata" == _type_1 then - _u53d8_u91cfabc = _obj_1["字段d"] - end - end - do - local _obj_1 = _obj_0['字符串'] - local _type_1 = type(_obj_1) - if "table" == _type_1 or "userdata" == _type_1 then - _u6709_u9ed8_u8ba4_u503c = _obj_1["字段e"] - end - end - if _u53d8_u91cfabc == nil then - _u53d8_u91cfabc = 123 + local _obj_1 = _obj_0[ [[any string]]] + local _type_1 = type(_obj_1) + if "table" == _type_1 or "userdata" == _type_1 then + _u53d8_u91cfabc = _obj_1["字段d"] end - if _u6709_u9ed8_u8ba4_u503c == nil then - _u6709_u9ed8_u8ba4_u503c = { } + end + do + local _obj_1 = _obj_0['字符串'] + local _type_1 = type(_obj_1) + if "table" == _type_1 or "userdata" == _type_1 then + _u6709_u9ed8_u8ba4_u503c = _obj_1["字段e"] end end - _u6253_u5370(_u5143_u5b57_u6bb5, _u53d8_u91cfabc, _u6709_u9ed8_u8ba4_u503c) + if _u53d8_u91cfabc == nil then + _u53d8_u91cfabc = 123 + end + if _u6709_u9ed8_u8ba4_u503c == nil then + _u6709_u9ed8_u8ba4_u503c = { } + end end + _u6253_u5370(_u5143_u5b57_u6bb5, _u53d8_u91cfabc, _u6709_u9ed8_u8ba4_u503c) end end return nil diff --git a/spec/outputs/unicode/global.lua b/spec/outputs/unicode/global.lua index c91db52..a34ce6d 100644 --- a/spec/outputs/unicode/global.lua +++ b/spec/outputs/unicode/global.lua @@ -3,29 +3,27 @@ do _u9177 = "📉" end do - 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 = "全局类" - }, { - __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 - _u5168_u5c40_u7c7b = _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 = "全局类" + }, { + __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 + _u5168_u5c40_u7c7b = _class_0 end do local _u53d8_u91cfc, _u53d8_u91cfd diff --git a/spec/outputs/unicode/import.lua b/spec/outputs/unicode/import.lua index 3499295..e4aec89 100644 --- a/spec/outputs/unicode/import.lua +++ b/spec/outputs/unicode/import.lua @@ -30,16 +30,14 @@ do end if _u7f29_u8fdb then local _u597d_u5427, _u5f88_u597d - do - local _obj_1 = _u5f88_u591a_u8868[100] - _u597d_u5427, _u5f88_u597d = _obj_1["好吧"], (function() - local _base_0 = _obj_1 - local _fn_0 = _base_0["很好"] - return _fn_0 and function(...) - return _fn_0(_base_0, ...) - end - end)() - end + local _obj_1 = _u5f88_u591a_u8868[100] + _u597d_u5427, _u5f88_u597d = _obj_1["好吧"], (function() + local _base_0 = _obj_1 + local _fn_0 = _base_0["很好"] + return _fn_0 and function(...) + return _fn_0(_base_0, ...) + end + end)() end do local _u5b57_u6bb5a, _u5b57_u6bb5b, _u5b57_u6bb5c = _u5bf9_u8c61z["字段a"], _u5bf9_u8c61z["字段b"], _u5bf9_u8c61z["字段c"] diff --git a/spec/outputs/unicode/in_expression.lua b/spec/outputs/unicode/in_expression.lua index 2f47b1f..4b8f711 100644 --- a/spec/outputs/unicode/in_expression.lua +++ b/spec/outputs/unicode/in_expression.lua @@ -173,10 +173,8 @@ do _u51fd_u65704 = function() local _u53d8_u91cfa = 2 local _u53d8_u91cfb - do - local _val_0 = a - _u53d8_u91cfb = 1 == _val_0 or 2 == _val_0 or 3 == _val_0 or 4 == _val_0 - end + local _val_0 = a + _u53d8_u91cfb = 1 == _val_0 or 2 == _val_0 or 3 == _val_0 or 4 == _val_0 end local _u51fd_u65705 _u51fd_u65705 = function() diff --git a/spec/outputs/unicode/local.lua b/spec/outputs/unicode/local.lua index 170144b..4b4b366 100644 --- a/spec/outputs/unicode/local.lua +++ b/spec/outputs/unicode/local.lua @@ -98,50 +98,46 @@ do F_u4e94 = 6 O_u4e00 = _class_0 end - do - local _class_0 - local N_u65e0 - 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 = "T二" - }, { - __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; - do - local _class_1 - local _base_1 = { } - if _base_1.__index == nil then - _base_1.__index = _base_1 - end - _class_1 = setmetatable({ - __init = function() end, - __base = _base_1, - __name = "N无" - }, { - __index = _base_1, - __call = function(cls, ...) - local _self_0 = setmetatable({ }, _base_1) - cls.__init(_self_0, ...) - return _self_0 - end - }) - _base_1.__class = _class_1 - N_u65e0 = _class_1 + local _class_0 + local N_u65e0 + 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 = "T二" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - T_u4e8c = _class_0 + }) + _base_0.__class = _class_0 + local self = _class_0; + local _class_1 + local _base_1 = { } + if _base_1.__index == nil then + _base_1.__index = _base_1 end + _class_1 = setmetatable({ + __init = function() end, + __base = _base_1, + __name = "N无" + }, { + __index = _base_1, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_1) + cls.__init(_self_0, ...) + return _self_0 + end + }) + _base_1.__class = _class_1 + N_u65e0 = _class_1 + T_u4e8c = _class_0 end do local _list_0 = { } diff --git a/spec/outputs/unicode/loops.lua b/spec/outputs/unicode/loops.lua index d630343..8379993 100644 --- a/spec/outputs/unicode/loops.lua +++ b/spec/outputs/unicode/loops.lua @@ -297,17 +297,15 @@ end do for _u53d8_u91cfi = 1, 10 do repeat - do - local _with_0 = _u5bf9_u8c61tb - if _with_0 ~= nil then - _with_0["字段a"] = 1 - if _with_0["字段b"] then - goto _continue_12 - end - do - if _with_0["字段c"] then - break - end + local _with_0 = _u5bf9_u8c61tb + if _with_0 ~= nil then + _with_0["字段a"] = 1 + if _with_0["字段b"] then + goto _continue_12 + end + do + if _with_0["字段c"] then + break end end end diff --git a/spec/outputs/unicode/macro.lua b/spec/outputs/unicode/macro.lua index 88f6de7..069f429 100644 --- a/spec/outputs/unicode/macro.lua +++ b/spec/outputs/unicode/macro.lua @@ -1,4 +1,6 @@ -assert(_u5bf9_u8c61 == nil) +do + assert(_u5bf9_u8c61 == nil) +end local _u7ed3_u679c = (_u5bf9_u8c61 == nil) if _u51fd_u65701() then _u6253_u5370("没问题") @@ -9,89 +11,89 @@ end local _u5bf9_u8c61 do local __u6e90_, __u76ee_u6807_ - do - __u76ee_u6807_ = { - ["位置"] = { }, - ["标签"] = (function() - local _call_0 = _u6807_u7b7e - return _call_0["转数字"](_call_0) - end)() - } - do - __u6e90_ = self - __u76ee_u6807_["标识"] = __u6e90_["标识"] - __u76ee_u6807_["连接们"] = __u6e90_["连接们"] - __u76ee_u6807_["位置"]["x坐标"] = __u6e90_["位置"]["x坐标"] - __u76ee_u6807_["位置"]["y坐标"] = __u6e90_["位置"]["y坐标"] - __u76ee_u6807_["位置"]["z坐标"] = __u6e90_["位置"]["z坐标"] - end - _u5bf9_u8c61 = __u76ee_u6807_ - end + __u76ee_u6807_ = { + ["位置"] = { }, + ["标签"] = (function() + local _call_0 = _u6807_u7b7e + return _call_0["转数字"](_call_0) + end)() + } + __u6e90_ = self + __u76ee_u6807_["标识"] = __u6e90_["标识"] + __u76ee_u6807_["连接们"] = __u6e90_["连接们"] + __u76ee_u6807_["位置"]["x坐标"] = __u6e90_["位置"]["x坐标"] + __u76ee_u6807_["位置"]["y坐标"] = __u6e90_["位置"]["y坐标"] + __u76ee_u6807_["位置"]["z坐标"] = __u6e90_["位置"]["z坐标"] + _u5bf9_u8c61 = __u76ee_u6807_ end if (_u53d8_u91cfx == "🍎" or _u53d8_u91cfx == "🐷" or _u53d8_u91cfx == "🐶") then _u6253_u5370("存在") end -local _list_0 = (function() - local _accum_0 = { } - local _len_0 = 1 +do local _list_0 = (function() - local _accum_1 = { } - local _len_1 = 1 - local _list_0 = { - 1, - 2, - 3 - } + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = (function() + local _accum_1 = { } + local _len_1 = 1 + local _list_0 = { + 1, + 2, + 3 + } + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + _accum_1[_len_1] = _ * 2 + _len_1 = _len_1 + 1 + end + return _accum_1 + end)() for _index_0 = 1, #_list_0 do local _ = _list_0[_index_0] - _accum_1[_len_1] = _ * 2 - _len_1 = _len_1 + 1 + if _ > 4 then + _accum_0[_len_0] = _ + _len_0 = _len_0 + 1 + end end - return _accum_1 + return _accum_0 end)() for _index_0 = 1, #_list_0 do local _ = _list_0[_index_0] - if _ > 4 then - _accum_0[_len_0] = _ - _len_0 = _len_0 + 1 - end + _u6253_u5370(_) end - return _accum_0 -end)() -for _index_0 = 1, #_list_0 do - local _ = _list_0[_index_0] - _u6253_u5370(_) end -local _list_1 = (function() - local _accum_0 = { } - local _len_0 = 1 - local _list_1 = (function() - local _accum_1 = { } - local _len_1 = 1 - local _list_1 = { - 1, - 2, - 3 - } - for _index_0 = 1, #_list_1 do - local _ = _list_1[_index_0] - _accum_1[_len_1] = _ * 2 - _len_1 = _len_1 + 1 +do + local _list_0 = (function() + local _accum_0 = { } + local _len_0 = 1 + local _list_0 = (function() + local _accum_1 = { } + local _len_1 = 1 + local _list_0 = { + 1, + 2, + 3 + } + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + _accum_1[_len_1] = _ * 2 + _len_1 = _len_1 + 1 + end + return _accum_1 + end)() + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + if _ > 4 then + _accum_0[_len_0] = _ + _len_0 = _len_0 + 1 + end end - return _accum_1 + return _accum_0 end)() - for _index_0 = 1, #_list_1 do - local _ = _list_1[_index_0] - if _ > 4 then - _accum_0[_len_0] = _ - _len_0 = _len_0 + 1 - end + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] + _u6253_u5370(_) end - return _accum_0 -end)() -for _index_0 = 1, #_list_1 do - local _ = _list_1[_index_0] - _u6253_u5370(_) end local _u503c do @@ -99,13 +101,13 @@ do do local _accum_0 = { } local _len_0 = 1 - local _list_2 = { + local _list_0 = { 1, 2, 3 } - for _index_0 = 1, #_list_2 do - local _ = _list_2[_index_0] + for _index_0 = 1, #_list_0 do + local _ = _list_0[_index_0] _accum_0[_len_0] = _ * 2 _len_0 = _len_0 + 1 end @@ -137,8 +139,10 @@ do end _u503c = _4 end -local _call_0 = (1 + 2) -_call_0["调用"](_call_0, 123) +do + local _call_0 = (1 + 2) + _call_0["调用"](_call_0, 123) +end _u7ed3_u679c = (1 + 2) local f f = function(_u53c2_u6570x) @@ -203,7 +207,7 @@ local function dummy() end -- 这有个注释 local _ = require('下划线') -local _call_1 = (_({ +local _call_0 = (_({ 1, 2, 3, @@ -211,61 +215,65 @@ local _call_1 = (_({ -2, 3 })) -_call_1 = _call_1["链"](_call_1) -_call_1 = _call_1["映射"](_call_1, function(self) +_call_0 = _call_0["链"](_call_0) +_call_0 = _call_0["映射"](_call_0, function(self) return self * 2 end) -_call_1 = _call_1["过滤"](_call_1, function(self) +_call_0 = _call_0["过滤"](_call_0, function(self) return self > 3 end) -local _u7ed3_u679ca = _call_1["取值"](_call_1) -local _call_2 = (_({ - 1, - 2, - 3, - 4, - -2, - 3 -})) -_call_2 = _call_2["链"](_call_2) -_call_2 = _call_2["映射"](_call_2, function(self) - return self * 2 -end) -_call_2 = _call_2["过滤"](_call_2, function(self) - return self > 3 -end) -_call_2["每一个"](_call_2, function(self) - return _u6253_u5370(self) -end) -local _call_3 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] -_call_3 = _call_3["父节点"](_call_3) -_call_3 = _call_3["后代"](_call_3) -_call_3 = _call_3["选择启用"](_call_3) -_call_3 = _call_3["选择可见"](_call_3) -_call_3 = _call_3["标签等于"](_call_3, "fx") -_call_3 = _call_3["其中"](_call_3, function(x) - local _call_4 = x["名称"] - return _call_4["结尾为"](_call_4, "(克隆)") -end) -_u7ed3_u679c = _call_3["摧毁"](_call_3) +local _u7ed3_u679ca = _call_0["取值"](_call_0) do - local _1 - local _call_4 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] - _1 = _call_4["父节点"](_call_4) - local _2 - _2 = _1["后代"](_1) - local _3 - _3 = _2["选择启用"](_2) - local _4 - _4 = _3["选择可见"](_3) - local _5 - _5 = _4["标签等于"](_4, "fx") - local _6 - _6 = _5["其中"](_5, function(x) - local _call_5 = x["名称"] - return _call_5["结尾为"](_call_5, "(克隆)") + local _call_1 = (_({ + 1, + 2, + 3, + 4, + -2, + 3 + })) + _call_1 = _call_1["链"](_call_1) + _call_1 = _call_1["映射"](_call_1, function(self) + return self * 2 + end) + _call_1 = _call_1["过滤"](_call_1, function(self) + return self > 3 + end) + _call_1["每一个"](_call_1, function(self) + return _u6253_u5370(self) end) - _6["摧毁"](_6) +end +local _call_1 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] +_call_1 = _call_1["父节点"](_call_1) +_call_1 = _call_1["后代"](_call_1) +_call_1 = _call_1["选择启用"](_call_1) +_call_1 = _call_1["选择可见"](_call_1) +_call_1 = _call_1["标签等于"](_call_1, "fx") +_call_1 = _call_1["其中"](_call_1, function(x) + local _call_2 = x["名称"] + return _call_2["结尾为"](_call_2, "(克隆)") +end) +_u7ed3_u679c = _call_1["摧毁"](_call_1) +do + do + local _1 + local _call_2 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] + _1 = _call_2["父节点"](_call_2) + local _2 + _2 = _1["后代"](_1) + local _3 + _3 = _2["选择启用"](_2) + local _4 + _4 = _3["选择可见"](_3) + local _5 + _5 = _4["标签等于"](_4, "fx") + local _6 + _6 = _5["其中"](_5, function(x) + local _call_3 = x["名称"] + return _call_3["结尾为"](_call_3, "(克隆)") + end) + _6["摧毁"](_6) + end end local _call_0 = _u539f_u70b9["变换"]["根节点"]["游戏对象"] _call_0["父节点"](_call_0):_u540e_u4ee3():_u9009_u62e9_u542f_u7528():_u9009_u62e9_u53ef_u89c1():_u6807_u7b7e_u7b49_u4e8e("fx"):_u5176_u4e2d(function(x) @@ -302,7 +310,9 @@ _u6253_u5370((setmetatable({ end })) _u6253_u5370("当前代码行数: " .. tostring(268)) +do -- 待实现 +end do _u6253_u5370(1) end @@ -317,5 +327,7 @@ _1 = function() end return _accum_0 end -_u6253_u5370('abc') -return 123 +do + _u6253_u5370('abc') + return 123 +end diff --git a/spec/outputs/unicode/metatable.lua b/spec/outputs/unicode/metatable.lua index b6ee48a..c7c8730 100644 --- a/spec/outputs/unicode/metatable.lua +++ b/spec/outputs/unicode/metatable.lua @@ -48,19 +48,17 @@ do end do local _u53d8_u91cfx, _u65b0, _u53d8_u91cf, close, _u5173_u95edA, num, add, sub + local _obj_0, _obj_1 + _u53d8_u91cfx, _obj_0, _obj_1 = 123, _u53d8_u91cfa["变量b"]["变量c"], _u51fd_u6570() + _u65b0, _u53d8_u91cf = _obj_0["新"], _obj_0["变量"] do - local _obj_0, _obj_1 - _u53d8_u91cfx, _obj_0, _obj_1 = 123, _u53d8_u91cfa["变量b"]["变量c"], _u51fd_u6570() - _u65b0, _u53d8_u91cf = _obj_0["新"], _obj_0["变量"] - do - local _obj_2 = getmetatable(_obj_0) - close, _u5173_u95edA = _obj_2.__close, _obj_2.__close - end - num = _obj_1.num - do - local _obj_2 = getmetatable(_obj_1) - add, sub = _obj_2.__add, _obj_2.__sub - end + local _obj_2 = getmetatable(_obj_0) + close, _u5173_u95edA = _obj_2.__close, _obj_2.__close + end + num = _obj_1.num + do + local _obj_2 = getmetatable(_obj_1) + add, sub = _obj_2.__add, _obj_2.__sub end end setmetatable(_u53d8_u91cfa["变量b"], { }) diff --git a/spec/outputs/unicode/multiline_chain.lua b/spec/outputs/unicode/multiline_chain.lua index f45e71f..c1da13f 100644 --- a/spec/outputs/unicode/multiline_chain.lua +++ b/spec/outputs/unicode/multiline_chain.lua @@ -127,16 +127,14 @@ do _with_0["项目方法C"](_with_0, _u53d8_u91cfi) end if not _with_0["变量b"] then - do - local _accum_0 = { } - local _len_0 = 1 - while _with_0["项目字段D"] do - local _call_17 = _with_0["下一个项目"](_with_0) - _accum_0[_len_0] = _call_17["取得"](_call_17) - _len_0 = _len_0 + 1 - end - _with_0["变量c"] = _accum_0 + local _accum_0 = { } + local _len_0 = 1 + while _with_0["项目字段D"] do + local _call_17 = _with_0["下一个项目"](_with_0) + _accum_0[_len_0] = _call_17["取得"](_call_17) + _len_0 = _len_0 + 1 end + _with_0["变量c"] = _accum_0 end end return nil diff --git a/spec/outputs/unicode/nil_coalescing.lua b/spec/outputs/unicode/nil_coalescing.lua index 90fd097..53e3711 100644 --- a/spec/outputs/unicode/nil_coalescing.lua +++ b/spec/outputs/unicode/nil_coalescing.lua @@ -1,23 +1,19 @@ do local _u53d8_u91cfa - do - local _exp_0 = _u53d8_u91cfb - if _exp_0 ~= nil then - _u53d8_u91cfa = _exp_0 - else - _u53d8_u91cfa = _u53d8_u91cfc - end + local _exp_0 = _u53d8_u91cfb + if _exp_0 ~= nil then + _u53d8_u91cfa = _exp_0 + else + _u53d8_u91cfa = _u53d8_u91cfc end end do local _u5b57_u6bb5a - do - local _exp_0 = _u53d8_u91cfb - if _exp_0 ~= nil then - _u5b57_u6bb5a = _exp_0["字段a"] - else - _u5b57_u6bb5a = _u53d8_u91cfc["字段a"] - end + local _exp_0 = _u53d8_u91cfb + if _exp_0 ~= nil then + _u5b57_u6bb5a = _exp_0["字段a"] + else + _u5b57_u6bb5a = _u53d8_u91cfc["字段a"] end end do @@ -50,23 +46,21 @@ do end do local _u53d8_u91cfa - do - local _exp_0 = _u53d8_u91cfb - if _exp_0 ~= nil then - _u53d8_u91cfa = _exp_0 - else - do - local _exp_1 = _u53d8_u91cfc - if _exp_1 ~= nil then - _u53d8_u91cfa = _exp_1 - else - do - local _exp_2 = _u53d8_u91cfd - if _exp_2 ~= nil then - _u53d8_u91cfa = _exp_2 - else - _u53d8_u91cfa = _u53d8_u91cfe - end + local _exp_0 = _u53d8_u91cfb + if _exp_0 ~= nil then + _u53d8_u91cfa = _exp_0 + else + do + local _exp_1 = _u53d8_u91cfc + if _exp_1 ~= nil then + _u53d8_u91cfa = _exp_1 + else + do + local _exp_2 = _u53d8_u91cfd + if _exp_2 ~= nil then + _u53d8_u91cfa = _exp_2 + else + _u53d8_u91cfa = _u53d8_u91cfe end end end @@ -84,18 +78,14 @@ do end)()) end do - do - local _with_0 - do - local _exp_0 = _u51fd_u6570A() - if _exp_0 ~= nil then - _with_0 = _exp_0 - else - _with_0 = _u51fd_u6570B() - end - end - _u6253_u5370(_with_0["字段"]) + local _with_0 + local _exp_0 = _u51fd_u6570A() + if _exp_0 ~= nil then + _with_0 = _exp_0 + else + _with_0 = _u51fd_u6570B() end + _u6253_u5370(_with_0["字段"]) end do local _u53d8_u91cfa = 1 + 2 + (function() @@ -138,18 +128,16 @@ do end do local _u53d8_u91cfa - do - local _exp_0 = 1 - if _exp_0 ~= nil then - _u53d8_u91cfa = _exp_0 - else - do - local _exp_1 = 2 - if _exp_1 ~= nil then - _u53d8_u91cfa = _exp_1 - else - _u53d8_u91cfa = 3 - end + local _exp_0 = 1 + if _exp_0 ~= nil then + _u53d8_u91cfa = _exp_0 + else + do + local _exp_1 = 2 + if _exp_1 ~= nil then + _u53d8_u91cfa = _exp_1 + else + _u53d8_u91cfa = 3 end end end diff --git a/spec/outputs/unicode/stub.lua b/spec/outputs/unicode/stub.lua index 5f183a1..426967b 100644 --- a/spec/outputs/unicode/stub.lua +++ b/spec/outputs/unicode/stub.lua @@ -15,12 +15,10 @@ end _u6253_u5370(_u51fd_u6570()) _u6253_u5370(_u53d8_u91cfx["值"](_u53d8_u91cfx)); (function(...) - do - local _base_0 = _u4f60_u597d(...) - local _fn_0 = _base_0["世界"] - _u53d8_u91cfx = _fn_0 and function(...) - return _fn_0(_base_0, ...) - end + local _base_0 = _u4f60_u597d(...) + local _fn_0 = _base_0["世界"] + _u53d8_u91cfx = _fn_0 and function(...) + return _fn_0(_base_0, ...) end end)() return nil diff --git a/spec/outputs/unicode/switch.lua b/spec/outputs/unicode/switch.lua index 6b8bbdc..76c078c 100644 --- a/spec/outputs/unicode/switch.lua +++ b/spec/outputs/unicode/switch.lua @@ -45,13 +45,11 @@ do end do local _with_0 = _u4e1c_u897f - do - local _exp_0 = _with_0["值"](_with_0) - if _with_0["确定"] == _exp_0 then - local _u53d8_u91cf_ = "世界" - else - local _u53d8_u91cf_ = "是的" - end + local _exp_0 = _with_0["值"](_with_0) + if _with_0["确定"] == _exp_0 then + local _u53d8_u91cf_ = "世界" + else + local _u53d8_u91cf_ = "是的" end end _u4fee_u590d(_u8fd9_u4e2a) @@ -106,66 +104,64 @@ do } } } - do - local _type_0 = type(_u5b57_u5178) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - local _u7b2c_u4e00 = _u5b57_u5178[1] - local _u4e00_u4e2a - do - local _obj_0 = _u5b57_u5178[2] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - _u4e00_u4e2a = _obj_0[1] - end + local _type_0 = type(_u5b57_u5178) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + local _u7b2c_u4e00 = _u5b57_u5178[1] + local _u4e00_u4e2a + do + local _obj_0 = _u5b57_u5178[2] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + _u4e00_u4e2a = _obj_0[1] end - local _u4e24_u4e2a - do - local _obj_0 = _u5b57_u5178[2] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - _u4e24_u4e2a = _obj_0[2] - end + end + local _u4e24_u4e2a + do + local _obj_0 = _u5b57_u5178[2] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + _u4e24_u4e2a = _obj_0[2] end - local _u4e09_u4e2a - do - local _obj_0 = _u5b57_u5178[2] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - _u4e09_u4e2a = _obj_0[3] - end + end + local _u4e09_u4e2a + do + local _obj_0 = _u5b57_u5178[2] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + _u4e09_u4e2a = _obj_0[3] end - local _u53d8_u91cfc - do - local _obj_0 = _u5b57_u5178["变量a"] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - do - local _obj_1 = _obj_0["变量b"] - local _type_2 = type(_obj_1) - if "table" == _type_2 or "userdata" == _type_2 then - _u53d8_u91cfc = _obj_1["变量c"] - end + end + local _u53d8_u91cfc + do + local _obj_0 = _u5b57_u5178["变量a"] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + do + local _obj_1 = _obj_0["变量b"] + local _type_2 = type(_obj_1) + if "table" == _type_2 or "userdata" == _type_2 then + _u53d8_u91cfc = _obj_1["变量c"] end end end - local _u53d8_u91cfz - do - local _obj_0 = _u5b57_u5178["变量x"] - local _type_1 = type(_obj_0) - if "table" == _type_1 or "userdata" == _type_1 then - do - local _obj_1 = _obj_0["变量y"] - local _type_2 = type(_obj_1) - if "table" == _type_2 or "userdata" == _type_2 then - _u53d8_u91cfz = _obj_1["变量z"] - end + end + local _u53d8_u91cfz + do + local _obj_0 = _u5b57_u5178["变量x"] + local _type_1 = type(_obj_0) + if "table" == _type_1 or "userdata" == _type_1 then + do + local _obj_1 = _obj_0["变量y"] + local _type_2 = type(_obj_1) + if "table" == _type_2 or "userdata" == _type_2 then + _u53d8_u91cfz = _obj_1["变量z"] end end end - if _u7b2c_u4e00 ~= nil and _u4e00_u4e2a ~= nil and _u4e24_u4e2a ~= nil and _u4e09_u4e2a ~= nil and _u53d8_u91cfc ~= nil and _u53d8_u91cfz ~= nil then - _u6253_u5370(_u7b2c_u4e00, _u4e00_u4e2a, _u4e24_u4e2a, _u4e09_u4e2a, _u53d8_u91cfc, _u53d8_u91cfz) - end + end + if _u7b2c_u4e00 ~= nil and _u4e00_u4e2a ~= nil and _u4e24_u4e2a ~= nil and _u4e09_u4e2a ~= nil and _u53d8_u91cfc ~= nil and _u53d8_u91cfz ~= nil then + _u6253_u5370(_u7b2c_u4e00, _u4e00_u4e2a, _u4e24_u4e2a, _u4e09_u4e2a, _u53d8_u91cfc, _u53d8_u91cfz) end end end @@ -183,56 +179,54 @@ do } for _index_0 = 1, #_u7269_u54c1 do local _u7269 = _u7269_u54c1[_index_0] - do - local _type_0 = type(_u7269) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false + local _type_0 = type(_u7269) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local _u53d8_u91cfx = _u7269["变量x"] + local _u53d8_u91cfy = _u7269["变量y"] + if _u53d8_u91cfx ~= nil and _u53d8_u91cfy ~= nil then + _match_0 = true + _u6253_u5370("Vec2 " .. tostring(_u53d8_u91cfx) .. ", " .. tostring(_u53d8_u91cfy)) + end + end + if not _match_0 then + local _match_1 = false if _tab_0 then - local _u53d8_u91cfx = _u7269["变量x"] - local _u53d8_u91cfy = _u7269["变量y"] - if _u53d8_u91cfx ~= nil and _u53d8_u91cfy ~= nil then - _match_0 = true - _u6253_u5370("Vec2 " .. tostring(_u53d8_u91cfx) .. ", " .. tostring(_u53d8_u91cfy)) + local _u5bbd_u5ea6 = _u7269["宽度"] + local _u9ad8_u5ea6 = _u7269["高度"] + if _u5bbd_u5ea6 ~= nil and _u9ad8_u5ea6 ~= nil then + _match_1 = true + _u6253_u5370("Size " .. tostring(_u5bbd_u5ea6) .. ", " .. tostring(_u9ad8_u5ea6)) end end - if not _match_0 then - local _match_1 = false - if _tab_0 then - local _u5bbd_u5ea6 = _u7269["宽度"] - local _u9ad8_u5ea6 = _u7269["高度"] - if _u5bbd_u5ea6 ~= nil and _u9ad8_u5ea6 ~= nil then - _match_1 = true - _u6253_u5370("Size " .. tostring(_u5bbd_u5ea6) .. ", " .. tostring(_u9ad8_u5ea6)) + if not _match_1 then + if false == _u7269 then + _u6253_u5370("没有") + else + local _match_2 = false + if _tab_0 then + local _u7c7b = _u7269["__类"] + if _u7c7b ~= nil then + _match_2 = true + if _u7c7b_u522bA == _u7c7b then + _u6253_u5370("对象 A") + elseif _u7c7b_u522bB == _u7c7b then + _u6253_u5370("对象 B") + end + end end - end - if not _match_1 then - if false == _u7269 then - _u6253_u5370("没有") - else - local _match_2 = false + if not _match_2 then + local _match_3 = false if _tab_0 then - local _u7c7b = _u7269["__类"] - if _u7c7b ~= nil then - _match_2 = true - if _u7c7b_u522bA == _u7c7b then - _u6253_u5370("对象 A") - elseif _u7c7b_u522bB == _u7c7b then - _u6253_u5370("对象 B") - end + local _u8868 = getmetatable(_u7269) + if _u8868 ~= nil then + _match_3 = true + _u6253_u5370("带有元表的表") end end - if not _match_2 then - local _match_3 = false - if _tab_0 then - local _u8868 = getmetatable(_u7269) - if _u8868 ~= nil then - _match_3 = true - _u6253_u5370("带有元表的表") - end - end - if not _match_3 then - _u6253_u5370("物品不被接受!") - end + if not _match_3 then + _u6253_u5370("物品不被接受!") end end end @@ -271,72 +265,66 @@ do end end end - do - local _type_0 = type(_u8868_u683c) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local _u53d8_u91cfa = _u8868_u683c["变量a"] - local _u53d8_u91cfb = _u8868_u683c["变量b"] - if _u53d8_u91cfa ~= nil and _u53d8_u91cfb ~= nil then - _match_0 = true - _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb) - end - end - if not _match_0 then - _u6253_u5370("没有匹配") + local _type_0 = type(_u8868_u683c) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local _u53d8_u91cfa = _u8868_u683c["变量a"] + local _u53d8_u91cfb = _u8868_u683c["变量b"] + if _u53d8_u91cfa ~= nil and _u53d8_u91cfb ~= nil then + _match_0 = true + _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb) end end + if not _match_0 then + _u6253_u5370("没有匹配") + end end do local _u8868_u683c = { ["变量x"] = "abc" } - do - local _type_0 = type(_u8868_u683c) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false + local _type_0 = type(_u8868_u683c) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local _u53d8_u91cfx = _u8868_u683c["变量x"] + local _u53d8_u91cfy = _u8868_u683c["变量y"] + if _u53d8_u91cfx ~= nil and _u53d8_u91cfy ~= nil then + _match_0 = true + _u6253_u5370("变量x: " .. tostring(_u53d8_u91cfx) .. " 和 变量y: " .. tostring(_u53d8_u91cfy)) + end + end + if not _match_0 then if _tab_0 then local _u53d8_u91cfx = _u8868_u683c["变量x"] - local _u53d8_u91cfy = _u8868_u683c["变量y"] - if _u53d8_u91cfx ~= nil and _u53d8_u91cfy ~= nil then - _match_0 = true - _u6253_u5370("变量x: " .. tostring(_u53d8_u91cfx) .. " 和 变量y: " .. tostring(_u53d8_u91cfy)) - end - end - if not _match_0 then - if _tab_0 then - local _u53d8_u91cfx = _u8868_u683c["变量x"] - if _u53d8_u91cfx ~= nil then - _u6253_u5370("只有 变量x: " .. tostring(_u53d8_u91cfx)) - end + if _u53d8_u91cfx ~= nil then + _u6253_u5370("只有 变量x: " .. tostring(_u53d8_u91cfx)) end end end end do local _u5339_u914d - do - local _exp_0 = _u8868_u683c - if 1 == _exp_0 then - _u5339_u914d = "1" - else - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local _u53d8_u91cfx = _exp_0["变量x"] - if _u53d8_u91cfx ~= nil then - _match_0 = true - _u5339_u914d = _u53d8_u91cfx - end + local _exp_0 = _u8868_u683c + if 1 == _exp_0 then + _u5339_u914d = "1" + else + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local _u53d8_u91cfx = _exp_0["变量x"] + if _u53d8_u91cfx ~= nil then + _match_0 = true + _u5339_u914d = _u53d8_u91cfx end - if not _match_0 then - if false == _exp_0 then - _u5339_u914d = "false" - else - _u5339_u914d = nil - end + end + if not _match_0 then + if false == _exp_0 then + _u5339_u914d = "false" + else + _u5339_u914d = nil end end end @@ -346,55 +334,51 @@ do if nil == _exp_0 then return "无效" else - do - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - local _match_0 = false - if _tab_0 then - local _u53d8_u91cfa = _exp_0["变量a"] - local _u53d8_u91cfb = _exp_0["变量b"] - if _u53d8_u91cfa ~= nil and _u53d8_u91cfb ~= nil then - _match_0 = true - return tostring(_u53d8_u91cfa + _u53d8_u91cfb) - end + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + local _match_0 = false + if _tab_0 then + local _u53d8_u91cfa = _exp_0["变量a"] + local _u53d8_u91cfb = _exp_0["变量b"] + if _u53d8_u91cfa ~= nil and _u53d8_u91cfb ~= nil then + _match_0 = true + return tostring(_u53d8_u91cfa + _u53d8_u91cfb) end - if not _match_0 then - if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 or 4 == _exp_0 or 5 == _exp_0 then - return "数字 1 - 5" - else - local _match_1 = false - if _tab_0 then - local _u5339_u914d_u4efb_u4f55_u8868_u683c = _exp_0["匹配任何表格"] - if _u5339_u914d_u4efb_u4f55_u8868_u683c == nil then - _u5339_u914d_u4efb_u4f55_u8868_u683c = "后备" - end - _match_1 = true - return _u5339_u914d_u4efb_u4f55_u8868_u683c - end - if not _match_1 then - return "除非它不是一个表格,否则不应到达这里" + end + if not _match_0 then + if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 or 4 == _exp_0 or 5 == _exp_0 then + return "数字 1 - 5" + else + local _match_1 = false + if _tab_0 then + local _u5339_u914d_u4efb_u4f55_u8868_u683c = _exp_0["匹配任何表格"] + if _u5339_u914d_u4efb_u4f55_u8868_u683c == nil then + _u5339_u914d_u4efb_u4f55_u8868_u683c = "后备" end + _match_1 = true + return _u5339_u914d_u4efb_u4f55_u8868_u683c + end + if not _match_1 then + return "除非它不是一个表格,否则不应到达这里" end end end end end do - do - local _exp_0 = _u53d8_u91cfy - local _type_0 = type(_exp_0) - local _tab_0 = "table" == _type_0 or "userdata" == _type_0 - if _tab_0 then - local _u8868 = (function() - local _obj_0 = _exp_0["变量x"] - if _obj_0 ~= nil then - return getmetatable(_obj_0) - end - return nil - end)() - if _u8868 ~= nil then - _u6253_u5370(_u8868) + local _exp_0 = _u53d8_u91cfy + local _type_0 = type(_exp_0) + local _tab_0 = "table" == _type_0 or "userdata" == _type_0 + if _tab_0 then + local _u8868 = (function() + local _obj_0 = _exp_0["变量x"] + if _obj_0 ~= nil then + return getmetatable(_obj_0) end + return nil + end)() + if _u8868 ~= nil then + _u6253_u5370(_u8868) end end end diff --git a/spec/outputs/unicode/syntax.lua b/spec/outputs/unicode/syntax.lua index f086db6..9ea8f68 100644 --- a/spec/outputs/unicode/syntax.lua +++ b/spec/outputs/unicode/syntax.lua @@ -235,15 +235,11 @@ else end do local _with_0 = _u8868 - do - local _obj_2 = _with_0["变量b"]["变量c"] - do - local _with_1 = _u5411_u91cf - _with_1["字段x"] = 1 - _with_1["字段y"] = 2 - _obj_2[#_obj_2 + 1] = _with_1 - end - end + local _obj_2 = _with_0["变量b"]["变量c"] + local _with_1 = _u5411_u91cf + _with_1["字段x"] = 1 + _with_1["字段y"] = 2 + _obj_2[#_obj_2 + 1] = _with_1 end do local _call_8 = _u5bf9_u8c61a["变量b"]["变量c"]["变量d"] diff --git a/spec/outputs/unicode/tables.lua b/spec/outputs/unicode/tables.lua index 28ad6e2..82ca299 100644 --- a/spec/outputs/unicode/tables.lua +++ b/spec/outputs/unicode/tables.lua @@ -392,11 +392,9 @@ do _tab_0[#_tab_0 + 1] = "b" _tab_0[#_tab_0 + 1] = "c" local _obj_1 - do - local _obj_2 = _u51fd_u6570 - if _obj_2 ~= nil then - _obj_1 = _obj_2() - end + local _obj_2 = _u51fd_u6570 + if _obj_2 ~= nil then + _obj_1 = _obj_2() end local _idx_1 = 1 for _key_0, _value_0 in pairs(_obj_1) do diff --git a/spec/outputs/unicode/vararg.lua b/spec/outputs/unicode/vararg.lua index 4acb6cc..b837006 100644 --- a/spec/outputs/unicode/vararg.lua +++ b/spec/outputs/unicode/vararg.lua @@ -46,57 +46,53 @@ local _anon_func_5 = function(_u9879_u76ee, ...) end local _anon_func_6 = function(_u51fd_u6570, setmetatable) local _u53d8_u91cfA - do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "变量A" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "变量A" - }, { - __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; - _u51fd_u6570() - _u53d8_u91cfA = _class_0 - return _class_0 - end + }) + _base_0.__class = _class_0 + local self = _class_0; + _u51fd_u6570() + _u53d8_u91cfA = _class_0 + return _class_0 end local _anon_func_7 = function(_u51fd_u6570, setmetatable, ...) local _u53d8_u91cfA - do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "变量A" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "变量A" - }, { - __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; - _u51fd_u6570(...) - _u53d8_u91cfA = _class_0 - return _class_0 - end + }) + _base_0.__class = _class_0 + local self = _class_0; + _u51fd_u6570(...) + _u53d8_u91cfA = _class_0 + return _class_0 end local _anon_func_8 = function(_u8868, pairs) local _tbl_0 = { } diff --git a/spec/outputs/unicode/with.lua b/spec/outputs/unicode/with.lua index 0dcd4a7..7a5ba00 100644 --- a/spec/outputs/unicode/with.lua +++ b/spec/outputs/unicode/with.lua @@ -9,24 +9,20 @@ do end end do - do - local _with_0 = _u53f6_u5b50 - _with_0["世界"]() - _with_0["世界"](1, 2, 3) - local _u53d8_u91cfg = _with_0["什么"]["是"]["这"] - _with_0["你好"](1, 2, 3) - _with_0["你好"](_with_0, 1, 2)["世界"](2323) - _with_0["你好"](_with_0, "是的", "伙计") - _with_0["世界"] = 200 - end + local _with_0 = _u53f6_u5b50 + _with_0["世界"]() + _with_0["世界"](1, 2, 3) + local _u53d8_u91cfg = _with_0["什么"]["是"]["这"] + _with_0["你好"](1, 2, 3) + _with_0["你好"](_with_0, 1, 2)["世界"](2323) + _with_0["你好"](_with_0, "是的", "伙计") + _with_0["世界"] = 200 end do local _u6ecb_u6ecb_u6ecb - do - local _with_0 = _u4e1c_u897f - _with_0["设置状态"]("你好 世界") - _u6ecb_u6ecb_u6ecb = _with_0 - end + local _with_0 = _u4e1c_u897f + _with_0["设置状态"]("你好 世界") + _u6ecb_u6ecb_u6ecb = _with_0 end do local _u53d8_u91cfx = 5 + (function() @@ -45,14 +41,12 @@ do } end do - do - local _with_0 = _u4e1c_u897f - local _ = _with_0["属性"](_with_0, "某物")["你好"] - local _call_0 = _with_0["属性"] - _call_0["发送"](_call_0, _u4e00_u4e2a) - local _call_1 = _with_0["属性"] - _call_1["发送"](_call_1, _u4e00_u4e2a) - end + local _with_0 = _u4e1c_u897f + local _ = _with_0["属性"](_with_0, "某物")["你好"] + local _call_0 = _with_0["属性"] + _call_0["发送"](_call_0, _u4e00_u4e2a) + local _call_1 = _with_0["属性"] + _call_1["发送"](_call_1, _u4e00_u4e2a) end do do @@ -81,69 +75,49 @@ do return _u53d8_u91cfa end)()) local p - do - local _with_0 = 1 - _u4f60_u597d()["字段x"], _u4e16_u754c()["字段y"] = _with_0, 2 - _u6253_u5370(_u53d8_u91cfa + _u53d8_u91cfb) - p = _with_0 - end + local _with_0 = 1 + _u4f60_u597d()["字段x"], _u4e16_u754c()["字段y"] = _with_0, 2 + _u6253_u5370(_u53d8_u91cfa + _u53d8_u91cfb) + p = _with_0 end do local _u53d8_u91cfx = "你好" _u53d8_u91cfx["大写"](_u53d8_u91cfx) end do - do - local _u53d8_u91cfk = "乔" - _u6253_u5370(_u53d8_u91cfk["大写"](_u53d8_u91cfk)) - end + local _u53d8_u91cfk = "乔" + _u6253_u5370(_u53d8_u91cfk["大写"](_u53d8_u91cfk)) end do - do - local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = "", "", "" - _u6253_u5370(_u53d8_u91cfa["大写"](_u53d8_u91cfa)) - end + local _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = "", "", "" + _u6253_u5370(_u53d8_u91cfa["大写"](_u53d8_u91cfa)) end do local _u53d8_u91cfa = "床铺" - do - local _u53d8_u91cfb, _u53d8_u91cfc - _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = "", "", "" - _u6253_u5370(_u53d8_u91cfa["大写"](_u53d8_u91cfa)) - end + local _u53d8_u91cfb, _u53d8_u91cfc + _u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc = "", "", "" + _u6253_u5370(_u53d8_u91cfa["大写"](_u53d8_u91cfa)) end do - do - local _with_0 = _u53d8_u91cfj - _u6253_u5370(_with_0["大写"](_with_0)) - end + local _with_0 = _u53d8_u91cfj + _u6253_u5370(_with_0["大写"](_with_0)) end do - do - local _with_0 = "乔" - _u53d8_u91cfk["变量j"] = _with_0 - _u6253_u5370(_with_0["大写"](_with_0)) - end + local _with_0 = "乔" + _u53d8_u91cfk["变量j"] = _with_0 + _u6253_u5370(_with_0["大写"](_with_0)) end do - do - local _with_0 = _u53d8_u91cfa - _u6253_u5370(_with_0.b) - do - local _with_1 = _with_0.c - _u6253_u5370(_with_1.d) - end - end + local _with_0 = _u53d8_u91cfa + _u6253_u5370(_with_0.b) + local _with_1 = _with_0.c + _u6253_u5370(_with_1.d) end do - do - local _with_0 = _u53d8_u91cfa - do - local _with_1 = 2 - _with_0.b = _with_1 - _u6253_u5370(_with_1.c) - end - end + local _with_0 = _u53d8_u91cfa + local _with_1 = 2 + _with_0.b = _with_1 + _u6253_u5370(_with_1.c) end do local _ @@ -153,44 +127,38 @@ do end end do - do - local _with_0 = _u8868_u683c - local _call_0 = _u9879_u76ee["字段"] - _with_0.x = _call_0["函数"](_call_0, 123) - end + local _with_0 = _u8868_u683c + local _call_0 = _u9879_u76ee["字段"] + _with_0.x = _call_0["函数"](_call_0, 123) end do - do - local _with_0 = _u7238_u7238 - _with_0["如果"]("是的") - local _u53d8_u91cfy = _with_0["结束"]["函数"] - end + local _with_0 = _u7238_u7238 + _with_0["如果"]("是的") + local _u53d8_u91cfy = _with_0["结束"]["函数"] end do + local _with_0 = _u8868_u683c do - local _with_0 = _u8868_u683c - do - local _obj_0 = _with_0[2] - if _obj_0 ~= nil then - _with_0[1] = _obj_0["函数"](_obj_0) - end - end - _with_0["%a-b-c%"] = 123 - _with_0[ [[x y z]]] = _with_0[_u53d8_u91cf] - _u6253_u5370(_with_0[_with_0[3]]) - do - local _with_1 = _with_0[4] - _with_1[1] = 1 + local _obj_0 = _with_0[2] + if _obj_0 ~= nil then + _with_0[1] = _obj_0["函数"](_obj_0) end - _with_0[#_with_0 + 1] = "abc" - _with_0[#_with_0 + 1] = { - ["类型"] = "你好", - { - ["名字"] = "xyz", - ["值"] = 998 - } - } end + _with_0["%a-b-c%"] = 123 + _with_0[ [[x y z]]] = _with_0[_u53d8_u91cf] + _u6253_u5370(_with_0[_with_0[3]]) + do + local _with_1 = _with_0[4] + _with_1[1] = 1 + end + _with_0[#_with_0 + 1] = "abc" + _with_0[#_with_0 + 1] = { + ["类型"] = "你好", + { + ["名字"] = "xyz", + ["值"] = 998 + } + } end do do @@ -207,16 +175,14 @@ do end end do - do - local _u63a9_u7801 = _u5b9e_u5fc3_u77e9_u5f62({ - ["宽"] = w, - ["高"] = h, - ["颜色"] = 0x66000000 - }) - if _u63a9_u7801 ~= nil then - _u63a9_u7801["触摸启用"] = true - _u63a9_u7801["吞噬触摸"] = true - end + local _u63a9_u7801 = _u5b9e_u5fc3_u77e9_u5f62({ + ["宽"] = w, + ["高"] = h, + ["颜色"] = 0x66000000 + }) + if _u63a9_u7801 ~= nil then + _u63a9_u7801["触摸启用"] = true + _u63a9_u7801["吞噬触摸"] = true end end return nil diff --git a/spec/outputs/upvalue_func.lua b/spec/outputs/upvalue_func.lua index 5768d2d..14fe400 100644 --- a/spec/outputs/upvalue_func.lua +++ b/spec/outputs/upvalue_func.lua @@ -320,28 +320,26 @@ local _anon_func_13 = function(pairs, tb) return _accum_0 end local _anon_func_14 = function(setmetatable) - do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_0 + local _class_0 + local _base_0 = { } + if _base_0.__index == nil then + _base_0.__index = _base_0 + end + _class_0 = setmetatable({ + __init = function(self) + self.value = 1 + end, + __base = _base_0 + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function(self) - self.value = 1 - end, - __base = _base_0 - }, { - __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 - return _class_0 - end + }) + _base_0.__class = _class_0 + return _class_0 end local _anon_func_15 = function(tb) tb.field = 1 diff --git a/spec/outputs/vararg.lua b/spec/outputs/vararg.lua index 27918e9..dabba44 100644 --- a/spec/outputs/vararg.lua +++ b/spec/outputs/vararg.lua @@ -46,57 +46,53 @@ local _anon_func_5 = function(items, ...) end local _anon_func_6 = function(func, setmetatable) local A - do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "A" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "A" - }, { - __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; - func() - A = _class_0 - return _class_0 - end + }) + _base_0.__class = _class_0 + local self = _class_0; + func() + A = _class_0 + return _class_0 end local _anon_func_7 = function(func, setmetatable, ...) local A - do - local _class_0 - local _base_0 = { } - if _base_0.__index == nil then - _base_0.__index = _base_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 = "A" + }, { + __index = _base_0, + __call = function(cls, ...) + local _self_0 = setmetatable({ }, _base_0) + cls.__init(_self_0, ...) + return _self_0 end - _class_0 = setmetatable({ - __init = function() end, - __base = _base_0, - __name = "A" - }, { - __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; - func(...) - A = _class_0 - return _class_0 - end + }) + _base_0.__class = _class_0 + local self = _class_0; + func(...) + A = _class_0 + return _class_0 end local _anon_func_8 = function(pairs, tb) local _tbl_0 = { } diff --git a/spec/outputs/with.lua b/spec/outputs/with.lua index 304d26e..b2a1c3b 100644 --- a/spec/outputs/with.lua +++ b/spec/outputs/with.lua @@ -9,24 +9,20 @@ do end end do - do - local _with_0 = leaf - _with_0.world() - _with_0.world(1, 2, 3) - local g = _with_0.what.is.this - _with_0.hi(1, 2, 3) - _with_0:hi(1, 2).world(2323) - _with_0:hi("yeah", "man") - _with_0.world = 200 - end + local _with_0 = leaf + _with_0.world() + _with_0.world(1, 2, 3) + local g = _with_0.what.is.this + _with_0.hi(1, 2, 3) + _with_0:hi(1, 2).world(2323) + _with_0:hi("yeah", "man") + _with_0.world = 200 end do local zyzyzy - do - local _with_0 = something - _with_0.set_state("hello world") - zyzyzy = _with_0 - end + local _with_0 = something + _with_0.set_state("hello world") + zyzyzy = _with_0 end do local x = 5 + (function() @@ -45,12 +41,10 @@ do } end do - do - local _with_0 = foo - local _ = _with_0:prop("something").hello - _with_0.prop:send(one) - _with_0.prop:send(one) - end + local _with_0 = foo + local _ = _with_0:prop("something").hello + _with_0.prop:send(one) + _with_0.prop:send(one) end do do @@ -79,69 +73,49 @@ do return a end)()) local p - do - local _with_0 = 1 - hello().x, world().y = _with_0, 2 - print(a + b) - p = _with_0 - end + local _with_0 = 1 + hello().x, world().y = _with_0, 2 + print(a + b) + p = _with_0 end do local x = "hello" x:upper() end do - do - local k = "jo" - print(k:upper()) - end + local k = "jo" + print(k:upper()) end do - do - local a, b, c = "", "", "" - print(a:upper()) - end + local a, b, c = "", "", "" + print(a:upper()) end do local a = "bunk" - do - local b, c - a, b, c = "", "", "" - print(a:upper()) - end + local b, c + a, b, c = "", "", "" + print(a:upper()) end do - do - local _with_0 = j - print(_with_0:upper()) - end + local _with_0 = j + print(_with_0:upper()) end do - do - local _with_0 = "jo" - k.j = _with_0 - print(_with_0:upper()) - end + local _with_0 = "jo" + k.j = _with_0 + print(_with_0:upper()) end do - do - local _with_0 = a - print(_with_0.b) - do - local _with_1 = _with_0.c - print(_with_1.d) - end - end + local _with_0 = a + print(_with_0.b) + local _with_1 = _with_0.c + print(_with_1.d) end do - do - local _with_0 = a - do - local _with_1 = 2 - _with_0.b = _with_1 - print(_with_1.c) - end - end + local _with_0 = a + local _with_1 = 2 + _with_0.b = _with_1 + print(_with_1.c) end do local _ @@ -151,43 +125,37 @@ do end end do - do - local _with_0 = tb - _with_0.x = item.field:func(123) - end + local _with_0 = tb + _with_0.x = item.field:func(123) end do - do - local _with_0 = dad - _with_0["if"]("yes") - local y = _with_0["end"].of["function"] - end + local _with_0 = dad + _with_0["if"]("yes") + local y = _with_0["end"].of["function"] end do + local _with_0 = tb do - local _with_0 = tb - do - local _obj_0 = _with_0[2] - if _obj_0 ~= nil then - _with_0[1] = _obj_0:func() - end - end - _with_0["%a-b-c%"] = 123 - _with_0[ [[x y z]]] = _with_0[var] - print(_with_0[_with_0[3]]) - do - local _with_1 = _with_0[4] - _with_1[1] = 1 + local _obj_0 = _with_0[2] + if _obj_0 ~= nil then + _with_0[1] = _obj_0:func() end - _with_0[#_with_0 + 1] = "abc" - _with_0[#_with_0 + 1] = { - type = "hello", - { - name = "xyz", - value = 998 - } - } end + _with_0["%a-b-c%"] = 123 + _with_0[ [[x y z]]] = _with_0[var] + print(_with_0[_with_0[3]]) + do + local _with_1 = _with_0[4] + _with_1[1] = 1 + end + _with_0[#_with_0 + 1] = "abc" + _with_0[#_with_0 + 1] = { + type = "hello", + { + name = "xyz", + value = 998 + } + } end do do @@ -204,16 +172,14 @@ do end end do - do - local mask = SolidRect({ - width = w, - height = h, - color = 0x66000000 - }) - if mask ~= nil then - mask.touchEnabled = true - mask.swallowTouches = true - end + local mask = SolidRect({ + width = w, + height = h, + color = 0x66000000 + }) + if mask ~= nil then + mask.touchEnabled = true + mask.swallowTouches = true end end return nil diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 1864846..ae6c0e4 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp @@ -75,7 +75,7 @@ static std::unordered_set Metamethods = { "close"s // Lua 5.4 }; -const std::string_view version = "0.23.0"sv; +const std::string_view version = "0.23.1"sv; const std::string_view extension = "yue"sv; class CompileError : public std::logic_error { @@ -431,6 +431,7 @@ class YueCompilerImpl { }; struct Scope { GlobalMode mode = GlobalMode::None; + bool lastStatement = false; std::unique_ptr> vars; std::unique_ptr> allows; std::unique_ptr> globals; @@ -1854,12 +1855,17 @@ class YueCompilerImpl { preAssignment->expList.set(preExplist); str_list temp; temp.push_back(getPreDefineLine(assignment)); - temp.push_back(indent() + "do"s + nll(assignment)); - pushScope(); + bool needScope = !currentScope().lastStatement; + if (needScope) { + temp.push_back(indent() + "do"s + nll(assignment)); + pushScope(); + } transformAssignmentCommon(preAssignment, temp); transformAssignment(assignment, temp); - popScope(); - temp.push_back(indent() + "end"s + nll(assignment)); + if (needScope) { + popScope(); + temp.push_back(indent() + "end"s + nll(assignment)); + } out.push_back(join(temp)); return; BLOCK_END @@ -1906,11 +1912,14 @@ class YueCompilerImpl { } } auto varName = singleVariableFrom(tmpChain, AccessType::Write); - bool isScoped = false; + bool needScope = !currentScope().lastStatement; + bool extraScoped = false; if (varName.empty() || !isLocal(varName)) { - isScoped = true; - temp.push_back(indent() + "do"s + nll(x)); - pushScope(); + if (needScope) { + extraScoped = true; + temp.push_back(indent() + "do"s + nll(x)); + pushScope(); + } auto objVar = getUnusedName("_obj_"sv); auto newAssignment = x->new_ptr(); newAssignment->expList.set(toAst(objVar, x)); @@ -1929,7 +1938,7 @@ class YueCompilerImpl { assign->values.push_back(*vit); newAssignment->action.set(assign); transformAssignment(newAssignment, temp); - if (isScoped) { + if (extraScoped) { popScope(); temp.push_back(indent() + "end"s + nlr(x)); } @@ -2126,6 +2135,8 @@ class YueCompilerImpl { } else { auto x = assignment; str_list temp; + bool needScope = !currentScope().lastStatement; + bool extraScope = false; if (info.extraScope) { str_list defs; for (auto& destruct : info.destructures) { @@ -2144,8 +2155,11 @@ class YueCompilerImpl { } temp.push_back(indent() + "local "s + join(defs, ", "sv) + nll(x)); } - temp.push_back(indent() + "do"s + nll(x)); - pushScope(); + if (needScope) { + extraScope = true; + temp.push_back(indent() + "do"s + nll(x)); + pushScope(); + } } if (info.assignment) { transformAssignmentCommon(info.assignment, temp); @@ -2355,7 +2369,7 @@ class YueCompilerImpl { temp.push_back(clearBuf()); } } - if (info.extraScope) { + if (extraScope) { popScope(); temp.push_back(indent() + "end"s + nlr(x)); } @@ -3202,6 +3216,7 @@ class YueCompilerImpl { auto asmt = firstIfCond->assignment.get(); bool storingValue = false; ast_ptr extraAssignment; + bool extraScope = false; if (asmt) { auto exp = firstIfCond->condition.get(); auto x = exp; @@ -3218,8 +3233,11 @@ class YueCompilerImpl { } if (storingValue) { if (usage != ExpUsage::Closure) { - temp.push_back(indent() + "do"s + nll(asmt)); - pushScope(); + if (!currentScope().lastStatement) { + extraScope = true; + temp.push_back(indent() + "do"s + nll(asmt)); + pushScope(); + } } auto expList = toAst(desVar, x); auto assignment = x->new_ptr(); @@ -3248,8 +3266,11 @@ class YueCompilerImpl { if (!isDefined(var)) { storingValue = true; if (usage != ExpUsage::Closure) { - temp.push_back(indent() + "do"s + nll(asmt)); - pushScope(); + if (!currentScope().lastStatement) { + extraScope = true; + temp.push_back(indent() + "do"s + nll(asmt)); + pushScope(); + } } } auto expList = x->new_ptr(); @@ -3295,7 +3316,7 @@ class YueCompilerImpl { break; } } - if (storingValue && usage != ExpUsage::Closure) { + if (extraScope) { popScope(); temp.push_back(indent() + "end"s + nlr(nodes.front())); } @@ -3823,9 +3844,12 @@ class YueCompilerImpl { auto objVar = singleVariableFrom(left, AccessType::Read); auto prepareValue = [&](bool forAssignment = false) { if (objVar.empty() || !isLocal(objVar)) { + bool extraScope = !currentScope().lastStatement; if (forAssignment) { - temp.push_back(indent() + "do"s + nll(x)); - pushScope(); + if (extraScope) { + temp.push_back(indent() + "do"s + nll(x)); + pushScope(); + } } objVar = getUnusedName("_exp_"sv); auto expList = toAst(objVar, x); @@ -3835,7 +3859,7 @@ class YueCompilerImpl { assignment->expList.set(expList); assignment->action.set(assign); transformAssignment(assignment, temp); - return forAssignment; + return extraScope; } return false; }; @@ -4531,6 +4555,7 @@ class YueCompilerImpl { if (!nodes.empty()) { str_list temp; for (auto node : nodes) { + currentScope().lastStatement = (node == nodes.back()) && currentScope().mode == GlobalMode::None; transformStatement(static_cast(node), temp); if (isRoot && !_rootDefs.empty()) { auto last = std::move(temp.back()); @@ -5166,12 +5191,14 @@ class YueCompilerImpl { auto objVar = singleVariableFrom(partOne, AccessType::Read); bool isScoped = false; if (objVar.empty() || !isLocal(objVar)) { - switch (usage) { - case ExpUsage::Common: - case ExpUsage::Assignment: - isScoped = true; - break; - default: break; + if (!currentScope().lastStatement) { + switch (usage) { + case ExpUsage::Common: + case ExpUsage::Assignment: + isScoped = true; + break; + default: break; + } } if (isScoped) { temp.push_back(indent() + "do"s + nll(x)); @@ -5302,10 +5329,13 @@ class YueCompilerImpl { auto x = chainList.front(); str_list temp; std::string* funcStart = nullptr; + bool isScoped = !currentScope().lastStatement; switch (usage) { case ExpUsage::Assignment: - temp.push_back(indent() + "do"s + nll(x)); - pushScope(); + if (isScoped) { + temp.push_back(indent() + "do"s + nll(x)); + pushScope(); + } break; case ExpUsage::Closure: pushAnonFunctionScope(); @@ -5378,8 +5408,10 @@ class YueCompilerImpl { } switch (usage) { case ExpUsage::Assignment: - popScope(); - temp.push_back(indent() + "end"s + nlr(x)); + if (isScoped) { + popScope(); + temp.push_back(indent() + "end"s + nlr(x)); + } break; case ExpUsage::Closure: popScope(); @@ -5432,6 +5464,7 @@ class YueCompilerImpl { case id(): { auto colon = static_cast(*opIt); auto meta = colon->name.to(); + bool isScoped = !currentScope().lastStatement; switch (meta->item->get_id()) { case id(): { auto name = _parser.toString(meta->item); @@ -5457,8 +5490,10 @@ class YueCompilerImpl { funcStart = &temp.emplace_back(); pushScope(); } else if (usage != ExpUsage::Return) { - temp.push_back(indent() + "do"s + nll(x)); - pushScope(); + if (isScoped) { + temp.push_back(indent() + "do"s + nll(x)); + pushScope(); + } } auto var = getUnusedName("_obj_"sv); auto target = toAst(var, x); @@ -5513,14 +5548,18 @@ class YueCompilerImpl { assign->values.push_back(newChainExp); assignment->action.set(assign); transformAssignment(assignment, temp); - popScope(); - temp.push_back(indent() + "end"s + nlr(x)); + if (isScoped) { + popScope(); + temp.push_back(indent() + "end"s + nlr(x)); + } break; } case ExpUsage::Common: transformExp(newChainExp, temp, usage); - popScope(); - temp.push_back(indent() + "end"s + nlr(x)); + if (isScoped) { + popScope(); + temp.push_back(indent() + "end"s + nlr(x)); + } break; } out.push_back(join(temp)); @@ -6060,36 +6099,6 @@ class YueCompilerImpl { if (auto blockEnd = info.node.as()) { auto block = blockEnd->block.get(); info.node.set(block); - for (auto stmt_ : block->statements.objects()) { - auto stmt = static_cast(stmt_); - if (auto global = stmt->content.as()) { - if (global->item.is()) { - throw CompileError("can not use global statement with wildcard operator in macro"sv, x); - } - } else if (auto local = stmt->content.as()) { - if (local->item.is()) { - throw CompileError("can not use local statement with wildcard operator in macro"sv, x); - } - } else if (auto localAttrib = stmt->content.as()) { - if (localAttrib->attrib.is()) { - throw CompileError("can not use close attribute statement in macro"sv, x); - } - } else if (stmt->content.as()) { - throw CompileError("can not use back call statement in macro"sv, x); - } else if (auto expListAssign = stmt->content.as(); - expListAssign && expListAssign->action && expListAssign->action.is()) { - BLOCK_START - auto unary = singleUnaryExpFrom(expListAssign->expList->exprs.back()); - BREAK_IF(!unary->ops.empty()); - auto value = static_cast(unary->expos.front()); - auto simpleValue = value->item.as(); - BREAK_IF(!simpleValue); - auto varArg = simpleValue->value.as(); - BREAK_IF(!varArg); - throw CompileError("can not use variadic arguments assignment statement in macro"sv, x); - BLOCK_END - } - } } return {info.node, std::move(info.codes), Empty, std::move(localVars)}; } else { @@ -6118,7 +6127,15 @@ class YueCompilerImpl { return; } if (usage == ExpUsage::Common || (usage == ExpUsage::Return && node.is())) { - transformBlock(node.to(), out, usage, assignList); + if (node.to()->statements.empty()) { + out.push_back(Empty); + } else { + auto doBody = node->new_ptr(); + doBody->content.set(node); + auto doNode = node->new_ptr(); + doNode->body.set(doBody); + transformDo(doNode, out, usage, assignList); + } } else { auto x = chainValue; switch (usage) { @@ -6428,6 +6445,7 @@ class YueCompilerImpl { } if (varName.empty()) { str_list temp; + bool isScoped = !currentScope().lastStatement; if (usage == ExpUsage::Closure) { if (transformAsUpValueFunc(newExp(unary_exp, unary_exp), out)) { return; @@ -6436,8 +6454,10 @@ class YueCompilerImpl { pushAnonVarArg(); pushScope(); } else if (usage == ExpUsage::Assignment) { - temp.push_back(indent() + "do"s + nll(x)); - pushScope(); + if (isScoped) { + temp.push_back(indent() + "do"s + nll(x)); + pushScope(); + } } auto newUnaryExp = x->new_ptr(); newUnaryExp->ops.dup(unary_exp->ops); @@ -6485,8 +6505,10 @@ class YueCompilerImpl { popAnonVarArg(); popFunctionScope(); } else if (usage == ExpUsage::Assignment) { - popScope(); - temp.push_back(indent() + "end"s + nll(x)); + if (isScoped) { + popScope(); + temp.push_back(indent() + "end"s + nll(x)); + } out.push_back(join(temp)); } else { out.push_back(join(temp)); @@ -6573,6 +6595,7 @@ class YueCompilerImpl { void transformSpreadTable(const node_container& values, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { auto x = values.front(); + bool extraScope = false; switch (usage) { case ExpUsage::Closure: { auto tableLit = x->new_ptr(); @@ -6590,7 +6613,10 @@ class YueCompilerImpl { break; } case ExpUsage::Assignment: - pushScope(); + if (!currentScope().lastStatement) { + extraScope = true; + pushScope(); + } break; default: break; @@ -6850,9 +6876,11 @@ class YueCompilerImpl { assignment->expList.set(assignList); assignment->action.set(assign); transformAssignment(assignment, temp); - popScope(); + if (extraScope) popScope(); out.push_back(join(temp)); - out.back() = indent() + "do"s + nll(x) + out.back() + indent() + "end"s + nlr(x); + if (extraScope) { + out.back() = indent() + "do"s + nll(x) + out.back() + indent() + "end"s + nlr(x); + } break; } case ExpUsage::Return: @@ -7107,6 +7135,7 @@ class YueCompilerImpl { if (!def || def->defVal) { throw CompileError("invalid comprehension expression", comp->items.front()); } + bool extraScope = false; switch (usage) { case ExpUsage::Closure: { auto simpleValue = x->new_ptr(); @@ -7120,7 +7149,10 @@ class YueCompilerImpl { break; } case ExpUsage::Assignment: - pushScope(); + if (!currentScope().lastStatement) { + extraScope = true; + pushScope(); + } break; default: break; @@ -7191,8 +7223,11 @@ class YueCompilerImpl { assignment->expList.set(assignList); assignment->action.set(assign); transformAssignment(assignment, temp); - popScope(); - out.back() = indent() + "do"s + nll(comp) + out.back() + temp.back() + indent() + "end"s + nlr(comp); + out.back().append(temp.back()); + if (extraScope) { + popScope(); + out.back() = indent() + "do"s + nll(comp) + out.back() + indent() + "end"s + nlr(comp); + } break; } case ExpUsage::Return: @@ -7204,13 +7239,14 @@ class YueCompilerImpl { } } - bool transformForEachHead(AssignableNameList_t* nameList, ast_node* loopTarget, str_list& out, bool isStatement = false) { + bool transformForEachHead(AssignableNameList_t* nameList, ast_node* loopTarget, str_list& out, bool inClosure) { auto x = nameList; str_list temp; str_list vars; str_list varBefore, varAfter; std::string varConstAfter; bool extraScope = false; + bool needScope = !currentScope().lastStatement; std::list>> destructPairs; for (auto _item : nameList->items.objects()) { auto item = static_cast(_item)->item.get(); @@ -7287,7 +7323,7 @@ class YueCompilerImpl { } if (listVar.empty()) { std::string prefix; - if (isStatement) { + if (!inClosure && needScope) { extraScope = true; prefix = indent() + "do"s + nll(x); pushScope(); @@ -7300,7 +7336,7 @@ class YueCompilerImpl { std::string maxVar; if (!stopValue.empty()) { std::string prefix; - if (isStatement && !extraScope) { + if (!extraScope && !inClosure && needScope) { extraScope = true; prefix = indent() + "do"s + nll(x); pushScope(); @@ -7376,7 +7412,7 @@ class YueCompilerImpl { } void transformCompForEach(CompForEach_t* comp, str_list& out) { - transformForEachHead(comp->nameList, comp->loopValue, out); + transformForEachHead(comp->nameList, comp->loopValue, out, true); } void transformInvokeArgs(InvokeArgs_t* invokeArgs, str_list& out) { @@ -7741,9 +7777,12 @@ class YueCompilerImpl { void transformForInPlace(For_t* forNode, str_list& out, ExpList_t* assignExpList = nullptr) { auto x = forNode; str_list temp; + bool isScoped = !currentScope().lastStatement; if (assignExpList) { - _buf << indent() << "do"sv << nll(forNode); - pushScope(); + if (isScoped) { + _buf << indent() << "do"sv << nll(forNode); + pushScope(); + } auto accum = transformForInner(forNode, temp); auto assign = x->new_ptr(); assign->values.push_back(toAst(accum, x)); @@ -7751,8 +7790,10 @@ class YueCompilerImpl { assignment->expList.set(assignExpList); assignment->action.set(assign); transformAssignment(assignment, temp); - popScope(); - temp.push_back(indent() + "end"s + nlr(forNode)); + if (isScoped) { + popScope(); + temp.push_back(indent() + "end"s + nlr(forNode)); + } } else { auto accum = transformForInner(forNode, temp); auto returnNode = x->new_ptr(); @@ -7783,11 +7824,11 @@ class YueCompilerImpl { void transformForEach(ForEach_t* forEach, str_list& out) { str_list temp; - bool extraScope = transformForEachHead(forEach->nameList, forEach->loopValue, temp, true); + bool extraScoped = transformForEachHead(forEach->nameList, forEach->loopValue, temp, false); transformLoopBody(forEach->body, temp, Empty, ExpUsage::Common); popScope(); out.push_back(temp.front() + temp.back() + indent() + "end"s + nlr(forEach)); - if (extraScope) { + if (extraScoped) { popScope(); out.back().append(indent() + "end"s + nlr(forEach)); } @@ -7802,7 +7843,7 @@ class YueCompilerImpl { _buf << indent() << "local "sv << accum << " = { }"sv << nll(forEach); _buf << indent() << "local "sv << len << " = 1"sv << nll(forEach); out.push_back(clearBuf()); - transformForEachHead(forEach->nameList, forEach->loopValue, out); + transformForEachHead(forEach->nameList, forEach->loopValue, out, true); auto expList = toAst(accum + '[' + len + ']', x); auto lenLine = len + " = "s + len + " + 1"s + nlr(forEach->body); transformLoopBody(forEach->body, out, lenLine, ExpUsage::Assignment, expList); @@ -7835,9 +7876,12 @@ class YueCompilerImpl { void transformForEachInPlace(ForEach_t* forEach, str_list& out, ExpList_t* assignExpList = nullptr) { auto x = forEach; str_list temp; + bool isScoped = !currentScope().lastStatement; if (assignExpList) { - _buf << indent() << "do"sv << nll(forEach); - pushScope(); + if (isScoped) { + _buf << indent() << "do"sv << nll(forEach); + pushScope(); + } auto accum = transformForEachInner(forEach, temp); auto assign = x->new_ptr(); assign->values.push_back(toAst(accum, x)); @@ -7845,8 +7889,10 @@ class YueCompilerImpl { assignment->expList.set(assignExpList); assignment->action.set(assign); transformAssignment(assignment, temp); - popScope(); - temp.push_back(indent() + "end"s + nlr(forEach)); + if (isScoped) { + popScope(); + temp.push_back(indent() + "end"s + nlr(forEach)); + } } else { auto accum = transformForEachInner(forEach, temp); auto returnNode = x->new_ptr(); @@ -8035,6 +8081,7 @@ class YueCompilerImpl { std::string className; std::string assignItem; std::string classTextName; + bool isScoped = !currentScope().lastStatement; if (assignable) { if (!isAssignable(assignable)) { throw CompileError("left hand expression is not assignable"sv, assignable); @@ -8078,8 +8125,10 @@ class YueCompilerImpl { } } } - temp.push_back(indent() + "do"s + nll(classDecl)); - pushScope(); + if (isScoped) { + temp.push_back(indent() + "do"s + nll(classDecl)); + pushScope(); + } auto classVar = getUnusedName("_class_"sv); addToScope(classVar); temp.push_back(indent() + "local "s + classVar + nll(classDecl)); @@ -8295,8 +8344,10 @@ class YueCompilerImpl { default: break; } temp.push_back(clearBuf()); - popScope(); - temp.push_back(indent() + "end"s + nlr(classDecl)); + if (isScoped) { + popScope(); + temp.push_back(indent() + "end"s + nlr(classDecl)); + } out.push_back(join(temp)); } @@ -8469,7 +8520,8 @@ class YueCompilerImpl { auto x = with; str_list temp; std::string withVar; - bool scoped = false; + bool needScope = !currentScope().lastStatement && !returnValue; + bool extraScope = false; if (with->assigns) { auto vars = getAssignVars(with); if (vars.front().empty() || isDeclaredAsGlobal(vars.front())) { @@ -8486,8 +8538,8 @@ class YueCompilerImpl { auto assign = x->new_ptr(); assign->values.push_back(with->assigns->values.objects().front()); assignment->action.set(assign); - if (!returnValue) { - scoped = true; + if (needScope) { + extraScope = true; temp.push_back(indent() + "do"s + nll(with)); pushScope(); } @@ -8512,8 +8564,8 @@ class YueCompilerImpl { auto assignment = x->new_ptr(); assignment->expList.set(with->valueList); assignment->action.set(with->assigns); - if (!returnValue) { - scoped = true; + if (needScope) { + extraScope = true; temp.push_back(indent() + "do"s + nll(with)); pushScope(); } @@ -8528,17 +8580,17 @@ class YueCompilerImpl { auto assign = x->new_ptr(); assign->values.dup(with->valueList->exprs); assignment->action.set(assign); - if (!returnValue) { - scoped = true; + if (needScope) { + extraScope = true; temp.push_back(indent() + "do"s + nll(with)); pushScope(); } transformAssignment(assignment, temp); } } - if (!with->eop && !scoped && !returnValue) { + if (needScope && !with->eop && !extraScope) { pushScope(); - scoped = traversal::Stop == with->body->traverse([&](ast_node* node) { + extraScope = traversal::Stop == with->body->traverse([&](ast_node* node) { if (auto statement = ast_cast(node)) { ClassDecl_t* clsDecl = nullptr; if (auto assignment = assignmentFrom(statement)) { @@ -8576,7 +8628,7 @@ class YueCompilerImpl { return traversal::Continue; }); popScope(); - if (scoped) { + if (extraScope) { temp.push_back(indent() + "do"s + nll(with)); pushScope(); } @@ -8606,7 +8658,7 @@ class YueCompilerImpl { temp.push_back(indent() + "return "s + withVar + nll(with)); } } - if (scoped) { + if (extraScope) { popScope(); temp.push_back(indent() + "end"s + nll(with)); } @@ -8863,6 +8915,7 @@ class YueCompilerImpl { } void transformTblComprehension(TblComprehension_t* comp, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { + bool extraScope = false; switch (usage) { case ExpUsage::Closure: { auto simpleValue = comp->new_ptr(); @@ -8876,7 +8929,10 @@ class YueCompilerImpl { break; } case ExpUsage::Assignment: - pushScope(); + if (!currentScope().lastStatement) { + extraScope = true; + pushScope(); + } break; default: break; @@ -8944,9 +9000,11 @@ class YueCompilerImpl { assignment->action.set(assign); transformAssignment(assignment, temp); out.back().append(temp.back()); - popScope(); - out.back().insert(0, indent() + "do"s + nll(comp)); - out.back().append(indent() + "end"s + nlr(comp)); + if (extraScope) { + popScope(); + out.back().insert(0, indent() + "do"s + nll(comp)); + out.back().append(indent() + "end"s + nlr(comp)); + } break; } case ExpUsage::Return: @@ -8986,18 +9044,20 @@ class YueCompilerImpl { pushAnonFunctionScope(); pushAnonVarArg(); funcStart = &temp.emplace_back(); + pushScope(); } else { temp.push_back(indent() + "do"s + nll(doNode)); + pushScope(); } - pushScope(); transformBody(doNode->body, temp, usage, assignList); - popScope(); if (usage == ExpUsage::Closure) { + popScope(); *funcStart = anonFuncStart() + nll(doNode); temp.push_back(indent() + anonFuncEnd()); popAnonVarArg(); popFunctionScope(); } else { + popScope(); temp.push_back(indent() + "end"s + nlr(doNode)); } out.push_back(join(temp)); @@ -9225,13 +9285,17 @@ class YueCompilerImpl { default: YUEE("AST node mismatch", name); break; } } + bool extraScope = false; if (objAssign) { auto preDef = toLocalDecl(transformAssignDefs(expList, DefOp::Mark)); if (!preDef.empty()) { temp.push_back(preDef + nll(importNode)); } - temp.push_back(indent() + "do"s + nll(importNode)); - pushScope(); + if (!currentScope().lastStatement) { + extraScope = true; + temp.push_back(indent() + "do"s + nll(importNode)); + pushScope(); + } transformAssignment(objAssign, temp); } auto assignment = x->new_ptr(); @@ -9239,8 +9303,10 @@ class YueCompilerImpl { assignment->action.set(assign); transformAssignment(assignment, temp); if (objAssign) { - popScope(); - temp.push_back(indent() + "end"s + nlr(importNode)); + if (extraScope) { + popScope(); + temp.push_back(indent() + "end"s + nlr(importNode)); + } } out.push_back(join(temp)); auto vars = getAssignVars(assignment); @@ -9485,9 +9551,13 @@ class YueCompilerImpl { void transformWhileInPlace(While_t* whileNode, str_list& out, ExpList_t* expList = nullptr) { auto x = whileNode; str_list temp; + bool extraScope = false; if (expList) { - temp.push_back(indent() + "do"s + nll(whileNode)); - pushScope(); + if (!currentScope().lastStatement) { + extraScope = true; + temp.push_back(indent() + "do"s + nll(whileNode)); + pushScope(); + } } auto accumVar = getUnusedName("_accum_"sv); addToScope(accumVar); @@ -9511,11 +9581,11 @@ class YueCompilerImpl { assignment->expList.set(expList); assignment->action.set(assign); transformAssignment(assignment, temp); - popScope(); + if (extraScope) popScope(); } else { temp.push_back(indent() + "return "s + accumVar + nlr(whileNode)); } - if (expList) { + if (expList && extraScope) { temp.push_back(indent() + "end"s + nlr(whileNode)); } out.push_back(join(temp)); @@ -9589,6 +9659,7 @@ class YueCompilerImpl { void transformSwitch(Switch_t* switchNode, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { auto x = switchNode; str_list temp; + bool needScope = !currentScope().lastStatement; std::string* funcStart = nullptr; if (usage == ExpUsage::Closure) { auto simpleValue = x->new_ptr(); @@ -9605,9 +9676,11 @@ class YueCompilerImpl { auto objVar = singleVariableFrom(switchNode->target, AccessType::Read); if (objVar.empty() || !isLocal(objVar)) { if (usage == ExpUsage::Common || usage == ExpUsage::Assignment) { - extraScope = true; - temp.push_back(indent() + "do"s + nll(x)); - pushScope(); + if (needScope) { + extraScope = true; + temp.push_back(indent() + "do"s + nll(x)); + pushScope(); + } } objVar = getUnusedName("_exp_"sv); auto expList = toAst(objVar, x); @@ -9640,7 +9713,7 @@ class YueCompilerImpl { addScope++; } if (tabCheckVar.empty()) { - if (!extraScope) { + if (!extraScope && needScope) { temp.push_back(indent() + "do"s + nll(branch)); pushScope(); extraScope = true;