summaryrefslogtreecommitdiff
path: root/src/lparser.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lparser.js')
-rw-r--r--src/lparser.js527
1 files changed, 310 insertions, 217 deletions
diff --git a/src/lparser.js b/src/lparser.js
index d183d25..a427424 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -1,23 +1,117 @@
"use strict";
-const assert = require('assert');
-
-const defs = require('./defs.js');
-const lcode = require('./lcode.js');
+const {
+ LUA_MULTRET,
+ to_luastring
+} = require('./defs.js');
+const {
+ BinOpr: {
+ OPR_ADD,
+ OPR_AND,
+ OPR_BAND,
+ OPR_BOR,
+ OPR_BXOR,
+ OPR_CONCAT,
+ OPR_DIV,
+ OPR_EQ,
+ OPR_GE,
+ OPR_GT,
+ OPR_IDIV,
+ OPR_LE,
+ OPR_LT,
+ OPR_MOD,
+ OPR_MUL,
+ OPR_NE,
+ OPR_NOBINOPR,
+ OPR_OR,
+ OPR_POW,
+ OPR_SHL,
+ OPR_SHR,
+ OPR_SUB
+ },
+ UnOpr: {
+ OPR_BNOT,
+ OPR_LEN,
+ OPR_MINUS,
+ OPR_NOT,
+ OPR_NOUNOPR
+ },
+ NO_JUMP,
+ getinstruction,
+ luaK_checkstack,
+ luaK_codeABC,
+ luaK_codeABx,
+ luaK_codeAsBx,
+ luaK_codek,
+ luaK_concat,
+ luaK_dischargevars,
+ luaK_exp2RK,
+ luaK_exp2anyreg,
+ luaK_exp2anyregup,
+ luaK_exp2nextreg,
+ luaK_exp2val,
+ luaK_fixline,
+ luaK_getlabel,
+ luaK_goiffalse,
+ luaK_goiftrue,
+ luaK_indexed,
+ luaK_infix,
+ luaK_intK,
+ luaK_jump,
+ luaK_jumpto,
+ luaK_nil,
+ luaK_patchclose,
+ luaK_patchlist,
+ luaK_patchtohere,
+ luaK_posfix,
+ luaK_prefix,
+ luaK_reserveregs,
+ luaK_ret,
+ luaK_self,
+ luaK_setlist,
+ luaK_setmultret,
+ luaK_setoneret,
+ luaK_setreturns,
+ luaK_storevar,
+ luaK_stringK
+} = require('./lcode.js');
const ldo = require('./ldo.js');
const lfunc = require('./lfunc.js');
const llex = require('./llex.js');
-const llimits = require('./llimits.js');
+const {
+ LUAI_MAXCCALLS,
+ MAX_INT,
+ lua_assert
+} = require('./llimits.js');
const lobject = require('./lobject.js');
-const lopcodes = require('./lopcodes.js');
-const lstring = require('./lstring.js');
+const {
+ OpCodesI: {
+ OP_CALL,
+ OP_CLOSURE,
+ OP_FORLOOP,
+ OP_FORPREP,
+ OP_GETUPVAL,
+ OP_MOVE,
+ OP_NEWTABLE,
+ OP_SETTABLE,
+ OP_TAILCALL,
+ OP_TFORCALL,
+ OP_TFORLOOP,
+ OP_VARARG
+ },
+ LFIELDS_PER_FLUSH,
+ SETARG_B,
+ SETARG_C,
+ SET_OPCODE
+} = require('./lopcodes.js');
+const {
+ luaS_eqlngstr,
+ luaS_new,
+ luaS_newliteral
+} = require('./lstring.js');
const ltable = require('./ltable.js');
-const BinOpr = lcode.BinOpr;
-const OpCodesI = lopcodes.OpCodesI;
const Proto = lfunc.Proto;
const R = llex.RESERVED;
-const UnOpr = lcode.UnOpr;
-const char = defs.char;
const MAXVARS = 200;
@@ -27,7 +121,7 @@ const hasmultret = function(k) {
const eqstr = function(a, b) {
/* TODO: use plain equality as strings are cached */
- return lstring.luaS_eqlngstr(a, b);
+ return luaS_eqlngstr(a, b);
};
class BlockCnt {
@@ -165,16 +259,16 @@ const semerror = function(ls, msg) {
};
const error_expected = function(ls, token) {
- llex.luaX_syntaxerror(ls, lobject.luaO_pushfstring(ls.L, defs.to_luastring("%s expected", true), llex.luaX_token2str(ls, token)));
+ llex.luaX_syntaxerror(ls, lobject.luaO_pushfstring(ls.L, to_luastring("%s expected", true), llex.luaX_token2str(ls, token)));
};
const errorlimit = function(fs, limit, what) {
let L = fs.ls.L;
let line = fs.f.linedefined;
let where = (line === 0)
- ? defs.to_luastring("main function", true)
- : lobject.luaO_pushfstring(L, defs.to_luastring("function at line %d", true), line);
- let msg = lobject.luaO_pushfstring(L, defs.to_luastring("too many %s (limit is %d) in %s", true),
+ ? to_luastring("main function", true)
+ : lobject.luaO_pushfstring(L, to_luastring("function at line %d", true), line);
+ let msg = lobject.luaO_pushfstring(L, to_luastring("too many %s (limit is %d) in %s", true),
what, limit, where);
llex.luaX_syntaxerror(fs.ls, msg);
};
@@ -213,7 +307,7 @@ const check_match = function(ls, what, who, where) {
error_expected(ls, what);
else
llex.luaX_syntaxerror(ls, lobject.luaO_pushfstring(ls.L,
- defs.to_luastring("%s expected (to close %s at line %d)"),
+ to_luastring("%s expected (to close %s at line %d)"),
llex.luaX_token2str(ls, what), llex.luaX_token2str(ls, who), where));
}
};
@@ -226,13 +320,13 @@ const str_checkname = function(ls) {
};
const init_exp = function(e, k, i) {
- e.f = e.t = lcode.NO_JUMP;
+ e.f = e.t = NO_JUMP;
e.k = k;
e.u.info = i;
};
const codestring = function(ls, e, s) {
- init_exp(e, expkind.VK, lcode.luaK_stringK(ls.fs, s));
+ init_exp(e, expkind.VK, luaK_stringK(ls.fs, s));
};
const checkname = function(ls, e) {
@@ -251,19 +345,19 @@ 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, defs.to_luastring("local variables", true));
+ checklimit(fs, dyd.actvar.n + 1 - fs.firstlocal, MAXVARS, 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, llex.luaX_newstring(ls, defs.to_luastring(name, true)));
+ new_localvar(ls, llex.luaX_newstring(ls, to_luastring(name, true)));
};
const getlocvar = function(fs, i) {
let idx = fs.ls.dyd.actvar.arr[fs.firstlocal + i].idx;
- assert(idx < fs.nlocvars);
+ lua_assert(idx < fs.nlocvars);
return fs.f.locvars[idx];
};
@@ -291,7 +385,7 @@ const searchupvalue = function(fs, name) {
const newupvalue = function(fs, name, v) {
let f = fs.f;
- checklimit(fs, fs.nups + 1, lfunc.MAXUPVAL, defs.to_luastring("upvalues", true));
+ checklimit(fs, fs.nups + 1, lfunc.MAXUPVAL, to_luastring("upvalues", true));
f.upvalues[fs.nups] = {
instack: v.k === expkind.VLOCAL,
idx: v.u.info,
@@ -354,9 +448,9 @@ const singlevar = function(ls, vr) {
if (vr.k === expkind.VVOID) { /* is global name? */
let key = new expdesc();
singlevaraux(fs, ls.envn, vr, 1); /* get environment variable */
- assert(vr.k !== expkind.VVOID); /* this one must exist */
+ lua_assert(vr.k !== expkind.VVOID); /* this one must exist */
codestring(ls, key, varname); /* key is variable name */
- lcode.luaK_indexed(fs, vr, key); /* env[varname] */
+ luaK_indexed(fs, vr, key); /* env[varname] */
}
};
@@ -366,14 +460,14 @@ const adjust_assign = function(ls, nvars, nexps, e) {
if (hasmultret(e.k)) {
extra++; /* includes call itself */
if (extra < 0) extra = 0;
- lcode.luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
- if (extra > 1) lcode.luaK_reserveregs(fs, extra - 1);
+ luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
+ if (extra > 1) luaK_reserveregs(fs, extra - 1);
} else {
- if (e.k !== expkind.VVOID) lcode.luaK_exp2nextreg(fs, e); /* close last expression */
+ if (e.k !== expkind.VVOID) luaK_exp2nextreg(fs, e); /* close last expression */
if (extra > 0) {
let reg = fs.freereg;
- lcode.luaK_reserveregs(fs, extra);
- lcode.luaK_nil(fs, reg, extra);
+ luaK_reserveregs(fs, extra);
+ luaK_nil(fs, reg, extra);
}
}
if (nexps > nvars)
@@ -383,7 +477,7 @@ const adjust_assign = function(ls, nvars, nexps, e) {
const enterlevel = function(ls) {
let L = ls.L;
++L.nCcalls;
- checklimit(ls.fs, L.nCcalls, llimits.LUAI_MAXCCALLS, defs.to_luastring("JS levels", true));
+ checklimit(ls.fs, L.nCcalls, LUAI_MAXCCALLS, to_luastring("JS levels", true));
};
const leavelevel = function(ls) {
@@ -394,15 +488,15 @@ const closegoto = function(ls, g, label) {
let fs = ls.fs;
let gl = ls.dyd.gt;
let gt = gl.arr[g];
- assert(eqstr(gt.name, label.name));
+ lua_assert(eqstr(gt.name, label.name));
if (gt.nactvar < label.nactvar) {
let vname = getlocvar(fs, gt.nactvar).varname;
let msg = lobject.luaO_pushfstring(ls.L,
- defs.to_luastring("<goto %s> at line %d jumps into the scope of local '%s'"),
+ to_luastring("<goto %s> at line %d jumps into the scope of local '%s'"),
gt.name.getstr(), gt.line, vname.getstr());
semerror(ls, msg);
}
- lcode.luaK_patchlist(fs, gt.pc, label.pc);
+ luaK_patchlist(fs, gt.pc, label.pc);
/* remove goto from pending list */
for (let i = g; i < gl.n - 1; i++)
gl.arr[i] = gl.arr[i + 1];
@@ -421,7 +515,7 @@ const findlabel = function(ls, g) {
let lb = dyd.label.arr[i];
if (eqstr(lb.name, gt.name)) { /* correct label? */
if (gt.nactvar > lb.nactvar && (bl.upval || dyd.label.n > bl.firstlabel))
- lcode.luaK_patchclose(ls.fs, gt.pc, lb.nactvar);
+ luaK_patchclose(ls.fs, gt.pc, lb.nactvar);
closegoto(ls, g, lb); /* close it */
return true;
}
@@ -470,7 +564,7 @@ const movegotosout = function(fs, bl) {
let gt = gl.arr[i];
if (gt.nactvar > bl.nactvar) {
if (bl.upval)
- lcode.luaK_patchclose(fs, gt.pc, bl.nactvar);
+ luaK_patchclose(fs, gt.pc, bl.nactvar);
gt.nactvar = bl.nactvar;
}
if (!findlabel(fs.ls, i))
@@ -486,14 +580,14 @@ const enterblock = function(fs, bl, isloop) {
bl.upval = 0;
bl.previous = fs.bl;
fs.bl = bl;
- assert(fs.freereg === fs.nactvar);
+ lua_assert(fs.freereg === fs.nactvar);
};
/*
** create a label named 'break' to resolve break statements
*/
const breaklabel = function(ls) {
- let n = lstring.luaS_newliteral(ls.L, "break");
+ let n = luaS_newliteral(ls.L, "break");
let l = newlabelentry(ls, ls.dyd.label, n, 0, ls.fs.pc);
findgotos(ls, ls.dyd.label.arr[l]);
};
@@ -506,7 +600,7 @@ const undefgoto = function(ls, gt) {
let msg = llex.isreserved(gt.name)
? "<%s> at line %d not inside a loop"
: "no visible label '%s' for <goto> at line %d";
- msg = lobject.luaO_pushfstring(ls.L, defs.to_luastring(msg), gt.name.getstr(), gt.line);
+ msg = lobject.luaO_pushfstring(ls.L, to_luastring(msg), gt.name.getstr(), gt.line);
semerror(ls, msg);
};
@@ -527,8 +621,8 @@ const addprototype = function(ls) {
*/
const codeclosure = function(ls, v) {
let fs = ls.fs.prev;
- init_exp(v, expkind.VRELOCABLE, lcode.luaK_codeABx(fs, OpCodesI.OP_CLOSURE, 0, fs.np -1));
- lcode.luaK_exp2nextreg(fs, v); /* fix it at the last register */
+ init_exp(v, expkind.VRELOCABLE, luaK_codeABx(fs, OP_CLOSURE, 0, fs.np -1));
+ luaK_exp2nextreg(fs, v); /* fix it at the last register */
};
const open_func = function(ls, fs, bl) {
@@ -537,7 +631,7 @@ const open_func = function(ls, fs, bl) {
ls.fs = fs;
fs.pc = 0;
fs.lasttarget = 0;
- fs.jpc = lcode.NO_JUMP;
+ fs.jpc = NO_JUMP;
fs.freereg = 0;
fs.nk = 0;
fs.np = 0;
@@ -558,9 +652,9 @@ const leaveblock = function(fs) {
let ls = fs.ls;
if (bl.previous && bl.upval) {
/* create a 'jump to here' to close upvalues */
- let j = lcode.luaK_jump(fs);
- lcode.luaK_patchclose(fs, j , bl.nactvar);
- lcode.luaK_patchtohere(fs, j);
+ let j = luaK_jump(fs);
+ luaK_patchclose(fs, j , bl.nactvar);
+ luaK_patchtohere(fs, j);
}
if (bl.isloop)
@@ -568,7 +662,7 @@ const leaveblock = function(fs) {
fs.bl = bl.previous;
removevars(fs, bl.nactvar);
- assert(bl.nactvar === fs.nactvar);
+ lua_assert(bl.nactvar === fs.nactvar);
fs.freereg = fs.nactvar; /* free registers */
ls.dyd.label.n = bl.firstlabel; /* remove local labels */
if (bl.previous) /* inner block? */
@@ -579,9 +673,9 @@ const leaveblock = function(fs) {
const close_func = function(ls) {
let fs = ls.fs;
- lcode.luaK_ret(fs, 0, 0); /* final return */
+ luaK_ret(fs, 0, 0); /* final return */
leaveblock(fs);
- assert(fs.bl === null);
+ lua_assert(fs.bl === null);
ls.fs = fs.prev;
};
@@ -614,18 +708,18 @@ const fieldsel = function(ls, v) {
/* fieldsel -> ['.' | ':'] NAME */
let fs = ls.fs;
let key = new expdesc();
- lcode.luaK_exp2anyregup(fs, v);
+ luaK_exp2anyregup(fs, v);
llex.luaX_next(ls); /* skip the dot or colon */
checkname(ls, key);
- lcode.luaK_indexed(fs, v, key);
+ luaK_indexed(fs, v, key);
};
const yindex = function(ls, v) {
/* index -> '[' expr ']' */
llex.luaX_next(ls); /* skip the '[' */
expr(ls, v);
- lcode.luaK_exp2val(ls.fs, v);
- checknext(ls, char[']']);
+ luaK_exp2val(ls.fs, v);
+ checknext(ls, 93 /* (']').charCodeAt(0) */);
};
/*
@@ -652,24 +746,24 @@ const recfield = function(ls, cc) {
let val = new expdesc();
if (ls.t.token === R.TK_NAME) {
- checklimit(fs, cc.nh, llimits.MAX_INT, defs.to_luastring("items in a constructor", true));
+ checklimit(fs, cc.nh, MAX_INT, to_luastring("items in a constructor", true));
checkname(ls, key);
} else /* ls->t.token === '[' */
yindex(ls, key);
cc.nh++;
- checknext(ls, char['=']);
- let rkkey = lcode.luaK_exp2RK(fs, key);
+ checknext(ls, 61 /* ('=').charCodeAt(0) */);
+ let rkkey = luaK_exp2RK(fs, key);
expr(ls, val);
- lcode.luaK_codeABC(fs, OpCodesI.OP_SETTABLE, cc.t.u.info, rkkey, lcode.luaK_exp2RK(fs, val));
+ luaK_codeABC(fs, OP_SETTABLE, cc.t.u.info, rkkey, luaK_exp2RK(fs, val));
fs.freereg = reg; /* free registers */
};
const closelistfield = function(fs, cc) {
if (cc.v.k === expkind.VVOID) return; /* there is no list item */
- lcode.luaK_exp2nextreg(fs, cc.v);
+ luaK_exp2nextreg(fs, cc.v);
cc.v.k = expkind.VVOID;
- if (cc.tostore === lopcodes.LFIELDS_PER_FLUSH) {
- lcode.luaK_setlist(fs, cc.t.u.info, cc.na, cc.tostore); /* flush */
+ if (cc.tostore === LFIELDS_PER_FLUSH) {
+ luaK_setlist(fs, cc.t.u.info, cc.na, cc.tostore); /* flush */
cc.tostore = 0; /* no more items pending */
}
};
@@ -677,20 +771,20 @@ const closelistfield = function(fs, cc) {
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, defs.LUA_MULTRET);
+ luaK_setmultret(fs, cc.v);
+ luaK_setlist(fs, cc.t.u.info, cc.na, LUA_MULTRET);
cc.na--; /* do not count last expression (unknown number of elements) */
} else {
if (cc.v.k !== expkind.VVOID)
- lcode.luaK_exp2nextreg(fs, cc.v);
- lcode.luaK_setlist(fs, cc.t.u.info, cc.na, cc.tostore);
+ luaK_exp2nextreg(fs, cc.v);
+ luaK_setlist(fs, cc.t.u.info, cc.na, cc.tostore);
}
};
const listfield = function(ls, cc) {
/* listfield -> exp */
expr(ls, cc.v);
- checklimit(ls.fs, cc.na, llimits.MAX_INT, defs.to_luastring("items in a constructor", true));
+ checklimit(ls.fs, cc.na, MAX_INT, to_luastring("items in a constructor", true));
cc.na++;
cc.tostore++;
};
@@ -699,13 +793,13 @@ const field = function(ls, cc) {
/* field -> listfield | recfield */
switch (ls.t.token) {
case R.TK_NAME: { /* may be 'listfield' or 'recfield' */
- if (llex.luaX_lookahead(ls) !== char['=']) /* expression? */
+ if (llex.luaX_lookahead(ls) !== 61 /* ('=').charCodeAt(0) */) /* expression? */
listfield(ls, cc);
else
recfield(ls, cc);
break;
}
- case char['[']: {
+ case 91 /* ('[').charCodeAt(0) */: {
recfield(ls, cc);
break;
}
@@ -721,24 +815,24 @@ const constructor = function(ls, t) {
sep -> ',' | ';' */
let fs = ls.fs;
let line = ls.linenumber;
- let pc = lcode.luaK_codeABC(fs, OpCodesI.OP_NEWTABLE, 0, 0, 0);
+ let pc = luaK_codeABC(fs, OP_NEWTABLE, 0, 0, 0);
let cc = new ConsControl();
cc.na = cc.nh = cc.tostore = 0;
cc.t = t;
init_exp(t, expkind.VRELOCABLE, pc);
init_exp(cc.v, expkind.VVOID, 0); /* no value (yet) */
- lcode.luaK_exp2nextreg(ls.fs, t); /* fix it at stack top */
- checknext(ls, char['{']);
+ luaK_exp2nextreg(ls.fs, t); /* fix it at stack top */
+ checknext(ls, 123 /* ('{').charCodeAt(0) */);
do {
- assert(cc.v.k === expkind.VVOID || cc.tostore > 0);
- if (ls.t.token === char['}']) break;
+ lua_assert(cc.v.k === expkind.VVOID || cc.tostore > 0);
+ if (ls.t.token === 125 /* ('}').charCodeAt(0) */) break;
closelistfield(fs, cc);
field(ls, cc);
- } while (testnext(ls, char[',']) || testnext(ls, char[';']));
- check_match(ls, char['}'], char['{'], line);
+ } while (testnext(ls, 44 /* (',').charCodeAt(0) */) || testnext(ls, 59 /* (';').charCodeAt(0) */));
+ check_match(ls, 125 /* ('}').charCodeAt(0) */, 123 /* ('{').charCodeAt(0) */, line);
lastlistfield(fs, cc);
- lopcodes.SETARG_B(fs.f.code[pc], lobject.luaO_int2fb(cc.na)); /* set initial array size */
- lopcodes.SETARG_C(fs.f.code[pc], lobject.luaO_int2fb(cc.nh)); /* set initial table size */
+ SETARG_B(fs.f.code[pc], lobject.luaO_int2fb(cc.na)); /* set initial array size */
+ SETARG_C(fs.f.code[pc], lobject.luaO_int2fb(cc.nh)); /* set initial table size */
};
/* }====================================================================== */
@@ -749,7 +843,7 @@ const parlist = function(ls) {
let f = fs.f;
let nparams = 0;
f.is_vararg = false;
- if (ls.t.token !== char[')']) { /* is 'parlist' not empty? */
+ if (ls.t.token !== 41 /* (')').charCodeAt(0) */) { /* is 'parlist' not empty? */
do {
switch (ls.t.token) {
case R.TK_NAME: { /* param -> NAME */
@@ -762,13 +856,13 @@ const parlist = function(ls) {
f.is_vararg = true; /* declared vararg */
break;
}
- default: llex.luaX_syntaxerror(ls, defs.to_luastring("<name> or '...' expected", true));
+ default: llex.luaX_syntaxerror(ls, to_luastring("<name> or '...' expected", true));
}
- } while(!f.is_vararg && testnext(ls, char[',']));
+ } while(!f.is_vararg && testnext(ls, 44 /* (',').charCodeAt(0) */));
}
adjustlocalvars(ls, nparams);
f.numparams = fs.nactvar;
- lcode.luaK_reserveregs(fs, fs.nactvar); /* reserve register for parameters */
+ luaK_reserveregs(fs, fs.nactvar); /* reserve register for parameters */
};
const body = function(ls, e, ismethod, line) {
@@ -778,13 +872,13 @@ const body = function(ls, e, ismethod, line) {
new_fs.f = addprototype(ls);
new_fs.f.linedefined = line;
open_func(ls, new_fs, bl);
- checknext(ls, char['(']);
+ checknext(ls, 40 /* ('(').charCodeAt(0) */);
if (ismethod) {
new_localvarliteral(ls, "self"); /* create 'self' parameter */
adjustlocalvars(ls, 1);
}
parlist(ls);
- checknext(ls, char[')']);
+ checknext(ls, 41 /* (')').charCodeAt(0) */);
statlist(ls);
new_fs.f.lastlinedefined = ls.linenumber;
check_match(ls, R.TK_END, R.TK_FUNCTION, line);
@@ -796,8 +890,8 @@ const explist = function(ls, v) {
/* explist -> expr { ',' expr } */
let n = 1; /* at least one expression */
expr(ls, v);
- while (testnext(ls, char[','])) {
- lcode.luaK_exp2nextreg(ls.fs, v);
+ while (testnext(ls, 44 /* (',').charCodeAt(0) */)) {
+ luaK_exp2nextreg(ls.fs, v);
expr(ls, v);
n++;
}
@@ -808,18 +902,18 @@ const funcargs = function(ls, f, line) {
let fs = ls.fs;
let args = new expdesc();
switch (ls.t.token) {
- case char['(']: { /* funcargs -> '(' [ explist ] ')' */
+ case 40 /* ('(').charCodeAt(0) */: { /* funcargs -> '(' [ explist ] ')' */
llex.luaX_next(ls);
- if (ls.t.token === char[')']) /* arg list is empty? */
+ if (ls.t.token === 41 /* (')').charCodeAt(0) */) /* arg list is empty? */
args.k = expkind.VVOID;
else {
explist(ls, args);
- lcode.luaK_setmultret(fs, args);
+ luaK_setmultret(fs, args);
}
- check_match(ls, char[')'], char['('], line);
+ check_match(ls, 41 /* (')').charCodeAt(0) */, 40 /* ('(').charCodeAt(0) */, line);
break;
}
- case char['{']: { /* funcargs -> constructor */
+ case 123 /* ('{').charCodeAt(0) */: { /* funcargs -> constructor */
constructor(ls, args);
break;
}
@@ -829,21 +923,21 @@ const funcargs = function(ls, f, line) {
break;
}
default: {
- llex.luaX_syntaxerror(ls, defs.to_luastring("function arguments expected", true));
+ llex.luaX_syntaxerror(ls, to_luastring("function arguments expected", true));
}
}
- assert(f.k === expkind.VNONRELOC);
+ lua_assert(f.k === expkind.VNONRELOC);
let nparams;
let base = f.u.info; /* base register for call */
if (hasmultret(args.k))
- nparams = defs.LUA_MULTRET; /* open call */
+ nparams = LUA_MULTRET; /* open call */
else {
if (args.k !== expkind.VVOID)
- lcode.luaK_exp2nextreg(fs, args); /* close last argument */
+ luaK_exp2nextreg(fs, args); /* close last argument */
nparams = fs.freereg - (base+1);
}
- init_exp(f, expkind.VCALL, lcode.luaK_codeABC(fs, OpCodesI.OP_CALL, base, nparams+1, 2));
- lcode.luaK_fixline(fs, line);
+ init_exp(f, expkind.VCALL, luaK_codeABC(fs, OP_CALL, base, nparams+1, 2));
+ luaK_fixline(fs, line);
fs.freereg = base + 1; /* call remove function and arguments and leaves (unless changed) one result */
};
@@ -856,12 +950,12 @@ const funcargs = function(ls, f, line) {
const primaryexp = function(ls, v) {
/* primaryexp -> NAME | '(' expr ')' */
switch (ls.t.token) {
- case char['(']: {
+ case 40 /* ('(').charCodeAt(0) */: {
let line = ls.linenumber;
llex.luaX_next(ls);
expr(ls, v);
- check_match(ls, char[')'], char['('], line);
- lcode.luaK_dischargevars(ls.fs, v);
+ check_match(ls, 41 /* (')').charCodeAt(0) */, 40 /* ('(').charCodeAt(0) */, line);
+ luaK_dischargevars(ls.fs, v);
return;
}
case R.TK_NAME: {
@@ -869,7 +963,7 @@ const primaryexp = function(ls, v) {
return;
}
default: {
- llex.luaX_syntaxerror(ls, defs.to_luastring("unexpected symbol", true));
+ llex.luaX_syntaxerror(ls, to_luastring("unexpected symbol", true));
}
}
};
@@ -882,27 +976,27 @@ const suffixedexp = function(ls, v) {
primaryexp(ls, v);
for (;;) {
switch (ls.t.token) {
- case char['.']: { /* fieldsel */
+ case 46 /* ('.').charCodeAt(0) */: { /* fieldsel */
fieldsel(ls, v);
break;
}
- case char['[']: { /* '[' exp1 ']' */
+ case 91 /* ('[').charCodeAt(0) */: { /* '[' exp1 ']' */
let key = new expdesc();
- lcode.luaK_exp2anyregup(fs, v);
+ luaK_exp2anyregup(fs, v);
yindex(ls, key);
- lcode.luaK_indexed(fs, v, key);
+ luaK_indexed(fs, v, key);
break;
}
- case char[':']: { /* ':' NAME funcargs */
+ case 58 /* (':').charCodeAt(0) */: { /* ':' NAME funcargs */
let key = new expdesc();
llex.luaX_next(ls);
checkname(ls, key);
- lcode.luaK_self(fs, v, key);
+ luaK_self(fs, v, key);
funcargs(ls, v, line);
break;
}
- case char['(']: case R.TK_STRING: case char['{']: { /* funcargs */
- lcode.luaK_exp2nextreg(fs, v);
+ case 40 /* ('(').charCodeAt(0) */: case R.TK_STRING: case 123 /* ('{').charCodeAt(0) */: { /* funcargs */
+ luaK_exp2nextreg(fs, v);
funcargs(ls, v, line);
break;
}
@@ -943,11 +1037,11 @@ const simpleexp = function(ls, v) {
}
case R.TK_DOTS: { /* vararg */
let fs = ls.fs;
- 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));
+ check_condition(ls, fs.f.is_vararg, to_luastring("cannot use '...' outside a vararg function", true));
+ init_exp(v, expkind.VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 1, 0));
break;
}
- case char['{']: { /* constructor */
+ case 123 /* ('{').charCodeAt(0) */: { /* constructor */
constructor(ls, v);
return;
}
@@ -966,38 +1060,38 @@ const simpleexp = function(ls, v) {
const getunopr = function(op) {
switch (op) {
- case R.TK_NOT: return UnOpr.OPR_NOT;
- case char['-']: return UnOpr.OPR_MINUS;
- case char['~']: return UnOpr.OPR_BNOT;
- case char['#']: return UnOpr.OPR_LEN;
- default: return UnOpr.OPR_NOUNOPR;
+ case R.TK_NOT: return OPR_NOT;
+ case 45 /* ('-').charCodeAt(0) */: return OPR_MINUS;
+ case 126 /* ('~').charCodeAt(0) */: return OPR_BNOT;
+ case 35 /* ('#').charCodeAt(0) */: return OPR_LEN;
+ default: return OPR_NOUNOPR;
}
};
const getbinopr = function(op) {
switch (op) {
- case char['+']: return BinOpr.OPR_ADD;
- case char['-']: return BinOpr.OPR_SUB;
- case char['*']: return BinOpr.OPR_MUL;
- case char['%']: return BinOpr.OPR_MOD;
- case char['^']: return BinOpr.OPR_POW;
- case char['/']: return BinOpr.OPR_DIV;
- case R.TK_IDIV: return BinOpr.OPR_IDIV;
- case char['&']: return BinOpr.OPR_BAND;
- case char['|']: return BinOpr.OPR_BOR;
- case char['~']: return BinOpr.OPR_BXOR;
- case R.TK_SHL: return BinOpr.OPR_SHL;
- case R.TK_SHR: return BinOpr.OPR_SHR;
- case R.TK_CONCAT: return BinOpr.OPR_CONCAT;
- case R.TK_NE: return BinOpr.OPR_NE;
- case R.TK_EQ: return BinOpr.OPR_EQ;
- case char['<']: return BinOpr.OPR_LT;
- case R.TK_LE: return BinOpr.OPR_LE;
- case char['>']: return BinOpr.OPR_GT;
- case R.TK_GE: return BinOpr.OPR_GE;
- case R.TK_AND: return BinOpr.OPR_AND;
- case R.TK_OR: return BinOpr.OPR_OR;
- default: return BinOpr.OPR_NOBINOPR;
+ case 43 /* ('+').charCodeAt(0) */: return OPR_ADD;
+ case 45 /* ('-').charCodeAt(0) */: return OPR_SUB;
+ case 42 /* ('*').charCodeAt(0) */: return OPR_MUL;
+ case 37 /* ('%').charCodeAt(0) */: return OPR_MOD;
+ case 94 /* ('^').charCodeAt(0) */: return OPR_POW;
+ case 47 /* ('/').charCodeAt(0) */: return OPR_DIV;
+ case R.TK_IDIV: return OPR_IDIV;
+ case 38 /* ('&').charCodeAt(0) */: return OPR_BAND;
+ case 124 /* ('|').charCodeAt(0) */: return OPR_BOR;
+ case 126 /* ('~').charCodeAt(0) */: return OPR_BXOR;
+ case R.TK_SHL: return OPR_SHL;
+ case R.TK_SHR: return OPR_SHR;
+ case R.TK_CONCAT: return OPR_CONCAT;
+ case R.TK_NE: return OPR_NE;
+ case R.TK_EQ: return OPR_EQ;
+ case 60 /* ('<').charCodeAt(0) */: return OPR_LT;
+ case R.TK_LE: return OPR_LE;
+ case 62 /* ('>').charCodeAt(0) */: return OPR_GT;
+ case R.TK_GE: return OPR_GE;
+ case R.TK_AND: return OPR_AND;
+ case R.TK_OR: return OPR_OR;
+ default: return OPR_NOBINOPR;
}
};
@@ -1023,23 +1117,23 @@ const UNARY_PRIORITY = 12;
const subexpr = function(ls, v, limit) {
enterlevel(ls);
let uop = getunopr(ls.t.token);
- if (uop !== UnOpr.OPR_NOUNOPR) {
+ if (uop !== OPR_NOUNOPR) {
let line = ls.linenumber;
llex.luaX_next(ls);
subexpr(ls, v, UNARY_PRIORITY);
- lcode.luaK_prefix(ls.fs, uop, v, line);
+ luaK_prefix(ls.fs, uop, v, line);
} else
simpleexp(ls, v);
/* expand while operators have priorities higher than 'limit' */
let op = getbinopr(ls.t.token);
- while (op !== BinOpr.OPR_NOBINOPR && priority[op].left > limit) {
+ while (op !== OPR_NOBINOPR && priority[op].left > limit) {
let v2 = new expdesc();
let line = ls.linenumber;
llex.luaX_next(ls);
- lcode.luaK_infix(ls.fs, op, v);
+ luaK_infix(ls.fs, op, v);
/* read sub-expression with higher priority */
let nextop = subexpr(ls, v2, priority[op].right);
- lcode.luaK_posfix(ls.fs, op, v, v2, line);
+ luaK_posfix(ls.fs, op, v, v2, line);
op = nextop;
}
leavelevel(ls);
@@ -1107,36 +1201,36 @@ const check_conflict = function(ls, lh, v) {
}
if (conflict) {
/* copy upvalue/local value to a temporary (in position 'extra') */
- let op = v.k === expkind.VLOCAL ? OpCodesI.OP_MOVE : OpCodesI.OP_GETUPVAL;
- lcode.luaK_codeABC(fs, op, extra, v.u.info, 0);
- lcode.luaK_reserveregs(fs, 1);
+ let op = v.k === expkind.VLOCAL ? OP_MOVE : OP_GETUPVAL;
+ luaK_codeABC(fs, op, extra, v.u.info, 0);
+ luaK_reserveregs(fs, 1);
}
};
const assignment = function(ls, lh, nvars) {
let e = new expdesc();
- check_condition(ls, vkisvar(lh.v.k), defs.to_luastring("syntax error", true));
- if (testnext(ls, char[','])) { /* assignment -> ',' suffixedexp assignment */
+ check_condition(ls, vkisvar(lh.v.k), to_luastring("syntax error", true));
+ if (testnext(ls, 44 /* (',').charCodeAt(0) */)) { /* 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, llimits.LUAI_MAXCCALLS, defs.to_luastring("JS levels", true));
+ checklimit(ls.fs, nvars + ls.L.nCcalls, LUAI_MAXCCALLS, to_luastring("JS levels", true));
assignment(ls, nv, nvars + 1);
} else { /* assignment -> '=' explist */
- checknext(ls, char['=']);
+ checknext(ls, 61 /* ('=').charCodeAt(0) */);
let nexps = explist(ls, e);
if (nexps !== nvars)
adjust_assign(ls, nvars, nexps, e);
else {
- lcode.luaK_setoneret(ls.fs, e); /* close last expression */
- lcode.luaK_storevar(ls.fs, lh.v, e);
+ luaK_setoneret(ls.fs, e); /* close last expression */
+ luaK_storevar(ls.fs, lh.v, e);
return; /* avoid default */
}
}
init_exp(e, expkind.VNONRELOC, ls.fs.freereg-1); /* default assignment */
- lcode.luaK_storevar(ls.fs, lh.v, e);
+ luaK_storevar(ls.fs, lh.v, e);
};
const cond = function(ls) {
@@ -1144,7 +1238,7 @@ const cond = function(ls) {
let v = new expdesc();
expr(ls, v); /* read condition */
if (v.k === expkind.VNIL) v.k = expkind.VFALSE; /* 'falses' are all equal here */
- lcode.luaK_goiftrue(ls.fs, v);
+ luaK_goiftrue(ls.fs, v);
return v.f;
};
@@ -1155,7 +1249,7 @@ const gotostat = function(ls, pc) {
label = str_checkname(ls);
else {
llex.luaX_next(ls); /* skip break */
- label = lstring.luaS_newliteral(ls.L, "break");
+ label = luaS_newliteral(ls.L, "break");
}
let g = newlabelentry(ls, ls.dyd.gt, label, line, pc);
findlabel(ls, g); /* close it if label already defined */
@@ -1166,7 +1260,7 @@ const checkrepeated = function(fs, ll, label) {
for (let i = fs.bl.firstlabel; i < ll.n; i++) {
if (eqstr(label, ll.arr[i].name)) {
let msg = lobject.luaO_pushfstring(fs.ls.L,
- defs.to_luastring("label '%s' already defined on line %d", true),
+ to_luastring("label '%s' already defined on line %d", true),
label.getstr(), ll.arr[i].line);
semerror(fs.ls, msg);
}
@@ -1175,7 +1269,7 @@ const checkrepeated = function(fs, ll, label) {
/* skip no-op statements */
const skipnoopstat = function(ls) {
- while (ls.t.token === char[';'] || ls.t.token === R.TK_DBCOLON)
+ while (ls.t.token === 59 /* (';').charCodeAt(0) */ || ls.t.token === R.TK_DBCOLON)
statement(ls);
};
@@ -1187,7 +1281,7 @@ const labelstat = function(ls, label, line) {
checkrepeated(fs, ll, label); /* check for repeated labels */
checknext(ls, R.TK_DBCOLON); /* skip double colon */
/* create new entry for this label */
- l = newlabelentry(ls, ll, label, line, lcode.luaK_getlabel(fs));
+ l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));
skipnoopstat(ls); /* skip other no-op statements */
if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
/* assume that locals are already out of scope */
@@ -1201,21 +1295,21 @@ const whilestat = function(ls, line) {
let fs = ls.fs;
let bl = new BlockCnt();
llex.luaX_next(ls); /* skip WHILE */
- let whileinit = lcode.luaK_getlabel(fs);
+ let whileinit = luaK_getlabel(fs);
let condexit = cond(ls);
enterblock(fs, bl, 1);
checknext(ls, R.TK_DO);
block(ls);
- lcode.luaK_jumpto(fs, whileinit);
+ luaK_jumpto(fs, whileinit);
check_match(ls, R.TK_END, R.TK_WHILE, line);
leaveblock(fs);
- lcode.luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
+ luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
};
const repeatstat = function(ls, line) {
/* repeatstat -> REPEAT block UNTIL cond */
let fs = ls.fs;
- let repeat_init = lcode.luaK_getlabel(fs);
+ let repeat_init = luaK_getlabel(fs);
let bl1 = new BlockCnt();
let bl2 = new BlockCnt();
enterblock(fs, bl1, 1); /* loop block */
@@ -1225,17 +1319,17 @@ const repeatstat = function(ls, line) {
check_match(ls, R.TK_UNTIL, R.TK_REPEAT, line);
let condexit = cond(ls); /* read condition (inside scope block) */
if (bl2.upval) /* upvalues? */
- lcode.luaK_patchclose(fs, condexit, bl2.nactvar);
+ luaK_patchclose(fs, condexit, bl2.nactvar);
leaveblock(fs); /* finish scope */
- lcode.luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
+ luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
leaveblock(fs); /* finish loop */
};
const exp1 = function(ls) {
let e = new expdesc();
expr(ls, e);
- lcode.luaK_exp2nextreg(ls.fs, e);
- assert(e.k === expkind.VNONRELOC);
+ luaK_exp2nextreg(ls.fs, e);
+ lua_assert(e.k === expkind.VNONRELOC);
let reg = e.u.info;
return reg;
};
@@ -1247,22 +1341,22 @@ const forbody = function(ls, base, line, nvars, isnum) {
let endfor;
adjustlocalvars(ls, 3); /* control variables */
checknext(ls, R.TK_DO);
- let prep = isnum ? lcode.luaK_codeAsBx(fs, OpCodesI.OP_FORPREP, base, lcode.NO_JUMP) : lcode.luaK_jump(fs);
+ let prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
enterblock(fs, bl, 0); /* scope for declared variables */
adjustlocalvars(ls, nvars);
- lcode.luaK_reserveregs(fs, nvars);
+ luaK_reserveregs(fs, nvars);
block(ls);
leaveblock(fs); /* end of scope for declared variables */
- lcode.luaK_patchtohere(fs, prep);
+ luaK_patchtohere(fs, prep);
if (isnum) /* end of scope for declared variables */
- endfor = lcode.luaK_codeAsBx(fs, OpCodesI.OP_FORLOOP, base, lcode.NO_JUMP);
+ endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);
else { /* generic for */
- lcode.luaK_codeABC(fs, OpCodesI.OP_TFORCALL, base, 0, nvars);
- lcode.luaK_fixline(fs, line);
- endfor = lcode.luaK_codeAsBx(fs, OpCodesI.OP_TFORLOOP, base + 2, lcode.NO_JUMP);
+ luaK_codeABC(fs, OP_TFORCALL, base, 0, nvars);
+ luaK_fixline(fs, line);
+ endfor = luaK_codeAsBx(fs, OP_TFORLOOP, base + 2, NO_JUMP);
}
- lcode.luaK_patchlist(fs, endfor, prep + 1);
- lcode.luaK_fixline(fs, line);
+ luaK_patchlist(fs, endfor, prep + 1);
+ luaK_fixline(fs, line);
};
const fornum = function(ls, varname, line) {
@@ -1273,15 +1367,15 @@ const fornum = function(ls, varname, line) {
new_localvarliteral(ls, "(for limit)");
new_localvarliteral(ls, "(for step)");
new_localvar(ls, varname);
- checknext(ls, char['=']);
+ checknext(ls, 61 /* ('=').charCodeAt(0) */);
exp1(ls); /* initial value */
- checknext(ls, char[',']);
+ checknext(ls, 44 /* (',').charCodeAt(0) */);
exp1(ls); /* limit */
- if (testnext(ls, char[',']))
+ if (testnext(ls, 44 /* (',').charCodeAt(0) */))
exp1(ls); /* optional step */
else { /* default step = 1 */
- lcode.luaK_codek(fs, fs.freereg, lcode.luaK_intK(fs, 1));
- lcode.luaK_reserveregs(fs, 1);
+ luaK_codek(fs, fs.freereg, luaK_intK(fs, 1));
+ luaK_reserveregs(fs, 1);
}
forbody(ls, base, line, 1, 1);
};
@@ -1298,14 +1392,14 @@ const forlist = function(ls, indexname) {
new_localvarliteral(ls, "(for control)");
/* create declared variables */
new_localvar(ls, indexname);
- while (testnext(ls, char[','])) {
+ while (testnext(ls, 44 /* (',').charCodeAt(0) */)) {
new_localvar(ls, str_checkname(ls));
nvars++;
}
checknext(ls, R.TK_IN);
let line = ls.linenumber;
adjust_assign(ls, 3, explist(ls, e), e);
- lcode.luaK_checkstack(fs, 3); /* extra space to call generator */
+ luaK_checkstack(fs, 3); /* extra space to call generator */
forbody(ls, base, line, nvars - 3, 0);
};
@@ -1317,9 +1411,9 @@ const forstat = function(ls, line) {
llex.luaX_next(ls); /* skip 'for' */
let varname = str_checkname(ls); /* first variable name */
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, defs.to_luastring("'=' or 'in' expected", true));
+ case 61 /* ('=').charCodeAt(0) */: fornum(ls, varname, line); break;
+ case 44 /* (',').charCodeAt(0) */: case R.TK_IN: forlist(ls, varname); break;
+ default: llex.luaX_syntaxerror(ls, 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) */
@@ -1337,17 +1431,17 @@ const test_then_block = function(ls, escapelist) {
checknext(ls, R.TK_THEN);
if (ls.t.token === R.TK_GOTO || ls.t.token === R.TK_BREAK) {
- lcode.luaK_goiffalse(ls.fs, v); /* will jump to label if condition is true */
+ luaK_goiffalse(ls.fs, v); /* will jump to label if condition is true */
enterblock(fs, bl, false); /* must enter block before 'goto' */
gotostat(ls, v.t); /* handle goto/break */
- while (testnext(ls, char[';'])); /* skip colons */
+ while (testnext(ls, 59 /* (';').charCodeAt(0) */)); /* skip colons */
if (block_follow(ls, 0)) { /* 'goto' is the entire block? */
leaveblock(fs);
return escapelist; /* and that is it */
} else /* must skip over 'then' part if condition is false */
- jf = lcode.luaK_jump(fs);
+ jf = luaK_jump(fs);
} else { /* regular case (not goto/break) */
- lcode.luaK_goiftrue(ls.fs, v); /* skip over block if condition is false */
+ luaK_goiftrue(ls.fs, v); /* skip over block if condition is false */
enterblock(fs, bl, false);
jf = v.f;
}
@@ -1355,8 +1449,8 @@ const test_then_block = function(ls, escapelist) {
statlist(ls); /* 'then' part */
leaveblock(fs);
if (ls.t.token === R.TK_ELSE || ls.t.token === R.TK_ELSEIF) /* followed by 'else'/'elseif'? */
- escapelist = lcode.luaK_concat(fs, escapelist, lcode.luaK_jump(fs)); /* must jump over it */
- lcode.luaK_patchtohere(fs, jf);
+ escapelist = luaK_concat(fs, escapelist, luaK_jump(fs)); /* must jump over it */
+ luaK_patchtohere(fs, jf);
return escapelist;
};
@@ -1364,14 +1458,14 @@ const test_then_block = function(ls, escapelist) {
const ifstat = function(ls, line) {
/* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */
let fs = ls.fs;
- let escapelist = lcode.NO_JUMP; /* exit list for finished parts */
+ let escapelist = NO_JUMP; /* exit list for finished parts */
escapelist = test_then_block(ls, escapelist); /* IF cond THEN block */
while (ls.t.token === R.TK_ELSEIF)
escapelist = test_then_block(ls, escapelist); /* ELSEIF cond THEN block */
if (testnext(ls, R.TK_ELSE))
block(ls); /* 'else' part */
check_match(ls, R.TK_END, R.TK_IF, line);
- lcode.luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
+ luaK_patchtohere(fs, escapelist); /* patch escape list to 'if' end */
};
const localfunc = function(ls) {
@@ -1392,8 +1486,8 @@ const localstat = function(ls) {
do {
new_localvar(ls, str_checkname(ls));
nvars++;
- } while (testnext(ls, char[',']));
- if (testnext(ls, char['=']))
+ } while (testnext(ls, 44 /* (',').charCodeAt(0) */));
+ if (testnext(ls, 61 /* ('=').charCodeAt(0) */))
nexps = explist(ls, e);
else {
e.k = expkind.VVOID;
@@ -1407,9 +1501,9 @@ const funcname = function(ls, v) {
/* funcname -> NAME {fieldsel} [':' NAME] */
let ismethod = 0;
singlevar(ls, v);
- while (ls.t.token === char['.'])
+ while (ls.t.token === 46 /* ('.').charCodeAt(0) */)
fieldsel(ls, v);
- if (ls.t.token === char[':']) {
+ if (ls.t.token === 58 /* (':').charCodeAt(0) */) {
ismethod = 1;
fieldsel(ls, v);
}
@@ -1423,8 +1517,8 @@ const funcstat = function(ls, line) {
llex.luaX_next(ls); /* skip FUNCTION */
let ismethod = funcname(ls, v);
body(ls, b, ismethod, line);
- lcode.luaK_storevar(ls.fs, v, b);
- lcode.luaK_fixline(ls.fs, line); /* definition "happens" in the first line */
+ luaK_storevar(ls.fs, v, b);
+ luaK_fixline(ls.fs, line); /* definition "happens" in the first line */
};
const exprstat= function(ls) {
@@ -1432,13 +1526,13 @@ const exprstat= function(ls) {
let fs = ls.fs;
let v = new LHS_assign();
suffixedexp(ls, v.v);
- if (ls.t.token === char['='] || ls.t.token === char[',']) { /* stat . assignment ? */
+ if (ls.t.token === 61 /* ('=').charCodeAt(0) */ || ls.t.token === 44 /* (',').charCodeAt(0) */) { /* stat . assignment ? */
v.prev = null;
assignment(ls, v, 1);
}
else { /* stat -> func */
- check_condition(ls, v.v.k === expkind.VCALL, defs.to_luastring("syntax error", true));
- lopcodes.SETARG_C(lcode.getinstruction(fs, v.v), 1); /* call statement uses no results */
+ check_condition(ls, v.v.k === expkind.VCALL, to_luastring("syntax error", true));
+ SETARG_C(getinstruction(fs, v.v), 1); /* call statement uses no results */
}
};
@@ -1447,37 +1541,37 @@ const retstat = function(ls) {
let fs = ls.fs;
let e = new expdesc();
let first, nret; /* registers with returned values */
- if (block_follow(ls, 1) || ls.t.token === char[';'])
+ if (block_follow(ls, 1) || ls.t.token === 59 /* (';').charCodeAt(0) */)
first = nret = 0; /* return no values */
else {
nret = explist(ls, e); /* optional return values */
if (hasmultret(e.k)) {
- lcode.luaK_setmultret(fs, e);
+ luaK_setmultret(fs, e);
if (e.k === expkind.VCALL && nret === 1) { /* tail call? */
- lopcodes.SET_OPCODE(lcode.getinstruction(fs, e), OpCodesI.OP_TAILCALL);
- assert(lcode.getinstruction(fs, e).A === fs.nactvar);
+ SET_OPCODE(getinstruction(fs, e), OP_TAILCALL);
+ lua_assert(getinstruction(fs, e).A === fs.nactvar);
}
first = fs.nactvar;
- nret = defs.LUA_MULTRET; /* return all values */
+ nret = LUA_MULTRET; /* return all values */
} else {
if (nret === 1) /* only one single value? */
- first = lcode.luaK_exp2anyreg(fs, e);
+ first = luaK_exp2anyreg(fs, e);
else {
- lcode.luaK_exp2nextreg(fs, e); /* values must go to the stack */
+ luaK_exp2nextreg(fs, e); /* values must go to the stack */
first = fs.nactvar; /* return all active values */
- assert(nret === fs.freereg - first);
+ lua_assert(nret === fs.freereg - first);
}
}
}
- lcode.luaK_ret(fs, first, nret);
- testnext(ls, char[';']); /* skip optional semicolon */
+ luaK_ret(fs, first, nret);
+ testnext(ls, 59 /* (';').charCodeAt(0) */); /* skip optional semicolon */
};
const statement = function(ls) {
let line = ls.linenumber; /* may be needed for error messages */
enterlevel(ls);
switch(ls.t.token) {
- case char[';']: { /* stat -> ';' (empty statement) */
+ case 59 /* (';').charCodeAt(0) */: { /* stat -> ';' (empty statement) */
llex.luaX_next(ls); /* skip ';' */
break;
}
@@ -1527,7 +1621,7 @@ const statement = function(ls) {
}
case R.TK_BREAK: /* stat -> breakstat */
case R.TK_GOTO: { /* stat -> 'goto' NAME */
- gotostat(ls, lcode.luaK_jump(ls.fs));
+ gotostat(ls, luaK_jump(ls.fs));
break;
}
default: { /* stat -> func | assignment */
@@ -1535,8 +1629,7 @@ const statement = function(ls) {
break;
}
}
-
- assert(ls.fs.f.maxstacksize >= ls.fs.freereg && ls.fs.freereg >= ls.fs.nactvar);
+ lua_assert(ls.fs.f.maxstacksize >= ls.fs.freereg && ls.fs.freereg >= ls.fs.nactvar);
ls.fs.freereg = ls.fs.nactvar; /* free registers */
leavelevel(ls);
};
@@ -1568,15 +1661,15 @@ const luaY_parser = function(L, z, buff, dyd, name, firstchar) {
ldo.luaD_inctop(L);
L.stack[L.top-1].sethvalue(lexstate.h);
funcstate.f = cl.p = new Proto(L);
- funcstate.f.source = lstring.luaS_new(L, name);
+ funcstate.f.source = luaS_new(L, name);
lexstate.buff = buff;
lexstate.dyd = dyd;
dyd.actvar.n = dyd.gt.n = dyd.label.n = 0;
llex.luaX_setinput(L, lexstate, z, funcstate.f.source, firstchar);
mainfunc(lexstate, funcstate);
- assert(!funcstate.prev && funcstate.nups === 1 && !lexstate.fs);
+ lua_assert(!funcstate.prev && funcstate.nups === 1 && !lexstate.fs);
/* all scopes should be correctly finished */
- assert(dyd.actvar.n === 0 && dyd.gt.n === 0 && dyd.label.n === 0);
+ lua_assert(dyd.actvar.n === 0 && dyd.gt.n === 0 && dyd.label.n === 0);
delete L.stack[--L.top]; /* remove scanner's table */
return cl; /* closure is on the stack, too */
};