1 /* go-print.c -- support for the go print statement.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
13 #include "go-string.h"
14 #include "interface.h"
16 /* This implements the various little functions which are called by
17 the predeclared functions print/println/panic/panicln. */
32 __go_print_string (struct __go_string val)
34 fprintf (stderr, "%.*s", (int) val.__length, (const char *) val.__data);
38 __go_print_uint64 (uint64_t val)
40 fprintf (stderr, "%llu", (unsigned long long) val);
44 __go_print_int64 (int64_t val)
46 fprintf (stderr, "%lld", (long long) val);
50 __go_print_double (double v)
58 fputs ("NaN", stderr);
63 putc (v < 0 ? '-' : '+', stderr);
64 fputs ("Inf", stderr);
68 /* The number of digits printed. */
96 for (i = 0; i < n; ++i)
107 /* The format is +d.dddd+edd. */
108 buf[0] = s ? '-' : '+';
109 for (i = 0; i < n; ++i)
114 buf[i + 2] = d + '0';
122 buf[n + 3] = e < 0 ? '-' : '+';
125 buf[n + 4] = e / 100 + '0';
126 buf[n + 5] = (e / 10) % 10 + '0';
127 buf[n + 6] = e % 10 + '0';
133 __go_print_complex (__complex double val)
136 __go_print_double (__builtin_creal (val));
137 __go_print_double (__builtin_cimag (val));
138 fputs ("i)", stderr);
142 __go_print_bool (_Bool val)
144 fputs (val ? "true" : "false", stderr);
148 __go_print_pointer (void *val)
150 fprintf (stderr, "0x%lx", (unsigned long) (uintptr_t) val);
154 __go_print_empty_interface (struct __go_empty_interface e)
156 fprintf (stderr, "(%p,%p)", e.__type_descriptor, e.__object);
160 __go_print_interface (struct __go_interface i)
162 fprintf (stderr, "(%p,%p)", i.__methods, i.__object);
166 __go_print_slice (struct __go_open_array val)
168 fprintf (stderr, "[%d/%d]", val.__count, val.__capacity);
169 __go_print_pointer (val.__values);