diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-02-11 11:12:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-02-11 11:12:33 -0300 |
commit | 9b7987a9d1471ba94764286b28e0998f73deb46a (patch) | |
tree | b24e2836a29621521d65e6dc77fb39bdc4b627ee | |
parent | 28ef7061bbcce39590c97a2ad662e0b60f7adab5 (diff) | |
download | lua-github-9b7987a9d1471ba94764286b28e0998f73deb46a.tar.gz |
OP_LOADFALSE broken in two instructions
-rw-r--r-- | lcode.c | 8 | ||||
-rw-r--r-- | ljumptab.h | 1 | ||||
-rw-r--r-- | lopcodes.c | 1 | ||||
-rw-r--r-- | lopcodes.h | 3 | ||||
-rw-r--r-- | lopnames.h | 1 | ||||
-rw-r--r-- | lvm.c | 6 |
6 files changed, 14 insertions, 6 deletions
@@ -872,9 +872,9 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) { } -static int code_loadbool (FuncState *fs, int A, OpCode op, int jump) { +static int code_loadbool (FuncState *fs, int A, OpCode op) { luaK_getlabel(fs); /* those instructions may be jump targets */ - return luaK_codeABC(fs, op, A, jump, 0); + return luaK_codeABC(fs, op, A, 0, 0); } @@ -908,8 +908,8 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) { int p_t = NO_JUMP; /* position of an eventual LOAD true */ if (need_value(fs, e->t) || need_value(fs, e->f)) { int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); - p_f = code_loadbool(fs, reg, OP_LOADFALSE, 1); /* skip next inst. */ - p_t = code_loadbool(fs, reg, OP_LOADTRUE, 0); + p_f = code_loadbool(fs, reg, OP_LFALSESKIP); /* skip next inst. */ + p_t = code_loadbool(fs, reg, OP_LOADTRUE); /* jump around these booleans if 'e' is not a test */ luaK_patchtohere(fs, fj); } @@ -31,6 +31,7 @@ static void *disptab[NUM_OPCODES] = { &&L_OP_LOADK, &&L_OP_LOADKX, &&L_OP_LOADFALSE, +&&L_OP_LFALSESKIP, &&L_OP_LOADTRUE, &&L_OP_LOADNIL, &&L_OP_GETUPVAL, @@ -25,6 +25,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ + ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ @@ -202,7 +202,8 @@ OP_LOADI,/* A sBx R[A] := sBx */ OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */ OP_LOADK,/* A Bx R[A] := K[Bx] */ OP_LOADKX,/* A R[A] := K[extra arg] */ -OP_LOADFALSE,/* A B R[A] := false; if (B) pc++ */ +OP_LOADFALSE,/* A R[A] := false */ +OP_LFALSESKIP,/*A R[A] := false; pc++ */ OP_LOADTRUE,/* A R[A] := true */ OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ OP_GETUPVAL,/* A B R[A] := UpValue[B] */ @@ -16,6 +16,7 @@ static const char *const opnames[] = { "LOADK", "LOADKX", "LOADFALSE", + "LFALSESKIP", "LOADTRUE", "LOADNIL", "GETUPVAL", @@ -1183,7 +1183,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } vmcase(OP_LOADFALSE) { setbfvalue(s2v(ra)); - if (GETARG_B(i)) pc++; /* if B, skip next instruction */ + vmbreak; + } + vmcase(OP_LFALSESKIP) { + setbfvalue(s2v(ra)); + pc++; /* skip next instruction */ vmbreak; } vmcase(OP_LOADTRUE) { |