shithub: mc

Download patch

ref: d51d40bc1674f5845dab709096be84a4e5c51b2b
parent: a68e92f1e80f262e04d6e6c1d27af80199afbdc0
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Mar 3 17:32:07 EST 2019

Give traits the necessary env.

--- a/parse/node.c
+++ b/parse/node.c
@@ -242,9 +242,6 @@
 	n->impl.decls = decls;
 	n->impl.ndecls = ndecls;
 	lappend(&impltab, &nimpltab, n);
-	if (name->name.ns)
-		for (i = 0; i < ndecls; i++)
-			setns(decls[i]->decl.name, name->name.ns);
 	if (hasparams(t)) {
 		n->impl.env = mkenv();
 		bindtype(n->impl.env, t);
@@ -252,6 +249,12 @@
 	for (i = 0; i < naux; i++)
 		if (hasparams(aux[i]))
 			bindtype(n->impl.env, aux[i]);
+	for (i = 0; i < ndecls; i++) {
+		if (name->name.ns)
+			setns(decls[i]->decl.name, name->name.ns);
+		if (decls[i]->decl.env)
+			decls[i]->decl.env->super = n->impl.env;
+	}
 	return n;
 }
 
@@ -542,9 +545,8 @@
 setns(Node *n, char *ns)
 {
 	assert(!ns || !n->name.ns || !strcmp(n->name.ns, ns));
-	if (!ns)
-		return;
-	n->name.ns = strdup(ns);
+	if (ns)
+		n->name.ns = strdup(ns);
 }
 
 Op
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -192,6 +192,7 @@
 	size_t naux;
 	Node **proto;	/* type must implement these prototypes */
 	size_t nproto;
+	Tyenv *env;
 
 	char isproto;	/* is it a prototype (for exporting purposes) */
 	char ishidden;	/* should user code be able to use this? */
--- a/parse/type.c
+++ b/parse/type.c
@@ -162,6 +162,7 @@
 	int isproto)
 {
 	Trait *t;
+	size_t i;
 
 	t = zalloc(sizeof(Trait));
 	t->uid = ntraittab++;
@@ -174,8 +175,18 @@
 	t->proto = proto;
 	t->nproto = nproto;
 	t->aux = aux;
+	t->env = mkenv();
 	t->naux = naux;
 	t->isproto = isproto;
+
+	bindtype(t->env, param);
+	for (i = 0; i < naux; i++)
+		bindtype(t->env, aux[i]);
+
+	for (i = 0; i < nproto; i++)
+		if (proto[i]->decl.env)
+			proto[i]->decl.env->super = t->env;
+
 
 	traittab = xrealloc(traittab, ntraittab * sizeof(Trait *));
 	traittab[t->uid] = t;