]> Cypherpunks repositories - gostls13.git/commitdiff
new []int literal
authorRuss Cox <rsc@golang.org>
Fri, 19 Dec 2008 05:59:12 +0000 (21:59 -0800)
committerRuss Cox <rsc@golang.org>
Fri, 19 Dec 2008 05:59:12 +0000 (21:59 -0800)
R=ken
OCL=21568
CL=21568

src/cmd/gc/walk.c

index a8f988b049933b2f46acd897f006c1a07abb938b..8460a82d782b41b601396f0994f8c81288396189 100644 (file)
@@ -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)
 {