summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/gc/walk.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index a8f988b04..8460a82d7 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;
@@ -3501,6 +3501,47 @@ 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)
{
Iter saver;