Skip to content

Commit

Permalink
cmd/compile: document wasmexport directive, update permitted types fo…
Browse files Browse the repository at this point in the history
…r wasmimport

For #65199, #66984.

Change-Id: I9b651a00265fa7d3438d8a73ff04ddca7c4bed99
Reviewed-on: https://go-review.googlesource.com/c/go/+/633776
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
  • Loading branch information
cherrymui committed Dec 5, 2024
1 parent 1fe6583 commit 32e19fc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/cmd/compile/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,33 @@ The types of parameters and return values to the Go function are translated to
Wasm according to the following table:
Go types Wasm types
bool i32
int32, uint32 i32
int64, uint64 i64
float32 f32
float64 f64
unsafe.Pointer i32
pointer i32 (more restrictions below)
string (i32, i32) (only permitted as a parameters, not a result)
For a pointer type, its element type must be a bool, int8, uint8, int16, uint16,
int32, uint32, int64, uint64, float32, float64, an array whose element type is
a permitted pointer element type, or a struct, which, if non-empty, embeds
structs.HostLayout, and contains only fields whose types are permitted pointer
element types.
Any other parameter types are disallowed by the compiler.
//go:wasmexport exportname
The //go:wasmexport directive is wasm-only and must be followed by a
function definition.
It specifies that the function is exported to the wasm host as ``exportname``.
//go:wasmexport f
func g()
The types of parameters and return values to the Go function are permitted and
translated to Wasm in the same way as //go:wasmimport functions.
*/
package main

0 comments on commit 32e19fc

Please sign in to comment.