Fossil SCM

Bug fix in pikchr.

drh 2025-03-03 20:57 trunk
Commit c32f97e9e49cc197f3948783a7917dcffbc9c04702554e71832540d4fd198af9
+9 -10
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -486,11 +486,11 @@
486486
static void pik_bbox_addbox(PBox*,PBox*);
487487
static void pik_bbox_add_xy(PBox*,PNum,PNum);
488488
static void pik_bbox_addellipse(PBox*,PNum x,PNum y,PNum rx,PNum ry);
489489
static void pik_add_txt(Pik*,PToken*,int);
490490
static int pik_text_length(const PToken *pToken, const int isMonospace);
491
-static void pik_size_to_fit(Pik*,PToken*,int);
491
+static void pik_size_to_fit(Pik*,PObj*,PToken*,int);
492492
static int pik_text_position(int,PToken*);
493493
static PNum pik_property_of(PObj*,PToken*);
494494
static PNum pik_func(Pik*,PToken*,PNum,PNum);
495495
static PPoint pik_position_between(PNum x, PPoint p1, PPoint p2);
496496
static PPoint pik_position_at_angle(PNum dist, PNum r, PPoint pt);
@@ -2670,11 +2670,11 @@
26702670
{pik_add_txt(p,&yymsp[-1].minor.yy0,yymsp[0].minor.yy188);}
26712671
#line 2696 "pikchr.c"
26722672
break;
26732673
case 48: /* attribute ::= FIT */
26742674
#line 660 "pikchr.y"
2675
-{pik_size_to_fit(p,&yymsp[0].minor.yy0,3); }
2675
+{pik_size_to_fit(p,0,&yymsp[0].minor.yy0,3); }
26762676
#line 2701 "pikchr.c"
26772677
break;
26782678
case 49: /* attribute ::= BEHIND object */
26792679
#line 661 "pikchr.y"
26802680
{pik_behind(p,yymsp[0].minor.yy162);}
@@ -4350,11 +4350,11 @@
43504350
static PPoint textOffset(Pik *p, PObj *pObj, int cp){
43514351
/* Automatically slim-down the width and height of text
43524352
** statements so that the bounding box tightly encloses the text,
43534353
** then get boxOffset() to do the offset computation.
43544354
*/
4355
- pik_size_to_fit(p, &pObj->errTok,3);
4355
+ pik_size_to_fit(p, pObj, &pObj->errTok,3);
43564356
return boxOffset(p, pObj, cp);
43574357
}
43584358
static void textRender(Pik *p, PObj *pObj){
43594359
pik_append_txt(p, pObj, 0);
43604360
}
@@ -6359,16 +6359,15 @@
63596359
**
63606360
** 1: Fit horizontally only
63616361
** 2: Fit vertically only
63626362
** 3: Fit both ways
63636363
*/
6364
-static void pik_size_to_fit(Pik *p, PToken *pFit, int eWhich){
6365
- PObj *pObj;
6364
+static void pik_size_to_fit(Pik *p, PObj *pObj, PToken *pFit, int eWhich){
63666365
PNum w, h;
63676366
PBox bbox;
63686367
if( p->nErr ) return;
6369
- pObj = p->cur;
6368
+ if( pObj==0 ) pObj = p->cur;
63706369
63716370
if( pObj->nTxt==0 ){
63726371
pik_error(0, pFit, "no text to fit to");
63736372
return;
63746373
}
@@ -6908,20 +6907,20 @@
69086907
*/
69096908
if( pObj->h<=0.0 ){
69106909
if( pObj->nTxt==0 ){
69116910
pObj->h = 0.0;
69126911
}else if( pObj->w<=0.0 ){
6913
- pik_size_to_fit(p, &pObj->errTok, 3);
6912
+ pik_size_to_fit(p, pObj, &pObj->errTok, 3);
69146913
}else{
6915
- pik_size_to_fit(p, &pObj->errTok, 2);
6914
+ pik_size_to_fit(p, pObj, &pObj->errTok, 2);
69166915
}
69176916
}
69186917
if( pObj->w<=0.0 ){
69196918
if( pObj->nTxt==0 ){
69206919
pObj->w = 0.0;
69216920
}else{
6922
- pik_size_to_fit(p, &pObj->errTok, 1);
6921
+ pik_size_to_fit(p, pObj, &pObj->errTok, 1);
69236922
}
69246923
}
69256924
ofst = pik_elem_offset(p, pObj, pObj->eWith);
69266925
dx = (pObj->with.x - ofst.x) - pObj->ptAt.x;
69276926
dy = (pObj->with.y - ofst.y) - pObj->ptAt.y;
@@ -8254,6 +8253,6 @@
82548253
82558254
82568255
#endif /* PIKCHR_TCL */
82578256
82588257
8259
-#line 8284 "pikchr.c"
8258
+#line 8283 "pikchr.c"
82608259
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -486,11 +486,11 @@
486 static void pik_bbox_addbox(PBox*,PBox*);
487 static void pik_bbox_add_xy(PBox*,PNum,PNum);
488 static void pik_bbox_addellipse(PBox*,PNum x,PNum y,PNum rx,PNum ry);
489 static void pik_add_txt(Pik*,PToken*,int);
490 static int pik_text_length(const PToken *pToken, const int isMonospace);
491 static void pik_size_to_fit(Pik*,PToken*,int);
492 static int pik_text_position(int,PToken*);
493 static PNum pik_property_of(PObj*,PToken*);
494 static PNum pik_func(Pik*,PToken*,PNum,PNum);
495 static PPoint pik_position_between(PNum x, PPoint p1, PPoint p2);
496 static PPoint pik_position_at_angle(PNum dist, PNum r, PPoint pt);
@@ -2670,11 +2670,11 @@
2670 {pik_add_txt(p,&yymsp[-1].minor.yy0,yymsp[0].minor.yy188);}
2671 #line 2696 "pikchr.c"
2672 break;
2673 case 48: /* attribute ::= FIT */
2674 #line 660 "pikchr.y"
2675 {pik_size_to_fit(p,&yymsp[0].minor.yy0,3); }
2676 #line 2701 "pikchr.c"
2677 break;
2678 case 49: /* attribute ::= BEHIND object */
2679 #line 661 "pikchr.y"
2680 {pik_behind(p,yymsp[0].minor.yy162);}
@@ -4350,11 +4350,11 @@
4350 static PPoint textOffset(Pik *p, PObj *pObj, int cp){
4351 /* Automatically slim-down the width and height of text
4352 ** statements so that the bounding box tightly encloses the text,
4353 ** then get boxOffset() to do the offset computation.
4354 */
4355 pik_size_to_fit(p, &pObj->errTok,3);
4356 return boxOffset(p, pObj, cp);
4357 }
4358 static void textRender(Pik *p, PObj *pObj){
4359 pik_append_txt(p, pObj, 0);
4360 }
@@ -6359,16 +6359,15 @@
6359 **
6360 ** 1: Fit horizontally only
6361 ** 2: Fit vertically only
6362 ** 3: Fit both ways
6363 */
6364 static void pik_size_to_fit(Pik *p, PToken *pFit, int eWhich){
6365 PObj *pObj;
6366 PNum w, h;
6367 PBox bbox;
6368 if( p->nErr ) return;
6369 pObj = p->cur;
6370
6371 if( pObj->nTxt==0 ){
6372 pik_error(0, pFit, "no text to fit to");
6373 return;
6374 }
@@ -6908,20 +6907,20 @@
6908 */
6909 if( pObj->h<=0.0 ){
6910 if( pObj->nTxt==0 ){
6911 pObj->h = 0.0;
6912 }else if( pObj->w<=0.0 ){
6913 pik_size_to_fit(p, &pObj->errTok, 3);
6914 }else{
6915 pik_size_to_fit(p, &pObj->errTok, 2);
6916 }
6917 }
6918 if( pObj->w<=0.0 ){
6919 if( pObj->nTxt==0 ){
6920 pObj->w = 0.0;
6921 }else{
6922 pik_size_to_fit(p, &pObj->errTok, 1);
6923 }
6924 }
6925 ofst = pik_elem_offset(p, pObj, pObj->eWith);
6926 dx = (pObj->with.x - ofst.x) - pObj->ptAt.x;
6927 dy = (pObj->with.y - ofst.y) - pObj->ptAt.y;
@@ -8254,6 +8253,6 @@
8254
8255
8256 #endif /* PIKCHR_TCL */
8257
8258
8259 #line 8284 "pikchr.c"
8260
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -486,11 +486,11 @@
486 static void pik_bbox_addbox(PBox*,PBox*);
487 static void pik_bbox_add_xy(PBox*,PNum,PNum);
488 static void pik_bbox_addellipse(PBox*,PNum x,PNum y,PNum rx,PNum ry);
489 static void pik_add_txt(Pik*,PToken*,int);
490 static int pik_text_length(const PToken *pToken, const int isMonospace);
491 static void pik_size_to_fit(Pik*,PObj*,PToken*,int);
492 static int pik_text_position(int,PToken*);
493 static PNum pik_property_of(PObj*,PToken*);
494 static PNum pik_func(Pik*,PToken*,PNum,PNum);
495 static PPoint pik_position_between(PNum x, PPoint p1, PPoint p2);
496 static PPoint pik_position_at_angle(PNum dist, PNum r, PPoint pt);
@@ -2670,11 +2670,11 @@
2670 {pik_add_txt(p,&yymsp[-1].minor.yy0,yymsp[0].minor.yy188);}
2671 #line 2696 "pikchr.c"
2672 break;
2673 case 48: /* attribute ::= FIT */
2674 #line 660 "pikchr.y"
2675 {pik_size_to_fit(p,0,&yymsp[0].minor.yy0,3); }
2676 #line 2701 "pikchr.c"
2677 break;
2678 case 49: /* attribute ::= BEHIND object */
2679 #line 661 "pikchr.y"
2680 {pik_behind(p,yymsp[0].minor.yy162);}
@@ -4350,11 +4350,11 @@
4350 static PPoint textOffset(Pik *p, PObj *pObj, int cp){
4351 /* Automatically slim-down the width and height of text
4352 ** statements so that the bounding box tightly encloses the text,
4353 ** then get boxOffset() to do the offset computation.
4354 */
4355 pik_size_to_fit(p, pObj, &pObj->errTok,3);
4356 return boxOffset(p, pObj, cp);
4357 }
4358 static void textRender(Pik *p, PObj *pObj){
4359 pik_append_txt(p, pObj, 0);
4360 }
@@ -6359,16 +6359,15 @@
6359 **
6360 ** 1: Fit horizontally only
6361 ** 2: Fit vertically only
6362 ** 3: Fit both ways
6363 */
6364 static void pik_size_to_fit(Pik *p, PObj *pObj, PToken *pFit, int eWhich){
 
6365 PNum w, h;
6366 PBox bbox;
6367 if( p->nErr ) return;
6368 if( pObj==0 ) pObj = p->cur;
6369
6370 if( pObj->nTxt==0 ){
6371 pik_error(0, pFit, "no text to fit to");
6372 return;
6373 }
@@ -6908,20 +6907,20 @@
6907 */
6908 if( pObj->h<=0.0 ){
6909 if( pObj->nTxt==0 ){
6910 pObj->h = 0.0;
6911 }else if( pObj->w<=0.0 ){
6912 pik_size_to_fit(p, pObj, &pObj->errTok, 3);
6913 }else{
6914 pik_size_to_fit(p, pObj, &pObj->errTok, 2);
6915 }
6916 }
6917 if( pObj->w<=0.0 ){
6918 if( pObj->nTxt==0 ){
6919 pObj->w = 0.0;
6920 }else{
6921 pik_size_to_fit(p, pObj, &pObj->errTok, 1);
6922 }
6923 }
6924 ofst = pik_elem_offset(p, pObj, pObj->eWith);
6925 dx = (pObj->with.x - ofst.x) - pObj->ptAt.x;
6926 dy = (pObj->with.y - ofst.y) - pObj->ptAt.y;
@@ -8254,6 +8253,6 @@
8253
8254
8255 #endif /* PIKCHR_TCL */
8256
8257
8258 #line 8283 "pikchr.c"
8259
+166 -130
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,10 +1,11 @@
1
+
12
var initPikchrModule = (() => {
23
var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
34
45
return (
5
-async function(moduleArg = {}) {
6
+function(moduleArg = {}) {
67
var moduleRtn;
78
89
// include: shell.js
910
// The Module object: Our interface to the outside world. We import
1011
// and export values on it. There are various ways Module can be used:
@@ -88,25 +89,25 @@
8889
// If scriptDirectory contains a query (starting with ?) or a fragment (starting with #),
8990
// they are removed because they could contain a slash.
9091
if (scriptDirectory.startsWith("blob:")) {
9192
scriptDirectory = "";
9293
} else {
93
- scriptDirectory = scriptDirectory.slice(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
94
+ scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
9495
}
9596
{
9697
// include: web_or_worker_shell_read.js
97
- readAsync = async url => {
98
- var response = await fetch(url, {
99
- credentials: "same-origin"
100
- });
98
+ readAsync = url => fetch(url, {
99
+ credentials: "same-origin"
100
+ }).then(response => {
101101
if (response.ok) {
102102
return response.arrayBuffer();
103103
}
104
- throw new Error(response.status + " : " + response.url);
105
- };
104
+ return Promise.reject(new Error(response.status + " : " + response.url));
105
+ });
106106
}
107
-} else {}
107
+} else // end include: web_or_worker_shell_read.js
108
+{}
108109
109110
var out = Module["print"] || console.log.bind(console);
110111
111112
var err = Module["printErr"] || console.error.bind(console);
112113
@@ -152,25 +153,13 @@
152153
// NOTE: This is also used as the process return code code in shell environments
153154
// but only when noExitRuntime is false.
154155
var EXITSTATUS;
155156
156157
// 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;
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;
162159
163160
// 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
172161
function updateMemoryViews() {
173162
var b = wasmMemory.buffer;
174163
Module["HEAP8"] = HEAP8 = new Int8Array(b);
175164
Module["HEAP16"] = HEAP16 = new Int16Array(b);
176165
Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
@@ -177,48 +166,77 @@
177166
Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
178167
Module["HEAP32"] = HEAP32 = new Int32Array(b);
179168
Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
180169
Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
181170
Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
182
- Module["HEAP64"] = HEAP64 = new BigInt64Array(b);
183
- Module["HEAPU64"] = HEAPU64 = new BigUint64Array(b);
184171
}
185172
186173
// 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
- if (Module["preRun"]) {
189
- if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ];
190
- while (Module["preRun"].length) {
191
- addOnPreRun(Module["preRun"].shift());
192
- }
188
+ var preRuns = Module["preRun"];
189
+ if (preRuns) {
190
+ if (typeof preRuns == "function") preRuns = [ preRuns ];
191
+ preRuns.forEach(addOnPreRun);
193192
}
194
- callRuntimeCallbacks(onPreRuns);
193
+ callRuntimeCallbacks(__ATPRERUN__);
195194
}
196195
197196
function initRuntime() {
198197
runtimeInitialized = true;
199
- wasmExports["e"]();
198
+ callRuntimeCallbacks(__ATINIT__);
200199
}
201200
202201
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
- }
202
+ var postRuns = Module["postRun"];
203
+ if (postRuns) {
204
+ if (typeof postRuns == "function") postRuns = [ postRuns ];
205
+ postRuns.forEach(addOnPostRun);
208206
}
209
- callRuntimeCallbacks(onPostRuns);
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);
210220
}
211221
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
212228
// A counter of dependencies for calling run(). If we need to
213229
// do asynchronous work before running, increment this and
214230
// decrement it. Incrementing must happen in a place like
215231
// Module.preRun (used by emcc to add file preloading).
216232
// Note that you can add dependencies in preRun, even though
217233
// it happens right before run - run will be postponed until
218234
// the dependencies are met.
219235
var runDependencies = 0;
236
+
237
+var runDependencyWatcher = null;
220238
221239
var dependenciesFulfilled = null;
222240
223241
function addRunDependency(id) {
224242
runDependencies++;
@@ -227,10 +245,14 @@
227245
228246
function removeRunDependency(id) {
229247
runDependencies--;
230248
Module["monitorRunDependencies"]?.(runDependencies);
231249
if (runDependencies == 0) {
250
+ if (runDependencyWatcher !== null) {
251
+ clearInterval(runDependencyWatcher);
252
+ runDependencyWatcher = null;
253
+ }
232254
if (dependenciesFulfilled) {
233255
var callback = dependenciesFulfilled;
234256
dependenciesFulfilled = null;
235257
callback();
236258
}
@@ -263,15 +285,33 @@
263285
// in code paths apart from instantiation where an exception is expected
264286
// to be thrown when abort is called.
265287
throw e;
266288
}
267289
268
-var wasmBinaryFile;
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,";
269295
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
270304
function findWasmBinary() {
271
- return locateFile("pikchr.wasm");
305
+ var f = "pikchr.wasm";
306
+ if (!isDataURI(f)) {
307
+ return locateFile(f);
308
+ }
309
+ return f;
272310
}
311
+
312
+var wasmBinaryFile;
273313
274314
function getBinarySync(file) {
275315
if (file == wasmBinaryFile && wasmBinary) {
276316
return new Uint8Array(wasmBinary);
277317
}
@@ -279,50 +319,48 @@
279319
return readBinary(file);
280320
}
281321
throw "both async and sync fetching of the wasm failed";
282322
}
283323
284
-async function getWasmBinary(binaryFile) {
324
+function getBinaryPromise(binaryFile) {
285325
// If we don't have the binary yet, load it asynchronously using readAsync.
286326
if (!wasmBinary) {
287327
// Fetch the binary using readAsync
288
- try {
289
- var response = await readAsync(binaryFile);
290
- return new Uint8Array(response);
291
- } catch {}
328
+ return readAsync(binaryFile).then(response => new Uint8Array(/** @type{!ArrayBuffer} */ (response)), // Fall back to getBinarySync if readAsync fails
329
+ () => getBinarySync(binaryFile));
292330
}
293331
// Otherwise, getBinarySync should be able to get it synchronously
294
- return getBinarySync(binaryFile);
332
+ return Promise.resolve().then(() => getBinarySync(binaryFile));
295333
}
296334
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) {
335
+function instantiateArrayBuffer(binaryFile, imports, receiver) {
336
+ return getBinaryPromise(binaryFile).then(binary => WebAssembly.instantiate(binary, imports)).then(receiver, reason => {
303337
err(`failed to asynchronously prepare wasm: ${reason}`);
304338
abort(reason);
305
- }
339
+ });
306340
}
307341
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"
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);
313358
});
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);
359
+ });
360
+ }
361
+ return instantiateArrayBuffer(binaryFile, imports, callback);
324362
}
325363
326364
function getWasmImports() {
327365
// prepare imports
328366
return {
@@ -330,18 +368,20 @@
330368
};
331369
}
332370
333371
// Create the wasm instance.
334372
// Receives the wasm imports, returns the exports.
335
-async function createWasm() {
373
+function createWasm() {
374
+ var info = getWasmImports();
336375
// Load the wasm module and create an instance of using native support in the JS engine.
337376
// handle a generated wasm instance, receiving its exports and
338377
// performing other necessary setup
339378
/** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) {
340379
wasmExports = instance.exports;
341380
wasmMemory = wasmExports["d"];
342381
updateMemoryViews();
382
+ addOnInit(wasmExports["e"]);
343383
removeRunDependency("wasm-instantiate");
344384
return wasmExports;
345385
}
346386
// wait for the pthread pool (if any)
347387
addRunDependency("wasm-instantiate");
@@ -349,64 +389,48 @@
349389
function receiveInstantiationResult(result) {
350390
// 'result' is a ResultObject object which has both the module and instance.
351391
// receiveInstance() will swap in the exports (to Module.asm) so they can be called
352392
// 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.
353393
// When the regression is fixed, can restore the above PTHREADS-enabled path.
354
- return receiveInstance(result["instance"]);
394
+ receiveInstance(result["instance"]);
355395
}
356
- var info = getWasmImports();
357396
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
358397
// to manually instantiate the Wasm module themselves. This allows pages to
359398
// run the instantiation parallel to any other async startup actions they are
360399
// performing.
361400
// Also pthreads and wasm workers initialize the wasm instance through this
362401
// path.
363402
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
- });
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
+ }
370410
}
371411
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
- }
412
+ // If instantiation fails, reject the module ready promise.
413
+ instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject);
414
+ return {};
381415
}
382416
417
+// include: runtime_debug.js
418
+// end include: runtime_debug.js
383419
// === Body ===
384420
// 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
- }
421
+/** @constructor */ function ExitStatus(status) {
422
+ this.name = "ExitStatus";
423
+ this.message = `Program terminated with exit(${status})`;
424
+ this.status = status;
391425
}
392426
393427
var callRuntimeCallbacks = callbacks => {
394
- while (callbacks.length > 0) {
395
- // Pass the module as the first argument.
396
- callbacks.shift()(Module);
397
- }
428
+ // Pass the module as the first argument.
429
+ callbacks.forEach(f => f(Module));
398430
};
399431
400
-var onPostRuns = [];
401
-
402
-var addOnPostRun = cb => onPostRuns.unshift(cb);
403
-
404
-var onPreRuns = [];
405
-
406
-var addOnPreRun = cb => onPreRuns.unshift(cb);
407
-
408432
/**
409433
* @param {number} ptr
410434
* @param {string} type
411435
*/ function getValue(ptr, type = "i8") {
412436
if (type.endsWith("*")) type = "*";
@@ -422,11 +446,11 @@
422446
423447
case "i32":
424448
return HEAP32[((ptr) >> 2)];
425449
426450
case "i64":
427
- return HEAP64[((ptr) >> 3)];
451
+ abort("to do getValue(i64) use WASM_BIGINT");
428452
429453
case "float":
430454
return HEAPF32[((ptr) >> 2)];
431455
432456
case "double":
@@ -464,12 +488,11 @@
464488
case "i32":
465489
HEAP32[((ptr) >> 2)] = value;
466490
break;
467491
468492
case "i64":
469
- HEAP64[((ptr) >> 3)] = BigInt(value);
470
- break;
493
+ abort("to do setValue(i64) use WASM_BIGINT");
471494
472495
case "float":
473496
HEAPF32[((ptr) >> 2)] = value;
474497
break;
475498
@@ -560,11 +583,13 @@
560583
* frequent uses of UTF8ToString() with and without maxBytesToRead may throw
561584
* JS JIT optimizations off, so it is worth to consider consistently using one
562585
* @return {string}
563586
*/ var UTF8ToString = (ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
564587
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" ]);
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
+};
566591
567592
var abortOnCannotGrowMemory = requestedSize => {
568593
abort("OOM");
569594
};
570595
@@ -756,21 +781,21 @@
756781
/** @export */ a: ___assert_fail,
757782
/** @export */ b: _emscripten_resize_heap,
758783
/** @export */ c: _exit
759784
};
760785
761
-var wasmExports = await createWasm();
762
-
763
-var ___wasm_call_ctors = wasmExports["e"];
764
-
765
-var _pikchr = Module["_pikchr"] = wasmExports["g"];
766
-
767
-var __emscripten_stack_restore = wasmExports["h"];
768
-
769
-var __emscripten_stack_alloc = wasmExports["i"];
770
-
771
-var _emscripten_stack_get_current = wasmExports["j"];
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"])();
772797
773798
// include: postamble.js
774799
// === Auto-generated postamble setup entry stuff ===
775800
Module["stackSave"] = stackSave;
776801
@@ -782,25 +807,39 @@
782807
783808
Module["setValue"] = setValue;
784809
785810
Module["getValue"] = getValue;
786811
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
787823
function run() {
788824
if (runDependencies > 0) {
789
- dependenciesFulfilled = run;
790825
return;
791826
}
792
- preRun();
793
- // a preRun added a dependency, run will be called later
794
- if (runDependencies > 0) {
795
- dependenciesFulfilled = run;
796
- return;
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
+ }
797834
}
798835
function doRun() {
799836
// run may have just been called through dependencies being fulfilled just in this very frame,
800837
// or while the async setStatus time below was happening
801
- Module["calledRun"] = true;
838
+ if (calledRun) return;
839
+ calledRun = 1;
840
+ Module["calledRun"] = 1;
802841
if (ABORT) return;
803842
initRuntime();
804843
readyPromiseResolve(Module);
805844
Module["onRuntimeInitialized"]?.();
806845
postRun();
@@ -836,12 +875,9 @@
836875
837876
return moduleRtn;
838877
}
839878
);
840879
})();
841
-if (typeof exports === 'object' && typeof module === 'object') {
880
+if (typeof exports === 'object' && typeof module === 'object')
842881
module.exports = initPikchrModule;
843
- // This default export looks redundant, but it allows TS to import this
844
- // commonjs style module.
845
- module.exports.default = initPikchrModule;
846
-} else if (typeof define === 'function' && define['amd'])
882
+else if (typeof define === 'function' && define['amd'])
847883
define([], () => initPikchrModule);
848884
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,10 +1,11 @@
 
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:
@@ -88,25 +89,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
@@ -152,25 +153,13 @@
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);
@@ -177,48 +166,77 @@
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++;
@@ -227,10 +245,14 @@
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 }
@@ -263,15 +285,33 @@
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 }
@@ -279,50 +319,48 @@
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 {
@@ -330,18 +368,20 @@
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");
@@ -349,64 +389,48 @@
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 = "*";
@@ -422,11 +446,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":
@@ -464,12 +488,11 @@
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
@@ -560,11 +583,13 @@
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
@@ -756,21 +781,21 @@
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 = Module["_pikchr"] = wasmExports["g"];
766
767 var __emscripten_stack_restore = wasmExports["h"];
768
769 var __emscripten_stack_alloc = wasmExports["i"];
770
771 var _emscripten_stack_get_current = wasmExports["j"];
772
773 // include: postamble.js
774 // === Auto-generated postamble setup entry stuff ===
775 Module["stackSave"] = stackSave;
776
@@ -782,25 +807,39 @@
782
783 Module["setValue"] = setValue;
784
785 Module["getValue"] = getValue;
786
 
 
 
 
 
 
 
 
 
 
 
787 function run() {
788 if (runDependencies > 0) {
789 dependenciesFulfilled = run;
790 return;
791 }
792 preRun();
793 // a preRun added a dependency, run will be called later
794 if (runDependencies > 0) {
795 dependenciesFulfilled = run;
796 return;
 
 
797 }
798 function doRun() {
799 // run may have just been called through dependencies being fulfilled just in this very frame,
800 // or while the async setStatus time below was happening
801 Module["calledRun"] = true;
 
 
802 if (ABORT) return;
803 initRuntime();
804 readyPromiseResolve(Module);
805 Module["onRuntimeInitialized"]?.();
806 postRun();
@@ -836,12 +875,9 @@
836
837 return moduleRtn;
838 }
839 );
840 })();
841 if (typeof exports === 'object' && typeof module === 'object') {
842 module.exports = initPikchrModule;
843 // This default export looks redundant, but it allows TS to import this
844 // commonjs style module.
845 module.exports.default = initPikchrModule;
846 } else if (typeof define === 'function' && define['amd'])
847 define([], () => initPikchrModule);
848
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,10 +1,11 @@
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:
@@ -88,25 +89,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
@@ -152,25 +153,13 @@
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);
@@ -177,48 +166,77 @@
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++;
@@ -227,10 +245,14 @@
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 }
@@ -263,15 +285,33 @@
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.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 }
@@ -279,50 +319,48 @@
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 {
@@ -330,18 +368,20 @@
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");
@@ -349,64 +389,48 @@
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 = "*";
@@ -422,11 +446,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":
@@ -464,12 +488,11 @@
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
@@ -560,11 +583,13 @@
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
@@ -756,21 +781,21 @@
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
@@ -782,25 +807,39 @@
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();
@@ -836,12 +875,9 @@
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.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

Keyboard Shortcuts

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