diff options
| author | Li Jin <dragon-fly@qq.com> | 2024-03-21 09:14:34 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2024-03-21 09:14:34 +0800 |
| commit | 4a3cc26c6dfd74e61c8b6480038d6a292ea86e47 (patch) | |
| tree | 9554b94cfc15e4acee0c2e60b63af16f1b828207 /spec/outputs/macro.lua | |
| parent | 80b65520da432843f0c63431a1867bd2620bc4ac (diff) | |
| download | yuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.tar.gz yuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.tar.bz2 yuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.zip | |
remove redundant 'do' blocks in code generation.
Diffstat (limited to 'spec/outputs/macro.lua')
| -rw-r--r-- | spec/outputs/macro.lua | 214 |
1 files changed, 113 insertions, 101 deletions
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 @@ | |||
| 1 | assert(item == nil) | 1 | do |
| 2 | assert(item == nil) | ||
| 3 | end | ||
| 2 | local v = (item == nil) | 4 | local v = (item == nil) |
| 3 | if f1() then | 5 | if f1() then |
| 4 | print("OK") | 6 | print("OK") |
| @@ -9,86 +11,86 @@ end | |||
| 9 | local item | 11 | local item |
| 10 | do | 12 | do |
| 11 | local _src_, _dst_ | 13 | local _src_, _dst_ |
| 12 | do | 14 | _dst_ = { |
| 13 | _dst_ = { | 15 | pos = { }, |
| 14 | pos = { }, | 16 | flags = flags:tonumber() |
| 15 | flags = flags:tonumber() | 17 | } |
| 16 | } | 18 | _src_ = self |
| 17 | do | 19 | _dst_.id = _src_.id |
| 18 | _src_ = self | 20 | _dst_.connections = _src_.connections |
| 19 | _dst_.id = _src_.id | 21 | _dst_.pos.x = _src_.pos.x |
| 20 | _dst_.connections = _src_.connections | 22 | _dst_.pos.y = _src_.pos.y |
| 21 | _dst_.pos.x = _src_.pos.x | 23 | _dst_.pos.z = _src_.pos.z |
| 22 | _dst_.pos.y = _src_.pos.y | 24 | item = _dst_ |
| 23 | _dst_.pos.z = _src_.pos.z | ||
| 24 | end | ||
| 25 | item = _dst_ | ||
| 26 | end | ||
| 27 | end | 25 | end |
| 28 | if (x == "Apple" or x == "Pig" or x == "Dog") then | 26 | if (x == "Apple" or x == "Pig" or x == "Dog") then |
| 29 | print("exist") | 27 | print("exist") |
| 30 | end | 28 | end |
| 31 | local _list_0 = (function() | 29 | do |
| 32 | local _accum_0 = { } | ||
| 33 | local _len_0 = 1 | ||
| 34 | local _list_0 = (function() | 30 | local _list_0 = (function() |
| 35 | local _accum_1 = { } | 31 | local _accum_0 = { } |
| 36 | local _len_1 = 1 | 32 | local _len_0 = 1 |
| 37 | local _list_0 = { | 33 | local _list_0 = (function() |
| 38 | 1, | 34 | local _accum_1 = { } |
| 39 | 2, | 35 | local _len_1 = 1 |
| 40 | 3 | 36 | local _list_0 = { |
| 41 | } | 37 | 1, |
| 38 | 2, | ||
| 39 | 3 | ||
| 40 | } | ||
| 41 | for _index_0 = 1, #_list_0 do | ||
| 42 | local _ = _list_0[_index_0] | ||
| 43 | _accum_1[_len_1] = _ * 2 | ||
| 44 | _len_1 = _len_1 + 1 | ||
| 45 | end | ||
| 46 | return _accum_1 | ||
| 47 | end)() | ||
| 42 | for _index_0 = 1, #_list_0 do | 48 | for _index_0 = 1, #_list_0 do |
| 43 | local _ = _list_0[_index_0] | 49 | local _ = _list_0[_index_0] |
| 44 | _accum_1[_len_1] = _ * 2 | 50 | if _ > 4 then |
| 45 | _len_1 = _len_1 + 1 | 51 | _accum_0[_len_0] = _ |
| 52 | _len_0 = _len_0 + 1 | ||
| 53 | end | ||
| 46 | end | 54 | end |
| 47 | return _accum_1 | 55 | return _accum_0 |
| 48 | end)() | 56 | end)() |
| 49 | for _index_0 = 1, #_list_0 do | 57 | for _index_0 = 1, #_list_0 do |
| 50 | local _ = _list_0[_index_0] | 58 | local _ = _list_0[_index_0] |
| 51 | if _ > 4 then | 59 | print(_) |
| 52 | _accum_0[_len_0] = _ | ||
| 53 | _len_0 = _len_0 + 1 | ||
| 54 | end | ||
| 55 | end | 60 | end |
| 56 | return _accum_0 | ||
| 57 | end)() | ||
| 58 | for _index_0 = 1, #_list_0 do | ||
| 59 | local _ = _list_0[_index_0] | ||
| 60 | print(_) | ||
| 61 | end | 61 | end |
| 62 | local _list_1 = (function() | 62 | do |
| 63 | local _accum_0 = { } | 63 | local _list_0 = (function() |
| 64 | local _len_0 = 1 | 64 | local _accum_0 = { } |
| 65 | local _list_1 = (function() | 65 | local _len_0 = 1 |
| 66 | local _accum_1 = { } | 66 | local _list_0 = (function() |
| 67 | local _len_1 = 1 | 67 | local _accum_1 = { } |
| 68 | local _list_1 = { | 68 | local _len_1 = 1 |
| 69 | 1, | 69 | local _list_0 = { |
| 70 | 2, | 70 | 1, |
| 71 | 3 | 71 | 2, |
| 72 | } | 72 | 3 |
| 73 | for _index_0 = 1, #_list_1 do | 73 | } |
| 74 | local _ = _list_1[_index_0] | 74 | for _index_0 = 1, #_list_0 do |
| 75 | _accum_1[_len_1] = _ * 2 | 75 | local _ = _list_0[_index_0] |
| 76 | _len_1 = _len_1 + 1 | 76 | _accum_1[_len_1] = _ * 2 |
| 77 | _len_1 = _len_1 + 1 | ||
| 78 | end | ||
| 79 | return _accum_1 | ||
| 80 | end)() | ||
| 81 | for _index_0 = 1, #_list_0 do | ||
| 82 | local _ = _list_0[_index_0] | ||
| 83 | if _ > 4 then | ||
| 84 | _accum_0[_len_0] = _ | ||
| 85 | _len_0 = _len_0 + 1 | ||
| 86 | end | ||
| 77 | end | 87 | end |
| 78 | return _accum_1 | 88 | return _accum_0 |
| 79 | end)() | 89 | end)() |
| 80 | for _index_0 = 1, #_list_1 do | 90 | for _index_0 = 1, #_list_0 do |
| 81 | local _ = _list_1[_index_0] | 91 | local _ = _list_0[_index_0] |
| 82 | if _ > 4 then | 92 | print(_) |
| 83 | _accum_0[_len_0] = _ | ||
| 84 | _len_0 = _len_0 + 1 | ||
| 85 | end | ||
| 86 | end | 93 | end |
| 87 | return _accum_0 | ||
| 88 | end)() | ||
| 89 | for _index_0 = 1, #_list_1 do | ||
| 90 | local _ = _list_1[_index_0] | ||
| 91 | print(_) | ||
| 92 | end | 94 | end |
| 93 | local val | 95 | local val |
| 94 | do | 96 | do |
| @@ -96,13 +98,13 @@ do | |||
| 96 | do | 98 | do |
| 97 | local _accum_0 = { } | 99 | local _accum_0 = { } |
| 98 | local _len_0 = 1 | 100 | local _len_0 = 1 |
| 99 | local _list_2 = { | 101 | local _list_0 = { |
| 100 | 1, | 102 | 1, |
| 101 | 2, | 103 | 2, |
| 102 | 3 | 104 | 3 |
| 103 | } | 105 | } |
| 104 | for _index_0 = 1, #_list_2 do | 106 | for _index_0 = 1, #_list_0 do |
| 105 | local _ = _list_2[_index_0] | 107 | local _ = _list_0[_index_0] |
| 106 | _accum_0[_len_0] = _ * 2 | 108 | _accum_0[_len_0] = _ * 2 |
| 107 | _len_0 = _len_0 + 1 | 109 | _len_0 = _len_0 + 1 |
| 108 | end | 110 | end |
| @@ -134,7 +136,9 @@ do | |||
| 134 | end | 136 | end |
| 135 | val = _4 | 137 | val = _4 |
| 136 | end | 138 | end |
| 137 | (1 + 2):call(123) | 139 | do |
| 140 | (1 + 2):call(123) | ||
| 141 | end | ||
| 138 | local res = (1 + 2) | 142 | local res = (1 + 2) |
| 139 | local f | 143 | local f |
| 140 | f = function(x) | 144 | f = function(x) |
| @@ -210,40 +214,44 @@ local a = ((((_({ | |||
| 210 | return self * 2 | 214 | return self * 2 |
| 211 | end)):filter(function(self) | 215 | end)):filter(function(self) |
| 212 | return self > 3 | 216 | return self > 3 |
| 213 | end)):value(); | 217 | end)):value() |
| 214 | ((((_({ | 218 | do |
| 215 | 1, | 219 | ((((_({ |
| 216 | 2, | 220 | 1, |
| 217 | 3, | 221 | 2, |
| 218 | 4, | 222 | 3, |
| 219 | -2, | 223 | 4, |
| 220 | 3 | 224 | -2, |
| 221 | })):chain()):map(function(self) | 225 | 3 |
| 222 | return self * 2 | 226 | })):chain()):map(function(self) |
| 223 | end)):filter(function(self) | 227 | return self * 2 |
| 224 | return self > 3 | 228 | end)):filter(function(self) |
| 225 | end)):each(function(self) | 229 | return self > 3 |
| 226 | return print(self) | 230 | end)):each(function(self) |
| 227 | end) | 231 | return print(self) |
| 232 | end) | ||
| 233 | end | ||
| 228 | local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()):SelectEnable()):SelectVisible()):TagEqual("fx")):Where(function(x) | 234 | local result = ((((((origin.transform.root.gameObject:Parents()):Descendants()):SelectEnable()):SelectVisible()):TagEqual("fx")):Where(function(x) |
| 229 | return x.name:EndsWith("(Clone)") | 235 | return x.name:EndsWith("(Clone)") |
| 230 | end)):Destroy() | 236 | end)):Destroy() |
| 231 | do | 237 | do |
| 232 | local _1 | 238 | do |
| 233 | _1 = origin.transform.root.gameObject:Parents() | 239 | local _1 |
| 234 | local _2 | 240 | _1 = origin.transform.root.gameObject:Parents() |
| 235 | _2 = _1:Descendants() | 241 | local _2 |
| 236 | local _3 | 242 | _2 = _1:Descendants() |
| 237 | _3 = _2:SelectEnable() | 243 | local _3 |
| 238 | local _4 | 244 | _3 = _2:SelectEnable() |
| 239 | _4 = _3:SelectVisible() | 245 | local _4 |
| 240 | local _5 | 246 | _4 = _3:SelectVisible() |
| 241 | _5 = _4:TagEqual("fx") | 247 | local _5 |
| 242 | local _6 | 248 | _5 = _4:TagEqual("fx") |
| 243 | _6 = _5:Where(function(x) | 249 | local _6 |
| 244 | return x.name:EndsWith("(Clone)") | 250 | _6 = _5:Where(function(x) |
| 245 | end) | 251 | return x.name:EndsWith("(Clone)") |
| 246 | _6:Destroy() | 252 | end) |
| 253 | _6:Destroy() | ||
| 254 | end | ||
| 247 | end | 255 | end |
| 248 | origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) | 256 | origin.transform.root.gameObject:Parents():Descendants():SelectEnable():SelectVisible():TagEqual("fx"):Where(function(x) |
| 249 | return x.name:EndsWith("(Clone)") | 257 | return x.name:EndsWith("(Clone)") |
| @@ -278,7 +286,9 @@ print((setmetatable({ | |||
| 278 | end | 286 | end |
| 279 | })) | 287 | })) |
| 280 | print("current line: " .. tostring(268)) | 288 | print("current line: " .. tostring(268)) |
| 289 | do | ||
| 281 | -- TODO | 290 | -- TODO |
| 291 | end | ||
| 282 | do | 292 | do |
| 283 | print(1) | 293 | print(1) |
| 284 | end | 294 | end |
| @@ -293,5 +303,7 @@ _1 = function() | |||
| 293 | end | 303 | end |
| 294 | return _accum_0 | 304 | return _accum_0 |
| 295 | end | 305 | end |
| 296 | print('abc') | 306 | do |
| 297 | return 123 | 307 | print('abc') |
| 308 | return 123 | ||
| 309 | end | ||
