aboutsummaryrefslogtreecommitdiff
path: root/src/z/App/main.js
blob: 6251a4744ebb20763d4f085762c15345b1799b26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const imports = {
	object_store: {
		process: ObjectStore.processWasm,
	},
	console: {
		log(buffer, length) {
			console.log(ObjectStore.decodeString(buffer, length))
		},
		warn(buffer, length) {
			console.warn(ObjectStore.decodeString(buffer, length))
		},
		err(buffer, length) {
			console.error(ObjectStore.decodeString(buffer, length))
		},
		debug(buffer, length) {
			console.debug(ObjectStore.decodeString(buffer, length))
		},
	}
}

WebAssembly.instantiateStreaming(fetch("index.wasm"), imports).then(
	({ instance, module }) => {
		const is64 = new Uint8Array(
			instance.exports.memory.buffer,
			instance.exports.bit_length,
			1,
		)[0] == 8

		window.wasm = {
			exports: instance.exports,
			memory: instance.exports.memory,
			is64: is64,
			UsizeArray: is64 ? BigUint64Array : Uint32Array,
			IsizeArray: is64 ? BigInt64Array : Int32Array,
		}

		wasm.exports.run();
	},
);