mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
Add support for printing slices via print/println
With help from @aykevl.
This commit is contained in:
committed by
Ron Evans
parent
5fdb894760
commit
ea36fea5a9
+21
-8
@@ -39,6 +39,17 @@ func printint8(n int8) {
|
||||
}
|
||||
}
|
||||
|
||||
func printuint(n uintptr) {
|
||||
switch unsafe.Sizeof(n) {
|
||||
case 2:
|
||||
printuint16(uint16(n))
|
||||
case 4:
|
||||
printuint32(uint32(n))
|
||||
case 8:
|
||||
printuint64(uint64(n))
|
||||
}
|
||||
}
|
||||
|
||||
func printuint16(n uint16) {
|
||||
printuint32(uint32(n))
|
||||
}
|
||||
@@ -323,14 +334,7 @@ func printitf(msg interface{}) {
|
||||
// cast to underlying type
|
||||
itf := *(*_interface)(unsafe.Pointer(&msg))
|
||||
putchar('(')
|
||||
switch unsafe.Sizeof(itf.typecode) {
|
||||
case 2:
|
||||
printuint16(uint16(itf.typecode))
|
||||
case 4:
|
||||
printuint32(uint32(itf.typecode))
|
||||
case 8:
|
||||
printuint64(uint64(itf.typecode))
|
||||
}
|
||||
printuint(uintptr(itf.typecode))
|
||||
putchar(':')
|
||||
print(itf.value)
|
||||
putchar(')')
|
||||
@@ -372,3 +376,12 @@ func printbool(b bool) {
|
||||
printstring("false")
|
||||
}
|
||||
}
|
||||
|
||||
func printslice(ptr, len_, cap_ uintptr) {
|
||||
putchar('[')
|
||||
printuint(len_)
|
||||
putchar('/')
|
||||
printuint(cap_)
|
||||
putchar(']')
|
||||
printptr(ptr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user