summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-11 23:44:38 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-11 23:44:38 +1100
commit970c179a034ad53f6a64f987070e78bf1de5e6fa (patch)
tree7a2b7b055d886f03adb86a4ac9ab46fa5aa4bfd5
parenta39f24f204a15cb4587e75b38424952fe444d9d2 (diff)
downloadfengari-970c179a034ad53f6a64f987070e78bf1de5e6fa.tar.gz
fengari-970c179a034ad53f6a64f987070e78bf1de5e6fa.tar.bz2
fengari-970c179a034ad53f6a64f987070e78bf1de5e6fa.zip
Remove defs.CT alias for defs.constant_types
-rw-r--r--src/defs.js3
-rw-r--r--src/lcode.js28
-rw-r--r--src/llex.js6
-rw-r--r--src/lua.js20
-rw-r--r--src/lundump.js31
5 files changed, 52 insertions, 36 deletions
diff --git a/src/defs.js b/src/defs.js
index c1720c3..a203db6 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -61,8 +61,6 @@ constant_types.LUA_TLCL = constant_types.LUA_TFUNCTION | (0 << 4); /* Lua closu
constant_types.LUA_TLCF = constant_types.LUA_TFUNCTION | (1 << 4); /* light C function */
constant_types.LUA_TCCL = constant_types.LUA_TFUNCTION | (2 << 4); /* C closure */
-const CT = constant_types;
-
/*
** Comparison and arithmetic functions
*/
@@ -426,7 +424,6 @@ if (typeof process === "undefined") {
module.exports.LUA_CPATH_DEFAULT = LUA_CPATH_DEFAULT;
}
-module.exports.CT = CT;
module.exports.LUA_AUTHORS = LUA_AUTHORS;
module.exports.LUA_COPYRIGHT = LUA_COPYRIGHT;
module.exports.LUA_HOOKCALL = LUA_HOOKCALL;
diff --git a/src/lcode.js b/src/lcode.js
index e7259f2..8646144 100644
--- a/src/lcode.js
+++ b/src/lcode.js
@@ -10,7 +10,15 @@ const lparser = require('./lparser.js');
const ltable = require('./ltable.js');
const lvm = require('./lvm.js');
-const CT = defs.CT;
+const {
+ LUA_TBOOLEAN,
+ LUA_TLIGHTUSERDATA,
+ LUA_TLNGSTR,
+ LUA_TNIL,
+ LUA_TNUMFLT,
+ LUA_TNUMINT,
+ LUA_TTABLE
+} = defs.constant_types;
const OpCodesI = lopcodes.OpCodesI;
const TValue = lobject.TValue;
@@ -71,12 +79,12 @@ const tonumeral = function(e, make_tvalue) {
switch (e.k) {
case ek.VKINT:
if (make_tvalue) {
- return new TValue(CT.LUA_TNUMINT, e.u.ival);
+ return new TValue(LUA_TNUMINT, e.u.ival);
}
return true;
case ek.VKFLT:
if (make_tvalue) {
- return new TValue(CT.LUA_TNUMFLT, e.u.nval);
+ return new TValue(LUA_TNUMFLT, e.u.nval);
}
return true;
default: return false;
@@ -458,7 +466,7 @@ const addk = function(fs, key, v) {
** Add a string to list of constants and return its index.
*/
const luaK_stringK = function(fs, s) {
- let o = new TValue(CT.LUA_TLNGSTR, s);
+ let o = new TValue(LUA_TLNGSTR, s);
return addk(fs, o, o); /* use string itself as key */
};
@@ -469,8 +477,8 @@ const luaK_stringK = function(fs, s) {
** same value.
*/
const luaK_intK = function(fs, n) {
- let k = new TValue(CT.LUA_TLIGHTUSERDATA, n);
- let o = new TValue(CT.LUA_TNUMINT, n);
+ let k = new TValue(LUA_TLIGHTUSERDATA, n);
+ let o = new TValue(LUA_TNUMINT, n);
return addk(fs, k, o);
};
@@ -478,7 +486,7 @@ const luaK_intK = function(fs, n) {
** Add a float to list of constants and return its index.
*/
const luaK_numberK = function(fs, r) {
- let o = new TValue(CT.LUA_TNUMFLT, r);
+ let o = new TValue(LUA_TNUMFLT, r);
return addk(fs, o, o); /* use number itself as key */
};
@@ -487,7 +495,7 @@ const luaK_numberK = function(fs, r) {
** Add a boolean to list of constants and return its index.
*/
const boolK = function(fs, b) {
- let o = new TValue(CT.LUA_TBOOLEAN, b);
+ let o = new TValue(LUA_TBOOLEAN, b);
return addk(fs, o, o); /* use boolean itself as key */
};
@@ -496,8 +504,8 @@ const boolK = function(fs, b) {
** Add nil to list of constants and return its index.
*/
const nilK = function(fs) {
- let v = new TValue(CT.LUA_TNIL, null);
- let k = new TValue(CT.LUA_TTABLE, fs.ls.h);
+ let v = new TValue(LUA_TNIL, null);
+ let k = new TValue(LUA_TTABLE, fs.ls.h);
/* cannot use nil as key; instead use table itself to represent nil */
return addk(fs, k, v);
};
diff --git a/src/llex.js b/src/llex.js
index 438f288..bd05aad 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -11,8 +11,10 @@ const lstring = require('./lstring.js');
const ltable = require('./ltable.js');
const llimits = require('./llimits.js');
const lzio = require('./lzio.js');
-const TS = defs.thread_status;
+
+const {LUA_TLNGSTR} = defs.constant_types;
const char = defs.char;
+const TS = defs.thread_status;
const FIRST_RESERVED = 257;
@@ -151,7 +153,7 @@ const save_and_next = function(ls) {
const luaX_newstring = function(ls, str) {
let L = ls.L;
let ts = lstring.luaS_new(L, str);
- let o = ltable.luaH_set(L, ls.h, new lobject.TValue(defs.CT.LUA_TLNGSTR, ts));
+ 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 */
diff --git a/src/lua.js b/src/lua.js
index 6bbb1a0..d008f27 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -51,16 +51,16 @@ module.exports.LUA_RIDX_GLOBALS = defs.LUA_RIDX_GLOBALS;
module.exports.LUA_RIDX_LAST = defs.LUA_RIDX_LAST;
module.exports.LUA_RIDX_MAINTHREAD = defs.LUA_RIDX_MAINTHREAD;
module.exports.LUA_SIGNATURE = defs.LUA_SIGNATURE;
-module.exports.LUA_TNONE = defs.CT.LUA_TNONE;
-module.exports.LUA_TNIL = defs.CT.LUA_TNIL;
-module.exports.LUA_TBOOLEAN = defs.CT.LUA_TBOOLEAN;
-module.exports.LUA_TLIGHTUSERDATA = defs.CT.LUA_TLIGHTUSERDATA;
-module.exports.LUA_TNUMBER = defs.CT.LUA_TNUMBER;
-module.exports.LUA_TSTRING = defs.CT.LUA_TSTRING;
-module.exports.LUA_TTABLE = defs.CT.LUA_TTABLE;
-module.exports.LUA_TFUNCTION = defs.CT.LUA_TFUNCTION;
-module.exports.LUA_TUSERDATA = defs.CT.LUA_TUSERDATA;
-module.exports.LUA_TTHREAD = defs.CT.LUA_TTHREAD;
+module.exports.LUA_TNONE = defs.constant_types.LUA_TNONE;
+module.exports.LUA_TNIL = defs.constant_types.LUA_TNIL;
+module.exports.LUA_TBOOLEAN = defs.constant_types.LUA_TBOOLEAN;
+module.exports.LUA_TLIGHTUSERDATA = defs.constant_types.LUA_TLIGHTUSERDATA;
+module.exports.LUA_TNUMBER = defs.constant_types.LUA_TNUMBER;
+module.exports.LUA_TSTRING = defs.constant_types.LUA_TSTRING;
+module.exports.LUA_TTABLE = defs.constant_types.LUA_TTABLE;
+module.exports.LUA_TFUNCTION = defs.constant_types.LUA_TFUNCTION;
+module.exports.LUA_TUSERDATA = defs.constant_types.LUA_TUSERDATA;
+module.exports.LUA_TTHREAD = defs.constant_types.LUA_TTHREAD;
module.exports.LUA_VERSION = defs.LUA_VERSION;
module.exports.LUA_VERSION_MAJOR = defs.LUA_VERSION_MAJOR;
module.exports.LUA_VERSION_MINOR = defs.LUA_VERSION_MINOR;
diff --git a/src/lundump.js b/src/lundump.js
index ee1e738..bf1b7e6 100644
--- a/src/lundump.js
+++ b/src/lundump.js
@@ -10,6 +10,15 @@ const lopcodes = require('./lopcodes.js');
const lstring = require('./lstring.js');
const lzio = require('./lzio.js');
+const {
+ LUA_TBOOLEAN,
+ LUA_TLNGSTR,
+ LUA_TNIL,
+ LUA_TNUMFLT,
+ LUA_TNUMINT,
+ LUA_TSHRSTR
+} = defs.constant_types;
+
let LUAC_DATA = [0x19, 0x93, defs.char["\r"], defs.char["\n"], 0x1a, defs.char["\n"]];
class BytecodeParser {
@@ -145,21 +154,21 @@ class BytecodeParser {
let t = this.readByte();
switch (t) {
- case defs.CT.LUA_TNIL:
- f.k.push(new lobject.TValue(defs.CT.LUA_TNIL, null));
+ case LUA_TNIL:
+ f.k.push(new lobject.TValue(LUA_TNIL, null));
break;
- case defs.CT.LUA_TBOOLEAN:
- f.k.push(new lobject.TValue(defs.CT.LUA_TBOOLEAN, this.readByte() !== 0));
+ case LUA_TBOOLEAN:
+ f.k.push(new lobject.TValue(LUA_TBOOLEAN, this.readByte() !== 0));
break;
- case defs.CT.LUA_TNUMFLT:
- f.k.push(new lobject.TValue(defs.CT.LUA_TNUMFLT, this.readNumber()));
+ case LUA_TNUMFLT:
+ f.k.push(new lobject.TValue(LUA_TNUMFLT, this.readNumber()));
break;
- case defs.CT.LUA_TNUMINT:
- f.k.push(new lobject.TValue(defs.CT.LUA_TNUMINT, this.readInteger()));
+ case LUA_TNUMINT:
+ f.k.push(new lobject.TValue(LUA_TNUMINT, this.readInteger()));
break;
- case defs.CT.LUA_TSHRSTR:
- case defs.CT.LUA_TLNGSTR:
- f.k.push(new lobject.TValue(defs.CT.LUA_TLNGSTR, this.readString()));
+ case LUA_TSHRSTR:
+ case LUA_TLNGSTR:
+ f.k.push(new lobject.TValue(LUA_TLNGSTR, this.readString()));
break;
default:
this.error(`unrecognized constant '${t}'`);