mdn.go-v.org

call: Wasm text instruction

call calls a function, returncall being the tail-call version of it. callindirect calls a function in a table with the returncallindirect tail-call version as well.

source: MDN Web Docslicence: CC BY-SA 2.5+ (MDN)database: /home/dbs/mdn.dbmode: tablerecords: 14753 (max_rowid)citation: https://developer.mozilla.org/

**`call`** calls a function, `return_call` being the tail-call version of it. `call_indirect` calls a function in a table with the `return_call_indirect` tail-call version as well.

tabbed-taller

```wat interactive-example
(module
;; Import the `greet` function from the environment
(import "env" "greet" (func $greet))

(func (export "greet")
;; Call the imported `greet` function
call $greet
)

;; Calculate the factorial of a number
(func $fac (export "fac") (param $x i64) (result i64)
;; Call the `fac-aux` function with $x and 1 parameters
(return_call $fac-aux (local.get $x) (i64.const 1))
)

;; Perform the factorial calculation
(func $fac-aux (param $x i64) (param $r i64) (result i64)
;; If $x is zero, return the accumulated result $r
(if (result i64) (i64.eqz (local.get $x))
(then (return (local.get $r)))
(else
;; Otherwise, recursively call `fac-aux` with $x-1 and $x*$r
(return_call $fac-aux
(i64.sub (local.get $x) (i64.const 1))
(i64.mul (local.get $x) (local.get $r))
)
)
)
)
)
```

```js interactive-example
const url = "{%wasm-url%}";
const { instance } = await WebAssembly.instantiateStreaming(fetch(url), {
env: {
greet() {
console.log("Hello");
},
},
});

instance.exports.greet();
// Expected output: "Hello"

console.log(instance.exports.fac(5n));
// Expected output: 120n
```

## Syntax

```wat
call $greet
```

| Instruction | Binary opcode |
| ---------------------- | ------------- |
| `call` | `0x10` |
| `call_indirect` | `0x11` |
| `return_call` | `0x12` |
| `return_call_indirect` | `0x13` |

## Specifications

## Browser compatibility

## See also

- [Tail Call Extension proposal overview](https://github.com/WebAssembly/tail-call/blob/main/proposals/tail-call/Overview.md)
- [V8 on WebAssembly tail calls support](https://v8.dev/blog/wasm-tail-call)

source: MDN Web Docslicence: CC BY-SA 2.5+ (MDN)year: —id: WebAssembly/Reference/Control_flow/callcitation: https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow/callcharacters: 1,992

record · JSON · record JSON

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.