Files
llgo/internal/runtime/z_print.go

76 lines
1.3 KiB
Go
Raw Normal View History

2024-05-20 21:32:10 +08:00
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
import (
"unsafe"
2024-05-25 11:57:09 +08:00
"github.com/goplus/llgo/internal/runtime/c"
2024-05-20 21:32:10 +08:00
)
func PrintByte(v byte) {
c.Fputc(c.Int(v), c.Stderr)
}
func PrintBool(v bool) {
if v {
c.Fprintf(c.Stderr, c.Str("true"))
} else {
c.Fprintf(c.Stderr, c.Str("false"))
}
}
func PrintFloat(v float64) {
2024-05-20 22:27:33 +08:00
switch {
2024-05-20 21:32:10 +08:00
case v != v:
c.Fprintf(c.Stderr, c.Str("NaN"))
return
2024-05-20 22:27:33 +08:00
case v+v == v && v != 0:
2024-05-20 21:32:10 +08:00
if v > 0 {
c.Fprintf(c.Stderr, c.Str("+Inf"))
2024-05-20 22:27:33 +08:00
} else {
2024-05-20 21:32:10 +08:00
c.Fprintf(c.Stderr, c.Str("-Inf"))
}
return
}
2024-05-20 22:27:33 +08:00
c.Fprintf(c.Stderr, c.Str("%e"), v)
2024-05-20 21:32:10 +08:00
}
// func PrintComplex(c complex128) {
// print("(", real(c), imag(c), "i)")
// }
func PrintUint(v uint64) {
c.Fprintf(c.Stderr, c.Str("%llu"), v)
}
func PrintInt(v int64) {
c.Fprintf(c.Stderr, c.Str("%lld"), v)
}
func PrintHex(v uint64) {
c.Fprintf(c.Stderr, c.Str("%llx"), v)
}
func PrintPointer(p unsafe.Pointer) {
c.Fprintf(c.Stderr, c.Str("%p"), p)
}
func PrintString(s String) {
c.Fwrite(s.data, 1, uintptr(s.len), c.Stderr)
}
func PrintSlice(s Slice) {
print("[", s.len, "/", s.cap, "]", s.data)
}
func PrintEface(e Eface) {
print("(", e._type, ",", e.data, ")")
2024-05-20 21:32:10 +08:00
}
2024-05-27 09:56:42 +08:00
func PrintIface(i Iface) {
print("(", i.tab, ",", i.data, ")")
}