ref: 4e54802e15be131d64e47486df1b5e2502aef6e9
parent: 9ee86f915781eb5acfabfaf482f123a5da162ff3
author: Ori Bernstein <[email protected]>
date: Mon Apr 14 16:03:19 EDT 2014
Build the export list for traits correctly.
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -299,7 +299,6 @@
}
| implstmt {
$1->impl.vis = Visexport;
- lappend(&exportimpls, &nexportimpls, $1);
}
| visdef {die("Unimplemented visdef");}
| /* empty */
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -857,15 +857,17 @@
if (nx->impl.isproto) {
if (!ng)
fatal(nx->line, "Missing trait impl body for %s %s\n", namestr(nx->impl.traitname), tystr(nx->impl.type));
- nx->impl.isproto = 0;
- nx->impl.decls = ng->impl.decls;
- nx->impl.ndecls = ng->impl.ndecls;
+ htdel(exports->impl, k[i]);
+ putimpl(exports, ng);
+ lappend(&exportimpls, &nexportimpls, ng);
} else {
- if (ng)
+ if (!ng) {
+ putimpl(globls, nx);
+ lappend(&exportimpls, &nexportimpls, nx);
+ } else {
fatal(nx->line, "Double trait impl body for %s %s on line %d\n",
namestr(nx->impl.traitname), tystr(nx->impl.type), ng->line);
- else
- putimpl(globls, nx);
+ }
}
}
@@ -1360,6 +1362,7 @@
size_t i, j;
t = gettrait(curstab(), n->impl.traitname);
+ n->impl.trait = t;
if (!t)
fatal(n->line, "No trait %s\n", namestr(n->impl.traitname));
n->impl.type = tf(st, n->impl.type);
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -297,6 +297,7 @@
struct {
Node *traitname;
+ Trait *trait;
Type *type;
Node **decls;
size_t ndecls;
--- a/parse/use.c
+++ b/parse/use.c
@@ -263,9 +263,15 @@
wrsym(fd, tr->funcs[i]);
}
-static void implpickle(FILE *fd, Node *impl)
+static void implpickle(FILE *fd, Node *n)
{
- die("Pickling impls not yet supported.");
+ size_t i;
+
+ pickle(fd, n->impl.traitname);
+ wrint(fd, n->impl.trait->uid);
+ wrtype(fd, n->impl.type);
+ for (i = 0; i < n->impl.ndecls; i++)
+ pickle(fd, n->impl.decls[i]);
}
static void wrtype(FILE *fd, Type *ty)