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