From: Russ Cox Date: Fri, 19 Dec 2008 05:59:12 +0000 (-0800) Subject: new []int literal X-Git-Tag: weekly.2009-11-06~2481 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f38d2b80a4f693aab1c7d3d3750a54aad8c83e7b;p=gostls13.git new []int literal R=ken OCL=21568 CL=21568 --- diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c index a8f988b049..8460a82d78 100644 --- a/src/cmd/gc/walk.c +++ b/src/cmd/gc/walk.c @@ -3450,7 +3450,7 @@ loop: } Node* -arraylit(Node *n) +oldarraylit(Node *n) { Iter saver; Type *t; @@ -3500,6 +3500,47 @@ loop: goto loop; } +Node* +arraylit(Node *n) +{ + Iter saver; + Type *t; + Node *var, *r, *a, *nas, *nnew, *ncon; + int idx; + + t = n->type; + if(t->etype != TARRAY) + fatal("arraylit: not array"); + + if(t->bound >= 0) + fatal("arraylit: literal fixed arrays not implemented"); + + var = nod(OXXX, N, N); + tempname(var, t); + + nnew = nod(ONEW, N, N); + nnew->type = t; + + nas = nod(OAS, var, nnew); + addtop = list(addtop, nas); + + idx = 0; + r = listfirst(&saver, &n->left); + if(r != N && r->op == OEMPTY) + r = N; + while(r != N) { + // build list of var[c] = expr + a = nodintconst(idx); + a = nod(OINDEX, var, a); + a = nod(OAS, a, r); + addtop = list(addtop, a); + idx++; + r = listnext(&saver); + } + nnew->left = nodintconst(idx); + return var; +} + Node* maplit(Node *n) {