summaryrefslogtreecommitdiff
path: root/src/lcode.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-22 10:51:55 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-22 10:51:55 +0200
commit25e2110a5eac0a2e6c7b4d502ffbd53fc61af301 (patch)
tree7e0ccc2dd0a03b36fc2ecee1887765b24bf3ac6a /src/lcode.js
parent18271b4169631ce8f10c10c0776d9bfb40bd691f (diff)
parent5b764695bdc939784fd448fe6ba16ed3a9f44b19 (diff)
downloadfengari-25e2110a5eac0a2e6c7b4d502ffbd53fc61af301.tar.gz
fengari-25e2110a5eac0a2e6c7b4d502ffbd53fc61af301.tar.bz2
fengari-25e2110a5eac0a2e6c7b4d502ffbd53fc61af301.zip
Merge remote-tracking branch 'daurnimator/stack'
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;
};