summaryrefslogtreecommitdiff
path: root/src/lcode.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-22 18:36:25 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-22 18:46:32 +1000
commita021614ebb948f218156cb38c4f441af904aa8c1 (patch)
tree666d3f5e9aa36a4bfd085aa6e3b153e479b82985 /src/lcode.js
parent91e09ea32148c34965809b8d69987d439d389870 (diff)
downloadfengari-a021614ebb948f218156cb38c4f441af904aa8c1.tar.gz
fengari-a021614ebb948f218156cb38c4f441af904aa8c1.tar.bz2
fengari-a021614ebb948f218156cb38c4f441af904aa8c1.zip
src/lcode.js: Fix patchtestreg to actually modify the instruction
Diffstat (limited to 'src/lcode.js')
-rw-r--r--src/lcode.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lcode.js b/src/lcode.js
index 6515d93..ea010aa 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -211,11 +211,14 @@ const luaK_getlabel = function(fs) {
** jump (that is, its condition), or the jump itself if it is
** unconditional.
*/
-const getjumpcontrol = function(fs, pc) {
+const getjumpcontroloffset = function(fs, pc) {
if (pc >= 1 && lopcodes.testTMode(fs.f.code[pc - 1].opcode))
- return fs.f.code[pc - 1];
+ return pc - 1;
else
- return fs.f.code[pc];
+ return pc;
+};
+const getjumpcontrol = function(fs, pc) {
+ return fs.f.code[getjumpcontroloffset(fs, pc)];
};
/*
@@ -226,7 +229,8 @@ const getjumpcontrol = function(fs, pc) {
** no register value)
*/
const patchtestreg = function(fs, node, reg) {
- let i = getjumpcontrol(fs, node);
+ let pc = getjumpcontroloffset(fs, node);
+ let i = fs.f.code[pc];
if (i.opcode !== OpCodesI.OP_TESTSET)
return false; /* cannot patch other instructions */
if (reg !== lopcodes.NO_REG && reg !== i.B)
@@ -234,7 +238,7 @@ const patchtestreg = function(fs, node, reg) {
else {
/* no register to put value or register already has the value;
change instruction to simple test */
- i = lopcodes.CREATE_ABC(OpCodesI.OP_TEST, i.B, 0, i.C);
+ fs.f.code[pc] = lopcodes.CREATE_ABC(OpCodesI.OP_TEST, i.B, 0, i.C);
}
return true;
};