summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-11-30 17:42:04 -0800
committerOri Bernstein <ori@eigenstate.org>2014-11-30 17:42:04 -0800
commit9526e43a51595f081bfa0cc8b63d625ea785ff6d (patch)
treecc94e364e7daad25d730635e1186ce8ab292eb1a
parentd534f4ba7940abe04a5e8e12b3b41a86dc0a7107 (diff)
downloadmc-9526e43a51595f081bfa0cc8b63d625ea785ff6d.tar.gz
Be stricter about negating booleans.
We used to allow non-booleans. This was bad.
-rw-r--r--libstd/alloc.myr6
-rw-r--r--libstd/optparse.myr4
-rw-r--r--libstd/utf.myr2
-rw-r--r--mk/c.mk2
-rw-r--r--parse/infer.c10
-rw-r--r--test/encodechar.myr2
6 files changed, 16 insertions, 10 deletions
diff --git a/libstd/alloc.myr b/libstd/alloc.myr
index cddebe6..e65ca98 100644
--- a/libstd/alloc.myr
+++ b/libstd/alloc.myr
@@ -56,7 +56,7 @@ const Pagesz = 4*KiB
const Align = 16 /* minimum allocation alignment */
var buckets : bucket[32] /* excessive */
-var initdone : int
+var initdone : bool
type slheader = struct
cap : size /* capacity in bytes */
@@ -217,7 +217,7 @@ const bytealloc = {sz
for i = 0; i < buckets.len && (Align << i) <= Bktmax; i++
bktinit(&buckets[i], Align << i)
;;
- initdone = 1
+ initdone = true
;;
if (sz <= Bktmax)
@@ -319,7 +319,7 @@ const bktalloc = {bkt
b = s.freehd
s.freehd = b.next
s.nfree--
- if !s.nfree
+ if s.nfree == 0
bkt.slabs = s.next
s.next = Zslab
;;
diff --git a/libstd/optparse.myr b/libstd/optparse.myr
index e1bdb61..40374db 100644
--- a/libstd/optparse.myr
+++ b/libstd/optparse.myr
@@ -82,7 +82,7 @@ const optnext = {ctx
;;
| `Some (false, _):
arg = ""
- if !ctx.curarg.len
+ if ctx.curarg.len != 0
next(ctx)
;;
;;
@@ -92,7 +92,7 @@ const optnext = {ctx
}
const optdone = {ctx
- -> !ctx.curarg.len && ctx.finished
+ -> ctx.curarg.len == 0 && ctx.finished
}
const optinfo = {ctx, arg
diff --git a/libstd/utf.myr b/libstd/utf.myr
index 16c3cbb..cefba97 100644
--- a/libstd/utf.myr
+++ b/libstd/utf.myr
@@ -68,7 +68,7 @@ const striter = {str
var c
var tmp
- if !str.len
+ if str.len == 0
/* empty string: no resync needed */
-> (Badchar, str)
;;
diff --git a/mk/c.mk b/mk/c.mk
index eee1a29..5b1ddad 100644
--- a/mk/c.mk
+++ b/mk/c.mk
@@ -6,7 +6,7 @@ _LIBSRCHPATHS=$(addprefix -L, $(dir $(DEPS)))
_LIBINCPATHS=$(addprefix -I, $(dir $(DEPS)))
_LIBPATHS=$(addprefix -l, $(patsubst lib%.a,%,$(notdir $(DEPS))))
-CFLAGS += -Wall -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -g
+CFLAGS += -O0 -Wall -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -g
CFLAGS += -MMD -MP -MF ${_DEPSDIR}/$(subst /,-,$*).d
LIB ?= $(INSTLIB)
diff --git a/parse/infer.c b/parse/infer.c
index 7a5058c..cdcc71a 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1317,13 +1317,12 @@ static void inferexpr(Inferstate *st, Node *n, Type *ret, int *sawret)
t = unify(st, n, t, type(st, args[i]));
settype(st, n, t);
if (args[0]->expr.isconst)
- fatal(n, "Attempting to assign constant \"%s\"", ctxstr(st, args[0]));
+ fatal(n, "attempting to assign constant \"%s\"", ctxstr(st, args[0]));
break;
/* operands same type, returning bool */
case Olor: /* @a || @b -> bool */
case Oland: /* @a && @b -> bool */
- case Olnot: /* !@a -> bool */
case Oeq: /* @a == @a -> bool */
case One: /* @a != @a -> bool */
case Ogt: /* @a > @a -> bool */
@@ -1337,6 +1336,12 @@ static void inferexpr(Inferstate *st, Node *n, Type *ret, int *sawret)
settype(st, n, mktype(Zloc, Tybool));
break;
+ case Olnot: /* !bool -> bool */
+ infersub(st, n, ret, sawret, &isconst);
+ t = unify(st, n, type(st, args[0]), mktype(Zloc, Tybool));
+ settype(st, n, t);
+ break;
+
/* reach into a type and pull out subtypes */
case Oaddr: /* &@a -> @a* */
infersub(st, n, ret, sawret, &isconst);
@@ -2242,3 +2247,4 @@ void infer(Node *file)
typesub(&st, file);
specialize(&st, file);
}
+
diff --git a/test/encodechar.myr b/test/encodechar.myr
index eb32e18..ca2ff76 100644
--- a/test/encodechar.myr
+++ b/test/encodechar.myr
@@ -15,7 +15,7 @@ const chartypes = {
while s.len != 0
(c, s) = std.striter(s)
foo = c
- if !std.encode(buf[:std.charlen(c)], c)
+ if std.encode(buf[:std.charlen(c)], c) == 0
std.write(1, "couldn't encode\n")
;;
std.write(1, buf[:std.charlen(c)])