@@ -20,6 +20,7 @@ import (
20
20
"unsafe"
21
21
22
22
"github.com/goplus/llgo/c"
23
+ "github.com/goplus/llgo/c/bitcast"
23
24
"github.com/goplus/llgo/c/pthread"
24
25
"github.com/goplus/llgo/internal/abi"
25
26
)
@@ -58,7 +59,7 @@ func Panic(v any) {
58
59
func Rethrow (link * Defer ) {
59
60
if ptr := excepKey .Get (); ptr != nil {
60
61
if link == nil {
61
- TracePanic (* (* Eface )(ptr ))
62
+ TracePanic (* (* any )(ptr ))
62
63
c .Free (ptr )
63
64
c .Exit (2 )
64
65
} else {
@@ -77,14 +78,57 @@ func init() {
77
78
78
79
// -----------------------------------------------------------------------------
79
80
81
+ func unpackEface (i any ) * eface {
82
+ return (* eface )(unsafe .Pointer (& i ))
83
+ }
84
+
80
85
// TracePanic prints panic message.
81
- func TracePanic (v Eface ) {
82
- kind := v ._type .Kind ()
83
- switch {
84
- case kind == abi .String :
85
- stringTracef (c .Stderr , c .Str ("panic: %s\n " ), * (* String )(v .data ))
86
+ func TracePanic (v any ) {
87
+ print ("panic: " )
88
+ switch e := v .(type ) {
89
+ case nil :
90
+ println ("nil" )
91
+ return
92
+ case (interface { Error () string }):
93
+ println (e .Error ())
94
+ return
95
+ case (interface { String () string }):
96
+ println (e .String ())
97
+ return
98
+ }
99
+ e := unpackEface (v )
100
+ switch e .Kind () {
101
+ case abi .Int , abi .Int8 , abi .Int16 , abi .Int32 , abi .Int64 :
102
+ if isDirectIface (e ._type ) {
103
+ println (int64 (uintptr (e .data )))
104
+ } else {
105
+ println (* (* int64 )(e .data ))
106
+ }
107
+ case abi .Uint , abi .Uint8 , abi .Uint16 , abi .Uint32 , abi .Uint64 , abi .Uintptr :
108
+ if isDirectIface (e ._type ) {
109
+ println (uint64 (uintptr (e .data )))
110
+ } else {
111
+ println (* (* uint64 )(e .data ))
112
+ }
113
+ case abi .Float32 :
114
+ if isDirectIface (e ._type ) {
115
+ println (bitcast .ToFloat32 ((uintptr (e .data ))))
116
+ } else {
117
+ println (* (* float32 )(e .data ))
118
+ }
119
+ case abi .Float64 :
120
+ if isDirectIface (e ._type ) {
121
+ println (bitcast .ToFloat64 (uintptr (e .data )))
122
+ } else {
123
+ println (* (* float64 )(e .data ))
124
+ }
125
+ case abi .String :
126
+ println (* (* string )(e .data ))
127
+ default :
128
+ // TODO kind to e._type.Str_
129
+ print ("(" , e .Kind (), ") " )
130
+ println (e .data )
86
131
}
87
- // TODO(xsw): other message type
88
132
}
89
133
90
134
func stringTracef (fp c.FilePtr , format * c.Char , s String ) {
0 commit comments