Fossil SCM

Render the pikchr version in the /pikchrshow footer/toolbar. Update to latest upstream pikchr.c to work around an Emscripten issue when trying to export inlined functions (pikchr_version()). Rebuild pikchr wasm pieces with emscripten 4.0.4 (latest as of this writing).

stephan 2025-03-05 06:25 wasm-cache-workaround
Commit f3227f8f1a9359324a66ee224d11611f631d826dc22af797d015c1237897c0fc
--- extsrc/pikchr-worker.js
+++ extsrc/pikchr-worker.js
@@ -214,8 +214,9 @@
214214
building with:
215215
216216
emcc ... -sMODULARIZE=1 -sEXPORT_NAME=initPikchrModule
217217
*/
218218
initPikchrModule(pikchrModule).then(function(thisModule){
219
- wMsg('pikchr-ready');
219
+ //globalThis.M = pikchrModule; console.warn("pikchrModule=globalThis.M=",globalThis.M);
220
+ wMsg('pikchr-ready', pikchrModule.ccall('pikchr_version','string'));
220221
});
221222
})();
222223
--- extsrc/pikchr-worker.js
+++ extsrc/pikchr-worker.js
@@ -214,8 +214,9 @@
214 building with:
215
216 emcc ... -sMODULARIZE=1 -sEXPORT_NAME=initPikchrModule
217 */
218 initPikchrModule(pikchrModule).then(function(thisModule){
219 wMsg('pikchr-ready');
 
220 });
221 })();
222
--- extsrc/pikchr-worker.js
+++ extsrc/pikchr-worker.js
@@ -214,8 +214,9 @@
214 building with:
215
216 emcc ... -sMODULARIZE=1 -sEXPORT_NAME=initPikchrModule
217 */
218 initPikchrModule(pikchrModule).then(function(thisModule){
219 //globalThis.M = pikchrModule; console.warn("pikchrModule=globalThis.M=",globalThis.M);
220 wMsg('pikchr-ready', pikchrModule.ccall('pikchr_version','string'));
221 });
222 })();
223
+4 -1
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -7970,10 +7970,13 @@
79707970
}
79717971
79727972
/*
79737973
** Return the version name.
79747974
*/
7975
+const char *pikchr_version(void)
7976
+ /* Emscripten workaround, else it chokes on the inlined version */;
7977
+
79757978
const char *pikchr_version(void){
79767979
return RELEASE_VERSION " " MANIFEST_DATE;
79777980
}
79787981
79797982
/*
@@ -8312,6 +8315,6 @@
83128315
83138316
83148317
#endif /* PIKCHR_TCL */
83158318
83168319
8317
-#line 8317 "pikchr.c"
8320
+#line 8320 "pikchr.c"
83188321
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -7970,10 +7970,13 @@
7970 }
7971
7972 /*
7973 ** Return the version name.
7974 */
 
 
 
7975 const char *pikchr_version(void){
7976 return RELEASE_VERSION " " MANIFEST_DATE;
7977 }
7978
7979 /*
@@ -8312,6 +8315,6 @@
8312
8313
8314 #endif /* PIKCHR_TCL */
8315
8316
8317 #line 8317 "pikchr.c"
8318
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -7970,10 +7970,13 @@
7970 }
7971
7972 /*
7973 ** Return the version name.
7974 */
7975 const char *pikchr_version(void)
7976 /* Emscripten workaround, else it chokes on the inlined version */;
7977
7978 const char *pikchr_version(void){
7979 return RELEASE_VERSION " " MANIFEST_DATE;
7980 }
7981
7982 /*
@@ -8312,6 +8315,6 @@
8315
8316
8317 #endif /* PIKCHR_TCL */
8318
8319
8320 #line 8320 "pikchr.c"
8321
+142 -174
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,11 +1,10 @@
1
-
21
var initPikchrModule = (() => {
32
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
43
54
return (
6
-function(moduleArg = {}) {
5
+async function(moduleArg = {}) {
76
var moduleRtn;
87
98
// include: shell.js
109
// The Module object: Our interface to the outside world. We import
1110
// and export values on it. There are various ways Module can be used:
@@ -89,25 +88,25 @@
8988
// If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
9089
// they are removed because they could contain a slash.
9190
if (scriptDirectory.startsWith("blob:")) {
9291
scriptDirectory = "";
9392
} else {
94
- scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
93
+ scriptDirectory = scriptDirectory.slice(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
9594
}
9695
{
9796
// include: web_or_worker_shell_read.js
98
- readAsync = url => fetch(url, {
99
- credentials: "same-origin"
100
- }).then(response => {
97
+ readAsync = async url => {
98
+ var response = await fetch(url, {
99
+ credentials: "same-origin"
100
+ });
101101
if (response.ok) {
102102
return response.arrayBuffer();
103103
}
104
- return Promise.reject(new Error(response.status + " : " + response.url));
105
- });
104
+ throw new Error(response.status + " : " + response.url);
105
+ };
106106
}
107
-} else // end include: web_or_worker_shell_read.js
108
-{}
107
+} else {}
109108
110109
var out = Module["print"] || console.log.bind(console);
111110
112111
var err = Module["printErr"] || console.error.bind(console);
113112
@@ -153,13 +152,25 @@
153152
// NOTE: This is also used as the process return code code in shell environments
154153
// but only when noExitRuntime is false.
155154
var EXITSTATUS;
156155
157156
// Memory management
158
-var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /** @type {!Float64Array} */ HEAPF64;
157
+var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /* BigInt64Array type is not correctly defined in closure
158
+/** not-@type {!BigInt64Array} */ HEAP64, /* BigUint64Array type is not correctly defined in closure
159
+/** not-t@type {!BigUint64Array} */ HEAPU64, /** @type {!Float64Array} */ HEAPF64;
160
+
161
+var runtimeInitialized = false;
159162
160163
// include: runtime_shared.js
164
+// include: runtime_stack_check.js
165
+// end include: runtime_stack_check.js
166
+// include: runtime_exceptions.js
167
+// end include: runtime_exceptions.js
168
+// include: runtime_debug.js
169
+// end include: runtime_debug.js
170
+// include: memoryprofiler.js
171
+// end include: memoryprofiler.js
161172
function updateMemoryViews() {
162173
var b = wasmMemory.buffer;
163174
Module["HEAP8"] = HEAP8 = new Int8Array(b);
164175
Module["HEAP16"] = HEAP16 = new Int16Array(b);
165176
Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
@@ -166,78 +177,49 @@
166177
Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
167178
Module["HEAP32"] = HEAP32 = new Int32Array(b);
168179
Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
169180
Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
170181
Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
182
+ Module["HEAP64"] = HEAP64 = new BigInt64Array(b);
183
+ Module["HEAPU64"] = HEAPU64 = new BigUint64Array(b);
171184
}
172185
173186
// end include: runtime_shared.js
174
-// include: runtime_stack_check.js
175
-// end include: runtime_stack_check.js
176
-var __ATPRERUN__ = [];
177
-
178
-// functions called before the runtime is initialized
179
-var __ATINIT__ = [];
180
-
181
-// functions called during shutdown
182
-var __ATPOSTRUN__ = [];
183
-
184
-// functions called after the main() is called
185
-var runtimeInitialized = false;
186
-
187187
function preRun() {
188
- var preRuns = Module["preRun"];
189
- if (preRuns) {
190
- if (typeof preRuns == "function") preRuns = [ preRuns ];
191
- preRuns.forEach(addOnPreRun);
188
+ if (Module["preRun"]) {
189
+ if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ];
190
+ while (Module["preRun"].length) {
191
+ addOnPreRun(Module["preRun"].shift());
192
+ }
192193
}
193
- callRuntimeCallbacks(__ATPRERUN__);
194
+ callRuntimeCallbacks(onPreRuns);
194195
}
195196
196197
function initRuntime() {
197198
runtimeInitialized = true;
198
- callRuntimeCallbacks(__ATINIT__);
199
+ wasmExports["e"]();
199200
}
200201
201202
function postRun() {
202
- var postRuns = Module["postRun"];
203
- if (postRuns) {
204
- if (typeof postRuns == "function") postRuns = [ postRuns ];
205
- postRuns.forEach(addOnPostRun);
206
- }
207
- callRuntimeCallbacks(__ATPOSTRUN__);
208
-}
209
-
210
-function addOnPreRun(cb) {
211
- __ATPRERUN__.unshift(cb);
212
-}
213
-
214
-function addOnInit(cb) {
215
- __ATINIT__.unshift(cb);
216
-}
217
-
218
-function addOnPostRun(cb) {
219
- __ATPOSTRUN__.unshift(cb);
220
-}
221
-
222
-// include: runtime_math.js
223
-// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
224
-// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
225
-// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
226
-// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
227
-// end include: runtime_math.js
203
+ if (Module["postRun"]) {
204
+ if (typeof Module["postRun"] == "function") Module["postRun"] = [ Module["postRun"] ];
205
+ while (Module["postRun"].length) {
206
+ addOnPostRun(Module["postRun"].shift());
207
+ }
208
+ }
209
+ callRuntimeCallbacks(onPostRuns);
210
+}
211
+
228212
// A counter of dependencies for calling run(). If we need to
229213
// do asynchronous work before running, increment this and
230214
// decrement it. Incrementing must happen in a place like
231215
// Module.preRun (used by emcc to add file preloading).
232216
// Note that you can add dependencies in preRun, even though
233217
// it happens right before run - run will be postponed until
234218
// the dependencies are met.
235219
var runDependencies = 0;
236220
237
-var runDependencyWatcher = null;
238
-
239221
var dependenciesFulfilled = null;
240222
241223
function addRunDependency(id) {
242224
runDependencies++;
243225
Module["monitorRunDependencies"]?.(runDependencies);
@@ -245,14 +227,10 @@
245227
246228
function removeRunDependency(id) {
247229
runDependencies--;
248230
Module["monitorRunDependencies"]?.(runDependencies);
249231
if (runDependencies == 0) {
250
- if (runDependencyWatcher !== null) {
251
- clearInterval(runDependencyWatcher);
252
- runDependencyWatcher = null;
253
- }
254232
if (dependenciesFulfilled) {
255233
var callback = dependenciesFulfilled;
256234
dependenciesFulfilled = null;
257235
callback();
258236
}
@@ -285,33 +263,15 @@
285263
// in code paths apart from instantiation where an exception is expected
286264
// to be thrown when abort is called.
287265
throw e;
288266
}
289267
290
-// include: memoryprofiler.js
291
-// end include: memoryprofiler.js
292
-// include: URIUtils.js
293
-// Prefix of data URIs emitted by SINGLE_FILE and related options.
294
-var dataURIPrefix = "data:application/octet-stream;base64,";
295
-
296
-/**
297
- * Indicates whether filename is a base64 data URI.
298
- * @noinline
299
- */ var isDataURI = filename => filename.startsWith(dataURIPrefix);
300
-
301
-// end include: URIUtils.js
302
-// include: runtime_exceptions.js
303
-// end include: runtime_exceptions.js
268
+var wasmBinaryFile;
269
+
304270
function findWasmBinary() {
305
- var f = "pikchr-v12344321.wasm";
306
- if (!isDataURI(f)) {
307
- return locateFile(f);
308
- }
309
- return f;
310
-}
311
-
312
-var wasmBinaryFile;
271
+ return locateFile("pikchr.wasm");
272
+}
313273
314274
function getBinarySync(file) {
315275
if (file == wasmBinaryFile && wasmBinary) {
316276
return new Uint8Array(wasmBinary);
317277
}
@@ -319,48 +279,50 @@
319279
return readBinary(file);
320280
}
321281
throw "both async and sync fetching of the wasm failed";
322282
}
323283
324
-function getBinaryPromise(binaryFile) {
284
+async function getWasmBinary(binaryFile) {
325285
// If we don't have the binary yet, load it asynchronously using readAsync.
326286
if (!wasmBinary) {
327287
// Fetch the binary using readAsync
328
- return readAsync(binaryFile).then(response => new Uint8Array(/** @type{!ArrayBuffer} */ (response)), // Fall back to getBinarySync if readAsync fails
329
- () => getBinarySync(binaryFile));
288
+ try {
289
+ var response = await readAsync(binaryFile);
290
+ return new Uint8Array(response);
291
+ } catch {}
330292
}
331293
// Otherwise, getBinarySync should be able to get it synchronously
332
- return Promise.resolve().then(() => getBinarySync(binaryFile));
294
+ return getBinarySync(binaryFile);
333295
}
334296
335
-function instantiateArrayBuffer(binaryFile, imports, receiver) {
336
- return getBinaryPromise(binaryFile).then(binary => WebAssembly.instantiate(binary, imports)).then(receiver, reason => {
297
+async function instantiateArrayBuffer(binaryFile, imports) {
298
+ try {
299
+ var binary = await getWasmBinary(binaryFile);
300
+ var instance = await WebAssembly.instantiate(binary, imports);
301
+ return instance;
302
+ } catch (reason) {
337303
err(`failed to asynchronously prepare wasm: ${reason}`);
338304
abort(reason);
339
- });
340
-}
341
-
342
-function instantiateAsync(binary, binaryFile, imports, callback) {
343
- if (!binary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(binaryFile) && typeof fetch == "function") {
344
- return fetch(binaryFile, {
345
- credentials: "same-origin"
346
- }).then(response => {
347
- // Suppress closure warning here since the upstream definition for
348
- // instantiateStreaming only allows Promise<Repsponse> rather than
349
- // an actual Response.
350
- // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure is fixed.
351
- /** @suppress {checkTypes} */ var result = WebAssembly.instantiateStreaming(response, imports);
352
- return result.then(callback, function(reason) {
353
- // We expect the most common failure cause to be a bad MIME type for the binary,
354
- // in which case falling back to ArrayBuffer instantiation should work.
355
- err(`wasm streaming compile failed: ${reason}`);
356
- err("falling back to ArrayBuffer instantiation");
357
- return instantiateArrayBuffer(binaryFile, imports, callback);
358
- });
359
- });
360
- }
361
- return instantiateArrayBuffer(binaryFile, imports, callback);
305
+ }
306
+}
307
+
308
+async function instantiateAsync(binary, binaryFile, imports) {
309
+ if (!binary && typeof WebAssembly.instantiateStreaming == "function") {
310
+ try {
311
+ var response = fetch(binaryFile, {
312
+ credentials: "same-origin"
313
+ });
314
+ var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
315
+ return instantiationResult;
316
+ } catch (reason) {
317
+ // We expect the most common failure cause to be a bad MIME type for the binary,
318
+ // in which case falling back to ArrayBuffer instantiation should work.
319
+ err(`wasm streaming compile failed: ${reason}`);
320
+ err("falling back to ArrayBuffer instantiation");
321
+ }
322
+ }
323
+ return instantiateArrayBuffer(binaryFile, imports);
362324
}
363325
364326
function getWasmImports() {
365327
// prepare imports
366328
return {
@@ -368,20 +330,18 @@
368330
};
369331
}
370332
371333
// Create the wasm instance.
372334
// Receives the wasm imports, returns the exports.
373
-function createWasm() {
374
- var info = getWasmImports();
335
+async function createWasm() {
375336
// Load the wasm module and create an instance of using native support in the JS engine.
376337
// handle a generated wasm instance, receiving its exports and
377338
// performing other necessary setup
378339
/** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) {
379340
wasmExports = instance.exports;
380341
wasmMemory = wasmExports["d"];
381342
updateMemoryViews();
382
- addOnInit(wasmExports["e"]);
383343
removeRunDependency("wasm-instantiate");
384344
return wasmExports;
385345
}
386346
// wait for the pthread pool (if any)
387347
addRunDependency("wasm-instantiate");
@@ -389,48 +349,64 @@
389349
function receiveInstantiationResult(result) {
390350
// 'result' is a ResultObject object which has both the module and instance.
391351
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
392352
// TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
393353
// When the regression is fixed, can restore the above PTHREADS-enabled path.
394
- receiveInstance(result["instance"]);
354
+ return receiveInstance(result["instance"]);
395355
}
356
+ var info = getWasmImports();
396357
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
397358
// to manually instantiate the Wasm module themselves. This allows pages to
398359
// run the instantiation parallel to any other async startup actions they are
399360
// performing.
400361
// Also pthreads and wasm workers initialize the wasm instance through this
401362
// path.
402363
if (Module["instantiateWasm"]) {
403
- try {
404
- return Module["instantiateWasm"](info, receiveInstance);
405
- } catch (e) {
406
- err(`Module.instantiateWasm callback failed with error: ${e}`);
407
- // If instantiation fails, reject the module ready promise.
408
- readyPromiseReject(e);
409
- }
364
+ return new Promise((resolve, reject) => {
365
+ Module["instantiateWasm"](info, (mod, inst) => {
366
+ receiveInstance(mod, inst);
367
+ resolve(mod.exports);
368
+ });
369
+ });
410370
}
411371
wasmBinaryFile ??= findWasmBinary();
412
- // If instantiation fails, reject the module ready promise.
413
- instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject);
414
- return {};
372
+ try {
373
+ var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
374
+ var exports = receiveInstantiationResult(result);
375
+ return exports;
376
+ } catch (e) {
377
+ // If instantiation fails, reject the module ready promise.
378
+ readyPromiseReject(e);
379
+ return Promise.reject(e);
380
+ }
415381
}
416382
417
-// include: runtime_debug.js
418
-// end include: runtime_debug.js
419383
// === Body ===
420384
// end include: preamble.js
421
-/** @constructor */ function ExitStatus(status) {
422
- this.name = "ExitStatus";
423
- this.message = `Program terminated with exit(${status})`;
424
- this.status = status;
385
+class ExitStatus {
386
+ name="ExitStatus";
387
+ constructor(status) {
388
+ this.message = `Program terminated with exit(${status})`;
389
+ this.status = status;
390
+ }
425391
}
426392
427393
var callRuntimeCallbacks = callbacks => {
428
- // Pass the module as the first argument.
429
- callbacks.forEach(f => f(Module));
394
+ while (callbacks.length > 0) {
395
+ // Pass the module as the first argument.
396
+ callbacks.shift()(Module);
397
+ }
430398
};
431399
400
+var onPostRuns = [];
401
+
402
+var addOnPostRun = cb => onPostRuns.unshift(cb);
403
+
404
+var onPreRuns = [];
405
+
406
+var addOnPreRun = cb => onPreRuns.unshift(cb);
407
+
432408
/**
433409
* @param {number} ptr
434410
* @param {string} type
435411
*/ function getValue(ptr, type = "i8") {
436412
if (type.endsWith("*")) type = "*";
@@ -446,11 +422,11 @@
446422
447423
case "i32":
448424
return HEAP32[((ptr) >> 2)];
449425
450426
case "i64":
451
- abort("to do getValue(i64) use WASM_BIGINT");
427
+ return HEAP64[((ptr) >> 3)];
452428
453429
case "float":
454430
return HEAPF32[((ptr) >> 2)];
455431
456432
case "double":
@@ -488,11 +464,12 @@
488464
case "i32":
489465
HEAP32[((ptr) >> 2)] = value;
490466
break;
491467
492468
case "i64":
493
- abort("to do setValue(i64) use WASM_BIGINT");
469
+ HEAP64[((ptr) >> 3)] = BigInt(value);
470
+ break;
494471
495472
case "float":
496473
HEAPF32[((ptr) >> 2)] = value;
497474
break;
498475
@@ -583,13 +560,11 @@
583560
* frequent uses of UTF8ToString() with and without maxBytesToRead may throw
584561
* JS JIT optimizations off, so it is worth to consider consistently using one
585562
* @return {string}
586563
*/ var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
587564
588
-var ___assert_fail = (condition, filename, line, func) => {
589
- abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]);
590
-};
565
+var ___assert_fail = (condition, filename, line, func) => abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]);
591566
592567
var abortOnCannotGrowMemory = requestedSize => {
593568
abort("OOM");
594569
};
595570
@@ -781,65 +756,55 @@
781756
/** @export */ a: ___assert_fail,
782757
/** @export */ b: _emscripten_resize_heap,
783758
/** @export */ c: _exit
784759
};
785760
786
-var wasmExports = createWasm();
787
-
788
-var ___wasm_call_ctors = () => (___wasm_call_ctors = wasmExports["e"])();
789
-
790
-var _pikchr = Module["_pikchr"] = (a0, a1, a2, a3, a4) => (_pikchr = Module["_pikchr"] = wasmExports["g"])(a0, a1, a2, a3, a4);
791
-
792
-var __emscripten_stack_restore = a0 => (__emscripten_stack_restore = wasmExports["h"])(a0);
793
-
794
-var __emscripten_stack_alloc = a0 => (__emscripten_stack_alloc = wasmExports["i"])(a0);
795
-
796
-var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports["j"])();
761
+var wasmExports = await createWasm();
762
+
763
+var ___wasm_call_ctors = wasmExports["e"];
764
+
765
+var _pikchr_version = Module["_pikchr_version"] = wasmExports["g"];
766
+
767
+var _pikchr = Module["_pikchr"] = wasmExports["h"];
768
+
769
+var __emscripten_stack_restore = wasmExports["i"];
770
+
771
+var __emscripten_stack_alloc = wasmExports["j"];
772
+
773
+var _emscripten_stack_get_current = wasmExports["k"];
797774
798775
// include: postamble.js
799776
// === Auto-generated postamble setup entry stuff ===
800777
Module["stackSave"] = stackSave;
801778
802779
Module["stackRestore"] = stackRestore;
803780
804781
Module["stackAlloc"] = stackAlloc;
805782
783
+Module["ccall"] = ccall;
784
+
806785
Module["cwrap"] = cwrap;
807786
808787
Module["setValue"] = setValue;
809788
810789
Module["getValue"] = getValue;
811790
812
-var calledRun;
813
-
814
-var calledPrerun;
815
-
816
-dependenciesFulfilled = function runCaller() {
817
- // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
818
- if (!calledRun) run();
819
- if (!calledRun) dependenciesFulfilled = runCaller;
820
-};
821
-
822
-// try this again later, after new deps are fulfilled
823791
function run() {
824792
if (runDependencies > 0) {
793
+ dependenciesFulfilled = run;
825794
return;
826795
}
827
- if (!calledPrerun) {
828
- calledPrerun = 1;
829
- preRun();
830
- // a preRun added a dependency, run will be called later
831
- if (runDependencies > 0) {
832
- return;
833
- }
796
+ preRun();
797
+ // a preRun added a dependency, run will be called later
798
+ if (runDependencies > 0) {
799
+ dependenciesFulfilled = run;
800
+ return;
834801
}
835802
function doRun() {
836803
// run may have just been called through dependencies being fulfilled just in this very frame,
837804
// or while the async setStatus time below was happening
838
- if (calledRun) return;
839
- calledRun = 1;
840
- Module["calledRun"] = 1;
805
+ Module["calledRun"] = true;
841806
if (ABORT) return;
842807
initRuntime();
843808
readyPromiseResolve(Module);
844809
Module["onRuntimeInitialized"]?.();
845810
postRun();
@@ -875,9 +840,12 @@
875840
876841
return moduleRtn;
877842
}
878843
);
879844
})();
880
-if (typeof exports === 'object' && typeof module === 'object')
845
+if (typeof exports === 'object' && typeof module === 'object') {
881846
module.exports = initPikchrModule;
882
-else if (typeof define === 'function' && define['amd'])
847
+ // This default export looks redundant, but it allows TS to import this
848
+ // commonjs style module.
849
+ module.exports.default = initPikchrModule;
850
+} else if (typeof define === 'function' && define['amd'])
883851
define([], () => initPikchrModule);
884852
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,11 +1,10 @@
1
2 var initPikchrModule = (() => {
3 var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
4
5 return (
6 function(moduleArg = {}) {
7 var moduleRtn;
8
9 // include: shell.js
10 // The Module object: Our interface to the outside world. We import
11 // and export values on it. There are various ways Module can be used:
@@ -89,25 +88,25 @@
89 // If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
90 // they are removed because they could contain a slash.
91 if (scriptDirectory.startsWith("blob:")) {
92 scriptDirectory = "";
93 } else {
94 scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
95 }
96 {
97 // include: web_or_worker_shell_read.js
98 readAsync = url => fetch(url, {
99 credentials: "same-origin"
100 }).then(response => {
 
101 if (response.ok) {
102 return response.arrayBuffer();
103 }
104 return Promise.reject(new Error(response.status + " : " + response.url));
105 });
106 }
107 } else // end include: web_or_worker_shell_read.js
108 {}
109
110 var out = Module["print"] || console.log.bind(console);
111
112 var err = Module["printErr"] || console.error.bind(console);
113
@@ -153,13 +152,25 @@
153 // NOTE: This is also used as the process return code code in shell environments
154 // but only when noExitRuntime is false.
155 var EXITSTATUS;
156
157 // Memory management
158 var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /** @type {!Float64Array} */ HEAPF64;
 
 
 
 
159
160 // include: runtime_shared.js
 
 
 
 
 
 
 
 
161 function updateMemoryViews() {
162 var b = wasmMemory.buffer;
163 Module["HEAP8"] = HEAP8 = new Int8Array(b);
164 Module["HEAP16"] = HEAP16 = new Int16Array(b);
165 Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
@@ -166,78 +177,49 @@
166 Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
167 Module["HEAP32"] = HEAP32 = new Int32Array(b);
168 Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
169 Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
170 Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
 
 
171 }
172
173 // end include: runtime_shared.js
174 // include: runtime_stack_check.js
175 // end include: runtime_stack_check.js
176 var __ATPRERUN__ = [];
177
178 // functions called before the runtime is initialized
179 var __ATINIT__ = [];
180
181 // functions called during shutdown
182 var __ATPOSTRUN__ = [];
183
184 // functions called after the main() is called
185 var runtimeInitialized = false;
186
187 function preRun() {
188 var preRuns = Module["preRun"];
189 if (preRuns) {
190 if (typeof preRuns == "function") preRuns = [ preRuns ];
191 preRuns.forEach(addOnPreRun);
 
192 }
193 callRuntimeCallbacks(__ATPRERUN__);
194 }
195
196 function initRuntime() {
197 runtimeInitialized = true;
198 callRuntimeCallbacks(__ATINIT__);
199 }
200
201 function postRun() {
202 var postRuns = Module["postRun"];
203 if (postRuns) {
204 if (typeof postRuns == "function") postRuns = [ postRuns ];
205 postRuns.forEach(addOnPostRun);
206 }
207 callRuntimeCallbacks(__ATPOSTRUN__);
208 }
209
210 function addOnPreRun(cb) {
211 __ATPRERUN__.unshift(cb);
212 }
213
214 function addOnInit(cb) {
215 __ATINIT__.unshift(cb);
216 }
217
218 function addOnPostRun(cb) {
219 __ATPOSTRUN__.unshift(cb);
220 }
221
222 // include: runtime_math.js
223 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
224 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
225 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
226 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
227 // end include: runtime_math.js
228 // A counter of dependencies for calling run(). If we need to
229 // do asynchronous work before running, increment this and
230 // decrement it. Incrementing must happen in a place like
231 // Module.preRun (used by emcc to add file preloading).
232 // Note that you can add dependencies in preRun, even though
233 // it happens right before run - run will be postponed until
234 // the dependencies are met.
235 var runDependencies = 0;
236
237 var runDependencyWatcher = null;
238
239 var dependenciesFulfilled = null;
240
241 function addRunDependency(id) {
242 runDependencies++;
243 Module["monitorRunDependencies"]?.(runDependencies);
@@ -245,14 +227,10 @@
245
246 function removeRunDependency(id) {
247 runDependencies--;
248 Module["monitorRunDependencies"]?.(runDependencies);
249 if (runDependencies == 0) {
250 if (runDependencyWatcher !== null) {
251 clearInterval(runDependencyWatcher);
252 runDependencyWatcher = null;
253 }
254 if (dependenciesFulfilled) {
255 var callback = dependenciesFulfilled;
256 dependenciesFulfilled = null;
257 callback();
258 }
@@ -285,33 +263,15 @@
285 // in code paths apart from instantiation where an exception is expected
286 // to be thrown when abort is called.
287 throw e;
288 }
289
290 // include: memoryprofiler.js
291 // end include: memoryprofiler.js
292 // include: URIUtils.js
293 // Prefix of data URIs emitted by SINGLE_FILE and related options.
294 var dataURIPrefix = "data:application/octet-stream;base64,";
295
296 /**
297 * Indicates whether filename is a base64 data URI.
298 * @noinline
299 */ var isDataURI = filename => filename.startsWith(dataURIPrefix);
300
301 // end include: URIUtils.js
302 // include: runtime_exceptions.js
303 // end include: runtime_exceptions.js
304 function findWasmBinary() {
305 var f = "pikchr-v12344321.wasm";
306 if (!isDataURI(f)) {
307 return locateFile(f);
308 }
309 return f;
310 }
311
312 var wasmBinaryFile;
313
314 function getBinarySync(file) {
315 if (file == wasmBinaryFile && wasmBinary) {
316 return new Uint8Array(wasmBinary);
317 }
@@ -319,48 +279,50 @@
319 return readBinary(file);
320 }
321 throw "both async and sync fetching of the wasm failed";
322 }
323
324 function getBinaryPromise(binaryFile) {
325 // If we don't have the binary yet, load it asynchronously using readAsync.
326 if (!wasmBinary) {
327 // Fetch the binary using readAsync
328 return readAsync(binaryFile).then(response => new Uint8Array(/** @type{!ArrayBuffer} */ (response)), // Fall back to getBinarySync if readAsync fails
329 () => getBinarySync(binaryFile));
 
 
330 }
331 // Otherwise, getBinarySync should be able to get it synchronously
332 return Promise.resolve().then(() => getBinarySync(binaryFile));
333 }
334
335 function instantiateArrayBuffer(binaryFile, imports, receiver) {
336 return getBinaryPromise(binaryFile).then(binary => WebAssembly.instantiate(binary, imports)).then(receiver, reason => {
 
 
 
 
337 err(`failed to asynchronously prepare wasm: ${reason}`);
338 abort(reason);
339 });
340 }
341
342 function instantiateAsync(binary, binaryFile, imports, callback) {
343 if (!binary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(binaryFile) && typeof fetch == "function") {
344 return fetch(binaryFile, {
345 credentials: "same-origin"
346 }).then(response => {
347 // Suppress closure warning here since the upstream definition for
348 // instantiateStreaming only allows Promise<Repsponse> rather than
349 // an actual Response.
350 // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure is fixed.
351 /** @suppress {checkTypes} */ var result = WebAssembly.instantiateStreaming(response, imports);
352 return result.then(callback, function(reason) {
353 // We expect the most common failure cause to be a bad MIME type for the binary,
354 // in which case falling back to ArrayBuffer instantiation should work.
355 err(`wasm streaming compile failed: ${reason}`);
356 err("falling back to ArrayBuffer instantiation");
357 return instantiateArrayBuffer(binaryFile, imports, callback);
358 });
359 });
360 }
361 return instantiateArrayBuffer(binaryFile, imports, callback);
362 }
363
364 function getWasmImports() {
365 // prepare imports
366 return {
@@ -368,20 +330,18 @@
368 };
369 }
370
371 // Create the wasm instance.
372 // Receives the wasm imports, returns the exports.
373 function createWasm() {
374 var info = getWasmImports();
375 // Load the wasm module and create an instance of using native support in the JS engine.
376 // handle a generated wasm instance, receiving its exports and
377 // performing other necessary setup
378 /** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) {
379 wasmExports = instance.exports;
380 wasmMemory = wasmExports["d"];
381 updateMemoryViews();
382 addOnInit(wasmExports["e"]);
383 removeRunDependency("wasm-instantiate");
384 return wasmExports;
385 }
386 // wait for the pthread pool (if any)
387 addRunDependency("wasm-instantiate");
@@ -389,48 +349,64 @@
389 function receiveInstantiationResult(result) {
390 // 'result' is a ResultObject object which has both the module and instance.
391 // receiveInstance() will swap in the exports (to Module.asm) so they can be called
392 // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
393 // When the regression is fixed, can restore the above PTHREADS-enabled path.
394 receiveInstance(result["instance"]);
395 }
 
396 // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
397 // to manually instantiate the Wasm module themselves. This allows pages to
398 // run the instantiation parallel to any other async startup actions they are
399 // performing.
400 // Also pthreads and wasm workers initialize the wasm instance through this
401 // path.
402 if (Module["instantiateWasm"]) {
403 try {
404 return Module["instantiateWasm"](info, receiveInstance);
405 } catch (e) {
406 err(`Module.instantiateWasm callback failed with error: ${e}`);
407 // If instantiation fails, reject the module ready promise.
408 readyPromiseReject(e);
409 }
410 }
411 wasmBinaryFile ??= findWasmBinary();
412 // If instantiation fails, reject the module ready promise.
413 instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject);
414 return {};
 
 
 
 
 
 
415 }
416
417 // include: runtime_debug.js
418 // end include: runtime_debug.js
419 // === Body ===
420 // end include: preamble.js
421 /** @constructor */ function ExitStatus(status) {
422 this.name = "ExitStatus";
423 this.message = `Program terminated with exit(${status})`;
424 this.status = status;
 
 
425 }
426
427 var callRuntimeCallbacks = callbacks => {
428 // Pass the module as the first argument.
429 callbacks.forEach(f => f(Module));
 
 
430 };
431
 
 
 
 
 
 
 
 
432 /**
433 * @param {number} ptr
434 * @param {string} type
435 */ function getValue(ptr, type = "i8") {
436 if (type.endsWith("*")) type = "*";
@@ -446,11 +422,11 @@
446
447 case "i32":
448 return HEAP32[((ptr) >> 2)];
449
450 case "i64":
451 abort("to do getValue(i64) use WASM_BIGINT");
452
453 case "float":
454 return HEAPF32[((ptr) >> 2)];
455
456 case "double":
@@ -488,11 +464,12 @@
488 case "i32":
489 HEAP32[((ptr) >> 2)] = value;
490 break;
491
492 case "i64":
493 abort("to do setValue(i64) use WASM_BIGINT");
 
494
495 case "float":
496 HEAPF32[((ptr) >> 2)] = value;
497 break;
498
@@ -583,13 +560,11 @@
583 * frequent uses of UTF8ToString() with and without maxBytesToRead may throw
584 * JS JIT optimizations off, so it is worth to consider consistently using one
585 * @return {string}
586 */ var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
587
588 var ___assert_fail = (condition, filename, line, func) => {
589 abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]);
590 };
591
592 var abortOnCannotGrowMemory = requestedSize => {
593 abort("OOM");
594 };
595
@@ -781,65 +756,55 @@
781 /** @export */ a: ___assert_fail,
782 /** @export */ b: _emscripten_resize_heap,
783 /** @export */ c: _exit
784 };
785
786 var wasmExports = createWasm();
787
788 var ___wasm_call_ctors = () => (___wasm_call_ctors = wasmExports["e"])();
789
790 var _pikchr = Module["_pikchr"] = (a0, a1, a2, a3, a4) => (_pikchr = Module["_pikchr"] = wasmExports["g"])(a0, a1, a2, a3, a4);
791
792 var __emscripten_stack_restore = a0 => (__emscripten_stack_restore = wasmExports["h"])(a0);
793
794 var __emscripten_stack_alloc = a0 => (__emscripten_stack_alloc = wasmExports["i"])(a0);
795
796 var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports["j"])();
 
 
797
798 // include: postamble.js
799 // === Auto-generated postamble setup entry stuff ===
800 Module["stackSave"] = stackSave;
801
802 Module["stackRestore"] = stackRestore;
803
804 Module["stackAlloc"] = stackAlloc;
805
 
 
806 Module["cwrap"] = cwrap;
807
808 Module["setValue"] = setValue;
809
810 Module["getValue"] = getValue;
811
812 var calledRun;
813
814 var calledPrerun;
815
816 dependenciesFulfilled = function runCaller() {
817 // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
818 if (!calledRun) run();
819 if (!calledRun) dependenciesFulfilled = runCaller;
820 };
821
822 // try this again later, after new deps are fulfilled
823 function run() {
824 if (runDependencies > 0) {
 
825 return;
826 }
827 if (!calledPrerun) {
828 calledPrerun = 1;
829 preRun();
830 // a preRun added a dependency, run will be called later
831 if (runDependencies > 0) {
832 return;
833 }
834 }
835 function doRun() {
836 // run may have just been called through dependencies being fulfilled just in this very frame,
837 // or while the async setStatus time below was happening
838 if (calledRun) return;
839 calledRun = 1;
840 Module["calledRun"] = 1;
841 if (ABORT) return;
842 initRuntime();
843 readyPromiseResolve(Module);
844 Module["onRuntimeInitialized"]?.();
845 postRun();
@@ -875,9 +840,12 @@
875
876 return moduleRtn;
877 }
878 );
879 })();
880 if (typeof exports === 'object' && typeof module === 'object')
881 module.exports = initPikchrModule;
882 else if (typeof define === 'function' && define['amd'])
 
 
 
883 define([], () => initPikchrModule);
884
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,11 +1,10 @@
 
1 var initPikchrModule = (() => {
2 var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
3
4 return (
5 async function(moduleArg = {}) {
6 var moduleRtn;
7
8 // include: shell.js
9 // The Module object: Our interface to the outside world. We import
10 // and export values on it. There are various ways Module can be used:
@@ -89,25 +88,25 @@
88 // If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
89 // they are removed because they could contain a slash.
90 if (scriptDirectory.startsWith("blob:")) {
91 scriptDirectory = "";
92 } else {
93 scriptDirectory = scriptDirectory.slice(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
94 }
95 {
96 // include: web_or_worker_shell_read.js
97 readAsync = async url => {
98 var response = await fetch(url, {
99 credentials: "same-origin"
100 });
101 if (response.ok) {
102 return response.arrayBuffer();
103 }
104 throw new Error(response.status + " : " + response.url);
105 };
106 }
107 } else {}
 
108
109 var out = Module["print"] || console.log.bind(console);
110
111 var err = Module["printErr"] || console.error.bind(console);
112
@@ -153,13 +152,25 @@
152 // NOTE: This is also used as the process return code code in shell environments
153 // but only when noExitRuntime is false.
154 var EXITSTATUS;
155
156 // Memory management
157 var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /* BigInt64Array type is not correctly defined in closure
158 /** not-@type {!BigInt64Array} */ HEAP64, /* BigUint64Array type is not correctly defined in closure
159 /** not-t@type {!BigUint64Array} */ HEAPU64, /** @type {!Float64Array} */ HEAPF64;
160
161 var runtimeInitialized = false;
162
163 // include: runtime_shared.js
164 // include: runtime_stack_check.js
165 // end include: runtime_stack_check.js
166 // include: runtime_exceptions.js
167 // end include: runtime_exceptions.js
168 // include: runtime_debug.js
169 // end include: runtime_debug.js
170 // include: memoryprofiler.js
171 // end include: memoryprofiler.js
172 function updateMemoryViews() {
173 var b = wasmMemory.buffer;
174 Module["HEAP8"] = HEAP8 = new Int8Array(b);
175 Module["HEAP16"] = HEAP16 = new Int16Array(b);
176 Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
@@ -166,78 +177,49 @@
177 Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
178 Module["HEAP32"] = HEAP32 = new Int32Array(b);
179 Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
180 Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
181 Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
182 Module["HEAP64"] = HEAP64 = new BigInt64Array(b);
183 Module["HEAPU64"] = HEAPU64 = new BigUint64Array(b);
184 }
185
186 // end include: runtime_shared.js
 
 
 
 
 
 
 
 
 
 
 
 
 
187 function preRun() {
188 if (Module["preRun"]) {
189 if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ];
190 while (Module["preRun"].length) {
191 addOnPreRun(Module["preRun"].shift());
192 }
193 }
194 callRuntimeCallbacks(onPreRuns);
195 }
196
197 function initRuntime() {
198 runtimeInitialized = true;
199 wasmExports["e"]();
200 }
201
202 function postRun() {
203 if (Module["postRun"]) {
204 if (typeof Module["postRun"] == "function") Module["postRun"] = [ Module["postRun"] ];
205 while (Module["postRun"].length) {
206 addOnPostRun(Module["postRun"].shift());
207 }
208 }
209 callRuntimeCallbacks(onPostRuns);
210 }
211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212 // A counter of dependencies for calling run(). If we need to
213 // do asynchronous work before running, increment this and
214 // decrement it. Incrementing must happen in a place like
215 // Module.preRun (used by emcc to add file preloading).
216 // Note that you can add dependencies in preRun, even though
217 // it happens right before run - run will be postponed until
218 // the dependencies are met.
219 var runDependencies = 0;
220
 
 
221 var dependenciesFulfilled = null;
222
223 function addRunDependency(id) {
224 runDependencies++;
225 Module["monitorRunDependencies"]?.(runDependencies);
@@ -245,14 +227,10 @@
227
228 function removeRunDependency(id) {
229 runDependencies--;
230 Module["monitorRunDependencies"]?.(runDependencies);
231 if (runDependencies == 0) {
 
 
 
 
232 if (dependenciesFulfilled) {
233 var callback = dependenciesFulfilled;
234 dependenciesFulfilled = null;
235 callback();
236 }
@@ -285,33 +263,15 @@
263 // in code paths apart from instantiation where an exception is expected
264 // to be thrown when abort is called.
265 throw e;
266 }
267
268 var wasmBinaryFile;
269
 
 
 
 
 
 
 
 
 
 
 
 
270 function findWasmBinary() {
271 return locateFile("pikchr.wasm");
272 }
 
 
 
 
 
 
273
274 function getBinarySync(file) {
275 if (file == wasmBinaryFile && wasmBinary) {
276 return new Uint8Array(wasmBinary);
277 }
@@ -319,48 +279,50 @@
279 return readBinary(file);
280 }
281 throw "both async and sync fetching of the wasm failed";
282 }
283
284 async function getWasmBinary(binaryFile) {
285 // If we don't have the binary yet, load it asynchronously using readAsync.
286 if (!wasmBinary) {
287 // Fetch the binary using readAsync
288 try {
289 var response = await readAsync(binaryFile);
290 return new Uint8Array(response);
291 } catch {}
292 }
293 // Otherwise, getBinarySync should be able to get it synchronously
294 return getBinarySync(binaryFile);
295 }
296
297 async function instantiateArrayBuffer(binaryFile, imports) {
298 try {
299 var binary = await getWasmBinary(binaryFile);
300 var instance = await WebAssembly.instantiate(binary, imports);
301 return instance;
302 } catch (reason) {
303 err(`failed to asynchronously prepare wasm: ${reason}`);
304 abort(reason);
305 }
306 }
307
308 async function instantiateAsync(binary, binaryFile, imports) {
309 if (!binary && typeof WebAssembly.instantiateStreaming == "function") {
310 try {
311 var response = fetch(binaryFile, {
312 credentials: "same-origin"
313 });
314 var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
315 return instantiationResult;
316 } catch (reason) {
317 // We expect the most common failure cause to be a bad MIME type for the binary,
318 // in which case falling back to ArrayBuffer instantiation should work.
319 err(`wasm streaming compile failed: ${reason}`);
320 err("falling back to ArrayBuffer instantiation");
321 }
322 }
323 return instantiateArrayBuffer(binaryFile, imports);
 
 
 
 
324 }
325
326 function getWasmImports() {
327 // prepare imports
328 return {
@@ -368,20 +330,18 @@
330 };
331 }
332
333 // Create the wasm instance.
334 // Receives the wasm imports, returns the exports.
335 async function createWasm() {
 
336 // Load the wasm module and create an instance of using native support in the JS engine.
337 // handle a generated wasm instance, receiving its exports and
338 // performing other necessary setup
339 /** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) {
340 wasmExports = instance.exports;
341 wasmMemory = wasmExports["d"];
342 updateMemoryViews();
 
343 removeRunDependency("wasm-instantiate");
344 return wasmExports;
345 }
346 // wait for the pthread pool (if any)
347 addRunDependency("wasm-instantiate");
@@ -389,48 +349,64 @@
349 function receiveInstantiationResult(result) {
350 // 'result' is a ResultObject object which has both the module and instance.
351 // receiveInstance() will swap in the exports (to Module.asm) so they can be called
352 // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
353 // When the regression is fixed, can restore the above PTHREADS-enabled path.
354 return receiveInstance(result["instance"]);
355 }
356 var info = getWasmImports();
357 // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
358 // to manually instantiate the Wasm module themselves. This allows pages to
359 // run the instantiation parallel to any other async startup actions they are
360 // performing.
361 // Also pthreads and wasm workers initialize the wasm instance through this
362 // path.
363 if (Module["instantiateWasm"]) {
364 return new Promise((resolve, reject) => {
365 Module["instantiateWasm"](info, (mod, inst) => {
366 receiveInstance(mod, inst);
367 resolve(mod.exports);
368 });
369 });
 
370 }
371 wasmBinaryFile ??= findWasmBinary();
372 try {
373 var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
374 var exports = receiveInstantiationResult(result);
375 return exports;
376 } catch (e) {
377 // If instantiation fails, reject the module ready promise.
378 readyPromiseReject(e);
379 return Promise.reject(e);
380 }
381 }
382
 
 
383 // === Body ===
384 // end include: preamble.js
385 class ExitStatus {
386 name="ExitStatus";
387 constructor(status) {
388 this.message = `Program terminated with exit(${status})`;
389 this.status = status;
390 }
391 }
392
393 var callRuntimeCallbacks = callbacks => {
394 while (callbacks.length > 0) {
395 // Pass the module as the first argument.
396 callbacks.shift()(Module);
397 }
398 };
399
400 var onPostRuns = [];
401
402 var addOnPostRun = cb => onPostRuns.unshift(cb);
403
404 var onPreRuns = [];
405
406 var addOnPreRun = cb => onPreRuns.unshift(cb);
407
408 /**
409 * @param {number} ptr
410 * @param {string} type
411 */ function getValue(ptr, type = "i8") {
412 if (type.endsWith("*")) type = "*";
@@ -446,11 +422,11 @@
422
423 case "i32":
424 return HEAP32[((ptr) >> 2)];
425
426 case "i64":
427 return HEAP64[((ptr) >> 3)];
428
429 case "float":
430 return HEAPF32[((ptr) >> 2)];
431
432 case "double":
@@ -488,11 +464,12 @@
464 case "i32":
465 HEAP32[((ptr) >> 2)] = value;
466 break;
467
468 case "i64":
469 HEAP64[((ptr) >> 3)] = BigInt(value);
470 break;
471
472 case "float":
473 HEAPF32[((ptr) >> 2)] = value;
474 break;
475
@@ -583,13 +560,11 @@
560 * frequent uses of UTF8ToString() with and without maxBytesToRead may throw
561 * JS JIT optimizations off, so it is worth to consider consistently using one
562 * @return {string}
563 */ var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
564
565 var ___assert_fail = (condition, filename, line, func) => abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]);
 
 
566
567 var abortOnCannotGrowMemory = requestedSize => {
568 abort("OOM");
569 };
570
@@ -781,65 +756,55 @@
756 /** @export */ a: ___assert_fail,
757 /** @export */ b: _emscripten_resize_heap,
758 /** @export */ c: _exit
759 };
760
761 var wasmExports = await createWasm();
762
763 var ___wasm_call_ctors = wasmExports["e"];
764
765 var _pikchr_version = Module["_pikchr_version"] = wasmExports["g"];
766
767 var _pikchr = Module["_pikchr"] = wasmExports["h"];
768
769 var __emscripten_stack_restore = wasmExports["i"];
770
771 var __emscripten_stack_alloc = wasmExports["j"];
772
773 var _emscripten_stack_get_current = wasmExports["k"];
774
775 // include: postamble.js
776 // === Auto-generated postamble setup entry stuff ===
777 Module["stackSave"] = stackSave;
778
779 Module["stackRestore"] = stackRestore;
780
781 Module["stackAlloc"] = stackAlloc;
782
783 Module["ccall"] = ccall;
784
785 Module["cwrap"] = cwrap;
786
787 Module["setValue"] = setValue;
788
789 Module["getValue"] = getValue;
790
 
 
 
 
 
 
 
 
 
 
 
791 function run() {
792 if (runDependencies > 0) {
793 dependenciesFulfilled = run;
794 return;
795 }
796 preRun();
797 // a preRun added a dependency, run will be called later
798 if (runDependencies > 0) {
799 dependenciesFulfilled = run;
800 return;
 
 
801 }
802 function doRun() {
803 // run may have just been called through dependencies being fulfilled just in this very frame,
804 // or while the async setStatus time below was happening
805 Module["calledRun"] = true;
 
 
806 if (ABORT) return;
807 initRuntime();
808 readyPromiseResolve(Module);
809 Module["onRuntimeInitialized"]?.();
810 postRun();
@@ -875,9 +840,12 @@
840
841 return moduleRtn;
842 }
843 );
844 })();
845 if (typeof exports === 'object' && typeof module === 'object') {
846 module.exports = initPikchrModule;
847 // This default export looks redundant, but it allows TS to import this
848 // commonjs style module.
849 module.exports.default = initPikchrModule;
850 } else if (typeof define === 'function' && define['amd'])
851 define([], () => initPikchrModule);
852
--- extsrc/pikchr.wasm
+++ extsrc/pikchr.wasm
cannot compute difference between binary files
11
--- extsrc/pikchr.wasm
+++ extsrc/pikchr.wasm
0 annot compute difference between binary files
1
--- extsrc/pikchr.wasm
+++ extsrc/pikchr.wasm
0 annot compute difference between binary files
1
--- src/fossil.page.pikchrshowasm.js
+++ src/fossil.page.pikchrshowasm.js
@@ -172,21 +172,21 @@
172172
PS.renderModeLabels[PS.renderModes[PS.renderModes.selectedIndex]];
173173
174174
/**
175175
The 'pikchr-ready' event is fired (with no payload) when the
176176
wasm module has finished loading. */
177
- PS.addMsgHandler('pikchr-ready', function(){
177
+ PS.addMsgHandler('pikchr-ready', function(event){
178178
PS.clearMsgHandlers('pikchr-ready');
179
- F.page.onPikchrshowLoaded();
179
+ F.page.onPikchrshowLoaded(event.data);
180180
});
181181
182182
/**
183183
Performs all app initialization which must wait until after the
184184
worker module is loaded. This function removes itself when it's
185185
called.
186186
*/
187
- F.page.onPikchrshowLoaded = function(){
187
+ F.page.onPikchrshowLoaded = function(pikchrVersion){
188188
delete this.onPikchrshowLoaded;
189189
// Unhide all elements which start out hidden
190190
EAll('.initially-hidden').forEach((e)=>e.classList.remove('initially-hidden'));
191191
const taInput = E('#input');
192192
const btnClearIn = E('#btn-clear');
@@ -439,10 +439,13 @@
439439
if( src && (new URL(self.location.href).searchParams).has('fromSession') ){
440440
taInput.value = src;
441441
window.sessionStorage.removeItem('pikchr-xfer');
442442
}
443443
}
444
+ D.append(E('fieldset.options > div'),
445
+ D.append(D.addClass(D.span(), 'labeled-input'),
446
+ 'pikchr v. '+pikchrVersion));
444447
445448
PS.e.btnRender.click();
446449
447450
/** Debounce handler for auto-rendering while typing. */
448451
const debounceAutoRender = F.debounce(function f(){
449452
--- src/fossil.page.pikchrshowasm.js
+++ src/fossil.page.pikchrshowasm.js
@@ -172,21 +172,21 @@
172 PS.renderModeLabels[PS.renderModes[PS.renderModes.selectedIndex]];
173
174 /**
175 The 'pikchr-ready' event is fired (with no payload) when the
176 wasm module has finished loading. */
177 PS.addMsgHandler('pikchr-ready', function(){
178 PS.clearMsgHandlers('pikchr-ready');
179 F.page.onPikchrshowLoaded();
180 });
181
182 /**
183 Performs all app initialization which must wait until after the
184 worker module is loaded. This function removes itself when it's
185 called.
186 */
187 F.page.onPikchrshowLoaded = function(){
188 delete this.onPikchrshowLoaded;
189 // Unhide all elements which start out hidden
190 EAll('.initially-hidden').forEach((e)=>e.classList.remove('initially-hidden'));
191 const taInput = E('#input');
192 const btnClearIn = E('#btn-clear');
@@ -439,10 +439,13 @@
439 if( src && (new URL(self.location.href).searchParams).has('fromSession') ){
440 taInput.value = src;
441 window.sessionStorage.removeItem('pikchr-xfer');
442 }
443 }
 
 
 
444
445 PS.e.btnRender.click();
446
447 /** Debounce handler for auto-rendering while typing. */
448 const debounceAutoRender = F.debounce(function f(){
449
--- src/fossil.page.pikchrshowasm.js
+++ src/fossil.page.pikchrshowasm.js
@@ -172,21 +172,21 @@
172 PS.renderModeLabels[PS.renderModes[PS.renderModes.selectedIndex]];
173
174 /**
175 The 'pikchr-ready' event is fired (with no payload) when the
176 wasm module has finished loading. */
177 PS.addMsgHandler('pikchr-ready', function(event){
178 PS.clearMsgHandlers('pikchr-ready');
179 F.page.onPikchrshowLoaded(event.data);
180 });
181
182 /**
183 Performs all app initialization which must wait until after the
184 worker module is loaded. This function removes itself when it's
185 called.
186 */
187 F.page.onPikchrshowLoaded = function(pikchrVersion){
188 delete this.onPikchrshowLoaded;
189 // Unhide all elements which start out hidden
190 EAll('.initially-hidden').forEach((e)=>e.classList.remove('initially-hidden'));
191 const taInput = E('#input');
192 const btnClearIn = E('#btn-clear');
@@ -439,10 +439,13 @@
439 if( src && (new URL(self.location.href).searchParams).has('fromSession') ){
440 taInput.value = src;
441 window.sessionStorage.removeItem('pikchr-xfer');
442 }
443 }
444 D.append(E('fieldset.options > div'),
445 D.append(D.addClass(D.span(), 'labeled-input'),
446 'pikchr v. '+pikchrVersion));
447
448 PS.e.btnRender.click();
449
450 /** Debounce handler for auto-rendering while typing. */
451 const debounceAutoRender = F.debounce(function f(){
452
+2 -2
--- src/main.mk
+++ src/main.mk
@@ -2136,12 +2136,12 @@
21362136
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
21372137
$(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
21382138
21392139
$(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
21402140
$(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2141
- -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackAlloc,stackRestore \
2142
- -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
2141
+ -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore \
2142
+ -sEXPORTED_FUNCTIONS=_pikchr,_pikchr_version $(SRCDIR_extsrc)/pikchr.c \
21432143
-sENVIRONMENT=web \
21442144
-sMODULARIZE \
21452145
-sEXPORT_NAME=initPikchrModule \
21462146
--minify 0
21472147
@chmod -x $(SRCDIR_extsrc)/pikchr.wasm
21482148
--- src/main.mk
+++ src/main.mk
@@ -2136,12 +2136,12 @@
2136 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
2137 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
2138
2139 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
2140 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2141 -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackAlloc,stackRestore \
2142 -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
2143 -sENVIRONMENT=web \
2144 -sMODULARIZE \
2145 -sEXPORT_NAME=initPikchrModule \
2146 --minify 0
2147 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
2148
--- src/main.mk
+++ src/main.mk
@@ -2136,12 +2136,12 @@
2136 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
2137 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
2138
2139 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
2140 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2141 -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore \
2142 -sEXPORTED_FUNCTIONS=_pikchr,_pikchr_version $(SRCDIR_extsrc)/pikchr.c \
2143 -sENVIRONMENT=web \
2144 -sMODULARIZE \
2145 -sEXPORT_NAME=initPikchrModule \
2146 --minify 0
2147 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
2148
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -569,12 +569,12 @@
569569
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
570570
$(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
571571
572572
$(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
573573
$(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry <<<NEXT_LINE>>>
574
- -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackAlloc,stackRestore <<<NEXT_LINE>>>
575
- -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c <<<NEXT_LINE>>>
574
+ -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore <<<NEXT_LINE>>>
575
+ -sEXPORTED_FUNCTIONS=_pikchr,_pikchr_version $(SRCDIR_extsrc)/pikchr.c <<<NEXT_LINE>>>
576576
-sENVIRONMENT=web <<<NEXT_LINE>>>
577577
-sMODULARIZE <<<NEXT_LINE>>>
578578
-sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
579579
--minify 0
580580
@chmod -x $(SRCDIR_extsrc)/pikchr.wasm
581581
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -569,12 +569,12 @@
569 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
570 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
571
572 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
573 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry <<<NEXT_LINE>>>
574 -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackAlloc,stackRestore <<<NEXT_LINE>>>
575 -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c <<<NEXT_LINE>>>
576 -sENVIRONMENT=web <<<NEXT_LINE>>>
577 -sMODULARIZE <<<NEXT_LINE>>>
578 -sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
579 --minify 0
580 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
581
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -569,12 +569,12 @@
569 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
570 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
571
572 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c $(MAKEFILE_LIST)
573 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry <<<NEXT_LINE>>>
574 -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,setValue,getValue,stackSave,stackAlloc,stackRestore <<<NEXT_LINE>>>
575 -sEXPORTED_FUNCTIONS=_pikchr,_pikchr_version $(SRCDIR_extsrc)/pikchr.c <<<NEXT_LINE>>>
576 -sENVIRONMENT=web <<<NEXT_LINE>>>
577 -sMODULARIZE <<<NEXT_LINE>>>
578 -sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
579 --minify 0
580 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
581

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button