Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Node status for tail calls (#370)
Using [Binaryen v116](https://github.com/WebAssembly/binaryen/tree/version_116), assemble `fac.wat` (adapted from [here](https://github.com/WebAssembly/tail-call/blob/6f44ca27af411a0f6bc4e07520807d7adfc0de88/proposals/tail-call/Overview.md#examples)) ```wat (module (func (export "fac") (param $x i64) (result i64) (return_call $fac-aux (local.get $x) (i64.const 1))) (func $fac-aux (param $x i64) (param $r i64) (result i64) (if (i64.eqz (local.get $x)) (then (return (local.get $r))) (else (return_call $fac-aux (i64.sub (local.get $x) (i64.const 1)) (i64.mul (local.get $x) (local.get $r))))))) ``` via this command: ```sh wasm-as --enable-tail-call fac.wat ``` Then try to run `fac.mjs` ```js import * as fs from "fs/promises"; const bytes = await fs.readFile("fac.wasm"); const mod = await WebAssembly.compile(bytes); const { fac } = (await WebAssembly.instantiate(mod)).exports; console.log(fac(5n)); ``` via this command: ```sh node fac.mjs ``` Node v20.0.0 or newer prints `120n` as expected, while Node v19.9.0 instead gives this error message: ``` node:internal/process/esm_loader:100 internalBinding('errors').triggerUncaughtException( ^ [CompileError: WebAssembly.compile(): Compiling function #0 failed: Invalid opcode 0x12 (enable with --experimental-wasm-return_call) @+45] Node.js v19.9.0 ```
- Loading branch information