Commit 949ab5c7 authored by Ken Thompson's avatar Ken Thompson

select

R=r
APPROVED=r
DELTA=41  (24 added, 13 deleted, 4 changed)
OCL=13480
CL=13480
parent e963cba8
......@@ -20,6 +20,23 @@ walk(Node *fn)
dump("fn", fn->nbody);
}
int
isselect(Node *n)
{
Sym *s;
if(n == N)
return 0;
n = n->left;
s = pkglookup("selectsend", "sys");
if(s == n->sym)
return 1;
s = pkglookup("selectrecv", "sys");
if(s == n->sym)
return 1;
return 0;
}
void
walktype(Node *n, int top)
{
......@@ -227,16 +244,20 @@ loop:
case OCALL:
l = ascompatte(n->op, getinarg(t), &n->right, 0);
n->right = reorder1(l);
if(isselect(n)) {
// clear output bool - special prob with selectsend
r = ascompatte(n->op, getoutarg(t), &boolfalse, 0);
n->right = list(n->right, r);
}
break;
case OCALLMETH:
l = ascompatte(n->op, getinarg(t), &n->right, 0);
r = ascompatte(n->op, getthis(t), &n->left->left, 0);
if(l != N)
r = list(r, l);
l = list(r, l);
n->left->left = N;
ullmancalc(n->left);
n->right = reorder1(r);
n->right = reorder1(l);
break;
}
goto ret;
......@@ -919,6 +940,7 @@ selcase(Node *n, Node *var)
{
Node *a, *r, *on, *c;
Type *t;
Iter iter;
c = n->left;
if(c->op == ORECV)
......@@ -949,11 +971,7 @@ selcase(Node *n, Node *var)
a = var; // sel-var
r = list(a, r);
a = nod(OCALL, on, r);
r = nod(OIF, N, N);
r->ntest = a;
return r;
goto out;
recv:
walktype(c->left, Elv); // elem
......@@ -982,12 +1000,12 @@ recv:
a = var; // sel-var
r = list(a, r);
out:
a = nod(OCALL, on, r);
r = nod(OIF, N, N);
r->ntest = a;
return r;
}
void
......
......@@ -377,7 +377,7 @@ sys·selectsend(Select *sel, Hchan *c, ...)
{
int32 i, eo;
Scase *cas;
byte *as, *ae;
byte *ae;
// nil cases do not compete
if(c == nil)
......@@ -400,9 +400,6 @@ sys·selectsend(Select *sel, Hchan *c, ...)
ae = (byte*)&sel + eo;
c->elemalg->copy(c->elemsize, cas->u.elem, ae);
as = (byte*)&sel + cas->so;
*as = false;
if(debug) {
prints("newselect s=");
sys·printpointer(sel);
......@@ -424,7 +421,6 @@ sys·selectrecv(Select *sel, Hchan *c, ...)
{
int32 i, epo;
Scase *cas;
byte *as;
// nil cases do not compete
if(c == nil)
......@@ -445,9 +441,6 @@ sys·selectrecv(Select *sel, Hchan *c, ...)
cas->send = 0;
cas->u.elemp = *(byte**)((byte*)&sel + epo);
as = (byte*)&sel + cas->so;
*as = false;
if(debug) {
prints("newselect s=");
sys·printpointer(sel);
......
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