summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-08-17 20:34:44 -0700
committerOri Bernstein <ori@eigenstate.org>2018-08-17 20:34:44 -0700
commitda1c3640344a42e464266f75c71c813181303b7e (patch)
treebc5f43ab44cbd483962395541208cab71e7096c8
parent1db9bc54f99b5489d34b7c048fe3909b0279a317 (diff)
downloadmc-da1c3640344a42e464266f75c71c813181303b7e.tar.gz
Revert "Fix overlapping match statements (thanks Mako)"
This reverts commit beab0276a94c684f938ae5ea3d2c29c3dc331386.
-rw-r--r--mi/match.c33
-rw-r--r--test/matchoverwild.myr43
-rw-r--r--test/tests2
3 files changed, 17 insertions, 61 deletions
diff --git a/mi/match.c b/mi/match.c
index 299fbee..7ae1a3b 100644
--- a/mi/match.c
+++ b/mi/match.c
@@ -16,7 +16,6 @@
typedef struct Dtree Dtree;
struct Dtree {
int id;
- int obscured;
Srcloc loc;
/* values for matching */
@@ -353,13 +352,14 @@ addwildrec(Srcloc loc, Type *ty, Dtree *start, Dtree *accept, Dtree ***end, size
for (i = 0; i < ty->nmemb; i++) {
uc = ty->udecls[i];
next = dtbytag(start, uc);
- if (!next)
- continue;
-
- if (uc->etype && addwildrec(loc, uc->etype, next, accept, end, nend))
- ret = 1;
- else
- lappend(end, nend, next);
+ if (next) {
+ if (uc->etype) {
+ if (addwildrec(loc, uc->etype, next, accept, end, nend))
+ ret = 1;
+ } else {
+ lappend(end, nend, next);
+ }
+ }
}
if (!start->any) {
start->any = accept;
@@ -399,8 +399,10 @@ addunion(Node *pat, Node *val, Dtree *start, Dtree *accept, Node ***cap, size_t
Dtree *next;
Ucon *uc;
- if (start->any)
+ if (start->any) {
lappend(end, nend, start->any);
+ return 0;
+ }
uc = finducon(tybase(exprtype(pat)), pat->expr.args[0]);
next = dtbytag(start, uc);
@@ -423,15 +425,13 @@ addunion(Node *pat, Node *val, Dtree *start, Dtree *accept, Node ***cap, size_t
lappend(&start->pat, &start->npat, tagid);
if (uc->etype) {
next = mkdtree(pat->loc, genlbl(pat->loc));
- next->obscured = (start->obscured || start->any != NULL);
lappend(&start->next, &start->nnext, next);
addpat(pat->expr.args[1], uvalue(val, uc->etype), next, accept, cap, ncap, end, nend);
} else {
- accept->obscured = (start->obscured || start->any != NULL);
lappend(&start->next, &start->nnext, accept);
lappend(end, nend, accept);
}
- return !start->obscured && start->any == NULL;
+ return 1;
}
static int
@@ -493,10 +493,12 @@ addlit(Node *pat, Node *val, Dtree *start, Dtree *accept, Node ***cap, size_t *n
if (pat->expr.args[0]->lit.littype == Lstr) {
return addstr(pat, val, start, accept, cap, ncap, end, nend);
} else {
- if (start->any)
+ /* if we already have a match, we're not adding a new node */
+ if (start->any) {
lappend(end, nend, start->any);
+ return 0;
+ }
- /* if we already have a match, we're not adding a new node */
for (i = 0; i < start->npat; i++) {
if (liteq(start->pat[i]->expr.args[0], pat->expr.args[0])) {
lappend(end, nend, start->next[i]);
@@ -509,11 +511,10 @@ addlit(Node *pat, Node *val, Dtree *start, Dtree *accept, Node ***cap, size_t *n
start->load = val;
start->nconstructors = nconstructors(exprtype(pat));
}
- accept->obscured = (start->obscured || start->any != NULL);
lappend(&start->pat, &start->npat, pat);
lappend(&start->next, &start->nnext, accept);
lappend(end, nend, accept);
- return !start->obscured && start->any == NULL;
+ return 1;
}
}
diff --git a/test/matchoverwild.myr b/test/matchoverwild.myr
deleted file mode 100644
index e34e8a1..0000000
--- a/test/matchoverwild.myr
+++ /dev/null
@@ -1,43 +0,0 @@
-use std
-
-type ast = struct
- body : op[:]
-;;
-type op = union
- `Go int
- `Set int
- `Add int
- `Mul (int, int)
- `Read
- `Write
- `Loop ast
-;;
-
-const combine = {lhs : op, rhs : op
- match (lhs, rhs)
- | (`Add x, `Add y): -> `std.Some `Add (x + y)
- | (`Go x, `Go y): -> `std.Some `Go (x + y)
- | (`Go 0, _): -> `std.Some rhs
- | (`Set x, `Add y): -> `std.Some `Set(x + y)
- | (`Add _, `Set y): -> `std.Some rhs
- | (`Add _, `Read): -> `std.Some rhs
- | (`Set _, `Read): -> `std.Some rhs
- | (`Loop _, `Loop _): -> `std.Some lhs
- | _: -> `std.None
- ;;
-}
-
-const main = {
- match combine(`Add 123, `Set 246)
- | `std.Some `Set 246:
- /* ok */
- | r:
- std.fatal("bad combine {}\n", r)
- ;;
- match combine(`Add 123, `Add 246)
- | `std.Some `Add 369:
- /* ok */
- | r:
- std.fatal("bad combine {}\n", r)
- ;;
-}
diff --git a/test/tests b/test/tests
index 4ac4fb0..1e49566 100644
--- a/test/tests
+++ b/test/tests
@@ -111,7 +111,6 @@ B sizeof E 4
B gsizeof E 5
B matchint E 84
B matchconst E 88
-B matchoverwild E 0
B matchnsconst P 'matched badchar'
B matchunion E 84
B matchtup E 42
@@ -153,7 +152,6 @@ B strjoin C
B exporttrait E 0
B local-labels E 10
B empty-struct E 21
-B empty-struct E 21
F declmismatch
F infermismatch
F usedef