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-9b7987a9d1471ba94764286b28e0998f73deb46a.tar.gz lua-9b7987a9d1471ba94764286b28e0998f73deb46a.tar.bz2 lua-9b7987a9d1471ba94764286b28e0998f73deb46a.zip |
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) { | |||
872 | } | 872 | } |
873 | 873 | ||
874 | 874 | ||
875 | static int code_loadbool (FuncState *fs, int A, OpCode op, int jump) { | 875 | static int code_loadbool (FuncState *fs, int A, OpCode op) { |
876 | luaK_getlabel(fs); /* those instructions may be jump targets */ | 876 | 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); |
878 | } | 878 | } |
879 | 879 | ||
880 | 880 | ||
@@ -908,8 +908,8 @@ static void exp2reg (FuncState *fs, expdesc *e, int reg) { | |||
908 | int p_t = NO_JUMP; /* position of an eventual LOAD true */ | 908 | int p_t = NO_JUMP; /* position of an eventual LOAD true */ |
909 | if (need_value(fs, e->t) || need_value(fs, e->f)) { | 909 | if (need_value(fs, e->t) || need_value(fs, e->f)) { |
910 | int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); | 910 | int fj = (e->k == VJMP) ? NO_JUMP : luaK_jump(fs); |
911 | p_f = code_loadbool(fs, reg, OP_LOADFALSE, 1); /* skip next inst. */ | 911 | p_f = code_loadbool(fs, reg, OP_LFALSESKIP); /* skip next inst. */ |
912 | p_t = code_loadbool(fs, reg, OP_LOADTRUE, 0); | 912 | p_t = code_loadbool(fs, reg, OP_LOADTRUE); |
913 | /* jump around these booleans if 'e' is not a test */ | 913 | /* jump around these booleans if 'e' is not a test */ |
914 | luaK_patchtohere(fs, fj); | 914 | luaK_patchtohere(fs, fj); |
915 | } | 915 | } |
@@ -31,6 +31,7 @@ static void *disptab[NUM_OPCODES] = { | |||
31 | &&L_OP_LOADK, | 31 | &&L_OP_LOADK, |
32 | &&L_OP_LOADKX, | 32 | &&L_OP_LOADKX, |
33 | &&L_OP_LOADFALSE, | 33 | &&L_OP_LOADFALSE, |
34 | &&L_OP_LFALSESKIP, | ||
34 | &&L_OP_LOADTRUE, | 35 | &&L_OP_LOADTRUE, |
35 | &&L_OP_LOADNIL, | 36 | &&L_OP_LOADNIL, |
36 | &&L_OP_GETUPVAL, | 37 | &&L_OP_GETUPVAL, |
@@ -25,6 +25,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
25 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ | 25 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ |
26 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ | 26 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ |
27 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ | 27 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ |
28 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */ | ||
28 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ | 29 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ |
29 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ | 30 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ |
30 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ | 31 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ |
@@ -202,7 +202,8 @@ OP_LOADI,/* A sBx R[A] := sBx */ | |||
202 | OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */ | 202 | OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */ |
203 | OP_LOADK,/* A Bx R[A] := K[Bx] */ | 203 | OP_LOADK,/* A Bx R[A] := K[Bx] */ |
204 | OP_LOADKX,/* A R[A] := K[extra arg] */ | 204 | 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++ */ | ||
206 | OP_LOADTRUE,/* A R[A] := true */ | 207 | OP_LOADTRUE,/* A R[A] := true */ |
207 | OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ | 208 | OP_LOADNIL,/* A B R[A], R[A+1], ..., R[A+B] := nil */ |
208 | OP_GETUPVAL,/* A B R[A] := UpValue[B] */ | 209 | OP_GETUPVAL,/* A B R[A] := UpValue[B] */ |
@@ -16,6 +16,7 @@ static const char *const opnames[] = { | |||
16 | "LOADK", | 16 | "LOADK", |
17 | "LOADKX", | 17 | "LOADKX", |
18 | "LOADFALSE", | 18 | "LOADFALSE", |
19 | "LFALSESKIP", | ||
19 | "LOADTRUE", | 20 | "LOADTRUE", |
20 | "LOADNIL", | 21 | "LOADNIL", |
21 | "GETUPVAL", | 22 | "GETUPVAL", |
@@ -1183,7 +1183,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1183 | } | 1183 | } |
1184 | vmcase(OP_LOADFALSE) { | 1184 | vmcase(OP_LOADFALSE) { |
1185 | setbfvalue(s2v(ra)); | 1185 | 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 */ | ||
1187 | vmbreak; | 1191 | vmbreak; |
1188 | } | 1192 | } |
1189 | vmcase(OP_LOADTRUE) { | 1193 | vmcase(OP_LOADTRUE) { |