Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed allocation calculation #113

Merged
merged 1 commit into from Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions 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;
Expand All @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions 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;
Expand All @@ -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);
Expand Down