summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-23 17:37:20 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-27 22:14:35 +1000
commit888c1286cfe25c1b21605c3443cc0a20b522972b (patch)
tree803c8a31cccbb5013539fd0a575cc10f6af5a7fb /src
parentb3c87776e08f546a9994527f7c2c7fc4ec07d9a1 (diff)
downloadfengari-888c1286cfe25c1b21605c3443cc0a20b522972b.tar.gz
fengari-888c1286cfe25c1b21605c3443cc0a20b522972b.tar.bz2
fengari-888c1286cfe25c1b21605c3443cc0a20b522972b.zip
Introduce setobj2s
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js27
-rw-r--r--src/ldebug.js4
-rw-r--r--src/ldo.js2
-rw-r--r--src/lobject.js5
-rw-r--r--src/ltable.js4
-rw-r--r--src/ltm.js8
-rw-r--r--src/lvm.js8
7 files changed, 30 insertions, 28 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 00e608f..2cf3a1c 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -112,7 +112,7 @@ const lua_xmove = function(from, to, n) {
from.top -= n;
for (let i = 0; i < n; i++) {
- to.stack[to.top] = from.stack[from.top + i];
+ lobject.setobj2s(to, to.top, from.stack[from.top + i]);
to.top++;
}
};
@@ -135,8 +135,7 @@ const lua_gettop = function(L) {
};
const lua_pushvalue = function(L, idx) {
- L.stack[L.top] = index2addr(L, idx);
-
+ lobject.setobj2s(L, L.top, index2addr(L, idx));
L.top++;
assert(L.top <= L.ci.top, "stack overflow");
};
@@ -164,7 +163,7 @@ const reverse = function(L, from, to) {
for (; from < to; from++, to--) {
let temp = L.stack[from];
lobject.setobjs2s(L, from, to);
- L.stack[to] = temp;
+ lobject.setobj2s(L, to, temp);
}
};
@@ -474,12 +473,10 @@ const auxgetstr = function(L, t, k) {
const lua_rawgeti = function(L, idx, n) {
let t = index2addr(L, idx);
-
assert(t.ttistable(), "table expected");
-
- L.stack[L.top++] = ltable.luaH_getint(t.value, n);
+ lobject.setobj2s(L, L.top, ltable.luaH_getint(t.value, n));
+ L.top++;
assert(L.top <= L.ci.top, "stack overflow");
-
return L.stack[L.top - 1].ttnov();
};
@@ -487,18 +484,16 @@ const lua_rawgetp = function(L, idx, p) {
let t = index2addr(L, idx);
assert(t.ttistable(), "table expected");
let k = new TValue(CT.LUA_TLIGHTUSERDATA, p);
- L.stack[L.top++] = ltable.luaH_get(L, t.value, k);
+ lobject.setobj2s(L, L.top, ltable.luaH_get(L, t.value, k));
+ L.top++;
assert(L.top <= L.ci.top, "stack overflow");
return L.stack[L.top - 1].ttnov();
};
const lua_rawget = function(L, idx) {
let t = index2addr(L, idx);
-
assert(t.ttistable(t), "table expected");
-
- L.stack[L.top - 1] = ltable.luaH_get(L, t.value, L.stack[L.top - 1]);
-
+ lobject.setobj2s(L, L.top - 1, ltable.luaH_get(L, t.value, L.stack[L.top - 1]));
return L.stack[L.top - 1].ttnov();
};
@@ -552,9 +547,9 @@ const lua_getupvalue = function(L, funcindex, n) {
if (up) {
let name = up.name;
let val = up.val;
-
- L.stack[L.top++] = new TValue(val.type, val.value);
-
+ lobject.setobj2s(L, L.top, val);
+ L.top++;
+ assert(L.top <= L.ci.top, "stack overflow");
return name;
}
return null;
diff --git a/src/ldebug.js b/src/ldebug.js
index 0231e67..e78d3e7 100644
--- a/src/ldebug.js
+++ b/src/ldebug.js
@@ -140,7 +140,9 @@ const lua_getlocal = function(L, ar, n) {
let local = findlocal(L, ar.i_ci, n);
if (local) {
name = local.name;
- L.stack[L.top++] = L.stack[local.pos];
+ lobject.setobj2s(L, L.top, L.stack[local.pos]);
+ L.top++;
+ assert(L.top <= L.ci.top, "stack overflow");
} else {
name = null;
}
diff --git a/src/ldo.js b/src/ldo.js
index d236968..5fa51db 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -270,7 +270,7 @@ const tryfuncTM = function(L, off, func) {
for (let p = L.top; p > off; p--)
lobject.setobjs2s(L, p, p-1);
L.top++; /* slot ensured by caller */
- L.stack[off] = new lobject.TValue(tm.type, tm.value); /* tag method is the new function to be called */
+ lobject.setobj2s(L, off, tm); /* tag method is the new function to be called */
};
/*
diff --git a/src/lobject.js b/src/lobject.js
index 7b8a332..3a442ee 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -189,6 +189,10 @@ class TValue {
const setobjs2s = function(L, newidx, oldidx) {
L.stack[newidx] = L.stack[oldidx];
};
+/* to stack (not from same stack) */
+const setobj2s = function(L, newidx, oldtv) {
+ L.stack[newidx] = new TValue(oldtv.type, oldtv.value);
+};
const luaO_nilobject = new TValue(CT.LUA_TNIL, null);
Object.freeze(luaO_nilobject);
@@ -673,3 +677,4 @@ module.exports.luaO_utf8desc = luaO_utf8desc;
module.exports.luaO_utf8esc = luaO_utf8esc;
module.exports.numarith = numarith;
module.exports.setobjs2s = setobjs2s;
+module.exports.setobj2s = setobj2s;
diff --git a/src/ltable.js b/src/ltable.js
index 5a31b48..53a5d79 100644
--- a/src/ltable.js
+++ b/src/ltable.js
@@ -261,8 +261,8 @@ const luaH_next = function(L, table, keyI) {
} while (entry.key.ttisdeadkey());
}
}
- L.stack[keyI] = new lobject.TValue(entry.key.type, entry.key.value);
- L.stack[keyI+1] = new lobject.TValue(entry.value.type, entry.value.value);
+ lobject.setobj2s(L, keyI, entry.key);
+ lobject.setobj2s(L, keyI+1, entry.value);
return true;
};
diff --git a/src/ltm.js b/src/ltm.js
index 041dd19..c3efc1e 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -110,13 +110,13 @@ const luaT_objtypename = function(L, o) {
const luaT_callTM = function(L, f, p1, p2, p3, hasres) {
let func = L.top;
- L.stack[L.top] = new lobject.TValue(f.type, f.value); /* push function (assume EXTRA_STACK) */
- L.stack[L.top + 1] = new lobject.TValue(p1.type, p1.value); /* 1st argument */
- L.stack[L.top + 2] = new lobject.TValue(p2.type, p2.value); /* 2nd argument */
+ lobject.setobj2s(L, L.top, f); /* push function (assume EXTRA_STACK) */
+ lobject.setobj2s(L, L.top + 1, p1); /* 1st argument */
+ lobject.setobj2s(L, L.top + 2, p2); /* 2nd argument */
L.top += 3;
if (!hasres) /* no result? 'p3' is third argument */
- L.stack[L.top++] = new lobject.TValue(p3.type, p3.value); /* 3rd argument */
+ lobject.setobj2s(L, L.top++, p3); /* 3rd argument */
if (L.ci.callstatus & lstate.CIST_LUA)
ldo.luaD_call(L, func, hasres);
diff --git a/src/lvm.js b/src/lvm.js
index 602fe5c..c7bb7ad 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -126,13 +126,13 @@ const luaV_execute = function(L) {
}
case OCi.OP_LOADK: {
let konst = k[i.Bx];
- L.stack[ra] = new lobject.TValue(konst.type, konst.value);
+ lobject.setobj2s(L, ra, konst);
break;
}
case OCi.OP_LOADKX: {
assert(ci.l_code[ci.l_savedpc].opcode === OCi.OP_EXTRAARG);
let konst = k[ci.l_code[ci.l_savedpc++].Ax];
- L.stack[ra] = new lobject.TValue(konst.type, konst.value);
+ lobject.setobj2s(L, ra, konst);
break;
}
case OCi.OP_LOADBOOL: {
@@ -150,7 +150,7 @@ const luaV_execute = function(L) {
}
case OCi.OP_GETUPVAL: {
let o = cl.upvals[i.B].val();
- L.stack[ra] = new lobject.TValue(o.type, o.value);
+ lobject.setobj2s(L, ra, o);
break;
}
case OCi.OP_SETUPVAL: {
@@ -1033,7 +1033,7 @@ const gettable = function(L, t, key, ra) {
} else {
let slot = ltable.luaH_get(L, t.value, key);
if (!slot.ttisnil()) {
- L.stack[ra] = new lobject.TValue(slot.type, slot.value);
+ lobject.setobj2s(L, ra, slot);
return;
} else { /* 't' is a table */
tm = ltm.fasttm(L, t.value.metatable, ltm.TMS.TM_INDEX); /* table's metamethod */