diff options
| author | LLLL Colonq <llll@colonq> | 2026-08-17 20:14:16 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-08-17 20:14:16 -0400 |
| commit | de99c5f7636a952025ea13de02bafd25bcb6bdec (patch) | |
| tree | be359424af4f6717103e3b667b6529ae5a4b4e6a /2026/games_submissions/liquidcake1/wasm.mjs | |
| parent | 4d4d1f24721f27fbf37e1070be6414de130ace61 (diff) | |
Fix broken
Diffstat (limited to '2026/games_submissions/liquidcake1/wasm.mjs')
| -rw-r--r-- | 2026/games_submissions/liquidcake1/wasm.mjs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/2026/games_submissions/liquidcake1/wasm.mjs b/2026/games_submissions/liquidcake1/wasm.mjs new file mode 100644 index 0000000..18bf547 --- /dev/null +++ b/2026/games_submissions/liquidcake1/wasm.mjs @@ -0,0 +1,51 @@ +export function load_wasm(interpreter) { + /* + (memory $memory 1) + (export "memory" (memory $memory)) + (func (export "load_first_item_in_mem") (param) (result i32) + i32.const 0 + + ;; load first item in memory and return the result + i32.load + ;; store 10000 in the first location in memory + i32.const 0 + i32.const 10000 + i32.store + ) + */ + /* + (module +(func $pop (import "my_namespace" "pop") (param i32) (result i32)) +(func $push (import "my_namespace" "push") (param i32 i32)) +(func (export "plus") (param i32) + local.get 0 + local.get 0 + call $pop + local.get 0 + call $pop + i32.add + call $push +)) +*/ + //let wasm_string = "AGFzbQEAAAABBwFgAn9/AX8DAgEABwoBBmFkZFR3bwAACgkBBwAgACABagsACgRuYW1lAgMBAAA="; + let wasm_string = "AGFzbQEAAAABDwNgAX8Bf2ACf38AYAF/AAIoAgxteV9uYW1lc3BhY2UDcG9wAAAMbXlfbmFtZXNwYWNlBHB1c2gAAQMCAQIHCAEEcGx1cwACChEBDwAgACAAEAAgABAAahABCwAcBG5hbWUBDAIAA3BvcAEEcHVzaAIHAwAAAQACAA=="; + // Fake minus version + //let wasm_string = "AGFzbQEAAAABDwNgAX8Bf2ACf38AYAF/AAIoAgxteV9uYW1lc3BhY2UDcG9wAAAMbXlfbmFtZXNwYWNlBHB1c2gAAQMCAQIHCAEEcGx1cwACChEBDwAgACAAEAAgABAAaxABCwAcBG5hbWUBDAIAA3BvcAEEcHVzaAIHAwAAAQACAA=="; + let wasm_array = new TextEncoder().encode(atob(wasm_string)) + const importObject = { + my_namespace: { + pop: threadNo => interpreter.threads[threadNo].pop(), + push: (threadNo, i) => interpreter.threads[threadNo].stack.push(i), + } + }; + return WebAssembly.compile(wasm_array).then((mod) => + WebAssembly.instantiate(mod, importObject).then(instance => { + patch_interpreter(interpreter, instance); + return instance; + }) + ); +} +function patch_interpreter(interpreter, instance) { + interpreter.instructions_raw["+"].impl = function (thread, thread_num) { instance.exports.plus(thread_num); }; + interpreter.instructions["+".charCodeAt(0)] = function (thread, thread_num) { instance.exports.plus(thread_num); }; +} |
