Browse Source

OP_LOADFALSE broken in two instructions

pull/23/head
Roberto Ierusalimschy 5 years ago
parent
commit
9b7987a9d1
  1. 8
      lcode.c
  2. 1
      ljumptab.h
  3. 1
      lopcodes.c
  4. 3
      lopcodes.h
  5. 1
      lopnames.h
  6. 6
      lvm.c

8
lcode.c

@ -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);
}

1
ljumptab.h

@ -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,

1
lopcodes.c

@ -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 */

3
lopcodes.h

@ -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] */

1
lopnames.h

@ -16,6 +16,7 @@ static const char *const opnames[] = {
"LOADK",
"LOADKX",
"LOADFALSE",
"LFALSESKIP",
"LOADTRUE",
"LOADNIL",
"GETUPVAL",

6
lvm.c

@ -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) {

Loading…
Cancel
Save