cl: callRuntimeInit; runtime: TracePanic

This commit is contained in:
xushiwei
2024-05-01 11:03:52 +08:00
parent 673b9d9a5c
commit 666808b427
31 changed files with 330 additions and 102 deletions

View File

@@ -19,6 +19,7 @@ package runtime
import (
"unsafe"
"github.com/goplus/llgo/internal/abi"
"github.com/goplus/llgo/internal/runtime/c"
)
@@ -27,18 +28,15 @@ func Alloc(size uintptr) unsafe.Pointer {
return c.Malloc(size)
}
/*
// Panic panics with a value.
func Panic(v Interface) {
c.Printf(c.String("Panic!!!\n"))
// TracePanic prints panic message.
func TracePanic(v Interface) {
c.Printf(c.Str("Panic(%p)\n"), v.tab._type)
kind := abi.Kind(v.tab._type.Kind_)
switch {
case kind == abi.String:
s := (*String)(v.data)
cs := c.Alloca(uintptr(s.len) + 1)
c.Memcpy(cs, s.data, uintptr(s.len))
(*[1 << 30]int8)(cs)[s.len] = 0
c.Printf(c.String("%s\n"), cs)
c.Printf(c.Str("panic: %s\n"), CStrCopy(cs, *s))
}
// TODO(xsw): other message type
}
*/