summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lapi.js20
-rw-r--r--src/ldo.js8
-rw-r--r--src/llex.js19
-rw-r--r--src/lobject.js9
-rw-r--r--src/lparser.js14
-rw-r--r--src/ltable.js11
-rw-r--r--src/ltm.js55
-rw-r--r--src/lundump.js6
-rw-r--r--src/lvm.js14
9 files changed, 92 insertions, 64 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 1b10e29..4218338 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -11,7 +11,11 @@ const ldump = require('./ldump.js');
const lfunc = require('./lfunc.js');
const lobject = require('./lobject.js');
const lstate = require('./lstate.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_bless,
+ luaS_new,
+ luaS_newliteral
+} = require('./lstring.js');
const ltm = require('./ltm.js');
const luaconf = require('./luaconf.js');
const lvm = require('./lvm.js');
@@ -242,11 +246,11 @@ const lua_pushlstring = function(L, s, len) {
let ts;
if (len === 0) {
s = defs.to_luastring("", true);
- ts = lstring.luaS_bless(L, s);
+ ts = luaS_bless(L, s);
} else {
s = defs.from_userstring(s);
api_check(L, s.length >= len, "invalid length to lua_pushlstring");
- ts = lstring.luaS_new(L, s.subarray(0, len));
+ ts = luaS_new(L, s.subarray(0, len));
}
lobject.pushsvalue2s(L, ts);
api_check(L, L.top <= L.ci.top, "stack overflow");
@@ -258,7 +262,7 @@ const lua_pushstring = function (L, s) {
L.stack[L.top] = new TValue(CT.LUA_TNIL, null);
L.top++;
} else {
- let ts = lstring.luaS_new(L, defs.from_userstring(s));
+ let ts = luaS_new(L, defs.from_userstring(s));
lobject.pushsvalue2s(L, ts);
s = ts.getstr(); /* internal copy */
}
@@ -283,7 +287,7 @@ const lua_pushliteral = function (L, s) {
L.top++;
} else {
fengari_argcheck(typeof s === "string", "lua_pushliteral expects a JS string");
- let ts = lstring.luaS_newliteral(L, s);
+ let ts = luaS_newliteral(L, s);
lobject.pushsvalue2s(L, ts);
s = ts.getstr(); /* internal copy */
}
@@ -347,7 +351,7 @@ const lua_pushglobaltable = function(L) {
** t[k] = value at the top of the stack (where 'k' is a string)
*/
const auxsetstr = function(L, t, k) {
- let str = lstring.luaS_new(L, defs.from_userstring(k));
+ let str = luaS_new(L, defs.from_userstring(k));
api_checknelems(L, 1);
lobject.pushsvalue2s(L, str); /* push 'str' (to make it a TValue) */
api_check(L, L.top <= L.ci.top, "stack overflow");
@@ -457,7 +461,7 @@ const lua_rawsetp = function(L, idx, p) {
*/
const auxgetstr = function(L, t, k) {
- let str = lstring.luaS_new(L, defs.from_userstring(k));
+ let str = luaS_new(L, defs.from_userstring(k));
lobject.pushsvalue2s(L, str);
api_check(L, L.top <= L.ci.top, "stack overflow");
lvm.luaV_gettable(L, t, L.stack[L.top - 1], L.top - 1);
@@ -1033,7 +1037,7 @@ const lua_concat = function(L, n) {
if (n >= 2)
lvm.luaV_concat(L, n);
else if (n === 0) {
- lobject.pushsvalue2s(L, lstring.luaS_bless(L, defs.to_luastring("", true)));
+ lobject.pushsvalue2s(L, luaS_bless(L, defs.to_luastring("", true)));
api_check(L, L.top <= L.ci.top, "stack overflow");
}
};
diff --git a/src/ldo.js b/src/ldo.js
index c38d6c7..efb3d51 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -13,7 +13,7 @@ const lobject = require('./lobject.js');
const lopcodes = require('./lopcodes.js');
const lparser = require('./lparser.js');
const lstate = require('./lstate.js');
-const lstring = require('./lstring.js');
+const { luaS_newliteral } = require('./lstring.js');
const ltm = require('./ltm.js');
const luaconf = require('./luaconf.js');
const lundump = require('./lundump.js');
@@ -42,11 +42,11 @@ const seterrorobj = function(L, errcode, oldtop) {
switch (errcode) {
case TS.LUA_ERRMEM: {
- lobject.setsvalue2s(L, oldtop, lstring.luaS_newliteral(L, "not enough memory"));
+ lobject.setsvalue2s(L, oldtop, luaS_newliteral(L, "not enough memory"));
break;
}
case TS.LUA_ERRERR: {
- lobject.setsvalue2s(L, oldtop, lstring.luaS_newliteral(L, "error in error handling"));
+ lobject.setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
break;
}
default: {
@@ -506,7 +506,7 @@ const recover = function(L, status) {
** coroutine error handler and should not kill the coroutine.)
*/
const resume_error = function(L, msg, narg) {
- let ts = lstring.luaS_newliteral(L, msg);
+ let ts = luaS_newliteral(L, msg);
if (narg === 0) {
lobject.pushsvalue2s(L, ts);
api_check(L, L.top <= L.ci.top, "stack overflow");
diff --git a/src/llex.js b/src/llex.js
index a838158..257042f 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -11,7 +11,12 @@ const ldebug = require('./ldebug.js');
const ldo = require('./ldo.js');
const ljstype = require('./ljstype.js');
const lobject = require('./lobject.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_bless,
+ luaS_hash,
+ luaS_hashlongstr,
+ luaS_new
+} = require('./lstring.js');
const ltable = require('./ltable.js');
const llimits = require('./llimits.js');
const lzio = require('./lzio.js');
@@ -152,13 +157,13 @@ const save_and_next = function(ls) {
*/
const luaX_newstring = function(ls, str) {
let L = ls.L;
- let ts = lstring.luaS_new(L, str);
+ let ts = luaS_new(L, str);
let o = ltable.luaH_set(L, ls.h, new lobject.TValue(LUA_TLNGSTR, ts));
if (o.ttisnil()) { /* not in use yet? */
o.setbvalue(true);
} else { /* string already present */
/* HACK: Workaround lack of ltable 'keyfromval' */
- let tpair = ls.h.strong.get(lstring.luaS_hashlongstr(ts));
+ let tpair = ls.h.strong.get(luaS_hashlongstr(ts));
lua_assert(tpair.value == o); /* fengari addition */
ts = tpair.key.tsvalue(); /* re-use value previously stored */
}
@@ -195,7 +200,7 @@ const luaX_setinput = function(L, ls, z, source, firstchar) {
ls.linenumber = 1;
ls.lastline = 1;
ls.source = source;
- ls.envn = lstring.luaS_bless(L, LUA_ENV);
+ ls.envn = luaS_bless(L, LUA_ENV);
lzio.luaZ_resizebuffer(L, ls.buff, llimits.LUA_MINBUFFER); /* initialize buffer */
};
@@ -459,10 +464,10 @@ const read_string = function(ls, del, seminfo) {
};
const token_to_index = Object.create(null); /* don't want to return true for e.g. 'hasOwnProperty' */
-luaX_tokens.forEach((e, i)=>token_to_index[lstring.luaS_hash(to_luastring(e))] = i);
+luaX_tokens.forEach((e, i)=>token_to_index[luaS_hash(to_luastring(e))] = i);
const isreserved = function(w) {
- let kidx = token_to_index[lstring.luaS_hashlongstr(w)];
+ let kidx = token_to_index[luaS_hashlongstr(w)];
return kidx !== void 0 && kidx <= 22;
};
@@ -568,7 +573,7 @@ const llex = function(ls, seminfo) {
} while (ljstype.lislalnum(ls.current));
let ts = luaX_newstring(ls, lzio.luaZ_buffer(ls.buff));
seminfo.ts = ts;
- let kidx = token_to_index[lstring.luaS_hashlongstr(ts)];
+ let kidx = token_to_index[luaS_hashlongstr(ts)];
if (kidx !== void 0 && kidx <= 22) /* reserved word? */
return kidx + FIRST_RESERVED;
else
diff --git a/src/lobject.js b/src/lobject.js
index 133084a..297401c 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -46,7 +46,10 @@ const ldebug = require('./ldebug.js');
const ldo = require('./ldo.js');
const lfunc = require('./lfunc.js');
const lstate = require('./lstate.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_bless,
+ luaS_new
+} = require('./lstring.js');
const ltable = require('./ltable.js');
const luaconf = require('./luaconf.js');
const lvm = require('./lvm.js');
@@ -576,12 +579,12 @@ const luaO_tostring = function(L, obj) {
}
buff = to_luastring(str);
}
- obj.setsvalue(lstring.luaS_bless(L, buff));
+ obj.setsvalue(luaS_bless(L, buff));
};
const pushstr = function(L, str) {
ldo.luaD_inctop(L);
- setsvalue2s(L, L.top-1, lstring.luaS_new(L, str));
+ setsvalue2s(L, L.top-1, luaS_new(L, str));
};
const luaO_pushvfstring = function(L, fmt, argp) {
diff --git a/src/lparser.js b/src/lparser.js
index ac5b232..b235367 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -105,7 +105,11 @@ const {
SETARG_C,
SET_OPCODE
} = require('./lopcodes.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_eqlngstr,
+ luaS_new,
+ luaS_newliteral
+} = require('./lstring.js');
const ltable = require('./ltable.js');
const Proto = lfunc.Proto;
const R = llex.RESERVED;
@@ -118,7 +122,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 {
@@ -584,7 +588,7 @@ const enterblock = function(fs, bl, isloop) {
** 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]);
};
@@ -1246,7 +1250,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 */
@@ -1658,7 +1662,7 @@ 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;
diff --git a/src/ltable.js b/src/ltable.js
index 7ca7c4a..d5ae6e6 100644
--- a/src/ltable.js
+++ b/src/ltable.js
@@ -21,7 +21,10 @@ const {
const { lua_assert } = require('./llimits.js');
const ldebug = require('./ldebug.js');
const lobject = require('./lobject.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_hashlongstr,
+ TString
+} = require('./lstring.js');
const lstate = require('./lstate.js');
/* used to prevent conflicts with lightuserdata keys */
@@ -56,7 +59,7 @@ const table_hash = function(L, key) {
return key.value;
case LUA_TSHRSTR:
case LUA_TLNGSTR:
- return lstring.luaS_hashlongstr(key.tsvalue());
+ return luaS_hashlongstr(key.tsvalue());
case LUA_TLIGHTUSERDATA: {
let v = key.value;
switch(typeof v) {
@@ -171,8 +174,8 @@ const luaH_getint = function(t, key) {
};
const luaH_getstr = function(t, key) {
- lua_assert(key instanceof lstring.TString);
- return getgeneric(t, lstring.luaS_hashlongstr(key));
+ lua_assert(key instanceof TString);
+ return getgeneric(t, luaS_hashlongstr(key));
};
const luaH_get = function(L, t, key) {
diff --git a/src/ltm.js b/src/ltm.js
index 79a483e..5e05f65 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -6,7 +6,10 @@ const defs = require('./defs.js');
const lobject = require('./lobject.js');
const ldo = require('./ldo.js');
const lstate = require('./lstate.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_bless,
+ luaS_new
+} = require('./lstring.js');
const ltable = require('./ltable.js');
const ldebug = require('./ldebug.js');
const lvm = require('./lvm.js');
@@ -64,30 +67,30 @@ const TMS = {
};
const luaT_init = function(L) {
- L.l_G.tmname[TMS.TM_INDEX] = new lstring.luaS_new(L, defs.to_luastring("__index", true));
- L.l_G.tmname[TMS.TM_NEWINDEX] = new lstring.luaS_new(L, defs.to_luastring("__newindex", true));
- L.l_G.tmname[TMS.TM_GC] = new lstring.luaS_new(L, defs.to_luastring("__gc", true));
- L.l_G.tmname[TMS.TM_MODE] = new lstring.luaS_new(L, defs.to_luastring("__mode", true));
- L.l_G.tmname[TMS.TM_LEN] = new lstring.luaS_new(L, defs.to_luastring("__len", true));
- L.l_G.tmname[TMS.TM_EQ] = new lstring.luaS_new(L, defs.to_luastring("__eq", true));
- L.l_G.tmname[TMS.TM_ADD] = new lstring.luaS_new(L, defs.to_luastring("__add", true));
- L.l_G.tmname[TMS.TM_SUB] = new lstring.luaS_new(L, defs.to_luastring("__sub", true));
- L.l_G.tmname[TMS.TM_MUL] = new lstring.luaS_new(L, defs.to_luastring("__mul", true));
- L.l_G.tmname[TMS.TM_MOD] = new lstring.luaS_new(L, defs.to_luastring("__mod", true));
- L.l_G.tmname[TMS.TM_POW] = new lstring.luaS_new(L, defs.to_luastring("__pow", true));
- L.l_G.tmname[TMS.TM_DIV] = new lstring.luaS_new(L, defs.to_luastring("__div", true));
- L.l_G.tmname[TMS.TM_IDIV] = new lstring.luaS_new(L, defs.to_luastring("__idiv", true));
- L.l_G.tmname[TMS.TM_BAND] = new lstring.luaS_new(L, defs.to_luastring("__band", true));
- L.l_G.tmname[TMS.TM_BOR] = new lstring.luaS_new(L, defs.to_luastring("__bor", true));
- L.l_G.tmname[TMS.TM_BXOR] = new lstring.luaS_new(L, defs.to_luastring("__bxor", true));
- L.l_G.tmname[TMS.TM_SHL] = new lstring.luaS_new(L, defs.to_luastring("__shl", true));
- L.l_G.tmname[TMS.TM_SHR] = new lstring.luaS_new(L, defs.to_luastring("__shr", true));
- L.l_G.tmname[TMS.TM_UNM] = new lstring.luaS_new(L, defs.to_luastring("__unm", true));
- L.l_G.tmname[TMS.TM_BNOT] = new lstring.luaS_new(L, defs.to_luastring("__bnot", true));
- L.l_G.tmname[TMS.TM_LT] = new lstring.luaS_new(L, defs.to_luastring("__lt", true));
- L.l_G.tmname[TMS.TM_LE] = new lstring.luaS_new(L, defs.to_luastring("__le", true));
- L.l_G.tmname[TMS.TM_CONCAT] = new lstring.luaS_new(L, defs.to_luastring("__concat", true));
- L.l_G.tmname[TMS.TM_CALL] = new lstring.luaS_new(L, defs.to_luastring("__call", true));
+ L.l_G.tmname[TMS.TM_INDEX] = new luaS_new(L, defs.to_luastring("__index", true));
+ L.l_G.tmname[TMS.TM_NEWINDEX] = new luaS_new(L, defs.to_luastring("__newindex", true));
+ L.l_G.tmname[TMS.TM_GC] = new luaS_new(L, defs.to_luastring("__gc", true));
+ L.l_G.tmname[TMS.TM_MODE] = new luaS_new(L, defs.to_luastring("__mode", true));
+ L.l_G.tmname[TMS.TM_LEN] = new luaS_new(L, defs.to_luastring("__len", true));
+ L.l_G.tmname[TMS.TM_EQ] = new luaS_new(L, defs.to_luastring("__eq", true));
+ L.l_G.tmname[TMS.TM_ADD] = new luaS_new(L, defs.to_luastring("__add", true));
+ L.l_G.tmname[TMS.TM_SUB] = new luaS_new(L, defs.to_luastring("__sub", true));
+ L.l_G.tmname[TMS.TM_MUL] = new luaS_new(L, defs.to_luastring("__mul", true));
+ L.l_G.tmname[TMS.TM_MOD] = new luaS_new(L, defs.to_luastring("__mod", true));
+ L.l_G.tmname[TMS.TM_POW] = new luaS_new(L, defs.to_luastring("__pow", true));
+ L.l_G.tmname[TMS.TM_DIV] = new luaS_new(L, defs.to_luastring("__div", true));
+ L.l_G.tmname[TMS.TM_IDIV] = new luaS_new(L, defs.to_luastring("__idiv", true));
+ L.l_G.tmname[TMS.TM_BAND] = new luaS_new(L, defs.to_luastring("__band", true));
+ L.l_G.tmname[TMS.TM_BOR] = new luaS_new(L, defs.to_luastring("__bor", true));
+ L.l_G.tmname[TMS.TM_BXOR] = new luaS_new(L, defs.to_luastring("__bxor", true));
+ L.l_G.tmname[TMS.TM_SHL] = new luaS_new(L, defs.to_luastring("__shl", true));
+ L.l_G.tmname[TMS.TM_SHR] = new luaS_new(L, defs.to_luastring("__shr", true));
+ L.l_G.tmname[TMS.TM_UNM] = new luaS_new(L, defs.to_luastring("__unm", true));
+ L.l_G.tmname[TMS.TM_BNOT] = new luaS_new(L, defs.to_luastring("__bnot", true));
+ L.l_G.tmname[TMS.TM_LT] = new luaS_new(L, defs.to_luastring("__lt", true));
+ L.l_G.tmname[TMS.TM_LE] = new luaS_new(L, defs.to_luastring("__le", true));
+ L.l_G.tmname[TMS.TM_CONCAT] = new luaS_new(L, defs.to_luastring("__concat", true));
+ L.l_G.tmname[TMS.TM_CALL] = new luaS_new(L, defs.to_luastring("__call", true));
};
/*
@@ -99,7 +102,7 @@ const luaT_objtypename = function(L, o) {
let mt;
if ((o.ttistable() && (mt = o.value.metatable) !== null) ||
(o.ttisfulluserdata() && (mt = o.value.metatable) !== null)) {
- let name = ltable.luaH_getstr(mt, lstring.luaS_bless(L, __name));
+ let name = ltable.luaH_getstr(mt, luaS_bless(L, __name));
if (name.ttisstring())
return name.svalue();
}
diff --git a/src/lundump.js b/src/lundump.js
index bf1b7e6..bb6cb29 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -7,7 +7,9 @@ const ldo = require('./ldo.js');
const lfunc = require('./lfunc.js');
const lobject = require('./lobject.js');
const lopcodes = require('./lopcodes.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_bless
+} = require('./lstring.js');
const lzio = require('./lzio.js');
const {
@@ -96,7 +98,7 @@ class BytecodeParser {
return null;
}
- return lstring.luaS_bless(this.L, this.read(size));
+ return luaS_bless(this.L, this.read(size));
}
/* creates a mask with 'n' 1 bits at position 'p' */
diff --git a/src/lvm.js b/src/lvm.js
index d0917b0..0f184a1 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -85,7 +85,11 @@ const {
const lobject = require('./lobject.js');
const lfunc = require('./lfunc.js');
const lstate = require('./lstate.js');
-const lstring = require('./lstring.js');
+const {
+ luaS_bless,
+ luaS_eqlngstr,
+ luaS_hashlongstr
+} = require('./lstring.js');
const ldo = require('./ldo.js');
const ltm = require('./ltm.js');
const ltable = require('./ltable.js');
@@ -762,7 +766,7 @@ const luaV_equalobj = function(L, t1, t2) {
return t1.value === t2.value ? 1 : 0;
case LUA_TSHRSTR:
case LUA_TLNGSTR: {
- return lstring.luaS_eqlngstr(t1.tsvalue(), t2.tsvalue()) ? 1 : 0;
+ return luaS_eqlngstr(t1.tsvalue(), t2.tsvalue()) ? 1 : 0;
}
case LUA_TUSERDATA:
case LUA_TTABLE:
@@ -880,8 +884,8 @@ const LEnum = function(l, r) {
** -larger than zero if 'ls' is smaller-equal-larger than 'rs'.
*/
const l_strcmp = function(ls, rs) {
- let l = lstring.luaS_hashlongstr(ls);
- let r = lstring.luaS_hashlongstr(rs);
+ let l = luaS_hashlongstr(ls);
+ let r = luaS_hashlongstr(rs);
/* In fengari we assume string hash has same collation as byte values */
if (l === r)
return 0;
@@ -1060,7 +1064,7 @@ const luaV_concat = function(L, total) {
}
let buff = new Uint8Array(tl);
copy2buff(L, top, n, buff);
- let ts = lstring.luaS_bless(L, buff);
+ let ts = luaS_bless(L, buff);
lobject.setsvalue2s(L, top - n, ts);
}
total -= n - 1; /* got 'n' strings to create 1 new */