summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse/node.c14
-rw-r--r--parse/parse.h1
-rw-r--r--parse/type.c11
3 files changed, 20 insertions, 6 deletions
diff --git a/parse/node.c b/parse/node.c
index 85f1763..9ff3975 100644
--- a/parse/node.c
+++ b/parse/node.c
@@ -242,9 +242,6 @@ mkimplstmt(Srcloc loc, Node *name, Type *t, Type **aux, size_t naux, Node **decl
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 @@ mkimplstmt(Srcloc loc, Node *name, Type *t, Type **aux, size_t naux, Node **decl
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 @@ void
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
diff --git a/parse/parse.h b/parse/parse.h
index c58906b..79ab880 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -192,6 +192,7 @@ struct Trait {
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? */
diff --git a/parse/type.c b/parse/type.c
index 62d4a5e..4d8c96b 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -162,6 +162,7 @@ mktrait(Srcloc loc, Node *name, Type *param,
int isproto)
{
Trait *t;
+ size_t i;
t = zalloc(sizeof(Trait));
t->uid = ntraittab++;
@@ -174,9 +175,19 @@ mktrait(Srcloc loc, Node *name, Type *param,
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;
return t;