From 214dcf73833f7a29c58eef2b85d68ee3277039f0 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 18 Jan 2018 04:29:58 +1100 Subject: src/: Start using lua_assert() instead of plain assert() --- src/lcode.js | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'src/lcode.js') diff --git a/src/lcode.js b/src/lcode.js index 8646144..88885b9 100644 --- a/src/lcode.js +++ b/src/lcode.js @@ -1,8 +1,7 @@ "use strict"; -const assert = require('assert'); - const defs = require('./defs.js'); +const { lua_assert } = require("./llimits.js"); const llex = require('./llex.js'); const lobject = require('./lobject.js'); const lopcodes = require('./lopcodes.js'); @@ -141,7 +140,7 @@ const getjump = function(fs, pc) { const fixjump = function(fs, pc, dest) { let jmp = fs.f.code[pc]; let offset = dest - (pc + 1); - assert(dest !== NO_JUMP); + lua_assert(dest !== NO_JUMP); if (Math.abs(offset) > lopcodes.MAXARG_sBx) llex.luaX_syntaxerror(fs.ls, defs.to_luastring("control structure too long", true)); lopcodes.SETARG_sBx(jmp, offset); @@ -299,7 +298,7 @@ const luaK_patchlist = function(fs, list, target) { if (target === fs.pc) /* 'target' is current position? */ luaK_patchtohere(fs, list); /* add list to pending jumps */ else { - assert(target < fs.pc); + lua_assert(target < fs.pc); patchlistaux(fs, list, target, lopcodes.NO_REG, target); } }; @@ -313,7 +312,7 @@ const luaK_patchclose = function(fs, list, level) { level++; /* argument is +1 to reserve 0 as non-op */ for (; list !== NO_JUMP; list = getjump(fs, list)) { let ins = fs.f.code[list]; - assert(ins.opcode === OpCodesI.OP_JMP && (ins.A === 0 || ins.A >= level)); + lua_assert(ins.opcode === OpCodesI.OP_JMP && (ins.A === 0 || ins.A >= level)); lopcodes.SETARG_A(ins, level); } }; @@ -336,10 +335,10 @@ const luaK_code = function(fs, i) { ** of parameters versus opcode.) */ const luaK_codeABC = function(fs, o, a, b, c) { - assert(lopcodes.getOpMode(o) === lopcodes.iABC); - assert(lopcodes.getBMode(o) !== lopcodes.OpArgN || b === 0); - assert(lopcodes.getCMode(o) !== lopcodes.OpArgN || c === 0); - assert(a <= lopcodes.MAXARG_A && b <= lopcodes.MAXARG_B && c <= lopcodes.MAXARG_C); + lua_assert(lopcodes.getOpMode(o) === lopcodes.iABC); + lua_assert(lopcodes.getBMode(o) !== lopcodes.OpArgN || b === 0); + lua_assert(lopcodes.getCMode(o) !== lopcodes.OpArgN || c === 0); + lua_assert(a <= lopcodes.MAXARG_A && b <= lopcodes.MAXARG_B && c <= lopcodes.MAXARG_C); return luaK_code(fs, lopcodes.CREATE_ABC(o, a, b, c)); }; @@ -347,9 +346,9 @@ const luaK_codeABC = function(fs, o, a, b, c) { ** Format and emit an 'iABx' instruction. */ const luaK_codeABx = function(fs, o, a, bc) { - assert(lopcodes.getOpMode(o) === lopcodes.iABx || lopcodes.getOpMode(o) === lopcodes.iAsBx); - assert(lopcodes.getCMode(o) === lopcodes.OpArgN); - assert(a <= lopcodes.MAXARG_A && bc <= lopcodes.MAXARG_Bx); + lua_assert(lopcodes.getOpMode(o) === lopcodes.iABx || lopcodes.getOpMode(o) === lopcodes.iAsBx); + lua_assert(lopcodes.getCMode(o) === lopcodes.OpArgN); + lua_assert(a <= lopcodes.MAXARG_A && bc <= lopcodes.MAXARG_Bx); return luaK_code(fs, lopcodes.CREATE_ABx(o, a, bc)); }; @@ -361,7 +360,7 @@ const luaK_codeAsBx = function(fs,o,A,sBx) { ** Emit an "extra argument" instruction (format 'iAx') */ const codeextraarg = function(fs, a) { - assert(a <= lopcodes.MAXARG_Ax); + lua_assert(a <= lopcodes.MAXARG_Ax); return luaK_code(fs, lopcodes.CREATE_Ax(OpCodesI.OP_EXTRAARG, a)); }; @@ -408,7 +407,7 @@ const luaK_reserveregs = function(fs, n) { const freereg = function(fs, reg) { if (!lopcodes.ISK(reg) && reg >= fs.nactvar) { fs.freereg--; - assert(reg === fs.freereg); + lua_assert(reg === fs.freereg); } }; @@ -526,7 +525,7 @@ const luaK_setreturns = function(fs, e, nresults) { lopcodes.SETARG_A(pc, fs.freereg); luaK_reserveregs(fs, 1); } - else assert(nresults === defs.LUA_MULTRET); + else lua_assert(nresults === defs.LUA_MULTRET); }; const luaK_setmultret = function(fs, e) { @@ -547,7 +546,7 @@ const luaK_setoneret = function(fs, e) { let ek = lparser.expkind; if (e.k === ek.VCALL) { /* expression is an open function call? */ /* already returns 1 value */ - assert(getinstruction(fs, e).C === 2); + lua_assert(getinstruction(fs, e).C === 2); e.k = ek.VNONRELOC; /* result has fixed position */ e.u.info = getinstruction(fs, e).A; } else if (e.k === ek.VVARARG) { @@ -579,7 +578,7 @@ const luaK_dischargevars = function(fs, e) { freereg(fs, e.u.ind.t); op = OpCodesI.OP_GETTABLE; } else { - assert(e.u.ind.vt === ek.VUPVAL); + lua_assert(e.u.ind.vt === ek.VUPVAL); op = OpCodesI.OP_GETTABUP; /* 't' is in an upvalue */ } e.u.info = luaK_codeABC(fs, op, 0, e.u.ind.t, e.u.ind.idx); @@ -638,7 +637,7 @@ const discharge2reg = function(fs, e, reg) { break; } default: { - assert(e.k === ek.VJMP); + lua_assert(e.k === ek.VJMP); return; /* nothing to do... */ } } @@ -825,7 +824,7 @@ const luaK_self = function(fs, e, key) { */ const negatecondition = function(fs, e) { let pc = getjumpcontrol(fs, e.u.info); - assert(lopcodes.testTMode(pc.opcode) && pc.opcode !== OpCodesI.OP_TESTSET && pc.opcode !== OpCodesI.OP_TEST); + lua_assert(lopcodes.testTMode(pc.opcode) && pc.opcode !== OpCodesI.OP_TESTSET && pc.opcode !== OpCodesI.OP_TEST); lopcodes.SETARG_A(pc, !(pc.A)); }; @@ -942,7 +941,7 @@ const codenot = function(fs, e) { */ const luaK_indexed = function(fs, t, k) { let ek = lparser.expkind; - assert(!hasjumps(t) && (lparser.vkisinreg(t.k) || t.k === ek.VUPVAL)); + lua_assert(!hasjumps(t) && (lparser.vkisinreg(t.k) || t.k === ek.VUPVAL)); t.u.ind.t = t.u.info; /* register or upvalue index */ t.u.ind.idx = luaK_exp2RK(fs, k); /* R/K index for key */ t.u.ind.vt = (t.k === ek.VUPVAL) ? ek.VUPVAL : ek.VLOCAL; @@ -1034,7 +1033,7 @@ const codecomp = function(fs, opr, e1, e2) { if (e1.k === ek.VK) rk1 = lopcodes.RKASK(e1.u.info); else { - assert(e1.k === ek.VNONRELOC); + lua_assert(e1.k === ek.VNONRELOC); rk1 = e1.u.info; } @@ -1126,14 +1125,14 @@ const luaK_posfix = function(fs, op, e1, e2, line) { let ek = lparser.expkind; switch (op) { case BinOpr.OPR_AND: { - assert(e1.t === NO_JUMP); /* list closed by 'luK_infix' */ + lua_assert(e1.t === NO_JUMP); /* list closed by 'luK_infix' */ luaK_dischargevars(fs, e2); e2.f = luaK_concat(fs, e2.f, e1.f); e1.to(e2); break; } case BinOpr.OPR_OR: { - assert(e1.f === NO_JUMP); /* list closed by 'luK_infix' */ + lua_assert(e1.f === NO_JUMP); /* list closed by 'luK_infix' */ luaK_dischargevars(fs, e2); e2.t = luaK_concat(fs, e2.t, e1.t); e1.to(e2); @@ -1143,7 +1142,7 @@ const luaK_posfix = function(fs, op, e1, e2, line) { luaK_exp2val(fs, e2); let ins = getinstruction(fs, e2); if (e2.k === ek.VRELOCABLE && ins.opcode === OpCodesI.OP_CONCAT) { - assert(e1.u.info === ins.B - 1); + lua_assert(e1.u.info === ins.B - 1); freeexp(fs, e1); lopcodes.SETARG_B(ins, e1.u.info); e1.k = ek.VRELOCABLE; e1.u.info = e2.u.info; @@ -1189,7 +1188,7 @@ const luaK_fixline = function(fs, line) { const luaK_setlist = function(fs, base, nelems, tostore) { let c = (nelems - 1)/lopcodes.LFIELDS_PER_FLUSH + 1; let b = (tostore === defs.LUA_MULTRET) ? 0 : tostore; - assert(tostore !== 0 && tostore <= lopcodes.LFIELDS_PER_FLUSH); + lua_assert(tostore !== 0 && tostore <= lopcodes.LFIELDS_PER_FLUSH); if (c <= lopcodes.MAXARG_C) luaK_codeABC(fs, OpCodesI.OP_SETLIST, base, b, c); else if (c <= lopcodes.MAXARG_Ax) { -- cgit v1.2.3-54-g00ecf