libgo: Update to weekly.2011-12-22.
[gcc.git] / libgo / runtime / go-print.c
1 /* go-print.c -- support for the go print statement.
2
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. */
6
7 #include <stdint.h>
8 #include <stdio.h>
9
10 #include "array.h"
11 #include "go-panic.h"
12 #include "go-string.h"
13 #include "interface.h"
14
15 /* This implements the various little functions which are called by
16 the predeclared functions print/println/panic/panicln. */
17
18 void
19 __go_print_space ()
20 {
21 putc (' ', stderr);
22 }
23
24 void
25 __go_print_nl ()
26 {
27 putc ('\n', stderr);
28 }
29
30 void
31 __go_print_string (struct __go_string val)
32 {
33 fprintf (stderr, "%.*s", (int) val.__length, (const char *) val.__data);
34 }
35
36 void
37 __go_print_uint64 (uint64_t val)
38 {
39 fprintf (stderr, "%llu", (unsigned long long) val);
40 }
41
42 void
43 __go_print_int64 (int64_t val)
44 {
45 fprintf (stderr, "%lld", (long long) val);
46 }
47
48 void
49 __go_print_double (double val)
50 {
51 fprintf (stderr, "%.24g", val);
52 }
53
54 void
55 __go_print_complex (__complex double val)
56 {
57 fprintf (stderr, "(%.24g%s%.24gi)",
58 __builtin_creal (val),
59 (__builtin_cimag (val) >= 0 || __builtin_isnan (__builtin_cimag(val))
60 ? "+"
61 : ""),
62 __builtin_cimag (val));
63 }
64
65 void
66 __go_print_bool (_Bool val)
67 {
68 fputs (val ? "true" : "false", stderr);
69 }
70
71 void
72 __go_print_pointer (void *val)
73 {
74 fprintf (stderr, "%p", val);
75 }
76
77 void
78 __go_print_empty_interface (struct __go_empty_interface e)
79 {
80 fprintf (stderr, "(%p,%p)", e.__type_descriptor, e.__object);
81 }
82
83 void
84 __go_print_interface (struct __go_interface i)
85 {
86 fprintf (stderr, "(%p,%p)", i.__methods, i.__object);
87 }
88
89 void
90 __go_print_slice (struct __go_open_array val)
91 {
92 fprintf (stderr, "[%d/%d]%p", val.__count, val.__capacity, val.__values);
93 }