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AAC;gBACnC;gBACA,4CACE,UAAkB,EAClB,eAAuB,EACvB,gBAAwB,EACxB;oBACA,MAAM,SAAS,QAAQ,cAAc,CAAC,iBAAiB;oBACvD,MAAM,SAAS,QAAQ,SAAS,CAAC,WAAW,CAAC,IAAI,CAC/C,YACG;oBAGL,IAAG,WAAW,aAAa,WAAW,IAAI,EACxC,MAAM,IAAI,MAAM,+GAA+G;oBAEjI,OAAO,QAAQ,wBAAwB,CAAC;gBAC1C;YACF;YAAE;SAAQ;IACZ;IAEA,MAAM,gBAAe,OAAe,EAAE;QACpC,MAAM,UAAU,MAAM,IAAI,CAAC,IAAI,CAAC;QAC/B,QAAQ,MAAM,CAAE,QAAQ,CAAC,OAAO,CAAC,IAAI;IACxC;IAEA,MAAM,MAAK,OAAe,EAAE;QAC1B,MAAM,CAAC,KAAI,QAAQ,GAAG,6BAAO,iBAAiB;QAC9C,MAAM,WAAW,MAAM,MAAM;QAC7B,MAAM,QAAQ,MAAM,SAAS,WAAW;QACxC,MAAM,SAAS,MAAM,YAAY,WAAW,CAAC,OAAO;iBAClD;QACF;QACA,QAAQ,MAAM,GAAG;QACjB,OAAO;IACT;AACF;AAEA,SAAS,gBAAgB,CAAC,oBAAoB,WAAY;IACxD,MAAM,cAAc,SAAS,gBAAgB,CAC3C;IAEF,IAAK,IAAI,IAAI,GAAG,IAAI,YAAY,MAAM,EAAE,IAAK;QAC3C,MAAM,MAAM,AAAC,WAAW,CAAC,EAAE,CAAuB,GAAG;QACrD,IAAI,KACF,6BAAO,cAAc,CAAC;aAEtB,QAAQ,KAAK,CAAC;IAElB;AACF","sources":["src/js-wasm.ts","node_modules/externref_polyfill/dist/index.js","node_modules/externref_polyfill/dist/externref.js","node_modules/externref_polyfill/dist/GenerationalArena.js"],"sourcesContent":["import { ExternRef } from '../node_modules/externref_polyfill/';\n\ninterface JSWasmHandlerContext {\n functions: ((...args: unknown[]) => number)[];\n utf8dec: TextDecoder;\n utf8enc: TextEncoder;\n utf16dec: TextDecoder;\n storeObject: (obj: unknown) => bigint;\n releaseObject: (objHandle: bigint) => void;\n module?: WebAssembly.WebAssemblyInstantiatedSource;\n readUtf8FromMemory: (start: number, end: number) => string;\n readUtf16FromMemory: (start: number, end: number) => string;\n getMemory: () => Uint8Array;\n createAllocation: (size: number) => [number,number] ;\n writeUtf8ToMemory: (txt: string) => number;\n writeArrayBufferToMemory: (ab: ArrayBuffer) => number;\n readUint8ArrayFromMemory: (start: number, length: number) => Uint8Array;\n getObject: (handle: bigint) => unknown;\n readParameters: (start: number, length: number) => unknown[];\n}\n\nconst JsWasm = {\n createEnvironment(): [WebAssembly.ModuleImports, JSWasmHandlerContext] {\n ExternRef.create(undefined);\n ExternRef.create(null);\n ExternRef.create(self);\n ExternRef.create(typeof document != \"undefined\" ? document : null);\n ExternRef.create(typeof document != \"undefined\" ? document.body : null);\n\n // 0 is reserved for undefined\n // 1 is reserved for null\n // 2 is reserved for self\n // 3 is reserved for document\n // 4 is reserved for document.body\n\n\n const context: JSWasmHandlerContext = {\n functions: [\n function () {\n debugger;\n return 0;\n },\n ],\n utf8dec: new TextDecoder(\"utf-8\"),\n utf8enc: new TextEncoder(),\n utf16dec: new TextDecoder(\"utf-16\"),\n readUtf8FromMemory: function (start: number, len: number) {\n const text = this.utf8dec.decode(\n this.getMemory().subarray(start, start + len)\n );\n return text;\n },\n createAllocation: function (size: number): [number,number] {\n if (!this.module) {\n throw new Error(\"module not set\");\n }\n const allocationId = (this.module.instance.exports.create_allocation as (\n size: number\n ) => number)(size);\n const allocationPtr = (this.module.instance.exports.allocation_ptr as (\n size: number\n ) => number)(allocationId);\n return [allocationId, allocationPtr];\n },\n writeUtf8ToMemory: function (str: string) {\n const bytes = this.utf8enc.encode(str);\n const len = bytes.length;\n const [id,start] = this.createAllocation(len);\n this.getMemory().set(bytes, start);\n return id;\n },\n writeArrayBufferToMemory: function (ab: ArrayBuffer) {\n const bytes = new Uint8Array(ab);\n const len = bytes.length;\n const [id,start] = this.createAllocation(len);\n this.getMemory().set(bytes, start);\n return id;\n },\n readUtf16FromMemory: function (start: number, len: number) {\n const text = this.utf16dec.decode(\n this.getMemory().subarray(start, start + len)\n );\n return text;\n },\n readUint8ArrayFromMemory(start: number, length: number) {\n if (!this.module) {\n throw new Error(\"module not set\");\n }\n const b = this.getMemory().slice(start,start+length);\n return new Uint8Array(b);\n },\n storeObject: function (obj: unknown) : bigint {\n return ExternRef.create(obj);\n },\n getObject: function (handle: bigint) {\n return ExternRef.load(handle);\n },\n releaseObject: function (handle: bigint) {\n // dont release our fixed references\n if(handle <= 4n) {\n return;\n }\n ExternRef.delete(handle);\n },\n getMemory: function () {\n if (!this.module) {\n throw new Error(\"module not set\");\n }\n return new Uint8Array(\n (this.module.instance.exports.memory as WebAssembly.Memory).buffer\n );\n },\n readParameters: function (start: number, length: number) {\n //get bytes of parameters out of wasm module\n const parameters = this.readUint8ArrayFromMemory(start, length);\n //convert bytes to array of values \n //assuming each paramter is preceded by a 32 bit integer indicating its type\n //0 = undefined\n //1 = null\n //2 = float-64\n //3 = bigint\n //4 = string (followed by 32-bit start and size of string in memory)\n //5 = extern ref\n //6 = array of float-64 (followed by 32-bit start and size of string in memory)\n //7 = true\n //8 = false\n \n const values: unknown[] = [];\n let i = 0;\n while (i < parameters.length) {\n const type = parameters[i];\n i++;\n switch (type) {\n case 0:\n values.push(undefined);\n break;\n case 1:\n values.push(null); \n break;\n case 2:\n values.push(new DataView(parameters.buffer).getFloat64(i, true));\n i += 8;\n break;\n case 3:\n values.push(new DataView(parameters.buffer).getBigInt64(i,true));\n i += 8;\n break;\n case 4: {\n const start = new DataView(parameters.buffer).getInt32(i, true);\n i += 4;\n const len = new DataView(parameters.buffer).getInt32(i, true);\n i += 4;\n values.push(\n context.readUtf8FromMemory(start, len)\n );\n break;\n }\n case 5: {\n const handle = new DataView(parameters.buffer).getBigInt64(i,true);\n values.push(context.getObject(handle));\n i += 8;\n break;\n }\n case 6: {\n const start = new DataView(parameters.buffer).getInt32(i, true);\n i += 4;\n const len = new DataView(parameters.buffer).getInt32(i, true);\n i += 4;\n const memory = context.getMemory();\n const slice = memory.buffer.slice(start, start + len * 4);\n const array = new Float32Array(slice);\n values.push(array);\n break;\n }\n case 7:\n values.push(true);\n break;\n case 8:\n values.push(false); \n break;\n case 9: {\n const start = new DataView(parameters.buffer).getInt32(i, true);\n i += 4;\n const len = new DataView(parameters.buffer).getInt32(i, true);\n i += 4;\n const memory = context.getMemory();\n const slice = memory.buffer.slice(start, start + len * 8);\n const array = new Float64Array(slice);\n values.push(array);\n break;\n }\n case 10: {\n const start = new DataView(parameters.buffer).getInt32(i, true);\n i += 4;\n const len = new DataView(parameters.buffer).getInt32(i, true);\n i += 4;\n const memory = context.getMemory();\n const slice = memory.buffer.slice(start, start + len * 4);\n const array = new Uint32Array(slice);\n values.push(array);\n break;\n }\n default:\n throw new Error(\"unknown parameter type\");\n }\n }\n return values;\n }\n };\n return [{\n abort() {\n throw new Error(\"WebAssembly module aborted\");\n },\n externref_drop(obj: bigint) {\n context.releaseObject(obj);\n },\n js_register_function(start: number, len: number, utfByteLen: number) {\n let functionBody;\n if (utfByteLen === 16) {\n functionBody = context.readUtf16FromMemory(start, len);\n } else {\n functionBody = context.readUtf8FromMemory(start, len);\n }\n const id = context.functions.length;\n context.functions.push(\n Function(`\"use strict\";return(${functionBody})`)()\n );\n return id;\n },\n js_invoke_function(\n funcHandle: number,\n parametersStart: number,\n parametersLength: number\n ) {\n const values = context.readParameters(parametersStart, parametersLength);\n \n return context.functions[funcHandle].call(\n context,\n ...values \n );\n },\n js_invoke_function_and_return_object(\n funcHandle: number,\n parametersStart: number,\n parametersLength: number\n ) {\n const values = context.readParameters(parametersStart, parametersLength);\n const result = context.functions[funcHandle].call(\n context,\n ...values \n );\n if(result === undefined || result === null) {\n throw new Error(\"js_invoke_function_and_return_object returned undefined or null while trying to return an object\");\n }\n return context.storeObject(result);\n },\n js_invoke_function_and_return_bool(\n funcHandle: number,\n parametersStart: number,\n parametersLength: number\n ) {\n const values = context.readParameters(parametersStart, parametersLength);\n const result = context.functions[funcHandle].call(\n context,\n ...values\n );\n return result ? 1 : 0;\n },\n js_invoke_function_and_return_bigint(\n funcHandle: number,\n parametersStart: number,\n parametersLength: number\n ) {\n const values = context.readParameters(parametersStart, parametersLength);\n const result = context.functions[funcHandle].call(\n context,\n ...values \n );\n return result;\n },\n js_invoke_function_and_return_string(\n funcHandle: number,\n parametersStart: number,\n parametersLength: number\n ) {\n const values = context.readParameters(parametersStart, parametersLength);\n const result = context.functions[funcHandle].call(\n context,\n ...values \n );\n\n if(result === undefined || result === null) {\n throw new Error(\"js_invoke_function_and_return_string returned undefined or null while trying to retrieve string.\");\n }\n return context.writeUtf8ToMemory(result);\n },\n js_invoke_function_and_return_array_buffer(\n funcHandle: number,\n parametersStart: number,\n parametersLength: number\n ) {\n const values = context.readParameters(parametersStart, parametersLength);\n const result = context.functions[funcHandle].call(\n context,\n ...values \n );\n\n if(result === undefined || result === null) {\n throw new Error(\"js_invoke_function_and_return_array_buffer returned undefined or null while trying to retrieve arraybuffer.\");\n }\n return context.writeArrayBufferToMemory(result);\n }\n },context];\n },\n\n async loadAndRunWasm(wasmURL: string) {\n const context = await this.load(wasmURL);\n (context.module!.instance.exports.main as ()=>void)();\n },\n\n async load(wasmURL: string) {\n const [env,context] = JsWasm.createEnvironment();\n const response = await fetch(wasmURL);\n const bytes = await response.arrayBuffer();\n const module = await WebAssembly.instantiate(bytes, {\n env,\n });\n context.module = module;\n return context;\n },\n};\n\ndocument.addEventListener(\"DOMContentLoaded\", function () {\n const wasmScripts = document.querySelectorAll(\n \"script[type='application/wasm']\"\n );\n for (let i = 0; i < wasmScripts.length; i++) {\n const src = (wasmScripts[i] as HTMLSourceElement).src;\n if (src) {\n JsWasm.loadAndRunWasm(src);\n } else {\n console.error(\"Script tag must have 'src' property.\");\n }\n }\n});\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ExternRef = void 0;\nvar ExternRef_1 = require(\"./ExternRef\");\nObject.defineProperty(exports, \"ExternRef\", { enumerable: true, get: function () { return ExternRef_1.ExternRef; } });\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ExternRef = void 0;\nconst GenerationalArena_1 = require(\"./GenerationalArena\");\nconst store = new GenerationalArena_1.GenerationalArena();\nclass ExternRef {\n static create(reference) {\n return store.allocate(reference);\n }\n static load(handle) {\n return store.retrieve(handle);\n }\n static delete(handle) {\n store.deallocate(handle);\n }\n}\nexports.ExternRef = ExternRef;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.GenerationalArena = void 0;\nconst MAX_GENERATION = 0xfffffff0;\nclass GenerationalArena {\n constructor() {\n this.objects = [];\n this.generations = [];\n this.freeList = [];\n this.nextIndex = 0;\n }\n allocate(o) {\n let index;\n if (this.freeList.length > 0) {\n index = this.freeList.pop();\n }\n else {\n index = this.nextIndex++;\n }\n const currentGeneration = this.generations[index];\n this.objects[index] = o;\n this.generations[index] = currentGeneration === undefined ? 1 : Math.abs(currentGeneration) + 1;\n // return handle as big integer that contains\n // index in low 32 bits and generation in high 32 bits\n const low = BigInt(index);\n const high = BigInt(this.generations[index]) << BigInt(32);\n const merged = low | high;\n return merged;\n }\n deallocate(handle) {\n const index = Number(handle & BigInt(0xffffffff));\n const generation = Number(handle >> BigInt(32));\n if (generation >= MAX_GENERATION) {\n this.generations[index] = -this.generations[index];\n // don't put handle in free list as it's already totally used\n // this will prevent it from being reused ever again\n }\n else if (generation === this.generations[index]) {\n this.generations[index] = -this.generations[index];\n this.freeList.push(index);\n }\n else {\n throw new Error(\"attempt to deallocate invalid handle\");\n }\n }\n retrieve(handle) {\n const index = Number(handle & BigInt(0xffffffff));\n const generation = Number(handle >> BigInt(32));\n if (generation === this.generations[index]) {\n return this.objects[index];\n }\n else {\n throw new Error(\"attempt to retrieve invalid handle\");\n }\n }\n}\nexports.GenerationalArena = GenerationalArena;\n"],"names":[],"version":3,"file":"js-wasm.js.map"}