aboutsummaryrefslogtreecommitdiff
path: root/testes/goto.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-10-30 15:04:19 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-10-30 15:04:19 -0300
commit2316ec4c24a475e091ec3153a5bd908801a3a109 (patch)
treece14172ed7d7dc8874ea282a97d41f4b380f419e /testes/goto.lua
parenta006514ea138a29b6031058d9002b48a572b5dd6 (diff)
downloadlua-2316ec4c24a475e091ec3153a5bd908801a3a109.tar.gz
lua-2316ec4c24a475e091ec3153a5bd908801a3a109.tar.bz2
lua-2316ec4c24a475e091ec3153a5bd908801a3a109.zip
Back with optimization for 'if cond then goto'
Statements like 'if cond then goto label' generate code so that the jump in the 'if' goes directly to the given label. This optimization cannot be done when the jump is backwards leaving the scope of some variable, as it cannot add the needed 'close' instruction. (The jumps were already generated by the 'if'.) This commit also added 'likely'/'unlikely' for tests for errors in the parser, and it changed the way breaks outside loops are detected. (Now they are detected like other goto's with undefined labels.)
Diffstat (limited to 'testes/goto.lua')
-rw-r--r--testes/goto.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/testes/goto.lua b/testes/goto.lua
index 85038d02..92f048fb 100644
--- a/testes/goto.lua
+++ b/testes/goto.lua
@@ -249,6 +249,22 @@ assert(testG(2) == "2")
249assert(testG(3) == "3") 249assert(testG(3) == "3")
250assert(testG(4) == 5) 250assert(testG(4) == 5)
251assert(testG(5) == 10) 251assert(testG(5) == 10)
252
253do
254 -- if x back goto out of scope of upvalue
255 local X
256 goto L1
257
258 ::L2:: goto L3
259
260 ::L1:: do
261 local scoped a = function () X = true end
262 assert(X == nil)
263 if a then goto L2 end -- jumping back out of scope of 'a'
264 end
265
266 ::L3:: assert(X == true) -- checks that 'a' was correctly closed
267end
252-------------------------------------------------------------------------------- 268--------------------------------------------------------------------------------
253 269
254 270