diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-10-29 14:26:48 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-10-29 14:26:48 -0300 |
commit | a006514ea138a29b6031058d9002b48a572b5dd6 (patch) | |
tree | b289a8af0c0497f2555784a0cf666659ceab0236 /testes | |
parent | 6e9b719694bffb8de711f182d405ec37d32ae0b1 (diff) | |
download | lua-github-a006514ea138a29b6031058d9002b48a572b5dd6.tar.gz |
Big revamp in the implmentation of labels/gotos
Added restriction that, when a label is created, there cannot be
another label with the same name visible. That allows backward goto's
to be resolved when they are read. Backward goto's get a close if
they jump out of the scope of some variable; labels get a close only
if previous goto to it jumps out of the scope of some upvalue.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/code.lua | 19 | ||||
-rw-r--r-- | testes/goto.lua | 3 |
2 files changed, 8 insertions, 14 deletions
diff --git a/testes/code.lua b/testes/code.lua index ad484485..9b3f2b68 100644 --- a/testes/code.lua +++ b/testes/code.lua @@ -297,7 +297,7 @@ check(function () b[a], a = c, b a, b = c, a a = a -end, +end, 'LOADNIL', 'MOVE', 'MOVE', 'SETTABLE', 'MOVE', 'MOVE', 'MOVE', 'SETTABLE', @@ -329,18 +329,13 @@ checkequal(function (l) local a; return 0 <= a and a <= l end, function (l) local a; return not (not(a >= 0) or not(a <= l)) end) --- if-goto optimizations -check(function (a, b, c, d, e) - if a == b then goto l1; - elseif a == c then goto l2; - elseif a == d then goto l2; - else if a == e then goto l3; - else goto l3 - end +-- if-break optimizations +check(function (a, b) + while a do + if b then break else a = a + 1 end end - ::l1:: ::l2:: ::l3:: ::l4:: -end, 'EQ', 'JMP', 'EQ', 'JMP', 'EQ', 'JMP', 'EQ', 'JMP', 'JMP', -'CLOSE', 'CLOSE', 'CLOSE', 'CLOSE', 'RETURN0') + end, +'TEST', 'JMP', 'TEST', 'JMP', 'ADDI', 'JMP', 'RETURN0') checkequal( function (a) while a < 10 do a = a + 1 end end, diff --git a/testes/goto.lua b/testes/goto.lua index 238bc04a..85038d02 100644 --- a/testes/goto.lua +++ b/testes/goto.lua @@ -14,6 +14,7 @@ errmsg([[ do ::l1:: end goto l1; ]], "label 'l1'") -- repeated label errmsg([[ ::l1:: ::l1:: ]], "label 'l1'") +errmsg([[ ::l1:: do ::l1:: end]], "label 'l1'") -- undefined label @@ -67,8 +68,6 @@ do assert(assert(load(prog))() == 31) end --- goto to correct label when nested -do goto l3; ::l3:: end -- does not loop jumping to previous label 'l3' -- ok to jump over local dec. to end of block do |