mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 19:44:00 +00:00
Be able to print maps to some degree
Print the number of elements, or nil if it is a nil map.
This commit is contained in:
@@ -1277,6 +1277,8 @@ func (c *Compiler) parseBuiltin(frame *Frame, args []ssa.Value, callName string)
|
|||||||
}
|
}
|
||||||
case *types.Interface:
|
case *types.Interface:
|
||||||
c.builder.CreateCall(c.mod.NamedFunction("runtime.printitf"), []llvm.Value{value}, "")
|
c.builder.CreateCall(c.mod.NamedFunction("runtime.printitf"), []llvm.Value{value}, "")
|
||||||
|
case *types.Map:
|
||||||
|
c.builder.CreateCall(c.mod.NamedFunction("runtime.printmap"), []llvm.Value{value}, "")
|
||||||
case *types.Pointer:
|
case *types.Pointer:
|
||||||
ptrValue := c.builder.CreatePtrToInt(value, c.uintptrType, "")
|
ptrValue := c.builder.CreatePtrToInt(value, c.uintptrType, "")
|
||||||
c.builder.CreateCall(c.mod.NamedFunction("runtime.printptr"), []llvm.Value{ptrValue}, "")
|
c.builder.CreateCall(c.mod.NamedFunction("runtime.printptr"), []llvm.Value{ptrValue}, "")
|
||||||
|
|||||||
@@ -102,7 +102,21 @@ func printitf(msg interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printmap(m *hashmap) {
|
||||||
|
print("map[")
|
||||||
|
if m == nil {
|
||||||
|
print("nil")
|
||||||
|
} else {
|
||||||
|
print(m.count)
|
||||||
|
}
|
||||||
|
putchar(']')
|
||||||
|
}
|
||||||
|
|
||||||
func printptr(ptr uintptr) {
|
func printptr(ptr uintptr) {
|
||||||
|
if ptr == 0 {
|
||||||
|
print("nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
putchar('0')
|
putchar('0')
|
||||||
putchar('x')
|
putchar('x')
|
||||||
for i := 0; i < int(unsafe.Sizeof(ptr))*2; i++ {
|
for i := 0; i < int(unsafe.Sizeof(ptr))*2; i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user