Commit 27c0eb84 authored by Rob Pike's avatar Rob Pike

update tests to new communications syntax

powser1.go has not been tested - waiting for compiler to catch up

R=ken
OCL=15415
CL=15415
parent 47919799
...@@ -13,7 +13,7 @@ func M(f uint64) (in, out *T) { ...@@ -13,7 +13,7 @@ func M(f uint64) (in, out *T) {
out = new(T, 100); out = new(T, 100);
go func(in, out *T, f uint64) { go func(in, out *T, f uint64) {
for { for {
out -< f * <- in; out <- f * <-in;
} }
}(in, out, f); }(in, out, f);
return in, out; return in, out;
...@@ -55,7 +55,7 @@ func main() { ...@@ -55,7 +55,7 @@ func main() {
for i := 0; i < len(OUT); i++ { for i := 0; i < len(OUT); i++ {
t := min(xs); t := min(xs);
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
ins[i] -< x; ins[i] <- x;
} }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
......
...@@ -13,7 +13,7 @@ const N = 10 ...@@ -13,7 +13,7 @@ const N = 10
func AsynchFifo() { func AsynchFifo() {
ch := new(chan int, N); ch := new(chan int, N);
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
ch -< i ch <- i
} }
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
if <-ch != i { if <-ch != i {
...@@ -23,12 +23,12 @@ func AsynchFifo() { ...@@ -23,12 +23,12 @@ 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
} }
// thread together a daisy chain to read the elements in sequence // thread together a daisy chain to read the elements in sequence
...@@ -41,9 +41,9 @@ func SynchFifo() { ...@@ -41,9 +41,9 @@ func SynchFifo() {
go Chain(ch, i, in, out); go Chain(ch, i, in, out);
in = out; in = out;
} }
start -< 0; start <- 0;
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
ch -< i ch <- i
} }
<-in <-in
} }
......
...@@ -18,7 +18,7 @@ func i32receiver(c *chan int32) { ...@@ -18,7 +18,7 @@ func i32receiver(c *chan int32) {
} }
func i32sender(c *chan int32) { func i32sender(c *chan int32) {
c -< 234 c <- 234
} }
func i64receiver(c *chan int64) { func i64receiver(c *chan int64) {
...@@ -26,7 +26,7 @@ func i64receiver(c *chan int64) { ...@@ -26,7 +26,7 @@ func i64receiver(c *chan int64) {
} }
func i64sender(c *chan int64) { func i64sender(c *chan int64) {
c -< 234567 c <- 234567
} }
func breceiver(c *chan bool) { func breceiver(c *chan bool) {
...@@ -34,7 +34,7 @@ func breceiver(c *chan bool) { ...@@ -34,7 +34,7 @@ func breceiver(c *chan bool) {
} }
func bsender(c *chan bool) { func bsender(c *chan bool) {
c -< true c <- true
} }
func sreceiver(c *chan string) { func sreceiver(c *chan string) {
...@@ -42,7 +42,7 @@ func sreceiver(c *chan string) { ...@@ -42,7 +42,7 @@ func sreceiver(c *chan string) {
} }
func ssender(c *chan string) { func ssender(c *chan string) {
c -< "hello again" c <- "hello again"
} }
func main() { func main() {
...@@ -71,7 +71,7 @@ func main() { ...@@ -71,7 +71,7 @@ func main() {
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();
...@@ -81,7 +81,7 @@ func main() { ...@@ -81,7 +81,7 @@ func main() {
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();
...@@ -91,7 +91,7 @@ func main() { ...@@ -91,7 +91,7 @@ func main() {
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();
...@@ -101,7 +101,7 @@ func main() { ...@@ -101,7 +101,7 @@ func main() {
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();
......
...@@ -92,33 +92,33 @@ func dosplit(in *dch, out *dch2, wait *chan int ){ ...@@ -92,33 +92,33 @@ func dosplit(in *dch, out *dch2, wait *chan int ){
} }
seqno++; seqno++;
in.req -< seqno; in.req <- seqno;
release := new(chan int); release := new(chan int);
go dosplit(in, out, release); go dosplit(in, out, release);
dat := <-in.dat; dat := <-in.dat;
out[0].dat -< dat; out[0].dat <- dat;
if !both { if !both {
<-wait <-wait
} }
<-out[1].req; <-out[1].req;
out[1].dat -< dat; out[1].dat <- dat;
release -< 0; release <- 0;
} }
func split(in *dch, out *dch2){ func split(in *dch, out *dch2){
release := new(chan int); release := new(chan int);
go dosplit(in, out, release); go dosplit(in, out, release);
release -< 0; release <- 0;
} }
func put(dat item, out *dch){ func put(dat item, out *dch){
<-out.req; <-out.req;
out.dat -< dat; out.dat <- dat;
} }
func get(in *dch) item{ func get(in *dch) item{
seqno++; seqno++;
in.req -< seqno; in.req <- seqno;
return <-in.dat; return <-in.dat;
} }
...@@ -140,16 +140,16 @@ func getn(in *[]*dch, n int) *[]item { ...@@ -140,16 +140,16 @@ func getn(in *[]*dch, n int) *[]item {
seqno++ seqno++
select{ select{
case req[0] -< seqno: case req[0] <- seqno:
dat[0] = in[0].dat; dat[0] = in[0].dat;
req[0] = nil; req[0] = nil;
case req[1] -< seqno: case req[1] <- seqno:
dat[1] = in[1].dat; dat[1] = in[1].dat;
req[1] = nil; req[1] = nil;
case it <- dat[0]: case it = <-dat[0]:
out[0] = it; out[0] = it;
dat[0] = nil; dat[0] = nil;
case it <- dat[1]: case it = <-dat[1]:
out[1] = it; out[1] = it;
dat[1] = nil; dat[1] = nil;
} }
...@@ -169,7 +169,7 @@ func get2(in0 *dch, in1 *dch) *[]item { ...@@ -169,7 +169,7 @@ func get2(in0 *dch, in1 *dch) *[]item {
func copy(in *dch, out *dch){ func copy(in *dch, out *dch){
for { for {
<-out.req; <-out.req;
out.dat -< get(in); out.dat <- get(in);
} }
} }
...@@ -331,15 +331,15 @@ func Add(U, V PS) PS{ ...@@ -331,15 +331,15 @@ func Add(U, V PS) PS{
uv = get2(U,V); uv = get2(U,V);
switch end(uv[0])+2*end(uv[1]) { switch end(uv[0])+2*end(uv[1]) {
case 0: case 0:
Z.dat -< add(uv[0], uv[1]); Z.dat <- add(uv[0], uv[1]);
case 1: case 1:
Z.dat -< uv[1]; Z.dat <- uv[1];
copy(V,Z); copy(V,Z);
case 2: case 2:
Z.dat -< uv[0]; Z.dat <- uv[0];
copy(U,Z) copy(U,Z)
case 3: case 3:
Z.dat -< finis; Z.dat <- finis;
} }
} }
}(U, V, Z); }(U, V, Z);
...@@ -355,9 +355,9 @@ func Cmul(c *rat,U PS) PS{ ...@@ -355,9 +355,9 @@ func Cmul(c *rat,U PS) PS{
<-Z.req; <-Z.req;
u := get(U); u := get(U);
if end(u) != 0 { done = true } if end(u) != 0 { done = true }
else { Z.dat -< mul(c,u) } else { Z.dat <- mul(c,u) }
} }
Z.dat -< finis; Z.dat <- finis;
}(c, U, Z); }(c, U, Z);
return Z; return Z;
} }
...@@ -446,14 +446,14 @@ func Mul(U, V PS) PS{ ...@@ -446,14 +446,14 @@ func Mul(U, V PS) PS{
<-Z.req; <-Z.req;
uv := get2(U,V); uv := get2(U,V);
if end(uv[0])!=0 || end(uv[1]) != 0 { if end(uv[0])!=0 || end(uv[1]) != 0 {
Z.dat -< finis; Z.dat <- finis;
} else { } else {
Z.dat -< mul(uv[0],uv[1]); Z.dat <- mul(uv[0],uv[1]);
UU := Split(U); UU := Split(U);
VV := Split(V); VV := Split(V);
W := Add(Cmul(uv[0],VV[0]),Cmul(uv[1],UU[0])); W := Add(Cmul(uv[0],VV[0]),Cmul(uv[1],UU[0]));
<-Z.req; <-Z.req;
Z.dat -< get(W); Z.dat <- get(W);
copy(Add(W,Mul(UU[1],VV[1])),Z); copy(Add(W,Mul(UU[1],VV[1])),Z);
} }
}(U, V, Z); }(U, V, Z);
...@@ -473,12 +473,12 @@ func Diff(U PS) PS{ ...@@ -473,12 +473,12 @@ func Diff(U PS) PS{
u = get(U); u = get(U);
if end(u) != 0 { done=true } if end(u) != 0 { done=true }
else { else {
Z.dat -< mul(itor(int64(i)),u); Z.dat <- mul(itor(int64(i)),u);
<-Z.req; <-Z.req;
} }
} }
} }
Z.dat -< finis; Z.dat <- finis;
}(U, Z); }(U, Z);
return Z; return Z;
} }
...@@ -493,9 +493,9 @@ func Integ(c *rat,U PS) PS{ ...@@ -493,9 +493,9 @@ func Integ(c *rat,U PS) PS{
<-Z.req; <-Z.req;
u := get(U); u := get(U);
if end(u) != 0 { done= true } if end(u) != 0 { done= true }
Z.dat -< mul(i2tor(1,int64(i)),u); Z.dat <- mul(i2tor(1,int64(i)),u);
} }
Z.dat -< finis; Z.dat <- finis;
}(c, U, Z); }(c, U, Z);
return Z; return Z;
} }
...@@ -532,7 +532,7 @@ func Recip(U PS) PS{ ...@@ -532,7 +532,7 @@ func Recip(U PS) PS{
ZZ:=mkPS2(); ZZ:=mkPS2();
<-Z.req; <-Z.req;
z := inv(get(U)); z := inv(get(U));
Z.dat -< z; Z.dat <- z;
split(Mul(Cmul(neg(z),U),Shift(z,ZZ[0])),ZZ); split(Mul(Cmul(neg(z),U),Shift(z,ZZ[0])),ZZ);
copy(ZZ[1],Z); copy(ZZ[1],Z);
}(U, Z); }(U, Z);
...@@ -564,7 +564,7 @@ func Subst(U, V PS) PS { ...@@ -564,7 +564,7 @@ func Subst(U, V PS) PS {
VV := Split(V); VV := Split(V);
<-Z.req; <-Z.req;
u := get(U); u := get(U);
Z.dat -< u; Z.dat <- u;
if end(u) == 0 { if end(u) == 0 {
if end(get(VV[0])) != 0 { put(finis,Z); } if end(get(VV[0])) != 0 { put(finis,Z); }
else { copy(Mul(VV[0],Subst(U,VV[1])),Z); } else { copy(Mul(VV[0],Subst(U,VV[1])),Z); }
...@@ -583,15 +583,15 @@ func MonSubst(U PS, c0 *rat, n int) PS { ...@@ -583,15 +583,15 @@ func MonSubst(U PS, c0 *rat, n int) PS {
for { for {
<-Z.req; <-Z.req;
u := get(U); u := get(U);
Z.dat -< mul(u, c); Z.dat <- mul(u, c);
c = mul(c, c0); c = mul(c, c0);
if end(u) != 0 { if end(u) != 0 {
Z.dat -< finis; Z.dat <- finis;
break; break;
} }
for i := 1; i < n; i++ { for i := 1; i < n; i++ {
<-Z.req; <-Z.req;
Z.dat -< zero; Z.dat <- zero;
} }
} }
}(U, Z, c0, n); }(U, Z, c0, n);
......
...@@ -10,30 +10,30 @@ ...@@ -10,30 +10,30 @@
package main package main
// Send the sequence 2, 3, 4, ... to channel 'ch'. // Send the sequence 2, 3, 4, ... to channel 'ch'.
func Generate(ch *chan-< int) { func Generate(ch *chan<- int) {
for i := 2; ; i++ { for i := 2; ; i++ {
ch -< i // Send 'i' to channel 'ch'. ch <- i // Send 'i' to channel 'ch'.
} }
} }
// Copy the values from channel 'in' to channel 'out', // Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'. // removing those divisible by 'prime'.
func Filter(in *chan<- int, out *chan-< int, prime int) { func Filter(in *<-chan int, out *chan<- int, prime int) {
for { for {
i := <-in // Receive value of new variable 'i' from 'in'. i := <-in // Receive value of new variable 'i' from 'in'.
if i % prime != 0 { if i % prime != 0 {
out -< i // Send 'i' to channel 'out'. out <- i // Send 'i' to channel 'out'.
} }
} }
} }
// The prime sieve: Daisy-chain Filter processes together. // The prime sieve: Daisy-chain Filter processes together.
func Sieve(primes *chan-< int) { func Sieve(primes *chan<- int) {
ch := new(chan int); // Create a new channel. ch := new(chan int); // Create a new channel.
go Generate(ch); // Start Generate() as a subprocess. go Generate(ch); // Start Generate() as a subprocess.
for { for {
prime := <-ch; prime := <-ch;
primes -< prime; primes <- prime;
ch1 := new(chan int); ch1 := new(chan int);
go Filter(ch, ch1, prime); go Filter(ch, ch1, prime);
ch = ch1 ch = ch1
...@@ -43,30 +43,9 @@ func Sieve(primes *chan-< int) { ...@@ -43,30 +43,9 @@ 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) } a := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
if <-primes != 3 { panic(3) } for i := 0; i < len(a); i++ {
if <-primes != 5 { panic(5) } if <-primes != a[i] { panic(a[i])}
if <-primes != 7 { panic(7) } }
if <-primes != 11 { panic(11) }
if <-primes != 13 { panic(13) }
if <-primes != 17 { panic(17) }
if <-primes != 19 { panic(19) }
if <-primes != 23 { panic(23) }
if <-primes != 29 { panic(29) }
if <-primes != 31 { panic(31) }
if <-primes != 37 { panic(37) }
if <-primes != 41 { panic(41) }
if <-primes != 43 { panic(43) }
if <-primes != 47 { panic(47) }
if <-primes != 53 { panic(53) }
if <-primes != 59 { panic(59) }
if <-primes != 61 { panic(61) }
if <-primes != 67 { panic(67) }
if <-primes != 71 { panic(71) }
if <-primes != 73 { panic(73) }
if <-primes != 79 { panic(79) }
if <-primes != 83 { panic(83) }
if <-primes != 89 { panic(89) }
if <-primes != 97 { panic(97) }
sys.exit(0); sys.exit(0);
} }
...@@ -7,19 +7,19 @@ ...@@ -7,19 +7,19 @@
package main package main
// Send the sequence 2, 3, 4, ... to channel 'ch'. // Send the sequence 2, 3, 4, ... to channel 'ch'.
func Generate(ch *chan-< int) { func Generate(ch *chan<- int) {
for i := 2; ; i++ { for i := 2; ; i++ {
ch -< i // Send 'i' to channel 'ch'. ch <- i // Send 'i' to channel 'ch'.
} }
} }
// Copy the values from channel 'in' to channel 'out', // Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'. // removing those divisible by 'prime'.
func Filter(in *chan<- int, out *chan-< int, prime int) { func Filter(in *<-chan int, out *chan<- int, prime int) {
for { for {
i := <-in // Receive value of new variable 'i' from 'in'. i := <-in // Receive value of new variable 'i' from 'in'.
if i % prime != 0 { if i % prime != 0 {
out -< i // Send 'i' to channel 'out'. out <- i // Send 'i' to channel 'out'.
} }
} }
} }
......
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