Skip to content

Commit

Permalink
Merge pull request #67 from well-in-that-case/cfix
Browse files Browse the repository at this point in the history
Fix continue statement again.
  • Loading branch information
well-in-that-case authored Jul 15, 2022
2 parents cafde6e + 05ec744 commit 2eb0e8d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,7 @@ static void continuestat (LexState *ls) {
}
if (bl) {
if (upval) luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); /* close upvalues */
luaK_code(fs, CREATE_sJ(OP_JMP, (bl->scopeend + OFFSET_sJ + 4), false));
luaK_concat(fs, &bl->scopeend, luaK_jump(fs));
}
else error_expected(ls, TK_PCONTINUE);
}
Expand Down Expand Up @@ -2146,11 +2146,11 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isgen) {
block(ls);
leaveblock(fs); /* end of scope for declared variables */
fixforjump(fs, prep, luaK_getlabel(fs), 0);
luaK_patchtohere(fs, bl.previous->scopeend);
if (isgen) { /* generic for? */
luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
luaK_fixline(fs, line);
}
luaK_patchtohere(fs, bl.previous->scopeend);
endfor = luaK_codeABx(fs, forloop[isgen], base, 0);
fixforjump(fs, endfor, prep + 1, 1);
luaK_fixline(fs, line);
Expand Down
2 changes: 1 addition & 1 deletion src/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "luaconf.h"


#define PLUTO_VERSION "Pluto 0.2.1"
#define PLUTO_VERSION "Pluto 0.2.2"

#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "4"
Expand Down
36 changes: 36 additions & 0 deletions tests/basic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,42 @@ assert(str[-3] == "a")
assert(str[-4] == nil)
assert(str[-5] == nil)

print "Testing continue statement."
local t = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }
local sum = 0
for index, value in ipairs(t) do
if value == 5 then
continue
end
sum += value
end
assert(sum == 40)

local sum = 0
for i = 1, 10 do
if i == 5 then
continue
end
sum += i
end
assert(sum == 50)

local lines = {
"This",
"Is",
"Some",
"Lines",
}

for index, line in ipairs(lines) do
if index == 1 and line == "This" then
continue
elseif index == #lines and line == "Lines" then
continue
end
assert(line != "This" and line != "Lines")
end

print "Testing table length cache."
local t = {}
for i = 1, 1000 do
Expand Down

0 comments on commit 2eb0e8d

Please sign in to comment.