aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js56
-rw-r--r--src/lbaselib.js2
-rw-r--r--src/lcode.js40
-rw-r--r--src/ldebug.js68
-rw-r--r--src/ldo.js50
-rw-r--r--src/ldump.js10
-rw-r--r--src/llex.js50
-rw-r--r--src/lobject.js92
-rw-r--r--src/lparser.js72
-rw-r--r--src/lstate.js22
-rw-r--r--src/ltable.js4
-rw-r--r--src/ltm.js60
-rw-r--r--src/lundump.js32
-rw-r--r--src/lvm.js30
14 files changed, 294 insertions, 294 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 51b869f..ac13f87 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -2,6 +2,7 @@
const assert = require('assert');
+const defs = require('./defs.js');
const ldebug = require('./ldebug.js');
const ldo = require('./ldo.js');
const ldump = require('./ldump.js');
@@ -10,14 +11,13 @@ const llex = require('./llex.js');
const lobject = require('./lobject.js');
const lstate = require('./lstate.js');
const ltm = require('./ltm.js');
-const lua = require('./lua.js');
const luaconf = require('./luaconf.js');
const lundump = require('./lundump.js');
const lvm = require('./lvm.js');
const ltable = require('./ltable.js');
const MAXUPVAL = lfunc.MAXUPVAL;
-const CT = lua.constant_types;
-const TS = lua.thread_status;
+const CT = defs.constant_types;
+const TS = defs.thread_status;
const TValue = lobject.TValue;
const CClosure = lobject.CClosure;
@@ -26,7 +26,7 @@ const isvalid = function(o) {
};
const lua_version = function(L) {
- if (L === null) return lua.LUA_VERSION_NUM;
+ if (L === null) return defs.LUA_VERSION_NUM;
else return L.l_G.version;
};
@@ -44,13 +44,13 @@ const index2addr = function(L, idx) {
assert(idx <= ci.top - (ci.funcOff + 1), "unacceptable index");
if (o >= L.top) return lobject.luaO_nilobject;
else return L.stack[o];
- } else if (idx > lua.LUA_REGISTRYINDEX) {
+ } else if (idx > defs.LUA_REGISTRYINDEX) {
assert(idx !== 0 && -idx <= L.top, "invalid index");
return L.stack[L.top + idx];
- } else if (idx === lua.LUA_REGISTRYINDEX) {
+ } else if (idx === defs.LUA_REGISTRYINDEX) {
return L.l_G.l_registry;
} else { /* upvalues */
- idx = lua.LUA_REGISTRYINDEX - idx;
+ idx = defs.LUA_REGISTRYINDEX - idx;
assert(idx <= MAXUPVAL + 1, "upvalue index too large");
if (ci.func.ttislcf()) /* light C function? */
return lobject.luaO_nilobject; /* it has no upvalues */
@@ -68,13 +68,13 @@ const index2addr_ = function(L, idx) {
assert(idx <= ci.top - (ci.funcOff + 1), "unacceptable index");
if (o >= L.top) return null;
else return o;
- } else if (idx > lua.LUA_REGISTRYINDEX) {
+ } else if (idx > defs.LUA_REGISTRYINDEX) {
assert(idx !== 0 && -idx <= L.top, "invalid index");
return L.top + idx;
- } else if (idx === lua.LUA_REGISTRYINDEX) {
+ } else if (idx === defs.LUA_REGISTRYINDEX) {
return null;
} else { /* upvalues */
- idx = lua.LUA_REGISTRYINDEX - idx;
+ idx = defs.LUA_REGISTRYINDEX - idx;
assert(idx <= MAXUPVAL + 1, "upvalue index too large");
if (ci.func.ttislcf()) /* light C function? */
return null; /* it has no upvalues */
@@ -109,7 +109,7 @@ const lua_xmove = function(from, to, n) {
** convert an acceptable stack index into an absolute index
*/
const lua_absindex = function(L, idx) {
- return (idx > 0 || idx <= lua.LUA_REGISTRYINDEX)
+ return (idx > 0 || idx <= defs.LUA_REGISTRYINDEX)
? idx
: (L.top - L.ci.funcOff) + idx;
};
@@ -163,7 +163,7 @@ const lua_rotate = function(L, idx, n) {
let p = index2addr(L, idx);
let pIdx = index2addr_(L, idx);
- assert(p !== lobject.luaO_nilobject && idx > lua.LUA_REGISTRYINDEX, "index not in the stack");
+ assert(p !== lobject.luaO_nilobject && idx > defs.LUA_REGISTRYINDEX, "index not in the stack");
assert((n >= 0 ? n : -n) <= (L.top - idx), "invalid 'n'");
let m = n >= 0 ? L.top - 1 - n : pIdx - n - 1; /* end of prefix */
@@ -222,7 +222,7 @@ const lua_pushlstring = function(L, s, len) {
assert(Array.isArray(s), "lua_pushlstring expects array of byte");
assert(typeof len === "number");
- let ts = len === 0 ? L.l_G.intern(lua.to_luastring("", true)) : new TValue(CT.LUA_TLNGSTR, s.slice(0, len));
+ let ts = len === 0 ? L.l_G.intern(defs.to_luastring("", true)) : new TValue(CT.LUA_TLNGSTR, s.slice(0, len));
L.stack[L.top++] = ts;
assert(L.top <= L.ci.top, "stack overflow");
@@ -251,7 +251,7 @@ const lua_pushliteral = function (L, s) {
if (s === undefined || s === null)
L.stack[L.top] = new TValue(CT.LUA_TNIL, null);
else {
- let ts = L.l_G.intern(lua.to_luastring(s));
+ let ts = L.l_G.intern(defs.to_luastring(s));
L.stack[L.top] = ts;
}
@@ -319,7 +319,7 @@ const lua_pushthread = function(L) {
};
const lua_pushglobaltable = function(L) {
- lua_rawgeti(L, lua.LUA_REGISTRYINDEX, lua.LUA_RIDX_GLOBALS);
+ lua_rawgeti(L, defs.LUA_REGISTRYINDEX, defs.LUA_RIDX_GLOBALS);
};
/*
@@ -347,7 +347,7 @@ const auxsetstr = function(L, t, k) {
};
const lua_setglobal = function(L, name) {
- auxsetstr(L, L.l_G.l_registry.value.get(lua.LUA_RIDX_GLOBALS), name);
+ auxsetstr(L, L.l_G.l_registry.value.get(defs.LUA_RIDX_GLOBALS), name);
};
const lua_setmetatable = function(L, objindex) {
@@ -597,7 +597,7 @@ const lua_geti = function(L, idx, n) {
};
const lua_getglobal = function(L, name) {
- return auxgetstr(L, L.l_G.l_registry.value.get(lua.LUA_RIDX_GLOBALS), name);
+ return auxgetstr(L, L.l_G.l_registry.value.get(defs.LUA_RIDX_GLOBALS), name);
};
/*
@@ -615,7 +615,7 @@ const lua_tolstring = function(L, idx) {
if ((!o.ttisstring() && !o.ttisnumber()))
return null;
- return o.ttisstring() ? o.value : lua.to_luastring(`${o.value}`);
+ return o.ttisstring() ? o.value : defs.to_luastring(`${o.value}`);
};
const lua_tostring = lua_tolstring;
@@ -710,9 +710,9 @@ const lua_compare_ = function(L, o1, o2, op) {
if (isvalid(o1) && isvalid(o2)) {
switch (op) {
- case lua.LUA_OPEQ: i = lvm.luaV_equalobj(L, o1, o2); break;
- case lua.LUA_OPLT: i = lvm.luaV_lessthan(L, o1, o2); break;
- case lua.LUA_OPLE: i = lvm.luaV_lessequal(L, o1, o2); break;
+ case defs.LUA_OPEQ: i = lvm.luaV_equalobj(L, o1, o2); break;
+ case defs.LUA_OPLT: i = lvm.luaV_lessthan(L, o1, o2); break;
+ case defs.LUA_OPLE: i = lvm.luaV_lessequal(L, o1, o2); break;
default: assert(false, "invalid option");
}
}
@@ -805,14 +805,14 @@ const lua_load = function(L, reader, data, chunckname, mode) {
assert(Array.isArray(chunckname), "lua_load expect an array of byte as chunckname");
assert(mode ? Array.isArray(mode) : true, "lua_load expect an array of byte as mode");
let z = new llex.MBuffer(L, data, reader);
- if (!chunckname) chunckname = [lua.char["?"]];
+ if (!chunckname) chunckname = [defs.char["?"]];
let status = ldo.luaD_protectedparser(L, z, chunckname, mode);
if (status === TS.LUA_OK) { /* no errors? */
let f = L.stack[L.top - 1]; /* get newly created function */
if (f.nupvalues >= 1) { /* does it have an upvalue? */
/* get global table from registry */
let reg = L.l_G.l_registry;
- let gt = reg.value.get(lua.LUA_RIDX_GLOBALS);
+ let gt = reg.value.get(defs.LUA_RIDX_GLOBALS);
/* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
f.upvals[0].u.value = new TValue(gt.type, gt.value);
}
@@ -846,7 +846,7 @@ const lua_callk = function(L, nargs, nresults, ctx, k) {
assert(k === null || !(L.ci.callstatus & lstate.CIST_LUA), "cannot use continuations inside hooks");
assert(nargs + 1 < L.top - L.ci.funcOff, "not enough elements in the stack");
assert(L.status === TS.LUA_OK, "cannot do calls on non-normal thread");
- assert(nargs === lua.LUA_MULTRET || (L.ci.top - L.top >= nargs - nresults, "results from function overflow current stack size"));
+ assert(nargs === defs.LUA_MULTRET || (L.ci.top - L.top >= nargs - nresults, "results from function overflow current stack size"));
let func = L.top - (nargs + 1);
if (k !== null && L.nny === 0) { /* need to prepare continuation? */
@@ -857,7 +857,7 @@ const lua_callk = function(L, nargs, nresults, ctx, k) {
ldo.luaD_callnoyield(L, func, nresults);
}
- if (nresults === lua.LUA_MULTRET && L.ci.top < L.top)
+ if (nresults === defs.LUA_MULTRET && L.ci.top < L.top)
L.ci.top = L.top;
};
@@ -868,7 +868,7 @@ const lua_call = function(L, n, r) {
const lua_pcallk = function(L, nargs, nresults, errfunc, ctx, k) {
assert(nargs + 1 < L.top - L.ci.funcOff, "not enough elements in the stack");
assert(L.status === TS.LUA_OK, "cannot do calls on non-normal thread");
- assert(nargs === lua.LUA_MULTRET || (L.ci.top - L.top >= nargs - nresults, "results from function overflow current stack size"));
+ assert(nargs === defs.LUA_MULTRET || (L.ci.top - L.top >= nargs - nresults, "results from function overflow current stack size"));
let c = {
func: null,
@@ -908,7 +908,7 @@ const lua_pcallk = function(L, nargs, nresults, errfunc, ctx, k) {
status = TS.LUA_OK;
}
- if (nresults === lua.LUA_MULTRET && L.ci.top < L.top)
+ if (nresults === defs.LUA_MULTRET && L.ci.top < L.top)
L.ci.top = L.top;
return status;
@@ -945,7 +945,7 @@ const lua_concat = function(L, n) {
if (n >= 2)
lvm.luaV_concat(L, n);
else if (n === 0) {
- L.stack[L.top++] = L.l_G.intern(lua.to_luastring("", true));
+ L.stack[L.top++] = L.l_G.intern(defs.to_luastring("", true));
assert(L.top <= L.ci.top, "stack overflow");
}
};
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 57173b6..02b9fc6 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -369,7 +369,7 @@ if (typeof require === "function") {
base_funcs.loadfile = luaB_loadfile;
base_funcs.dofile = luaB_dofile;
}
-
+
}
const luaopen_base = function(L) {
diff --git a/src/lcode.js b/src/lcode.js
index 2f95baa..cae07e1 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -2,24 +2,24 @@
const assert = require('assert');
+const defs = require('./defs.js');
const llex = require('./llex.js');
const llimit = require('./llimit.js');
const lobject = require('./lobject.js');
const lopcode = require('./lopcodes.js');
const lparser = require('./lparser.js');
const ltm = require('./ltm.js');
-const lua = require('./lua.js');
const lvm = require('./lvm.js');
-const CT = lua.CT;
+const CT = defs.CT;
const OpCodes = lopcode.OpCodes;
const OpCodesI = lopcode.OpCodesI;
const TValue = lobject.TValue;
const luaO_arith = function(L, op, p1, p2, res) {
switch (op) {
- case lua.LUA_OPBAND: case lua.LUA_OPBOR: case lua.LUA_OPBXOR:
- case lua.LUA_OPSHL: case lua.LUA_OPSHR:
- case lua.LUA_OPBNOT: { /* operate only on integers */
+ case defs.LUA_OPBAND: case defs.LUA_OPBOR: case defs.LUA_OPBXOR:
+ case defs.LUA_OPSHL: case defs.LUA_OPSHR:
+ case defs.LUA_OPBNOT: { /* operate only on integers */
let i1 = lvm.tointeger(p1);
let i2 = lvm.tointeger(p2);
if (i1 !== false && i2 !== false) {
@@ -29,7 +29,7 @@ const luaO_arith = function(L, op, p1, p2, res) {
}
else break; /* go to the end */
}
- case lua.LUA_OPDIV: case lua.LUA_OPPOW: { /* operate only on floats */
+ case defs.LUA_OPDIV: case defs.LUA_OPPOW: { /* operate only on floats */
let n1 = lvm.tonumber(p1);
let n2 = lvm.tonumber(p2);
if (n1 !== false && n2 !== false) {
@@ -57,7 +57,7 @@ const luaO_arith = function(L, op, p1, p2, res) {
}
/* could not perform raw operation; try metamethod */
assert(L !== null); /* should not fail when folding (compile time) */
- ltm.luaT_trybinTM(L, p1, p2, res, (op - lua.LUA_OPADD) + ltm.TMS.TM_ADD);
+ ltm.luaT_trybinTM(L, p1, p2, res, (op - defs.LUA_OPADD) + ltm.TMS.TM_ADD);
};
/* Maximum number of registers in a Lua function (must fit in 8 bits) */
@@ -183,7 +183,7 @@ const fixjump = function(fs, pc, dest) {
let offset = dest - (pc + 1);
assert(dest !== NO_JUMP);
if (Math.abs(offset) > lopcode.MAXARG_sBx)
- llex.luaX_syntaxerror(fs.ls, lua.to_luastring("control structure too long", true));
+ llex.luaX_syntaxerror(fs.ls, defs.to_luastring("control structure too long", true));
lopcode.SETARG_sBx(jmp, offset);
};
@@ -424,7 +424,7 @@ const luaK_checkstack = function(fs, n) {
let newstack = fs.freereg + n;
if (newstack > fs.f.maxstacksize) {
if (newstack >= MAXREGS)
- llex.luaX_syntaxerror(fs.ls, lua.to_luastring("function or expression needs to many registers", true));
+ llex.luaX_syntaxerror(fs.ls, defs.to_luastring("function or expression needs to many registers", true));
fs.f.maxstacksize = newstack;
}
};
@@ -512,7 +512,7 @@ const luaK_stringK = function(fs, s) {
** are no "precision" problems.
*/
const luaK_intK = function(fs, n) {
- let k = new TValue(CT.LUA_TLNGSTR, lua.to_luastring(`${n}`));
+ let k = new TValue(CT.LUA_TLNGSTR, defs.to_luastring(`${n}`));
let o = new TValue(CT.LUA_TNUMINT, n);
return addk(fs, k, o);
};
@@ -539,7 +539,7 @@ const boolK = function(fs, b) {
** Add nil to list of constants and return its index.
*/
const nilK = function(fs) {
- return addk(fs, new TValue(CT.LUA_TLNGSTR, lua.to_luastring(`null`)), new TValue(CT.LUA_TNIL, null));
+ return addk(fs, new TValue(CT.LUA_TLNGSTR, defs.to_luastring(`null`)), new TValue(CT.LUA_TNIL, null));
};
/*
@@ -558,11 +558,11 @@ const luaK_setreturns = function(fs, e, nresults) {
lopcode.SETARG_A(pc, fs.freereg);
luaK_reserveregs(fs, 1);
}
- else assert(nresults === lua.LUA_MULTRET);
+ else assert(nresults === defs.LUA_MULTRET);
};
const luaK_setmultret = function(fs, e) {
- luaK_setreturns(fs, e, lua.LUA_MULTRET);
+ luaK_setreturns(fs, e, defs.LUA_MULTRET);
};
/*
@@ -988,11 +988,11 @@ const luaK_indexed = function(fs, t, k) {
*/
const validop = function(op, v1, v2) {
switch (op) {
- case lua.LUA_OPBAND: case lua.LUA_OPBOR: case lua.LUA_OPBXOR:
- case lua.LUA_OPSHL: case lua.LUA_OPSHR: case lua.LUA_OPBNOT: { /* conversion errors */
+ case defs.LUA_OPBAND: case defs.LUA_OPBOR: case defs.LUA_OPBXOR:
+ case defs.LUA_OPSHL: case defs.LUA_OPSHR: case defs.LUA_OPBNOT: { /* conversion errors */
return (lvm.tointeger(v1) && lvm.tointeger(v2));
}
- case lua.LUA_OPDIV: case lua.LUA_OPIDIV: case lua.LUA_OPMOD: /* division by 0 */
+ case defs.LUA_OPDIV: case defs.LUA_OPIDIV: case defs.LUA_OPMOD: /* division by 0 */
return (v2.value !== 0);
default: return 1; /* everything else is valid */
}
@@ -1104,7 +1104,7 @@ const luaK_prefix = function(fs, op, e, line) {
ef.f = NO_JUMP;
switch (op) {
case UnOpr.OPR_MINUS: case UnOpr.OPR_BNOT: /* use 'ef' as fake 2nd operand */
- if (constfolding(fs, op + lua.LUA_OPUNM, e, ef))
+ if (constfolding(fs, op + defs.LUA_OPUNM, e, ef))
break;
/* FALLTHROUGH */
case UnOpr.OPR_LEN:
@@ -1191,7 +1191,7 @@ const luaK_posfix = function(fs, op, e1, e2, line) {
case BinOpr.OPR_IDIV: case BinOpr.OPR_MOD: case BinOpr.OPR_POW:
case BinOpr.OPR_BAND: case BinOpr.OPR_BOR: case BinOpr.OPR_BXOR:
case BinOpr.OPR_SHL: case BinOpr.OPR_SHR: {
- if (!constfolding(fs, op + lua.LUA_OPADD, e1, e2))
+ if (!constfolding(fs, op + defs.LUA_OPADD, e1, e2))
codebinexpval(fs, op + OpCodesI.OP_ADD, e1, e2, line);
break;
}
@@ -1221,7 +1221,7 @@ const luaK_fixline = function(fs, line) {
*/
const luaK_setlist = function(fs, base, nelems, tostore) {
let c = (nelems - 1)/lopcode.LFIELDS_PER_FLUSH + 1;
- let b = (tostore === lua.LUA_MULTRET) ? 0 : tostore;
+ let b = (tostore === defs.LUA_MULTRET) ? 0 : tostore;
assert(tostore !== 0 && tostore <= lopcode.LFIELDS_PER_FLUSH);
if (c <= lopcode.MAXARG_C)
luaK_codeABC(fs, OpCodesI.OP_SETLIST, base, b, c);
@@ -1230,7 +1230,7 @@ const luaK_setlist = function(fs, base, nelems, tostore) {
codeextraarg(fs, c);
}
else
- llex.luaX_syntaxerror(fs.ls, lua.to_luastring("constructor too long", true));
+ llex.luaX_syntaxerror(fs.ls, defs.to_luastring("constructor too long", true));
fs.freereg = base + 1; /* free registers with list values */
};
diff --git a/src/ldebug.js b/src/ldebug.js
index 34071a1..7add30f 100644
--- a/src/ldebug.js
+++ b/src/ldebug.js
@@ -3,7 +3,7 @@
const assert = require('assert');
-const lua = require('./lua.js');
+const defs = require('./defs.js');
const ldo = require('./ldo.js');
const lobject = require('./lobject.js');
const lstate = require('./lstate.js');
@@ -14,8 +14,8 @@ const ltm = require('./ltm.js');
const lfunc = require('./lfunc.js');
const lapi = require('./lapi.js');
const TValue = lobject.TValue;
-const CT = lua.constant_types;
-const TS = lua.thread_status;
+const CT = defs.constant_types;
+const TS = defs.thread_status;
const currentline = function(ci) {
return ci.func.p.lineinfo ? ci.func.p.lineinfo[ci.pcOff] : -1;
@@ -93,7 +93,7 @@ const findvararg = function(ci, n, pos) {
else {
return {
pos: ci.funcOff + nparams + n,
- name: lua.to_luastring("(*vararg)", true) /* generic name for any vararg */
+ name: defs.to_luastring("(*vararg)", true) /* generic name for any vararg */
};
}
};
@@ -114,7 +114,7 @@ const findlocal = function(L, ci, n) {
if (name === null) { /* no 'standard' name? */
let limit = ci === L.ci ? L.top : ci.next.func;
if (limit - base >= n && n > 0) /* is 'n' inside 'ci' stack? */
- name = lua.to_luastring("(*temporary)", true); /* generic name for any valid slot */
+ name = defs.to_luastring("(*temporary)", true); /* generic name for any valid slot */
else
return null; /* no name */
}
@@ -159,16 +159,16 @@ const lua_setlocal = function(L, ar, n) {
const funcinfo = function(ar, cl) {
if (cl === null || cl.type === CT.LUA_TCCL) {
- ar.source = lua.to_luastring("=[JS]", true);
+ ar.source = defs.to_luastring("=[JS]", true);
ar.linedefined = -1;
ar.lastlinedefined = -1;
ar.what = "J";
} else {
let p = cl.p;
- ar.source = p.source ? p.source : lua.to_luastring("=?", true);
+ ar.source = p.source ? p.source : defs.to_luastring("=?", true);
ar.linedefined = p.linedefined;
ar.lastlinedefined = p.lastlinedefined;
- ar.what = ar.linedefined === 0 ? lua.to_luastring("main", true) : lua.to_luastring("Lua", true);
+ ar.what = ar.linedefined === 0 ? defs.to_luastring("main", true) : defs.to_luastring("Lua", true);
}
ar.short_src = lobject.luaO_chunkid(ar.source, luaconf.LUA_IDSIZE);
@@ -197,8 +197,8 @@ const getfuncname = function(L, ci) {
if (ci === null)
return null;
else if (ci.callstatus & lstate.CIST_FIN) { /* is this a finalizer? */
- r.name = lua.to_luastring("__gc", true);
- r.funcname = lua.to_luastring("metamethod", true); /* report it as such */
+ r.name = defs.to_luastring("__gc", true);
+ r.funcname = defs.to_luastring("metamethod", true); /* report it as such */
return r;
}
/* calling function is a known Lua function? */
@@ -306,7 +306,7 @@ const kname = function(p, pc, c) {
}
/* else no reasonable name found */
}
- r.name = [lua.char["?"]];
+ r.name = [defs.char["?"]];
return r; /* no reasonable name found */
};
@@ -372,7 +372,7 @@ const getobjname = function(p, lastpc, reg) {
};
if (r.name) { /* is a local? */
- r.funcname = lua.to_luastring("local", true);
+ r.funcname = defs.to_luastring("local", true);
return r;
}
@@ -395,12 +395,12 @@ const getobjname = function(p, lastpc, reg) {
let vn = op === 'OP_GETTABLE' ? lfunc.luaF_getlocalname(p, t + 1, pc) : upvalname(p, t);
vn = vn ? vn.jsstring() : null;
r.name = kname(p, pc, k).name;
- r.funcname = vn && vn === "_ENV" ? lua.to_luastring("global", true) : lua.to_luastring("field", true);
+ r.funcname = vn && vn === "_ENV" ? defs.to_luastring("global", true) : defs.to_luastring("field", true);
return r;
}
case 'OP_GETUPVAL': {
r.name = upvalname(p, i.B);
- r.funcname = lua.to_luastring("upvalue", true);
+ r.funcname = defs.to_luastring("upvalue", true);
return r;
}
case 'OP_LOADK':
@@ -408,7 +408,7 @@ const getobjname = function(p, lastpc, reg) {
let b = op === 'OP_LOADK' ? i.Bx : p.code[pc + 1].Ax;
if (p.k[b].ttisstring()) {
r.name = p.k[b].value;
- r.funcname = lua.to_luastring("constant", true);
+ r.funcname = defs.to_luastring("constant", true);
return r;
}
break;
@@ -416,7 +416,7 @@ const getobjname = function(p, lastpc, reg) {
case 'OP_SELF': {
let k = i.C;
r.name = kname(p, pc, k).name;
- r.funcname = lua.to_luastring("method", true);
+ r.funcname = defs.to_luastring("method", true);
return r;
}
default: break;
@@ -444,8 +444,8 @@ const funcnamefromcode = function(L, ci) {
let i = p.code[pc]; /* calling instruction */
if (ci.callstatus & lstate.CIST_HOOKED) {
- r.name = [lua.char["?"]];
- r.funcname = lua.to_luastring("hook", true);
+ r.name = [defs.char["?"]];
+ r.funcname = defs.to_luastring("hook", true);
return r;
}
@@ -454,8 +454,8 @@ const funcnamefromcode = function(L, ci) {
case 'OP_TAILCALL':
return getobjname(p, pc, i.A); /* get function name */
case 'OP_TFORCALL':
- r.name = lua.to_luastring("for iterator", true);
- r.funcname = lua.to_luastring("for iterator", true);
+ r.name = defs.to_luastring("for iterator", true);
+ r.funcname = defs.to_luastring("for iterator", true);
return r;
/* other instructions can do calls through metamethods */
case 'OP_SELF':
@@ -491,7 +491,7 @@ const funcnamefromcode = function(L, ci) {
}
r.name = L.l_G.tmname[tm];
- r.funcname = lua.to_luastring("metamethod", true);
+ r.funcname = defs.to_luastring("metamethod", true);
return r;
};
@@ -515,7 +515,7 @@ const getupvalname = function(L, ci, o, name) {
if (c.upvals[i].val(L) === o) {
return {
name: upvalname(c.p, i),
- funcname: lua.to_luastring('upvalue', true)
+ funcname: defs.to_luastring('upvalue', true)
};
}
}
@@ -533,17 +533,17 @@ const varinfo = function(L, o) {
kind = getobjname(ci.func.p, ci.pcOff, stkid - ci.u.l.base);
}
- return lua.to_luastring(kind ? ` (${lobject.jsstring(kind.funcname)} '${lobject.jsstring(kind.name.value ? kind.name.value : kind.name)}')` : ``);
+ return defs.to_luastring(kind ? ` (${lobject.jsstring(kind.funcname)} '${lobject.jsstring(kind.name.value ? kind.name.value : kind.name)}')` : ``);
};
const luaG_typeerror = function(L, o, op) {
let t = ltm.luaT_objtypename(L, o);
- luaG_runerror(L, lua.to_luastring(`attempt to ${lobject.jsstring(op)} a ${lobject.jsstring(t)} value${lobject.jsstring(varinfo(L, o))}`));
+ luaG_runerror(L, defs.to_luastring(`attempt to ${lobject.jsstring(op)} a ${lobject.jsstring(t)} value${lobject.jsstring(varinfo(L, o))}`));
};
const luaG_concaterror = function(L, p1, p2) {
if (p1.ttisstring() || p1.ttisnumber()) p1 = p2;
- luaG_typeerror(L, p1, lua.to_luastring('concatenate', true));
+ luaG_typeerror(L, p1, defs.to_luastring('concatenate', true));
};
/*
@@ -560,9 +560,9 @@ const luaG_ordererror = function(L, p1, p2) {
let t1 = ltm.luaT_objtypename(L, p1);
let t2 = ltm.luaT_objtypename(L, p2);
if (t1.join() === t2.join())
- luaG_runerror(L, lua.to_luastring(`attempt to compare two ${lobject.jsstring(t1)} values`));
+ luaG_runerror(L, defs.to_luastring(`attempt to compare two ${lobject.jsstring(t1)} values`));
else
- luaG_runerror(L, lua.to_luastring(`attempt to compare ${lobject.jsstring(t1)} with ${lobject.jsstring(t2)}`));
+ luaG_runerror(L, defs.to_luastring(`attempt to compare ${lobject.jsstring(t1)} with ${lobject.jsstring(t2)}`));
};
/* add src:line information to 'msg' */
@@ -571,7 +571,7 @@ const luaG_addinfo = function(L, msg, src, line) {
if (src)
buff = lobject.luaO_chunkid(src, luaconf.LUA_IDSIZE);
- L.stack[L.top++] = L.l_G.intern(lua.to_luastring(`${lobject.jsstring(buff)}:${line}: ${lobject.jsstring(msg)}`));
+ L.stack[L.top++] = L.l_G.intern(defs.to_luastring(`${lobject.jsstring(buff)}:${line}: ${lobject.jsstring(msg)}`));
return L.stack[L.top - 1];
};
@@ -602,31 +602,31 @@ const luaG_tointerror = function(L, p1, p2) {
let temp = lvm.tointeger(p1);
if (temp === false)
p2 = p1;
- luaG_runerror(L, lua.to_luastring(`number${lobject.jsstring(varinfo(L, p2))} has no integer representation`));
+ luaG_runerror(L, defs.to_luastring(`number${lobject.jsstring(varinfo(L, p2))} has no integer representation`));
};
const luaG_traceexec = function(L) {
let ci = L.ci;
let mask = L.hookmask;
- let counthook = (--L.hookcount === 0 && (mask & lua.LUA_MASKCOUNT));
+ let counthook = (--L.hookcount === 0 && (mask & defs.LUA_MASKCOUNT));
if (counthook)
L.hookcount = L.basehookcount; /* reset count */
- else if (!(mask & lua.LUA_MASKLINE))
+ else if (!(mask & defs.LUA_MASKLINE))
return; /* no line hook and count != 0; nothing to be done */
if (ci.callstatus & lstate.CIST_HOOKYIELD) { /* called hook last time? */
ci.callstatus &= ~lstate.CIST_HOOKYIELD; /* erase mark */
return; /* do not call hook again (VM yielded, so it did not move) */
}
if (counthook)
- ldo.luaD_hook(L, lua.LUA_HOOKCOUNT, -1); /* call count hook */
- if (mask & lua.LUA_MASKLINE) {
+ ldo.luaD_hook(L, defs.LUA_HOOKCOUNT, -1); /* call count hook */
+ if (mask & defs.LUA_MASKLINE) {
let p = ci.func.p;
let npc = ci.pcOff; // pcRel(ci.u.l.savedpc, p);
let newline = p.lineinfo ? p.lineinfo[npc] : -1;
if (npc === 0 || /* call linehook when enter a new function, */
ci.pcOff <= L.oldpc || /* when jump back (loop), or when */
newline !== p.lineinfo ? p.lineinfo[L.oldpc] : -1) /* enter a new line */
- ldo.luaD_hook(L, lua.LUA_HOOKLINE, newline); /* call line hook */
+ ldo.luaD_hook(L, defs.LUA_HOOKLINE, newline); /* call line hook */
}
L.oldpc = ci.pcOff;
if (L.status === TS.LUA_YIELD) { /* did hook yield? */
diff --git a/src/ldo.js b/src/ldo.js
index 4105722..dccee08 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -3,6 +3,7 @@
const assert = require('assert');
+const defs = require('./defs.js');
const BytecodeParser = require('./lundump.js');
const lapi = require('./lapi.js');
const ldebug = require('./ldebug.js');
@@ -13,21 +14,20 @@ const lobject = require('./lobject.js');
const lparser = require('./lparser.js');
const lstate = require('./lstate.js');
const ltm = require('./ltm.js');
-const lua = require('./lua.js');
const lvm = require('./lvm.js');
-const CT = lua.constant_types;
-const TS = lua.thread_status;
-const LUA_MULTRET = lua.LUA_MULTRET;
+const CT = defs.constant_types;
+const TS = defs.thread_status;
+const LUA_MULTRET = defs.LUA_MULTRET;
const TValue = lobject.TValue;
const seterrorobj = function(L, errcode, oldtop) {
switch (errcode) {
case TS.LUA_ERRMEM: {
- L.stack[oldtop] = L.l_G.intern(lua.to_luastring("not enough memory", true));
+ L.stack[oldtop] = L.l_G.intern(defs.to_luastring("not enough memory", true));
break;
}
case TS.LUA_ERRERR: {
- L.stack[oldtop] = L.l_G.intern(lua.to_luastring("error in error handling", true));
+ L.stack[oldtop] = L.l_G.intern(defs.to_luastring("error in error handling", true));
break;
}
default: {
@@ -71,14 +71,14 @@ const luaD_precall = function(L, off, nresults) {
ci.nresults = nresults;
ci.func = func;
ci.funcOff = off;
- ci.top = L.top + lua.LUA_MINSTACK;
+ ci.top = L.top + defs.LUA_MINSTACK;
ci.callstatus = 0;
- if (L.hookmask & lua.LUA_MASKCALL)
- luaD_hook(L, lua.LUA_HOOKCALL, -1);
+ if (L.hookmask & defs.LUA_MASKCALL)
+ luaD_hook(L, defs.LUA_HOOKCALL, -1);
let n = f(L); /* do the actual call */
assert(n < L.top - L.ci.funcOff, "not enough elements in the stack");
-
+
luaD_poscall(L, ci, L.top - n, n);
return true;
@@ -131,9 +131,9 @@ const luaD_precall = function(L, off, nresults) {
const luaD_poscall = function(L, ci, firstResult, nres) {
let wanted = ci.nresults;
- if (L.hookmask & (lua.LUA_MASKRET | lua.LUA_MASKLINE)) {
- if (L.hookmask & lua.LUA_MASKRET)
- luaD_hook(L, lua.LUA_HOOKRET, -1);
+ if (L.hookmask & (defs.LUA_MASKRET | defs.LUA_MASKLINE)) {
+ if (L.hookmask & defs.LUA_MASKRET)
+ luaD_hook(L, defs.LUA_HOOKRET, -1);
L.oldpc = ci.previous.pcOff; /* 'oldpc' for caller function */
}
@@ -190,11 +190,11 @@ const luaD_hook = function(L, event, line) {
let ci = L.ci;
let top = L.top;
let ci_top = ci.top;
- let ar = new lua.lua_Debug();
+ let ar = new defs.lua_Debug();
ar.event = event;
ar.currentline = line;
ar.i_ci = ci;
- ci.top = L.top + lua.LUA_MINSTACK;
+ ci.top = L.top + defs.LUA_MINSTACK;
L.allowhook = 0; /* cannot call hooks inside a hook */
ci.callstatus |= lstate.CIST_HOOKED;
hook(L, ar);
@@ -227,12 +227,12 @@ const adjust_varargs = function(L, p, actual) {
const tryfuncTM = function(L, off, func) {
let tm = ltm.luaT_gettmbyobj(L, func, ltm.TMS.TM_CALL);
if (!tm.ttisfunction(tm))
- ldebug.luaG_typeerror(L, func, lua.to_luastring("call", true));
+ ldebug.luaG_typeerror(L, func, defs.to_luastring("call", true));
/* Open a hole inside the stack at 'func' */
for (let p = L.top; p > off; p--)
L.stack[p] = L.stack[p-1];
L.top++; /* slot ensured by caller */
- L.stack[off] = tm; /* tag method is the new function to be called */
+ L.stack[off] = tm; /* tag method is the new function to be called */
};
/*
@@ -392,7 +392,7 @@ const recover = function(L, status) {
*/
const resume_error = function(L, msg, narg) {
L.top -= narg; /* remove args from the stack */
- L.stack[L.top++] = L.l_G.intern(lua.to_luastring(msg)); /* push error message */
+ L.stack[L.top++] = L.l_G.intern(defs.to_luastring(msg)); /* push error message */
assert(L.top <= L.ci.top, "stack overflow");
return TS.LUA_ERRRUN;
};
@@ -408,7 +408,7 @@ const resume = function(L, n) {
let firstArg = L.top - n; /* first argument */
let ci = L.ci;
if (L.status === TS.LUA_OK) { /* starting a coroutine? */
- if (!luaD_precall(L, firstArg - 1, lua.LUA_MULTRET)) /* Lua function? */
+ if (!luaD_precall(L, firstArg - 1, defs.LUA_MULTRET)) /* Lua function? */
lvm.luaV_execute(L); /* call it */
} else { /* resuming from previous yield */
assert(L.status === TS.LUA_YIELD);
@@ -483,9 +483,9 @@ const lua_yieldk = function(L, nresults, ctx, k) {
if (L.nny > 0) {
if (L !== L.l_G.mainthread)
- ldebug.luaG_runerror(L, lua.to_luastring("attempt to yield across a JS-call boundary", true));
+ ldebug.luaG_runerror(L, defs.to_luastring("attempt to yield across a JS-call boundary", true));
else
- ldebug.luaG_runerror(L, lua.to_luastring("attempt to yield from outside a coroutine", true));
+ ldebug.luaG_runerror(L, defs.to_luastring("attempt to yield from outside a coroutine", true));
}
L.status = TS.LUA_YIELD;
@@ -555,7 +555,7 @@ class SParser {
const checkmode = function(L, mode, x) {
if (mode && mode.indexOf(x[0]) === -1) {
- lapi.lua_pushstring(L, lua.to_luastring(`attempt to load a ${lobject.jsstring(x)} chunk (mode is '${lobject.jsstring(mode)}')`));
+ lapi.lua_pushstring(L, defs.to_luastring(`attempt to load a ${lobject.jsstring(x)} chunk (mode is '${lobject.jsstring(mode)}')`));
luaD_throw(L, TS.LUA_ERRSYNTAX);
}
};
@@ -563,11 +563,11 @@ const checkmode = function(L, mode, x) {
const f_parser = function(L, p) {
let cl;
let c = p.z.getc(); /* read first character */
- if (c === lua.LUA_SIGNATURE.charCodeAt(0)) {
- checkmode(L, p.mode, lua.to_luastring("binary", true));
+ if (c === defs.LUA_SIGNATURE.charCodeAt(0)) {
+ checkmode(L, p.mode, defs.to_luastring("binary", true));
cl = new BytecodeParser(L, p.z.buffer, p.name).luaU_undump();
} else {
- checkmode(L, p.mode, lua.to_luastring("text", true));
+ checkmode(L, p.mode, defs.to_luastring("text", true));
cl = lparser.luaY_parser(L, p.z, p.buff, p.dyd, p.name, c);
}
diff --git a/src/ldump.js b/src/ldump.js
index e35d3be..00fab36 100644
--- a/src/ldump.js
+++ b/src/ldump.js
@@ -2,15 +2,15 @@
const assert = require('assert');
-const lua = require('./lua.js');
+const defs = require('./defs.js');
const lstate = require('./lstate.js');
const lobject = require('./lobject.js');
-const CT = lua.constant_types;
+const CT = defs.constant_types;
const LUAC_DATA = "\x19\x93\r\n\x1a\n";
const LUAC_INT = 0x5678;
const LUAC_NUM = 370.5;
-const LUAC_VERSION = Number.parseInt(lua.LUA_VERSION_MAJOR) * 16 + Number.parseInt(lua.LUA_VERSION_MINOR);
+const LUAC_VERSION = Number.parseInt(defs.LUA_VERSION_MAJOR) * 16 + Number.parseInt(defs.LUA_VERSION_MINOR);
const LUAC_FORMAT = 0; /* this is the official format */
class DumpState {
@@ -29,7 +29,7 @@ const DumpBlock = function(b, size, D) {
};
const DumpLiteral = function(s, D) {
- s = lua.to_luastring(s);
+ s = defs.to_luastring(s);
DumpBlock(s, s.length, D);
};
@@ -168,7 +168,7 @@ const DumpFunction = function(f, psource, D) {
};
const DumpHeader = function(D) {
- DumpLiteral(lua.LUA_SIGNATURE, D);
+ DumpLiteral(defs.LUA_SIGNATURE, D);
DumpByte(LUAC_VERSION, D);
DumpByte(LUAC_FORMAT, D);
let cdata = LUAC_DATA.split('').map(e => e.charCodeAt(0));
diff --git a/src/llex.js b/src/llex.js
index 0927fec..8d26389 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -2,18 +2,18 @@
const assert = require('assert');
+const defs = require('./defs.js');
const lapi = require('./lapi.js');
const lauxlib = require('./lauxlib.js');
const ldebug = require('./ldebug.js');
const ldo = require('./ldo.js');
const ljstype = require('./ljstype');
const lobject = require('./lobject');
-const lua = require('./lua.js');
const llimit = require('./llimit.js');
const TValue = lobject.TValue;
-const CT = lua.constant_types;
-const TS = lua.thread_status;
-const char = lua.char;
+const CT = defs.constant_types;
+const TS = defs.thread_status;
+const char = defs.char;
const FIRST_RESERVED = 257;
@@ -153,20 +153,20 @@ const save = function(ls, c) {
let b = ls.buff;
if (b.n + 1 > b.buffer.length) {
if (b.buffer.length >= llimit.MAX_INT/2)
- lexerror(ls, lua.to_luastring("lexical element too long", true), 0);
+ lexerror(ls, defs.to_luastring("lexical element too long", true), 0);
}
b.buffer[b.n++] = c < 0 ? 255 + c + 1 : c;
};
const luaX_token2str = function(ls, token) {
if (typeof token === "string" || token < FIRST_RESERVED) { /* single-byte symbols? */
- return lua.to_luastring(`'${typeof token === "string" ? token : lobject.jsstring([token])}'`);
+ return defs.to_luastring(`'${typeof token === "string" ? token : lobject.jsstring([token])}'`);
} else {
let s = luaX_tokens[token - FIRST_RESERVED];
if (token < R.TK_EOS) /* fixed format (symbols and reserved words)? */
- return lua.to_luastring(`'${s}'`);
+ return defs.to_luastring(`'${s}'`);
else /* names, strings, and numerals */
- return lua.to_luastring(s);
+ return defs.to_luastring(s);
}
};
@@ -194,7 +194,7 @@ const inclinenumber = function(ls) {
if (currIsNewline(ls) && ls.current !== old)
next(ls); /* skip '\n\r' or '\r\n' */
if (++ls.linenumber >= llimit.MAX_INT)
- lexerror(ls, lua.to_luastring("chunk has too many lines", true), 0);
+ lexerror(ls, defs.to_luastring("chunk has too many lines", true), 0);
};
const luaX_setinput = function(L, ls, z, source, firstchar) {
@@ -221,7 +221,7 @@ const luaX_setinput = function(L, ls, z, source, firstchar) {
ls.linenumber = 1;
ls.lastline = 1;
ls.source = source;
- ls.envn = L.l_G.intern(lua.to_luastring("_ENV", true));
+ ls.envn = L.l_G.intern(defs.to_luastring("_ENV", true));
};
const check_next1 = function(ls, c) {
@@ -229,7 +229,7 @@ const check_next1 = function(ls, c) {
next(ls);
return true;
}
-
+
return false;
};
@@ -268,7 +268,7 @@ const read_numeral = function(ls, seminfo) {
let obj = lobject.luaO_str2num(ls.buff.buffer);
if (obj === false) /* format error? */
- lexerror(ls, lua.to_luastring("malformed number", true), R.TK_FLT);
+ lexerror(ls, defs.to_luastring("malformed number", true), R.TK_FLT);
if (obj.ttisinteger()) {
seminfo.i = obj.value;
return R.TK_INT;
@@ -284,7 +284,7 @@ const txtToken = function(ls, token) {
case R.TK_NAME: case R.TK_STRING:
case R.TK_FLT: case R.TK_INT:
save(ls, 0);
- return lua.to_luastring(`'${lobject.jsstring(ls.buff.buffer)}'`);
+ return defs.to_luastring(`'${lobject.jsstring(ls.buff.buffer)}'`);
default:
return luaX_token2str(ls, token);
}
@@ -293,7 +293,7 @@ const txtToken = function(ls, token) {
const lexerror = function(ls, msg, token) {
msg = ldebug.luaG_addinfo(ls.L, msg, ls.source, ls.linenumber);
if (token)
- lapi.lua_pushstring(ls.L, lua.to_luastring(`${msg instanceof TValue ? msg.jsstring() : msg} near ${lobject.jsstring(txtToken(ls, token))}`));
+ lapi.lua_pushstring(ls.L, defs.to_luastring(`${msg instanceof TValue ? msg.jsstring() : msg} near ${lobject.jsstring(txtToken(ls, token))}`));
ldo.luaD_throw(ls.L, TS.LUA_ERRSYNTAX);
};
@@ -331,7 +331,7 @@ const read_long_string = function(ls, seminfo, sep) {
case -1: { /* error */
let what = seminfo ? "string" : "comment";
let msg = `unfinished long ${what} (starting at line ${line})`;
- lexerror(ls, lua.to_luastring(msg), R.TK_EOS);
+ lexerror(ls, defs.to_luastring(msg), R.TK_EOS);
break;
}
case char[']']: {
@@ -374,7 +374,7 @@ const esccheck = function(ls, c, msg) {
const gethexa = function(ls) {
save_and_next(ls);
- esccheck(ls, ljstype.lisxdigit(ls.current), lua.to_luastring("hexadecimal digit expected", true));
+ esccheck(ls, ljstype.lisxdigit(ls.current), defs.to_luastring("hexadecimal digit expected", true));
return lobject.luaO_hexavalue(ls.current);
};
@@ -388,17 +388,17 @@ const readhexaesc = function(ls) {
const readutf8desc = function(ls) {
let i = 4; /* chars to be removed: '\', 'u', '{', and first digit */
save_and_next(ls); /* skip 'u' */
- esccheck(ls, ls.current === char['{'], lua.to_luastring("missing '{'", true));
+ esccheck(ls, ls.current === char['{'], defs.to_luastring("missing '{'", true));
let r = gethexa(ls); /* must have at least one digit */
save_and_next(ls);
while (ljstype.lisxdigit(ls.current)) {
i++;
r = (r << 4) + lobject.luaO_hexavalue(ls.current);
- esccheck(ls, r <= 0x10FFFF, lua.to_luastring("UTF-8 value too large", true));
+ esccheck(ls, r <= 0x10FFFF, defs.to_luastring("UTF-8 value too large", true));
save_and_next(ls);
}
- esccheck(ls, ls.current === char['}'], lua.to_luastring("missing '}'", true));
+ esccheck(ls, ls.current === char['}'], defs.to_luastring("missing '}'", true));
next(ls); /* skip '}' */
ls.buff.n -= i; /* remove saved chars from buffer */
return r;
@@ -418,7 +418,7 @@ const readdecesc = function(ls) {
r = 10 * r + ls.current - char['0'];
save_and_next(ls);
}
- esccheck(ls, r <= 255, lua.to_luastring("decimal escape too large", true));
+ esccheck(ls, r <= 255, defs.to_luastring("decimal escape too large", true));
ls.buff.n -= i; /* remove read digits from buffer */
return r;
};
@@ -429,11 +429,11 @@ const read_string = function(ls, del, seminfo) {
while (ls.current !== del) {
switch (ls.current) {
case -1:
- lexerror(ls, lua.to_luastring("unfinished string", true), R.TK_EOS);
+ lexerror(ls, defs.to_luastring("unfinished string", true), R.TK_EOS);
break;
case char['\n']:
case char['\r']:
- lexerror(ls, lua.to_luastring("unfinished string", true), R.TK_STRING);
+ lexerror(ls, defs.to_luastring("unfinished string", true), R.TK_STRING);
break;
case char['\\']: { /* escape sequences */
save_and_next(ls); /* keep '\\' for error messages */
@@ -464,7 +464,7 @@ const read_string = function(ls, del, seminfo) {
will = 'no_save'; break;
}
default: {
- esccheck(ls, ljstype.lisdigit(ls.current), lua.to_luastring("invalid escape sequence", true));
+ esccheck(ls, ljstype.lisdigit(ls.current), defs.to_luastring("invalid escape sequence", true));
c = readdecesc(ls); /* digital escape '\ddd' */
will = 'only_save'; break;
}
@@ -472,7 +472,7 @@ const read_string = function(ls, del, seminfo) {
if (will === 'read_save')
next(ls);
-
+
if (will === 'read_save' || will === 'only_save') {
ls.buff.n -= 1; /* remove '\\' */
save(ls, c);
@@ -538,7 +538,7 @@ const llex = function(ls, seminfo) {
read_long_string(ls, seminfo, sep);
return R.TK_STRING;
} else if (sep !== -1) /* '[=...' missing second bracket */
- lexerror(ls, lua.to_luastring("invalid long string delimiter", true), R.TK_STRING);
+ lexerror(ls, defs.to_luastring("invalid long string delimiter", true), R.TK_STRING);
return char['['];
}
case char['=']: {
diff --git a/src/lobject.js b/src/lobject.js
index 0f71405..c15101a 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -3,13 +3,13 @@
const assert = require('assert');
+const defs = require('./defs.js');
const ljstype = require('./ljstype.js');
-const lua = require('./lua.js');
const luaconf = require('./luaconf.js');
const llimit = require('./llimit.js');
-const CT = lua.constant_types;
+const CT = defs.constant_types;
const UpVal = require('./lfunc.js').UpVal;
-const char = lua.char;
+const char = defs.char;
let tvalueCount = 0;
@@ -35,31 +35,31 @@ class TValue {
checktag(t) {
return this.type === t;
}
-
+
checktype(t) {
return this.ttnov() === t;
}
-
+
ttisnumber() {
return this.checktype(CT.LUA_TNUMBER);
}
-
+
ttisfloat() {
return this.checktag(CT.LUA_TNUMFLT);
}
-
+
ttisinteger() {
return this.checktag(CT.LUA_TNUMINT);
}
-
+
ttisnil() {
return this.checktag(CT.LUA_TNIL);
}
-
+
ttisboolean() {
return this.checktag(CT.LUA_TBOOLEAN);
}
-
+
ttislightuserdata() {
return this.checktag(CT.LUA_TLIGHTUSERDATA);
}
@@ -71,51 +71,51 @@ class TValue {
ttisptr() {
return this.checktag(CT.LUA_TLIGHTUSERDATA_PTR);
}
-
+
ttisstring() {
return this.checktype(CT.LUA_TSTRING);
}
-
+
ttisshrstring() {
return this.checktag(CT.LUA_TSHRSTR);
}
-
+
ttislngstring() {
return this.checktag(CT.LUA_TLNGSTR);
}
-
+
ttistable() {
return this.checktag(CT.LUA_TTABLE);
}
-
+
ttisfunction() {
return this.checktype(CT.LUA_TFUNCTION);
}
-
+
ttisclosure() {
return (this.type & 0x1F) === CT.LUA_TFUNCTION;
}
-
+
ttisCclosure() {
return this.checktag(CT.LUA_TCCL);
}
-
+
ttisLclosure() {
return this.checktag(CT.LUA_TLCL);
}
-
+
ttislcf() {
return this.checktag(CT.LUA_TLCF);
}
-
+
ttisfulluserdata() {
return this.checktag(CT.LUA_TUSERDATA);
}
-
+
ttisthread() {
return this.checktag(CT.LUA_TTHREAD);
}
-
+
ttisdeadkey() {
return this.checktag(CT.LUA_TDEADKEY);
}
@@ -189,7 +189,7 @@ const table_keyValue = function(key) {
key = key.value.map(e => `${e}|`).join('');
}
} else if (typeof key === "string") { // To avoid
- key = lua.to_luastring(key).map(e => `${e}|`).join('');
+ key = defs.to_luastring(key).map(e => `${e}|`).join('');
} else if (Array.isArray(key)) {
key = key.map(e => `${e}|`).join('');
}
@@ -261,9 +261,9 @@ class LocVar {
}
}
-const RETS = lua.to_luastring("...", true);
-const PRE = lua.to_luastring("[string \"");
-const POS = lua.to_luastring("\"]");
+const RETS = defs.to_luastring("...", true);
+const PRE = defs.to_luastring("[string \"");
+const POS = defs.to_luastring("\"]");
const luaO_chunkid = function(source, bufflen) {
source = source instanceof TValue ? source.value : source;
@@ -524,32 +524,32 @@ const luaO_int2fb = function(x) {
const intarith = function(L, op, v1, v2) {
switch (op) {
- case lua.LUA_OPADD: return (v1 + v2)|0;
- case lua.LUA_OPSUB: return (v1 - v2)|0;
- case lua.LUA_OPMUL: return (v1 * v2)|0;
- case lua.LUA_OPMOD: return (v1 - Math.floor(v1 / v2) * v2)|0; // % semantic on negative numbers is different in js
- case lua.LUA_OPIDIV: return (v1 / v2)|0;
- case lua.LUA_OPBAND: return (v1 & v2);
- case lua.LUA_OPBOR: return (v1 | v2);
- case lua.LUA_OPBXOR: return (v1 ^ v2);
- case lua.LUA_OPSHL: return (v1 << v2);
- case lua.LUA_OPSHR: return (v1 >> v2);
- case lua.LUA_OPUNM: return (0 - v1);
- case lua.LUA_OPBNOT: return (~0 ^ v1);
+ case defs.LUA_OPADD: return (v1 + v2)|0;
+ case defs.LUA_OPSUB: return (v1 - v2)|0;
+ case defs.LUA_OPMUL: return (v1 * v2)|0;
+ case defs.LUA_OPMOD: return (v1 - Math.floor(v1 / v2) * v2)|0; // % semantic on negative numbers is different in js
+ case defs.LUA_OPIDIV: return (v1 / v2)|0;
+ case defs.LUA_OPBAND: return (v1 & v2);
+ case defs.LUA_OPBOR: return (v1 | v2);
+ case defs.LUA_OPBXOR: return (v1 ^ v2);
+ case defs.LUA_OPSHL: return (v1 << v2);
+ case defs.LUA_OPSHR: return (v1 >> v2);
+ case defs.LUA_OPUNM: return (0 - v1);
+ case defs.LUA_OPBNOT: return (~0 ^ v1);
}
};
const numarith = function(L, op, v1, v2) {
switch (op) {
- case lua.LUA_OPADD: return v1 + v2;
- case lua.LUA_OPSUB: return v1 - v2;
- case lua.LUA_OPMUL: return v1 * v2;
- case lua.LUA_OPDIV: return v1 / v2;
- case lua.LUA_OPPOW: return Math.pow(v1, v2);
- case lua.LUA_OPIDIV: return (v1 / v2);
- case lua.LUA_OPUNM: return -v1;
- case lua.LUA_OPMOD: return v1 % v2;
+ case defs.LUA_OPADD: return v1 + v2;
+ case defs.LUA_OPSUB: return v1 - v2;
+ case defs.LUA_OPMUL: return v1 * v2;
+ case defs.LUA_OPDIV: return v1 / v2;
+ case defs.LUA_OPPOW: return Math.pow(v1, v2);
+ case defs.LUA_OPIDIV: return (v1 / v2);
+ case defs.LUA_OPUNM: return -v1;
+ case defs.LUA_OPMOD: return v1 % v2;
}
};
diff --git a/src/lparser.js b/src/lparser.js
index fba5f94..9ba5941 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -2,13 +2,13 @@
const assert = require('assert');
+const defs = require('./defs.js');
const lcode = require('./lcode.js');
const lfunc = require('./lfunc.js');
const llex = require('./llex.js');
const llimit = require('./llimit.js');
const lobject = require('./lobject.js');
const lopcode = require('./lopcodes.js');
-const lua = require('./lua.js');
const BinOpr = lcode.BinOpr;
const OpCodesI = lopcode.OpCodesI;
const Proto = lfunc.Proto;
@@ -16,7 +16,7 @@ const R = llex.RESERVED;
const TValue = lobject.TValue;
const UnOpr = lcode.UnOpr;
const UpVal = lfunc.UpVal;
-const char = lua.char;
+const char = defs.char;
const MAXVARS = 200;
@@ -159,7 +159,7 @@ const semerror = function(ls, msg) {
};
const error_expected = function(ls, token) {
- llex.luaX_syntaxerror(ls, lua.to_luastring(`${lobject.jsstring(llex.luaX_token2str(ls, token))} expected`));
+ llex.luaX_syntaxerror(ls, defs.to_luastring(`${lobject.jsstring(llex.luaX_token2str(ls, token))} expected`));
};
const errorlimit = function(fs, limit, what) {
@@ -167,7 +167,7 @@ const errorlimit = function(fs, limit, what) {
let line = fs.f.linedefined;
let where = (line === 0) ? "main function" : `function at line ${line}`;
let msg = `too many ${what} (limit is ${limit}) in ${where}`;
- llex.luaX_syntaxerror(fs.ls, lua.to_luastring(msg));
+ llex.luaX_syntaxerror(fs.ls, defs.to_luastring(msg));
};
const checklimit = function(fs, v, l, what) {
@@ -204,7 +204,7 @@ const check_match = function(ls, what, who, where) {
error_expected(ls, what);
else
llex.luaX_syntaxerror(ls,
- lua.to_luastring(`${lobject.jsstring(llex.luaX_token2str(ls, what))} expected (to close ${lobject.jsstring(llex.luaX_token2str(ls, who))} at line ${where}`));
+ defs.to_luastring(`${lobject.jsstring(llex.luaX_token2str(ls, what))} expected (to close ${lobject.jsstring(llex.luaX_token2str(ls, who))} at line ${where}`));
}
};
@@ -241,14 +241,14 @@ const new_localvar = function(ls, name) {
let fs = ls.fs;
let dyd = ls.dyd;
let reg = registerlocalvar(ls, name);
- checklimit(fs, dyd.actvar.n + 1 - fs.firstlocal, MAXVARS, lua.to_luastring("local variables", true));
+ checklimit(fs, dyd.actvar.n + 1 - fs.firstlocal, MAXVARS, defs.to_luastring("local variables", true));
dyd.actvar.arr[dyd.actvar.n] = new Vardesc();
dyd.actvar.arr[dyd.actvar.n].idx = reg;
dyd.actvar.n++;
};
const new_localvarliteral = function(ls, name) {
- new_localvar(ls, new TValue(lua.CT.LUA_TLNGSTR, name));
+ new_localvar(ls, new TValue(defs.CT.LUA_TLNGSTR, name));
};
const getlocvar = function(fs, i) {
@@ -281,7 +281,7 @@ const searchupvalue = function(fs, name) {
const newupvalue = function(fs, name, v) {
let f = fs.f;
- checklimit(fs, fs.nups + 1, lfunc.MAXUPVAL, lua.to_luastring("upvalues", true));
+ checklimit(fs, fs.nups + 1, lfunc.MAXUPVAL, defs.to_luastring("upvalues", true));
f.upvalues[fs.nups] = new UpVal(fs.ls.L);
f.upvalues[fs.nups].instack = v.k === expkind.VLOCAL;
f.upvalues[fs.nups].idx = v.u.info;
@@ -372,7 +372,7 @@ const adjust_assign = function(ls, nvars, nexps, e) {
const enterlevel = function(ls) {
let L = ls.L;
++L.nCcalls;
- checklimit(ls.fs, L.nCcalls, llimit.LUAI_MAXCCALLS, lua.to_luastring("JS levels", true));
+ checklimit(ls.fs, L.nCcalls, llimit.LUAI_MAXCCALLS, defs.to_luastring("JS levels", true));
};
const leavelevel = function(ls) {
@@ -386,7 +386,7 @@ const closegoto = function(ls, g, label) {
assert(gt.name.value.join() === label.name.value.join());
if (gt.nactvar < label.nactvar) {
let vname = getlocvar(fs, gt.nactvar).varname;
- semerror(ls, lua.to_luastring(`<goto ${gt.name.jsstring()}> at line ${gt.line} jumps into the scope of local '${vname.jsstring()}'`));
+ semerror(ls, defs.to_luastring(`<goto ${gt.name.jsstring()}> at line ${gt.line} jumps into the scope of local '${vname.jsstring()}'`));
}
lcode.luaK_patchlist(fs, gt.pc, label.pc);
/* remove goto from pending list */
@@ -479,7 +479,7 @@ const enterblock = function(fs, bl, isloop) {
** create a label named 'break' to resolve break statements
*/
const breaklabel = function(ls) {
- let n = new TValue(lua.CT.LUA_TLNGSTR, lua.to_luastring("break", true));
+ let n = new TValue(defs.CT.LUA_TLNGSTR, defs.to_luastring("break", true));
let l = newlabelentry(ls, ls.dyd.label, n, 0, ls.fs.pc);
findgotos(ls, ls.dyd.label.arr[l]);
};
@@ -492,7 +492,7 @@ const undefgoto = function(ls, gt) {
const msg = llex.isreserved(gt.name.value)
? `<${gt.name.jsstring()}> at line ${gt.line} not inside a loop`
: `no visible label '${gt.name.jsstring()}' for <goto> at line ${gt.line}`;
- semerror(ls, lua.to_luastring(msg));
+ semerror(ls, defs.to_luastring(msg));
};
/*
@@ -638,7 +638,7 @@ const recfield = function(ls, cc) {
let val = new expdesc();
if (ls.t.token === R.TK_NAME) {
- checklimit(fs, cc.nh, llimit.MAX_INT, lua.to_luastring("items in a constructor", true));
+ checklimit(fs, cc.nh, llimit.MAX_INT, defs.to_luastring("items in a constructor", true));
checkname(ls, key);
} else /* ls->t.token === '[' */
yindex(ls, key);
@@ -664,7 +664,7 @@ const lastlistfield = function(fs, cc) {
if (cc.tostore === 0) return;
if (hasmultret(cc.v.k)) {
lcode.luaK_setmultret(fs, cc.v);
- lcode.luaK_setlist(fs, cc.t.u.info, cc.na, lua.LUA_MULTRET);
+ lcode.luaK_setlist(fs, cc.t.u.info, cc.na, defs.LUA_MULTRET);
cc.na--; /* do not count last expression (unknown number of elements) */
} else {
if (cc.v.k !== expkind.VVOID)
@@ -676,7 +676,7 @@ const lastlistfield = function(fs, cc) {
const listfield = function(ls, cc) {
/* listfield -> exp */
expr(ls, cc.v);
- checklimit(ls.fs, cc.na, llimit.MAX_INT, lua.to_luastring("items in a constructor", true));
+ checklimit(ls.fs, cc.na, llimit.MAX_INT, defs.to_luastring("items in a constructor", true));
cc.na++;
cc.tostore++;
};
@@ -748,7 +748,7 @@ const parlist = function(ls) {
f.is_vararg = 1; /* declared vararg */
break;
}
- default: llex.luaX_syntaxerror(ls, lua.to_luastring("<name> or '...' expected", true));
+ default: llex.luaX_syntaxerror(ls, defs.to_luastring("<name> or '...' expected", true));
}
} while(!f.is_vararg && testnext(ls, char[',']));
}
@@ -766,7 +766,7 @@ const body = function(ls, e, ismethod, line) {
open_func(ls, new_fs, bl);
checknext(ls, char['(']);
if (ismethod) {
- new_localvarliteral(ls, lua.to_luastring("self", true)); /* create 'self' parameter */
+ new_localvarliteral(ls, defs.to_luastring("self", true)); /* create 'self' parameter */
adjustlocalvars(ls, 1);
}
parlist(ls);
@@ -815,14 +815,14 @@ const funcargs = function(ls, f, line) {
break;
}
default: {
- llex.luaX_syntaxerror(ls, lua.to_luastring("function arguments expected", true));
+ llex.luaX_syntaxerror(ls, defs.to_luastring("function arguments expected", true));
}
}
assert(f.k === expkind.VNONRELOC);
let nparams;
let base = f.u.info; /* base register for call */
if (hasmultret(args.k))
- nparams = lua.LUA_MULTRET; /* open call */
+ nparams = defs.LUA_MULTRET; /* open call */
else {
if (args.k !== expkind.VVOID)
lcode.luaK_exp2nextreg(fs, args); /* close last argument */
@@ -855,7 +855,7 @@ const primaryexp = function(ls, v) {
return;
}
default: {
- llex.luaX_syntaxerror(ls, lua.to_luastring("unexpected symbol", true));
+ llex.luaX_syntaxerror(ls, defs.to_luastring("unexpected symbol", true));
}
}
};
@@ -929,7 +929,7 @@ const simpleexp = function(ls, v) {
}
case R.TK_DOTS: { /* vararg */
let fs = ls.fs;
- check_condition(ls, fs.f.is_vararg, lua.to_luastring("cannot use '...' outside a vararg function", true));
+ check_condition(ls, fs.f.is_vararg, defs.to_luastring("cannot use '...' outside a vararg function", true));
init_exp(v, expkind.VVARARG, lcode.luaK_codeABC(fs, OpCodesI.OP_VARARG, 0, 1, 0));
break;
}
@@ -1101,14 +1101,14 @@ const check_conflict = function(ls, lh, v) {
const assignment = function(ls, lh, nvars) {
let e = new expdesc();
- check_condition(ls, vkisvar(lh.v.k), lua.to_luastring("syntax error", true));
+ check_condition(ls, vkisvar(lh.v.k), defs.to_luastring("syntax error", true));
if (testnext(ls, char[','])) { /* assignment -> ',' suffixedexp assignment */
let nv = new LHS_assign();
nv.prev = lh;
suffixedexp(ls, nv.v);
if (nv.v.k !== expkind.VINDEXED)
check_conflict(ls, lh, nv.v);
- checklimit(ls.fs, nvars + ls.L.nCcalls, llimit.LUAI_MAXCCALLS, lua.to_luastring("JS levels", true));
+ checklimit(ls.fs, nvars + ls.L.nCcalls, llimit.LUAI_MAXCCALLS, defs.to_luastring("JS levels", true));
assignment(ls, nv, nvars + 1);
} else { /* assignment -> '=' explist */
checknext(ls, char['=']);
@@ -1141,7 +1141,7 @@ const gotostat = function(ls, pc) {
label = str_checkname(ls);
else {
llex.luaX_next(ls); /* skip break */
- label = new TValue(lua.CT.LUA_TLNGSTR, lua.to_luastring("break", true));
+ label = new TValue(defs.CT.LUA_TLNGSTR, defs.to_luastring("break", true));
}
let g = newlabelentry(ls, ls.dyd.gt, label, line, pc);
findlabel(ls, g); /* close it if label already defined */
@@ -1151,7 +1151,7 @@ const gotostat = function(ls, pc) {
const checkrepeated = function(fs, ll, label) {
for (let i = fs.bl.firstlabel; i < ll.n; i++) {
if (label.value.join() === ll.arr[i].name.value.join()) {
- semerror(fs.ls, lua.to_luastring(`label '${label.jsstring()}' already defined on line ${ll.arr[i].line}`));
+ semerror(fs.ls, defs.to_luastring(`label '${label.jsstring()}' already defined on line ${ll.arr[i].line}`));
}
}
};
@@ -1252,9 +1252,9 @@ const fornum = function(ls, varname, line) {
/* fornum -> NAME = exp1,exp1[,exp1] forbody */
let fs = ls.fs;
let base = fs.freereg;
- new_localvarliteral(ls, lua.to_luastring("(for index)", true));
- new_localvarliteral(ls, lua.to_luastring("(for limit)", true));
- new_localvarliteral(ls, lua.to_luastring("(for step)", true));
+ new_localvarliteral(ls, defs.to_luastring("(for index)", true));
+ new_localvarliteral(ls, defs.to_luastring("(for limit)", true));
+ new_localvarliteral(ls, defs.to_luastring("(for step)", true));
new_localvar(ls, varname);
checknext(ls, char['=']);
exp1(ls); /* initial value */
@@ -1276,9 +1276,9 @@ const forlist = function(ls, indexname) {
let nvars = 4; /* gen, state, control, plus at least one declared var */
let base = fs.freereg;
/* create control variables */
- new_localvarliteral(ls, lua.to_luastring("(for generator)", true));
- new_localvarliteral(ls, lua.to_luastring("(for state)", true));
- new_localvarliteral(ls, lua.to_luastring("(for control)", true));
+ new_localvarliteral(ls, defs.to_luastring("(for generator)", true));
+ new_localvarliteral(ls, defs.to_luastring("(for state)", true));
+ new_localvarliteral(ls, defs.to_luastring("(for control)", true));
/* create declared variables */
new_localvar(ls, indexname);
while (testnext(ls, char[','])) {
@@ -1302,7 +1302,7 @@ const forstat = function(ls, line) {
switch (ls.t.token) {
case char['=']: fornum(ls, varname, line); break;
case char[',']: case R.TK_IN: forlist(ls, varname); break;
- default: llex.luaX_syntaxerror(ls, lua.to_luastring("'=' or 'in' expected", true));
+ default: llex.luaX_syntaxerror(ls, defs.to_luastring("'=' or 'in' expected", true));
}
check_match(ls, R.TK_END, R.TK_FOR, line);
leaveblock(fs); /* loop scope ('break' jumps to this point) */
@@ -1420,7 +1420,7 @@ const exprstat= function(ls) {
assignment(ls, v, 1);
}
else { /* stat -> func */
- check_condition(ls, v.v.k === expkind.VCALL, lua.to_luastring("syntax error", true));
+ check_condition(ls, v.v.k === expkind.VCALL, defs.to_luastring("syntax error", true));
lopcode.SETARG_C(lcode.getinstruction(fs, v.v), 1); /* call statement uses no results */
}
};
@@ -1441,7 +1441,7 @@ const retstat = function(ls) {
assert(lcode.getinstruction(fs, e).A === fs.nactvar);
}
first = fs.nactvar;
- nret = lua.LUA_MULTRET; /* return all values */
+ nret = defs.LUA_MULTRET; /* return all values */
} else {
if (nret === 1) /* only one single value? */
first = lcode.luaK_exp2anyreg(fs, e);
@@ -1546,10 +1546,10 @@ const luaY_parser = function(L, z, buff, dyd, name, firstchar) {
let funcstate = new FuncState();
let cl = lfunc.luaF_newLclosure(L, 1); /* create main closure */
L.stack[L.top++] = cl;
- lexstate.h = new TValue(lua.CT.LUA_TTABLE, new Map()); /* create table for scanner */
+ lexstate.h = new TValue(defs.CT.LUA_TTABLE, new Map()); /* create table for scanner */
L.stack[L.top++] = lexstate.h;
funcstate.f = cl.p = new Proto(L);
- funcstate.f.source = new TValue(lua.CT.LUA_TLNGSTR, name);
+ funcstate.f.source = new TValue(defs.CT.LUA_TLNGSTR, name);
lexstate.buff = buff;
lexstate.dyd = dyd;
dyd.actvar.n = dyd.gt.n = dyd.label.n = 0;
diff --git a/src/lstate.js b/src/lstate.js
index 5842562..0541a8e 100644
--- a/src/lstate.js
+++ b/src/lstate.js
@@ -3,17 +3,17 @@
const assert = require('assert');
-const lua = require('./lua.js');
+const defs = require('./defs.js');
const lobject = require('./lobject.js');
const ldo = require('./ldo.js');
const lapi = require('./lapi.js');
const luaT_init = require('./ltm.js').luaT_init;
-const CT = lua.constant_types;
-const LUA_MULTRET = lua.LUA_MULTRET;
-const TS = lua.thread_status;
-const LUA_NUMTAGS = lua.LUA_NUMTAGS;
+const CT = defs.constant_types;
+const LUA_MULTRET = defs.LUA_MULTRET;
+const TS = defs.thread_status;
+const LUA_NUMTAGS = defs.LUA_NUMTAGS;
-const BASIC_STACK_SIZE = 2 * lua.LUA_MINSTACK;
+const BASIC_STACK_SIZE = 2 * defs.LUA_MINSTACK;
class CallInfo {
@@ -79,11 +79,11 @@ class global_State {
// TODO: when weak value maps are available
// let key = stringArray.map(e => `${e}|`).join('');
- // if (!this.strt.has(key))
+ // if (!this.strt.has(key))
// this.strt.set(key, new lobject.TValue(CT.LUA_TLNGSTR, stringArray));
// return this.strt.get(key);
-
+
return new lobject.TValue(CT.LUA_TLNGSTR, stringArray);
}
@@ -99,7 +99,7 @@ const stack_init = function(L1, L) {
ci.func = L1.stack[L1.top];
ci.funcOff = L1.top;
L1.stack[L1.top++] = new lobject.TValue(CT.LUA_TNIL, null);
- ci.top = L1.top + lua.LUA_MINSTACK;
+ ci.top = L1.top + defs.LUA_MINSTACK;
L1.ci = ci;
};
@@ -109,8 +109,8 @@ const stack_init = function(L1, L) {
const init_registry = function(L, g) {
let registry = new lobject.TValue(CT.LUA_TTABLE, new Map());
g.l_registry = registry;
- registry.value.set(lua.LUA_RIDX_MAINTHREAD, L);
- registry.value.set(lua.LUA_RIDX_GLOBALS, new lobject.TValue(CT.LUA_TTABLE, new Map()));
+ registry.value.set(defs.LUA_RIDX_MAINTHREAD, L);
+ registry.value.set(defs.LUA_RIDX_GLOBALS, new lobject.TValue(CT.LUA_TTABLE, new Map()));
};
/*
diff --git a/src/ltable.js b/src/ltable.js
index 23ecc11..a0ff59f 100644
--- a/src/ltable.js
+++ b/src/ltable.js
@@ -3,10 +3,10 @@
const assert = require('assert');
+const defs = require('./defs.js');
const lobject = require('./lobject.js');
-const lua = require('./lua.js');
-const CT = lua.constant_types;
const nil = require('./ldo.js').nil;
+const CT = defs.constant_types;
const TValue = lobject.TValue;
diff --git a/src/ltm.js b/src/ltm.js
index 1a9e454..92bfd74 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -3,41 +3,41 @@
const assert = require('assert');
+const defs = require('./defs.js');
const lobject = require('./lobject.js');
const TValue = lobject.TValue;
const ldo = require('./ldo.js');
const lstate = require('./lstate.js');
-const lua = require('./lua.js');
const ldebug = require('./ldebug.js');
const lvm = require('./lvm.js');
-const CT = lua.constant_types;
+const CT = defs.constant_types;
const TMS = {
- TM_INDEX: lua.to_luastring("__index", true),
- TM_NEWINDEX: lua.to_luastring("__newindex", true),
- TM_GC: lua.to_luastring("__gc", true),
- TM_MODE: lua.to_luastring("__mode", true),
- TM_LEN: lua.to_luastring("__len", true),
- TM_EQ: lua.to_luastring("__eq", true), /* last tag method with fast access */
- TM_ADD: lua.to_luastring("__add", true),
- TM_SUB: lua.to_luastring("__sub", true),
- TM_MUL: lua.to_luastring("__mul", true),
- TM_MOD: lua.to_luastring("__mod", true),
- TM_POW: lua.to_luastring("__pow", true),
- TM_DIV: lua.to_luastring("__div", true),
- TM_IDIV: lua.to_luastring("__idiv", true),
- TM_BAND: lua.to_luastring("__band", true),
- TM_BOR: lua.to_luastring("__bor", true),
- TM_BXOR: lua.to_luastring("__bxor", true),
- TM_SHL: lua.to_luastring("__shl", true),
- TM_SHR: lua.to_luastring("__shr", true),
- TM_UNM: lua.to_luastring("__unm", true),
- TM_BNOT: lua.to_luastring("__bnot", true),
- TM_LT: lua.to_luastring("__lt", true),
- TM_LE: lua.to_luastring("__le", true),
- TM_CONCAT: lua.to_luastring("__concat", true),
- TM_CALL: lua.to_luastring("__call", true)
+ TM_INDEX: defs.to_luastring("__index", true),
+ TM_NEWINDEX: defs.to_luastring("__newindex", true),
+ TM_GC: defs.to_luastring("__gc", true),
+ TM_MODE: defs.to_luastring("__mode", true),
+ TM_LEN: defs.to_luastring("__len", true),
+ TM_EQ: defs.to_luastring("__eq", true), /* last tag method with fast access */
+ TM_ADD: defs.to_luastring("__add", true),
+ TM_SUB: defs.to_luastring("__sub", true),
+ TM_MUL: defs.to_luastring("__mul", true),
+ TM_MOD: defs.to_luastring("__mod", true),
+ TM_POW: defs.to_luastring("__pow", true),
+ TM_DIV: defs.to_luastring("__div", true),
+ TM_IDIV: defs.to_luastring("__idiv", true),
+ TM_BAND: defs.to_luastring("__band", true),
+ TM_BOR: defs.to_luastring("__bor", true),
+ TM_BXOR: defs.to_luastring("__bxor", true),
+ TM_SHL: defs.to_luastring("__shl", true),
+ TM_SHR: defs.to_luastring("__shr", true),
+ TM_UNM: defs.to_luastring("__unm", true),
+ TM_BNOT: defs.to_luastring("__bnot", true),
+ TM_LT: defs.to_luastring("__lt", true),
+ TM_LE: defs.to_luastring("__le", true),
+ TM_CONCAT: defs.to_luastring("__concat", true),
+ TM_CALL: defs.to_luastring("__call", true)
};
const luaT_typenames_ = [
@@ -52,7 +52,7 @@ const luaT_typenames_ = [
"userdata",
"thread",
"proto" /* this last case is used for tests only */
-].map(e => lua.to_luastring(e));
+].map(e => defs.to_luastring(e));
const ttypename = function(t) {
return luaT_typenames_[t + 1];
@@ -70,7 +70,7 @@ const luaT_init = function(L) {
*/
const luaT_objtypename = function(L, o) {
if ((o.ttistable() && o.metatable !== null) || (o.ttisfulluserdata() && o.metatable !== null)) {
- let name = lobject.table_index(o, lua.to_luastring('__name', true));
+ let name = lobject.table_index(o, defs.to_luastring('__name', true));
if (name.ttisstring())
return name.jsstring();
}
@@ -122,10 +122,10 @@ const luaT_trybinTM = function(L, p1, p2, res, event) {
if (n1 !== false && n2 !== false)
ldebug.luaG_tointerror(L, p1, p2);
else
- ldebug.luaG_opinterror(L, p1, p2, lua.to_luastring("perform bitwise operation on", true));
+ ldebug.luaG_opinterror(L, p1, p2, defs.to_luastring("perform bitwise operation on", true));
}
default:
- ldebug.luaG_opinterror(L, p1, p2, lua.to_luastring("perform arithmetic on", true));
+ ldebug.luaG_opinterror(L, p1, p2, defs.to_luastring("perform arithmetic on", true));
}
}
};
diff --git a/src/lundump.js b/src/lundump.js
index b229926..e2daf6e 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -4,7 +4,7 @@
const fs = require('fs');
const assert = require('assert');
-const lua = require('./lua.js');
+const defs = require('./defs.js');
const lobject = require('./lobject.js');
const Proto = require('./lfunc.js').Proto;
const OpCodes = require('./lopcodes.js');
@@ -161,25 +161,25 @@ class BytecodeParser {
readConstants(f) {
let n = this.readInt();
-
+
for (let i = 0; i < n; i++) {
let t = this.readByte();
switch (t) {
- case lua.CT.LUA_TNIL:
- f.k.push(new lobject.TValue(lua.CT.LUA_TNIL, null));
+ case defs.CT.LUA_TNIL:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TNIL, null));
break;
- case lua.CT.LUA_TBOOLEAN:
- f.k.push(new lobject.TValue(lua.CT.LUA_TBOOLEAN, this.readByte()));
+ case defs.CT.LUA_TBOOLEAN:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TBOOLEAN, this.readByte()));
break;
- case lua.CT.LUA_TNUMFLT:
- f.k.push(new lobject.TValue(lua.CT.LUA_TNUMFLT, this.readNumber()));
+ case defs.CT.LUA_TNUMFLT:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TNUMFLT, this.readNumber()));
break;
- case lua.CT.LUA_TNUMINT:
- f.k.push(new lobject.TValue(lua.CT.LUA_TNUMINT, this.readInteger()));
+ case defs.CT.LUA_TNUMINT:
+ f.k.push(new lobject.TValue(defs.CT.LUA_TNUMINT, this.readInteger()));
break;
- case lua.CT.LUA_TSHRSTR:
- case lua.CT.LUA_TLNGSTR:
+ case defs.CT.LUA_TSHRSTR:
+ case defs.CT.LUA_TLNGSTR:
f.k.push(this.L.l_G.intern(this.read8bitString()));
break;
default:
@@ -205,7 +205,7 @@ class BytecodeParser {
n = this.readInt();
for (let i = 0; i < n; i++) {
f.locvars[i] = {
- varname: new lobject.TValue(lua.CT.LUA_TLNGSTR, lua.to_luastring(this.readString())),
+ varname: new lobject.TValue(defs.CT.LUA_TLNGSTR, defs.to_luastring(this.readString())),
startpc: this.readInt(),
endpc: this.readInt()
};
@@ -234,7 +234,7 @@ class BytecodeParser {
}
checkHeader() {
- if (this.readString(4) !== lua.LUA_SIGNATURE)
+ if (this.readString(4) !== defs.LUA_SIGNATURE)
throw new Error("bad LUA_SIGNATURE, expected '<esc>Lua'");
if (this.readByte() !== 0x53)
@@ -269,8 +269,8 @@ class BytecodeParser {
error(why) {
const lapi = require('./lapi.js');
const ldo = require('./ldo.js');
- lapi.lua_pushstring(this.L, lua.to_luastring(`${this.name}: ${why} precompiled chunk`, true));
- ldo.luaD_throw(this.L, lua.thread_status.LUA_ERRSYNTAX);
+ lapi.lua_pushstring(this.L, defs.to_luastring(`${this.name}: ${why} precompiled chunk`, true));
+ ldo.luaD_throw(this.L, defs.thread_status.LUA_ERRSYNTAX);
}
checksize(byte, size, tname) {
diff --git a/src/lvm.js b/src/lvm.js
index be4ebfc..455d091 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -3,12 +3,10 @@
const assert = require('assert');
+const defs = require('./defs.js');
const BytecodeParser = require('./lundump.js');
const OC = require('./lopcodes.js');
-const lua = require('./lua.js');
const luaconf = require('./luaconf.js');
-const CT = lua.constant_types;
-const LUA_MULTRET = lua.LUA_MULTRET;
const lobject = require('./lobject.js');
const TValue = lobject.TValue;
const LClosure = lobject.LClosure;
@@ -21,6 +19,8 @@ const ldo = require('./ldo.js');
const ltm = require('./ltm.js');
const ltable = require('./ltable.js');
const ldebug = require('./ldebug.js');
+const CT = defs.constant_types;
+const LUA_MULTRET = defs.LUA_MULTRET;
/*
** finish execution of an opcode interrupted by an yield
@@ -108,7 +108,7 @@ const luaV_execute = function(L) {
let specialCase = null; // To enable jump to specific opcode without reading current op/ra
let opcode, k, base, i, ra;
var cl;
-
+
ci.callstatus |= lstate.CIST_FRESH;
newframe:
for (;;) {
@@ -123,7 +123,7 @@ const luaV_execute = function(L) {
i = ci.u.l.savedpc[ci.pcOff++];
- if (L.hookmask & (lua.LUA_MASKLINE | lua.LUA_MASKCOUNT)) {
+ if (L.hookmask & (defs.LUA_MASKLINE | defs.LUA_MASKCOUNT)) {
ldebug.luaG_traceexec(L);
base = ci.u.l.base;
}
@@ -553,7 +553,7 @@ const luaV_execute = function(L) {
if (ci.callstatus & lstate.CIST_FRESH)
return; /* external invocation: return */
-
+
ci = L.ci;
if (b) L.top = ci.top;
@@ -600,19 +600,19 @@ const luaV_execute = function(L) {
let nstep = tonumber(pstep);
if (nlimit === false)
- ldebug.luaG_runerror(L, lua.to_luastring("'for' limit must be a number", true));
+ ldebug.luaG_runerror(L, defs.to_luastring("'for' limit must be a number", true));
plimit.type = CT.LUA_TNUMFLT;
plimit.value = nlimit;
if (nstep === false)
- ldebug.luaG_runerror(L, lua.to_luastring("'for' step must be a number", true));
+ ldebug.luaG_runerror(L, defs.to_luastring("'for' step must be a number", true));
pstep.type = CT.LUA_TNUMFLT;
pstep.value = nstep;
if (ninit === false)
- ldebug.luaG_runerror(L, lua.to_luastring("'for' initial value must be a number", true));
+ ldebug.luaG_runerror(L, defs.to_luastring("'for' initial value must be a number", true));
init.type = CT.LUA_TNUMFLT;
init.value = ninit - nstep;
@@ -986,7 +986,7 @@ const luaV_objlen = function(L, ra, rb) {
default: {
tm = ltm.luaT_gettmbyobj(L, rb, ltm.TMS.TM_LEN);
if (tm.ttisnil())
- ldebug.luaG_typeerror(L, rb, lua.to_luastring("get length of", true));
+ ldebug.luaG_typeerror(L, rb, defs.to_luastring("get length of", true));
break;
}
}
@@ -1000,7 +1000,7 @@ const tostring = function(L, i) {
if (o.ttisstring()) return true;
if (o.ttisnumber() && !isNaN(o.value)) {
- L.stack[i] = L.l_G.intern(lua.to_luastring(`${o.value}`));
+ L.stack[i] = L.l_G.intern(defs.to_luastring(`${o.value}`));
return true;
}
@@ -1051,7 +1051,7 @@ const gettable = function(L, table, key, ra, recur) {
recur = recur ? recur : 0;
if (recur >= MAXTAGRECUR)
- ldebug.luaG_runerror(L, lua.to_luastring("'__index' chain too long; possible loop", true));
+ ldebug.luaG_runerror(L, defs.to_luastring("'__index' chain too long; possible loop", true));
if (table.ttistable()) {
let element = lobject.table_index(table, key);
@@ -1072,7 +1072,7 @@ const luaV_finishget = function(L, t, key, val, slot, recur) {
assert(!t.ttistable());
tm = ltm.luaT_gettmbyobj(L, t, ltm.TMS.TM_INDEX);
if (tm.ttisnil())
- ldebug.luaG_typeerror(L, t, lua.to_luastring('index', true));
+ ldebug.luaG_typeerror(L, t, defs.to_luastring('index', true));
} else { /* 't' is a table */
assert(slot.ttisnil());
tm = ltm.luaT_gettmbyobj(L, t, ltm.TMS.TM_INDEX); // TODO: fasttm
@@ -1094,7 +1094,7 @@ const settable = function(L, table, key, v, recur) {
recur = recur ? recur : 0;
if (recur >= MAXTAGRECUR)
- ldebug.luaG_runerror(L, lua.to_luastring("'__newindex' chain too long; possible loop", true));
+ ldebug.luaG_runerror(L, defs.to_luastring("'__newindex' chain too long; possible loop", true));
if (table.ttistable()) {
let element = lobject.table_index(table, key);
@@ -1121,7 +1121,7 @@ const luaV_finishset = function(L, t, key, val, slot, recur) {
} else { /* not a table; check metamethod */
tm = ltm.luaT_gettmbyobj(L, t, ltm.TMS.TM_NEWINDEX);
if (tm.ttisnil())
- ldebug.luaG_typeerror(L, t, lua.to_luastring('index', true));
+ ldebug.luaG_typeerror(L, t, defs.to_luastring('index', true));
}
if (tm.ttisfunction()) {