diff --git a/src/waforth.wat b/src/waforth.wat index e657999..83baae2 100644 --- a/src/waforth.wat +++ b/src/waforth.wat @@ -2201,9 +2201,12 @@ (global.set $cp (i32.add (global.get $cp) (local.get $nameLength))))) ;; Load the code - (call $shell_load (i32.const 0x1000 (; = MODULE_HEADER_BASE ;)) - (i32.sub (global.get $cp) (i32.const 0x1000 (; = MODULE_HEADER_BASE ;))) - (global.get $nextTableIndex)) + (if (i32.ge_u (global.get $nextTableIndex) (table.size 0)) + (then (drop (table.grow 0 (ref.func $!) (table.size 0))))) ;; Double size + (call $shell_load + (i32.const 0x1000 (; = MODULE_HEADER_BASE ;)) + (i32.sub (global.get $cp) (i32.const 0x1000 (; = MODULE_HEADER_BASE ;))) + (global.get $nextTableIndex)) (global.set $nextTableIndex (i32.add (global.get $nextTableIndex) (i32.const 1)))) diff --git a/src/web/waforth.ts b/src/web/waforth.ts index ded122a..ebdac49 100644 --- a/src/web/waforth.ts +++ b/src/web/waforth.ts @@ -147,9 +147,6 @@ class WAForth { } data = new Uint8Array(dataCopy); } - if (index >= table.length) { - table.grow(table.length); // Double size - } // console.log("Load", index, arrayToBase64(data)); try { var module = new WebAssembly.Module(data);