summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-06-09 13:47:28 -0700
committerOri Bernstein <ori@eigenstate.org>2018-06-09 13:47:28 -0700
commit84393ead97a2e189b6057420ad7d94170b9aa00f (patch)
tree0356c0bc422713adde510745645d652aa867944f
parent92840bc1ade4d670ce1b6cd3dc7be48b16148a5e (diff)
downloadmc-84393ead97a2e189b6057420ad7d94170b9aa00f.tar.gz
Consistently and corretly add Oundef.
-rw-r--r--6/simp.c1
-rw-r--r--lib/std/bigint.myr4
-rw-r--r--lib/std/fltfmt.myr2
-rw-r--r--lib/thread/spawn+openbsd.myr9
-rw-r--r--parse/gram.y28
-rw-r--r--parse/infer.c2
6 files changed, 28 insertions, 18 deletions
diff --git a/6/simp.c b/6/simp.c
index acf2db3..457227e 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -790,6 +790,7 @@ assign(Simp *s, Node *lhs, Node *rhs)
u = addr(s, u, exprtype(lhs));
v = disp(lhs->loc, size(lhs));
r = mkexpr(lhs->loc, Oblit, t, u, v, NULL);
+ r->expr.type = exprtype(lhs);
} else {
r = set(t, u);
}
diff --git a/lib/std/bigint.myr b/lib/std/bigint.myr
index afa65c1..64b93ca 100644
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -192,8 +192,9 @@ const bigbfmt = {buf, x, base
die("invalid base in bigbfmt\n")
;;
+ n = 0
if bigiszero(x)
- n
+ n += encode(buf[n:], '0')
;;
if base == 0
@@ -201,7 +202,6 @@ const bigbfmt = {buf, x, base
else
b = mkbigint(base)
;;
- n = 0
val = bigdup(x)
/* generate the digits in reverse order */
while !bigiszero(val)
diff --git a/lib/std/fltfmt.myr b/lib/std/fltfmt.myr
index dbe19ce..5019201 100644
--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -65,6 +65,8 @@ const dragon4 = {sb, isneg, f, e, p, mode, cutoff
/* initialize */
roundup = false
+ low = false
+ high = false
u = mkbigint(0)
r = bigshli(mkbigint(f), max(e, 0))
s = bigshli(mkbigint(1), max(0, -e))
diff --git a/lib/thread/spawn+openbsd.myr b/lib/thread/spawn+openbsd.myr
index a72e752..4526520 100644
--- a/lib/thread/spawn+openbsd.myr
+++ b/lib/thread/spawn+openbsd.myr
@@ -51,10 +51,11 @@ const spawnstk = {fn, sz
.tid = &ret,
.stk = (tos : byte#),
]
- if sys.__tfork_thread(&tfp, \
- sizeof(sys.tforkparams), \
- (startthread : void#), \
- (0 : void#)) < 0
+ ret = sys.__tfork_thread(&tfp,
+ sizeof(sys.tforkparams),
+ (startthread : void#),
+ (0 : void#))
+ if ret < 0
-> `std.Err "couldn't spawn thread"
;;
-> `std.Ok (ret : tid)
diff --git a/parse/gram.y b/parse/gram.y
index 9d9ddef..146c842 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -35,6 +35,7 @@ static void installucons(Stab *st, Type *t);
static void setattrs(Node *dcl, char **attrs, size_t nattrs);
static void setwith(Type *ty, Traitspec **spec, size_t nspec);
static void setupinit(Node *n);
+static void addinit(Node *blk, Node *dcl);
%}
@@ -1064,19 +1065,11 @@ block : blkbody Tendblk
blkbody : decl {
size_t i;
- Node *n, *d, *u;
$$ = mkblock($1.loc, mkstab(0));
for (i = 0; i < $1.nn; i++) {
- d = $1.nl[i];
- putdcl($$->block.scope, d);
- if (!d->decl.init) {
- n = mkexpr(d->loc, Ovar, d->decl.name, NULL);
- u = mkexpr(n->loc, Oundef, n, NULL);
- n->expr.did = d->decl.did;
- lappend(&$$->block.stmts, &$$->block.nstmts, u);
- }
- lappend(&$$->block.stmts, &$$->block.nstmts, d);
+ putdcl($$->block.scope, $1.nl[i]);
+ addinit($$, $1.nl[i]);
}
}
| stmt {
@@ -1098,7 +1091,7 @@ blkbody : decl {
size_t i;
for (i = 0; i < $3.nn; i++){
putdcl($$->block.scope, $3.nl[i]);
- lappend(&$1->block.stmts, &$1->block.nstmts, $3.nl[i]);
+ addinit($$, $3.nl[i]);
}
}
| blkbody Tendln tydef {
@@ -1119,6 +1112,19 @@ label : Tcolon Tident {
%%
static void
+addinit(Node *blk, Node *dcl)
+{
+ Node *n, *u;
+ if (!dcl->decl.init) {
+ n = mkexpr(dcl->loc, Ovar, dcl->decl.name, NULL);
+ u = mkexpr(n->loc, Oundef, n, NULL);
+ n->expr.did = dcl->decl.did;
+ lappend(&blk->block.stmts, &blk->block.nstmts, u);
+ }
+ lappend(&blk->block.stmts, &blk->block.nstmts, dcl);
+}
+
+static void
setupinit(Node *n)
{
char name[1024];
diff --git a/parse/infer.c b/parse/infer.c
index 58399b0..808a485 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -2108,7 +2108,7 @@ infernode(Node **np, Type *ret, int *sawret)
t = type(n->iterstmt.seq);
constrain(n, t, traittab[Tciter]);
b = basetype(t);
- if (b)
+ if (b && t->type != Typtr)
unify(n, e, b);
else
t->seqaux = e;