Commit 97cab903 authored by Ken Thompson's avatar Ken Thompson

chan

SVN=126959
parent 594175d0
......@@ -1364,6 +1364,7 @@ deep(Type *t)
case TPTR32:
case TPTR64:
case TCHAN:
nt = shallow(t);
nt->type = deep(t->type);
break;
......
......@@ -1700,12 +1700,16 @@ chanop(Node *n, int top)
break;
case OAS:
// chansend(hchan *chan any, elem any);
cl = listcount(n->left);
cr = listcount(n->right);
//dump("assign1", n);
if(n->left->op != OSEND)
if(cl == 2 && cr == 1 && n->right->op == ORECV)
goto recv2;
if(cl != 1 || cr != 1 || n->left->op != OSEND)
goto shape;
// chansend(hchan *chan any, elem any);
t = fixchan(n->left->left->type);
if(t == T)
break;
......@@ -1716,14 +1720,54 @@ chanop(Node *n, int top)
r = nod(OLIST, a, r);
on = syslook("chansend", 1);
print("type=%lT\n", t);
print("on=%lT\n", on->type);
argtype(on, t->type); // any-1
print("on=%lT\n", on->type);
argtype(on, t->type); // any-2
print("on=%lT\n", on->type);
r = nod(OCALL, on, r);
walktype(r, Erv);
break;
case ORECV:
// chanrecv1(hchan *chan any) (elem any);
t = fixchan(n->left->type);
if(t == T)
break;
a = n->left; // chan
r = a;
on = syslook("chanrecv1", 1);
argtype(on, t->type); // any-1
argtype(on, t->type); // any-2
r = nod(OCALL, on, r);
walktype(r, Erv);
break;
recv2:
// chanrecv2(hchan *chan any) (elem any, pres bool);
t = fixchan(n->right->left->type);
if(t == T)
break;
a = n->right->left; // chan
r = a;
on = syslook("chanrecv2", 1);
argtype(on, t->type); // any-1
argtype(on, t->type); // any-2
r = nod(OCALL, on, r);
n->right = r;
r = n;
walktype(r, Etop);
break;
}
return r;
......@@ -1950,6 +1994,18 @@ multi:
a = old2new(nl->right, types[TBOOL]);
n = nod(OLIST, n, a);
break;
case ORECV:
if(cl != 2)
goto badt;
walktype(nr->left, Erv);
t = nr->left->type;
if(!isptrto(t, TCHAN))
goto badt;
a = old2new(nl->left, t->type->type);
n = a;
a = old2new(nl->right, types[TBOOL]);
n = nod(OLIST, n, a);
}
n = rev(n);
return n;
......
......@@ -73,3 +73,31 @@ sys·chansend(Hchan* c, ...)
prints("\n");
}
}
// chanrecv1(hchan *chan any) (elem any);
void
sys·chanrecv1(Hchan* c, ...)
{
byte *ae;
ae = (byte*)&c + c->eo;
if(debug) {
prints("chanrecv1: chan=");
sys·printpointer(c);
prints("\n");
}
}
// chanrecv2(hchan *chan any) (elem any, pres bool);
void
sys·chanrecv2(Hchan* c, ...)
{
byte *ae;
ae = (byte*)&c + c->eo;
if(debug) {
prints("chanrecv2: chan=");
sys·printpointer(c);
prints("\n");
}
}
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