ref: ea5a4f8b5cea8d90491e6568d208dd656676bf61
parent: 23f4bc49055d8a9a28648b1c6e52f24eb4425ddf
author: Ori Bernstein <[email protected]>
date: Sun Jul 22 10:31:04 EDT 2012
Fix loading generics from exported usefiles.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -441,6 +441,7 @@
Stab *stab;
Node *s;
+ /* check that this is a namespaced declaration */
if (n->type != Nexpr)
return;
if (!n->expr.nargs)
@@ -452,6 +453,8 @@
stab = getns(curstab(), name);
if (!stab)
return;
+
+ /* substitute the namespaced name */
nsname = mknsname(n->line, namestr(name), namestr(args[1]));
s = getdcl(stab, args[1]);
if (!s)
@@ -458,7 +461,10 @@
fatal(n->line, "Undeclared var %s.%s", nsname->name.ns, nsname->name.name);
var = mkexpr(n->line, Ovar, nsname, NULL);
var->expr.did = s->decl.did;
- settype(st, var, s->decl.type);
+ if (s->decl.isgeneric)
+ settype(st, var, freshen(st, s->decl.type));
+ else
+ settype(st, var, s->decl.type);
*ret = var;
}
--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -117,9 +117,12 @@
wrtype(fd, val->decl.type);
/* symflags */
- wrint(fd, val->decl.isconst);
- wrint(fd, val->decl.isgeneric);
- wrint(fd, val->decl.isextern);
+ wrbool(fd, val->decl.isconst);
+ wrbool(fd, val->decl.isgeneric);
+ wrbool(fd, val->decl.isextern);
+
+ if (val->decl.isgeneric)
+ pickle(val->decl.init, fd);
}
static Node *rdsym(FILE *fd)
@@ -134,9 +137,13 @@
type = rdtype(fd);
n = mkdecl(line, name, type);
- n->decl.isconst = rdint(fd);
- n->decl.isgeneric = rdint(fd);
- n->decl.isextern = rdint(fd);
+ n->decl.isconst = rdbool(fd);
+ n->decl.isgeneric = rdbool(fd);
+ n->decl.isextern = rdbool(fd);
+
+
+ if (n->decl.isgeneric)
+ n->decl.init = unpickle(fd);
return n;
}