summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2013-10-21 21:37:23 -0400
committerOri Bernstein <ori@eigenstate.org>2013-10-21 21:37:23 -0400
commitc3955db0543c35b4adb822f5beca686e8c3726ef (patch)
treeafcb56c050f63de5661a63eea41b7b8970fd1527
parentf1383ff55a560228d15cf59dabba30dee3e3daeb (diff)
downloadmc-c3955db0543c35b4adb822f5beca686e8c3726ef.tar.gz
Add tests for the new match types
-rw-r--r--6/simp.c9
-rw-r--r--test/matcharray.myr13
-rw-r--r--test/matchstruct.myr24
-rw-r--r--test/tests1
4 files changed, 43 insertions, 4 deletions
diff --git a/6/simp.c b/6/simp.c
index 59513ce..03a0db6 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -502,7 +502,7 @@ static void umatch(Simp *s, Node *pat, Node *val, Type *t, Node *iftrue, Node *i
case Tyvoid: case Tybad: case Tyvalist: case Tyvar:
case Typaram: case Tyunres: case Tyname: case Ntypes:
/* Should never show up */
- case Tyslice: case Tyarray:
+ case Tyslice:
die("Unsupported type for compare");
break;
case Tybool: case Tychar: case Tybyte:
@@ -515,9 +515,10 @@ static void umatch(Simp *s, Node *pat, Node *val, Type *t, Node *iftrue, Node *i
v->expr.type = mktype(pat->line, Tybool);
cjmp(s, v, iftrue, iffalse);
break;
- /* We got lucky. The structure of tuple and struct literals is the
- * same, so long as we don't inspect the type */
- case Tystruct: case Tytuple:
+ /* We got lucky. The structure of tuple, array, and struct literals
+ * is the same, so long as we don't inspect the type, so we can
+ * share the code*/
+ case Tystruct: case Tytuple: case Tyarray:
patarg = pat->expr.args;
off = 0;
for (i = 0; i < pat->expr.nargs; i++) {
diff --git a/test/matcharray.myr b/test/matcharray.myr
new file mode 100644
index 0000000..67e8efe
--- /dev/null
+++ b/test/matcharray.myr
@@ -0,0 +1,13 @@
+use std
+
+const main = {
+ var v = [2, 40, 10]
+
+ match v
+ [x, y, 10]:
+ -> x + y
+ ;;
+ _: std.die("Wat");;
+ ;;
+ -> 0
+}
diff --git a/test/matchstruct.myr b/test/matchstruct.myr
new file mode 100644
index 0000000..38bc5e0
--- /dev/null
+++ b/test/matchstruct.myr
@@ -0,0 +1,24 @@
+use std
+
+type t = struct
+ v1 : int
+ v2 : int
+ v3 : int
+;;
+
+const main = {
+ var v : t
+
+ v.v1 = 2
+ v.v2 = 40
+ v.v3 = 10
+ match v
+ [.v1 = x,
+ .v2 = y,
+ .v3 = 10]:
+ -> x + y
+ ;;
+ _: std.die("Wat");;
+ ;;
+ -> 0
+}
diff --git a/test/tests b/test/tests
index 9bff4ca..8dcef5d 100644
--- a/test/tests
+++ b/test/tests
@@ -83,6 +83,7 @@ B matchconst E 88
B matchunion E 84
B matchtup E 42
B matchstruct E 42
+B matcharray E 42
B matchargunion E 69
B matchunion_sl P foo
B matchbind E 8