aboutsummaryrefslogtreecommitdiff
path: root/src/llex.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-15 17:20:06 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-15 17:20:06 +1000
commitf7e5203a20ef41cf9bc59d339b4f85007a7f3764 (patch)
tree3c6f0907231588f528902eec3b2b1d09d19a53e1 /src/llex.js
parent3947c2cb2fa6193645ac30898064e3d335a63545 (diff)
downloadfengari-f7e5203a20ef41cf9bc59d339b4f85007a7f3764.tar.gz
fengari-f7e5203a20ef41cf9bc59d339b4f85007a7f3764.tar.bz2
fengari-f7e5203a20ef41cf9bc59d339b4f85007a7f3764.zip
Separate ZIO and MBuffer data structures
- lua_load no longer takes a null reader function
Diffstat (limited to 'src/llex.js')
-rw-r--r--src/llex.js64
1 files changed, 3 insertions, 61 deletions
diff --git a/src/llex.js b/src/llex.js
index 0825146..41b3ec8 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -69,63 +69,6 @@ const luaX_tokens = [
"<number>", "<integer>", "<name>", "<string>"
];
-class MBuffer {
- constructor(L, data, reader) {
- this.L = L;
- this.data = data;
- this.n = 0;
- this.buffer = null;
- this.off = 0;
- this.reader = reader ? reader : null;
-
- if (!this.reader) {
- assert(typeof data !== "string", "Should only load binary of array of bytes");
- this.buffer = data ? data : [];
- this.n = this.buffer instanceof DataView ? this.buffer.byteLength : this.buffer.length;
- this.off = 0;
- }
- }
-
- getc() {
- if (this.n <= 0)
- this.fill();
- if (this.n <= 0)
- return -1;
- let r;
- if (this.buffer instanceof DataView) {
- r = this.buffer.getUint8(this.off++, true);
- } else {
- r = this.buffer[this.off++];
- }
- if (this.n-- === 0) // remove reference to input so it can get freed
- this.buffer = null;
- return r;
- }
-
- read(size) {
- let r = [];
-
- while (size > 0) {
- let byte = this.getc();
- if (byte !== -1) r.push(byte);
- size--;
- }
-
- return r;
- }
-
- fill() {
- if (this.reader) {
- this.buffer = this.reader(this.L, this.data);
- assert(typeof this.buffer !== "string", "Should only load binary of array of bytes");
- if (this.buffer !== null) {
- this.n = ((this.buffer instanceof DataView) ? this.buffer.byteLength : this.buffer.length);
- this.off = 0;
- }
- }
- }
-}
-
class SemInfo {
constructor() {
this.r = NaN;
@@ -152,8 +95,8 @@ class LexState {
this.lookahead = new Token(); /* look ahead token */
this.fs = null; /* current function (parser) */
this.L = null;
- this.z = new MBuffer();
- this.buff = new MBuffer(); /* buffer for tokens */
+ this.z = null; /* input stream */
+ this.buff = null; /* buffer for tokens */
this.h = null; /* to reuse strings */
this.dyd = null; /* dynamic structures used by the parser */
this.source = null; /* current source name */
@@ -187,7 +130,7 @@ const currIsNewline = function(ls) {
};
const next = function(ls) {
- ls.current = ls.z.getc();
+ ls.current = ls.z.zgetc();
};
const save_and_next = function(ls) {
@@ -664,7 +607,6 @@ const luaX_lookahead = function(ls) {
module.exports.FIRST_RESERVED = FIRST_RESERVED;
module.exports.LexState = LexState;
-module.exports.MBuffer = MBuffer;
module.exports.RESERVED = RESERVED;
module.exports.isreserved = isreserved;
module.exports.luaX_lookahead = luaX_lookahead;