ref: 6d7e87f1599c3af33dc52d9867b60d845441f760
parent: 86176386c885b1f424d86321c06ca353842fa3b1
author: Ori Bernstein <[email protected]>
date: Tue Nov 4 20:40:35 EST 2014
Fix up pattern tree generation. We're no longer clobbering things with wildcards.
--- a/bench/runner.c
+++ b/bench/runner.c
@@ -50,7 +50,7 @@
return sec + usec;
}
-void timed_run(char *prog)
+double timed_run(char *prog)
{
double avg, m, d, x;
int i, n;
@@ -66,15 +66,19 @@
m = m + d*(x - avg);
}
printf("%s:\t%fs (σ^2: %f)\n", prog, avg, m/(n-1));
+ return avg;
}
int main(int argc, char **argv)
{
+ double tot;
int i;
printf("Running benchmarks: %d samples per binary\n", Nsamp);
+ tot = 0;
for (i = 1; i < argc; i++)
- timed_run(argv[i]);
+ tot += timed_run(argv[i]);
+ printf("total:\t%fs\n", tot);
return 0;
}
--- a/mi/match.c
+++ b/mi/match.c
@@ -98,7 +98,7 @@
if (t->any)
return t->any;
t->any = mkdtree();
- t->patexpr = pat;
+ t->any->patexpr = pat;
lappend(cap, ncap, pat);
return t->any;
}
@@ -290,17 +290,16 @@
pat = m->matchstmt.matches;
npat = m->matchstmt.nmatches;
- cap = NULL;
- ncap = 0;
-
t = mkdtree();
for (i = 0; i < npat; i++) {
+ cap = NULL;
+ ncap = 0;
leaf = addpat(t, pat[i]->match.pat, NULL, &cap, &ncap);
/* TODO: NULL is returned by unsupported patterns. */
if (!leaf)
return NULL;
if (leaf->act)
- fatal(pat[i], "pattern matched by earlier case");
+ fatal(pat[i], "pattern matched by earlier case on line %d", leaf->act->loc.line);
leaf->act = pat[i]->match.block;
leaf->cap = cap;
leaf->ncap = ncap;
@@ -314,7 +313,7 @@
{
switch (exprop(n)) {
case Ovar:
- return namestr(n);
+ return namestr(n->expr.args[0]);
case Olit:
return litstr(n->expr.args[0]->lit.littype);
case Oucon:
@@ -332,22 +331,26 @@
return "???";
}
-void dtdumpnode(Dtree *dt, FILE *f, int depth)
+void dtdumpnode(Dtree *dt, FILE *f, int depth, int iswild)
{
Node *e;
size_t i;
-
if (dt->patexpr) {
e = dt->patexpr;
- indentf(depth, "%s %s : %s\n", opstr(exprop(e)), dtnodestr(e), tystr(exprtype(e)));
- } else {
- printf("ROOT:\n");
- }
+ indentf(depth, "%s%s %s : %s\n", iswild ? "WILDCARD " : "", opstr(exprop(e)), dtnodestr(e), tystr(exprtype(e)));
+ }
+ if (dt->cap)
+ for (i = 0; i < dt->ncap; i++)
+ indentf(depth + 1, "capture %s\n", dtnodestr(dt->cap[i]));
+ if (dt->act)
+ indentf(depth + 1, "action\n");
for (i = 0; i < dt->nsub; i++)
- dtdumpnode(dt->sub[i], f, depth + 1);
+ dtdumpnode(dt->sub[i], f, depth + 1, 0);
+ if (dt->any)
+ dtdumpnode(dt->any, f, depth + 1, 1);
}
void dtdump(Dtree *dt, FILE *f)
{
- dtdumpnode(dt, f, 0);
+ dtdumpnode(dt, f, 0, 0);
}