typeAssert: bool float string

This commit is contained in:
visualfc
2024-05-10 13:25:36 +08:00
parent c9cc7ad9f7
commit e985eda857
8 changed files with 412 additions and 238 deletions

Binary file not shown.

View File

@@ -77,38 +77,18 @@ func CheckI2Int(v Interface, t *Type) (uintptr, bool) {
return 0, false
}
func I2Float64(v Interface, t *Type) float64 {
func I2String(v Interface, t *Type) string {
if v.tab._type == t {
return bitCastTo64F(uint64(uintptr(v.data)))
return *(*string)(v.data)
}
panic("I2Float64: type mismatch")
panic("I2String: type mismatch")
}
func CheckI2Float64(v Interface, t *Type) (float64, bool) {
func CheckI2String(v Interface, t *Type) (string, bool) {
if v.tab._type == t {
return bitCastTo64F(uint64(uintptr(v.data))), true
return *(*string)(v.data), true
}
return 0, false
return "", false
}
func I2Float32(v Interface, t *Type) float32 {
if v.tab._type == t {
return bitCastTo32F(uint32(uintptr(v.data)))
}
panic("I2Float32: type mismatch")
}
func CheckI2Float32(v Interface, t *Type) (float32, bool) {
if v.tab._type == t {
return bitCastTo32F(uint32(uintptr(v.data))), true
}
return 0, false
}
//go:linkname bitCastTo64F llgo.bitCastTo64F
func bitCastTo64F(uint64) float64
//go:linkname bitCastTo32F llgo.bitCastTo32F
func bitCastTo32F(uint32) float32
// -----------------------------------------------------------------------------