mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
Implement printing of int8/uint8/pointers
This commit is contained in:
@@ -1,12 +1,40 @@
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func printstring(s string) {
|
||||
for i := 0; i < len(s); i++ {
|
||||
putchar(s[i])
|
||||
}
|
||||
}
|
||||
|
||||
func printuint8(n uint8) {
|
||||
if TargetBits >= 32 {
|
||||
printuint32(uint32(n))
|
||||
} else {
|
||||
prevdigits := n / 10
|
||||
if prevdigits != 0 {
|
||||
printuint8(prevdigits)
|
||||
}
|
||||
putchar(byte((n % 10) + '0'))
|
||||
}
|
||||
}
|
||||
|
||||
func printint8(n int8) {
|
||||
if TargetBits >= 32 {
|
||||
printint32(int32(n))
|
||||
} else {
|
||||
if n < 0 {
|
||||
putchar('-')
|
||||
n = -n
|
||||
}
|
||||
printuint8(uint8(n))
|
||||
}
|
||||
}
|
||||
|
||||
func printuint32(n uint32) {
|
||||
// TODO: don't recurse, but still be compact (and don't divide/mod
|
||||
// more than necessary).
|
||||
@@ -64,3 +92,17 @@ func printitf(msg interface{}) {
|
||||
print("???")
|
||||
}
|
||||
}
|
||||
|
||||
func printptr(ptr uintptr) {
|
||||
putchar('0')
|
||||
putchar('x')
|
||||
for i := 0; i < int(unsafe.Sizeof(ptr)) * 2; i++ {
|
||||
nibble := byte(ptr >> (unsafe.Sizeof(ptr) * 8 - 4))
|
||||
if nibble < 10 {
|
||||
putchar(nibble + '0')
|
||||
} else {
|
||||
putchar(nibble - 10 + 'a')
|
||||
}
|
||||
ptr <<= 4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package runtime
|
||||
|
||||
const Compiler = "tgo"
|
||||
|
||||
// The bitness of the CPU (e.g. 8, 32, 64). Set by the compiler as a constant.
|
||||
var TargetBits uint8
|
||||
|
||||
func _panic(message interface{}) {
|
||||
printstring("panic: ")
|
||||
printitf(message)
|
||||
|
||||
Reference in New Issue
Block a user