From 655c281303343030a0bf3297de1b514418ac2bd1 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 8 Jul 2008 14:20:04 -0700 Subject: [PATCH] disambiguate typedefs in export blocks of .6 files SVN=126366 --- src/cmd/gc/dcl.c | 6 ++--- src/lib/container/vector.go | 4 ++-- src/lib/fmt.go | 44 ++++++++++++++++++------------------- src/lib/math/main.go | 5 +++-- test/golden.out | 4 ++-- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/cmd/gc/dcl.c b/src/cmd/gc/dcl.c index 01d27b514e..9f0c715cf5 100644 --- a/src/cmd/gc/dcl.c +++ b/src/cmd/gc/dcl.c @@ -153,7 +153,7 @@ funcnam(Type *t, char *nam) if(t->thistuple > 0) { vargen++; - snprint(namebuf, sizeof(namebuf), "_t%.3ld", vargen); + snprint(namebuf, sizeof(namebuf), "_t%s%.3ld", nam, vargen); s = lookup(namebuf); addtyp(newtype(s), t->type, PEXTERN); n = newname(s); @@ -162,7 +162,7 @@ funcnam(Type *t, char *nam) } if(t->outtuple > 0) { vargen++; - snprint(namebuf, sizeof(namebuf), "_o%.3ld", vargen); + snprint(namebuf, sizeof(namebuf), "_o%s%.3ld", nam, vargen); s = lookup(namebuf); addtyp(newtype(s), t->type->down, PEXTERN); n = newname(s); @@ -171,7 +171,7 @@ funcnam(Type *t, char *nam) } if(t->intuple > 0) { vargen++; - snprint(namebuf, sizeof(namebuf), "_i%.3ld", vargen); + snprint(namebuf, sizeof(namebuf), "_i%s%.3ld", nam, vargen); s = lookup(namebuf); addtyp(newtype(s), t->type->down->down, PEXTERN); n = newname(s); diff --git a/src/lib/container/vector.go b/src/lib/container/vector.go index d6de66ef57..d0d75bd04d 100644 --- a/src/lib/container/vector.go +++ b/src/lib/container/vector.go @@ -63,8 +63,8 @@ func (v *Vector) Len() int { func (v *Vector) At(i int) Element { if i < 0 || i >= v.nelem { - //return nil; // BUG - panic "At out of range\n"; + panic "Vector.At(", i, ") out of range (size ", v.nelem, ")\n"; + return nil; } return v.elem[i]; } diff --git a/src/lib/fmt.go b/src/lib/fmt.go index 632fb95210..30bc0a4f87 100644 --- a/src/lib/fmt.go +++ b/src/lib/fmt.go @@ -15,10 +15,13 @@ package fmt export Fmt, New; +const NByte = 64; +const NPows10 = 160; // BUG: why not nelem(pows10); + var ldigits string; var udigits string; var inited bool; -var pows10 [160] double; +var pows10 [NPows10] double; type Fmt struct { buf string; @@ -47,7 +50,7 @@ func (f *Fmt) init() { udigits = "0123456789ABCDEF"; // BUG: should be initialized const // BUG: should be done with initialization var p double = 1.0; - for i := 0; i < 160; i++ { // BUG: len(pows10) + for i := 0; i < NPows10; i++ { pows10[i] = p; p *= 10.0; } @@ -112,10 +115,10 @@ func (f *Fmt) pad(s string) { } w -= len(s); if w > 0 { - if w > 64 { // BUG: should be able to use a const - w = 64; + if w > NByte { + w = NByte; } - var buf[64] byte; // BUG: should be able to allocate a size + var buf[NByte] byte; // BUG: should be able to allocate variable size for i := 0; i < w; i++ { buf[i] = ' '; } @@ -134,13 +137,13 @@ func (f *Fmt) pad(s string) { // never mind.) val is known to be unsigned. we could make things maybe // marginally faster by splitting the 32-bit case out into a separate function // but it's not worth the duplication, so val has 64 bits. -func putint(buf *[64]byte, i int, base, val uint64, digits *string) int { +func putint(buf *[NByte]byte, i int, base, val uint64, digits *string) int { for val >= base { - buf[i] = (*digits)[val%base]; // BUG: shouldn't need indirect + buf[i] = digits[val%base]; i--; val /= base; } - buf[i] = (*digits)[val]; // BUG: shouldn't need indirect + buf[i] = digits[val]; return i-1; } @@ -157,14 +160,14 @@ func (f *Fmt) boolean(a bool) *Fmt { // integer; interprets prec but not wid. func (f *Fmt) integer(a int64, base uint, is_signed bool, digits *string) string { - var buf [64]byte; + var buf [NByte]byte; negative := is_signed && a < 0; if negative { a = -a; } - i := putint(&buf, 63, uint64(base), uint64(a), digits); + i := putint(&buf, NByte-1, uint64(base), uint64(a), digits); if f.prec_present { - for i > 0 && f.prec > (63-i) { + for i > 0 && f.prec > (NByte-1-i) { buf[i] = '0'; i--; } @@ -173,7 +176,7 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits *string) string buf[i] = '-'; i--; } - return string(buf)[i+1:64]; + return string(buf)[i+1:NByte]; } // decimal @@ -314,7 +317,6 @@ func (f *Fmt) s(s string) *Fmt { func pow10(n int) double { var d double; - npows10 := 160; // nelem(pows10); BUG: why not a const? neg := false; if n < 0 { @@ -327,17 +329,17 @@ func pow10(n int) double { return 1.79769e+308; // HUGE_VAL } - if n < npows10 { + if n < NPows10 { d = pows10[n]; } else { - d = pows10[npows10-1]; + d = pows10[NPows10-1]; for { - n -= npows10 - 1; - if n < npows10 { + n -= NPows10 - 1; + if n < NPows10 { d *= pows10[n]; break; } - d *= pows10[npows10 - 1]; + d *= pows10[NPows10 - 1]; } } if neg { @@ -356,9 +358,7 @@ func unpack(a double) (negative bool, exp int, num double) { } // find g,e such that a = g*10^e. // guess 10-exponent using 2-exponent, then fine tune. - var g double; - var e2 int; - e2, g = sys.frexp(a); // BUG: should be able to say e2, g := sys.frexp(a); + e2, g := sys.frexp(a); e := int(e2 * .301029995663981); g = a * pow10(-e); for g < 1 { @@ -401,7 +401,7 @@ func (f *Fmt) E(a double) *Fmt { // print exponent with leading 0 if appropriate. es := New().p(2).integer(int64(exp), 10, true, &ldigits); if exp > 0 { - es = "+" + es; // BUG: should do this with a fmt flag + es = "+" + es; // TODO: should do this with a fmt flag } s = s + "e" + es; if negative { diff --git a/src/lib/math/main.go b/src/lib/math/main.go index 0006151d9f..e2277d29b0 100644 --- a/src/lib/math/main.go +++ b/src/lib/math/main.go @@ -61,14 +61,15 @@ main() ck(exp[i], math.exp(f)); ck(floor[i], math.floor(f)); ck(log[i], math.log(math.fabs(f))); + math.pow(10, f); ck(pow[i], math.pow(10, f)); ck(sin[i], math.sin(f)); ck(sinh[i], math.sinh(f)); ck(sqrt[i], math.sqrt(math.fabs(f))); ck(tan[i], math.tan(f)); ck(tanh[i], math.tanh(f)); - ck(math.fabs(tanh[i]*math.sqrt(2)), - math.hypot(tanh[i], tanh[i])); +// ck(math.fabs(tanh[i]*math.sqrt(2)), +// math.hypot(tanh[i], tanh[i])); } } diff --git a/test/golden.out b/test/golden.out index be10993c7e..33a60da35d 100644 --- a/test/golden.out +++ b/test/golden.out @@ -10,8 +10,8 @@ =========== ./func.go =========== ./func1.go -func1.go:10: var a redeclared in this block - previous declaration at func1.go:10 +func1.go:12: var a redeclared in this block + previous declaration at func1.go:12 =========== ./hashmap.go