Commit c137d6b8 authored by Rob Pike's avatar Rob Pike

improve bug054.go

fix integer.ToString to return the proper, not-nul-terminated value

SVN=124654
parent 0ece7d47
...@@ -22,6 +22,23 @@ type TStruct struct { ...@@ -22,6 +22,23 @@ type TStruct struct {
fields *Vector; fields *Vector;
} }
func (s *TStruct) field() { func (s *TStruct) field(i int) *TStruct {
t := s.fields.At(0); // works if we say
// t := s.fields.At(i);
// return t;
return s.fields.At(i);
}
func main() {
v := new(Vector);
v.elem = new([10]Element);
t := new(TStruct);
t.name = "hi";
v.elem[0] = t;
s := new(TStruct);
s.name = "foo";
s.fields = v;
if s.field(0).name != "hi" {
panic "bad name"
}
} }
...@@ -13,6 +13,19 @@ ...@@ -13,6 +13,19 @@
BUG: known to succeed incorrectly BUG: known to succeed incorrectly
=========== ./hashmap.go =========== ./hashmap.go
fncalls
. MOD u(101) l(234) <uint32>UINT32
. . CALLINTER u(100) l(234) <uint32>UINT32
. . . DOTINTER u(1) l(234) 101({},{}){}
. . . . NAME-key G253 a(1) g(253) l(231) *<KeyType>I{}
. . . . NAME-Hash G0 a(1) l(182)
. . CALLMETH u(100) l(234) <uint32>UINT32
. . . DOTMETH u(1) l(234) 101({},{}){}
. . . . NAME-HashMap_capacity G0 a(1) l(208) 101({},{}){}
. . . AS u(1) l(234)
. . . . INDREG a(1) l(234) m G252 *<HashMap>{}
. . . . NAME-m G252 a(1) g(252) l(231) *<HashMap>{}
hashmap.go:71: fatal error: cgen: both sides functions
=========== ./helloworld.go =========== ./helloworld.go
hello, world hello, world
...@@ -32,7 +45,7 @@ hello, world ...@@ -32,7 +45,7 @@ hello, world
=========== ./nil.go =========== ./nil.go
=========== ./sieve.go =========== ./sieve.go
sieve.go:8: fatal error: walktype: switch 1 unknown op SEND l(151) sieve.go:8: fatal error: walktype: switch 1 unknown op SEND l(171)
BUG: known to fail incorrectly BUG: known to fail incorrectly
=========== ./string_lit.go =========== ./string_lit.go
...@@ -157,7 +170,7 @@ bugs/bug025.go:7: fatal error: dumpexportvar: oname nil: Foo ...@@ -157,7 +170,7 @@ bugs/bug025.go:7: fatal error: dumpexportvar: oname nil: Foo
BUG: known to fail incorrectly or at least with a bad message BUG: known to fail incorrectly or at least with a bad message
=========== bugs/bug026.go =========== bugs/bug026.go
traceback: main_sigs_I: not defined traceback: main·sigs_I: not defined
BUG: known to fail incorrectly BUG: known to fail incorrectly
=========== bugs/bug027.go =========== bugs/bug027.go
...@@ -256,7 +269,18 @@ bugs/bug053.go:6: syntax error ...@@ -256,7 +269,18 @@ bugs/bug053.go:6: syntax error
BUG: len should not be a keyword BUG: len should not be a keyword
=========== bugs/bug054.go =========== bugs/bug054.go
bugs/bug054.go:22: fatal error: cgen_aret xxx
. CALL u(100) l(188) <Element>I{}
. . NAME-Vector_At G0 a(1) l(175) 111({},{}){}
. . AS u(1) l(188)
. . . INDREG a(1) l(188) v G0 *<Vector>{}
. . . DOTPTR u(1) l(188) *<Vector>{}
. . . . NAME-s G224 a(1) g(224) l(184) *<TStruct>{}
. . . . NAME-fields G0 a(1) l(181)
. . AS u(1) l(188)
. . . INDREG a(1) l(188) i G225 <int32>INT32
. . . NAME-i G225 a(1) g(225) l(184) <int32>INT32
bugs/bug054.go:25: fatal error: agen_inter i2s
BUG: known to fail incorrectly BUG: known to fail incorrectly
=========== bugs/bug055.go =========== bugs/bug055.go
......
...@@ -439,7 +439,7 @@ func tostring(x Value) string { ...@@ -439,7 +439,7 @@ func tostring(x Value) string {
s[i] = '-'; s[i] = '-';
i++; i++;
} }
s[i] = 0; length := i;
ASSERT(0 < i && i < n); ASSERT(0 < i && i < n);
// reverse in place // reverse in place
...@@ -451,7 +451,7 @@ func tostring(x Value) string { ...@@ -451,7 +451,7 @@ func tostring(x Value) string {
i--; i--;
} }
return string(s); return string(s)[0:length];
} }
......
...@@ -22,9 +22,9 @@ var ( ...@@ -22,9 +22,9 @@ var (
) )
func CHECK(p bool) { func CHECK(msg string, p bool) {
if !p { if !p {
panic "CHECK failed\n"; panic "CHECK failed: ", msg, "\n";
} }
} }
...@@ -43,16 +43,16 @@ func Init() { ...@@ -43,16 +43,16 @@ func Init() {
a_c = Integer.FromString("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000991"); a_c = Integer.FromString("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000991");
} }
func N991() string { return "991" }
func TestConv() { func TestConv() {
print "TestConv\n"; print "TestConv\n";
CHECK(a.eql(Integer.FromInt(991))); CHECK("TC1", a.eql(Integer.FromInt(991)));
CHECK(b.eql(Integer.Fact(20))); CHECK("TC2", b.eql(Integer.Fact(20)));
CHECK(c.eql(Integer.Fact(100))); CHECK("TC3", c.eql(Integer.Fact(100)));
CHECK("TC4", a.ToString() == sa);
CHECK(a.ToString() == sa); CHECK("TC5", b.ToString() == sb);
CHECK(b.ToString() == sb); CHECK("TC6", c.ToString() == sc);
CHECK(c.ToString() == sc);
// also tested much via TestFact // also tested much via TestFact
} }
...@@ -60,18 +60,18 @@ func TestConv() { ...@@ -60,18 +60,18 @@ func TestConv() {
func TestAdd() { func TestAdd() {
print "TestAdd\n"; print "TestAdd\n";
CHECK(z.add(z).eql(z)); CHECK("TA1", z.add(z).eql(z));
CHECK(a.add(z).eql(a)); CHECK("TA2", a.add(z).eql(a));
CHECK(z.add(a).eql(a)); CHECK("TA3", z.add(a).eql(a));
CHECK(c.add(z).eql(c)); CHECK("TA4", c.add(z).eql(c));
CHECK(z.add(c).eql(c)); CHECK("TA5", z.add(c).eql(c));
CHECK(m.add(p).eql(z)); CHECK("TA6", m.add(p).eql(z));
CHECK(a.add(a).eql(a_a)); CHECK("TA7", a.add(a).eql(a_a));
CHECK(a.add(b).eql(a_b)); CHECK("TA8", a.add(b).eql(a_b));
CHECK(a.add(c).eql(a_c)); CHECK("TA9", a.add(c).eql(a_c));
// needs more // needs more
} }
...@@ -79,16 +79,16 @@ func TestAdd() { ...@@ -79,16 +79,16 @@ func TestAdd() {
func TestSub() { func TestSub() {
print "TestSub\n"; print "TestSub\n";
CHECK(z.sub(z).eql(z)); CHECK("TS1", z.sub(z).eql(z));
CHECK(a.sub(z).eql(a)); CHECK("TS2", a.sub(z).eql(a));
CHECK(z.sub(a).eql(a.neg())); CHECK("TS3", z.sub(a).eql(a.neg()));
CHECK(c.sub(z).eql(c)); CHECK("TS4", c.sub(z).eql(c));
CHECK(z.sub(c).eql(c.neg())); CHECK("TS5", z.sub(c).eql(c.neg()));
CHECK(p.sub(m).eql(p.add(p))); CHECK("TS6", p.sub(m).eql(p.add(p)));
CHECK(a.sub(a).eql(z)); CHECK("TS7", a.sub(a).eql(z));
// needs more // needs more
} }
...@@ -116,7 +116,7 @@ func TestFact() { ...@@ -116,7 +116,7 @@ func TestFact() {
print "TestFact\n"; print "TestFact\n";
for n := 990; n < 1010; n++ { for n := 990; n < 1010; n++ {
f := Integer.Fact(n); f := Integer.Fact(n);
CHECK(Integer.FromString(f.ToString()).eql(f)); CHECK("TF", Integer.FromString(f.ToString()).eql(f));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment