diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-24 20:44:34 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-27 22:43:18 +1000 |
commit | ed0518f417a61b32e531f85c434b8024859202cd (patch) | |
tree | 39df7684f14774877a6c454d125e23b28cb5dd18 /src/lobject.js | |
parent | 1428582c2d88b23f12c87921381796d03b388d9f (diff) | |
download | fengari-ed0518f417a61b32e531f85c434b8024859202cd.tar.gz fengari-ed0518f417a61b32e531f85c434b8024859202cd.tar.bz2 fengari-ed0518f417a61b32e531f85c434b8024859202cd.zip |
Modify stack values up to L.top instead of replacing
Diffstat (limited to 'src/lobject.js')
-rw-r--r-- | src/lobject.js | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/lobject.js b/src/lobject.js index aec7109..f395036 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -220,16 +220,22 @@ class TValue { } +const pushobj2s = function(L, tv) { + L.stack[L.top++] = new TValue(tv.type, tv.value); +}; +const pushsvalue2s = function(L, ts) { + L.stack[L.top++] = new TValue(CT.LUA_TLNGSTR, ts); +}; /* from stack to (same) stack */ const setobjs2s = function(L, newidx, oldidx) { - L.stack[newidx] = L.stack[oldidx]; + L.stack[newidx].setfrom(L.stack[oldidx]); }; /* to stack (not from same stack) */ const setobj2s = function(L, newidx, oldtv) { - L.stack[newidx] = new TValue(oldtv.type, oldtv.value); + L.stack[newidx].setfrom(oldtv); }; const setsvalue2s = function(L, newidx, ts) { - L.stack[newidx] = new TValue(CT.LUA_TLNGSTR, ts); + L.stack[newidx].setsvalue(ts); }; const luaO_nilobject = new TValue(CT.LUA_TNIL, null); @@ -528,8 +534,8 @@ const luaO_tostring = function(L, obj) { }; const pushstr = function(L, str) { - setsvalue2s(L, L.top, lstring.luaS_new(L, str)); ldo.luaD_inctop(L); + setsvalue2s(L, L.top-1, lstring.luaS_new(L, str)); }; const luaO_pushvfstring = function(L, fmt, argp) { @@ -659,8 +665,7 @@ const luaO_arith = function(L, op, p1, p2, res) { case defs.LUA_OPBNOT: { /* operate only on integers */ let i1, i2; if ((i1 = lvm.tointeger(p1)) !== false && (i2 = lvm.tointeger(p2)) !== false) { - res.type = CT.LUA_TNUMINT; - res.value = intarith(L, op, i1, i2); + res.setivalue(intarith(L, op, i1, i2)); return; } else break; /* go to the end */ @@ -668,8 +673,7 @@ const luaO_arith = function(L, op, p1, p2, res) { case defs.LUA_OPDIV: case defs.LUA_OPPOW: { /* operate only on floats */ let n1, n2; if ((n1 = lvm.tonumber(p1)) !== false && (n2 = lvm.tonumber(p2)) !== false) { - res.type = CT.LUA_TNUMFLT; - res.value = numarith(L, op, n1, n2); + res.setfltvalue(numarith(L, op, n1, n2)); return; } else break; /* go to the end */ @@ -677,13 +681,11 @@ const luaO_arith = function(L, op, p1, p2, res) { default: { /* other operations */ let n1, n2; if (p1.ttisinteger() && p2.ttisinteger()) { - res.type = CT.LUA_TNUMINT; - res.value = intarith(L, op, p1.value, p2.value); + res.setivalue(intarith(L, op, p1.value, p2.value)); return; } else if ((n1 = lvm.tonumber(p1)) !== false && (n2 = lvm.tonumber(p2)) !== false) { - res.type = CT.LUA_TNUMFLT; - res.value = numarith(L, op, n1, n2); + res.setfltvalue(numarith(L, op, n1, n2)); return; } else break; /* go to the end */ @@ -714,6 +716,8 @@ module.exports.luaO_tostring = luaO_tostring; module.exports.luaO_utf8desc = luaO_utf8desc; module.exports.luaO_utf8esc = luaO_utf8esc; module.exports.numarith = numarith; +module.exports.pushobj2s = pushobj2s; +module.exports.pushsvalue2s = pushsvalue2s; module.exports.setobjs2s = setobjs2s; module.exports.setobj2s = setobj2s; module.exports.setsvalue2s = setsvalue2s; |