mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 03:27:48 +00:00
a2d0f79be3
So far, we've pretended to be js/wasm in baremetal targets to make the
stdlib happy. Unfortunately, this has various problems because
syscall/js (a dependency of many stdlib packages) thinks it can do JS
calls, and emulating them gets quite hard with all changes to the
syscall/js packages in Go 1.12.
This commit does a few things:
* It lets baremetal targets pretend to be linux/arm instead of
js/wasm.
* It lets the loader only select particular packages from the src
overlay, instead of inserting them just before GOROOT. This makes it
possible to pick which packages to overlay for a given target.
* It adds a baremetal-only syscall package that stubs out almost all
syscalls.
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
// +build wasm
|
|
|
|
package runtime
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
type timeUnit float64 // time in milliseconds, just like Date.now() in JavaScript
|
|
|
|
const tickMicros = 1000000
|
|
|
|
//go:export io_get_stdout
|
|
func io_get_stdout() int32
|
|
|
|
//go:export resource_write
|
|
func resource_write(id int32, ptr *uint8, len int32) int32
|
|
|
|
var stdout int32
|
|
|
|
func init() {
|
|
stdout = io_get_stdout()
|
|
}
|
|
|
|
//go:export _start
|
|
func _start() {
|
|
initAll()
|
|
}
|
|
|
|
//go:export cwa_main
|
|
func cwa_main() {
|
|
initAll() // _start is not called by olin/cwa so has to be called here
|
|
callMain()
|
|
}
|
|
|
|
func putchar(c byte) {
|
|
resource_write(stdout, &c, 1)
|
|
}
|
|
|
|
//go:linkname setEventHandler syscall/js.setEventHandler
|
|
func setEventHandler(fn func()) {
|
|
// TODO
|
|
}
|
|
|
|
//go:export go_scheduler
|
|
func go_scheduler() {
|
|
scheduler()
|
|
}
|
|
|
|
const asyncScheduler = true
|
|
|
|
// This function is called by the scheduler.
|
|
// Schedule a call to runtime.scheduler, do not actually sleep.
|
|
//go:export runtime.sleepTicks
|
|
func sleepTicks(d timeUnit)
|
|
|
|
//go:export runtime.ticks
|
|
func ticks() timeUnit
|
|
|
|
// Abort executes the wasm 'unreachable' instruction.
|
|
func abort() {
|
|
trap()
|
|
}
|
|
|
|
//go:export memset
|
|
func memset(ptr unsafe.Pointer, c byte, size uintptr) unsafe.Pointer {
|
|
for i := uintptr(0); i < size; i++ {
|
|
*(*byte)(unsafe.Pointer(uintptr(ptr) + i)) = c
|
|
}
|
|
return ptr
|
|
}
|