Skip to content

Instantly share code, notes, and snippets.

@kripken
Created April 25, 2024 16:53
Show Gist options
  • Save kripken/286edabc866138d05716c2efbbd1cad4 to your computer and use it in GitHub Desktop.
Save kripken/286edabc866138d05716c2efbbd1cad4 to your computer and use it in GitHub Desktop.
var b;
b ||= typeof Module != 'undefined' ? Module : {};
var f = "object" == typeof window, g = "function" == typeof importScripts,
h = "object" == typeof process && "object" == typeof process.versions &&
"string" == typeof process.versions.node,
k = Object.assign({}, b), l = (a, c) => { throw c; }, m = "";
function n() {
var a = p;
return b.locateFile ? b.locateFile(a, m) : m + a
}
var q, r, t;
if (h) {
var fs = require("fs"), u = require("path");
m = g ? u.dirname(m) + "/" : __dirname + "/";
q = (a, c) => {
a = w(a) ? new URL(a) : u.normalize(a);
return fs.readFileSync(a, c ? void 0 : "utf8")
};
t = a => {
a = q(a, !0);
a.buffer || (a = new Uint8Array(a));
return a
};
r = (a, c, d, e = !0) => {
a = w(a) ? new URL(a) : u.normalize(a);
fs.readFile(a, e ? void 0 : "utf8", (v, G) => {v ? d(v) : c(e ? G.buffer : G)})
};
process.argv.slice(2);
"undefined" != typeof module && (module.exports = b);
process.on("uncaughtException", a => {
if (!("unwind" === a || a instanceof x || a.context instanceof x))
throw a;
});
l = (a, c) => {
process.exitCode = a;
throw c;
}
} else if (f || g)
g ? m = self.location.href
: "undefined" != typeof document && document.currentScript && (m = document.currentScript.src),
m = m.startsWith("blob:") ? "" : m.substr(0, m.replace(/[?#].*/, "").lastIndexOf("/") + 1),
q = a => {
var c = new XMLHttpRequest;
c.open("GET", a, !1);
c.send(null);
return c.responseText
}, g && (t = a => {
var c = new XMLHttpRequest;
c.open("GET", a, !1);
c.responseType = "arraybuffer";
c.send(null);
return new Uint8Array(c.response)
}), r = (a, c, d) => {
var e = new XMLHttpRequest;
e.open("GET", a, !0);
e.responseType = "arraybuffer";
e.onload = () => { 200 == e.status || 0 == e.status && e.response ? c(e.response) : d() };
e.onerror = d;
e.send(null)
};
b.print || console.log.bind(console);
var y = b.printErr || console.error.bind(console);
Object.assign(b, k);
k = null;
b.quit && (l = b.quit);
var z;
b.wasmBinary && (z = b.wasmBinary);
var A, B = !1, C = [], D = [], E = [], F = [], H = [];
function I() {
var a = b.preRun.shift();
C.unshift(a)
}
var J = 0, K = null, L = null, M = a => a.startsWith("data:application/octet-stream;base64,"),
w = a => a.startsWith("file://"), p;
function N(a) {
if (a == p && z)
return new Uint8Array(z);
if (t)
return t(a);
throw "both async and sync fetching of the wasm failed";
}
function O(a) {
if (!z && (f || g)) {
if ("function" == typeof fetch && !w(a))
return fetch(a, {credentials : "same-origin"})
.then(c => {
if (!c.ok)
throw `failed to load wasm binary file at '${a}'`;
return c.arrayBuffer()
})
.catch(() => N(a));
if (r)
return new Promise((c, d) => {r(a, e => c(new Uint8Array(e)), d)})
}
return Promise.resolve().then(() => N(a))
}
function P(a, c, d) {
return O(a).then(e => WebAssembly.instantiate(e, c)).then(d, e => {
y(`failed to asynchronously prepare wasm: ${e}`);
b.onAbort?.(e);
e = "Aborted(" + e + ")";
y(e);
B = !0;
throw new WebAssembly.RuntimeError(e + ". Build with -sASSERTIONS for more info.");
})
}
function Q(a, c) {
var d = p;
z || "function" != typeof WebAssembly.instantiateStreaming || M(d) || w(d) || h ||
"function" != typeof fetch
? P(d, a, c)
: fetch(d, {
credentials : "same-origin"
}).then(e => WebAssembly.instantiateStreaming(e, a).then(c, function(v) {
y(`wasm streaming compile failed: ${v}`);
y("falling back to ArrayBuffer instantiation");
return P(d, a, c)
}))
}
function x(a) {
this.name = "ExitStatus";
this.message = `Program terminated with exit(${a})`;
this.status = a
}
var R = a => {
for (; 0 < a.length;)
a.shift()(b)
}, S = b.noExitRuntime || !1, T = a => {
S || (b.onExit?.(a), B = !0);
l(a, new x(a))
}, U = {proc_exit : T}, V = function() {
function a(d) {
V = d.exports;
A = V.memory;
d = A.buffer;
b.HEAP8 = new Int8Array(d);
b.HEAP16 = new Int16Array(d);
b.HEAPU8 = new Uint8Array(d);
b.HEAPU16 = new Uint16Array(d);
b.HEAP32 = new Int32Array(d);
b.HEAPU32 = new Uint32Array(d);
b.HEAPF32 = new Float32Array(d);
b.HEAPF64 = new Float64Array(d);
J--;
b.monitorRunDependencies?.(J);
0 == J && (null !== K && (clearInterval(K), K = null), L && (d = L, L = null, d()));
return V
}
var c = {env : U, wasi_snapshot_preview1 : U};
J++;
b.monitorRunDependencies?.(J);
if (b.instantiateWasm)
try {
return b.instantiateWasm(c, a)
} catch (d) {
return y(`Module.instantiateWasm callback failed with error: ${d}`), !1
}
p = "a.out.wasm";
M(p) || (p = n());
Q(c, function(d) { a(d.instance) });
return {}
}(), W = b.__start = () => (W = b.__start = V._start)(), X;
L = function aa() {
X || Y();
X || (L = aa)
};
function Y() {
function a() {
if (!X && (X = !0, b.calledRun = !0, !B)) {
R(D);
R(E);
if (b.onRuntimeInitialized)
b.onRuntimeInitialized();
if (Z) {
var c = W;
try {
c(), S || R(F), T(0)
} catch (d) {
d instanceof x || "unwind" == d || l(1, d)
}
}
if (b.postRun)
for ("function" == typeof b.postRun && (b.postRun = [ b.postRun ]); b.postRun.length;)
c = b.postRun.shift(), H.unshift(c);
R(H)
}
}
if (!(0 < J)) {
if (b.preRun)
for ("function" == typeof b.preRun && (b.preRun = [ b.preRun ]); b.preRun.length;)
I();
R(C);
0 < J || (b.setStatus ? (b.setStatus("Running..."), setTimeout(function() {
setTimeout(function() { b.setStatus("") }, 1);
a()
}, 1)) : a())
}
}
if (b.preInit)
for ("function" == typeof b.preInit && (b.preInit = [ b.preInit ]); 0 < b.preInit.length;)
b.preInit.pop()();
var Z = !0;
b.noInitialRun && (Z = !1);
Y();
var b;
b ||= typeof Module != 'undefined' ? Module : {};
var f = "object" == typeof window, g = "function" == typeof importScripts,
h = "object" == typeof process && "object" == typeof process.versions &&
"string" == typeof process.versions.node,
k = Object.assign({}, b), l = (a, c) => { throw c; }, m = "", n, p, q;
if (h) {
var fs = require("fs"), r = require("path");
m = g ? r.dirname(m) + "/" : __dirname + "/";
n = (a, c) => {
a = t(a) ? new URL(a) : r.normalize(a);
return fs.readFileSync(a, c ? void 0 : "utf8")
};
q = a => {
a = n(a, !0);
a.buffer || (a = new Uint8Array(a));
return a
};
p = (a, c, d, e = !0) => {
a = t(a) ? new URL(a) : r.normalize(a);
fs.readFile(a, e ? void 0 : "utf8", (v, G) => {v ? d(v) : c(e ? G.buffer : G)})
};
process.argv.slice(2);
"undefined" != typeof module && (module.exports = b);
process.on("uncaughtException", a => {
if (!("unwind" === a || a instanceof u || a.context instanceof u))
throw a;
});
l = (a, c) => {
process.exitCode = a;
throw c;
}
} else if (f || g)
g ? m = self.location.href
: "undefined" != typeof document && document.currentScript && (m = document.currentScript.src),
m = m.startsWith("blob:") ? "" : m.substr(0, m.replace(/[?#].*/, "").lastIndexOf("/") + 1),
n = a => {
var c = new XMLHttpRequest;
c.open("GET", a, !1);
c.send(null);
return c.responseText
}, g && (q = a => {
var c = new XMLHttpRequest;
c.open("GET", a, !1);
c.responseType = "arraybuffer";
c.send(null);
return new Uint8Array(c.response)
}), p = (a, c, d) => {
var e = new XMLHttpRequest;
e.open("GET", a, !0);
e.responseType = "arraybuffer";
e.onload = () => { 200 == e.status || 0 == e.status && e.response ? c(e.response) : d() };
e.onerror = d;
e.send(null)
};
b.print || console.log.bind(console);
var w = b.printErr || console.error.bind(console);
Object.assign(b, k);
k = null;
b.quit && (l = b.quit);
var x;
b.wasmBinary && (x = b.wasmBinary);
var y, z = !1, A = [], B = [], C = [], D = [], E = [];
function F() {
var a = b.preRun.shift();
A.unshift(a)
}
var H = 0, I = null, J = null, K = a => a.startsWith("data:application/octet-stream;base64,"),
t = a => a.startsWith("file://"), L;
L = "a.out.wasm";
if (!K(L)) {
var M = L;
L = b.locateFile ? b.locateFile(M, m) : m + M
}
function N(a) {
if (a == L && x)
return new Uint8Array(x);
if (q)
return q(a);
throw "both async and sync fetching of the wasm failed";
}
function O(a) {
if (!x && (f || g)) {
if ("function" == typeof fetch && !t(a))
return fetch(a, {credentials : "same-origin"})
.then(c => {
if (!c.ok)
throw `failed to load wasm binary file at '${a}'`;
return c.arrayBuffer()
})
.catch(() => N(a));
if (p)
return new Promise((c, d) => {p(a, e => c(new Uint8Array(e)), d)})
}
return Promise.resolve().then(() => N(a))
}
function P(a, c, d) {
return O(a).then(e => WebAssembly.instantiate(e, c)).then(d, e => {
w(`failed to asynchronously prepare wasm: ${e}`);
b.onAbort?.(e);
e = "Aborted(" + e + ")";
w(e);
z = !0;
throw new WebAssembly.RuntimeError(e + ". Build with -sASSERTIONS for more info.");
})
}
function Q(a, c) {
var d = L;
x || "function" != typeof WebAssembly.instantiateStreaming || K(d) || t(d) || h ||
"function" != typeof fetch
? P(d, a, c)
: fetch(d, {
credentials : "same-origin"
}).then(e => WebAssembly.instantiateStreaming(e, a).then(c, function(v) {
w(`wasm streaming compile failed: ${v}`);
w("falling back to ArrayBuffer instantiation");
return P(d, a, c)
}))
}
function u(a) {
this.name = "ExitStatus";
this.message = `Program terminated with exit(${a})`;
this.status = a
}
var R = a => {
for (; 0 < a.length;)
a.shift()(b)
}, S = b.noExitRuntime || !1, T = a => {
S || (b.onExit?.(a), z = !0);
l(a, new u(a))
}, U = {proc_exit : T}, V = function() {
function a(d) {
V = d.exports;
y = V.memory;
d = y.buffer;
b.HEAP8 = new Int8Array(d);
b.HEAP16 = new Int16Array(d);
b.HEAPU8 = new Uint8Array(d);
b.HEAPU16 = new Uint16Array(d);
b.HEAP32 = new Int32Array(d);
b.HEAPU32 = new Uint32Array(d);
b.HEAPF32 = new Float32Array(d);
b.HEAPF64 = new Float64Array(d);
H--;
b.monitorRunDependencies?.(H);
0 == H && (null !== I && (clearInterval(I), I = null), J && (d = J, J = null, d()));
return V
}
var c = {env : U, wasi_snapshot_preview1 : U};
H++;
b.monitorRunDependencies?.(H);
if (b.instantiateWasm)
try {
return b.instantiateWasm(c, a)
} catch (d) {
return w(`Module.instantiateWasm callback failed with error: ${d}`), !1
}
Q(c, function(d) { a(d.instance) });
return {}
}(), W = b.__start = () => (W = b.__start = V._start)(), X;
J = function aa() {
X || Y();
X || (J = aa)
};
function Y() {
function a() {
if (!X && (X = !0, b.calledRun = !0, !z)) {
R(B);
R(C);
if (b.onRuntimeInitialized)
b.onRuntimeInitialized();
if (Z) {
var c = W;
try {
c(), S || R(D), T(0)
} catch (d) {
d instanceof u || "unwind" == d || l(1, d)
}
}
if (b.postRun)
for ("function" == typeof b.postRun && (b.postRun = [ b.postRun ]); b.postRun.length;)
c = b.postRun.shift(), E.unshift(c);
R(E)
}
}
if (!(0 < H)) {
if (b.preRun)
for ("function" == typeof b.preRun && (b.preRun = [ b.preRun ]); b.preRun.length;)
F();
R(A);
0 < H || (b.setStatus ? (b.setStatus("Running..."), setTimeout(function() {
setTimeout(function() { b.setStatus("") }, 1);
a()
}, 1)) : a())
}
}
if (b.preInit)
for ("function" == typeof b.preInit && (b.preInit = [ b.preInit ]); 0 < b.preInit.length;)
b.preInit.pop()();
var Z = !0;
b.noInitialRun && (Z = !1);
Y();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment