1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:34:40 -07:00

fix bug depot:

1) fix print statements, panic statements (parentheses required)
	2) len is now allowed as a var name (bug053)

R=gri
OCL=14106
CL=14106
This commit is contained in:
Rob Pike 2008-08-11 22:07:49 -07:00
parent 7293dab5a9
commit bc2f5f1dce
63 changed files with 310 additions and 314 deletions

View File

@ -8,12 +8,12 @@ package main
func main() { func main() {
if sys.argc() != 3 { if sys.argc() != 3 {
panic "argc" panic("argc")
} }
if sys.argv(1) != "arg1" { if sys.argv(1) != "arg1" {
panic "arg1" panic("arg1")
} }
if sys.argv(2) != "arg2" { if sys.argv(2) != "arg2" {
panic "arg2" panic("arg2")
} }
} }

View File

@ -39,7 +39,7 @@ func main() {
i3 := new(I); i3.val = 3333; i3 := new(I); i3.val = 3333;
i4 := new(I); i4.val = 44444; i4 := new(I); i4.val = 44444;
v := New(); v := New();
print "hi\n"; print("hi\n");
v.Insert(i4); v.Insert(i4);
v.Insert(i3); v.Insert(i3);
v.Insert(i2); v.Insert(i2);
@ -48,10 +48,10 @@ func main() {
for i := 0; i < v.nelem; i++ { for i := 0; i < v.nelem; i++ {
var x *I; var x *I;
x = v.At(i); x = v.At(i);
print i, " ", x.val, "\n"; // prints correct list print(i, " ", x.val, "\n"); // prints correct list
} }
for i := 0; i < v.nelem; i++ { for i := 0; i < v.nelem; i++ {
print i, " ", I(v.At(i)).val, "\n"; // always prints 5 - bad code - should be *I() print(i, " ", I(v.At(i)).val, "\n"); // always prints 5 - bad code - should be *I()
} }
} }
/* /*

View File

@ -39,6 +39,6 @@ func main() {
s.name = "foo"; s.name = "foo";
s.fields = v; s.fields = v;
if s.field(0).name != "hi" { if s.field(0).name != "hi" {
panic "bad name" panic("bad name")
} }
} }

View File

@ -11,7 +11,7 @@ func main() {
m[0] = 0; m[0] = 0;
m[0]++; m[0]++;
if m[0] != 1 { if m[0] != 1 {
print "map does not increment"; print("map does not increment");
sys.exit(1) sys.exit(1)
} }
} }

View File

@ -18,6 +18,6 @@ main()
b := 2; b := 2;
a, b = swap(swap(a, b)); a, b = swap(swap(a, b));
if a != 2 || b != 1 { if a != 2 || b != 1 {
panic "bad swap"; panic("bad swap");
} }
} }

View File

@ -10,16 +10,16 @@ func main() {
var i, j, k int; var i, j, k int;
outer: outer:
for k=0; k<2; k++ { for k=0; k<2; k++ {
print "outer loop top k ", k, "\n"; print("outer loop top k ", k, "\n");
if k != 0 { panic "k not zero" } // inner loop breaks this one every time if k != 0 { panic("k not zero") } // inner loop breaks this one every time
for i=0; i<2; i++ { for i=0; i<2; i++ {
if i != 0 { panic "i not zero" } // loop breaks every time if i != 0 { panic("i not zero") } // loop breaks every time
print "inner loop top i ", i, "\n"; print("inner loop top i ", i, "\n");
if true { if true {
print "do break\n"; print("do break\n");
break outer; break outer;
} }
} }
} }
print "broke\n"; print("broke\n");
} }

View File

@ -8,5 +8,5 @@ package main
func main() { func main() {
x := string('a', 'b', '\n'); x := string('a', 'b', '\n');
print x; print(x);
} }

View File

@ -9,7 +9,7 @@ package P
var x int var x int
func foo() { func foo() {
print P.x; // P should be defined between the outermost "universe" scope and the global scope print(P.x); // P should be defined between the outermost "universe" scope and the global scope
} }
/* /*

View File

@ -14,7 +14,7 @@ func f() int {
} }
func main() { func main() {
print f(), "\n"; print(f(), "\n");
} }
/* /*

View File

@ -17,7 +17,7 @@ func AsynchFifo() {
} }
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
if <-ch != i { if <-ch != i {
print "bad receive\n"; print("bad receive\n");
sys.exit(1); sys.exit(1);
} }
} }
@ -26,7 +26,7 @@ func AsynchFifo() {
func Chain(ch *chan<- int, val int, in *chan<- int, out *chan-< int) { func Chain(ch *chan<- int, val int, in *chan<- int, out *chan-< int) {
<-in; <-in;
if <-ch != val { if <-ch != val {
panic val panic(val)
} }
out -< 1 out -< 1
} }

View File

@ -14,7 +14,7 @@ func pause() {
} }
func i32receiver(c *chan int32) { func i32receiver(c *chan int32) {
if <-c != 123 { panic "i32 value" } if <-c != 123 { panic("i32 value") }
} }
func i32sender(c *chan int32) { func i32sender(c *chan int32) {
@ -22,7 +22,7 @@ func i32sender(c *chan int32) {
} }
func i64receiver(c *chan int64) { func i64receiver(c *chan int64) {
if <-c != 123456 { panic "i64 value" } if <-c != 123456 { panic("i64 value") }
} }
func i64sender(c *chan int64) { func i64sender(c *chan int64) {
@ -30,7 +30,7 @@ func i64sender(c *chan int64) {
} }
func breceiver(c *chan bool) { func breceiver(c *chan bool) {
if ! <-c { panic "b value" } if ! <-c { panic("b value") }
} }
func bsender(c *chan bool) { func bsender(c *chan bool) {
@ -38,7 +38,7 @@ func bsender(c *chan bool) {
} }
func sreceiver(c *chan string) { func sreceiver(c *chan string) {
if <-c != "hello" { panic "s value" } if <-c != "hello" { panic("s value") }
} }
func ssender(c *chan string) { func ssender(c *chan string) {
@ -58,55 +58,55 @@ func main() {
cs := new(chan string); cs := new(chan string);
i32, ok = <-c32; i32, ok = <-c32;
if ok { panic "blocked i32sender" } if ok { panic("blocked i32sender") }
i64, ok = <-c64; i64, ok = <-c64;
if ok { panic "blocked i64sender" } if ok { panic("blocked i64sender") }
b, ok = <-cb; b, ok = <-cb;
if ok { panic "blocked bsender" } if ok { panic("blocked bsender") }
s, ok = <-cs; s, ok = <-cs;
if ok { panic "blocked ssender" } if ok { panic("blocked ssender") }
go i32receiver(c32); go i32receiver(c32);
pause(); pause();
ok = c32 -< 123; ok = c32 -< 123;
if !ok { panic "i32receiver" } if !ok { panic("i32receiver") }
go i32sender(c32); go i32sender(c32);
pause(); pause();
i32, ok = <-c32; i32, ok = <-c32;
if !ok { panic "i32sender" } if !ok { panic("i32sender") }
if i32 != 234 { panic "i32sender value" } if i32 != 234 { panic("i32sender value") }
go i64receiver(c64); go i64receiver(c64);
pause(); pause();
ok = c64 -< 123456; ok = c64 -< 123456;
if !ok { panic "i64receiver" } if !ok { panic("i64receiver") }
go i64sender(c64); go i64sender(c64);
pause(); pause();
i64, ok = <-c64; i64, ok = <-c64;
if !ok { panic "i64sender" } if !ok { panic("i64sender") }
if i64 != 234567 { panic "i64sender value" } if i64 != 234567 { panic("i64sender value") }
go breceiver(cb); go breceiver(cb);
pause(); pause();
ok = cb -< true; ok = cb -< true;
if !ok { panic "breceiver" } if !ok { panic("breceiver") }
go bsender(cb); go bsender(cb);
pause(); pause();
b, ok = <-cb; b, ok = <-cb;
if !ok { panic "bsender" } if !ok { panic("bsender") }
if !b{ panic "bsender value" } if !b{ panic("bsender value") }
go sreceiver(cs); go sreceiver(cs);
pause(); pause();
ok = cs -< "hello"; ok = cs -< "hello";
if !ok { panic "sreceiver" } if !ok { panic("sreceiver") }
go ssender(cs); go ssender(cs);
pause(); pause();
s, ok = <-cs; s, ok = <-cs;
if !ok { panic "ssender" } if !ok { panic("ssender") }
if s != "hello again" { panic "ssender value" } if s != "hello again" { panic("ssender value") }
print "PASS\n" print("PASS\n")
} }

View File

@ -18,8 +18,8 @@ type rat struct {
} }
func (u *rat) pr(){ func (u *rat) pr(){
if u.den==1 { print u.num } if u.den==1 { print(u.num) }
else { print u.num, "/", u.den } else { print(u.num, "/", u.den) }
print(" ") print(" ")
} }
@ -126,7 +126,7 @@ func get(in *dch) item{
func getn(in *[]*dch, n int) *[]item { func getn(in *[]*dch, n int) *[]item {
// BUG n:=len(in); // BUG n:=len(in);
if n != 2 { panic "bad n in getn" }; if n != 2 { panic("bad n in getn") };
req := new([2] *chan int); req := new([2] *chan int);
dat := new([2] *chan item); dat := new([2] *chan item);
out := new([2] item); out := new([2] item);
@ -264,7 +264,7 @@ func sub(u, v *rat) *rat{
} }
func inv(u *rat) *rat{ // invert a rat func inv(u *rat) *rat{ // invert a rat
if u.num == 0 { panic "zero divide in inv" } if u.num == 0 { panic("zero divide in inv") }
return i2tor(u.den, u.num); return i2tor(u.den, u.num);
} }
@ -283,7 +283,7 @@ Evaln(c *rat, U PS, n int)
val = val + x * float64(u.num)/float64(u.den); val = val + x * float64(u.num)/float64(u.den);
xn = xn*x; xn = xn*x;
} }
print val, "\n"; print(val, "\n");
} }
// Print n terms of a power series // Print n terms of a power series
@ -294,7 +294,7 @@ func Printn(U PS, n int){
if end(u) != 0 { done = true } if end(u) != 0 { done = true }
else { u.pr() } else { u.pr() }
} }
print ("\n"); print(("\n"));
} }
func Print(U PS){ func Print(U PS){
@ -614,12 +614,12 @@ func check(U PS, c *rat, count int, str string) {
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
r := get(U) r := get(U)
if !r.eq(c) { if !r.eq(c) {
print "got: "; print("got: ");
r.pr(); r.pr();
print "should get "; print("should get ");
c.pr(); c.pr();
print "\n"; print("\n");
panic str panic(str)
} }
} }
} }
@ -634,17 +634,17 @@ func checka(U PS, a *[]*rat, str string) {
func main() { func main() {
Init(); Init();
if sys.argc() > 1 { // print if sys.argc() > 1 { // print
print "Ones: "; Printn(Ones, 10); print("Ones: "); Printn(Ones, 10);
print "Twos: "; Printn(Twos, 10); print("Twos: "); Printn(Twos, 10);
print "Add: "; Printn(Add(Ones, Twos), 10); print("Add: "); Printn(Add(Ones, Twos), 10);
print "Diff: "; Printn(Diff(Ones), 10); print("Diff: "); Printn(Diff(Ones), 10);
print "Integ: "; Printn(Integ(zero, Ones), 10); print("Integ: "); Printn(Integ(zero, Ones), 10);
print "CMul: "; Printn(Cmul(neg(one), Ones), 10); print("CMul: "); Printn(Cmul(neg(one), Ones), 10);
print "Sub: "; Printn(Sub(Ones, Twos), 10); print("Sub: "); Printn(Sub(Ones, Twos), 10);
print "Mul: "; Printn(Mul(Ones, Ones), 10); print("Mul: "); Printn(Mul(Ones, Ones), 10);
print "Exp: "; Printn(Exp(Ones), 15); print("Exp: "); Printn(Exp(Ones), 15);
print "MonSubst: "; Printn(MonSubst(Ones, neg(one), 2), 10); print("MonSubst: "); Printn(MonSubst(Ones, neg(one), 2), 10);
print "ATan: "; Printn(Integ(zero, MonSubst(Ones, neg(one), 2)), 10); print("ATan: "); Printn(Integ(zero, MonSubst(Ones, neg(one), 2)), 10);
} else { // test } else { // test
check(Ones, one, 5, "Ones"); check(Ones, one, 5, "Ones");
check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones"); // 1 1 1 1 1 check(Add(Ones, Ones), itor(2), 0, "Add Ones Ones"); // 1 1 1 1 1

View File

@ -43,30 +43,30 @@ func Sieve(primes *chan-< int) {
func main() { func main() {
primes := new(chan int); primes := new(chan int);
go Sieve(primes); go Sieve(primes);
if <-primes != 2 { panic 2 } if <-primes != 2 { panic(2) }
if <-primes != 3 { panic 3 } if <-primes != 3 { panic(3) }
if <-primes != 5 { panic 5 } if <-primes != 5 { panic(5) }
if <-primes != 7 { panic 7 } if <-primes != 7 { panic(7) }
if <-primes != 11 { panic 11 } if <-primes != 11 { panic(11) }
if <-primes != 13 { panic 13 } if <-primes != 13 { panic(13) }
if <-primes != 17 { panic 17 } if <-primes != 17 { panic(17) }
if <-primes != 19 { panic 19 } if <-primes != 19 { panic(19) }
if <-primes != 23 { panic 23 } if <-primes != 23 { panic(23) }
if <-primes != 29 { panic 29 } if <-primes != 29 { panic(29) }
if <-primes != 31 { panic 31 } if <-primes != 31 { panic(31) }
if <-primes != 37 { panic 37 } if <-primes != 37 { panic(37) }
if <-primes != 41 { panic 41 } if <-primes != 41 { panic(41) }
if <-primes != 43 { panic 43 } if <-primes != 43 { panic(43) }
if <-primes != 47 { panic 47 } if <-primes != 47 { panic(47) }
if <-primes != 53 { panic 53 } if <-primes != 53 { panic(53) }
if <-primes != 59 { panic 59 } if <-primes != 59 { panic(59) }
if <-primes != 61 { panic 61 } if <-primes != 61 { panic(61) }
if <-primes != 67 { panic 67 } if <-primes != 67 { panic(67) }
if <-primes != 71 { panic 71 } if <-primes != 71 { panic(71) }
if <-primes != 73 { panic 73 } if <-primes != 73 { panic(73) }
if <-primes != 79 { panic 79 } if <-primes != 79 { panic(79) }
if <-primes != 83 { panic 83 } if <-primes != 83 { panic(83) }
if <-primes != 89 { panic 89 } if <-primes != 89 { panic(89) }
if <-primes != 97 { panic 97 } if <-primes != 97 { panic(97) }
sys.exit(0); sys.exit(0);
} }

View File

@ -32,11 +32,11 @@ func main() {
'\Ucafebabe' '\Ucafebabe'
; ;
if '\Ucafebabe' != 0xcafebabe { if '\Ucafebabe' != 0xcafebabe {
print "cafebabe wrong\n"; print("cafebabe wrong\n");
sys.exit(1) sys.exit(1)
} }
if i != 0xcc238de1 { if i != 0xcc238de1 {
print "number is ", i, " should be ", 0xcc238de1, "\n"; print("number is ", i, " should be ", 0xcc238de1, "\n");
sys.exit(1) sys.exit(1)
} }
} }

View File

@ -12,6 +12,6 @@ const (
); );
func main() { func main() {
if g == 0.0 { print "zero\n";} if g == 0.0 { print("zero\n");}
if g != 4.5 { print " fail\n"; sys.exit(1); } if g != 4.5 { print(" fail\n"); sys.exit(1); }
} }

View File

@ -12,10 +12,10 @@ func main() {
var u31 uint64 = 1; var u31 uint64 = 1;
var u32 uint64 = 18446744073709551615; var u32 uint64 = 18446744073709551615;
var u33 uint64 = +18446744073709551615; var u33 uint64 = +18446744073709551615;
if u32 != (1<<64)-1 { panic "u32\n"; } if u32 != (1<<64)-1 { panic("u32\n"); }
if u33 != (1<<64)-1 { panic "u33\n"; } if u33 != (1<<64)-1 { panic("u33\n"); }
var i34 int64 = ^0; // note: 2's complement means ^0 == -1 var i34 int64 = ^0; // note: 2's complement means ^0 == -1
if i34 != -1 { panic "i34" } if i34 != -1 { panic("i34") }
} }
/* /*
bug12.go:5: overflow converting constant to <uint64>UINT64 bug12.go:5: overflow converting constant to <uint64>UINT64

View File

@ -20,7 +20,7 @@ func Alloc(i int) int {
func main() { func main() {
s := Alloc(7); s := Alloc(7);
if s != 5 { panic "bad" } if s != 5 { panic("bad") }
} }
/* /*

View File

@ -7,5 +7,5 @@
package main package main
func main() { func main() {
go func() { print "ok\n" } (); go func() { print("ok\n") } ();
} }

View File

@ -9,7 +9,7 @@ package main
func main() { func main() {
x := 0; x := 0;
x = ^x; // unary ^ not yet implemented x = ^x; // unary ^ not yet implemented
if x != ^0 { panic x, " ", ^0 } if x != ^0 { panic(x, " ", ^0) }
} }
/* /*

View File

@ -11,7 +11,7 @@ type Service struct {
} }
func (s *Service) Serve(a int64) { func (s *Service) Serve(a int64) {
if a != 1234 { panic a, " not 1234\n" } if a != 1234 { panic(a, " not 1234\n") }
} }
var arith Service var arith Service

View File

@ -42,63 +42,63 @@ func
main() main()
{ {
if !close(0., 0, 1, 0) { print "0. is ", 0., "\n"; } if !close(0., 0, 1, 0) { print("0. is ", 0., "\n"); }
if !close(+10., 10, 1, 0) { print "+10. is ", +10., "\n"; } if !close(+10., 10, 1, 0) { print("+10. is ", +10., "\n"); }
if !close(-210., -210, 1, 0) { print "-210. is ", -210., "\n"; } if !close(-210., -210, 1, 0) { print("-210. is ", -210., "\n"); }
if !close(.0, 0, 1, 0) { print ".0 is ", .0, "\n"; } if !close(.0, 0, 1, 0) { print(".0 is ", .0, "\n"); }
if !close(+.01, 1, 100, 0) { print "+.01 is ", +.01, "\n"; } if !close(+.01, 1, 100, 0) { print("+.01 is ", +.01, "\n"); }
if !close(-.012, -12, 1000, 0) { print "-.012 is ", -.012, "\n"; } if !close(-.012, -12, 1000, 0) { print("-.012 is ", -.012, "\n"); }
if !close(0.0, 0, 1, 0) { print "0.0 is ", 0.0, "\n"; } if !close(0.0, 0, 1, 0) { print("0.0 is ", 0.0, "\n"); }
if !close(+10.01, 1001, 100, 0) { print "+10.01 is ", +10.01, "\n"; } if !close(+10.01, 1001, 100, 0) { print("+10.01 is ", +10.01, "\n"); }
if !close(-210.012, -210012, 1000, 0) { print "-210.012 is ", -210.012, "\n"; } if !close(-210.012, -210012, 1000, 0) { print("-210.012 is ", -210.012, "\n"); }
if !close(0E+1, 0, 1, 0) { print "0E+1 is ", 0E+1, "\n"; } if !close(0E+1, 0, 1, 0) { print("0E+1 is ", 0E+1, "\n"); }
if !close(+10e2, 10, 1, 2) { print "+10e2 is ", +10e2, "\n"; } if !close(+10e2, 10, 1, 2) { print("+10e2 is ", +10e2, "\n"); }
if !close(-210e3, -210, 1, 3) { print "-210e3 is ", -210e3, "\n"; } if !close(-210e3, -210, 1, 3) { print("-210e3 is ", -210e3, "\n"); }
if !close(0E-1, 0, 1, 0) { print "0E-1 is ", 0E-1, "\n"; } if !close(0E-1, 0, 1, 0) { print("0E-1 is ", 0E-1, "\n"); }
if !close(+0e23, 0, 1, 23) { print "+0e23 is ", +0e23, "\n"; } if !close(+0e23, 0, 1, 23) { print("+0e23 is ", +0e23, "\n"); }
if !close(-0e345, 0, 1, 345) { print "-0e345 is ", -0e345, "\n"; } if !close(-0e345, 0, 1, 345) { print("-0e345 is ", -0e345, "\n"); }
if !close(0E1, 0, 1, 1) { print "0E1 is ", 0E1, "\n"; } if !close(0E1, 0, 1, 1) { print("0E1 is ", 0E1, "\n"); }
if !close(+10e23, 10, 1, 23) { print "+10e23 is ", +10e23, "\n"; } if !close(+10e23, 10, 1, 23) { print("+10e23 is ", +10e23, "\n"); }
if !close(-210e34, -210, 1, 34) { print "-210e34 is ", -210e34, "\n"; } if !close(-210e34, -210, 1, 34) { print("-210e34 is ", -210e34, "\n"); }
if !close(0.E1, 0, 1, 1) { print "0.E1 is ", 0.E1, "\n"; } if !close(0.E1, 0, 1, 1) { print("0.E1 is ", 0.E1, "\n"); }
if !close(+10.e+2, 10, 1, 2) { print "+10.e+2 is ", +10.e+2, "\n"; } if !close(+10.e+2, 10, 1, 2) { print("+10.e+2 is ", +10.e+2, "\n"); }
if !close(-210.e-3, -210, 1, -3) { print "-210.e-3 is ", -210.e-3, "\n"; } if !close(-210.e-3, -210, 1, -3) { print("-210.e-3 is ", -210.e-3, "\n"); }
if !close(.0E1, 0, 1, 1) { print ".0E1 is ", .0E1, "\n"; } if !close(.0E1, 0, 1, 1) { print(".0E1 is ", .0E1, "\n"); }
if !close(+.01e2, 1, 100, 2) { print "+.01e2 is ", +.01e2, "\n"; } if !close(+.01e2, 1, 100, 2) { print("+.01e2 is ", +.01e2, "\n"); }
if !close(-.012e3, -12, 1000, 3) { print "-.012e3 is ", -.012e3, "\n"; } if !close(-.012e3, -12, 1000, 3) { print("-.012e3 is ", -.012e3, "\n"); }
if !close(0.0E1, 0, 1, 0) { print "0.0E1 is ", 0.0E1, "\n"; } if !close(0.0E1, 0, 1, 0) { print("0.0E1 is ", 0.0E1, "\n"); }
if !close(+10.01e2, 1001, 100, 2) { print "+10.01e2 is ", +10.01e2, "\n"; } if !close(+10.01e2, 1001, 100, 2) { print("+10.01e2 is ", +10.01e2, "\n"); }
if !close(-210.012e3, -210012, 1000, 3) { print "-210.012e3 is ", -210.012e3, "\n"; } if !close(-210.012e3, -210012, 1000, 3) { print("-210.012e3 is ", -210.012e3, "\n"); }
if !close(0.E+12, 0, 1, 0) { print "0.E+12 is ", 0.E+12, "\n"; } if !close(0.E+12, 0, 1, 0) { print("0.E+12 is ", 0.E+12, "\n"); }
if !close(+10.e23, 10, 1, 23) { print "+10.e23 is ", +10.e23, "\n"; } if !close(+10.e23, 10, 1, 23) { print("+10.e23 is ", +10.e23, "\n"); }
if !close(-210.e33, -210, 1, 33) { print "-210.e33 is ", -210.e33, "\n"; } if !close(-210.e33, -210, 1, 33) { print("-210.e33 is ", -210.e33, "\n"); }
if !close(.0E-12, 0, 1, 0) { print ".0E-12 is ", .0E-12, "\n"; } if !close(.0E-12, 0, 1, 0) { print(".0E-12 is ", .0E-12, "\n"); }
if !close(+.01e23, 1, 100, 23) { print "+.01e23 is ", +.01e23, "\n"; } if !close(+.01e23, 1, 100, 23) { print("+.01e23 is ", +.01e23, "\n"); }
if !close(-.012e34, -12, 1000, 34) { print "-.012e34 is ", -.012e34, "\n"; } if !close(-.012e34, -12, 1000, 34) { print("-.012e34 is ", -.012e34, "\n"); }
if !close(0.0E12, 0, 1, 12) { print "0.0E12 is ", 0.0E12, "\n"; } if !close(0.0E12, 0, 1, 12) { print("0.0E12 is ", 0.0E12, "\n"); }
if !close(+10.01e23, 1001, 100, 23) { print "+10.01e23 is ", +10.01e23, "\n"; } if !close(+10.01e23, 1001, 100, 23) { print("+10.01e23 is ", +10.01e23, "\n"); }
if !close(-210.012e33, -210012, 1000, 33) { print "-210.012e33 is ", -210.012e33, "\n"; } if !close(-210.012e33, -210012, 1000, 33) { print("-210.012e33 is ", -210.012e33, "\n"); }
if !close(0.E123, 0, 1, 123) { print "0.E123 is ", 0.E123, "\n"; } if !close(0.E123, 0, 1, 123) { print("0.E123 is ", 0.E123, "\n"); }
if !close(+10.e+23, 10, 1, 23) { print "+10.e+234 is ", +10.e+234, "\n"; } if !close(+10.e+23, 10, 1, 23) { print("+10.e+234 is ", +10.e+234, "\n"); }
if !close(-210.e-35, -210, 1, -35) { print "-210.e-35 is ", -210.e-35, "\n"; } if !close(-210.e-35, -210, 1, -35) { print("-210.e-35 is ", -210.e-35, "\n"); }
if !close(.0E123, 0, 1, 123) { print ".0E123 is ", .0E123, "\n"; } if !close(.0E123, 0, 1, 123) { print(".0E123 is ", .0E123, "\n"); }
if !close(+.01e29, 1, 100, 29) { print "+.01e29 is ", +.01e29, "\n"; } if !close(+.01e29, 1, 100, 29) { print("+.01e29 is ", +.01e29, "\n"); }
if !close(-.012e29, -12, 1000, 29) { print "-.012e29 is ", -.012e29, "\n"; } if !close(-.012e29, -12, 1000, 29) { print("-.012e29 is ", -.012e29, "\n"); }
if !close(0.0E123, 0, 1, 123) { print "0.0E123 is ", 0.0E123, "\n"; } if !close(0.0E123, 0, 1, 123) { print("0.0E123 is ", 0.0E123, "\n"); }
if !close(+10.01e31, 1001, 100, 31) { print "+10.01e31 is ", +10.01e31, "\n"; } if !close(+10.01e31, 1001, 100, 31) { print("+10.01e31 is ", +10.01e31, "\n"); }
if !close(-210.012e19, -210012, 1000, 19) { print "-210.012e19 is ", -210.012e19, "\n"; } if !close(-210.012e19, -210012, 1000, 19) { print("-210.012e19 is ", -210.012e19, "\n"); }
} }

View File

@ -11,15 +11,15 @@ import fmt "fmt" // BUG: shouldn't need the first 'fmt'.
func E(f *fmt.Fmt, e string) { func E(f *fmt.Fmt, e string) {
g := f.str(); g := f.str();
if sys.argc() > 1 { if sys.argc() > 1 {
print g, "\n"; print(g, "\n");
if g != e { if g != e {
print "expected <", e, ">\n"; print("expected <", e, ">\n");
} }
return; return;
} }
if g != e { if g != e {
print "expected <", e, ">\n"; print("expected <", e, ">\n");
print "got <", g, ">\n" print("got <", g, ">\n");
} }
} }

View File

@ -8,8 +8,8 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print "assertion fail", msg, "\n"; print("assertion fail", msg, "\n");
panic 1; panic(1);
} }
} }

View File

@ -9,8 +9,8 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print "assertion fail", msg, "\n"; print("assertion fail", msg, "\n");
panic 1; panic(1);
} }
} }

View File

@ -87,10 +87,6 @@ bugs/bug048.go:7: illegal types for operand: CONV
(MAP[<int32>INT32]<int32>INT32) (MAP[<int32>INT32]<int32>INT32)
BUG: known to fail incorrectly BUG: known to fail incorrectly
=========== bugs/bug053.go
bugs/bug053.go:6: syntax error
BUG: len should not be a keyword
=========== bugs/bug054.go =========== bugs/bug054.go
bugs/bug054.go:25: fatal error: agen_inter i2s bugs/bug054.go:25: fatal error: agen_inter i2s
BUG: known to fail incorrectly BUG: known to fail incorrectly

View File

@ -7,5 +7,5 @@
package main package main
func main() { func main() {
print "hello, world\n"; print("hello, world\n");
} }

View File

@ -8,8 +8,8 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print "assertion fail", msg, "\n"; print("assertion fail", msg, "\n");
panic 1; panic(1);
} }
} }

View File

@ -12,7 +12,7 @@ func main() {
count = count + one count = count + one
} }
if count != 8 { if count != 8 {
print count, " should be 8\n"; print(count, " should be 8\n");
sys.exit(1) sys.exit(1)
} }
} }

View File

@ -17,7 +17,7 @@ func main() {
0X0 + 0X0 +
0X123; 0X123;
if s != 788 { if s != 788 {
print "s is ", s, "; should be 788\n"; print("s is ", s, "; should be 788\n");
sys.exit(1); sys.exit(1);
} }
} }

View File

@ -8,8 +8,8 @@ package main
func assert(cond bool, msg string) { func assert(cond bool, msg string) {
if !cond { if !cond {
print "assertion fail: ", msg, "\n"; print("assertion fail: ", msg, "\n");
panic 1; panic(1);
} }
} }

View File

@ -15,5 +15,5 @@ main()
for i=0; i<100; i=i+1 { for i=0; i<100; i=i+1 {
t = t+i; t = t+i;
} }
if t != 50*99 { panic t; } if t != 50*99 { panic(t); }
} }

View File

@ -45,20 +45,20 @@ main()
s.b = 6; s.b = 6;
// call structure // call structure
if s.f() != 5 { panic 11; } if s.f() != 5 { panic(11); }
if s.g() != 6 { panic 12; } if s.g() != 6 { panic(12); }
i1 = s; // convert S to I1 i1 = s; // convert S to I1
i2 = i1; // convert I1 to I2 i2 = i1; // convert I1 to I2
// call interface // call interface
if i1.f() != 5 { panic 21; } if i1.f() != 5 { panic(21); }
if i2.f() != 5 { panic 22; } if i2.f() != 5 { panic(22); }
if i2.g() != 6 { panic 23; } if i2.g() != 6 { panic(23); }
g = i1; // convert I1 to S g = i1; // convert I1 to S
if g != s { panic 31; } if g != s { panic(31); }
g = i2; // convert I2 to S g = i2; // convert I2 to S
if g != s { panic 32; } if g != s { panic(32); }
} }

View File

@ -22,7 +22,7 @@ type Print struct
func (p *Print) func (p *Print)
dop() dop()
{ {
print " print ", p.whoami; print(" print ", p.whoami);
p.put.puts("abc"); p.put.puts("abc");
} }
@ -37,7 +37,7 @@ type Bio struct
func (b *Bio) func (b *Bio)
puts(s string) puts(s string)
{ {
print " bio ", b.whoami; print(" bio ", b.whoami);
b.put.puts(s); b.put.puts(s);
} }
@ -52,7 +52,7 @@ type File struct
func (f *File) func (f *File)
puts(s string) puts(s string)
{ {
print " file ", f.whoami, " -- ", s; print(" file ", f.whoami, " -- ", s);
} }
func func
@ -71,5 +71,5 @@ main()
f.whoami = 3; f.whoami = 3;
p.dop(); p.dop();
print "\n"; print("\n");
} }

View File

@ -28,8 +28,8 @@ loop:
if i < 100 { if i < 100 {
goto loop; goto loop;
} }
print i; print(i);
print "\n"; print("\n");
return; return;
gogoloop: gogoloop:

View File

@ -19,5 +19,5 @@ main()
}; };
return x(a)+11; return x(a)+11;
}; };
if x(3) != 3+5+7+11 { panic x(3); } if x(3) != 3+5+7+11 { panic(x(3)); }
} }

View File

@ -14,7 +14,7 @@ main()
var x,y int; var x,y int;
x,y = simple(10,20,30); x,y = simple(10,20,30);
if x+y != 65 { panic x+y; } if x+y != 65 { panic(x+y); }
} }
func func

View File

@ -32,13 +32,13 @@ main()
c.x = &g; c.x = &g;
v = g(c); v = g(c);
if v != 6 { panic v; } if v != 6 { panic(v); }
v = c.x(c); v = c.x(c);
if v != 6 { panic v; } if v != 6 { panic(v); }
v = c.f(); v = c.f();
if v != 6 { panic v; } if v != 6 { panic(v); }
} }
func func
@ -47,6 +47,6 @@ g(p *C)int
var v int; var v int;
v = p.a; v = p.a;
if v != 6 { panic v; } if v != 6 { panic(v); }
return p.a; return p.a;
} }

View File

@ -34,8 +34,8 @@ main()
s2.d.c = 23; s2.d.c = 23;
s2.d.d = 20; s2.d.d = 20;
if(s2.d.c != 23) { panic 1; } if(s2.d.c != 23) { panic(1); }
if(g2.d.c != 23) { panic 2; } if(g2.d.c != 23) { panic(2); }
x = s1.a + x = s1.a +
s1.b + s1.b +
@ -50,5 +50,5 @@ main()
s2.d.c + s2.d.c +
s2.d.d; s2.d.d;
if(x != 121) { panic x; } if(x != 121) { panic(x); }
} }

View File

@ -63,7 +63,7 @@ Init(i int) *Integer
func (this *Integer) func (this *Integer)
Print() Print()
{ {
print this.val; print(this.val);
} }
func func
@ -78,5 +78,5 @@ main()
} }
list.Print(); list.Print();
print "\n"; print("\n");
} }

View File

@ -100,21 +100,21 @@ func (slist *Slist) PrintOne(doparen bool)
} }
if slist.isatom { if slist.isatom {
if slist.isstring { if slist.isstring {
print slist.String(); print(slist.String());
} else { } else {
print slist.Integer(); print(slist.Integer());
} }
} else { } else {
if doparen { if doparen {
print "(" ; print("(" );
} }
slist.Car().PrintOne(true); slist.Car().PrintOne(true);
if slist.Cdr() != nil { if slist.Cdr() != nil {
print " "; print(" ");
slist.Cdr().PrintOne(false); slist.Cdr().PrintOne(false);
} }
if doparen { if doparen {
print ")"; print(")");
} }
} }
} }
@ -122,7 +122,7 @@ func (slist *Slist) PrintOne(doparen bool)
func (slist *Slist) Print() func (slist *Slist) Print()
{ {
slist.PrintOne(true); slist.PrintOne(true);
print "\n"; print("\n");
} }
func Get() int func Get() int
@ -182,7 +182,7 @@ func NextToken()
} }
} }
if i >= 100 - 1 { // sizeof tokenbuf - 1 if i >= 100 - 1 { // sizeof tokenbuf - 1
panic "atom too long\n"; panic("atom too long\n");
} }
tokenlen = i; tokenlen = i;
tokenbuf[i] = nilchar; tokenbuf[i] = nilchar;
@ -197,8 +197,8 @@ func NextToken()
func Expect(c int) func Expect(c int)
{ {
if token != c { if token != c {
print "parse error: expected ", c, "\n"; print("parse error: expected ", c, "\n");
panic "parse"; panic("parse");
} }
NextToken(); NextToken();
} }
@ -276,7 +276,7 @@ func Parse() *Slist
slist = atom(0); slist = atom(0);
default: default:
slist = nil; slist = nil;
print "unknown token"; //, token, tokenbuf; print("unknown token"); // token, tokenbuf);
} }
NextToken(); NextToken();
return slist; return slist;

View File

@ -8,8 +8,8 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print "assertion fail" + msg + "\n"; print("assertion fail" + msg + "\n");
panic 1; panic(1);
} }
} }

View File

@ -8,8 +8,8 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print "assertion fail" + msg + "\n"; print("assertion fail" + msg + "\n");
panic 1; panic(1);
} }
} }

View File

@ -8,8 +8,8 @@ package main
func assertequal(is, shouldbe int, msg string) { func assertequal(is, shouldbe int, msg string) {
if is != shouldbe { if is != shouldbe {
print "assertion fail" + msg + "\n"; print("assertion fail" + msg + "\n");
panic 1; panic(1);
} }
} }

View File

@ -8,8 +8,8 @@ package main
func assert(cond bool, msg string) { func assert(cond bool, msg string) {
if !cond { if !cond {
print "assertion fail: " + msg + "\n"; print("assertion fail: " + msg + "\n");
panic 1; panic(1);
} }
} }

View File

@ -22,7 +22,7 @@ main()
s1 = s1 + a[i]; s1 = s1 + a[i];
} }
if s1 != 35 { panic s1; } if s1 != 35 { panic(s1); }
for i:=short(5); i<10; i=i+1 { for i:=short(5); i<10; i=i+1 {
b[i] = float(i); b[i] = float(i);
@ -33,7 +33,7 @@ main()
s2 = s2 + b[i]; s2 = s2 + b[i];
} }
if s2 != 35 { panic s2; } if s2 != 35 { panic(s2); }
b := new([100]int); b := new([100]int);
for i:=0; i<100; i=i+1 { for i:=0; i<100; i=i+1 {
@ -45,5 +45,5 @@ main()
s3 = s3+b[i]; s3 = s3+b[i];
} }
if s3 != 4950 { panic s3; } if s3 != 4950 { panic(s3); }
} }

View File

@ -20,88 +20,88 @@ main()
a = true; a = true;
b = false; b = false;
if !a { panic 1; } if !a { panic(1); }
if b { panic 2; } if b { panic(2); }
if !!!a { panic 3; } if !!!a { panic(3); }
if !!b { panic 4; } if !!b { panic(4); }
a = !b; a = !b;
if !a { panic 5; } if !a { panic(5); }
if !!!a { panic 6; } if !!!a { panic(6); }
var x *s; var x *s;
x = new(s); x = new(s);
x.a = true; x.a = true;
x.b = false; x.b = false;
if !x.a { panic 7; } if !x.a { panic(7); }
if x.b { panic 8; } if x.b { panic(8); }
if !!!x.a { panic 9; } if !!!x.a { panic(9); }
if !!x.b { panic 10; } if !!x.b { panic(10); }
x.a = !x.b; x.a = !x.b;
if !x.a { panic 11; } if !x.a { panic(11); }
if !!!x.a { panic 12; } if !!!x.a { panic(12); }
/* /*
* test && * test &&
*/ */
a = true; a = true;
b = true; b = true;
if !(a && b) { panic 21; } if !(a && b) { panic(21); }
if a && !b { panic 22; } if a && !b { panic(22); }
if !a && b { panic 23; } if !a && b { panic(23); }
if !a && !b { panic 24; } if !a && !b { panic(24); }
a = false; a = false;
b = true; b = true;
if !(!a && b) { panic 31; } if !(!a && b) { panic(31); }
if !a && !b { panic 32; } if !a && !b { panic(32); }
if a && b { panic 33; } if a && b { panic(33); }
if a && !b { panic 34; } if a && !b { panic(34); }
a = true; a = true;
b = false; b = false;
if !(a && !b) { panic 41; } if !(a && !b) { panic(41); }
if a && b { panic 41; } if a && b { panic(41); }
if !a && !b { panic 41; } if !a && !b { panic(41); }
if !a && b { panic 44; } if !a && b { panic(44); }
a = false; a = false;
b = false; b = false;
if !(!a && !b) { panic 51; } if !(!a && !b) { panic(51); }
if !a && b { panic 52; } if !a && b { panic(52); }
if a && !b { panic 53; } if a && !b { panic(53); }
if a && b { panic 54; } if a && b { panic(54); }
/* /*
* test || * test ||
*/ */
a = true; a = true;
b = true; b = true;
if !(a || b) { panic 61; } if !(a || b) { panic(61); }
if !(a || !b) { panic 62; } if !(a || !b) { panic(62); }
if !(!a || b) { panic 63; } if !(!a || b) { panic(63); }
if !a || !b { panic 64; } if !a || !b { panic(64); }
a = false; a = false;
b = true; b = true;
if !(!a || b) { panic 71; } if !(!a || b) { panic(71); }
if !(!a || !b) { panic 72; } if !(!a || !b) { panic(72); }
if !(a || b) { panic 73; } if !(a || b) { panic(73); }
if a || !b { panic 74; } if a || !b { panic(74); }
a = true; a = true;
b = false; b = false;
if !(a || !b) { panic 81; } if !(a || !b) { panic(81); }
if !(a || b) { panic 82; } if !(a || b) { panic(82); }
if !(!a || !b) { panic 83; } if !(!a || !b) { panic(83); }
if !a || b { panic 84; } if !a || b { panic(84); }
a = false; a = false;
b = false; b = false;
if !(!a || !b) { panic 91; } if !(!a || !b) { panic(91); }
if !(!a || b) { panic 92; } if !(!a || b) { panic(92); }
if !(a || !b) { panic 93; } if !(a || !b) { panic(93); }
if a || b { panic 94; } if a || b { panic(94); }
} }

View File

@ -15,11 +15,11 @@ main()
for i:=short(0); i<10; i=i+1 { for i:=short(0); i<10; i=i+1 {
s1 = s1 + vlong(i); s1 = s1 + vlong(i);
} }
if s1 != 45 { panic s1; } if s1 != 45 { panic(s1); }
s2 := float(0); s2 := float(0);
for i:=0; i<10; i=i+1 { for i:=0; i<10; i=i+1 {
s2 = s2 + float(i); s2 = s2 + float(i);
} }
if s2 != 45 { panic s2; } if s2 != 45 { panic(s2); }
} }

View File

@ -15,7 +15,7 @@ main()
var x int; var x int;
x = fun(10,20,30); x = fun(10,20,30);
if x != 60 { panic x; } if x != 60 { panic(x); }
} }
func func
@ -24,6 +24,6 @@ fun(ia,ib,ic int)int
var o int; var o int;
o = ia+ib+ic; o = ia+ib+ic;
if o != 60 { panic o; } if o != 60 { panic(o); }
return o; return o;
} }

View File

@ -10,5 +10,5 @@ package main
func func
main() main()
{ {
print "hello world\n"; print("hello world\n");
} }

View File

@ -13,13 +13,13 @@ main()
for i:=0; i<10; i=i+1 { for i:=0; i<10; i=i+1 {
switch(i) { switch(i) {
case 5: case 5:
print "five"; print("five");
case a,7: case a,7:
print "a"; print("a");
default: default:
print i; print(i);
} }
print "out", i; print("out", i);
} }
print "\n"; print("\n");
} }

View File

@ -21,5 +21,5 @@ main()
y = 25; y = 25;
} }
x = x+y; x = x+y;
if(x != 40) { panic x; } if(x != 40) { panic(x); }
} }

View File

@ -16,69 +16,69 @@ main()
b := `xyz`; b := `xyz`;
/* print a literal */ /* print a literal */
print `abc`; print(`abc`);
/* print a variable */ /* print a variable */
print b, "-"; print(b, "-");
/* catenate literals */ /* catenate literals */
print `abc` + `xyz`, "-"; print(`abc` + `xyz`, "-");
/* catenate variables */ /* catenate variables */
print a+b, "-"; print(a+b, "-");
/* compare literals */ /* compare literals */
if `abc` == `xyz` || `abc` != "abc" || `abc` > `xyz` { if `abc` == `xyz` || `abc` != "abc" || `abc` > `xyz` {
panic "compare literals"; panic("compare literals");
} }
/* compare variables */ /* compare variables */
if a == b || a != a || a > b { if a == b || a != a || a > b {
panic "compare variables"; panic("compare variables");
} }
/* cat */ /* cat */
c = a+b; c = a+b;
print c, "-"; print(c, "-");
/* catequal */ /* catequal */
c = a; c = a;
c += b; c += b;
print c, "-"; print(c, "-");
/* clumsy evaluation */ /* clumsy evaluation */
c = b; c = b;
c = a + c; c = a + c;
print c, "-"; print(c, "-");
/* len */ /* len */
if len(c) != 6 { if len(c) != 6 {
panic "len ", len(c); panic("len ", len(c));
} }
/* index strings */ /* index strings */
for i:=0; i<len(c); i=i+1 { for i:=0; i<len(c); i=i+1 {
if c[i] != (a+b)[i] { if c[i] != (a+b)[i] {
panic "index ", i, " ", c[i], " ", (a+b)[i]; panic("index ", i, " ", c[i], " ", (a+b)[i]);
} }
} }
/* slice strings */ /* slice strings */
print c[0:3], c[3:6]; print(c[0:3], c[3:6]);
print "\n"; print("\n");
/* create string with integer constant */ /* create string with integer constant */
c = string('x'); c = string('x');
if c != "x" { if c != "x" {
panic "create int ", c; panic("create int ", c);
} }
/* create string with integer variable */ /* create string with integer variable */
v := 'x'; v := 'x';
c = string(v); c = string(v);
if c != "x" { if c != "x" {
panic "create int ", c; panic("create int ", c);
} }
/* create string with byte array */ /* create string with byte array */
@ -88,7 +88,7 @@ main()
z1[2] = 'c'; z1[2] = 'c';
c = string(z1); c = string(z1);
if c != "abc" { if c != "abc" {
panic "create array ", c; panic("create array ", c);
} }
/* create string with byte array pointer */ /* create string with byte array pointer */
@ -98,6 +98,6 @@ main()
z2[2] = 'c'; z2[2] = 'c';
c = string(z2); c = string(z2);
if c != "abc" { if c != "abc" {
panic "create array pointer ", c; panic("create array pointer ", c);
} }
} }

View File

@ -27,8 +27,8 @@ main()
s1.c = 3; s1.c = 3;
s1.d = 5; s1.d = 5;
if(s1.c != 3) { panic s1.c; } if(s1.c != 3) { panic(s1.c); }
if(g1.c != 3) { panic g1.c; } if(g1.c != 3) { panic(g1.c); }
s2.a = 7; s2.a = 7;
s2.b = 11; s2.b = 11;
@ -38,8 +38,8 @@ main()
s2.d.c = 23; s2.d.c = 23;
s2.d.d = 29; s2.d.d = 29;
if(s2.d.c != 23) { panic s2.d.c; } if(s2.d.c != 23) { panic(s2.d.c); }
if(g2.d.c != 23) { panic g2.d.c; } if(g2.d.c != 23) { panic(g2.d.c); }
x = s1.a + x = s1.a +
s1.b + s1.b +
@ -54,7 +54,7 @@ main()
s2.d.c + s2.d.c +
s2.d.d; s2.d.d;
if(x != 130) { panic x; } if(x != 130) { panic(x); }
// test an automatic struct // test an automatic struct
s3.a = 7; s3.a = 7;
@ -65,7 +65,7 @@ main()
s3.d.c = 23; s3.d.c = 23;
s3.d.d = 29; s3.d.d = 29;
if(s3.d.c != 23) { panic s3.d.c; } if(s3.d.c != 23) { panic(s3.d.c); }
x = s3.a + x = s3.a +
s3.b + s3.b +
@ -75,5 +75,5 @@ main()
s3.d.c + s3.d.c +
s3.d.d; s3.d.d;
if(x != 119) { panic x; } if(x != 119) { panic(x); }
} }

View File

@ -8,8 +8,8 @@ package main
func assert(cond bool, msg string) { func assert(cond bool, msg string) {
if !cond { if !cond {
print "assertion fail: ", msg, "\n"; print("assertion fail: ", msg, "\n");
panic 1; panic(1);
} }
} }

View File

@ -87,7 +87,7 @@ func count(x *Number) int {
func check(x *Number, expected int) { func check(x *Number, expected int) {
var c = count(x); var c = count(x);
if c != expected { if c != expected {
panic "error: found ", c, "; expected ", expected, "\n"; panic("error: found ", c, "; expected ", expected, "\n");
} }
} }
@ -125,7 +125,7 @@ func main() {
verify(); verify();
for i := 0; i <= 10; i++ { for i := 0; i <= 10; i++ {
print i, "! = ", count(fact(gen(i))), "\n"; print(i, "! = ", count(fact(gen(i))), "\n");
} }
} }

View File

@ -13,7 +13,7 @@ func main() {
s, ok = sys.readfile("readfile.go"); s, ok = sys.readfile("readfile.go");
if !ok { if !ok {
print "couldn't readfile\n"; print("couldn't readfile\n");
sys.exit(1) sys.exit(1)
} }
start_of_file := start_of_file :=
@ -22,7 +22,7 @@ func main() {
"\n" + "\n" +
"package main\n"; "package main\n";
if s[0:102] != start_of_file { if s[0:102] != start_of_file {
print "wrong data\n"; print("wrong data\n");
sys.exit(1) sys.exit(1)
} }
} }

View File

@ -30,7 +30,7 @@ func Sieve() {
go Generate(ch); // Start Generate() as a subprocess. go Generate(ch); // Start Generate() as a subprocess.
for { for {
prime := <-ch; prime := <-ch;
print prime, "\n"; print(prime, "\n");
ch1 := new(chan int); ch1 := new(chan int);
go Filter(ch, ch1, prime); go Filter(ch, ch1, prime);
ch = ch1 ch = ch1

View File

@ -11,16 +11,16 @@ var a,b,c,d,e,f,g,h,i int;
func func
printit() printit()
{ {
print a,b,c,d,e,f,g,h,i,"\n"; print(a,b,c,d,e,f,g,h,i,"\n");
} }
func func
testit() bool testit() bool
{ {
if a+b+c+d+e+f+g+h+i != 45 { if a+b+c+d+e+f+g+h+i != 45 {
print "sum does not add to 45\n"; print("sum does not add to 45\n");
printit(); printit();
panic; panic();
} }
return a == 1 && return a == 1 &&
b == 2 && b == 2 &&
@ -51,7 +51,7 @@ main()
h = 8; h = 8;
i = 9; i = 9;
if !testit() { panic "init val\n"; } if !testit() { panic("init val\n"); }
for z:=0; z<100; z++ { for z:=0; z<100; z++ {
a,b,c,d, e,f,g,h,i = b,c,d,a, i,e,f,g,h; a,b,c,d, e,f,g,h,i = b,c,d,a, i,e,f,g,h;
@ -60,24 +60,24 @@ main()
if z == 19 { if z == 19 {
break; break;
} }
print "on ", z, "th iteration\n"; print("on ", z, "th iteration\n");
printit(); printit();
panic; panic();
} }
} }
if !testit() { if !testit() {
print "final val\n"; print("final val\n");
printit(); printit();
panic; panic();
} }
a, b = swap(1, 2); a, b = swap(1, 2);
if a != 2 || b != 1 { if a != 2 || b != 1 {
panic "bad swap"; panic("bad swap");
} }
//BUG a, b = swap(swap(a, b)); //BUG a, b = swap(swap(a, b));
// if a != 2 || b != 1 { // if a != 2 || b != 1 {
// panic "bad swap"; // panic("bad swap");
// } // }
} }

View File

@ -11,7 +11,7 @@ var ecode int;
func assert(a, b, c string) { func assert(a, b, c string) {
if a != b { if a != b {
ecode = 1; ecode = 1;
print "FAIL: ", c, ": ", a, "!=", b, "\n"; print("FAIL: ", c, ": ", a, "!=", b, "\n");
var max int = len(a); var max int = len(a);
if len(b) > max { if len(b) > max {
max = len(b); max = len(b);
@ -26,7 +26,7 @@ func assert(a, b, c string) {
bc = int(b[i]); bc = int(b[i]);
} }
if ac != bc { if ac != bc {
print "\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n"; print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n");
} }
} }
} }

View File

@ -8,8 +8,8 @@ package main
func assert(cond bool, msg string) { func assert(cond bool, msg string) {
if !cond { if !cond {
print "assertion fail: ", msg, "\n"; print("assertion fail: ", msg, "\n");
panic 1; panic(1);
} }
} }

View File

@ -24,7 +24,7 @@ func main() {
case '-': case '-':
a[p]--; a[p]--;
case '.': case '.':
print string(a[p]); print(string(a[p]));
case '[': case '[':
if a[p] == 0 { if a[p] == 0 {
for nest := 1; nest > 0; pc++ { for nest := 1; nest > 0; pc++ {

View File

@ -22,13 +22,13 @@ func main() {
for w, i, j := 0,0,0; i < l; i += w { for w, i, j := 0,0,0; i < l; i += w {
var r int32; var r int32;
r, w = sys.stringtorune(s, i, l); r, w = sys.stringtorune(s, i, l);
if w == 0 { panic "zero width in string" } if w == 0 { panic("zero width in string") }
if r != chars[j] { panic "wrong value from string" } if r != chars[j] { panic("wrong value from string") }
j++; j++;
} }
// encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e // encoded as bytes: 'a' 'b' 'c' e6 97 a5 e6 9c ac e8 aa 9e
const L = 12; const L = 12;
if L != l { panic "wrong length constructing array" } if L != l { panic("wrong length constructing array") }
a := new([L]byte); a := new([L]byte);
a[0] = 'a'; a[0] = 'a';
a[1] = 'b'; a[1] = 'b';
@ -45,8 +45,8 @@ func main() {
for w, i, j := 0,0,0; i < L; i += w { for w, i, j := 0,0,0; i < L; i += w {
var r int32; var r int32;
r, w = sys.bytestorune(&a[0], i, L); r, w = sys.bytestorune(&a[0], i, L);
if w == 0 { panic "zero width in bytes" } if w == 0 { panic("zero width in bytes") }
if r != chars[j] { panic "wrong value from bytes" } if r != chars[j] { panic("wrong value from bytes") }
j++; j++;
} }
} }