shithub: mc

Download patch

ref: 537313ee9a2179cc6e869c6e8c70da4af1f07f28
parent: 6940a02fd47d73ba5dd0ad3a82b1945b639a23dc
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Apr 12 18:48:43 EDT 2019

Rename traits correctly.

--- a/6/main.c
+++ b/6/main.c
@@ -209,7 +209,6 @@
 main(int argc, char **argv)
 {
 	char buf[1024];
-	Stab *globls;
 	Optctx ctx;
 	size_t i;
 
@@ -282,12 +281,8 @@
 		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 */
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -100,11 +100,8 @@
 	}
 
 	/* 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();
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -554,6 +554,7 @@
 			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 @@
 			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 @@
 		} else {
 			die("unknown node for specialization\n");
 		}
+enditer:
 		popstab();
 	}
 }
@@ -3027,6 +3029,7 @@
 	for (i = 0; i < file.nstmts; i++)
 		typesub(file.stmts[i], 0);
 	popstab();
+
 	specialize();
 	verify();
 }
--- a/parse/node.c
+++ b/parse/node.c
@@ -30,6 +30,18 @@
 	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.
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -498,6 +498,7 @@
 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);
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -566,10 +566,8 @@
 	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 @@
 	fixup(d);
 
 	lappend(&file.stmts, &file.nstmts, d);
-	if (d->decl.name->name.ns)
-		popstab();
 	substfree(tsmap);
+	popstab();
 	return d;
 }
 
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -631,6 +631,7 @@
 {
 	void **k;
 	size_t i, nk;
+	Traitdefn *tr;
 	Tydefn *td;
 
 	if (st->name)
@@ -650,6 +651,13 @@
 		td = htget(st->ty, k[i]);
 		if (td->type && (td->type->type == Tyname || td->type->type == Tygeneric))
 			setns(td->type->name, 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);