summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-12-11 22:20:11 -0800
committerOri Bernstein <ori@eigenstate.org>2015-12-11 22:20:11 -0800
commite9a476ebae14c3d6a806bddc1b7514b60a846fc4 (patch)
tree3ef4b7eb6e6b609d04e872b9e81887bc669512a5
parentd21cc40703f9e3fb86e590fce62ee0847fc6cfd8 (diff)
downloadmc-e9a476ebae14c3d6a806bddc1b7514b60a846fc4.tar.gz
Fix code to disallow use before definition.
At least in some cases.
-rw-r--r--6/main.c5
-rw-r--r--6/simp.c4
-rw-r--r--lib/std/fltfmt.myr1
-rw-r--r--lib/std/fmtfuncs.myr4
-rw-r--r--lib/std/hashfuncs.myr1
-rw-r--r--mbld/syssel.myr3
-rw-r--r--mi/dfcheck.c8
-rw-r--r--support/vim/ftdetect/myr.vim4
8 files changed, 22 insertions, 8 deletions
diff --git a/6/main.c b/6/main.c
index 5d66e38..dbd77aa 100644
--- a/6/main.c
+++ b/6/main.c
@@ -23,7 +23,7 @@
Node *file;
char debugopt[128];
int writeasm;
-int extracheck;
+int extracheck = 1;
int p9asm;
char *outfile;
char **incpaths;
@@ -164,7 +164,7 @@ int main(int argc, char **argv)
outfile = NULL;
- optinit(&ctx, "d:hSo:I:9G", argv, argc);
+ optinit(&ctx, "cd:hSo:I:9G", argv, argc);
asmsyntax = Defaultasm;
while (!optdone(&ctx)) {
switch (optnext(&ctx)) {
@@ -181,6 +181,7 @@ int main(int argc, char **argv)
break;
case 'c':
extracheck = 1;
+ break;
case 'd':
while (ctx.optarg && *ctx.optarg)
debugopt[*ctx.optarg++ & 0x7f]++;
diff --git a/6/simp.c b/6/simp.c
index 59a12e9..03ad0b1 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -963,6 +963,10 @@ static Node *assign(Simp *s, Node *lhs, Node *rhs)
t = lval(s, lhs);
u = rval(s, rhs, t);
+ /* hack: we're assigning to lhs, but blitting shit over doesn't
+ * trigger that */
+ if (stacknode(lhs))
+ def(s, lhs);
/* if we stored the result into t, rval() should return that,
* so we know our work is done. */
if (u == t) {
diff --git a/lib/std/fltfmt.myr b/lib/std/fltfmt.myr
index 9a52b0e..42c0dc6 100644
--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -68,6 +68,7 @@ const dragon4 = {sb, isneg, f, e, p, mode, cutoff
s = bigshli(mkbigint(1), max(0, -(e - p)))
mm = bigshli(mkbigint(1), max((e - p), 0))
mp = bigdup(mm)
+ u = mkbigint(0)
/* fixup: unequal gaps */
t = mkbigint(1)
diff --git a/lib/std/fmtfuncs.myr b/lib/std/fmtfuncs.myr
index e20805e..3bb07f6 100644
--- a/lib/std/fmtfuncs.myr
+++ b/lib/std/fmtfuncs.myr
@@ -13,8 +13,12 @@ const __init__ = {
var bigint : bigint#
var bitset : bitset#
+ bigint = mkbigint(0)
+ bitset = mkbs()
fmtinstall(typeof(bigint), bigfmt, [][:])
fmtinstall(typeof(bitset), bsfmt, [][:])
+ bigfree(bigint)
+ bsfree(bitset)
}
const bigfmt = {sb, ap, opts
diff --git a/lib/std/hashfuncs.myr b/lib/std/hashfuncs.myr
index b3e0773..4f32604 100644
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -61,6 +61,7 @@ const strcasehash = {s
var chars
var c, h
+ chars = [][:]
while s.len != 0
(c, s) = std.striter(s)
chars = std.slpush(chars, c)
diff --git a/mbld/syssel.myr b/mbld/syssel.myr
index 437b013..d81452b 100644
--- a/mbld/syssel.myr
+++ b/mbld/syssel.myr
@@ -152,7 +152,8 @@ const skipspace = {data
const word = {data
var c, split
- c = std.decode(data[split:])
+ split = 0
+ c = std.decode(data[:])
while std.isalnum(c) || c == '.' || c == '_' || c == '$'
split += std.charlen(c)
;;
diff --git a/mi/dfcheck.c b/mi/dfcheck.c
index a83f1db..392c8dd 100644
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -23,6 +23,8 @@ static void checkundef(Node *n, Reaching *r, Bitset *reach, Bitset *kill)
return;
if (exprop(n) == Ovar) {
did = n->expr.did;
+ if (decls[did]->decl.isconst)
+ 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)
@@ -33,7 +35,7 @@ static void checkundef(Node *n, Reaching *r, Bitset *reach, Bitset *kill)
continue;
def = nodes[r->defs[did][j]];
if (exprop(def) == Oundef)
- fatal(n, "%s used before definition", namestr(n->expr.args[0]));
+ fatal(n, "%s used before definition [%d]", namestr(n->expr.args[0]), (int)did);
}
} else {
switch (exprop(n)) {
@@ -44,7 +46,7 @@ static void checkundef(Node *n, Reaching *r, Bitset *reach, Bitset *kill)
break;
case Oaddr:
case Oslice:
- /* these don't actually look at the of args[0], so they're ok. */
+ /* these don't actually look at the value of args[0], so they're ok. */
for (i = 1; i < n->expr.nargs; i++)
checkundef(n->expr.args[i], r, reach, kill);
break;
@@ -127,5 +129,5 @@ static void checkret(Cfg *cfg)
void check(Cfg *cfg)
{
checkret(cfg);
- if(0) checkreach(cfg);
+ checkreach(cfg);
}
diff --git a/support/vim/ftdetect/myr.vim b/support/vim/ftdetect/myr.vim
index 07b8129..0616ece 100644
--- a/support/vim/ftdetect/myr.vim
+++ b/support/vim/ftdetect/myr.vim
@@ -1,3 +1,3 @@
au BufRead,BufNewFile *.myr
- \ set ft=myr |
- \ set errorformat=%f:%l:\ %m,%D%f/%[a-z]%#...,%Dproject\ base\ %f:
+ \ setlocal ft=myr |
+ \ setlocal errorformat=%f:%l:\ %m,%D%f/%[a-z]%#...,%Dproject\ base\ %f: