mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 05:53:39 +00:00
wasm: add //go:wasmexport support to js/wasm
This adds support for //go:wasmexport with `-target=wasm` (in the browser). This follows the //go:wasmexport proposal, meaning that blocking functions are not allowed. Both `-buildmode=default` and `-buildmode=c-shared` are supported. The latter allows calling exported functions after `go.run()` has returned.
This commit is contained in:
committed by
Ron Evans
parent
6016d0c739
commit
4ef5109a07
@@ -2,26 +2,15 @@
|
||||
|
||||
package runtime
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type timeUnit float64 // time in milliseconds, just like Date.now() in JavaScript
|
||||
|
||||
// wasmNested is used to detect scheduler nesting (WASM calls into JS calls back into WASM).
|
||||
// When this happens, we need to use a reduced version of the scheduler.
|
||||
//
|
||||
// TODO: this variable can probably be removed once //go:wasmexport is the only
|
||||
// allowed way to export a wasm function (currently, //export also works).
|
||||
var wasmNested bool
|
||||
|
||||
//export _start
|
||||
func _start() {
|
||||
// These need to be initialized early so that the heap can be initialized.
|
||||
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
|
||||
|
||||
wasmNested = true
|
||||
run()
|
||||
__stdio_exit()
|
||||
wasmNested = false
|
||||
}
|
||||
|
||||
var handleEvent func()
|
||||
|
||||
//go:linkname setEventHandler syscall/js.setEventHandler
|
||||
@@ -50,3 +39,7 @@ func sleepTicks(d timeUnit)
|
||||
|
||||
//go:wasmimport gojs runtime.ticks
|
||||
func ticks() timeUnit
|
||||
|
||||
func beforeExit() {
|
||||
__stdio_exit()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build tinygo.wasm && !js
|
||||
//go:build tinygo.wasm
|
||||
|
||||
package runtime
|
||||
|
||||
|
||||
Reference in New Issue
Block a user