diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-02-14 21:39:16 +0100 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-02-14 21:40:39 +0100 |
commit | 829e47b9bd568c5722e9f59ca05036d2ae912ddf (patch) | |
tree | 40d51cbfa9449c0b07e7fb348d20365bc531e2f4 | |
parent | 8e19f368c2c40d99a92b39c6f566c7bcb2af6cf7 (diff) | |
download | fengari-829e47b9bd568c5722e9f59ca05036d2ae912ddf.tar.gz fengari-829e47b9bd568c5722e9f59ca05036d2ae912ddf.tar.bz2 fengari-829e47b9bd568c5722e9f59ca05036d2ae912ddf.zip |
Launch scripts with luaD_call
Will adjust L.top correctly. Still isn't what lua's doing since we still
miss the first 5 elements.
-rw-r--r-- | README.md | 24 | ||||
-rw-r--r-- | src/lvm.js | 24 | ||||
-rw-r--r-- | tests/ltm.js | 36 | ||||
-rw-r--r-- | tests/lvm.js | 59 |
4 files changed, 67 insertions, 76 deletions
@@ -23,18 +23,18 @@ - [x] `__mode` (unavailable) - [ ] `__len` - [ ] `__eq` - - [ ] `__add` - - [ ] `__sub` - - [ ] `__mul` - - [ ] `__mod` - - [ ] `__pow` - - [ ] `__div` - - [ ] `__idiv` - - [ ] `__band` - - [ ] `__bor` - - [ ] `__bxor` - - [ ] `__shl` - - [ ] `__shr` + - [x] `__add` + - [x] `__sub` + - [x] `__mul` + - [x] `__mod` + - [x] `__pow` + - [x] `__div` + - [x] `__idiv` + - [x] `__band` + - [x] `__bor` + - [x] `__bxor` + - [x] `__shl` + - [x] `__shr` - [ ] `__unm` - [ ] `__bnot` - [ ] `__lt` @@ -169,8 +169,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMFLT, op1.value + op2.value); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_ADD); - debugger; - console.log(`TM_ADD: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -187,8 +185,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMFLT, op1.value - op2.value); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_SUB); - debugger; - console.log(`TM_SUB: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -205,8 +201,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMFLT, k[i.B].value * op2.value); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_MUL); - debugger; - console.log(`TM_MUL: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -223,8 +217,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMFLT, k[i.B].value % op2.value); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_MOD); - debugger; - console.log(`TM_MOD: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -239,8 +231,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMFLT, Math.pow(op1.value, op2.value)); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_POW); - debugger; - console.log(`TM_POW: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -255,8 +245,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMFLT, k[i.B].value / op2.value); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_DIV); - debugger; - console.log(`TM_DIV: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -273,8 +261,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMFLT, (op1.value / op2.value)|0); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_IDIV); - debugger; - console.log(`TM_IDIV: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -289,8 +275,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value & op2.value)|0); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_BAND); - debugger; - console.log(`TM_BAND: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -305,8 +289,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value | op2.value)|0); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_BOR); - debugger; - console.log(`TM_BOR: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -321,8 +303,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value ^ op2.value)|0); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_BXOR); - debugger; - console.log(`TM_BXOR: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -337,8 +317,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value << op2.value)|0); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_SHL); - debugger; - console.log(`TM_SHL: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; @@ -353,8 +331,6 @@ const luaV_execute = function(L) { L.stack[ra] = new TValue(CT.LUA_TNUMINT, (op1.value >> op2.value)|0); } else { ltm.luaT_trybinTM(L, op1, op2, ra, TMS.TM_SHR); - debugger; - console.log(`TM_SHR: ${L.stack[ra].value} (${ra})`); base = ci.u.l.base; } break; diff --git a/tests/ltm.js b/tests/ltm.js index cacb20b..4aec5d9 100644 --- a/tests/ltm.js +++ b/tests/ltm.js @@ -5,6 +5,7 @@ const test = require('tape'); const beautify = require('js-beautify').js_beautify; const VM = require("../src/lvm.js"); +const ldo = require("../src/ldo.js"); const OC = require('../src/lopcodes.js'); const getState = require("./tests.js").getState; @@ -22,7 +23,7 @@ test('__index, __newindex: with actual table', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -54,7 +55,7 @@ test('__index: with non table', function (t) { }, "Bytecode parsed without errors"); t.throws(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed with expected error"); }); @@ -74,7 +75,7 @@ test('__newindex: with non table', function (t) { }, "Bytecode parsed without errors"); t.throws(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed with expected error"); }); @@ -129,7 +130,7 @@ test('__index function in metatable', function (t) { L.stack[0].p.code[4].breakpoint = true; t.doesNotThrow(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "First part of the program executed without errors"); t.strictEqual( @@ -220,7 +221,7 @@ test('__newindex function in metatable', function (t) { L.stack[0].p.code[4].breakpoint = true; t.doesNotThrow(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "First part of the program executed without errors"); t.strictEqual( @@ -305,7 +306,7 @@ test('__index table in metatable', function (t) { L.stack[0].p.code[5].breakpoint = true; t.doesNotThrow(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "First part of the program executed without errors"); t.strictEqual( @@ -394,7 +395,7 @@ test('__newindex table in metatable', function (t) { L.stack[0].p.code[5].breakpoint = true; t.doesNotThrow(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "First part of the program executed without errors"); t.strictEqual( @@ -499,7 +500,7 @@ test('__index table with own metatable', function (t) { L.stack[0].p.code[8].breakpoint = true; t.doesNotThrow(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "First part of the program executed without errors"); L.ci.pcOff--; @@ -604,7 +605,7 @@ test('__newindex table with own metatable', function (t) { L.stack[0].p.code[8].breakpoint = true; t.doesNotThrow(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "First part of the program executed without errors"); L.ci.pcOff--; @@ -781,7 +782,7 @@ test('binary __xxx functions in metatable', function (t) { L.stack[0].p.code[26].breakpoint = true; t.doesNotThrow(function () { - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "First part of the program executed without errors"); L.ci.pcOff--; @@ -796,7 +797,20 @@ test('binary __xxx functions in metatable', function (t) { t.deepEqual( L.stack.slice(L.top - 12, L.top).map(function (e) { return e.value }), - ["{} + 1", "{} - 1", "{} * 1", "{} % 1", "{} ^ 1", "{} / 1", "{} // 1", "{} & 1", "{} | 1", "{} ~ 1", "{} << 1", "{} >> 1", ], + [ + "{} + 1", + "{} - 1", + "{} * 1", + "{} % 1", + "{} ^ 1", + "{} / 1", + "{} // 1", + "{} & 1", + "{} | 1", + "{} ~ 1", + "{} << 1", + "{} >> 1" + ], "Program output is correct" ); });
\ No newline at end of file diff --git a/tests/lvm.js b/tests/lvm.js index 40a20bc..ac62f20 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -6,6 +6,7 @@ const beautify = require('js-beautify').js_beautify; const lua_State = require("../src/lstate.js").lua_State; const VM = require("../src/lvm.js"); +const ldo = require("../src/ldo.js"); const Table = require("../src/lobject.js").Table;; const getState = require("./tests.js").getState; @@ -22,7 +23,7 @@ test('LOADK, RETURN', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -46,7 +47,7 @@ test('MOV', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -69,7 +70,7 @@ test('Binary op', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.deepEqual( @@ -93,7 +94,7 @@ test('Unary op, LOADBOOL', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.deepEqual( @@ -116,7 +117,7 @@ test('NEWTABLE', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.ok( @@ -143,7 +144,7 @@ test('CALL', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -175,7 +176,7 @@ test('Multiple return', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.deepEqual( @@ -201,7 +202,7 @@ test('TAILCALL', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -227,7 +228,7 @@ test('VARARG', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.deepEqual( @@ -251,7 +252,7 @@ test('LE, JMP', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -275,7 +276,7 @@ test('LT', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -299,7 +300,7 @@ test('EQ', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -324,7 +325,7 @@ test('TESTSET (and)', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -349,7 +350,7 @@ test('TESTSET (or)', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -378,7 +379,7 @@ test('TEST (true)', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -407,7 +408,7 @@ test('TEST (false)', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -435,7 +436,7 @@ test('FORPREP, FORLOOP (int)', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -462,7 +463,7 @@ test('FORPREP, FORLOOP (float)', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -489,7 +490,7 @@ test('SETTABLE, GETTABLE', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -525,7 +526,7 @@ test('SETUPVAL, GETUPVAL', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -552,7 +553,7 @@ test('SETTABUP, GETTABUP', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -587,7 +588,7 @@ test('SELF', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -611,7 +612,7 @@ test('SETLIST', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.deepEqual( @@ -639,7 +640,7 @@ test('Variable SETLIST', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.deepEqual( @@ -663,7 +664,7 @@ test('Long SETLIST', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.deepEqual( @@ -687,7 +688,7 @@ test('Long SETLIST', function (t) { // // // t.doesNotThrow(function () { // L = getState(luaCode); -// VM.luaV_execute(L); +// ldo.luaD_call(L, 0, -1); // // }, "Program executed without errors"); // // t.deepEqual( @@ -727,7 +728,7 @@ test('TFORCALL, TFORLOOP', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -753,7 +754,7 @@ test('LEN', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( @@ -787,7 +788,7 @@ test('CONCAT', function (t) { t.doesNotThrow(function () { L = getState(luaCode); - VM.luaV_execute(L); + ldo.luaD_call(L, 0, -1); }, "Program executed without errors"); t.strictEqual( |