Skip to content

Commit 32e19fc

Browse files
committed
cmd/compile: document wasmexport directive, update permitted types for wasmimport
For #65199, #66984. Change-Id: I9b651a00265fa7d3438d8a73ff04ddca7c4bed99 Reviewed-on: https://go-review.googlesource.com/c/go/+/633776 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent 1fe6583 commit 32e19fc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/cmd/compile/doc.go

+20
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,33 @@ The types of parameters and return values to the Go function are translated to
309309
Wasm according to the following table:
310310
311311
Go types Wasm types
312+
bool i32
312313
int32, uint32 i32
313314
int64, uint64 i64
314315
float32 f32
315316
float64 f64
316317
unsafe.Pointer i32
318+
pointer i32 (more restrictions below)
319+
string (i32, i32) (only permitted as a parameters, not a result)
320+
321+
For a pointer type, its element type must be a bool, int8, uint8, int16, uint16,
322+
int32, uint32, int64, uint64, float32, float64, an array whose element type is
323+
a permitted pointer element type, or a struct, which, if non-empty, embeds
324+
structs.HostLayout, and contains only fields whose types are permitted pointer
325+
element types.
317326
318327
Any other parameter types are disallowed by the compiler.
319328
329+
//go:wasmexport exportname
330+
331+
The //go:wasmexport directive is wasm-only and must be followed by a
332+
function definition.
333+
It specifies that the function is exported to the wasm host as ``exportname``.
334+
335+
//go:wasmexport f
336+
func g()
337+
338+
The types of parameters and return values to the Go function are permitted and
339+
translated to Wasm in the same way as //go:wasmimport functions.
320340
*/
321341
package main

0 commit comments

Comments
 (0)