ref: f5a1454387098fa3abb7bf95f4123e1fac85cb7d
parent: 607b2662bc1093833bfea0c49236f098271cf348
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Dec 14 18:27:06 EST 2015
Initial support for void as an expression.
--- a/6/blob.c
+++ b/6/blob.c
@@ -134,6 +134,7 @@
assert(v->type == Nlit);
sz = tysize(ty);
switch (v->lit.littype) {
+ case Lvoid: break;
case Lint: b(seq, mkblobi(intsz[sz], v->lit.intval)); break;
case Lbool: b(seq, mkblobi(Bti8, v->lit.boolval)); break;
case Lchr: b(seq, mkblobi(Bti32, v->lit.chrval)); break;
--- a/6/isel.c
+++ b/6/isel.c
@@ -133,6 +133,7 @@
case Olit:
v = n->expr.args[0];
switch (v->lit.littype) {
+ case Lvoid: l = NULL; break;
case Lchr: l = loclit(v->lit.chrval, mode(n)); break;
case Lbool: l = loclit(v->lit.boolval, mode(n)); break;
case Lint: l = loclit(v->lit.intval, mode(n)); break;
--- a/6/simp.c
+++ b/6/simp.c
@@ -1328,6 +1328,8 @@
for (i = 1; i < n->expr.nargs; i++) {
if (i < ft->nsub && tybase(ft->sub[i])->type == Tyvalist)
lappend(&args, &nargs, vatypeinfo(s, n));
+ if (tybase(exprtype(n->expr.args[i]))->type == Tyvoid)
+ continue;
lappend(&args, &nargs, rval(s, n->expr.args[i], NULL));
if (exprop(n->expr.args[i]) == Oaddr)
if (exprop(n->expr.args[i]->expr.args[0]) == Ovar)
@@ -1483,7 +1485,10 @@
break;
case Olit:
switch (args[0]->lit.littype) {
- case Lchr: case Lbool: case Llbl:
+ case Lvoid:
+ case Lchr:
+ case Lbool:
+ case Llbl:
r = n;
break;
case Lint:
@@ -1535,7 +1540,8 @@
append(s, mkexpr(n->loc, Oret, NULL));
break;
case Oasn:
- r = assign(s, args[0], args[1]);
+ if (tybase(exprtype(n))->type != Tyvoid)
+ r = assign(s, args[0], args[1]);
break;
case Ocall:
r = simpcall(s, n, dst);
--- a/lib/cryptohash/md5.myr
+++ b/lib/cryptohash/md5.myr
@@ -45,7 +45,7 @@
std.slcp(st.tail[ntail:ntail + n], data[:n])
data = data[n:]
if n + ntail < 64
- ->
+ -> void
;;
step(st, st.tail[:])
;;
--- a/lib/cryptohash/sha1.myr
+++ b/lib/cryptohash/sha1.myr
@@ -46,7 +46,7 @@
std.slcp(st.tail[ntail:ntail + n], data[:n])
data = data[n:]
if n + ntail < 64
- ->
+ -> void
;;
step(st, st.tail[:])
;;
--- a/lib/cryptohash/sha256.myr
+++ b/lib/cryptohash/sha256.myr
@@ -51,7 +51,7 @@
std.slcp(st.tail[ntail:ntail + n], data[:n])
data = data[n:]
if n + ntail < 64
- ->
+ -> void
;;
step(st.x[:], st.tail[:])
;;
@@ -117,7 +117,7 @@
std.slcp(st.tail[ntail:ntail + n], data[:n])
data = data[n:]
if n + ntail < 64
- ->
+ -> void
;;
step(st.x[:], st.tail[:])
;;
--- a/lib/cryptohash/sha512.myr
+++ b/lib/cryptohash/sha512.myr
@@ -58,7 +58,7 @@
std.slcp(st.tail[ntail:ntail+n], data[:n])
data = data[n:]
if n + ntail < 128
- ->
+ -> void
;;
step(st.x[:], st.tail[:])
;;
@@ -118,7 +118,7 @@
std.slcp(st.tail[ntail:ntail+n], data[:n])
data = data[n:]
if n + ntail < 128
- ->
+ -> void
;;
step(st.x[:], st.tail[:])
;;
--- a/lib/regex/compile.myr
+++ b/lib/regex/compile.myr
@@ -189,7 +189,7 @@
std.assert(lo.len == hi.len, "range sizes differ")
if lo.len == 0
rt.end = true
- ->
+ -> void
;;
n = rt.ranges.len
@@ -362,7 +362,7 @@
/* instruction dump */
const idump = {re
if !re.debug
- ->
+ -> void
;;
for var i = 0; i < re.proglen; i++
std.put("{}:\t", i)
@@ -394,7 +394,7 @@
/* AST dump */
const dump = {re, t, indent
if !re.debug
- ->
+ -> void
;;
for var i = 0; i < indent; i++
std.put(" ")
--- a/lib/regex/interp.myr
+++ b/lib/regex/interp.myr
@@ -229,7 +229,7 @@
var thr
if ip == curip /* loop detection */
- ->
+ -> void
;;
thr = mkthread(re, ip)
thr.next = re.runq
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -150,7 +150,7 @@
var head
if sl.len == 0
- ->
+ -> void
;;
checkhdr(sl castto(byte#))
--- a/lib/std/memops-impl.myr
+++ b/lib/std/memops-impl.myr
@@ -16,7 +16,7 @@
s = src[:len]
if da == sa
- ->
+ -> void
elif da < sa
for var i = 0; i < d.len; i++
d[i] = s[i]
--- a/lib/std/resolve+posixy.myr
+++ b/lib/std/resolve+posixy.myr
@@ -94,7 +94,7 @@
match slurp(Hostfile)
| `Ok d: h = d
- | `Fail m: ->
+ | `Fail m: -> void
;;
lines = strsplit(h, "\n")
@@ -147,7 +147,7 @@
]
htput(hostmap, sldup(name), hinf)
| `None:
- ->
+ -> void
;;
;;
}
@@ -158,7 +158,7 @@
match slurp(Resolvfile)
| `Ok d: h = d
- | `Fail m: ->
+ | `Fail m: -> void
;;
lines = strsplit(h, "\n")
--- a/lib/std/sort.myr
+++ b/lib/std/sort.myr
@@ -54,7 +54,7 @@
sl[s] = tmp
r = s
else
- ->
+ -> void
;;
;;
}
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -66,7 +66,7 @@
const addeps = {b, targ, depset
if std.hthas(depset, targ)
- ->
+ -> void
;;
std.htput(depset, targ, true)
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -121,7 +121,7 @@
var keys
if !opt_debug
- ->
+ -> void
;;
keys = std.htkeys(dg.deps)
std.put("digraph dg {{\n")
@@ -137,7 +137,7 @@
var deps
if std.hthas(g.done, path)
- ->
+ -> void
;;
ds.depstk = std.slpush(ds.depstk, path)
@@ -185,7 +185,7 @@
if opt_debug
std.put("already loaded deps for {}\n", usefile)
;;
- ->
+ -> void
;;
match std.htget(g.input, usefile)
| `std.Some path:
@@ -314,7 +314,7 @@
var done
if std.hthas(dg.libs, lib)
- ->
+ -> void
;;
f = openlib(lib, incs)
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -72,7 +72,7 @@
;;
std.slfree(tests)
if tests.len == 0
- ->
+ -> void
;;
printfailed(failed)
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -27,7 +27,7 @@
return;
for (j = 0; j < r->ndefs[did]; j++) {
t = tybase(exprtype(n));
- if (t->type == Tystruct || t->type == Tyunion || t->type == Tyarray || t->type == Tytuple)
+ if (t->type == Tystruct || t->type == Tyunion || t->type == Tyarray || t->type == Tytuple || t->type == Tyvoid)
continue;
if (bshas(kill, r->defs[did][j]))
continue;
@@ -35,7 +35,7 @@
continue;
def = nodes[r->defs[did][j]];
if (exprop(def) == Oundef)
- fatal(n, "%s used before definition [%d]", namestr(n->expr.args[0]), (int)did);
+ fatal(n, "%s used before definition", namestr(n->expr.args[0]));
}
} else {
switch (exprop(n)) {
--- a/mi/match.c
+++ b/mi/match.c
@@ -764,6 +764,7 @@
s = lblstr(dt->lbl);
switch (n->lit.littype) {
+ case Lvoid: findentf(fd, depth, "%s: Lvoid\n"); break;
case Lchr: findentf(fd, depth, "%s: Lchr %c\n", s, n->lit.chrval); break;
case Lbool: findentf(fd, depth, "%s: Lbool %s\n", s, n->lit.boolval ? "true" : "false"); break;
case Lint: findentf(fd, depth, "%s: Lint %llu\n", s, n->lit.intval); break;
--- a/mk/c.mk
+++ b/mk/c.mk
@@ -9,7 +9,7 @@
_LIBPATHS=$(addprefix -l, $(patsubst lib%.a,%,$(notdir $(DEPS)))) $(_PCLIBS)
# yeah, I should probably remove -Werror, but it's nice for developing alone.
-CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-array-bounds -g
+CFLAGS += -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-array-bounds -g
CFLAGS += -MMD -MP -MF .deps/$(subst /,-,$*).d
LIB ?= $(INSTLIB)
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -209,6 +209,7 @@
break;
case Nlit:
switch (n->lit.littype) {
+ case Lvoid: fprintf(fd, " Lvoid\n"); break;
case Lchr: fprintf(fd, " Lchr %c\n", n->lit.chrval); break;
case Lbool: fprintf(fd, " Lbool %s\n", n->lit.boolval ? "true" : "false"); break;
case Lint: fprintf(fd, " Lint %llu\n", n->lit.intval); break;
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -97,6 +97,7 @@
%token<tok> Tfloatlit
%token<tok> Tchrlit
%token<tok> Tboollit
+%token<tok> Tvoidlit
%token<tok> Ttrait /* trait */
%token<tok> Timpl /* trait */
@@ -474,10 +475,11 @@
| type Tosqbrac Tcolon Tcsqbrac {$$ = mktyslice($2->loc, $1);}
| type Tosqbrac expr Tcsqbrac {$$ = mktyarray($2->loc, $1, $3);}
| type Tosqbrac Tellipsis Tcsqbrac {$$ = mktyarray($2->loc, $1, NULL);}
- | type Tderef {$$ = mktyptr($2->loc, $1);}
- | Tat Tident {$$ = mktyparam($1->loc, $2->id);}
- | name {$$ = mktyunres($1->loc, $1, NULL, 0);}
| name Toparen typelist Tcparen {$$ = mktyunres($1->loc, $1, $3.types, $3.ntypes);}
+ | type Tderef {$$ = mktyptr($2->loc, $1);}
+ | Tat Tident {$$ = mktyparam($1->loc, $2->id);}
+ | Tvoidlit {$$ = mktyunres($1->loc, mkname($1->loc, $1->id), NULL, 0);}
+ | name {$$ = mktyunres($1->loc, $1, NULL, 0);}
;
functype: Toparen funcsig Tcparen {$$ = $2;}
@@ -748,6 +750,7 @@
| Tchrlit {$$ = mkchar($1->loc, $1->chrval);}
| Tfloatlit {$$ = mkfloat($1->loc, $1->fltval);}
| Tboollit {$$ = mkbool($1->loc, !strcmp($1->id, "true"));}
+ | Tvoidlit {$$ = mkvoid($1->loc);}
| Tintlit {
$$ = mkint($1->loc, $1->intval);
if ($1->inttype)
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -526,6 +526,7 @@
t = NULL;
if (!n->lit.type) {
switch (n->lit.littype) {
+ case Lvoid: t = mktype(n->loc, Tyvoid); break;
case Lchr: t = mktype(n->loc, Tychar); break;
case Lbool: t = mktype(n->loc, Tybool); break;
case Lint: t = mktylike(n->loc, Tyint); break;
@@ -999,9 +1000,6 @@
fatal(n, "calling uncallable type %s", tystr(ft));
}
/* first arg: function itself */
- for (i = 1; i < n->expr.nargs; i++)
- if (exprtype(n->expr.args[i])->type == Tyvoid)
- fatal(n, "void passed where value expected, near %s", ctxstr(st, n));
for (i = 1; i < n->expr.nargs; i++) {
if (i == ft->nsub)
fatal(n, "%s arity mismatch (expected %zd args, got %zd)",
--- a/parse/lits.def
+++ b/parse/lits.def
@@ -5,3 +5,4 @@
L(Lstr)
L(Lfunc)
L(Llbl)
+L(Lvoid)
--- a/parse/node.c
+++ b/parse/node.c
@@ -374,6 +374,15 @@
return n;
}
+Node *mkvoid(Srcloc loc)
+{
+ Node *n;
+
+ n = mknode(loc, Nlit);
+ n->lit.littype = Lvoid;
+ return n;
+}
+
char *declname(Node *n)
{
Node *name;
@@ -413,6 +422,7 @@
if (!tyeq(a->lit.type, b->lit.type))
return 0;
switch (a->lit.littype) {
+ case Lvoid: return 1;
case Lchr: return a->lit.chrval == b->lit.chrval;
case Lbool: return a->lit.boolval == b->lit.boolval;
case Lint: return a->lit.intval == b->lit.intval;
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -563,6 +563,7 @@
Node *mkintlit(Srcloc l, uvlong val);
Node *mkidxinit(Srcloc l, Node *idx, Node *init);
+Node *mkvoid(Srcloc loc);
Node *mkbool(Srcloc l, int val);
Node *mkint(Srcloc l, uint64_t val);
Node *mkchar(Srcloc l, uint32_t val);
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -180,12 +180,13 @@
case Nlit:
switch (n->lit.littype) {
case Lfunc: fixup(n->lit.fnval); break;
- case Lchr:
- case Lint:
- case Lflt:
- case Lstr:
- case Llbl:
- case Lbool: break;
+ case Lvoid: break;
+ case Lchr: break;
+ case Lint: break;
+ case Lflt: break;
+ case Lstr: break;
+ case Llbl: break;
+ case Lbool: break;
}
break;
case Nifstmt:
@@ -273,6 +274,7 @@
r->lit.littype = n->lit.littype;
r->lit.type = tysubst(n->expr.type, tsmap);
switch (n->lit.littype) {
+ case Lvoid: break;
case Lchr: r->lit.chrval = n->lit.chrval; break;
case Lint: r->lit.intval = n->lit.intval; break;
case Lflt: r->lit.fltval = n->lit.fltval; break;
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -191,6 +191,7 @@
{"union", Tunion},
{"use", Tuse},
{"var", Tvar},
+ {"void", Tvoidlit},
{"while", Twhile},
};
--- a/parse/use.c
+++ b/parse/use.c
@@ -469,6 +469,7 @@
wrtype(fd, n->lit.type);
wrint(fd, n->lit.nelt);
switch (n->lit.littype) {
+ case Lvoid: break;
case Lchr: wrint(fd, n->lit.chrval); break;
case Lint: wrint(fd, n->lit.intval); break;
case Lflt: wrflt(fd, n->lit.fltval); break;
@@ -598,6 +599,7 @@
rdtype(fd, &n->lit.type);
n->lit.nelt = rdint(fd);
switch (n->lit.littype) {
+ case Lvoid: break;
case Lchr: n->lit.chrval = rdint(fd); break;
case Lint: n->lit.intval = rdint(fd); break;
case Lflt: n->lit.fltval = rdflt(fd); break;