mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 00:13:43 +00:00
Implement print() for interface values
This commit is contained in:
+15
-1
@@ -34,6 +34,14 @@ func printint8(n int8) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printuint16(n uint16) {
|
||||||
|
printuint32(uint32(n))
|
||||||
|
}
|
||||||
|
|
||||||
|
func printint16(n uint16) {
|
||||||
|
printint32(int32(n))
|
||||||
|
}
|
||||||
|
|
||||||
func printuint32(n uint32) {
|
func printuint32(n uint32) {
|
||||||
// TODO: don't recurse, but still be compact (and don't divide/mod
|
// TODO: don't recurse, but still be compact (and don't divide/mod
|
||||||
// more than necessary).
|
// more than necessary).
|
||||||
@@ -84,7 +92,13 @@ func printitf(msg interface{}) {
|
|||||||
case string:
|
case string:
|
||||||
print(msg)
|
print(msg)
|
||||||
default:
|
default:
|
||||||
print("???")
|
// cast to underlying type
|
||||||
|
itf := *(*_interface)(unsafe.Pointer(&msg))
|
||||||
|
putchar('(')
|
||||||
|
print(itf.typecode)
|
||||||
|
putchar(':')
|
||||||
|
print(itf.value)
|
||||||
|
putchar(')')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user