diff options
author | Ori Bernstein <ori@eigenstate.org> | 2018-01-21 16:47:19 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2018-01-21 23:41:40 -0800 |
commit | cd3218bd460b20238d67eea3c4518c8b47a41285 (patch) | |
tree | 0d6e3fafc024724b85d60867e894a44e2fd31e93 /mi | |
parent | 720cc29f19477550800adf5539837fec15296bbc (diff) | |
download | mc-cd3218bd460b20238d67eea3c4518c8b47a41285.tar.gz |
Allow using the '==' operator on enum-style union.
Diffstat (limited to 'mi')
-rw-r--r-- | mi/flatten.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/mi/flatten.c b/mi/flatten.c index 03f3df1..5582af9 100644 --- a/mi/flatten.c +++ b/mi/flatten.c @@ -351,7 +351,22 @@ destructure(Flattenctx *s, Node *lhs, Node *rhs) static Node * comparecomplex(Flattenctx *s, Node *n, Op op) { - fatal(n, "Complex comparisons not yet supported\n"); + Type *ty; + Node *l, *r, *e; + + /* special case: unions with nullary constructors can be compared easily. */ + ty = tybase(exprtype(n->expr.args[0])); + if (ty->type == Tyunion && isenum(ty)) { + l = mkexpr(n->loc, Outag, rval(s, n->expr.args[0]), NULL); + r = mkexpr(n->loc, Outag, rval(s, n->expr.args[1]), NULL); + l->expr.type = mktype(n->loc, Tyuint32); + r->expr.type = mktype(n->loc, Tyuint32); + e = mkexpr(n->loc, Oueq, l, r, NULL); + e->expr.type = mktype(n->loc, Tybool); + return e; + } + fatal(n, "cannot compare values of type %s for equality\n", + tystr(exprtype(n->expr.args[0])); return NULL; } |