summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2019-04-12 22:48:43 -0700
committerOri Bernstein <ori@eigenstate.org>2019-04-12 22:48:43 -0700
commit537313ee9a2179cc6e869c6e8c70da4af1f07f28 (patch)
tree6cc091ad8c73b5e71755c6f4977de8d0e1d98fd1
parent6940a02fd47d73ba5dd0ad3a82b1945b639a23dc (diff)
downloadmc-537313ee9a2179cc6e869c6e8c70da4af1f07f28.tar.gz
Rename traits correctly.
-rw-r--r--6/main.c7
-rw-r--r--muse/muse.c5
-rw-r--r--parse/infer.c5
-rw-r--r--parse/node.c12
-rw-r--r--parse/parse.h1
-rw-r--r--parse/specialize.c9
-rw-r--r--parse/stab.c8
7 files changed, 30 insertions, 17 deletions
diff --git a/6/main.c b/6/main.c
index 618eb5f..5af7b1e 100644
--- a/6/main.c
+++ b/6/main.c
@@ -209,7 +209,6 @@ int
main(int argc, char **argv)
{
char buf[1024];
- Stab *globls;
Optctx ctx;
size_t i;
@@ -282,12 +281,8 @@ main(int argc, char **argv)
else
localincpath = dirname(ctx.args[i]);
- globls = mkstab(0);
- tyinit(globls);
+ initfile(&file, ctx.args[0]);
tokinit(ctx.args[i]);
- file.ns = mkht(strhash, streq);
- file.globls = globls;
- lappend(&file.files, &file.nfiles, ctx.args[i]);
yyparse();
/* before we do anything to the parse */
diff --git a/muse/muse.c b/muse/muse.c
index 6ed5450..a1dcacb 100644
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -100,11 +100,8 @@ main(int argc, char **argv)
}
/* read and parse the file */
- file.ns = mkht(strhash, streq);
- file.globls = mkstab(0);
- lappend(&file.files, &file.nfiles, "internal");
+ initfile(&file, outfile);
updatens(file.globls, pkgname);
- tyinit(file.globls);
for (i = 0; i < ctx.nargs; i++)
mergeuse(ctx.args[i]);
loaduses();
diff --git a/parse/infer.c b/parse/infer.c
index 75ca5ec..725c4d3 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -554,6 +554,7 @@ tyresolve(Type *t)
bsput(t->trneed, tr->uid);
if (nameeq(t->spec[i]->trait[j], traittab[Tciter]->name))
t->seqaux = t->spec[i]->aux;
+ t->spec[i]->trait[j] = tr->name;
}
}
@@ -2800,7 +2801,7 @@ specialize(void)
assert(tr->nproto == 2);
ty = exprtype(n->iterstmt.seq);
if (ty->type == Typaram)
- continue;
+ goto enditer;
it = itertype(n->iterstmt.seq, mktype(n->loc, Tybool));
d = specializedcl(tr->proto[0], ty, it, &name);
@@ -2812,6 +2813,7 @@ specialize(void)
} else {
die("unknown node for specialization\n");
}
+enditer:
popstab();
}
}
@@ -3027,6 +3029,7 @@ infer(void)
for (i = 0; i < file.nstmts; i++)
typesub(file.stmts[i], 0);
popstab();
+
specialize();
verify();
}
diff --git a/parse/node.c b/parse/node.c
index 9ff3975..bf40143 100644
--- a/parse/node.c
+++ b/parse/node.c
@@ -30,6 +30,18 @@ lnum(Srcloc l)
return l.line;
}
+void
+initfile(File *f, char *name)
+{
+ memset(f, 0, sizeof(*f));
+ f->builtins = mkstab(0);
+ f->globls = mkstab(0);
+ f->globls->super = file.builtins;
+ f->ns = mkht(strhash, streq);
+ lappend(&f->files, &f->nfiles, name);
+ tyinit(f->builtins);
+}
+
/*
* Bah, this is going to need to know how to fold things.
* FIXME: teach it.
diff --git a/parse/parse.h b/parse/parse.h
index 79ab880..5e5d7bc 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -498,6 +498,7 @@ int traitfmt(char *buf, size_t len, Type *t);
char *traitstr(Type *t);
/* node creation */
+void initfile(File *f, char *path);
Node *mknode(Srcloc l, Ntype nt);
Node *mkuse(Srcloc l, char *use, int islocal);
Node *mksliceexpr(Srcloc l, Node *sl, Node *base, Node *off);
diff --git a/parse/specialize.c b/parse/specialize.c
index 9cec3c3..77cb872 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -566,10 +566,8 @@ specializedcl(Node *gnode, Type *param, Type *to, Node **name)
if (debugopt['S'])
printf("specializing [%d]%s => %s\n", g->loc.line,
namestr(g->decl.name), namestr(n));
- /* namespaced names need to be looked up in their correct
- * context. */
- if (n->name.ns)
- pushstab(st);
+ /* namespaced names need to be looked up in context. */
+ pushstab(st);
/* specialize */
tsmap = mksubst();
@@ -585,9 +583,8 @@ specializedcl(Node *gnode, Type *param, Type *to, Node **name)
fixup(d);
lappend(&file.stmts, &file.nstmts, d);
- if (d->decl.name->name.ns)
- popstab();
substfree(tsmap);
+ popstab();
return d;
}
diff --git a/parse/stab.c b/parse/stab.c
index 54ccfaa..491e009 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -631,6 +631,7 @@ updatens(Stab *st, char *name)
{
void **k;
size_t i, nk;
+ Traitdefn *tr;
Tydefn *td;
if (st->name)
@@ -653,6 +654,13 @@ updatens(Stab *st, char *name)
}
free(k);
+ k = htkeys(st->tr, &nk);
+ for (i = 0; i < nk; i++) {
+ tr = htget(st->tr, k[i]);
+ setns(tr->name, name);
+ }
+ free(k);
+
k = htkeys(st->uc, &nk);
for (i = 0; i < nk; i++)
setns(k[i], name);