tinygo/src/runtime/runtime_unix.go
Ayke van Laethem e171f32493
Implement minimal bump pointer allocator
Useful for MCUs, until a real garbage collector has been implemented.
2018-06-03 16:30:48 +02:00

39 строки
485 Б
Go

// +build linux
package runtime
import (
"unsafe"
)
// #include <stdio.h>
// #include <stdlib.h>
// #include <unistd.h>
import "C"
const Microsecond = 1
func putchar(c byte) {
C.putchar(C.int(c))
}
func Sleep(d Duration) {
C.usleep(C.useconds_t(d))
}
func abort() {
C.abort()
}
func alloc(size uintptr) unsafe.Pointer {
buf := C.calloc(1, C.size_t(size))
if buf == nil {
panic("cannot allocate memory")
}
return buf
}
func free(ptr unsafe.Pointer) {
C.free(ptr)
}