summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-06-08 00:55:49 -0400
committerOri Bernstein <ori@eigenstate.org>2013-06-08 00:55:49 -0400
commitb4e37364481ba805a39e8699ce9ae0e78b85d6c0 (patch)
treec39681539ec14df4f66214a479655eacd0c98a77
parent3c9502102b2b01d6b32dad5f4f23f6f1fe736721 (diff)
downloadmc-b4e37364481ba805a39e8699ce9ae0e78b85d6c0.tar.gz
Add indexed initializer tree support.
Needed to support indexed initialization of sequence literals.
-rw-r--r--parse/dump.c5
-rw-r--r--parse/gram.y3
-rw-r--r--parse/infer.c8
-rw-r--r--parse/node.c11
-rw-r--r--parse/nodes.def1
-rw-r--r--parse/parse.h6
-rw-r--r--parse/specialize.c7
-rw-r--r--parse/use.c13
8 files changed, 53 insertions, 1 deletions
diff --git a/parse/dump.c b/parse/dump.c
index 56536b5..a4861ec 100644
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -222,6 +222,11 @@ static void outnode(Node *n, FILE *fd, int depth)
fprintf(stderr, "Nnone not a real node type!");
fprintf(fd, "Nnone\n");
break;
+ case Nidxinit:
+ fprintf(fd, "\n");
+ outnode(n->idxinit.idx, fd, depth + 1);
+ outnode(n->idxinit.init, fd, depth + 1);
+ break;
}
}
diff --git a/parse/gram.y b/parse/gram.y
index 98192e1..0dd20e0 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -638,7 +638,8 @@ structelts
{lappend(&$$.nl, &$$.nn, $3);}
;
-structelt: endlns Tdot Tident Tasn expr endlns {$$ = $5;}
+structelt: endlns Tdot Tident Tasn expr endlns
+ {$$ = mkidxinit($2->line, mkname($3->line, $3->str), $5);}
;
endlns : /* none */
diff --git a/parse/infer.c b/parse/infer.c
index 8fb783f..bef0b79 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1143,6 +1143,10 @@ static void infernode(Inferstate *st, Node *n, Type *ret, int *sawret)
inferfunc(st, n);
popstab();
break;
+ case Nidxinit:
+ infernode(st, n->idxinit.idx, NULL, NULL);
+ infernode(st, n->idxinit.init, NULL, NULL);
+ break;
case Nname:
case Nlit:
case Nuse:
@@ -1351,6 +1355,10 @@ static void typesub(Inferstate *st, Node *n)
default: break;
}
break;
+ case Nidxinit:
+ typesub(st, n->idxinit.idx);
+ typesub(st, n->idxinit.init);
+ break;
case Nname:
case Nuse:
break;
diff --git a/parse/node.c b/parse/node.c
index 8aeeefe..327582a 100644
--- a/parse/node.c
+++ b/parse/node.c
@@ -256,6 +256,17 @@ Node *mkstruct(int line, Node **vals, size_t nvals)
return n;
}
+Node *mkidxinit(int line, Node *idx, Node *init)
+{
+ Node *n;
+
+ n = mknode(line, Nidxinit);
+ n->idxinit.idx = idx;
+ n->idxinit.init = init;
+
+ return n;
+}
+
Node *mkname(int line, char *name)
{
Node *n;
diff --git a/parse/nodes.def b/parse/nodes.def
index c9c5dab..7c9c861 100644
--- a/parse/nodes.def
+++ b/parse/nodes.def
@@ -11,3 +11,4 @@ N(Nlit)
N(Nname)
N(Ndecl)
N(Nfunc)
+N(Nidxinit)
diff --git a/parse/parse.h b/parse/parse.h
index 9738601..5269280 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -222,6 +222,11 @@ struct Node {
} match;
struct {
+ Node *idx;
+ Node *init;
+ } idxinit;
+
+ struct {
Stab *scope;
size_t nstmts;
Node **stmts;
@@ -387,6 +392,7 @@ Node *mkmatchstmt(int line, Node *val, Node **matches, size_t nmatches);
Node *mkmatch(int line, Node *pat, Node *body);
Node *mkblock(int line, Stab *scope);
Node *mkintlit(int line, uvlong val);
+Node *mkidxinit(int line, Node *idx, Node *init);
Node *mkbool(int line, int val);
Node *mkint(int line, uint64_t val);
diff --git a/parse/specialize.c b/parse/specialize.c
index 1e23065..cf8039c 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -192,6 +192,9 @@ static void fixup(Node *n)
fixup(n->func.body);
popstab();
break;
+ case Nidxinit:
+ fixup(n->idxinit.idx);
+ fixup(n->idxinit.init);
case Nnone: case Nname:
break;
}
@@ -312,6 +315,10 @@ static Node *specializenode(Node *n, Htab *tsmap)
r->func.body = specializenode(n->func.body, tsmap);
popstab();
break;
+ case Nidxinit:
+ r->idxinit.idx = specializenode(n->idxinit.idx, tsmap);
+ r->idxinit.init = specializenode(n->idxinit.init, tsmap);
+ break;
case Nnone:
die("Nnone should not be seen as node type!");
break;
diff --git a/parse/use.c b/parse/use.c
index 650cf37..5f0eaa4 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -413,6 +413,10 @@ static void pickle(Node *n, FILE *fd)
pickle(n->func.args[i], fd);
pickle(n->func.body, fd);
break;
+ case Nidxinit:
+ pickle(n->idxinit.idx, fd);
+ pickle(n->idxinit.init, fd);
+ break;
case Nnone:
die("Nnone should not be seen as node type!");
break;
@@ -546,6 +550,10 @@ static Node *unpickle(FILE *fd)
n->func.body = unpickle(fd);
popstab();
break;
+ case Nidxinit:
+ n->idxinit.idx = unpickle(fd);
+ n->idxinit.init = unpickle(fd);
+ break;
case Nnone:
die("Nnone should not be seen as node type!");
break;
@@ -768,6 +776,11 @@ static void nodetag(Node *n)
for (i = 0; i < n->func.nargs; i++)
nodetag(n->func.args[i]);
nodetag(n->func.body);
+ break;
+ case Nidxinit:
+ nodetag(n->idxinit.idx);
+ nodetag(n->idxinit.init);
+ break;
case Nuse: case Nname:
break;