ref: b7198a182264b7ef24dd1d03baca4c275361748b
parent: 5196e4c16239a9f593c4efa14819b70721006740
author: Ori Bernstein <[email protected]>
date: Fri Aug 17 21:32:17 EDT 2012
Change 'cons' to 'ucon', add uget. Makes it clearer what operators act on unions.
--- a/6/isel.c
+++ b/6/isel.c
@@ -596,7 +596,7 @@
case Osubeq: case Omuleq: case Odiveq: case Omodeq: case Oboreq:
case Obandeq: case Obxoreq: case Obsleq: case Obsreq: case Omemb:
case Oslice: case Oidx: case Osize: case Numops:
- case Ocons: case Otup: case Oarr:
+ case Oucon: case Ouget: case Otup: case Oarr:
case Oslbase: case Osllen: case Ocast:
dump(n, stdout);
die("Should not see %s in isel", opstr(exprop(n)));
--- a/6/simp.c
+++ b/6/simp.c
@@ -411,7 +411,7 @@
Ucon *uc;
t = tybase(n->expr.type);
- if (exprop(n) != Ocons)
+ if (exprop(n) != Oucon)
return NULL;
for (i = 0; i < t->nmemb; i++) {
uc = t->udecls[i];
@@ -426,7 +426,7 @@
{
Ucon *uc;
- if (exprop(n) != Ocons)
+ if (exprop(n) != Oucon)
return load(addk(addr(n, mktype(n->line, Tyuint)), off));
uc = finducon(n);
@@ -435,7 +435,7 @@
static Node *uval(Node *n, size_t off, Type *t)
{
- if (exprop(n) == Ocons)
+ if (exprop(n) == Oucon)
return n->expr.args[1];
else if (exprop(n) == Olit)
return n;
@@ -940,6 +940,11 @@
return tmp;
}
+static Node *simpuget(Simp *s, Node *n, Node *dst)
+{
+ die("No uget simplification yet");
+}
+
/* simplifies
* a || b
* to
@@ -1036,8 +1041,11 @@
r = load(t);
}
break;
- case Ocons:
+ case Oucon:
r = simpucon(s, n, dst);
+ break;
+ case Ouget:
+ r = simpuget(s, n, dst);
break;
case Otup:
r = simptup(s, n, dst);
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -447,9 +447,9 @@
unionexpr
: Ttick name borexpr
- {$$ = mkexpr($1->line, Ocons, $2, $3, NULL);}
+ {$$ = mkexpr($1->line, Oucon, $2, $3, NULL);}
| Ttick name
- {$$ = mkexpr($1->line, Ocons, $2, NULL);}
+ {$$ = mkexpr($1->line, Oucon, $2, NULL);}
| borexpr
;
@@ -659,9 +659,9 @@
;
unionpat: Ttick Tident pat
- {$$ = mkexpr($1->line, Ocons, mkname($2->line, $2->str), $3, NULL);}
+ {$$ = mkexpr($1->line, Oucon, mkname($2->line, $2->str), $3, NULL);}
| Ttick Tident
- {$$ = mkexpr($1->line, Ocons, mkname($2->line, $2->str), NULL);}
+ {$$ = mkexpr($1->line, Oucon, mkname($2->line, $2->str), NULL);}
;
block : body Tendblk
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -675,7 +675,7 @@
if (args[i]->type == Nexpr)
inferpat(st, args[i], bind, nbind);
switch (exprop(n)) {
- case Ocons:
+ case Oucon:
uc = uconresolve(st, n);
if (uc->etype)
unify(st, n, uc->etype, type(st, args[1]));
@@ -868,7 +868,7 @@
lappend(&st->genericdecls, &st->ngenericdecls, s);
}
break;
- case Ocons:
+ case Oucon:
uc = uconresolve(st, n);
if (uc->etype)
unify(st, n, uc->etype, type(st, args[1]));
@@ -899,6 +899,7 @@
case Oslbase: case Osllen:
case Oblit: case Numops:
case Otrunc: case Oswiden: case Ozwiden:
+ case Ouget:
die("Should not see %s in fe", opstr(exprop(n)));
break;
}
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -1,3 +1,4 @@
+/* operator name, is it pure */
O(Obad, 1)
O(Oadd, 1)
O(Osub, 1)
@@ -48,7 +49,8 @@
O(Ovar, 1)
O(Olit, 1)
O(Olbl, 1)
-O(Ocons, 1)
+O(Oucon, 1)
+O(Ouget, 1)
O(Otup, 1)
O(Oarr, 1)
/* backend-only */