github.com/aykevl/tinygo@v0.5.0/src/runtime/runtime_wasm.go (about) 1 // +build wasm 2 3 package runtime 4 5 import ( 6 "unsafe" 7 ) 8 9 type timeUnit float64 // time in milliseconds, just like Date.now() in JavaScript 10 11 const tickMicros = 1000000 12 13 //go:export io_get_stdout 14 func io_get_stdout() int32 15 16 //go:export resource_write 17 func resource_write(id int32, ptr *uint8, len int32) int32 18 19 var stdout int32 20 21 func init() { 22 stdout = io_get_stdout() 23 } 24 25 //go:export _start 26 func _start() { 27 initAll() 28 } 29 30 //go:export cwa_main 31 func cwa_main() { 32 initAll() // _start is not called by olin/cwa so has to be called here 33 callMain() 34 } 35 36 func putchar(c byte) { 37 resource_write(stdout, &c, 1) 38 } 39 40 //go:linkname setEventHandler syscall/js.setEventHandler 41 func setEventHandler(fn func()) { 42 // TODO 43 } 44 45 //go:export go_scheduler 46 func go_scheduler() { 47 scheduler() 48 } 49 50 const asyncScheduler = true 51 52 // This function is called by the scheduler. 53 // Schedule a call to runtime.scheduler, do not actually sleep. 54 //go:export runtime.sleepTicks 55 func sleepTicks(d timeUnit) 56 57 //go:export runtime.ticks 58 func ticks() timeUnit 59 60 // Abort executes the wasm 'unreachable' instruction. 61 func abort() { 62 trap() 63 } 64 65 //go:export memset 66 func memset(ptr unsafe.Pointer, c byte, size uintptr) unsafe.Pointer { 67 for i := uintptr(0); i < size; i++ { 68 *(*byte)(unsafe.Pointer(uintptr(ptr) + i)) = c 69 } 70 return ptr 71 }