Skip to content

Commit 9b7987a

Browse files
committed
OP_LOADFALSE broken in two instructions
1 parent 28ef706 commit 9b7987a

6 files changed

Lines changed: 14 additions & 6 deletions

File tree

lcode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,9 @@ static void discharge2anyreg (FuncState *fs, expdesc *e) {
872872
}
873873

874874

875-
static int code_loadbool (FuncState *fs, int A, OpCode op, int jump) {
875+
static int code_loadbool (FuncState *fs, int A, OpCode op) {
876876
luaK_getlabel(fs); /* those instructions may be jump targets */
877-
return luaK_codeABC(fs, op, A, jump, 0);
877+
return luaK_codeABC(fs, op, A, 0, 0);
878878
}
879879

880880

@@ -908,8 +908,8 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) {
908908
int p_t = NO_JUMP; /* position of an eventual LOAD true */
909909
if (need_value(fs, e->t) || need_value(fs, e->f)) {
910910
int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs);
911-
p_f = code_loadbool(fs, reg, OP_LOADFALSE, 1); /* skip next inst. */
912-
p_t = code_loadbool(fs, reg, OP_LOADTRUE, 0);
911+
p_f = code_loadbool(fs, reg, OP_LFALSESKIP); /* skip next inst. */
912+
p_t = code_loadbool(fs, reg, OP_LOADTRUE);
913913
/* jump around these booleans if 'e' is not a test */
914914
luaK_patchtohere(fs, fj);
915915
}

ljumptab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static void *disptab[NUM_OPCODES] = {
3131
&&L_OP_LOADK,
3232
&&L_OP_LOADKX,
3333
&&L_OP_LOADFALSE,
34+
&&L_OP_LFALSESKIP,
3435
&&L_OP_LOADTRUE,
3536
&&L_OP_LOADNIL,
3637
&&L_OP_GETUPVAL,

lopcodes.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
2525
,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */
2626
,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */
2727
,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */
28+
,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */
2829
,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */
2930
,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */
3031
,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */

lopcodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ OP_LOADI,/* A sBx R[A] := sBx */
202202
OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */
203203
OP_LOADK,/* A Bx R[A] := K[Bx] */
204204
OP_LOADKX,/* A R[A] := K[extra arg] */
205-
OP_LOADFALSE,/* A B R[A] := false; if (B) pc++ */
205+
OP_LOADFALSE,/* A R[A] := false */
206+
OP_LFALSESKIP,/*A R[A] := false; pc++ */
206207
OP_LOADTRUE,/* A R[A] := true */
207208
OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */
208209
OP_GETUPVAL,/* A B R[A] := UpValue[B] */

lopnames.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static const char *const opnames[] = {
1616
"LOADK",
1717
"LOADKX",
1818
"LOADFALSE",
19+
"LFALSESKIP",
1920
"LOADTRUE",
2021
"LOADNIL",
2122
"GETUPVAL",

lvm.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
11831183
}
11841184
vmcase(OP_LOADFALSE) {
11851185
setbfvalue(s2v(ra));
1186-
if (GETARG_B(i)) pc++; /* if B, skip next instruction */
1186+
vmbreak;
1187+
}
1188+
vmcase(OP_LFALSESKIP) {
1189+
setbfvalue(s2v(ra));
1190+
pc++; /* skip next instruction */
11871191
vmbreak;
11881192
}
11891193
vmcase(OP_LOADTRUE) {

0 commit comments

Comments
 (0)