-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
base: main
Are you sure you want to change the base?
Add Wasm return_call demo #36288
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
{{EmbedInteractiveExample("pages/wat/call.html", "tabbed-standard")}} | ||
|
||
|
@@ -23,6 +24,20 @@ call $greet | |
| `return_call` | `0x12` | | ||
| `return_call_indirect` | `0x13` | | ||
|
||
## Examples | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment.
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.