mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 00:13:43 +00:00
wasm: add //go:wasmexport support (#4451)
This adds support for the `//go:wasmexport` pragma as proposed here: https://github.com/golang/go/issues/65199 It is currently implemented only for wasip1 and wasm-unknown, but it is certainly possible to extend it to other targets like GOOS=js and wasip2.
This commit is contained in:
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
func init() {
|
||||
println("called init")
|
||||
}
|
||||
|
||||
//go:wasmimport tester callTestMain
|
||||
func callTestMain()
|
||||
|
||||
func main() {
|
||||
// main.main is not used when using -buildmode=c-shared.
|
||||
callTestMain()
|
||||
}
|
||||
|
||||
//go:wasmexport hello
|
||||
func hello() {
|
||||
println("hello!")
|
||||
}
|
||||
|
||||
//go:wasmexport add
|
||||
func add(a, b int) int {
|
||||
println("called add:", a, b)
|
||||
return a + b
|
||||
}
|
||||
|
||||
//go:wasmimport tester callOutside
|
||||
func callOutside(a, b int) int
|
||||
|
||||
//go:wasmexport reentrantCall
|
||||
func reentrantCall(a, b int) int {
|
||||
println("reentrantCall:", a, b)
|
||||
result := callOutside(a, b)
|
||||
println("reentrantCall result:", result)
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user