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