aboutsummaryrefslogtreecommitdiff
path: root/spec/outputs/switch.lua
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2024-03-21 09:14:34 +0800
committerLi Jin <dragon-fly@qq.com>2024-03-21 09:14:34 +0800
commit4a3cc26c6dfd74e61c8b6480038d6a292ea86e47 (patch)
tree9554b94cfc15e4acee0c2e60b63af16f1b828207 /spec/outputs/switch.lua
parent80b65520da432843f0c63431a1867bd2620bc4ac (diff)
downloadyuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.tar.gz
yuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.tar.bz2
yuescript-4a3cc26c6dfd74e61c8b6480038d6a292ea86e47.zip
remove redundant 'do' blocks in code generation.
Diffstat (limited to 'spec/outputs/switch.lua')
-rw-r--r--spec/outputs/switch.lua420
1 files changed, 201 insertions, 219 deletions
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
45end 45end
46do 46do
47 local _with_0 = something 47 local _with_0 = something
48 do 48 local _exp_0 = _with_0:value()
49 local _exp_0 = _with_0:value() 49 if _with_0.okay == _exp_0 then
50 if _with_0.okay == _exp_0 then 50 local _ = "world"
51 local _ = "world" 51 else
52 else 52 local _ = "yesh"
53 local _ = "yesh"
54 end
55 end 53 end
56end 54end
57fix(this) 55fix(this)
@@ -106,66 +104,64 @@ do
106 } 104 }
107 } 105 }
108 } 106 }
109 do 107 local _type_0 = type(dict)
110 local _type_0 = type(dict) 108 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
111 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 109 if _tab_0 then
112 if _tab_0 then 110 local first = dict[1]
113 local first = dict[1] 111 local one
114 local one 112 do
115 do 113 local _obj_0 = dict[2]
116 local _obj_0 = dict[2] 114 local _type_1 = type(_obj_0)
117 local _type_1 = type(_obj_0) 115 if "table" == _type_1 or "userdata" == _type_1 then
118 if "table" == _type_1 or "userdata" == _type_1 then 116 one = _obj_0[1]
119 one = _obj_0[1]
120 end
121 end 117 end
122 local two 118 end
123 do 119 local two
124 local _obj_0 = dict[2] 120 do
125 local _type_1 = type(_obj_0) 121 local _obj_0 = dict[2]
126 if "table" == _type_1 or "userdata" == _type_1 then 122 local _type_1 = type(_obj_0)
127 two = _obj_0[2] 123 if "table" == _type_1 or "userdata" == _type_1 then
128 end 124 two = _obj_0[2]
129 end 125 end
130 local three 126 end
131 do 127 local three
132 local _obj_0 = dict[2] 128 do
133 local _type_1 = type(_obj_0) 129 local _obj_0 = dict[2]
134 if "table" == _type_1 or "userdata" == _type_1 then 130 local _type_1 = type(_obj_0)
135 three = _obj_0[3] 131 if "table" == _type_1 or "userdata" == _type_1 then
136 end 132 three = _obj_0[3]
137 end 133 end
138 local c 134 end
139 do 135 local c
140 local _obj_0 = dict.a 136 do
141 local _type_1 = type(_obj_0) 137 local _obj_0 = dict.a
142 if "table" == _type_1 or "userdata" == _type_1 then 138 local _type_1 = type(_obj_0)
143 do 139 if "table" == _type_1 or "userdata" == _type_1 then
144 local _obj_1 = _obj_0.b 140 do
145 local _type_2 = type(_obj_1) 141 local _obj_1 = _obj_0.b
146 if "table" == _type_2 or "userdata" == _type_2 then 142 local _type_2 = type(_obj_1)
147 c = _obj_1.c 143 if "table" == _type_2 or "userdata" == _type_2 then
148 end 144 c = _obj_1.c
149 end 145 end
150 end 146 end
151 end 147 end
152 local z 148 end
153 do 149 local z
154 local _obj_0 = dict.x 150 do
155 local _type_1 = type(_obj_0) 151 local _obj_0 = dict.x
156 if "table" == _type_1 or "userdata" == _type_1 then 152 local _type_1 = type(_obj_0)
157 do 153 if "table" == _type_1 or "userdata" == _type_1 then
158 local _obj_1 = _obj_0.y 154 do
159 local _type_2 = type(_obj_1) 155 local _obj_1 = _obj_0.y
160 if "table" == _type_2 or "userdata" == _type_2 then 156 local _type_2 = type(_obj_1)
161 z = _obj_1.z 157 if "table" == _type_2 or "userdata" == _type_2 then
162 end 158 z = _obj_1.z
163 end 159 end
164 end 160 end
165 end 161 end
166 if first ~= nil and one ~= nil and two ~= nil and three ~= nil and c ~= nil and z ~= nil then 162 end
167 print(first, one, two, three, c, z) 163 if first ~= nil and one ~= nil and two ~= nil and three ~= nil and c ~= nil and z ~= nil then
168 end 164 print(first, one, two, three, c, z)
169 end 165 end
170 end 166 end
171end 167end
@@ -183,56 +179,54 @@ do
183 } 179 }
184 for _index_0 = 1, #items do 180 for _index_0 = 1, #items do
185 local item = items[_index_0] 181 local item = items[_index_0]
186 do 182 local _type_0 = type(item)
187 local _type_0 = type(item) 183 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
188 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 184 local _match_0 = false
189 local _match_0 = false 185 if _tab_0 then
186 local x = item.x
187 local y = item.y
188 if x ~= nil and y ~= nil then
189 _match_0 = true
190 print("Vec2 " .. tostring(x) .. ", " .. tostring(y))
191 end
192 end
193 if not _match_0 then
194 local _match_1 = false
190 if _tab_0 then 195 if _tab_0 then
191 local x = item.x 196 local width = item.width
192 local y = item.y 197 local height = item.height
193 if x ~= nil and y ~= nil then 198 if width ~= nil and height ~= nil then
194 _match_0 = true 199 _match_1 = true
195 print("Vec2 " .. tostring(x) .. ", " .. tostring(y)) 200 print("Size " .. tostring(width) .. ", " .. tostring(height))
196 end 201 end
197 end 202 end
198 if not _match_0 then 203 if not _match_1 then
199 local _match_1 = false 204 if false == item then
200 if _tab_0 then 205 print("None")
201 local width = item.width 206 else
202 local height = item.height 207 local _match_2 = false
203 if width ~= nil and height ~= nil then 208 if _tab_0 then
204 _match_1 = true 209 local cls = item.__class
205 print("Size " .. tostring(width) .. ", " .. tostring(height)) 210 if cls ~= nil then
211 _match_2 = true
212 if ClassA == cls then
213 print("Object A")
214 elseif ClassB == cls then
215 print("Object B")
216 end
217 end
206 end 218 end
207 end 219 if not _match_2 then
208 if not _match_1 then 220 local _match_3 = false
209 if false == item then
210 print("None")
211 else
212 local _match_2 = false
213 if _tab_0 then 221 if _tab_0 then
214 local cls = item.__class 222 local mt = getmetatable(item)
215 if cls ~= nil then 223 if mt ~= nil then
216 _match_2 = true 224 _match_3 = true
217 if ClassA == cls then 225 print("A table with metatable")
218 print("Object A")
219 elseif ClassB == cls then
220 print("Object B")
221 end
222 end 226 end
223 end 227 end
224 if not _match_2 then 228 if not _match_3 then
225 local _match_3 = false 229 print("item not accepted!")
226 if _tab_0 then
227 local mt = getmetatable(item)
228 if mt ~= nil then
229 _match_3 = true
230 print("A table with metatable")
231 end
232 end
233 if not _match_3 then
234 print("item not accepted!")
235 end
236 end 230 end
237 end 231 end
238 end 232 end
@@ -271,72 +265,66 @@ do
271 end 265 end
272 end 266 end
273 end 267 end
274 do 268 local _type_0 = type(tb)
275 local _type_0 = type(tb) 269 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
276 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 270 local _match_0 = false
277 local _match_0 = false 271 if _tab_0 then
278 if _tab_0 then 272 local a = tb.a
279 local a = tb.a 273 local b = tb.b
280 local b = tb.b 274 if a ~= nil and b ~= nil then
281 if a ~= nil and b ~= nil then 275 _match_0 = true
282 _match_0 = true 276 print(a, b)
283 print(a, b)
284 end
285 end
286 if not _match_0 then
287 print("not matched")
288 end 277 end
289 end 278 end
279 if not _match_0 then
280 print("not matched")
281 end
290end 282end
291do 283do
292 local tb = { 284 local tb = {
293 x = "abc" 285 x = "abc"
294 } 286 }
295 do 287 local _type_0 = type(tb)
296 local _type_0 = type(tb) 288 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
297 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 289 local _match_0 = false
298 local _match_0 = false 290 if _tab_0 then
291 local x = tb.x
292 local y = tb.y
293 if x ~= nil and y ~= nil then
294 _match_0 = true
295 print("x: " .. tostring(x) .. " with y: " .. tostring(y))
296 end
297 end
298 if not _match_0 then
299 if _tab_0 then 299 if _tab_0 then
300 local x = tb.x 300 local x = tb.x
301 local y = tb.y 301 if x ~= nil then
302 if x ~= nil and y ~= nil then 302 print("x: " .. tostring(x) .. " only")
303 _match_0 = true
304 print("x: " .. tostring(x) .. " with y: " .. tostring(y))
305 end
306 end
307 if not _match_0 then
308 if _tab_0 then
309 local x = tb.x
310 if x ~= nil then
311 print("x: " .. tostring(x) .. " only")
312 end
313 end 303 end
314 end 304 end
315 end 305 end
316end 306end
317do 307do
318 local matched 308 local matched
319 do 309 local _exp_0 = tb
320 local _exp_0 = tb 310 if 1 == _exp_0 then
321 if 1 == _exp_0 then 311 matched = "1"
322 matched = "1" 312 else
323 else 313 local _type_0 = type(_exp_0)
324 local _type_0 = type(_exp_0) 314 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
325 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 315 local _match_0 = false
326 local _match_0 = false 316 if _tab_0 then
327 if _tab_0 then 317 local x = _exp_0.x
328 local x = _exp_0.x 318 if x ~= nil then
329 if x ~= nil then 319 _match_0 = true
330 _match_0 = true 320 matched = x
331 matched = x
332 end
333 end 321 end
334 if not _match_0 then 322 end
335 if false == _exp_0 then 323 if not _match_0 then
336 matched = "false" 324 if false == _exp_0 then
337 else 325 matched = "false"
338 matched = nil 326 else
339 end 327 matched = nil
340 end 328 end
341 end 329 end
342 end 330 end
@@ -346,90 +334,84 @@ do
346 if nil == _exp_0 then 334 if nil == _exp_0 then
347 return "invalid" 335 return "invalid"
348 else 336 else
349 do 337 local _type_0 = type(_exp_0)
350 local _type_0 = type(_exp_0) 338 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
351 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 339 local _match_0 = false
352 local _match_0 = false 340 if _tab_0 then
353 if _tab_0 then 341 local a = _exp_0.a
354 local a = _exp_0.a 342 local b = _exp_0.b
355 local b = _exp_0.b 343 if a ~= nil and b ~= nil then
356 if a ~= nil and b ~= nil then 344 _match_0 = true
357 _match_0 = true 345 return tostring(a + b)
358 return tostring(a + b)
359 end
360 end 346 end
361 if not _match_0 then 347 end
362 if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 or 4 == _exp_0 or 5 == _exp_0 then 348 if not _match_0 then
363 return "number 1 - 5" 349 if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 or 4 == _exp_0 or 5 == _exp_0 then
364 else 350 return "number 1 - 5"
365 local _match_1 = false 351 else
366 if _tab_0 then 352 local _match_1 = false
367 local matchAnyTable = _exp_0.matchAnyTable 353 if _tab_0 then
368 if matchAnyTable == nil then 354 local matchAnyTable = _exp_0.matchAnyTable
369 matchAnyTable = "fallback" 355 if matchAnyTable == nil then
370 end 356 matchAnyTable = "fallback"
371 _match_1 = true
372 return matchAnyTable
373 end
374 if not _match_1 then
375 return "should not reach here unless it is not a table"
376 end 357 end
358 _match_1 = true
359 return matchAnyTable
360 end
361 if not _match_1 then
362 return "should not reach here unless it is not a table"
377 end 363 end
378 end 364 end
379 end 365 end
380 end 366 end
381end 367end
382do 368do
383 do 369 local _exp_0 = y
384 local _exp_0 = y 370 local _type_0 = type(_exp_0)
385 local _type_0 = type(_exp_0) 371 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
386 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 372 if _tab_0 then
387 if _tab_0 then 373 local mt = (function()
388 local mt = (function() 374 local _obj_0 = _exp_0.x
389 local _obj_0 = _exp_0.x 375 if _obj_0 ~= nil then
390 if _obj_0 ~= nil then 376 return getmetatable(_obj_0)
391 return getmetatable(_obj_0)
392 end
393 return nil
394 end)()
395 if mt ~= nil then
396 print(mt)
397 end 377 end
378 return nil
379 end)()
380 if mt ~= nil then
381 print(mt)
398 end 382 end
399 end 383 end
400end 384end
401do 385do
402 do 386 local _exp_0 = tb
403 local _exp_0 = tb 387 local _type_0 = type(_exp_0)
404 local _type_0 = type(_exp_0) 388 local _tab_0 = "table" == _type_0 or "userdata" == _type_0
405 local _tab_0 = "table" == _type_0 or "userdata" == _type_0 389 local _match_0 = false
406 local _match_0 = false 390 if _tab_0 then
407 if _tab_0 then 391 local item
408 local item 392 do
409 do 393 local _obj_0 = _exp_0[1]
410 local _obj_0 = _exp_0[1] 394 local _type_1 = type(_obj_0)
411 local _type_1 = type(_obj_0) 395 if "table" == _type_1 or "userdata" == _type_1 then
412 if "table" == _type_1 or "userdata" == _type_1 then 396 item = _obj_0[1]
413 item = _obj_0[1]
414 end
415 end
416 if item ~= nil then
417 _match_0 = true
418 print(item)
419 end 397 end
420 end 398 end
421 if not _match_0 then 399 if item ~= nil then
422 if _tab_0 then 400 _match_0 = true
423 local a = _exp_0[1] 401 print(item)
424 local b = _exp_0[2] 402 end
425 if a == nil then 403 end
426 a = 1 404 if not _match_0 then
427 end 405 if _tab_0 then
428 if b == nil then 406 local a = _exp_0[1]
429 b = "abc" 407 local b = _exp_0[2]
430 end 408 if a == nil then
431 print(a, b) 409 a = 1
410 end
411 if b == nil then
412 b = "abc"
432 end 413 end
414 print(a, b)
433 end 415 end
434 end 416 end
435end 417end