ref: a7ae86f6a9874e7fd38c36fe31cef8e7d52268db
parent: 184ef03517e984d9e9293ecaae60f8785ee73274
author: Ori Bernstein <[email protected]>
date: Fri Jun 29 06:39:54 EDT 2012
Add in node types for match and match patterns.
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -134,10 +134,22 @@
outnode(n->ifstmt.iffalse, fd, depth+1);
break;
case Nloopstmt:
+ fprintf(fd, "\n");
outnode(n->loopstmt.init, fd, depth+1);
outnode(n->loopstmt.cond, fd, depth+1);
outnode(n->loopstmt.step, fd, depth+1);
outnode(n->loopstmt.body, fd, depth+1);
+ break;
+ case Nmatchstmt:
+ fprintf(fd, "\n");
+ outnode(n->matchstmt.val, fd, depth+1);
+ for (i = 0; i < n->matchstmt.nmatches; i++)
+ outnode(n->matchstmt.matches[i], fd, depth+1);
+ break;
+ case Nmatch:
+ fprintf(fd, "\n");
+ outnode(n->match.pat, fd, depth+1);
+ outnode(n->match.block, fd, depth+1);
break;
case Nuse:
fprintf(fd, " (name = %s, islocal = %d)\n", n->use.name, n->use.islocal);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -685,6 +685,14 @@
infernode(n->loopstmt.body, ret, sawret);
constrain(n, type(n->loopstmt.cond), cstrtab[Tctest]);
break;
+ case Nmatchstmt:
+ infernode(n->matchstmt.val, NULL, sawret);
+ for (i = 0; i < n->matchstmt.nmatches; i++)
+ infernode(n->matchstmt.matches[i], NULL, sawret);
+ case Nmatch:
+ infernode(n->match.pat, NULL, sawret);
+ infernode(n->match.block, ret, sawret);
+ break;
case Nexpr:
inferexpr(n, ret, sawret);
break;
@@ -856,6 +864,13 @@
typesub(n->loopstmt.step);
typesub(n->loopstmt.body);
break;
+ case Nmatchstmt:
+ typesub(n->matchstmt.val);
+ for (i = 0; i < n->matchstmt.nmatches; i++)
+ typesub(n->matchstmt.matches[i]);
+ case Nmatch:
+ typesub(n->match.pat);
+ typesub(n->match.block);
case Nexpr:
settype(n, tyfix(n, type(n)));
for (i = 0; i < n->expr.nargs; i++)
--- a/parse/nodes.def
+++ b/parse/nodes.def
@@ -3,6 +3,8 @@
N(Nblock)
N(Nifstmt)
N(Nloopstmt)
+N(Nmatchstmt)
+N(Nmatch)
N(Nuse)
N(Nexpr)
N(Nlit)
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -184,6 +184,17 @@
} ifstmt;
struct {
+ Node *val;
+ Node **matches;
+ size_t nmatches;
+ } matchstmt;
+
+ struct {
+ Node *pat; /* literal expr. FIXME: this isn't an appropriate type */
+ Node *block;
+ } match;
+
+ struct {
Stab *scope;
size_t nstmts;
Node **stmts;
--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -320,6 +320,16 @@
pickle(n->loopstmt.step, fd);
pickle(n->loopstmt.body, fd);
break;
+ case Nmatchstmt:
+ pickle(n->matchstmt.val, fd);
+ wrint(fd, n->matchstmt.nmatches);
+ for (i = 0; i < n->matchstmt.nmatches; i++)
+ pickle(n->matchstmt.matches[i], fd);
+ break;
+ case Nmatch:
+ pickle(n->match.pat, fd);
+ pickle(n->match.block, fd);
+ break;
case Nifstmt:
pickle(n->ifstmt.cond, fd);
pickle(n->ifstmt.iftrue, fd);
@@ -422,6 +432,16 @@
n->loopstmt.cond = unpickle(fd);
n->loopstmt.step = unpickle(fd);
n->loopstmt.body = unpickle(fd);
+ break;
+ case Nmatchstmt:
+ n->matchstmt.val = unpickle(fd);
+ n->matchstmt.nmatches = rdint(fd);
+ for (i = 0; i < n->matchstmt.nmatches; i++)
+ n->matchstmt.matches[i] = unpickle(fd);
+ break;
+ case Nmatch:
+ n->match.pat = unpickle(fd);
+ n->match.block = unpickle(fd);
break;
case Nifstmt:
n->ifstmt.cond = unpickle(fd);
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -107,6 +107,11 @@
break;
}
break;
+ case Nifstmt:
+ fixup(n->ifstmt.cond);
+ fixup(n->ifstmt.iftrue);
+ fixup(n->ifstmt.iffalse);
+ break;
case Nloopstmt:
fixup(n->loopstmt.init);
fixup(n->loopstmt.cond);
@@ -113,10 +118,13 @@
fixup(n->loopstmt.step);
fixup(n->loopstmt.body);
break;
- case Nifstmt:
- fixup(n->ifstmt.cond);
- fixup(n->ifstmt.iftrue);
- fixup(n->ifstmt.iffalse);
+ case Nmatchstmt:
+ fixup(n->matchstmt.val);
+ for (i = 0; i < n->matchstmt.nmatches; i++)
+ fixup(n->matchstmt.matches[i]);
+ case Nmatch:
+ fixup(n->match.pat);
+ fixup(n->match.block);
break;
case Nblock:
pushstab(n->block.scope);
@@ -177,6 +185,11 @@
case Larray: r->lit.arrval = specializenode(n->lit.arrval, tsmap); break;
}
break;
+ case Nifstmt:
+ r->ifstmt.cond = specializenode(n->ifstmt.cond, tsmap);
+ r->ifstmt.iftrue = specializenode(n->ifstmt.iftrue, tsmap);
+ r->ifstmt.iffalse = specializenode(n->ifstmt.iffalse, tsmap);
+ break;
case Nloopstmt:
r->loopstmt.init = specializenode(n->loopstmt.init, tsmap);
r->loopstmt.cond = specializenode(n->loopstmt.cond, tsmap);
@@ -183,10 +196,16 @@
r->loopstmt.step = specializenode(n->loopstmt.step, tsmap);
r->loopstmt.body = specializenode(n->loopstmt.body, tsmap);
break;
- case Nifstmt:
- r->ifstmt.cond = specializenode(n->ifstmt.cond, tsmap);
- r->ifstmt.iftrue = specializenode(n->ifstmt.iftrue, tsmap);
- r->ifstmt.iffalse = specializenode(n->ifstmt.iffalse, tsmap);
+ case Nmatchstmt:
+ r->matchstmt.val = specializenode(n->matchstmt.val, tsmap);
+ r->matchstmt.nmatches = n->matchstmt.nmatches;
+ r->matchstmt.matches = xalloc(n->matchstmt.nmatches * sizeof(Node*));
+ for (i = 0; i < n->matchstmt.nmatches; i++)
+ r->matchstmt.matches[i] = specializenode(n->matchstmt.matches[i], tsmap);
+ break;
+ case Nmatch:
+ r->match.pat = specializenode(n->match.pat, tsmap);
+ r->match.block = specializenode(n->match.block, tsmap);
break;
case Nblock:
r->block.scope = mkstab();