bug - getting confused by MOVE after OP_CLOSURE - need to investigate properfix - for now fix getlocvartype(0 to check that fs == fs->ls->fs

Dibyendu Majumdar 9 years ago
parent fb917c0d75
commit d46777e918

@ -494,7 +494,7 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
case VNONRELOC: {
if (reg != e->u.info) {
/* code a MOVEI or MOVEF if the target register is a local typed variable */
int ravi_type = getlocvartype(fs, reg);
int ravi_type = fs == getlocvartype(fs, reg);
switch (ravi_type) {
case LUA_TNUMINT:
luaK_codeABC(fs, OP_RAVI_MOVEI, reg, e->u.info, 0);

@ -163,6 +163,12 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"LEIIRK",/* A B C if ((R(B) <= Kst(C)) ~= A) then pc++ */
"LEIIRR",/* A B C if ((R(B) <= R(C)) ~= A) then pc++ */
"TOINT", /* A R(A) := toint(R(A)) */
"TOFLT", /* A R(A) := tofloat(R(A)) */
"MOVEI", /* A B R(A) := R(B) */
"MOVEF", /* A B R(A) := R(B) */
"ARRAYGET_SIK",/* A B C R(A) := R(B)[Kst(C)] */
"ARRAYGET_SIR",/* A B C R(A) := R(B)[R(C)] */
"ARRAYGET_IIK",/* A B C R(A) := R(B)[Kst(C)] */
@ -189,12 +195,6 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"ARRAYSET_ILRK",/* A B C R(A)[R(B)] := Kst(C) */
"ARRAYSET_ILRR",/* A B C R(A)[R(B)] := R(C) */
"TOINT", /* A R(A) := toint(R(A)) */
"TOFLT", /* A R(A) := tofloat(R(A)) */
"MOVEI", /* A B R(A) := R(B) */
"MOVEF", /* A B R(A) := R(B) */
NULL
};

@ -354,6 +354,8 @@ static LocVar *getlocvar (FuncState *fs, int i) {
/* get type of a local var */
int getlocvartype(FuncState *fs, int i) {
if (fs != fs->ls->fs) /* not current function? */
return LUA_TNONE;
lua_assert(i < fs->ls->dyd->actvar.n);
if (i < 0 || i >= fs->ls->dyd->actvar.n)
return LUA_TNONE;

@ -1766,7 +1766,7 @@ newframe: /* reentry point when frame changes (call/return) */
setivalue(ra, i);
}
else
luaG_runerror(L, "int type expected");
luaG_runerror(L, "TOINT: int type expected");
} break;
case OP(OP_RAVI_TOFLT): {
lua_Number i;
@ -1774,7 +1774,7 @@ newframe: /* reentry point when frame changes (call/return) */
setfltvalue(ra, i);
}
else
luaG_runerror(L, "double type expected");
luaG_runerror(L, "TOFLT: double type expected");
} break;
case OP(OP_RAVI_MOVEI): {
lua_Integer i;
@ -1783,7 +1783,7 @@ newframe: /* reentry point when frame changes (call/return) */
setivalue(ra, i);
}
else
luaG_runerror(L, "int type expected");
luaG_runerror(L, "MOVEI: int type expected");
} break;
case OP(OP_RAVI_MOVEF): {
lua_Number i;
@ -1792,7 +1792,7 @@ newframe: /* reentry point when frame changes (call/return) */
setfltvalue(ra, i);
}
else
luaG_runerror(L, "double type expected");
luaG_runerror(L, "MOVEF: double type expected");
} break;
}

@ -550,6 +550,7 @@ static int test_luacompexec1(const char *code, int expected)
int main(const char *argv[])
{
int failures = 0;
failures += test_luacompexec1("local function tryme(); return 5,6; end; local i:int, j:int = tryme(); return i+j", 11);
failures += test_luacomp1("local i,j; j = i*j+i");
failures += test_luacomp1("local i:int; for i=1,10 do; print(i); end; print(i)");
failures += test_luacomp1("local i:int, j:double; i,j = f(); j = i*j+i");

Loading…
Cancel
Save