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