Skip to content

Commit 663a8c6

Browse files
committed
Supported multiple break values. Simplified some generated codes.
1 parent f85c61c commit 663a8c6

15 files changed

+406
-295
lines changed

spec/outputs/5.1/loops.lua

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -499,25 +499,21 @@ local _anon_func_0 = function(i, tb)
499499
end
500500
do
501501
local index
502-
do
503-
local _accum_0
504-
for i = 1, #tb do
505-
if tb[i] then
506-
_accum_0 = i
507-
break
508-
end
502+
for i = 1, #tb do
503+
if tb[i] then
504+
index = i
505+
break
509506
end
510-
index = _accum_0
511507
end
512508
f((function()
513-
local _accum_0
509+
local _val_0
514510
for i = 1, #tb do
515511
if tb[i] then
516-
_accum_0 = i
512+
_val_0 = i
517513
break
518514
end
519515
end
520-
return _accum_0
516+
return _val_0
521517
end)())
522518
f((function()
523519
local _accum_0 = { }
@@ -545,13 +541,13 @@ do
545541
i = 1
546542
local idx
547543
do
548-
local _accum_0
544+
local _val_0
549545
while tb[i] do
550546
i = i + 1
551-
_accum_0 = i - 1
547+
_val_0 = i - 1
552548
break
553549
end
554-
idx = _accum_0
550+
idx = _val_0
555551
end
556552
local f1
557553
f1 = function()
@@ -560,13 +556,13 @@ do
560556
end
561557
i = 1
562558
f((function()
563-
local _accum_0
559+
local _val_0
564560
while tb[i] do
565561
i = i + 1
566-
_accum_0 = i - 1
562+
_val_0 = i - 1
567563
break
568564
end
569-
return _accum_0
565+
return _val_0
570566
end)())
571567
local _accum_0 = { }
572568
local _len_0 = 1
@@ -592,13 +588,13 @@ do
592588
print(1)
593589
until true
594590
do
595-
local _accum_0
591+
local _val_0
596592
repeat
597593
a = func()
598-
_accum_0 = a.x
594+
_val_0 = a.x
599595
break
600596
until a.v
601-
x = _accum_0
597+
x = _val_0
602598
end
603599
local items
604600
local _accum_0 = { }

spec/outputs/codes_from_doc_de.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,16 +3260,14 @@ for i = 1, 20 do
32603260
end
32613261
doubled_evens = _accum_0
32623262
local first_large
3263-
local _accum_0
32643263
local _list_0 = numbers
32653264
for _index_0 = 1, #_list_0 do
32663265
local n = _list_0[_index_0]
32673266
if n > 10 then
3268-
_accum_0 = n
3267+
first_large = n
32693268
break
32703269
end
32713270
end
3272-
first_large = _accum_0
32733271
local func_a
32743272
func_a = function()
32753273
for i = 1, 10 do
@@ -3324,16 +3322,14 @@ for i = 1, 20 do
33243322
end
33253323
doubled_evens = _accum_0
33263324
local first_large
3327-
local _accum_0
33283325
local _list_0 = numbers
33293326
for _index_0 = 1, #_list_0 do
33303327
local n = _list_0[_index_0]
33313328
if n > 10 then
3332-
_accum_0 = n
3329+
first_large = n
33333330
break
33343331
end
33353332
end
3336-
first_large = _accum_0
33373333
local func_a
33383334
func_a = function()
33393335
for i = 1, 10 do

spec/outputs/codes_from_doc_en.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,16 +3260,14 @@ for i = 1, 20 do
32603260
end
32613261
doubled_evens = _accum_0
32623262
local first_large
3263-
local _accum_0
32643263
local _list_0 = numbers
32653264
for _index_0 = 1, #_list_0 do
32663265
local n = _list_0[_index_0]
32673266
if n > 10 then
3268-
_accum_0 = n
3267+
first_large = n
32693268
break
32703269
end
32713270
end
3272-
first_large = _accum_0
32733271
local func_a
32743272
func_a = function()
32753273
for i = 1, 10 do
@@ -3324,16 +3322,14 @@ for i = 1, 20 do
33243322
end
33253323
doubled_evens = _accum_0
33263324
local first_large
3327-
local _accum_0
33283325
local _list_0 = numbers
33293326
for _index_0 = 1, #_list_0 do
33303327
local n = _list_0[_index_0]
33313328
if n > 10 then
3332-
_accum_0 = n
3329+
first_large = n
33333330
break
33343331
end
33353332
end
3336-
first_large = _accum_0
33373333
local func_a
33383334
func_a = function()
33393335
for i = 1, 10 do

spec/outputs/codes_from_doc_id-id.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,16 +3260,14 @@ for i = 1, 20 do
32603260
end
32613261
doubled_evens = _accum_0
32623262
local first_large
3263-
local _accum_0
32643263
local _list_0 = numbers
32653264
for _index_0 = 1, #_list_0 do
32663265
local n = _list_0[_index_0]
32673266
if n > 10 then
3268-
_accum_0 = n
3267+
first_large = n
32693268
break
32703269
end
32713270
end
3272-
first_large = _accum_0
32733271
local func_a
32743272
func_a = function()
32753273
for i = 1, 10 do
@@ -3324,16 +3322,14 @@ for i = 1, 20 do
33243322
end
33253323
doubled_evens = _accum_0
33263324
local first_large
3327-
local _accum_0
33283325
local _list_0 = numbers
33293326
for _index_0 = 1, #_list_0 do
33303327
local n = _list_0[_index_0]
33313328
if n > 10 then
3332-
_accum_0 = n
3329+
first_large = n
33333330
break
33343331
end
33353332
end
3336-
first_large = _accum_0
33373333
local func_a
33383334
func_a = function()
33393335
for i = 1, 10 do

spec/outputs/codes_from_doc_pt-br.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,16 +3260,14 @@ for i = 1, 20 do
32603260
end
32613261
doubled_evens = _accum_0
32623262
local first_large
3263-
local _accum_0
32643263
local _list_0 = numbers
32653264
for _index_0 = 1, #_list_0 do
32663265
local n = _list_0[_index_0]
32673266
if n > 10 then
3268-
_accum_0 = n
3267+
first_large = n
32693268
break
32703269
end
32713270
end
3272-
first_large = _accum_0
32733271
local func_a
32743272
func_a = function()
32753273
for i = 1, 10 do
@@ -3324,16 +3322,14 @@ for i = 1, 20 do
33243322
end
33253323
doubled_evens = _accum_0
33263324
local first_large
3327-
local _accum_0
33283325
local _list_0 = numbers
33293326
for _index_0 = 1, #_list_0 do
33303327
local n = _list_0[_index_0]
33313328
if n > 10 then
3332-
_accum_0 = n
3329+
first_large = n
33333330
break
33343331
end
33353332
end
3336-
first_large = _accum_0
33373333
local func_a
33383334
func_a = function()
33393335
for i = 1, 10 do

spec/outputs/codes_from_doc_zh.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,16 +3260,14 @@ for i = 1, 20 do
32603260
end
32613261
doubled_evens = _accum_0
32623262
local first_large
3263-
local _accum_0
32643263
local _list_0 = numbers
32653264
for _index_0 = 1, #_list_0 do
32663265
local n = _list_0[_index_0]
32673266
if n > 10 then
3268-
_accum_0 = n
3267+
first_large = n
32693268
break
32703269
end
32713270
end
3272-
first_large = _accum_0
32733271
local func_a
32743272
func_a = function()
32753273
for i = 1, 10 do
@@ -3324,16 +3322,14 @@ for i = 1, 20 do
33243322
end
33253323
doubled_evens = _accum_0
33263324
local first_large
3327-
local _accum_0
33283325
local _list_0 = numbers
33293326
for _index_0 = 1, #_list_0 do
33303327
local n = _list_0[_index_0]
33313328
if n > 10 then
3332-
_accum_0 = n
3329+
first_large = n
33333330
break
33343331
end
33353332
end
3336-
first_large = _accum_0
33373333
local func_a
33383334
func_a = function()
33393335
for i = 1, 10 do

spec/outputs/loops.lua

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -380,25 +380,21 @@ local _anon_func_0 = function(i, tb)
380380
end
381381
do
382382
local index
383-
do
384-
local _accum_0
385-
for i = 1, #tb do
386-
if tb[i] then
387-
_accum_0 = i
388-
break
389-
end
383+
for i = 1, #tb do
384+
if tb[i] then
385+
index = i
386+
break
390387
end
391-
index = _accum_0
392388
end
393389
f((function()
394-
local _accum_0
390+
local _val_0
395391
for i = 1, #tb do
396392
if tb[i] then
397-
_accum_0 = i
393+
_val_0 = i
398394
break
399395
end
400396
end
401-
return _accum_0
397+
return _val_0
402398
end)())
403399
f((function()
404400
local _accum_0 = { }
@@ -426,13 +422,13 @@ do
426422
i = 1
427423
local idx
428424
do
429-
local _accum_0
425+
local _val_0
430426
while tb[i] do
431427
i = i + 1
432-
_accum_0 = i - 1
428+
_val_0 = i - 1
433429
break
434430
end
435-
idx = _accum_0
431+
idx = _val_0
436432
end
437433
local f1
438434
f1 = function()
@@ -441,13 +437,13 @@ do
441437
end
442438
i = 1
443439
f((function()
444-
local _accum_0
440+
local _val_0
445441
while tb[i] do
446442
i = i + 1
447-
_accum_0 = i - 1
443+
_val_0 = i - 1
448444
break
449445
end
450-
return _accum_0
446+
return _val_0
451447
end)())
452448
local _accum_0 = { }
453449
local _len_0 = 1
@@ -473,13 +469,13 @@ do
473469
print(1)
474470
until true
475471
do
476-
local _accum_0
472+
local _val_0
477473
repeat
478474
a = func()
479-
_accum_0 = a.x
475+
_val_0 = a.x
480476
break
481477
until a.v
482-
x = _accum_0
478+
x = _val_0
483479
end
484480
local items
485481
local _accum_0 = { }

spec/outputs/test/config_spec.lua

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,10 @@ return describe("config", function()
114114
y = 20
115115
}
116116
local result
117-
do
118-
local _accum_0
119-
repeat
120-
_accum_0 = obj.x + obj.y
121-
break
122-
until true
123-
result = _accum_0
124-
end
117+
repeat
118+
result = obj.x + obj.y
119+
break
120+
until true
125121
return assert.same(result, 30)
126122
end)
127123
it("should handle existential operators", function()

spec/outputs/test/do_statement_spec.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ return describe("do statement", function()
104104
}
105105
local result
106106
do
107-
local _accum_0
108107
repeat
109-
_accum_0 = obj:double()
108+
result = obj:double()
110109
break
111110
until true
112-
result = _accum_0
113111
end
114112
return assert.same(result, 20)
115113
end)

0 commit comments

Comments
 (0)