diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-07-11 12:53:23 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-07-11 12:53:23 -0300 |
| commit | 4d5de1c1fb2decb39d74dfb092ca5643ce47176f (patch) | |
| tree | 6d211899db43994b5d421a8a7e59dcb2ecccc0db /ltests.c | |
| parent | 9a825f6bb9a141023ac519a73f6a9958c113659e (diff) | |
| download | lua-4d5de1c1fb2decb39d74dfb092ca5643ce47176f.tar.gz lua-4d5de1c1fb2decb39d74dfb092ca5643ce47176f.tar.bz2 lua-4d5de1c1fb2decb39d74dfb092ca5643ce47176f.zip | |
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.
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 22 |
1 files changed, 21 insertions, 1 deletions
| @@ -526,7 +526,8 @@ static char *buildop (Proto *p, int pc, char *buff) { | |||
| 526 | OpCode o = GET_OPCODE(i); | 526 | OpCode o = GET_OPCODE(i); |
| 527 | const char *name = opnames[o]; | 527 | const char *name = opnames[o]; |
| 528 | int line = luaG_getfuncline(p, pc); | 528 | int line = luaG_getfuncline(p, pc); |
| 529 | sprintf(buff, "(%4d) %4d - ", line, pc); | 529 | int lineinfo = (p->lineinfo != NULL) ? p->lineinfo[pc] : 0; |
| 530 | sprintf(buff, "(%2d - %4d) %4d - ", lineinfo, line, pc); | ||
| 530 | switch (getOpMode(o)) { | 531 | switch (getOpMode(o)) { |
| 531 | case iABC: | 532 | case iABC: |
| 532 | sprintf(buff+strlen(buff), "%-12s%4d %4d %4d%s", name, | 533 | sprintf(buff+strlen(buff), "%-12s%4d %4d %4d%s", name, |
| @@ -621,6 +622,24 @@ static int listk (lua_State *L) { | |||
| 621 | } | 622 | } |
| 622 | 623 | ||
| 623 | 624 | ||
| 625 | static int listabslineinfo (lua_State *L) { | ||
| 626 | Proto *p; | ||
| 627 | int i; | ||
| 628 | luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), | ||
| 629 | 1, "Lua function expected"); | ||
| 630 | p = getproto(obj_at(L, 1)); | ||
| 631 | luaL_argcheck(L, p->abslineinfo != NULL, 1, "function has no debug info"); | ||
| 632 | lua_createtable(L, 2 * p->sizeabslineinfo, 0); | ||
| 633 | for (i=0; i < p->sizeabslineinfo; i++) { | ||
| 634 | lua_pushinteger(L, p->abslineinfo[i].pc); | ||
| 635 | lua_rawseti(L, -2, 2 * i + 1); | ||
| 636 | lua_pushinteger(L, p->abslineinfo[i].line); | ||
| 637 | lua_rawseti(L, -2, 2 * i + 2); | ||
| 638 | } | ||
| 639 | return 1; | ||
| 640 | } | ||
| 641 | |||
| 642 | |||
| 624 | static int listlocals (lua_State *L) { | 643 | static int listlocals (lua_State *L) { |
| 625 | Proto *p; | 644 | Proto *p; |
| 626 | int pc = cast_int(luaL_checkinteger(L, 2)) - 1; | 645 | int pc = cast_int(luaL_checkinteger(L, 2)) - 1; |
| @@ -1682,6 +1701,7 @@ static const struct luaL_Reg tests_funcs[] = { | |||
| 1682 | {"listcode", listcode}, | 1701 | {"listcode", listcode}, |
| 1683 | {"printcode", printcode}, | 1702 | {"printcode", printcode}, |
| 1684 | {"listk", listk}, | 1703 | {"listk", listk}, |
| 1704 | {"listabslineinfo", listabslineinfo}, | ||
| 1685 | {"listlocals", listlocals}, | 1705 | {"listlocals", listlocals}, |
| 1686 | {"loadlib", loadlib}, | 1706 | {"loadlib", loadlib}, |
| 1687 | {"checkpanic", checkpanic}, | 1707 | {"checkpanic", checkpanic}, |
