diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-09-30 11:29:41 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-09-30 11:29:41 +0800 |
| commit | 5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2 (patch) | |
| tree | 5c5c0ecdab0d19544652bc05b70d8131e1645337 /spec | |
| parent | a6b6753fda9745f316f3236462b74794b35b85c9 (diff) | |
| download | yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.tar.gz yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.tar.bz2 yuescript-5aa41b436b3fdf29f5a0046c68cb60b16fa09eb2.zip | |
fix issue #81, refactor continue with gotos.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/goto.yue | 4 | ||||
| -rw-r--r-- | spec/inputs/loops.yue | 8 | ||||
| -rw-r--r-- | spec/inputs/test/loops_spec.yue | 6 | ||||
| -rw-r--r-- | spec/outputs/5.1/loops.lua | 381 | ||||
| -rw-r--r-- | spec/outputs/5.1/test/loops_spec.lua | 69 | ||||
| -rw-r--r-- | spec/outputs/goto.lua | 4 | ||||
| -rw-r--r-- | spec/outputs/loops.lua | 204 | ||||
| -rw-r--r-- | spec/outputs/test/loops_spec.lua | 51 |
8 files changed, 537 insertions, 190 deletions
diff --git a/spec/inputs/goto.yue b/spec/inputs/goto.yue index 1197251..61584ca 100644 --- a/spec/inputs/goto.yue +++ b/spec/inputs/goto.yue | |||
| @@ -10,8 +10,8 @@ do | |||
| 10 | for z = 1, 10 do for y = 1, 10 do for x = 1, 10 | 10 | for z = 1, 10 do for y = 1, 10 do for x = 1, 10 |
| 11 | if x^2 + y^2 == z^2 | 11 | if x^2 + y^2 == z^2 |
| 12 | print 'found a Pythagorean triple:', x, y, z | 12 | print 'found a Pythagorean triple:', x, y, z |
| 13 | goto done | 13 | goto ok |
| 14 | ::done:: | 14 | ::ok:: |
| 15 | 15 | ||
| 16 | do | 16 | do |
| 17 | for z = 1, 10 | 17 | for z = 1, 10 |
diff --git a/spec/inputs/loops.yue b/spec/inputs/loops.yue index d03e661..d997c65 100644 --- a/spec/inputs/loops.yue +++ b/spec/inputs/loops.yue | |||
| @@ -111,10 +111,10 @@ until a == 10 | |||
| 111 | 111 | ||
| 112 | x = 0 | 112 | x = 0 |
| 113 | repeat | 113 | repeat |
| 114 | x += 1 | 114 | x += 1 |
| 115 | y = x | 115 | y = x |
| 116 | continue if x < 5 | 116 | continue if x < 5 |
| 117 | print y | 117 | print y |
| 118 | until y == 10 | 118 | until y == 10 |
| 119 | 119 | ||
| 120 | a = 3 | 120 | a = 3 |
diff --git a/spec/inputs/test/loops_spec.yue b/spec/inputs/test/loops_spec.yue index 817919f..a115581 100644 --- a/spec/inputs/test/loops_spec.yue +++ b/spec/inputs/test/loops_spec.yue | |||
| @@ -5,8 +5,8 @@ describe "loops", -> | |||
| 5 | continue if x % 2 == 1 | 5 | continue if x % 2 == 1 |
| 6 | x | 6 | x |
| 7 | 7 | ||
| 8 | assert.same output, { 2,4,6 } | 8 | assert.same { 2,4,6 }, output |
| 9 | 9 | ||
| 10 | it "continue in repeat", -> | 10 | it "continue in repeat", -> |
| 11 | output = {} | 11 | output = {} |
| 12 | a = 0 | 12 | a = 0 |
| @@ -19,5 +19,5 @@ describe "loops", -> | |||
| 19 | output[] = a | 19 | output[] = a |
| 20 | until a == 8 | 20 | until a == 8 |
| 21 | 21 | ||
| 22 | assert.same output, { 1,2,4 } | 22 | assert.same { 1,2,4 }, output |
| 23 | 23 | ||
diff --git a/spec/outputs/5.1/loops.lua b/spec/outputs/5.1/loops.lua new file mode 100644 index 0000000..a3b9548 --- /dev/null +++ b/spec/outputs/5.1/loops.lua | |||
| @@ -0,0 +1,381 @@ | |||
| 1 | for x = 1, 10 do | ||
| 2 | print("yeah") | ||
| 3 | end | ||
| 4 | for x = 1, #something do | ||
| 5 | print("yeah") | ||
| 6 | end | ||
| 7 | for y = 100, 60, -3 do | ||
| 8 | print("count down", y) | ||
| 9 | end | ||
| 10 | for a = 1, 10 do | ||
| 11 | print("okay") | ||
| 12 | end | ||
| 13 | for a = 1, 10 do | ||
| 14 | for b = 2, 43 do | ||
| 15 | print(a, b) | ||
| 16 | end | ||
| 17 | end | ||
| 18 | for i in iter do | ||
| 19 | for j in yeah do | ||
| 20 | local x = 343 + i + j | ||
| 21 | print(i, j) | ||
| 22 | end | ||
| 23 | end | ||
| 24 | local _list_0 = something | ||
| 25 | for _index_0 = 1, #_list_0 do | ||
| 26 | local x = _list_0[_index_0] | ||
| 27 | print(x) | ||
| 28 | end | ||
| 29 | for k, v in pairs(hello) do | ||
| 30 | print(k, v) | ||
| 31 | end | ||
| 32 | for x in y, z do | ||
| 33 | print(x) | ||
| 34 | end | ||
| 35 | for x in y, z, k do | ||
| 36 | print(x) | ||
| 37 | end | ||
| 38 | local _list_1 = modules | ||
| 39 | for _index_0 = 1, #_list_1 do | ||
| 40 | local name, members = _list_1[_index_0] | ||
| 41 | print(name, member) | ||
| 42 | end | ||
| 43 | local x | ||
| 44 | x = function() | ||
| 45 | for x in y do | ||
| 46 | local _ = y | ||
| 47 | end | ||
| 48 | end | ||
| 49 | local hello = { | ||
| 50 | 1, | ||
| 51 | 2, | ||
| 52 | 3, | ||
| 53 | 4, | ||
| 54 | 5 | ||
| 55 | } | ||
| 56 | do | ||
| 57 | local _accum_0 = { } | ||
| 58 | local _len_0 = 1 | ||
| 59 | for _index_0 = 1, #hello do | ||
| 60 | local y = hello[_index_0] | ||
| 61 | if y % 2 == 0 then | ||
| 62 | _accum_0[_len_0] = y | ||
| 63 | end | ||
| 64 | _len_0 = _len_0 + 1 | ||
| 65 | end | ||
| 66 | x = _accum_0 | ||
| 67 | end | ||
| 68 | x = function() | ||
| 69 | for _index_0 = 1, #hello do | ||
| 70 | local x = hello[_index_0] | ||
| 71 | local _ = y | ||
| 72 | end | ||
| 73 | end | ||
| 74 | local t | ||
| 75 | do | ||
| 76 | local _accum_0 = { } | ||
| 77 | local _len_0 = 1 | ||
| 78 | for i = 10, 20 do | ||
| 79 | _accum_0[_len_0] = i * 2 | ||
| 80 | _len_0 = _len_0 + 1 | ||
| 81 | end | ||
| 82 | t = _accum_0 | ||
| 83 | end | ||
| 84 | local hmm = 0 | ||
| 85 | local y | ||
| 86 | do | ||
| 87 | local _accum_0 = { } | ||
| 88 | local _len_0 = 1 | ||
| 89 | for j = 3, 30, 8 do | ||
| 90 | hmm = hmm + 1 | ||
| 91 | _accum_0[_len_0] = j * hmm | ||
| 92 | _len_0 = _len_0 + 1 | ||
| 93 | end | ||
| 94 | y = _accum_0 | ||
| 95 | end | ||
| 96 | local _ | ||
| 97 | _ = function() | ||
| 98 | for k = 10, 40 do | ||
| 99 | _ = "okay" | ||
| 100 | end | ||
| 101 | end | ||
| 102 | _ = function() | ||
| 103 | local _accum_0 = { } | ||
| 104 | local _len_0 = 1 | ||
| 105 | for k = 10, 40 do | ||
| 106 | _accum_0[_len_0] = "okay" | ||
| 107 | _len_0 = _len_0 + 1 | ||
| 108 | end | ||
| 109 | return _accum_0 | ||
| 110 | end | ||
| 111 | while true do | ||
| 112 | print("name") | ||
| 113 | end | ||
| 114 | while 5 + 5 do | ||
| 115 | print("okay world") | ||
| 116 | working(man) | ||
| 117 | end | ||
| 118 | while also do | ||
| 119 | i(work(too)) | ||
| 120 | _ = "okay" | ||
| 121 | end | ||
| 122 | local i = 0 | ||
| 123 | do | ||
| 124 | local _accum_0 = { } | ||
| 125 | local _len_0 = 1 | ||
| 126 | while i < 10 do | ||
| 127 | i = i + 1 | ||
| 128 | _len_0 = _len_0 + 1 | ||
| 129 | end | ||
| 130 | x = _accum_0 | ||
| 131 | end | ||
| 132 | do | ||
| 133 | local _accum_0 = { } | ||
| 134 | local _len_0 = 1 | ||
| 135 | local _list_2 = 3 | ||
| 136 | for _index_0 = 1, #_list_2 do | ||
| 137 | local thing = _list_2[_index_0] | ||
| 138 | y = "hello" | ||
| 139 | _len_0 = _len_0 + 1 | ||
| 140 | end | ||
| 141 | x = _accum_0 | ||
| 142 | end | ||
| 143 | do | ||
| 144 | local _accum_0 = { } | ||
| 145 | local _len_0 = 1 | ||
| 146 | for x = 1, 2 do | ||
| 147 | y = "hello" | ||
| 148 | _len_0 = _len_0 + 1 | ||
| 149 | end | ||
| 150 | x = _accum_0 | ||
| 151 | end | ||
| 152 | while true do | ||
| 153 | local _continue_0 = false | ||
| 154 | repeat | ||
| 155 | if false then | ||
| 156 | _continue_0 = true | ||
| 157 | break | ||
| 158 | end | ||
| 159 | print("yes") | ||
| 160 | if true then | ||
| 161 | break | ||
| 162 | end | ||
| 163 | print("no") | ||
| 164 | _continue_0 = true | ||
| 165 | until true | ||
| 166 | if not _continue_0 then | ||
| 167 | break | ||
| 168 | end | ||
| 169 | end | ||
| 170 | for i = 1, 10 do | ||
| 171 | while true do | ||
| 172 | local _continue_0 = false | ||
| 173 | repeat | ||
| 174 | do | ||
| 175 | if not true then | ||
| 176 | _continue_0 = true | ||
| 177 | break | ||
| 178 | end | ||
| 179 | break | ||
| 180 | end | ||
| 181 | _continue_0 = true | ||
| 182 | until true | ||
| 183 | if not _continue_0 then | ||
| 184 | break | ||
| 185 | end | ||
| 186 | end | ||
| 187 | end | ||
| 188 | local a = 1 | ||
| 189 | repeat | ||
| 190 | local _cond_0 = false | ||
| 191 | local _continue_0 = false | ||
| 192 | repeat | ||
| 193 | a = a + 1 | ||
| 194 | if a == 5 then | ||
| 195 | _cond_0 = a == 10 | ||
| 196 | _continue_0 = true | ||
| 197 | break | ||
| 198 | end | ||
| 199 | if a == 6 then | ||
| 200 | break | ||
| 201 | end | ||
| 202 | print(a) | ||
| 203 | _cond_0 = a == 10 | ||
| 204 | _continue_0 = true | ||
| 205 | until true | ||
| 206 | if not _continue_0 then | ||
| 207 | break | ||
| 208 | end | ||
| 209 | until _cond_0 | ||
| 210 | x = 0 | ||
| 211 | repeat | ||
| 212 | local _cond_0 = false | ||
| 213 | local _continue_0 = false | ||
| 214 | repeat | ||
| 215 | x = x + 1 | ||
| 216 | y = x | ||
| 217 | if x < 5 then | ||
| 218 | _cond_0 = y == 10 | ||
| 219 | _continue_0 = true | ||
| 220 | break | ||
| 221 | end | ||
| 222 | print(y) | ||
| 223 | _cond_0 = y == 10 | ||
| 224 | _continue_0 = true | ||
| 225 | until true | ||
| 226 | if not _continue_0 then | ||
| 227 | break | ||
| 228 | end | ||
| 229 | until _cond_0 | ||
| 230 | a = 3 | ||
| 231 | while not (a == 0) do | ||
| 232 | a = a - 1 | ||
| 233 | end | ||
| 234 | local done = false | ||
| 235 | while not done do | ||
| 236 | done = true | ||
| 237 | end | ||
| 238 | repeat | ||
| 239 | print("hello") | ||
| 240 | until true | ||
| 241 | while not done do | ||
| 242 | x = 10 | ||
| 243 | repeat | ||
| 244 | x = x - 1 | ||
| 245 | until x == 0 | ||
| 246 | end | ||
| 247 | while not cond do | ||
| 248 | print("okay") | ||
| 249 | end | ||
| 250 | for x = 1, 10 do | ||
| 251 | local _continue_0 = false | ||
| 252 | repeat | ||
| 253 | if x > 3 and x < 7 then | ||
| 254 | _continue_0 = true | ||
| 255 | break | ||
| 256 | end | ||
| 257 | print(x) | ||
| 258 | _continue_0 = true | ||
| 259 | until true | ||
| 260 | if not _continue_0 then | ||
| 261 | break | ||
| 262 | end | ||
| 263 | end | ||
| 264 | local list | ||
| 265 | do | ||
| 266 | local _accum_0 = { } | ||
| 267 | local _len_0 = 1 | ||
| 268 | for x = 1, 10 do | ||
| 269 | local _continue_0 = false | ||
| 270 | repeat | ||
| 271 | if x > 3 and x < 7 then | ||
| 272 | _continue_0 = true | ||
| 273 | break | ||
| 274 | end | ||
| 275 | _accum_0[_len_0] = x | ||
| 276 | _len_0 = _len_0 + 1 | ||
| 277 | _continue_0 = true | ||
| 278 | until true | ||
| 279 | if not _continue_0 then | ||
| 280 | break | ||
| 281 | end | ||
| 282 | end | ||
| 283 | list = _accum_0 | ||
| 284 | end | ||
| 285 | local _list_2 = { | ||
| 286 | 1, | ||
| 287 | 2, | ||
| 288 | 3, | ||
| 289 | 4, | ||
| 290 | 5, | ||
| 291 | 6 | ||
| 292 | } | ||
| 293 | for _index_0 = 1, #_list_2 do | ||
| 294 | local a = _list_2[_index_0] | ||
| 295 | local _continue_0 = false | ||
| 296 | repeat | ||
| 297 | if a == 1 then | ||
| 298 | _continue_0 = true | ||
| 299 | break | ||
| 300 | end | ||
| 301 | if a == 3 then | ||
| 302 | _continue_0 = true | ||
| 303 | break | ||
| 304 | end | ||
| 305 | print(a) | ||
| 306 | _continue_0 = true | ||
| 307 | until true | ||
| 308 | if not _continue_0 then | ||
| 309 | break | ||
| 310 | end | ||
| 311 | end | ||
| 312 | for x = 1, 10 do | ||
| 313 | local _continue_0 = false | ||
| 314 | repeat | ||
| 315 | if x % 2 == 0 then | ||
| 316 | _continue_0 = true | ||
| 317 | break | ||
| 318 | end | ||
| 319 | for y = 2, 12 do | ||
| 320 | local _continue_1 = false | ||
| 321 | repeat | ||
| 322 | if y % 3 == 0 then | ||
| 323 | _continue_1 = true | ||
| 324 | break | ||
| 325 | end | ||
| 326 | _continue_1 = true | ||
| 327 | until true | ||
| 328 | if not _continue_1 then | ||
| 329 | break | ||
| 330 | end | ||
| 331 | end | ||
| 332 | _continue_0 = true | ||
| 333 | until true | ||
| 334 | if not _continue_0 then | ||
| 335 | break | ||
| 336 | end | ||
| 337 | end | ||
| 338 | while true do | ||
| 339 | local _continue_0 = false | ||
| 340 | repeat | ||
| 341 | do | ||
| 342 | if false then | ||
| 343 | _continue_0 = true | ||
| 344 | break | ||
| 345 | end | ||
| 346 | break | ||
| 347 | end | ||
| 348 | _continue_0 = true | ||
| 349 | until true | ||
| 350 | if not _continue_0 then | ||
| 351 | break | ||
| 352 | end | ||
| 353 | end | ||
| 354 | while true do | ||
| 355 | local _continue_0 = false | ||
| 356 | repeat | ||
| 357 | if false then | ||
| 358 | _continue_0 = true | ||
| 359 | break | ||
| 360 | end | ||
| 361 | do | ||
| 362 | return 22 | ||
| 363 | end | ||
| 364 | _continue_0 = true | ||
| 365 | until true | ||
| 366 | if not _continue_0 then | ||
| 367 | break | ||
| 368 | end | ||
| 369 | end | ||
| 370 | do | ||
| 371 | local xxx = { | ||
| 372 | 1, | ||
| 373 | 2, | ||
| 374 | 3, | ||
| 375 | 4 | ||
| 376 | } | ||
| 377 | for _index_0 = 1, #xxx do | ||
| 378 | local thing = xxx[_index_0] | ||
| 379 | print(thing) | ||
| 380 | end | ||
| 381 | end | ||
diff --git a/spec/outputs/5.1/test/loops_spec.lua b/spec/outputs/5.1/test/loops_spec.lua new file mode 100644 index 0000000..bad17a6 --- /dev/null +++ b/spec/outputs/5.1/test/loops_spec.lua | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | return describe("loops", function() | ||
| 2 | it("should continue", function() | ||
| 3 | local input = { | ||
| 4 | 1, | ||
| 5 | 2, | ||
| 6 | 3, | ||
| 7 | 4, | ||
| 8 | 5, | ||
| 9 | 6 | ||
| 10 | } | ||
| 11 | local output | ||
| 12 | do | ||
| 13 | local _accum_0 = { } | ||
| 14 | local _len_0 = 1 | ||
| 15 | for _index_0 = 1, #input do | ||
| 16 | local x = input[_index_0] | ||
| 17 | local _continue_0 = false | ||
| 18 | repeat | ||
| 19 | if x % 2 == 1 then | ||
| 20 | _continue_0 = true | ||
| 21 | break | ||
| 22 | end | ||
| 23 | _accum_0[_len_0] = x | ||
| 24 | _len_0 = _len_0 + 1 | ||
| 25 | _continue_0 = true | ||
| 26 | until true | ||
| 27 | if not _continue_0 then | ||
| 28 | break | ||
| 29 | end | ||
| 30 | end | ||
| 31 | output = _accum_0 | ||
| 32 | end | ||
| 33 | return assert.same({ | ||
| 34 | 2, | ||
| 35 | 4, | ||
| 36 | 6 | ||
| 37 | }, output) | ||
| 38 | end) | ||
| 39 | return it("continue in repeat", function() | ||
| 40 | local output = { } | ||
| 41 | local a = 0 | ||
| 42 | repeat | ||
| 43 | local _cond_0 = false | ||
| 44 | local _continue_0 = false | ||
| 45 | repeat | ||
| 46 | a = a + 1 | ||
| 47 | if a == 3 then | ||
| 48 | _cond_0 = a == 8 | ||
| 49 | _continue_0 = true | ||
| 50 | break | ||
| 51 | end | ||
| 52 | if a == 5 then | ||
| 53 | break | ||
| 54 | end | ||
| 55 | output[#output + 1] = a | ||
| 56 | _cond_0 = a == 8 | ||
| 57 | _continue_0 = true | ||
| 58 | until true | ||
| 59 | if not _continue_0 then | ||
| 60 | break | ||
| 61 | end | ||
| 62 | until _cond_0 | ||
| 63 | return assert.same({ | ||
| 64 | 1, | ||
| 65 | 2, | ||
| 66 | 4 | ||
| 67 | }, output) | ||
| 68 | end) | ||
| 69 | end) | ||
diff --git a/spec/outputs/goto.lua b/spec/outputs/goto.lua index d1f7b77..421508a 100644 --- a/spec/outputs/goto.lua +++ b/spec/outputs/goto.lua | |||
| @@ -14,12 +14,12 @@ do | |||
| 14 | for x = 1, 10 do | 14 | for x = 1, 10 do |
| 15 | if x ^ 2 + y ^ 2 == z ^ 2 then | 15 | if x ^ 2 + y ^ 2 == z ^ 2 then |
| 16 | print('found a Pythagorean triple:', x, y, z) | 16 | print('found a Pythagorean triple:', x, y, z) |
| 17 | goto done | 17 | goto ok |
| 18 | end | 18 | end |
| 19 | end | 19 | end |
| 20 | end | 20 | end |
| 21 | end | 21 | end |
| 22 | ::done:: | 22 | ::ok:: |
| 23 | end | 23 | end |
| 24 | do | 24 | do |
| 25 | for z = 1, 10 do | 25 | for z = 1, 10 do |
diff --git a/spec/outputs/loops.lua b/spec/outputs/loops.lua index e5c189e..9c16ee4 100644 --- a/spec/outputs/loops.lua +++ b/spec/outputs/loops.lua | |||
| @@ -150,83 +150,47 @@ do | |||
| 150 | x = _accum_0 | 150 | x = _accum_0 |
| 151 | end | 151 | end |
| 152 | while true do | 152 | while true do |
| 153 | local _continue_0 = false | 153 | if false then |
| 154 | repeat | 154 | goto _continue_0 |
| 155 | if false then | 155 | end |
| 156 | _continue_0 = true | 156 | print("yes") |
| 157 | break | 157 | if true then |
| 158 | end | ||
| 159 | print("yes") | ||
| 160 | if true then | ||
| 161 | break | ||
| 162 | end | ||
| 163 | print("no") | ||
| 164 | _continue_0 = true | ||
| 165 | until true | ||
| 166 | if not _continue_0 then | ||
| 167 | break | 158 | break |
| 168 | end | 159 | end |
| 160 | print("no") | ||
| 161 | ::_continue_0:: | ||
| 169 | end | 162 | end |
| 170 | for i = 1, 10 do | 163 | for i = 1, 10 do |
| 171 | while true do | 164 | while true do |
| 172 | local _continue_0 = false | 165 | if not true then |
| 173 | repeat | 166 | goto _continue_1 |
| 174 | do | ||
| 175 | if not true then | ||
| 176 | _continue_0 = true | ||
| 177 | break | ||
| 178 | end | ||
| 179 | break | ||
| 180 | end | ||
| 181 | _continue_0 = true | ||
| 182 | until true | ||
| 183 | if not _continue_0 then | ||
| 184 | break | ||
| 185 | end | 167 | end |
| 168 | break | ||
| 169 | ::_continue_1:: | ||
| 186 | end | 170 | end |
| 187 | end | 171 | end |
| 188 | local a = 1 | 172 | local a = 1 |
| 189 | repeat | 173 | repeat |
| 190 | local _cond_0 = false | 174 | a = a + 1 |
| 191 | local _continue_0 = false | 175 | if a == 5 then |
| 192 | repeat | 176 | goto _continue_2 |
| 193 | a = a + 1 | 177 | end |
| 194 | if a == 5 then | 178 | if a == 6 then |
| 195 | _cond_0 = a == 10 | ||
| 196 | _continue_0 = true | ||
| 197 | break | ||
| 198 | end | ||
| 199 | if a == 6 then | ||
| 200 | break | ||
| 201 | end | ||
| 202 | print(a) | ||
| 203 | _cond_0 = a == 10 | ||
| 204 | _continue_0 = true | ||
| 205 | until true | ||
| 206 | if not _continue_0 then | ||
| 207 | break | 179 | break |
| 208 | end | 180 | end |
| 209 | until _cond_0 | 181 | print(a) |
| 182 | ::_continue_2:: | ||
| 183 | until a == 10 | ||
| 210 | x = 0 | 184 | x = 0 |
| 211 | repeat | 185 | repeat |
| 212 | local _cond_0 = false | 186 | x = x + 1 |
| 213 | local _continue_0 = false | 187 | y = x |
| 214 | repeat | 188 | if x < 5 then |
| 215 | x = x + 1 | 189 | goto _continue_3 |
| 216 | y = x | ||
| 217 | if x < 5 then | ||
| 218 | _cond_0 = y == 10 | ||
| 219 | _continue_0 = true | ||
| 220 | break | ||
| 221 | end | ||
| 222 | print(y) | ||
| 223 | _cond_0 = y == 10 | ||
| 224 | _continue_0 = true | ||
| 225 | until true | ||
| 226 | if not _continue_0 then | ||
| 227 | break | ||
| 228 | end | 190 | end |
| 229 | until _cond_0 | 191 | print(y) |
| 192 | ::_continue_3:: | ||
| 193 | until y == 10 | ||
| 230 | a = 3 | 194 | a = 3 |
| 231 | while not (a == 0) do | 195 | while not (a == 0) do |
| 232 | a = a - 1 | 196 | a = a - 1 |
| @@ -248,37 +212,23 @@ while not cond do | |||
| 248 | print("okay") | 212 | print("okay") |
| 249 | end | 213 | end |
| 250 | for x = 1, 10 do | 214 | for x = 1, 10 do |
| 251 | local _continue_0 = false | 215 | if x > 3 and x < 7 then |
| 252 | repeat | 216 | goto _continue_4 |
| 253 | if x > 3 and x < 7 then | ||
| 254 | _continue_0 = true | ||
| 255 | break | ||
| 256 | end | ||
| 257 | print(x) | ||
| 258 | _continue_0 = true | ||
| 259 | until true | ||
| 260 | if not _continue_0 then | ||
| 261 | break | ||
| 262 | end | 217 | end |
| 218 | print(x) | ||
| 219 | ::_continue_4:: | ||
| 263 | end | 220 | end |
| 264 | local list | 221 | local list |
| 265 | do | 222 | do |
| 266 | local _accum_0 = { } | 223 | local _accum_0 = { } |
| 267 | local _len_0 = 1 | 224 | local _len_0 = 1 |
| 268 | for x = 1, 10 do | 225 | for x = 1, 10 do |
| 269 | local _continue_0 = false | 226 | if x > 3 and x < 7 then |
| 270 | repeat | 227 | goto _continue_5 |
| 271 | if x > 3 and x < 7 then | ||
| 272 | _continue_0 = true | ||
| 273 | break | ||
| 274 | end | ||
| 275 | _accum_0[_len_0] = x | ||
| 276 | _len_0 = _len_0 + 1 | ||
| 277 | _continue_0 = true | ||
| 278 | until true | ||
| 279 | if not _continue_0 then | ||
| 280 | break | ||
| 281 | end | 228 | end |
| 229 | _accum_0[_len_0] = x | ||
| 230 | _len_0 = _len_0 + 1 | ||
| 231 | ::_continue_5:: | ||
| 282 | end | 232 | end |
| 283 | list = _accum_0 | 233 | list = _accum_0 |
| 284 | end | 234 | end |
| @@ -292,78 +242,42 @@ local _list_2 = { | |||
| 292 | } | 242 | } |
| 293 | for _index_0 = 1, #_list_2 do | 243 | for _index_0 = 1, #_list_2 do |
| 294 | local a = _list_2[_index_0] | 244 | local a = _list_2[_index_0] |
| 295 | local _continue_0 = false | 245 | if a == 1 then |
| 296 | repeat | 246 | goto _continue_6 |
| 297 | if a == 1 then | ||
| 298 | _continue_0 = true | ||
| 299 | break | ||
| 300 | end | ||
| 301 | if a == 3 then | ||
| 302 | _continue_0 = true | ||
| 303 | break | ||
| 304 | end | ||
| 305 | print(a) | ||
| 306 | _continue_0 = true | ||
| 307 | until true | ||
| 308 | if not _continue_0 then | ||
| 309 | break | ||
| 310 | end | 247 | end |
| 248 | if a == 3 then | ||
| 249 | goto _continue_6 | ||
| 250 | end | ||
| 251 | print(a) | ||
| 252 | ::_continue_6:: | ||
| 311 | end | 253 | end |
| 312 | for x = 1, 10 do | 254 | for x = 1, 10 do |
| 313 | local _continue_0 = false | 255 | if x % 2 == 0 then |
| 314 | repeat | 256 | goto _continue_7 |
| 315 | if x % 2 == 0 then | 257 | end |
| 316 | _continue_0 = true | 258 | for y = 2, 12 do |
| 317 | break | 259 | if y % 3 == 0 then |
| 318 | end | 260 | goto _continue_8 |
| 319 | for y = 2, 12 do | ||
| 320 | local _continue_1 = false | ||
| 321 | repeat | ||
| 322 | if y % 3 == 0 then | ||
| 323 | _continue_1 = true | ||
| 324 | break | ||
| 325 | end | ||
| 326 | _continue_1 = true | ||
| 327 | until true | ||
| 328 | if not _continue_1 then | ||
| 329 | break | ||
| 330 | end | ||
| 331 | end | 261 | end |
| 332 | _continue_0 = true | 262 | ::_continue_8:: |
| 333 | until true | ||
| 334 | if not _continue_0 then | ||
| 335 | break | ||
| 336 | end | 263 | end |
| 264 | ::_continue_7:: | ||
| 337 | end | 265 | end |
| 338 | while true do | 266 | while true do |
| 339 | local _continue_0 = false | 267 | if false then |
| 340 | repeat | 268 | goto _continue_9 |
| 341 | do | ||
| 342 | if false then | ||
| 343 | _continue_0 = true | ||
| 344 | break | ||
| 345 | end | ||
| 346 | break | ||
| 347 | end | ||
| 348 | _continue_0 = true | ||
| 349 | until true | ||
| 350 | if not _continue_0 then | ||
| 351 | break | ||
| 352 | end | 269 | end |
| 270 | break | ||
| 271 | ::_continue_9:: | ||
| 353 | end | 272 | end |
| 354 | while true do | 273 | while true do |
| 355 | local _continue_0 = false | 274 | if false then |
| 356 | repeat | 275 | goto _continue_10 |
| 357 | if false then | 276 | end |
| 358 | _continue_0 = true | 277 | do |
| 359 | break | ||
| 360 | end | ||
| 361 | return 22 | 278 | return 22 |
| 362 | _continue_0 = true | ||
| 363 | until true | ||
| 364 | if not _continue_0 then | ||
| 365 | break | ||
| 366 | end | 279 | end |
| 280 | ::_continue_10:: | ||
| 367 | end | 281 | end |
| 368 | do | 282 | do |
| 369 | local xxx = { | 283 | local xxx = { |
diff --git a/spec/outputs/test/loops_spec.lua b/spec/outputs/test/loops_spec.lua index 34f2e9c..9c85e1a 100644 --- a/spec/outputs/test/loops_spec.lua +++ b/spec/outputs/test/loops_spec.lua | |||
| @@ -14,56 +14,39 @@ return describe("loops", function() | |||
| 14 | local _len_0 = 1 | 14 | local _len_0 = 1 |
| 15 | for _index_0 = 1, #input do | 15 | for _index_0 = 1, #input do |
| 16 | local x = input[_index_0] | 16 | local x = input[_index_0] |
| 17 | local _continue_0 = false | 17 | if x % 2 == 1 then |
| 18 | repeat | 18 | goto _continue_0 |
| 19 | if x % 2 == 1 then | ||
| 20 | _continue_0 = true | ||
| 21 | break | ||
| 22 | end | ||
| 23 | _accum_0[_len_0] = x | ||
| 24 | _len_0 = _len_0 + 1 | ||
| 25 | _continue_0 = true | ||
| 26 | until true | ||
| 27 | if not _continue_0 then | ||
| 28 | break | ||
| 29 | end | 19 | end |
| 20 | _accum_0[_len_0] = x | ||
| 21 | _len_0 = _len_0 + 1 | ||
| 22 | ::_continue_0:: | ||
| 30 | end | 23 | end |
| 31 | output = _accum_0 | 24 | output = _accum_0 |
| 32 | end | 25 | end |
| 33 | return assert.same(output, { | 26 | return assert.same({ |
| 34 | 2, | 27 | 2, |
| 35 | 4, | 28 | 4, |
| 36 | 6 | 29 | 6 |
| 37 | }) | 30 | }, output) |
| 38 | end) | 31 | end) |
| 39 | return it("continue in repeat", function() | 32 | return it("continue in repeat", function() |
| 40 | local output = { } | 33 | local output = { } |
| 41 | local a = 0 | 34 | local a = 0 |
| 42 | repeat | 35 | repeat |
| 43 | local _cond_0 = false | 36 | a = a + 1 |
| 44 | local _continue_0 = false | 37 | if a == 3 then |
| 45 | repeat | 38 | goto _continue_0 |
| 46 | a = a + 1 | 39 | end |
| 47 | if a == 3 then | 40 | if a == 5 then |
| 48 | _cond_0 = a == 8 | ||
| 49 | _continue_0 = true | ||
| 50 | break | ||
| 51 | end | ||
| 52 | if a == 5 then | ||
| 53 | break | ||
| 54 | end | ||
| 55 | output[#output + 1] = a | ||
| 56 | _cond_0 = a == 8 | ||
| 57 | _continue_0 = true | ||
| 58 | until true | ||
| 59 | if not _continue_0 then | ||
| 60 | break | 41 | break |
| 61 | end | 42 | end |
| 62 | until _cond_0 | 43 | output[#output + 1] = a |
| 63 | return assert.same(output, { | 44 | ::_continue_0:: |
| 45 | until a == 8 | ||
| 46 | return assert.same({ | ||
| 64 | 1, | 47 | 1, |
| 65 | 2, | 48 | 2, |
| 66 | 4 | 49 | 4 |
| 67 | }) | 50 | }, output) |
| 68 | end) | 51 | end) |
| 69 | end) | 52 | end) |
