ref: 994b042eac3300dd62bbbc7dedbb6d9a0b525638
parent: 64a7a7346e02999cf451ee45220b86ba7c69c56f
author: Ori Bernstein <[email protected]>
date: Mon Dec 14 19:11:44 EST 2015
More fixes to void values. We now unbreak varargs, and compare them correctly.
--- a/6/isel.c
+++ b/6/isel.c
@@ -949,8 +949,10 @@
g(s, Imov, a, l, NULL);
htput(s->reglocs, arg, l);
nints++;
- } else {
- assert(tybase(decltype(arg))->type == Tyvoid);
+ } else if (tybase(decltype(arg))->type != Tyvoid) {
+ /* varargs go on the stack */
+ htput(s->stkoff, arg, itop(-(argoff + 2*Ptrsz)));
+ argoff += size(arg);
}
}
}
--- a/6/simp.c
+++ b/6/simp.c
@@ -963,6 +963,9 @@
t = lval(s, lhs);
u = rval(s, rhs, t);
+ if (tybase(exprtype(lhs))->type == Tyvoid)
+ return u;
+
/* hack: we're assigning to lhs, but blitting shit over doesn't
* trigger that */
if (stacknode(lhs))
@@ -1150,6 +1153,10 @@
Node *r;
Op newop;
+ /* void is always void */
+ if (tybase(exprtype(n->expr.args[0]))->type == Tyvoid)
+ return mkboollit(n->loc, 1);
+
newop = Obad;
if (istysigned(tybase(exprtype(n->expr.args[0]))))
newop = cmpmap[n->expr.op][0];
@@ -1509,7 +1516,7 @@
break;
case Ovar:
r = loadvar(s, n, dst);
- break;
+ break;;
case Oidxlen:
if (s->nidxctx == 0)
fatal(n, "'$' undefined outside of index or slice expression");
@@ -1540,12 +1547,7 @@
append(s, mkexpr(n->loc, Oret, NULL));
break;
case Oasn:
- if (tybase(exprtype(n))->type == Tyvoid) {
- if (!ispure(args[1]))
- r = rval(s, args[1], NULL);
- } else {
- r = assign(s, args[0], args[1]);
- }
+ r = assign(s, args[0], args[1]);
break;
case Ocall:
r = simpcall(s, n, dst);
--- a/parse/node.c
+++ b/parse/node.c
@@ -221,8 +221,6 @@
return n;
}
-Node *mkintlit(Srcloc loc, uvlong val) { return mkexpr(loc, Olit, mkint(loc, val), NULL); }
-
Node *mklbl(Srcloc loc, char *lbl)
{
Node *n;
@@ -273,6 +271,10 @@
return n;
}
+Node *mkintlit(Srcloc loc, uvlong val) {
+ return mkexpr(loc, Olit, mkint(loc, val), NULL);
+}
+
Node *mkchar(Srcloc loc, uint32_t val)
{
Node *n;
@@ -372,6 +374,14 @@
n->lit.boolval = val;
return n;
+}
+
+Node *mkboollit(Srcloc loc, int val) {
+ Node *e;
+
+ e = mkexpr(loc, Olit, mkbool(loc, val), NULL);
+ e->expr.type = mktype(loc, Tybool);
+ return e;
}
Node *mkvoid(Srcloc loc)
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -561,6 +561,7 @@
Node *mkblock(Srcloc l, Stab *scope);
Node *mkimplstmt(Srcloc l, Node *name, Type *type, Node **impls, size_t nimpls);
Node *mkintlit(Srcloc l, uvlong val);
+Node *mkboollit(Srcloc l, int val);
Node *mkidxinit(Srcloc l, Node *idx, Node *init);
Node *mkvoid(Srcloc loc);
--- a/test/tests
+++ b/test/tests
@@ -56,6 +56,7 @@
B doublecall P 42,33
B voidcall E 12
B voidarg P 3
+B voidassign P ok
B callbig E 42
B nestfn E 42
B foldidx P 123,456