ref: c52b156adc9c7f62a06918c878db26666eafadb2
parent: 6ceec6218bd3d7040758c09233c07d2afcdb2cbe
author: Ori Bernstein <[email protected]>
date: Fri Jun 29 11:51:48 EDT 2012
Add unions as patterns.
--- a/8/simp.c
+++ b/8/simp.c
@@ -370,13 +370,15 @@
for (i = 0; i < n->matchstmt.nmatches; i++) {
m = n->matchstmt.matches[i];
+ /* check pattern */
if (exprop(m->match.pat) != Olit)
die("Unsupported non-lit pat");
cond = mkexpr(m->line, Oeq, val, m->match.pat, NULL);
-
cur = genlbl();
next = genlbl();
cjmp(s, cond, cur, next);
+
+ /* do the action if it matches */
append(s, cur);
simp(s, m->match.block);
jmp(s, end);
--- /dev/null
+++ b/test/matchunion.myr
@@ -1,0 +1,26 @@
+type u = union
+ `Foo
+ `Bar
+ `Baz
+ `Quuz
+;;
+
+const main = {
+ var v
+
+ v = `Foo
+ match v
+ `Bar:
+ -> 42
+ ;;
+ `Baz;
+ -> 81
+ ;;
+ `Foo:
+ -> 84
+ ;;
+ `Quux:
+ -> 123
+ ;;
+ ;;
+}
--- a/test/tests
+++ b/test/tests
@@ -41,6 +41,7 @@
B gsizeof E 5
B mkunion E 0
B matchint E 84
+B matchunion E 84
F declmismatch
F infermismatch
F flow