Fossil SCM

Rebuild pikchr.js, adding stackAlloc to the list of Emscripten functions which need to be activated.

stephan 2025-02-28 22:33 trunk
Commit b6d02fe9648529c1db25d5ada360fe2b4ac72317d402044b606e8fafb2ce98d0
+751 -617
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,713 +1,847 @@
1
-
21
var initPikchrModule = (() => {
3
- var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
2
+ var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;
43
54
return (
6
-function(config) {
7
- var initPikchrModule = config || {};
5
+async function(moduleArg = {}) {
6
+ var moduleRtn;
87
9
-var Module = typeof initPikchrModule != "undefined" ? initPikchrModule : {};
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:
11
+// 1. Not defined. We create it here
12
+// 2. A function parameter, function(moduleArg) => Promise<Module>
13
+// 3. pre-run appended it, var Module = {}; ..generated code..
14
+// 4. External script tag defines var Module.
15
+// We need to check if Module already exists (e.g. case 3 above).
16
+// Substitution will be replaced with actual code on later stage of the build,
17
+// this way Closure Compiler will not mangle it (e.g. case 4. above).
18
+// Note that if you want to run closure, and also to use Module
19
+// after the generated code, you will need to define var Module = {};
20
+// before the code. Then that object will be used in the code, and you
21
+// can continue to use Module afterwards as well.
22
+var Module = moduleArg;
1023
24
+// Set up the promise that indicates the Module is initialized
1125
var readyPromiseResolve, readyPromiseReject;
1226
13
-Module["ready"] = new Promise(function(resolve, reject) {
14
- readyPromiseResolve = resolve;
15
- readyPromiseReject = reject;
27
+var readyPromise = new Promise((resolve, reject) => {
28
+ readyPromiseResolve = resolve;
29
+ readyPromiseReject = reject;
1630
});
1731
32
+// Determine the runtime environment we are in. You can customize this by
33
+// setting the ENVIRONMENT setting at compile time (see settings.js).
34
+var ENVIRONMENT_IS_WEB = true;
35
+
36
+var ENVIRONMENT_IS_WORKER = false;
37
+
38
+// --pre-jses are emitted after the Module integration code, so that they can
39
+// refer to Module (if they choose; they can also define Module)
40
+// Sometimes an existing Module object exists with properties
41
+// meant to overwrite the default module functionality. Here
42
+// we collect those properties and reapply _after_ we configure
43
+// the current environment's defaults to avoid having to be so
44
+// defensive during initialization.
1845
var moduleOverrides = Object.assign({}, Module);
1946
2047
var arguments_ = [];
2148
2249
var thisProgram = "./this.program";
2350
2451
var quit_ = (status, toThrow) => {
25
- throw toThrow;
52
+ throw toThrow;
2653
};
2754
28
-var ENVIRONMENT_IS_WEB = true;
29
-
30
-var ENVIRONMENT_IS_WORKER = false;
31
-
55
+// `/` should be present at the end if `scriptDirectory` is not empty
3256
var scriptDirectory = "";
3357
3458
function locateFile(path) {
35
- if (Module["locateFile"]) {
36
- return Module["locateFile"](path, scriptDirectory);
37
- }
38
- return scriptDirectory + path;
39
-}
40
-
41
-var read_, readAsync, readBinary, setWindowTitle;
42
-
43
-if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
44
- if (ENVIRONMENT_IS_WORKER) {
45
- scriptDirectory = self.location.href;
46
- } else if (typeof document != "undefined" && document.currentScript) {
47
- scriptDirectory = document.currentScript.src;
48
- }
49
- if (_scriptDir) {
50
- scriptDirectory = _scriptDir;
51
- }
52
- if (scriptDirectory.indexOf("blob:") !== 0) {
53
- scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
54
- } else {
55
- scriptDirectory = "";
56
- }
57
- {
58
- read_ = url => {
59
- var xhr = new XMLHttpRequest();
60
- xhr.open("GET", url, false);
61
- xhr.send(null);
62
- return xhr.responseText;
63
- };
64
- if (ENVIRONMENT_IS_WORKER) {
65
- readBinary = url => {
66
- var xhr = new XMLHttpRequest();
67
- xhr.open("GET", url, false);
68
- xhr.responseType = "arraybuffer";
69
- xhr.send(null);
70
- return new Uint8Array(xhr.response);
71
- };
72
- }
73
- readAsync = (url, onload, onerror) => {
74
- var xhr = new XMLHttpRequest();
75
- xhr.open("GET", url, true);
76
- xhr.responseType = "arraybuffer";
77
- xhr.onload = () => {
78
- if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
79
- onload(xhr.response);
80
- return;
81
- }
82
- onerror();
83
- };
84
- xhr.onerror = onerror;
85
- xhr.send(null);
86
- };
87
- }
88
- setWindowTitle = title => document.title = title;
59
+ if (Module["locateFile"]) {
60
+ return Module["locateFile"](path, scriptDirectory);
61
+ }
62
+ return scriptDirectory + path;
63
+}
64
+
65
+// Hooks that are implemented differently in different runtime environments.
66
+var readAsync, readBinary;
67
+
68
+// Note that this includes Node.js workers when relevant (pthreads is enabled).
69
+// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
70
+// ENVIRONMENT_IS_NODE.
71
+if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
72
+ if (ENVIRONMENT_IS_WORKER) {
73
+ // Check worker, not web, since window could be polyfilled
74
+ scriptDirectory = self.location.href;
75
+ } else if (typeof document != "undefined" && document.currentScript) {
76
+ // web
77
+ scriptDirectory = document.currentScript.src;
78
+ }
79
+ // When MODULARIZE, this JS may be executed later, after document.currentScript
80
+ // is gone, so we saved it, and we use it here instead of any other info.
81
+ if (_scriptName) {
82
+ scriptDirectory = _scriptName;
83
+ }
84
+ // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
85
+ // otherwise, slice off the final part of the url to find the script directory.
86
+ // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
87
+ // and scriptDirectory will correctly be replaced with an empty string.
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
+ }
89107
} else {}
90108
91109
var out = Module["print"] || console.log.bind(console);
92110
93
-var err = Module["printErr"] || console.warn.bind(console);
111
+var err = Module["printErr"] || console.error.bind(console);
94112
113
+// Merge back in the overrides
95114
Object.assign(Module, moduleOverrides);
96115
116
+// Free the object hierarchy contained in the overrides, this lets the GC
117
+// reclaim data used.
97118
moduleOverrides = null;
98119
120
+// Emit code to handle expected values on the Module object. This applies Module.x
121
+// to the proper local x. This has two benefits: first, we only emit it if it is
122
+// expected to arrive, and second, by using a local everywhere else that can be
123
+// minified.
99124
if (Module["arguments"]) arguments_ = Module["arguments"];
100125
101126
if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
102127
103
-if (Module["quit"]) quit_ = Module["quit"];
104
-
105
-var wasmBinary;
106
-
107
-if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
108
-
109
-var noExitRuntime = Module["noExitRuntime"] || true;
110
-
111
-if (typeof WebAssembly != "object") {
112
- abort("no native wasm support detected");
113
-}
114
-
128
+// perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
129
+// end include: shell.js
130
+// include: preamble.js
131
+// === Preamble library stuff ===
132
+// Documentation for the public APIs defined in this file must be updated in:
133
+// site/source/docs/api_reference/preamble.js.rst
134
+// A prebuilt local version of the documentation is available at:
135
+// site/build/text/docs/api_reference/preamble.js.txt
136
+// You can also build docs locally as HTML or other formats in site/
137
+// An online HTML version (which may be of a different version of Emscripten)
138
+// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
139
+var wasmBinary = Module["wasmBinary"];
140
+
141
+// Wasm globals
115142
var wasmMemory;
116143
144
+//========================================
145
+// Runtime essentials
146
+//========================================
147
+// whether we are quitting the application. no code should run after this.
148
+// set in exit() and abort()
117149
var ABORT = false;
118150
151
+// set by exit() and abort(). Passed to 'onExit' handler.
152
+// NOTE: This is also used as the process return code code in shell environments
153
+// but only when noExitRuntime is false.
119154
var EXITSTATUS;
120155
121
-var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : undefined;
122
-
123
-function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead) {
124
- var endIdx = idx + maxBytesToRead;
125
- var endPtr = idx;
126
- while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
127
- if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
128
- return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
129
- }
130
- var str = "";
131
- while (idx < endPtr) {
132
- var u0 = heapOrArray[idx++];
133
- if (!(u0 & 128)) {
134
- str += String.fromCharCode(u0);
135
- continue;
136
- }
137
- var u1 = heapOrArray[idx++] & 63;
138
- if ((u0 & 224) == 192) {
139
- str += String.fromCharCode((u0 & 31) << 6 | u1);
140
- continue;
141
- }
142
- var u2 = heapOrArray[idx++] & 63;
143
- if ((u0 & 240) == 224) {
144
- u0 = (u0 & 15) << 12 | u1 << 6 | u2;
145
- } else {
146
- u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63;
147
- }
148
- if (u0 < 65536) {
149
- str += String.fromCharCode(u0);
150
- } else {
151
- var ch = u0 - 65536;
152
- str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
153
- }
154
- }
155
- return str;
156
-}
157
-
158
-function UTF8ToString(ptr, maxBytesToRead) {
159
- return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
160
-}
161
-
162
-function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
163
- if (!(maxBytesToWrite > 0)) return 0;
164
- var startIdx = outIdx;
165
- var endIdx = outIdx + maxBytesToWrite - 1;
166
- for (var i = 0; i < str.length; ++i) {
167
- var u = str.charCodeAt(i);
168
- if (u >= 55296 && u <= 57343) {
169
- var u1 = str.charCodeAt(++i);
170
- u = 65536 + ((u & 1023) << 10) | u1 & 1023;
171
- }
172
- if (u <= 127) {
173
- if (outIdx >= endIdx) break;
174
- heap[outIdx++] = u;
175
- } else if (u <= 2047) {
176
- if (outIdx + 1 >= endIdx) break;
177
- heap[outIdx++] = 192 | u >> 6;
178
- heap[outIdx++] = 128 | u & 63;
179
- } else if (u <= 65535) {
180
- if (outIdx + 2 >= endIdx) break;
181
- heap[outIdx++] = 224 | u >> 12;
182
- heap[outIdx++] = 128 | u >> 6 & 63;
183
- heap[outIdx++] = 128 | u & 63;
184
- } else {
185
- if (outIdx + 3 >= endIdx) break;
186
- heap[outIdx++] = 240 | u >> 18;
187
- heap[outIdx++] = 128 | u >> 12 & 63;
188
- heap[outIdx++] = 128 | u >> 6 & 63;
189
- heap[outIdx++] = 128 | u & 63;
190
- }
191
- }
192
- heap[outIdx] = 0;
193
- return outIdx - startIdx;
194
-}
195
-
196
-function stringToUTF8(str, outPtr, maxBytesToWrite) {
197
- return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
198
-}
199
-
200
-var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
201
-
202
-function updateMemoryViews() {
203
- var b = wasmMemory.buffer;
204
- Module["HEAP8"] = HEAP8 = new Int8Array(b);
205
- Module["HEAP16"] = HEAP16 = new Int16Array(b);
206
- Module["HEAP32"] = HEAP32 = new Int32Array(b);
207
- Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
208
- Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
209
- Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
210
- Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
211
- Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
212
-}
213
-
214
-var INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 16777216;
215
-
216
-var wasmTable;
217
-
218
-var __ATPRERUN__ = [];
219
-
220
-var __ATINIT__ = [];
221
-
222
-var __ATPOSTRUN__ = [];
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;
223160
224161
var runtimeInitialized = false;
225162
226
-function keepRuntimeAlive() {
227
- return noExitRuntime;
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
+ 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);
228184
}
229185
186
+// end include: runtime_shared.js
230187
function preRun() {
231
- if (Module["preRun"]) {
232
- if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ];
233
- while (Module["preRun"].length) {
234
- addOnPreRun(Module["preRun"].shift());
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
+ }
235193
}
236
- }
237
- callRuntimeCallbacks(__ATPRERUN__);
194
+ callRuntimeCallbacks(onPreRuns);
238195
}
239196
240197
function initRuntime() {
241
- runtimeInitialized = true;
242
- callRuntimeCallbacks(__ATINIT__);
198
+ runtimeInitialized = true;
199
+ wasmExports["e"]();
243200
}
244201
245202
function postRun() {
246
- if (Module["postRun"]) {
247
- if (typeof Module["postRun"] == "function") Module["postRun"] = [ Module["postRun"] ];
248
- while (Module["postRun"].length) {
249
- addOnPostRun(Module["postRun"].shift());
250
- }
251
- }
252
- callRuntimeCallbacks(__ATPOSTRUN__);
253
-}
254
-
255
-function addOnPreRun(cb) {
256
- __ATPRERUN__.unshift(cb);
257
-}
258
-
259
-function addOnInit(cb) {
260
- __ATINIT__.unshift(cb);
261
-}
262
-
263
-function addOnPostRun(cb) {
264
- __ATPOSTRUN__.unshift(cb);
265
-}
266
-
267
-var runDependencies = 0;
268
-
269
-var runDependencyWatcher = null;
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;
270220
271221
var dependenciesFulfilled = null;
272222
273223
function addRunDependency(id) {
274
- runDependencies++;
275
- if (Module["monitorRunDependencies"]) {
276
- Module["monitorRunDependencies"](runDependencies);
277
- }
224
+ runDependencies++;
225
+ Module["monitorRunDependencies"]?.(runDependencies);
278226
}
279227
280228
function removeRunDependency(id) {
281
- runDependencies--;
282
- if (Module["monitorRunDependencies"]) {
283
- Module["monitorRunDependencies"](runDependencies);
284
- }
285
- if (runDependencies == 0) {
286
- if (runDependencyWatcher !== null) {
287
- clearInterval(runDependencyWatcher);
288
- runDependencyWatcher = null;
289
- }
290
- if (dependenciesFulfilled) {
291
- var callback = dependenciesFulfilled;
292
- dependenciesFulfilled = null;
293
- callback();
294
- }
295
- }
296
-}
297
-
298
-function abort(what) {
299
- if (Module["onAbort"]) {
300
- Module["onAbort"](what);
301
- }
302
- what = "Aborted(" + what + ")";
303
- err(what);
304
- ABORT = true;
305
- EXITSTATUS = 1;
306
- what += ". Build with -sASSERTIONS for more info.";
307
- var e = new WebAssembly.RuntimeError(what);
308
- readyPromiseReject(e);
309
- throw e;
310
-}
311
-
312
-var dataURIPrefix = "data:application/octet-stream;base64,";
313
-
314
-function isDataURI(filename) {
315
- return filename.startsWith(dataURIPrefix);
229
+ runDependencies--;
230
+ Module["monitorRunDependencies"]?.(runDependencies);
231
+ if (runDependencies == 0) {
232
+ if (dependenciesFulfilled) {
233
+ var callback = dependenciesFulfilled;
234
+ dependenciesFulfilled = null;
235
+ callback();
236
+ }
237
+ }
238
+}
239
+
240
+/** @param {string|number=} what */ function abort(what) {
241
+ Module["onAbort"]?.(what);
242
+ what = "Aborted(" + what + ")";
243
+ // TODO(sbc): Should we remove printing and leave it up to whoever
244
+ // catches the exception?
245
+ err(what);
246
+ ABORT = true;
247
+ what += ". Build with -sASSERTIONS for more info.";
248
+ // Use a wasm runtime error, because a JS error might be seen as a foreign
249
+ // exception, which means we'd run destructors on it. We need the error to
250
+ // simply make the program stop.
251
+ // FIXME This approach does not work in Wasm EH because it currently does not assume
252
+ // all RuntimeErrors are from traps; it decides whether a RuntimeError is from
253
+ // a trap or not based on a hidden field within the object. So at the moment
254
+ // we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
255
+ // allows this in the wasm spec.
256
+ // Suppress closure compiler warning here. Closure compiler's builtin extern
257
+ // definition for WebAssembly.RuntimeError claims it takes no arguments even
258
+ // though it can.
259
+ // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
260
+ /** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what);
261
+ readyPromiseReject(e);
262
+ // Throw the error whether or not MODULARIZE is set because abort is used
263
+ // in code paths apart from instantiation where an exception is expected
264
+ // to be thrown when abort is called.
265
+ throw e;
316266
}
317267
318268
var wasmBinaryFile;
319269
320
-wasmBinaryFile = "pikchr.wasm";
321
-
322
-if (!isDataURI(wasmBinaryFile)) {
323
- wasmBinaryFile = locateFile(wasmBinaryFile);
270
+function findWasmBinary() {
271
+ return locateFile("pikchr.wasm");
324272
}
325273
326
-function getBinary(file) {
327
- try {
274
+function getBinarySync(file) {
328275
if (file == wasmBinaryFile && wasmBinary) {
329
- return new Uint8Array(wasmBinary);
276
+ return new Uint8Array(wasmBinary);
330277
}
331278
if (readBinary) {
332
- return readBinary(file);
279
+ return readBinary(file);
333280
}
334281
throw "both async and sync fetching of the wasm failed";
335
- } catch (err) {
336
- abort(err);
337
- }
338
-}
339
-
340
-function getBinaryPromise() {
341
- if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
342
- if (typeof fetch == "function") {
343
- return fetch(wasmBinaryFile, {
344
- credentials: "same-origin"
345
- }).then(function(response) {
346
- if (!response["ok"]) {
347
- throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
348
- }
349
- return response["arrayBuffer"]();
350
- }).catch(function() {
351
- return getBinary(wasmBinaryFile);
352
- });
353
- }
354
- }
355
- return Promise.resolve().then(function() {
356
- return getBinary(wasmBinaryFile);
357
- });
358
-}
359
-
360
-function createWasm() {
361
- var info = {
362
- "a": asmLibraryArg
363
- };
364
- function receiveInstance(instance, module) {
365
- var exports = instance.exports;
366
- Module["asm"] = exports;
367
- wasmMemory = Module["asm"]["d"];
368
- updateMemoryViews();
369
- wasmTable = Module["asm"]["g"];
370
- addOnInit(Module["asm"]["e"]);
371
- removeRunDependency("wasm-instantiate");
372
- }
373
- addRunDependency("wasm-instantiate");
374
- function receiveInstantiationResult(result) {
375
- receiveInstance(result["instance"]);
376
- }
377
- function instantiateArrayBuffer(receiver) {
378
- return getBinaryPromise().then(function(binary) {
379
- return WebAssembly.instantiate(binary, info);
380
- }).then(function(instance) {
381
- return instance;
382
- }).then(receiver, function(reason) {
383
- err("failed to asynchronously prepare wasm: " + reason);
384
- abort(reason);
385
- });
386
- }
387
- function instantiateAsync() {
388
- if (!wasmBinary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(wasmBinaryFile) && typeof fetch == "function") {
389
- return fetch(wasmBinaryFile, {
390
- credentials: "same-origin"
391
- }).then(function(response) {
392
- var result = WebAssembly.instantiateStreaming(response, info);
393
- return result.then(receiveInstantiationResult, function(reason) {
394
- err("wasm streaming compile failed: " + reason);
395
- err("falling back to ArrayBuffer instantiation");
396
- return instantiateArrayBuffer(receiveInstantiationResult);
397
- });
398
- });
399
- } else {
400
- return instantiateArrayBuffer(receiveInstantiationResult);
401
- }
402
- }
403
- if (Module["instantiateWasm"]) {
404
- try {
405
- var exports = Module["instantiateWasm"](info, receiveInstance);
406
- return exports;
407
- } catch (e) {
408
- err("Module.instantiateWasm callback failed with error: " + e);
409
- readyPromiseReject(e);
410
- }
411
- }
412
- instantiateAsync().catch(readyPromiseReject);
413
- return {};
414
-}
415
-
416
-var tempDouble;
417
-
418
-var tempI64;
419
-
420
-function ExitStatus(status) {
421
- this.name = "ExitStatus";
422
- this.message = "Program terminated with exit(" + status + ")";
423
- this.status = status;
424
-}
425
-
426
-function callRuntimeCallbacks(callbacks) {
427
- while (callbacks.length > 0) {
428
- callbacks.shift()(Module);
429
- }
430
-}
431
-
432
-function getValue(ptr, type = "i8") {
433
- if (type.endsWith("*")) type = "*";
434
- switch (type) {
435
- case "i1":
436
- return HEAP8[ptr >> 0];
437
-
438
- case "i8":
439
- return HEAP8[ptr >> 0];
440
-
441
- case "i16":
442
- return HEAP16[ptr >> 1];
443
-
444
- case "i32":
445
- return HEAP32[ptr >> 2];
446
-
447
- case "i64":
448
- return HEAP32[ptr >> 2];
449
-
450
- case "float":
451
- return HEAPF32[ptr >> 2];
452
-
453
- case "double":
454
- return HEAPF64[ptr >> 3];
455
-
456
- case "*":
457
- return HEAPU32[ptr >> 2];
458
-
459
- default:
460
- abort("invalid type for getValue: " + type);
461
- }
462
- return null;
463
-}
464
-
465
-function setValue(ptr, value, type = "i8") {
466
- if (type.endsWith("*")) type = "*";
467
- switch (type) {
468
- case "i1":
469
- HEAP8[ptr >> 0] = value;
470
- break;
471
-
472
- case "i8":
473
- HEAP8[ptr >> 0] = value;
474
- break;
475
-
476
- case "i16":
477
- HEAP16[ptr >> 1] = value;
478
- break;
479
-
480
- case "i32":
481
- HEAP32[ptr >> 2] = value;
482
- break;
483
-
484
- case "i64":
485
- tempI64 = [ value >>> 0, (tempDouble = value, +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? (Math.min(+Math.floor(tempDouble / 4294967296), 4294967295) | 0) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0) ],
486
- HEAP32[ptr >> 2] = tempI64[0], HEAP32[ptr + 4 >> 2] = tempI64[1];
487
- break;
488
-
489
- case "float":
490
- HEAPF32[ptr >> 2] = value;
491
- break;
492
-
493
- case "double":
494
- HEAPF64[ptr >> 3] = value;
495
- break;
496
-
497
- case "*":
498
- HEAPU32[ptr >> 2] = value;
499
- break;
500
-
501
- default:
502
- abort("invalid type for setValue: " + type);
503
- }
504
-}
505
-
506
-function ___assert_fail(condition, filename, line, func) {
507
- abort("Assertion failed: " + UTF8ToString(condition) + ", at: " + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]);
508
-}
509
-
510
-function abortOnCannotGrowMemory(requestedSize) {
511
- abort("OOM");
512
-}
513
-
514
-function _emscripten_resize_heap(requestedSize) {
515
- var oldSize = HEAPU8.length;
516
- requestedSize = requestedSize >>> 0;
517
- abortOnCannotGrowMemory(requestedSize);
518
-}
519
-
520
-var SYSCALLS = {
521
- varargs: undefined,
522
- get: function() {
523
- SYSCALLS.varargs += 4;
524
- var ret = HEAP32[SYSCALLS.varargs - 4 >> 2];
525
- return ret;
526
- },
527
- getStr: function(ptr) {
528
- var ret = UTF8ToString(ptr);
529
- return ret;
530
- }
531
-};
532
-
533
-function _proc_exit(code) {
534
- EXITSTATUS = code;
535
- if (!keepRuntimeAlive()) {
536
- if (Module["onExit"]) Module["onExit"](code);
537
- ABORT = true;
538
- }
539
- quit_(code, new ExitStatus(code));
540
-}
541
-
542
-function exitJS(status, implicit) {
543
- EXITSTATUS = status;
544
- _proc_exit(status);
545
-}
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 {
329
+ "a": wasmImports
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");
348
+ // Prefer streaming instantiation if available.
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 = "*";
413
+ switch (type) {
414
+ case "i1":
415
+ return HEAP8[ptr];
416
+
417
+ case "i8":
418
+ return HEAP8[ptr];
419
+
420
+ case "i16":
421
+ return HEAP16[((ptr) >> 1)];
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":
433
+ return HEAPF64[((ptr) >> 3)];
434
+
435
+ case "*":
436
+ return HEAPU32[((ptr) >> 2)];
437
+
438
+ default:
439
+ abort(`invalid type for getValue: ${type}`);
440
+ }
441
+}
442
+
443
+var noExitRuntime = Module["noExitRuntime"] || true;
444
+
445
+/**
446
+ * @param {number} ptr
447
+ * @param {number} value
448
+ * @param {string} type
449
+ */ function setValue(ptr, value, type = "i8") {
450
+ if (type.endsWith("*")) type = "*";
451
+ switch (type) {
452
+ case "i1":
453
+ HEAP8[ptr] = value;
454
+ break;
455
+
456
+ case "i8":
457
+ HEAP8[ptr] = value;
458
+ break;
459
+
460
+ case "i16":
461
+ HEAP16[((ptr) >> 1)] = value;
462
+ break;
463
+
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
+
476
+ case "double":
477
+ HEAPF64[((ptr) >> 3)] = value;
478
+ break;
479
+
480
+ case "*":
481
+ HEAPU32[((ptr) >> 2)] = value;
482
+ break;
483
+
484
+ default:
485
+ abort(`invalid type for setValue: ${type}`);
486
+ }
487
+}
488
+
489
+var stackRestore = val => __emscripten_stack_restore(val);
490
+
491
+var stackSave = () => _emscripten_stack_get_current();
492
+
493
+var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder : undefined;
494
+
495
+/**
496
+ * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
497
+ * array that contains uint8 values, returns a copy of that string as a
498
+ * Javascript String object.
499
+ * heapOrArray is either a regular array, or a JavaScript typed array view.
500
+ * @param {number=} idx
501
+ * @param {number=} maxBytesToRead
502
+ * @return {string}
503
+ */ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead = NaN) => {
504
+ var endIdx = idx + maxBytesToRead;
505
+ var endPtr = idx;
506
+ // TextDecoder needs to know the byte length in advance, it doesn't stop on
507
+ // null terminator by itself. Also, use the length info to avoid running tiny
508
+ // strings through TextDecoder, since .subarray() allocates garbage.
509
+ // (As a tiny code save trick, compare endPtr against endIdx using a negation,
510
+ // so that undefined/NaN means Infinity)
511
+ while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
512
+ if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
513
+ return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
514
+ }
515
+ var str = "";
516
+ // If building with TextDecoder, we have already computed the string length
517
+ // above, so test loop end condition against that
518
+ while (idx < endPtr) {
519
+ // For UTF8 byte structure, see:
520
+ // http://en.wikipedia.org/wiki/UTF-8#Description
521
+ // https://www.ietf.org/rfc/rfc2279.txt
522
+ // https://tools.ietf.org/html/rfc3629
523
+ var u0 = heapOrArray[idx++];
524
+ if (!(u0 & 128)) {
525
+ str += String.fromCharCode(u0);
526
+ continue;
527
+ }
528
+ var u1 = heapOrArray[idx++] & 63;
529
+ if ((u0 & 224) == 192) {
530
+ str += String.fromCharCode(((u0 & 31) << 6) | u1);
531
+ continue;
532
+ }
533
+ var u2 = heapOrArray[idx++] & 63;
534
+ if ((u0 & 240) == 224) {
535
+ u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
536
+ } else {
537
+ u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
538
+ }
539
+ if (u0 < 65536) {
540
+ str += String.fromCharCode(u0);
541
+ } else {
542
+ var ch = u0 - 65536;
543
+ str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
544
+ }
545
+ }
546
+ return str;
547
+};
548
+
549
+/**
550
+ * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
551
+ * emscripten HEAP, returns a copy of that string as a Javascript String object.
552
+ *
553
+ * @param {number} ptr
554
+ * @param {number=} maxBytesToRead - An optional length that specifies the
555
+ * maximum number of bytes to read. You can omit this parameter to scan the
556
+ * string until the first 0 byte. If maxBytesToRead is passed, and the string
557
+ * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
558
+ * string will cut short at that byte index (i.e. maxBytesToRead will not
559
+ * produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing
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
+
571
+var _emscripten_resize_heap = requestedSize => {
572
+ var oldSize = HEAPU8.length;
573
+ // With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
574
+ requestedSize >>>= 0;
575
+ abortOnCannotGrowMemory(requestedSize);
576
+};
577
+
578
+var runtimeKeepaliveCounter = 0;
579
+
580
+var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
581
+
582
+var _proc_exit = code => {
583
+ EXITSTATUS = code;
584
+ if (!keepRuntimeAlive()) {
585
+ Module["onExit"]?.(code);
586
+ ABORT = true;
587
+ }
588
+ quit_(code, new ExitStatus(code));
589
+};
590
+
591
+/** @suppress {duplicate } */ /** @param {boolean|number=} implicit */ var exitJS = (status, implicit) => {
592
+ EXITSTATUS = status;
593
+ _proc_exit(status);
594
+};
546595
547596
var _exit = exitJS;
548597
549
-function getCFunc(ident) {
550
- var func = Module["_" + ident];
551
- return func;
552
-}
553
-
554
-function writeArrayToMemory(array, buffer) {
555
- HEAP8.set(array, buffer);
556
-}
557
-
558
-function ccall(ident, returnType, argTypes, args, opts) {
559
- var toC = {
560
- "string": str => {
561
- var ret = 0;
562
- if (str !== null && str !== undefined && str !== 0) {
563
- var len = (str.length << 2) + 1;
564
- ret = stackAlloc(len);
565
- stringToUTF8(str, ret, len);
566
- }
567
- return ret;
568
- },
569
- "array": arr => {
570
- var ret = stackAlloc(arr.length);
571
- writeArrayToMemory(arr, ret);
572
- return ret;
573
- }
574
- };
575
- function convertReturnValue(ret) {
576
- if (returnType === "string") {
577
- return UTF8ToString(ret);
578
- }
579
- if (returnType === "boolean") return Boolean(ret);
580
- return ret;
581
- }
582
- var func = getCFunc(ident);
583
- var cArgs = [];
584
- var stack = 0;
585
- if (args) {
586
- for (var i = 0; i < args.length; i++) {
587
- var converter = toC[argTypes[i]];
588
- if (converter) {
589
- if (stack === 0) stack = stackSave();
590
- cArgs[i] = converter(args[i]);
591
- } else {
592
- cArgs[i] = args[i];
593
- }
594
- }
595
- }
596
- var ret = func.apply(null, cArgs);
597
- function onDone(ret) {
598
- if (stack !== 0) stackRestore(stack);
599
- return convertReturnValue(ret);
600
- }
601
- ret = onDone(ret);
602
- return ret;
603
-}
604
-
605
-function cwrap(ident, returnType, argTypes, opts) {
606
- argTypes = argTypes || [];
607
- var numericArgs = argTypes.every(type => type === "number" || type === "boolean");
608
- var numericRet = returnType !== "string";
609
- if (numericRet && numericArgs && !opts) {
610
- return getCFunc(ident);
611
- }
612
- return function() {
613
- return ccall(ident, returnType, argTypes, arguments, opts);
614
- };
615
-}
616
-
617
-var asmLibraryArg = {
618
- "a": ___assert_fail,
619
- "b": _emscripten_resize_heap,
620
- "c": _exit
621
-};
622
-
623
-var asm = createWasm();
624
-
625
-var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() {
626
- return (___wasm_call_ctors = Module["___wasm_call_ctors"] = Module["asm"]["e"]).apply(null, arguments);
627
-};
628
-
629
-var _pikchr = Module["_pikchr"] = function() {
630
- return (_pikchr = Module["_pikchr"] = Module["asm"]["f"]).apply(null, arguments);
631
-};
632
-
633
-var stackSave = Module["stackSave"] = function() {
634
- return (stackSave = Module["stackSave"] = Module["asm"]["h"]).apply(null, arguments);
635
-};
636
-
637
-var stackRestore = Module["stackRestore"] = function() {
638
- return (stackRestore = Module["stackRestore"] = Module["asm"]["i"]).apply(null, arguments);
639
-};
640
-
641
-var stackAlloc = Module["stackAlloc"] = function() {
642
- return (stackAlloc = Module["stackAlloc"] = Module["asm"]["j"]).apply(null, arguments);
643
-};
644
-
598
+var getCFunc = ident => {
599
+ var func = Module["_" + ident];
600
+ // closure exported function
601
+ return func;
602
+};
603
+
604
+var writeArrayToMemory = (array, buffer) => {
605
+ HEAP8.set(array, buffer);
606
+};
607
+
608
+var lengthBytesUTF8 = str => {
609
+ var len = 0;
610
+ for (var i = 0; i < str.length; ++i) {
611
+ // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
612
+ // unit, not a Unicode code point of the character! So decode
613
+ // UTF16->UTF32->UTF8.
614
+ // See http://unicode.org/faq/utf_bom.html#utf16-3
615
+ var c = str.charCodeAt(i);
616
+ // possibly a lead surrogate
617
+ if (c <= 127) {
618
+ len++;
619
+ } else if (c <= 2047) {
620
+ len += 2;
621
+ } else if (c >= 55296 && c <= 57343) {
622
+ len += 4;
623
+ ++i;
624
+ } else {
625
+ len += 3;
626
+ }
627
+ }
628
+ return len;
629
+};
630
+
631
+var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
632
+ // Parameter maxBytesToWrite is not optional. Negative values, 0, null,
633
+ // undefined and false each don't write out any bytes.
634
+ if (!(maxBytesToWrite > 0)) return 0;
635
+ var startIdx = outIdx;
636
+ var endIdx = outIdx + maxBytesToWrite - 1;
637
+ // -1 for string null terminator.
638
+ for (var i = 0; i < str.length; ++i) {
639
+ // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
640
+ // unit, not a Unicode code point of the character! So decode
641
+ // UTF16->UTF32->UTF8.
642
+ // See http://unicode.org/faq/utf_bom.html#utf16-3
643
+ // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
644
+ // and https://www.ietf.org/rfc/rfc2279.txt
645
+ // and https://tools.ietf.org/html/rfc3629
646
+ var u = str.charCodeAt(i);
647
+ // possibly a lead surrogate
648
+ if (u >= 55296 && u <= 57343) {
649
+ var u1 = str.charCodeAt(++i);
650
+ u = 65536 + ((u & 1023) << 10) | (u1 & 1023);
651
+ }
652
+ if (u <= 127) {
653
+ if (outIdx >= endIdx) break;
654
+ heap[outIdx++] = u;
655
+ } else if (u <= 2047) {
656
+ if (outIdx + 1 >= endIdx) break;
657
+ heap[outIdx++] = 192 | (u >> 6);
658
+ heap[outIdx++] = 128 | (u & 63);
659
+ } else if (u <= 65535) {
660
+ if (outIdx + 2 >= endIdx) break;
661
+ heap[outIdx++] = 224 | (u >> 12);
662
+ heap[outIdx++] = 128 | ((u >> 6) & 63);
663
+ heap[outIdx++] = 128 | (u & 63);
664
+ } else {
665
+ if (outIdx + 3 >= endIdx) break;
666
+ heap[outIdx++] = 240 | (u >> 18);
667
+ heap[outIdx++] = 128 | ((u >> 12) & 63);
668
+ heap[outIdx++] = 128 | ((u >> 6) & 63);
669
+ heap[outIdx++] = 128 | (u & 63);
670
+ }
671
+ }
672
+ // Null-terminate the pointer to the buffer.
673
+ heap[outIdx] = 0;
674
+ return outIdx - startIdx;
675
+};
676
+
677
+var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
678
+
679
+var stackAlloc = sz => __emscripten_stack_alloc(sz);
680
+
681
+var stringToUTF8OnStack = str => {
682
+ var size = lengthBytesUTF8(str) + 1;
683
+ var ret = stackAlloc(size);
684
+ stringToUTF8(str, ret, size);
685
+ return ret;
686
+};
687
+
688
+/**
689
+ * @param {string|null=} returnType
690
+ * @param {Array=} argTypes
691
+ * @param {Arguments|Array=} args
692
+ * @param {Object=} opts
693
+ */ var ccall = (ident, returnType, argTypes, args, opts) => {
694
+ // For fast lookup of conversion functions
695
+ var toC = {
696
+ "string": str => {
697
+ var ret = 0;
698
+ if (str !== null && str !== undefined && str !== 0) {
699
+ // null string
700
+ ret = stringToUTF8OnStack(str);
701
+ }
702
+ return ret;
703
+ },
704
+ "array": arr => {
705
+ var ret = stackAlloc(arr.length);
706
+ writeArrayToMemory(arr, ret);
707
+ return ret;
708
+ }
709
+ };
710
+ function convertReturnValue(ret) {
711
+ if (returnType === "string") {
712
+ return UTF8ToString(ret);
713
+ }
714
+ if (returnType === "boolean") return Boolean(ret);
715
+ return ret;
716
+ }
717
+ var func = getCFunc(ident);
718
+ var cArgs = [];
719
+ var stack = 0;
720
+ if (args) {
721
+ for (var i = 0; i < args.length; i++) {
722
+ var converter = toC[argTypes[i]];
723
+ if (converter) {
724
+ if (stack === 0) stack = stackSave();
725
+ cArgs[i] = converter(args[i]);
726
+ } else {
727
+ cArgs[i] = args[i];
728
+ }
729
+ }
730
+ }
731
+ var ret = func(...cArgs);
732
+ function onDone(ret) {
733
+ if (stack !== 0) stackRestore(stack);
734
+ return convertReturnValue(ret);
735
+ }
736
+ ret = onDone(ret);
737
+ return ret;
738
+};
739
+
740
+/**
741
+ * @param {string=} returnType
742
+ * @param {Array=} argTypes
743
+ * @param {Object=} opts
744
+ */ var cwrap = (ident, returnType, argTypes, opts) => {
745
+ // When the function takes numbers and returns a number, we can just return
746
+ // the original function
747
+ var numericArgs = !argTypes || argTypes.every(type => type === "number" || type === "boolean");
748
+ var numericRet = returnType !== "string";
749
+ if (numericRet && numericArgs && !opts) {
750
+ return getCFunc(ident);
751
+ }
752
+ return (...args) => ccall(ident, returnType, argTypes, args, opts);
753
+};
754
+
755
+var wasmImports = {
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 ===
645775
Module["stackSave"] = stackSave;
646776
647777
Module["stackRestore"] = stackRestore;
778
+
779
+Module["stackAlloc"] = stackAlloc;
648780
649781
Module["cwrap"] = cwrap;
650782
651783
Module["setValue"] = setValue;
652784
653785
Module["getValue"] = getValue;
654786
655
-var calledRun;
656
-
657
-dependenciesFulfilled = function runCaller() {
658
- if (!calledRun) run();
659
- if (!calledRun) dependenciesFulfilled = runCaller;
660
-};
661
-
662
-function run(args) {
663
- args = args || arguments_;
664
- if (runDependencies > 0) {
665
- return;
666
- }
667
- preRun();
668
- if (runDependencies > 0) {
669
- return;
670
- }
671
- function doRun() {
672
- if (calledRun) return;
673
- calledRun = true;
674
- Module["calledRun"] = true;
675
- if (ABORT) return;
676
- initRuntime();
677
- readyPromiseResolve(Module);
678
- if (Module["onRuntimeInitialized"]) Module["onRuntimeInitialized"]();
679
- postRun();
680
- }
681
- if (Module["setStatus"]) {
682
- Module["setStatus"]("Running...");
683
- setTimeout(function() {
684
- setTimeout(function() {
685
- Module["setStatus"]("");
686
- }, 1);
687
- doRun();
688
- }, 1);
689
- } else {
690
- doRun();
691
- }
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();
807
+ }
808
+ if (Module["setStatus"]) {
809
+ Module["setStatus"]("Running...");
810
+ setTimeout(() => {
811
+ setTimeout(() => Module["setStatus"](""), 1);
812
+ doRun();
813
+ }, 1);
814
+ } else {
815
+ doRun();
816
+ }
692817
}
693818
694819
if (Module["preInit"]) {
695
- if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ];
696
- while (Module["preInit"].length > 0) {
697
- Module["preInit"].pop()();
698
- }
820
+ if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ];
821
+ while (Module["preInit"].length > 0) {
822
+ Module["preInit"].pop()();
823
+ }
699824
}
700825
701826
run();
702827
828
+// end include: postamble.js
829
+// include: postamble_modularize.js
830
+// In MODULARIZE mode we wrap the generated code in a factory function
831
+// and return either the Module itself, or a promise of the module.
832
+// We assign to the `moduleRtn` global here and configure closure to see
833
+// this as and extern so it won't get minified.
834
+moduleRtn = readyPromise;
835
+
703836
704
- return initPikchrModule.ready
837
+ return moduleRtn;
705838
}
706839
);
707840
})();
708
-if (typeof exports === 'object' && typeof module === 'object')
841
+if (typeof exports === 'object' && typeof module === 'object') {
709842
module.exports = initPikchrModule;
710
-else if (typeof define === 'function' && define['amd'])
711
- define([], function() { return initPikchrModule; });
712
-else if (typeof exports === 'object')
713
- exports["initPikchrModule"] = 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);
714848
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,713 +1,847 @@
1
2 var initPikchrModule = (() => {
3 var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
4
5 return (
6 function(config) {
7 var initPikchrModule = config || {};
8
9 var Module = typeof initPikchrModule != "undefined" ? initPikchrModule : {};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11 var readyPromiseResolve, readyPromiseReject;
12
13 Module["ready"] = new Promise(function(resolve, reject) {
14 readyPromiseResolve = resolve;
15 readyPromiseReject = reject;
16 });
17
 
 
 
 
 
 
 
 
 
 
 
 
 
18 var moduleOverrides = Object.assign({}, Module);
19
20 var arguments_ = [];
21
22 var thisProgram = "./this.program";
23
24 var quit_ = (status, toThrow) => {
25 throw toThrow;
26 };
27
28 var ENVIRONMENT_IS_WEB = true;
29
30 var ENVIRONMENT_IS_WORKER = false;
31
32 var scriptDirectory = "";
33
34 function locateFile(path) {
35 if (Module["locateFile"]) {
36 return Module["locateFile"](path, scriptDirectory);
37 }
38 return scriptDirectory + path;
39 }
40
41 var read_, readAsync, readBinary, setWindowTitle;
42
43 if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
44 if (ENVIRONMENT_IS_WORKER) {
45 scriptDirectory = self.location.href;
46 } else if (typeof document != "undefined" && document.currentScript) {
47 scriptDirectory = document.currentScript.src;
48 }
49 if (_scriptDir) {
50 scriptDirectory = _scriptDir;
51 }
52 if (scriptDirectory.indexOf("blob:") !== 0) {
53 scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
54 } else {
55 scriptDirectory = "";
56 }
57 {
58 read_ = url => {
59 var xhr = new XMLHttpRequest();
60 xhr.open("GET", url, false);
61 xhr.send(null);
62 return xhr.responseText;
63 };
64 if (ENVIRONMENT_IS_WORKER) {
65 readBinary = url => {
66 var xhr = new XMLHttpRequest();
67 xhr.open("GET", url, false);
68 xhr.responseType = "arraybuffer";
69 xhr.send(null);
70 return new Uint8Array(xhr.response);
71 };
72 }
73 readAsync = (url, onload, onerror) => {
74 var xhr = new XMLHttpRequest();
75 xhr.open("GET", url, true);
76 xhr.responseType = "arraybuffer";
77 xhr.onload = () => {
78 if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
79 onload(xhr.response);
80 return;
81 }
82 onerror();
83 };
84 xhr.onerror = onerror;
85 xhr.send(null);
86 };
87 }
88 setWindowTitle = title => document.title = title;
89 } else {}
90
91 var out = Module["print"] || console.log.bind(console);
92
93 var err = Module["printErr"] || console.warn.bind(console);
94
 
95 Object.assign(Module, moduleOverrides);
96
 
 
97 moduleOverrides = null;
98
 
 
 
 
99 if (Module["arguments"]) arguments_ = Module["arguments"];
100
101 if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
102
103 if (Module["quit"]) quit_ = Module["quit"];
104
105 var wasmBinary;
106
107 if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
108
109 var noExitRuntime = Module["noExitRuntime"] || true;
110
111 if (typeof WebAssembly != "object") {
112 abort("no native wasm support detected");
113 }
114
 
 
115 var wasmMemory;
116
 
 
 
 
 
117 var ABORT = false;
118
 
 
 
119 var EXITSTATUS;
120
121 var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : undefined;
122
123 function UTF8ArrayToString(heapOrArray, idx, maxBytesToRead) {
124 var endIdx = idx + maxBytesToRead;
125 var endPtr = idx;
126 while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
127 if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
128 return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
129 }
130 var str = "";
131 while (idx < endPtr) {
132 var u0 = heapOrArray[idx++];
133 if (!(u0 & 128)) {
134 str += String.fromCharCode(u0);
135 continue;
136 }
137 var u1 = heapOrArray[idx++] & 63;
138 if ((u0 & 224) == 192) {
139 str += String.fromCharCode((u0 & 31) << 6 | u1);
140 continue;
141 }
142 var u2 = heapOrArray[idx++] & 63;
143 if ((u0 & 240) == 224) {
144 u0 = (u0 & 15) << 12 | u1 << 6 | u2;
145 } else {
146 u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63;
147 }
148 if (u0 < 65536) {
149 str += String.fromCharCode(u0);
150 } else {
151 var ch = u0 - 65536;
152 str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
153 }
154 }
155 return str;
156 }
157
158 function UTF8ToString(ptr, maxBytesToRead) {
159 return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
160 }
161
162 function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
163 if (!(maxBytesToWrite > 0)) return 0;
164 var startIdx = outIdx;
165 var endIdx = outIdx + maxBytesToWrite - 1;
166 for (var i = 0; i < str.length; ++i) {
167 var u = str.charCodeAt(i);
168 if (u >= 55296 && u <= 57343) {
169 var u1 = str.charCodeAt(++i);
170 u = 65536 + ((u & 1023) << 10) | u1 & 1023;
171 }
172 if (u <= 127) {
173 if (outIdx >= endIdx) break;
174 heap[outIdx++] = u;
175 } else if (u <= 2047) {
176 if (outIdx + 1 >= endIdx) break;
177 heap[outIdx++] = 192 | u >> 6;
178 heap[outIdx++] = 128 | u & 63;
179 } else if (u <= 65535) {
180 if (outIdx + 2 >= endIdx) break;
181 heap[outIdx++] = 224 | u >> 12;
182 heap[outIdx++] = 128 | u >> 6 & 63;
183 heap[outIdx++] = 128 | u & 63;
184 } else {
185 if (outIdx + 3 >= endIdx) break;
186 heap[outIdx++] = 240 | u >> 18;
187 heap[outIdx++] = 128 | u >> 12 & 63;
188 heap[outIdx++] = 128 | u >> 6 & 63;
189 heap[outIdx++] = 128 | u & 63;
190 }
191 }
192 heap[outIdx] = 0;
193 return outIdx - startIdx;
194 }
195
196 function stringToUTF8(str, outPtr, maxBytesToWrite) {
197 return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
198 }
199
200 var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
201
202 function updateMemoryViews() {
203 var b = wasmMemory.buffer;
204 Module["HEAP8"] = HEAP8 = new Int8Array(b);
205 Module["HEAP16"] = HEAP16 = new Int16Array(b);
206 Module["HEAP32"] = HEAP32 = new Int32Array(b);
207 Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
208 Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
209 Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
210 Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
211 Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
212 }
213
214 var INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 16777216;
215
216 var wasmTable;
217
218 var __ATPRERUN__ = [];
219
220 var __ATINIT__ = [];
221
222 var __ATPOSTRUN__ = [];
223
224 var runtimeInitialized = false;
225
226 function keepRuntimeAlive() {
227 return noExitRuntime;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228 }
229
 
230 function preRun() {
231 if (Module["preRun"]) {
232 if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ];
233 while (Module["preRun"].length) {
234 addOnPreRun(Module["preRun"].shift());
 
235 }
236 }
237 callRuntimeCallbacks(__ATPRERUN__);
238 }
239
240 function initRuntime() {
241 runtimeInitialized = true;
242 callRuntimeCallbacks(__ATINIT__);
243 }
244
245 function postRun() {
246 if (Module["postRun"]) {
247 if (typeof Module["postRun"] == "function") Module["postRun"] = [ Module["postRun"] ];
248 while (Module["postRun"].length) {
249 addOnPostRun(Module["postRun"].shift());
250 }
251 }
252 callRuntimeCallbacks(__ATPOSTRUN__);
253 }
254
255 function addOnPreRun(cb) {
256 __ATPRERUN__.unshift(cb);
257 }
258
259 function addOnInit(cb) {
260 __ATINIT__.unshift(cb);
261 }
262
263 function addOnPostRun(cb) {
264 __ATPOSTRUN__.unshift(cb);
265 }
266
267 var runDependencies = 0;
268
269 var runDependencyWatcher = null;
270
271 var dependenciesFulfilled = null;
272
273 function addRunDependency(id) {
274 runDependencies++;
275 if (Module["monitorRunDependencies"]) {
276 Module["monitorRunDependencies"](runDependencies);
277 }
278 }
279
280 function removeRunDependency(id) {
281 runDependencies--;
282 if (Module["monitorRunDependencies"]) {
283 Module["monitorRunDependencies"](runDependencies);
284 }
285 if (runDependencies == 0) {
286 if (runDependencyWatcher !== null) {
287 clearInterval(runDependencyWatcher);
288 runDependencyWatcher = null;
289 }
290 if (dependenciesFulfilled) {
291 var callback = dependenciesFulfilled;
292 dependenciesFulfilled = null;
293 callback();
294 }
295 }
296 }
297
298 function abort(what) {
299 if (Module["onAbort"]) {
300 Module["onAbort"](what);
301 }
302 what = "Aborted(" + what + ")";
303 err(what);
304 ABORT = true;
305 EXITSTATUS = 1;
306 what += ". Build with -sASSERTIONS for more info.";
307 var e = new WebAssembly.RuntimeError(what);
308 readyPromiseReject(e);
309 throw e;
310 }
311
312 var dataURIPrefix = "data:application/octet-stream;base64,";
313
314 function isDataURI(filename) {
315 return filename.startsWith(dataURIPrefix);
 
 
316 }
317
318 var wasmBinaryFile;
319
320 wasmBinaryFile = "pikchr.wasm";
321
322 if (!isDataURI(wasmBinaryFile)) {
323 wasmBinaryFile = locateFile(wasmBinaryFile);
324 }
325
326 function getBinary(file) {
327 try {
328 if (file == wasmBinaryFile && wasmBinary) {
329 return new Uint8Array(wasmBinary);
330 }
331 if (readBinary) {
332 return readBinary(file);
333 }
334 throw "both async and sync fetching of the wasm failed";
335 } catch (err) {
336 abort(err);
337 }
338 }
339
340 function getBinaryPromise() {
341 if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
342 if (typeof fetch == "function") {
343 return fetch(wasmBinaryFile, {
344 credentials: "same-origin"
345 }).then(function(response) {
346 if (!response["ok"]) {
347 throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
348 }
349 return response["arrayBuffer"]();
350 }).catch(function() {
351 return getBinary(wasmBinaryFile);
352 });
353 }
354 }
355 return Promise.resolve().then(function() {
356 return getBinary(wasmBinaryFile);
357 });
358 }
359
360 function createWasm() {
361 var info = {
362 "a": asmLibraryArg
363 };
364 function receiveInstance(instance, module) {
365 var exports = instance.exports;
366 Module["asm"] = exports;
367 wasmMemory = Module["asm"]["d"];
368 updateMemoryViews();
369 wasmTable = Module["asm"]["g"];
370 addOnInit(Module["asm"]["e"]);
371 removeRunDependency("wasm-instantiate");
372 }
373 addRunDependency("wasm-instantiate");
374 function receiveInstantiationResult(result) {
375 receiveInstance(result["instance"]);
376 }
377 function instantiateArrayBuffer(receiver) {
378 return getBinaryPromise().then(function(binary) {
379 return WebAssembly.instantiate(binary, info);
380 }).then(function(instance) {
381 return instance;
382 }).then(receiver, function(reason) {
383 err("failed to asynchronously prepare wasm: " + reason);
384 abort(reason);
385 });
386 }
387 function instantiateAsync() {
388 if (!wasmBinary && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(wasmBinaryFile) && typeof fetch == "function") {
389 return fetch(wasmBinaryFile, {
390 credentials: "same-origin"
391 }).then(function(response) {
392 var result = WebAssembly.instantiateStreaming(response, info);
393 return result.then(receiveInstantiationResult, function(reason) {
394 err("wasm streaming compile failed: " + reason);
395 err("falling back to ArrayBuffer instantiation");
396 return instantiateArrayBuffer(receiveInstantiationResult);
397 });
398 });
399 } else {
400 return instantiateArrayBuffer(receiveInstantiationResult);
401 }
402 }
403 if (Module["instantiateWasm"]) {
404 try {
405 var exports = Module["instantiateWasm"](info, receiveInstance);
406 return exports;
407 } catch (e) {
408 err("Module.instantiateWasm callback failed with error: " + e);
409 readyPromiseReject(e);
410 }
411 }
412 instantiateAsync().catch(readyPromiseReject);
413 return {};
414 }
415
416 var tempDouble;
417
418 var tempI64;
419
420 function ExitStatus(status) {
421 this.name = "ExitStatus";
422 this.message = "Program terminated with exit(" + status + ")";
423 this.status = status;
424 }
425
426 function callRuntimeCallbacks(callbacks) {
427 while (callbacks.length > 0) {
428 callbacks.shift()(Module);
429 }
430 }
431
432 function getValue(ptr, type = "i8") {
433 if (type.endsWith("*")) type = "*";
434 switch (type) {
435 case "i1":
436 return HEAP8[ptr >> 0];
437
438 case "i8":
439 return HEAP8[ptr >> 0];
440
441 case "i16":
442 return HEAP16[ptr >> 1];
443
444 case "i32":
445 return HEAP32[ptr >> 2];
446
447 case "i64":
448 return HEAP32[ptr >> 2];
449
450 case "float":
451 return HEAPF32[ptr >> 2];
452
453 case "double":
454 return HEAPF64[ptr >> 3];
455
456 case "*":
457 return HEAPU32[ptr >> 2];
458
459 default:
460 abort("invalid type for getValue: " + type);
461 }
462 return null;
463 }
464
465 function setValue(ptr, value, type = "i8") {
466 if (type.endsWith("*")) type = "*";
467 switch (type) {
468 case "i1":
469 HEAP8[ptr >> 0] = value;
470 break;
471
472 case "i8":
473 HEAP8[ptr >> 0] = value;
474 break;
475
476 case "i16":
477 HEAP16[ptr >> 1] = value;
478 break;
479
480 case "i32":
481 HEAP32[ptr >> 2] = value;
482 break;
483
484 case "i64":
485 tempI64 = [ value >>> 0, (tempDouble = value, +Math.abs(tempDouble) >= 1 ? tempDouble > 0 ? (Math.min(+Math.floor(tempDouble / 4294967296), 4294967295) | 0) >>> 0 : ~~+Math.ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0) ],
486 HEAP32[ptr >> 2] = tempI64[0], HEAP32[ptr + 4 >> 2] = tempI64[1];
487 break;
488
489 case "float":
490 HEAPF32[ptr >> 2] = value;
491 break;
492
493 case "double":
494 HEAPF64[ptr >> 3] = value;
495 break;
496
497 case "*":
498 HEAPU32[ptr >> 2] = value;
499 break;
500
501 default:
502 abort("invalid type for setValue: " + type);
503 }
504 }
505
506 function ___assert_fail(condition, filename, line, func) {
507 abort("Assertion failed: " + UTF8ToString(condition) + ", at: " + [ filename ? UTF8ToString(filename) : "unknown filename", line, func ? UTF8ToString(func) : "unknown function" ]);
508 }
509
510 function abortOnCannotGrowMemory(requestedSize) {
511 abort("OOM");
512 }
513
514 function _emscripten_resize_heap(requestedSize) {
515 var oldSize = HEAPU8.length;
516 requestedSize = requestedSize >>> 0;
517 abortOnCannotGrowMemory(requestedSize);
518 }
519
520 var SYSCALLS = {
521 varargs: undefined,
522 get: function() {
523 SYSCALLS.varargs += 4;
524 var ret = HEAP32[SYSCALLS.varargs - 4 >> 2];
525 return ret;
526 },
527 getStr: function(ptr) {
528 var ret = UTF8ToString(ptr);
529 return ret;
530 }
531 };
532
533 function _proc_exit(code) {
534 EXITSTATUS = code;
535 if (!keepRuntimeAlive()) {
536 if (Module["onExit"]) Module["onExit"](code);
537 ABORT = true;
538 }
539 quit_(code, new ExitStatus(code));
540 }
541
542 function exitJS(status, implicit) {
543 EXITSTATUS = status;
544 _proc_exit(status);
545 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
547 var _exit = exitJS;
548
549 function getCFunc(ident) {
550 var func = Module["_" + ident];
551 return func;
552 }
553
554 function writeArrayToMemory(array, buffer) {
555 HEAP8.set(array, buffer);
556 }
557
558 function ccall(ident, returnType, argTypes, args, opts) {
559 var toC = {
560 "string": str => {
561 var ret = 0;
562 if (str !== null && str !== undefined && str !== 0) {
563 var len = (str.length << 2) + 1;
564 ret = stackAlloc(len);
565 stringToUTF8(str, ret, len);
566 }
567 return ret;
568 },
569 "array": arr => {
570 var ret = stackAlloc(arr.length);
571 writeArrayToMemory(arr, ret);
572 return ret;
573 }
574 };
575 function convertReturnValue(ret) {
576 if (returnType === "string") {
577 return UTF8ToString(ret);
578 }
579 if (returnType === "boolean") return Boolean(ret);
580 return ret;
581 }
582 var func = getCFunc(ident);
583 var cArgs = [];
584 var stack = 0;
585 if (args) {
586 for (var i = 0; i < args.length; i++) {
587 var converter = toC[argTypes[i]];
588 if (converter) {
589 if (stack === 0) stack = stackSave();
590 cArgs[i] = converter(args[i]);
591 } else {
592 cArgs[i] = args[i];
593 }
594 }
595 }
596 var ret = func.apply(null, cArgs);
597 function onDone(ret) {
598 if (stack !== 0) stackRestore(stack);
599 return convertReturnValue(ret);
600 }
601 ret = onDone(ret);
602 return ret;
603 }
604
605 function cwrap(ident, returnType, argTypes, opts) {
606 argTypes = argTypes || [];
607 var numericArgs = argTypes.every(type => type === "number" || type === "boolean");
608 var numericRet = returnType !== "string";
609 if (numericRet && numericArgs && !opts) {
610 return getCFunc(ident);
611 }
612 return function() {
613 return ccall(ident, returnType, argTypes, arguments, opts);
614 };
615 }
616
617 var asmLibraryArg = {
618 "a": ___assert_fail,
619 "b": _emscripten_resize_heap,
620 "c": _exit
621 };
622
623 var asm = createWasm();
624
625 var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() {
626 return (___wasm_call_ctors = Module["___wasm_call_ctors"] = Module["asm"]["e"]).apply(null, arguments);
627 };
628
629 var _pikchr = Module["_pikchr"] = function() {
630 return (_pikchr = Module["_pikchr"] = Module["asm"]["f"]).apply(null, arguments);
631 };
632
633 var stackSave = Module["stackSave"] = function() {
634 return (stackSave = Module["stackSave"] = Module["asm"]["h"]).apply(null, arguments);
635 };
636
637 var stackRestore = Module["stackRestore"] = function() {
638 return (stackRestore = Module["stackRestore"] = Module["asm"]["i"]).apply(null, arguments);
639 };
640
641 var stackAlloc = Module["stackAlloc"] = function() {
642 return (stackAlloc = Module["stackAlloc"] = Module["asm"]["j"]).apply(null, arguments);
643 };
644
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645 Module["stackSave"] = stackSave;
646
647 Module["stackRestore"] = stackRestore;
 
 
648
649 Module["cwrap"] = cwrap;
650
651 Module["setValue"] = setValue;
652
653 Module["getValue"] = getValue;
654
655 var calledRun;
656
657 dependenciesFulfilled = function runCaller() {
658 if (!calledRun) run();
659 if (!calledRun) dependenciesFulfilled = runCaller;
660 };
661
662 function run(args) {
663 args = args || arguments_;
664 if (runDependencies > 0) {
665 return;
666 }
667 preRun();
668 if (runDependencies > 0) {
669 return;
670 }
671 function doRun() {
672 if (calledRun) return;
673 calledRun = true;
674 Module["calledRun"] = true;
675 if (ABORT) return;
676 initRuntime();
677 readyPromiseResolve(Module);
678 if (Module["onRuntimeInitialized"]) Module["onRuntimeInitialized"]();
679 postRun();
680 }
681 if (Module["setStatus"]) {
682 Module["setStatus"]("Running...");
683 setTimeout(function() {
684 setTimeout(function() {
685 Module["setStatus"]("");
686 }, 1);
687 doRun();
688 }, 1);
689 } else {
690 doRun();
691 }
692 }
693
694 if (Module["preInit"]) {
695 if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ];
696 while (Module["preInit"].length > 0) {
697 Module["preInit"].pop()();
698 }
699 }
700
701 run();
702
 
 
 
 
 
 
 
 
703
704 return initPikchrModule.ready
705 }
706 );
707 })();
708 if (typeof exports === 'object' && typeof module === 'object')
709 module.exports = initPikchrModule;
710 else if (typeof define === 'function' && define['amd'])
711 define([], function() { return initPikchrModule; });
712 else if (typeof exports === 'object')
713 exports["initPikchrModule"] = initPikchrModule;
 
714
--- extsrc/pikchr.js
+++ extsrc/pikchr.js
@@ -1,713 +1,847 @@
 
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:
11 // 1. Not defined. We create it here
12 // 2. A function parameter, function(moduleArg) => Promise<Module>
13 // 3. pre-run appended it, var Module = {}; ..generated code..
14 // 4. External script tag defines var Module.
15 // We need to check if Module already exists (e.g. case 3 above).
16 // Substitution will be replaced with actual code on later stage of the build,
17 // this way Closure Compiler will not mangle it (e.g. case 4. above).
18 // Note that if you want to run closure, and also to use Module
19 // after the generated code, you will need to define var Module = {};
20 // before the code. Then that object will be used in the code, and you
21 // can continue to use Module afterwards as well.
22 var Module = moduleArg;
23
24 // Set up the promise that indicates the Module is initialized
25 var readyPromiseResolve, readyPromiseReject;
26
27 var readyPromise = new Promise((resolve, reject) => {
28 readyPromiseResolve = resolve;
29 readyPromiseReject = reject;
30 });
31
32 // Determine the runtime environment we are in. You can customize this by
33 // setting the ENVIRONMENT setting at compile time (see settings.js).
34 var ENVIRONMENT_IS_WEB = true;
35
36 var ENVIRONMENT_IS_WORKER = false;
37
38 // --pre-jses are emitted after the Module integration code, so that they can
39 // refer to Module (if they choose; they can also define Module)
40 // Sometimes an existing Module object exists with properties
41 // meant to overwrite the default module functionality. Here
42 // we collect those properties and reapply _after_ we configure
43 // the current environment's defaults to avoid having to be so
44 // defensive during initialization.
45 var moduleOverrides = Object.assign({}, Module);
46
47 var arguments_ = [];
48
49 var thisProgram = "./this.program";
50
51 var quit_ = (status, toThrow) => {
52 throw toThrow;
53 };
54
55 // `/` should be present at the end if `scriptDirectory` is not empty
 
 
 
56 var scriptDirectory = "";
57
58 function locateFile(path) {
59 if (Module["locateFile"]) {
60 return Module["locateFile"](path, scriptDirectory);
61 }
62 return scriptDirectory + path;
63 }
64
65 // Hooks that are implemented differently in different runtime environments.
66 var readAsync, readBinary;
67
68 // Note that this includes Node.js workers when relevant (pthreads is enabled).
69 // Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
70 // ENVIRONMENT_IS_NODE.
71 if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
72 if (ENVIRONMENT_IS_WORKER) {
73 // Check worker, not web, since window could be polyfilled
74 scriptDirectory = self.location.href;
75 } else if (typeof document != "undefined" && document.currentScript) {
76 // web
77 scriptDirectory = document.currentScript.src;
78 }
79 // When MODULARIZE, this JS may be executed later, after document.currentScript
80 // is gone, so we saved it, and we use it here instead of any other info.
81 if (_scriptName) {
82 scriptDirectory = _scriptName;
83 }
84 // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
85 // otherwise, slice off the final part of the url to find the script directory.
86 // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
87 // and scriptDirectory will correctly be replaced with an empty string.
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
113 // Merge back in the overrides
114 Object.assign(Module, moduleOverrides);
115
116 // Free the object hierarchy contained in the overrides, this lets the GC
117 // reclaim data used.
118 moduleOverrides = null;
119
120 // Emit code to handle expected values on the Module object. This applies Module.x
121 // to the proper local x. This has two benefits: first, we only emit it if it is
122 // expected to arrive, and second, by using a local everywhere else that can be
123 // minified.
124 if (Module["arguments"]) arguments_ = Module["arguments"];
125
126 if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
127
128 // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
129 // end include: shell.js
130 // include: preamble.js
131 // === Preamble library stuff ===
132 // Documentation for the public APIs defined in this file must be updated in:
133 // site/source/docs/api_reference/preamble.js.rst
134 // A prebuilt local version of the documentation is available at:
135 // site/build/text/docs/api_reference/preamble.js.txt
136 // You can also build docs locally as HTML or other formats in site/
137 // An online HTML version (which may be of a different version of Emscripten)
138 // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
139 var wasmBinary = Module["wasmBinary"];
140
141 // Wasm globals
142 var wasmMemory;
143
144 //========================================
145 // Runtime essentials
146 //========================================
147 // whether we are quitting the application. no code should run after this.
148 // set in exit() and abort()
149 var ABORT = false;
150
151 // set by exit() and abort(). Passed to 'onExit' handler.
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 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);
 
 
226 }
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 }
237 }
238 }
239
240 /** @param {string|number=} what */ function abort(what) {
241 Module["onAbort"]?.(what);
242 what = "Aborted(" + what + ")";
243 // TODO(sbc): Should we remove printing and leave it up to whoever
244 // catches the exception?
245 err(what);
246 ABORT = true;
247 what += ". Build with -sASSERTIONS for more info.";
248 // Use a wasm runtime error, because a JS error might be seen as a foreign
249 // exception, which means we'd run destructors on it. We need the error to
250 // simply make the program stop.
251 // FIXME This approach does not work in Wasm EH because it currently does not assume
252 // all RuntimeErrors are from traps; it decides whether a RuntimeError is from
253 // a trap or not based on a hidden field within the object. So at the moment
254 // we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that
255 // allows this in the wasm spec.
256 // Suppress closure compiler warning here. Closure compiler's builtin extern
257 // definition for WebAssembly.RuntimeError claims it takes no arguments even
258 // though it can.
259 // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
260 /** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what);
261 readyPromiseReject(e);
262 // Throw the error whether or not MODULARIZE is set because abort is used
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 }
278 if (readBinary) {
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 {
329 "a": wasmImports
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");
348 // Prefer streaming instantiation if available.
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 = "*";
413 switch (type) {
414 case "i1":
415 return HEAP8[ptr];
416
417 case "i8":
418 return HEAP8[ptr];
419
420 case "i16":
421 return HEAP16[((ptr) >> 1)];
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":
433 return HEAPF64[((ptr) >> 3)];
434
435 case "*":
436 return HEAPU32[((ptr) >> 2)];
437
438 default:
439 abort(`invalid type for getValue: ${type}`);
440 }
441 }
442
443 var noExitRuntime = Module["noExitRuntime"] || true;
444
445 /**
446 * @param {number} ptr
447 * @param {number} value
448 * @param {string} type
449 */ function setValue(ptr, value, type = "i8") {
450 if (type.endsWith("*")) type = "*";
451 switch (type) {
452 case "i1":
453 HEAP8[ptr] = value;
454 break;
455
456 case "i8":
457 HEAP8[ptr] = value;
458 break;
459
460 case "i16":
461 HEAP16[((ptr) >> 1)] = value;
462 break;
463
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
476 case "double":
477 HEAPF64[((ptr) >> 3)] = value;
478 break;
479
480 case "*":
481 HEAPU32[((ptr) >> 2)] = value;
482 break;
483
484 default:
485 abort(`invalid type for setValue: ${type}`);
486 }
487 }
488
489 var stackRestore = val => __emscripten_stack_restore(val);
490
491 var stackSave = () => _emscripten_stack_get_current();
492
493 var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder : undefined;
494
495 /**
496 * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
497 * array that contains uint8 values, returns a copy of that string as a
498 * Javascript String object.
499 * heapOrArray is either a regular array, or a JavaScript typed array view.
500 * @param {number=} idx
501 * @param {number=} maxBytesToRead
502 * @return {string}
503 */ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead = NaN) => {
504 var endIdx = idx + maxBytesToRead;
505 var endPtr = idx;
506 // TextDecoder needs to know the byte length in advance, it doesn't stop on
507 // null terminator by itself. Also, use the length info to avoid running tiny
508 // strings through TextDecoder, since .subarray() allocates garbage.
509 // (As a tiny code save trick, compare endPtr against endIdx using a negation,
510 // so that undefined/NaN means Infinity)
511 while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr;
512 if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
513 return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
514 }
515 var str = "";
516 // If building with TextDecoder, we have already computed the string length
517 // above, so test loop end condition against that
518 while (idx < endPtr) {
519 // For UTF8 byte structure, see:
520 // http://en.wikipedia.org/wiki/UTF-8#Description
521 // https://www.ietf.org/rfc/rfc2279.txt
522 // https://tools.ietf.org/html/rfc3629
523 var u0 = heapOrArray[idx++];
524 if (!(u0 & 128)) {
525 str += String.fromCharCode(u0);
526 continue;
527 }
528 var u1 = heapOrArray[idx++] & 63;
529 if ((u0 & 224) == 192) {
530 str += String.fromCharCode(((u0 & 31) << 6) | u1);
531 continue;
532 }
533 var u2 = heapOrArray[idx++] & 63;
534 if ((u0 & 240) == 224) {
535 u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
536 } else {
537 u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
538 }
539 if (u0 < 65536) {
540 str += String.fromCharCode(u0);
541 } else {
542 var ch = u0 - 65536;
543 str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
544 }
545 }
546 return str;
547 };
548
549 /**
550 * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
551 * emscripten HEAP, returns a copy of that string as a Javascript String object.
552 *
553 * @param {number} ptr
554 * @param {number=} maxBytesToRead - An optional length that specifies the
555 * maximum number of bytes to read. You can omit this parameter to scan the
556 * string until the first 0 byte. If maxBytesToRead is passed, and the string
557 * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
558 * string will cut short at that byte index (i.e. maxBytesToRead will not
559 * produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing
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
571 var _emscripten_resize_heap = requestedSize => {
572 var oldSize = HEAPU8.length;
573 // With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned.
574 requestedSize >>>= 0;
575 abortOnCannotGrowMemory(requestedSize);
576 };
577
578 var runtimeKeepaliveCounter = 0;
579
580 var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0;
581
582 var _proc_exit = code => {
583 EXITSTATUS = code;
584 if (!keepRuntimeAlive()) {
585 Module["onExit"]?.(code);
586 ABORT = true;
587 }
588 quit_(code, new ExitStatus(code));
589 };
590
591 /** @suppress {duplicate } */ /** @param {boolean|number=} implicit */ var exitJS = (status, implicit) => {
592 EXITSTATUS = status;
593 _proc_exit(status);
594 };
595
596 var _exit = exitJS;
597
598 var getCFunc = ident => {
599 var func = Module["_" + ident];
600 // closure exported function
601 return func;
602 };
603
604 var writeArrayToMemory = (array, buffer) => {
605 HEAP8.set(array, buffer);
606 };
607
608 var lengthBytesUTF8 = str => {
609 var len = 0;
610 for (var i = 0; i < str.length; ++i) {
611 // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
612 // unit, not a Unicode code point of the character! So decode
613 // UTF16->UTF32->UTF8.
614 // See http://unicode.org/faq/utf_bom.html#utf16-3
615 var c = str.charCodeAt(i);
616 // possibly a lead surrogate
617 if (c <= 127) {
618 len++;
619 } else if (c <= 2047) {
620 len += 2;
621 } else if (c >= 55296 && c <= 57343) {
622 len += 4;
623 ++i;
624 } else {
625 len += 3;
626 }
627 }
628 return len;
629 };
630
631 var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
632 // Parameter maxBytesToWrite is not optional. Negative values, 0, null,
633 // undefined and false each don't write out any bytes.
634 if (!(maxBytesToWrite > 0)) return 0;
635 var startIdx = outIdx;
636 var endIdx = outIdx + maxBytesToWrite - 1;
637 // -1 for string null terminator.
638 for (var i = 0; i < str.length; ++i) {
639 // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code
640 // unit, not a Unicode code point of the character! So decode
641 // UTF16->UTF32->UTF8.
642 // See http://unicode.org/faq/utf_bom.html#utf16-3
643 // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description
644 // and https://www.ietf.org/rfc/rfc2279.txt
645 // and https://tools.ietf.org/html/rfc3629
646 var u = str.charCodeAt(i);
647 // possibly a lead surrogate
648 if (u >= 55296 && u <= 57343) {
649 var u1 = str.charCodeAt(++i);
650 u = 65536 + ((u & 1023) << 10) | (u1 & 1023);
651 }
652 if (u <= 127) {
653 if (outIdx >= endIdx) break;
654 heap[outIdx++] = u;
655 } else if (u <= 2047) {
656 if (outIdx + 1 >= endIdx) break;
657 heap[outIdx++] = 192 | (u >> 6);
658 heap[outIdx++] = 128 | (u & 63);
659 } else if (u <= 65535) {
660 if (outIdx + 2 >= endIdx) break;
661 heap[outIdx++] = 224 | (u >> 12);
662 heap[outIdx++] = 128 | ((u >> 6) & 63);
663 heap[outIdx++] = 128 | (u & 63);
664 } else {
665 if (outIdx + 3 >= endIdx) break;
666 heap[outIdx++] = 240 | (u >> 18);
667 heap[outIdx++] = 128 | ((u >> 12) & 63);
668 heap[outIdx++] = 128 | ((u >> 6) & 63);
669 heap[outIdx++] = 128 | (u & 63);
670 }
671 }
672 // Null-terminate the pointer to the buffer.
673 heap[outIdx] = 0;
674 return outIdx - startIdx;
675 };
676
677 var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
678
679 var stackAlloc = sz => __emscripten_stack_alloc(sz);
680
681 var stringToUTF8OnStack = str => {
682 var size = lengthBytesUTF8(str) + 1;
683 var ret = stackAlloc(size);
684 stringToUTF8(str, ret, size);
685 return ret;
686 };
687
688 /**
689 * @param {string|null=} returnType
690 * @param {Array=} argTypes
691 * @param {Arguments|Array=} args
692 * @param {Object=} opts
693 */ var ccall = (ident, returnType, argTypes, args, opts) => {
694 // For fast lookup of conversion functions
695 var toC = {
696 "string": str => {
697 var ret = 0;
698 if (str !== null && str !== undefined && str !== 0) {
699 // null string
700 ret = stringToUTF8OnStack(str);
701 }
702 return ret;
703 },
704 "array": arr => {
705 var ret = stackAlloc(arr.length);
706 writeArrayToMemory(arr, ret);
707 return ret;
708 }
709 };
710 function convertReturnValue(ret) {
711 if (returnType === "string") {
712 return UTF8ToString(ret);
713 }
714 if (returnType === "boolean") return Boolean(ret);
715 return ret;
716 }
717 var func = getCFunc(ident);
718 var cArgs = [];
719 var stack = 0;
720 if (args) {
721 for (var i = 0; i < args.length; i++) {
722 var converter = toC[argTypes[i]];
723 if (converter) {
724 if (stack === 0) stack = stackSave();
725 cArgs[i] = converter(args[i]);
726 } else {
727 cArgs[i] = args[i];
728 }
729 }
730 }
731 var ret = func(...cArgs);
732 function onDone(ret) {
733 if (stack !== 0) stackRestore(stack);
734 return convertReturnValue(ret);
735 }
736 ret = onDone(ret);
737 return ret;
738 };
739
740 /**
741 * @param {string=} returnType
742 * @param {Array=} argTypes
743 * @param {Object=} opts
744 */ var cwrap = (ident, returnType, argTypes, opts) => {
745 // When the function takes numbers and returns a number, we can just return
746 // the original function
747 var numericArgs = !argTypes || argTypes.every(type => type === "number" || type === "boolean");
748 var numericRet = returnType !== "string";
749 if (numericRet && numericArgs && !opts) {
750 return getCFunc(ident);
751 }
752 return (...args) => ccall(ident, returnType, argTypes, args, opts);
753 };
754
755 var wasmImports = {
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
777 Module["stackRestore"] = stackRestore;
778
779 Module["stackAlloc"] = stackAlloc;
780
781 Module["cwrap"] = cwrap;
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();
807 }
808 if (Module["setStatus"]) {
809 Module["setStatus"]("Running...");
810 setTimeout(() => {
811 setTimeout(() => Module["setStatus"](""), 1);
812 doRun();
813 }, 1);
814 } else {
815 doRun();
816 }
 
 
 
 
 
 
 
817 }
818
819 if (Module["preInit"]) {
820 if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ];
821 while (Module["preInit"].length > 0) {
822 Module["preInit"].pop()();
823 }
824 }
825
826 run();
827
828 // end include: postamble.js
829 // include: postamble_modularize.js
830 // In MODULARIZE mode we wrap the generated code in a factory function
831 // and return either the Module itself, or a promise of the module.
832 // We assign to the `moduleRtn` global here and configure closure to see
833 // this as and extern so it won't get minified.
834 moduleRtn = readyPromise;
835
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.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
+1 -1
--- src/main.mk
+++ src/main.mk
@@ -2136,11 +2136,11 @@
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
21402140
$(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2141
- -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore \
2141
+ -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackAlloc,stackRestore \
21422142
-sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
21432143
-sENVIRONMENT=web \
21442144
-sMODULARIZE \
21452145
-sEXPORT_NAME=initPikchrModule \
21462146
--minify 0
21472147
--- src/main.mk
+++ src/main.mk
@@ -2136,11 +2136,11 @@
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
2140 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2141 -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore \
2142 -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
2143 -sENVIRONMENT=web \
2144 -sMODULARIZE \
2145 -sEXPORT_NAME=initPikchrModule \
2146 --minify 0
2147
--- src/main.mk
+++ src/main.mk
@@ -2136,11 +2136,11 @@
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
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

Keyboard Shortcuts

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