Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wasm return_call demo #36288

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion files/en-us/webassembly/reference/control_flow/call/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ page-type: webassembly-instruction

{{WebAssemblySidebar}}

**`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.
**`call`** calls a function, while **`call_indirect`** calls a function in a table.
**`return_call`** and **`return_call_indirect`** are the tail-call versions of `call` and `call_indirect`, respectively.
Comment on lines +9 to +10
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate that this predates you, but what is a tail-call? We should say, if you know?

It would be good to have an example of using call_indirect.


{{EmbedInteractiveExample("pages/wat/call.html", "tabbed-standard")}}

Expand All @@ -23,6 +24,20 @@ call $greet
| `return_call` | `0x12` |
| `return_call_indirect` | `0x13` |

## Examples
Copy link
Collaborator

@hamishwillee hamishwillee Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI Pushed this below syntax section, added headings for each example, and made the examples render as "taller".

There is no defined structure for examples and how they should be presented in WASM but the format used in Web APIs makes sense IMO. Note that this does mean that the example is duplicated from the top, but I am OK with that.


### Using call to run a function imported from JavaScript

Calling the `greet` function imported from JavaScript using `call`:

{{EmbedInteractiveExample("pages/wat/call.html", "tabbed-taller")}}

### Using return_call to calculate a factorial

Calculating factorial for a number using `return_call` and logging the result using the exported `fac` function:

{{EmbedInteractiveExample("pages/wat/return_call.html", "tabbed-taller")}}

## See also

- [Tail Call Extension proposal overview](https://github.com/WebAssembly/tail-call/blob/main/proposals/tail-call/Overview.md)
Expand Down