diff --git a/static/moon_phase_wasm.d.ts b/static/moon_phase_wasm.d.ts index 5d96558..5a8fe58 100644 --- a/static/moon_phase_wasm.d.ts +++ b/static/moon_phase_wasm.d.ts @@ -5,19 +5,18 @@ */ export function greet(name: string): void; /** -* @returns {string} +* @returns {Array} */ -export function send_phase(): string; +export function send_phase(): Array; export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; export interface InitOutput { readonly memory: WebAssembly.Memory; readonly greet: (a: number, b: number) => void; - readonly send_phase: (a: number) => void; + readonly send_phase: () => number; readonly __wbindgen_malloc: (a: number) => number; readonly __wbindgen_realloc: (a: number, b: number, c: number) => number; - readonly __wbindgen_add_to_stack_pointer: (a: number) => number; readonly __wbindgen_free: (a: number, b: number) => void; } diff --git a/static/moon_phase_wasm.js b/static/moon_phase_wasm.js index 3c77289..a2e332a 100644 --- a/static/moon_phase_wasm.js +++ b/static/moon_phase_wasm.js @@ -1,26 +1,6 @@ let wasm; -const heap = new Array(32).fill(undefined); - -heap.push(undefined, null, true, false); - -function getObject(idx) { return heap[idx]; } - -let heap_next = heap.length; - -function dropObject(idx) { - if (idx < 36) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); @@ -38,6 +18,35 @@ function getStringFromWasm0(ptr, len) { return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } +const heap = new Array(32).fill(undefined); + +heap.push(undefined, null, true, false); + +let heap_next = heap.length; + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +function getObject(idx) { return heap[idx]; } + +function dropObject(idx) { + if (idx < 36) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + let WASM_VECTOR_LEN = 0; const cachedTextEncoder = new TextEncoder('utf-8'); @@ -101,6 +110,14 @@ export function greet(name) { wasm.greet(ptr0, len0); } +/** +* @returns {Array} +*/ +export function send_phase() { + const ret = wasm.send_phase(); + return takeObject(ret); +} + let cachedInt32Memory0 = new Int32Array(); function getInt32Memory0() { @@ -109,30 +126,6 @@ function getInt32Memory0() { } return cachedInt32Memory0; } -/** -* @returns {string} -*/ -export function send_phase() { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.send_phase(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(r0, r1); - } -} - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - heap[idx] = obj; - return idx; -} async function load(module, imports) { if (typeof Response === 'function' && module instanceof Response) { @@ -171,6 +164,10 @@ function getImports() { imports.wbg.__wbg_alert_b29ee0fb3216154d = function(arg0, arg1) { alert(getStringFromWasm0(arg0, arg1)); }; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; imports.wbg.__wbg_new_abda76e883ba8a5f = function() { const ret = new Error(); return addHeapObject(ret); @@ -192,6 +189,13 @@ function getImports() { imports.wbg.__wbindgen_object_drop_ref = function(arg0) { takeObject(arg0); }; + imports.wbg.__wbg_newwithlength_7c42f7e738a9d5d3 = function(arg0) { + const ret = new Array(arg0 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_a68214f35c417fa9 = function(arg0, arg1, arg2) { + getObject(arg0)[arg1 >>> 0] = takeObject(arg2); + }; imports.wbg.__wbg_now_58886682b7e790d7 = function() { const ret = Date.now(); return ret; diff --git a/static/moon_phase_wasm_bg.wasm b/static/moon_phase_wasm_bg.wasm index 0612b3f..46a03f8 100644 Binary files a/static/moon_phase_wasm_bg.wasm and b/static/moon_phase_wasm_bg.wasm differ diff --git a/static/moon_phase_wasm_bg.wasm.d.ts b/static/moon_phase_wasm_bg.wasm.d.ts index 7595c01..6b6cb15 100644 --- a/static/moon_phase_wasm_bg.wasm.d.ts +++ b/static/moon_phase_wasm_bg.wasm.d.ts @@ -2,8 +2,7 @@ /* eslint-disable */ export const memory: WebAssembly.Memory; export function greet(a: number, b: number): void; -export function send_phase(a: number): void; +export function send_phase(): number; export function __wbindgen_malloc(a: number): number; export function __wbindgen_realloc(a: number, b: number, c: number): number; -export function __wbindgen_add_to_stack_pointer(a: number): number; export function __wbindgen_free(a: number, b: number): void; diff --git a/templates/index.html b/templates/index.html index e83e0ab..020621b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -38,7 +38,8 @@ Hey I'm Gallant, I work with mostly Rust. //greet("A"); const phase = send_phase(); const bro = document.getElementById("donald"); - bro.innerHTML = phase; + bro.innerHTML = phase[0]; + bro.setAttribute("title",phase[1]); })