tinygo/src/runtime/gc.go
Ayke van Laethem 734b0cb6bc
Implement runtime functions for reflect
The reflect package isn't supported yet. But at least the Go
parser/typechecker can now deal with it.
2018-08-30 22:53:34 +02:00

38 строки
772 Б
Go

// +build !linux
package runtime
import (
"unsafe"
)
var (
_extern__heap_start unsafe.Pointer // defined by the linker
heapptr = uintptr(unsafe.Pointer(&_extern__heap_start))
)
func alloc(size uintptr) unsafe.Pointer {
// TODO: this can be optimized by not casting between pointers and ints so
// much. And by using platform-native data types (e.g. *uint8 for 8-bit
// systems).
size = align(size)
addr := heapptr
heapptr += size
for i := uintptr(0); i < uintptr(size); i += 4 {
ptr := (*uint32)(unsafe.Pointer(addr + i))
*ptr = 0
}
return unsafe.Pointer(addr)
}
func free(ptr unsafe.Pointer) {
// TODO: use a GC
}
func GC() {
// Unimplemented.
}
func KeepAlive(x interface{}) {
// Unimplemented. Only required with SetFinalizer().
}