summaryrefslogtreecommitdiff
path: root/parse/infer.c
diff options
context:
space:
mode:
authormural <mura@ctli.io>2020-04-15 22:38:24 +0800
committerOri Bernstein <ori@eigenstate.org>2020-05-05 20:33:19 -0700
commit321aec6bf2b82698196a94725e37cee135b1fe2b (patch)
tree83aade6691594d565e78691fdd29a883478f05f0 /parse/infer.c
parent4a6a372ad70eb3bde6f0fa6bac7760383b6f6ea8 (diff)
downloadmc-321aec6bf2b82698196a94725e37cee135b1fe2b.tar.gz
Support or-pattern
Diffstat (limited to 'parse/infer.c')
-rw-r--r--parse/infer.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/parse/infer.c b/parse/infer.c
index 0053c19..5150621 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1531,16 +1531,20 @@ inferpat(Node **np, Node *val, Node ***bind, size_t *nbind)
n = *np;
n = checkns(n, np);
+ n->expr.ispat = 1;
args = n->expr.args;
for (i = 0; i < n->expr.nargs; i++)
- if (args[i]->type == Nexpr)
+ if (args[i]->type == Nexpr) {
+ args[i]->expr.ispat = 1;
inferpat(&args[i], val, bind, nbind);
+ }
switch (exprop(n)) {
case Otup:
case Ostruct:
case Oarr:
case Olit:
case Omemb:
+ case Olor:
infernode(np, NULL, NULL);
break;
/* arithmetic expressions just need to be constant */
@@ -1700,6 +1704,7 @@ inferexpr(Node **np, Type *ret, int *sawret)
case Obsreq: /* @a >>= @a -> @a */
infersub(n, ret, sawret, &isconst);
t = type(args[0]);
+
constrain(n, t, traittab[Tcnum]);
constrain(n, t, traittab[Tcint]);
isconst = args[0]->expr.isconst;
@@ -1722,6 +1727,15 @@ inferexpr(Node **np, Type *ret, int *sawret)
/* operands same type, returning bool */
case Olor: /* @a || @b -> bool */
+ if (n->expr.ispat) {
+ infersub(n, ret, sawret, &isconst);
+ t = type(args[0]);
+ for (i = 1; i < nargs; i++)
+ t = unify(n, t, type(args[i]));
+ n->expr.isconst = isconst;
+ settype(n, t);
+ break;
+ }
case Oland: /* @a && @b -> bool */
case Oeq: /* @a == @a -> bool */
case One: /* @a != @a -> bool */