return

return 用於從函式返回。

  • 如果棧中沒有剩餘值,則返回 nothing/void(空值/無)。
  • 如果棧中剩餘的值數量與函式型別簽名中指定的值數量相同,則返回這些值。
  • 如果棧中剩餘的值多於函式返回型別指定的數量,則返回最頂部的 N 個值,並丟棄棧中剩餘的值。

試一試

(module
  (func (export "get_90") (result i32)
    ;; load 10 onto the stack
    i32.const 10
    ;; load 90 onto the stack
    i32.const 90
    ;; return the second value (90); the first is discarded
    return
  )
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url)).then((result) => {
  const { get_90 } = result.instance.exports;
  console.log(get_90());
  // Expected output: 90
});

語法

wat
f32.const 4.3
return
wat
i32.const 7
f32.const 4.3
return
指令 二進位制操作碼
return 0x0f