From 057b19f80c899151b070b094175b8ccffe202cde Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 4 Apr 2022 03:34:37 -0700 Subject: [PATCH] fix: fixed allocation calculation (#113) --- lib/lexer.asm.js | 11 ++++++----- src/lexer.asm.js | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/lexer.asm.js b/lib/lexer.asm.js index ea959b4..cbdcbc1 100644 --- a/lib/lexer.asm.js +++ b/lib/lexer.asm.js @@ -1,4 +1,4 @@ -let asm, asmBuffer, allocSize = 2<<18, addr; +let asm, asmBuffer, allocSize = 2<<19, addr; const copy = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1 ? function (src, outBuf16) { const len = src.length; @@ -19,16 +19,17 @@ let source, name; export function parse (_source, _name = '@') { source = _source; name = _name; + // 2 bytes per string code point + // + analysis space (2^17) + // remaining space is EMCC stack space (2^17) const memBound = source.length * 2 + (2 << 18); if (memBound > allocSize || !asm) { while (memBound > allocSize) allocSize *= 2; asmBuffer = new ArrayBuffer(allocSize); copy(words, new Uint16Array(asmBuffer, 16, words.length)); asm = asmInit(typeof self !== 'undefined' ? self : global, {}, asmBuffer); - // 2 bytes per string code point - // + analysis space - // remaining space is stack space - addr = asm.su(source.length * 2 + (2 << 17)); + // lexer.c bulk allocates string space + analysis space + addr = asm.su(allocSize - (2<<17)); } const len = source.length + 1; asm.ses(addr); diff --git a/src/lexer.asm.js b/src/lexer.asm.js index c8f1799..01697d7 100644 --- a/src/lexer.asm.js +++ b/src/lexer.asm.js @@ -1,4 +1,4 @@ -let asm, asmBuffer, allocSize = 2<<18, addr; +let asm, asmBuffer, allocSize = 2<<19, addr; const copy = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1 ? function (src, outBuf16) { const len = src.length; @@ -19,16 +19,17 @@ let source, name; export function parse (_source, _name = '@') { source = _source; name = _name; + // 2 bytes per string code point + // + analysis space (2^17) + // remaining space is EMCC stack space (2^17) const memBound = source.length * 2 + (2 << 18); if (memBound > allocSize || !asm) { while (memBound > allocSize) allocSize *= 2; asmBuffer = new ArrayBuffer(allocSize); copy(words, new Uint16Array(asmBuffer, 16, words.length)); asm = asmInit(typeof self !== 'undefined' ? self : global, {}, asmBuffer); - // 2 bytes per string code point - // + analysis space - // remaining space is stack space - addr = asm.su(source.length * 2 + (2 << 17)); + // lexer.c bulk allocates string space + analysis space + addr = asm.su(allocSize - (2<<17)); } const len = source.length + 1; asm.ses(addr);