mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 10:37:46 +00:00
24c11d4ba5
compiler: align with current wasm types proposal https://github.com/golang/go/issues/66984 - Remove int and uint as allowed types in params, results, pointers, or struct fields - Only allow small integers in pointers, arrays, or struct fields - enforce structs.HostLayout usage per wasm types proposal https://github.com/golang/go/issues/66984 - require go1.23 for structs.HostLayout - use an interface to check if GoVersion() exists This permits TinyGo to compile with Go 1.21. - use goenv.Compare instead of WantGoVersion - testdata/wasmexport: use int32 instead of int - compiler/testdata: add structs.HostLayout - compiler/testdata: improve tests for structs.HostLayout
53 lines
869 B
Go
53 lines
869 B
Go
package main
|
|
|
|
import "time"
|
|
|
|
func init() {
|
|
println("called init")
|
|
go adder()
|
|
}
|
|
|
|
//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 int32) int32 {
|
|
println("called add:", a, b)
|
|
addInputs <- a
|
|
addInputs <- b
|
|
return <-addOutput
|
|
}
|
|
|
|
var addInputs = make(chan int32)
|
|
var addOutput = make(chan int32)
|
|
|
|
func adder() {
|
|
for {
|
|
a := <-addInputs
|
|
b := <-addInputs
|
|
time.Sleep(time.Millisecond)
|
|
addOutput <- a + b
|
|
}
|
|
}
|
|
|
|
//go:wasmimport tester callOutside
|
|
func callOutside(a, b int32) int32
|
|
|
|
//go:wasmexport reentrantCall
|
|
func reentrantCall(a, b int32) int32 {
|
|
println("reentrantCall:", a, b)
|
|
result := callOutside(a, b)
|
|
println("reentrantCall result:", result)
|
|
return result
|
|
}
|