github.com/aykevl/tinygo@v0.5.0/src/runtime/runtime.go (about) 1 package runtime 2 3 import ( 4 "unsafe" 5 ) 6 7 const Compiler = "tinygo" 8 9 // The compiler will fill this with calls to the initialization function of each 10 // package. 11 func initAll() 12 13 // A function call to this function is replaced withone of the following, 14 // depending on whether the scheduler is necessary: 15 // 16 // Without scheduler: 17 // 18 // main.main() 19 // 20 // With scheduler: 21 // 22 // main.main() 23 // scheduler() 24 func callMain() 25 26 func GOMAXPROCS(n int) int { 27 // Note: setting GOMAXPROCS is ignored. 28 return 1 29 } 30 31 func GOROOT() string { 32 // TODO: don't hardcode but take the one at compile time. 33 return "/usr/local/go" 34 } 35 36 //go:linkname os_runtime_args os.runtime_args 37 func os_runtime_args() []string { 38 return nil 39 } 40 41 // Copy size bytes from src to dst. The memory areas must not overlap. 42 func memcpy(dst, src unsafe.Pointer, size uintptr) { 43 for i := uintptr(0); i < size; i++ { 44 *(*uint8)(unsafe.Pointer(uintptr(dst) + i)) = *(*uint8)(unsafe.Pointer(uintptr(src) + i)) 45 } 46 } 47 48 // Copy size bytes from src to dst. The memory areas may overlap and will do the 49 // correct thing. 50 func memmove(dst, src unsafe.Pointer, size uintptr) { 51 if uintptr(dst) < uintptr(src) { 52 // Copy forwards. 53 memcpy(dst, src, size) 54 return 55 } 56 // Copy backwards. 57 for i := size; i != 0; { 58 i-- 59 *(*uint8)(unsafe.Pointer(uintptr(dst) + i)) = *(*uint8)(unsafe.Pointer(uintptr(src) + i)) 60 } 61 } 62 63 // Set the given number of bytes to zero. 64 func memzero(ptr unsafe.Pointer, size uintptr) { 65 for i := uintptr(0); i < size; i++ { 66 *(*byte)(unsafe.Pointer(uintptr(ptr) + i)) = 0 67 } 68 } 69 70 // Compare two same-size buffers for equality. 71 func memequal(x, y unsafe.Pointer, n uintptr) bool { 72 for i := uintptr(0); i < n; i++ { 73 cx := *(*uint8)(unsafe.Pointer(uintptr(x) + i)) 74 cy := *(*uint8)(unsafe.Pointer(uintptr(y) + i)) 75 if cx != cy { 76 return false 77 } 78 } 79 return true 80 } 81 82 //go:linkname sleep time.Sleep 83 func sleep(d int64) { 84 sleepTicks(timeUnit(d / tickMicros)) 85 } 86 87 func nanotime() int64 { 88 return int64(ticks()) * tickMicros 89 } 90 91 //go:linkname now time.now 92 func now() (sec int64, nsec int32, mono int64) { 93 mono = nanotime() 94 sec = mono / (1000 * 1000 * 1000) 95 nsec = int32(mono - sec*(1000*1000*1000)) 96 return 97 } 98 99 // Copied from the Go runtime source code. 100 //go:linkname os_sigpipe os.sigpipe 101 func os_sigpipe() { 102 runtimePanic("too many writes on closed pipe") 103 } 104 105 //go:linkname syscall_runtime_envs syscall.runtime_envs 106 func syscall_runtime_envs() []string { 107 return nil 108 }