summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/print.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/runtime/print.c')
-rw-r--r--src/pkg/runtime/print.c63
1 files changed, 38 insertions, 25 deletions
diff --git a/src/pkg/runtime/print.c b/src/pkg/runtime/print.c
index 8de3ae4fa..a04708fae 100644
--- a/src/pkg/runtime/print.c
+++ b/src/pkg/runtime/print.c
@@ -63,67 +63,85 @@ runtime·printf(int8 *s, ...)
vprintf(s, arg);
}
+#pragma textflag NOSPLIT
+int32
+runtime·snprintf(byte *buf, int32 n, int8 *s, ...)
+{
+ byte *arg;
+ int32 m;
+
+ arg = (byte*)(&s+1);
+ g->writebuf = buf;
+ g->writenbuf = n-1;
+ vprintf(s, arg);
+ *g->writebuf = '\0';
+ m = g->writebuf - buf;
+ g->writenbuf = 0;
+ g->writebuf = nil;
+ return m;
+}
+
// Very simple printf. Only for debugging prints.
// Do not add to this without checking with Rob.
static void
vprintf(int8 *s, byte *base)
{
int8 *p, *lp;
- uintptr arg, narg;
+ uintptr arg, siz;
byte *v;
//runtime·lock(&debuglock);
lp = p = s;
- arg = 0;
+ arg = (uintptr)base;
for(; *p; p++) {
if(*p != '%')
continue;
if(p > lp)
gwrite(lp, p-lp);
p++;
- narg = 0;
+ siz = 0;
switch(*p) {
case 't':
case 'c':
- narg = arg + 1;
+ siz = 1;
break;
case 'd': // 32-bit
case 'x':
arg = ROUND(arg, 4);
- narg = arg + 4;
+ siz = 4;
break;
case 'D': // 64-bit
case 'U':
case 'X':
case 'f':
- arg = ROUND(arg, sizeof(uintptr));
- narg = arg + 8;
+ arg = ROUND(arg, sizeof(uintreg));
+ siz = 8;
break;
case 'C':
- arg = ROUND(arg, sizeof(uintptr));
- narg = arg + 16;
+ arg = ROUND(arg, sizeof(uintreg));
+ siz = 16;
break;
case 'p': // pointer-sized
case 's':
arg = ROUND(arg, sizeof(uintptr));
- narg = arg + sizeof(uintptr);
+ siz = sizeof(uintptr);
break;
case 'S': // pointer-aligned but bigger
arg = ROUND(arg, sizeof(uintptr));
- narg = arg + sizeof(String);
+ siz = sizeof(String);
break;
case 'a': // pointer-aligned but bigger
arg = ROUND(arg, sizeof(uintptr));
- narg = arg + sizeof(Slice);
+ siz = sizeof(Slice);
break;
case 'i': // pointer-aligned but bigger
case 'e':
arg = ROUND(arg, sizeof(uintptr));
- narg = arg + sizeof(Eface);
+ siz = sizeof(Eface);
break;
}
- v = base+arg;
+ v = (byte*)arg;
switch(*p) {
case 'a':
runtime·printslice(*(Slice*)v);
@@ -171,7 +189,7 @@ vprintf(int8 *s, byte *base)
runtime·printhex(*(uint64*)v);
break;
}
- arg = narg;
+ arg += siz;
lp = p+1;
}
if(p > lp)
@@ -236,7 +254,10 @@ runtime·printfloat(float64 v)
n = 7; // digits printed
e = 0; // exp
s = 0; // sign
- if(v != 0) {
+ if(v == 0) {
+ if(1/v == runtime·neginf)
+ s = 1;
+ } else {
// sign
if(v < 0) {
v = -v;
@@ -345,7 +366,7 @@ runtime·printhex(uint64 v)
void
runtime·printpointer(void *p)
{
- runtime·printhex((uint64)p);
+ runtime·printhex((uintptr)p);
}
void
@@ -370,11 +391,3 @@ runtime·printnl(void)
{
gwrite("\n", 1);
}
-
-void
-runtime·typestring(Eface e, String s)
-{
- s = *e.type->string;
- FLUSH(&s);
-}
-