Fixed bug in line info. when using 'not' operator

When creating code for a jump on a 'not' condition, the code generator
was removing an instruction (the OP_NOT) without adjusting its
corresponding line information.

This fix also added tests for this case and extra functionality in
the test library to debug line info. structures.
This commit is contained in:
Roberto Ierusalimschy
2018-07-11 12:53:23 -03:00
parent 9a825f6bb9
commit 4d5de1c1fb
3 changed files with 93 additions and 26 deletions

View File

@@ -526,7 +526,8 @@ static char *buildop (Proto *p, int pc, char *buff) {
OpCode o = GET_OPCODE(i);
const char *name = opnames[o];
int line = luaG_getfuncline(p, pc);
sprintf(buff, "(%4d) %4d - ", line, pc);
int lineinfo = (p->lineinfo != NULL) ? p->lineinfo[pc] : 0;
sprintf(buff, "(%2d - %4d) %4d - ", lineinfo, line, pc);
switch (getOpMode(o)) {
case iABC:
sprintf(buff+strlen(buff), "%-12s%4d %4d %4d%s", name,
@@ -621,6 +622,24 @@ static int listk (lua_State *L) {
}
static int listabslineinfo (lua_State *L) {
Proto *p;
int i;
luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
1, "Lua function expected");
p = getproto(obj_at(L, 1));
luaL_argcheck(L, p->abslineinfo != NULL, 1, "function has no debug info");
lua_createtable(L, 2 * p->sizeabslineinfo, 0);
for (i=0; i < p->sizeabslineinfo; i++) {
lua_pushinteger(L, p->abslineinfo[i].pc);
lua_rawseti(L, -2, 2 * i + 1);
lua_pushinteger(L, p->abslineinfo[i].line);
lua_rawseti(L, -2, 2 * i + 2);
}
return 1;
}
static int listlocals (lua_State *L) {
Proto *p;
int pc = cast_int(luaL_checkinteger(L, 2)) - 1;
@@ -1682,6 +1701,7 @@ static const struct luaL_Reg tests_funcs[] = {
{"listcode", listcode},
{"printcode", printcode},
{"listk", listk},
{"listabslineinfo", listabslineinfo},
{"listlocals", listlocals},
{"loadlib", loadlib},
{"checkpanic", checkpanic},