ref: df7166675776274c295fa623b4801565f4c3a4e1
parent: be5f7b2fc3ff72a7e0b664ff7ad0413375c58392
author: Ori Bernstein <[email protected]>
date: Sun Jun 17 00:26:04 EDT 2012
Allow exporting types by name only.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -440,7 +440,10 @@
k = htkeys(s->ty, &n);
for (i = 0; i < n; i++) {
- t = tf(gettype(s, k[i]));
+ t = gettype(s, k[i]);
+ if (!t)
+ t = gettype(file->file.globls, k[i]);
+ t = tf(t);
updatetype(s, k[i], t);
}
}
@@ -447,8 +450,10 @@
static void infernode(Node *n, Type *ret, int *sawret)
{
- size_t i;
+ void **k;
+ size_t i, nk;
Node *d;
+ Type *ty;
Sym *s;
if (!n)
@@ -455,9 +460,17 @@
return;
switch (n->type) {
case Nfile:
+ k = htkeys(file->file.exports->ty, &nk);
+ for (i = 0; i < nk; i++) {
+ ty = gettype(file->file.globls, k[i]);
+ if (!ty)
+ fatal(((Node*)k[i])->line, "Exported type %s not declared", namestr(k[i]));
+ updatetype(file->file.exports, k[i], ty);
+ }
+ free(k);
pushstab(n->file.globls);
inferstab(n->file.globls);
- inferstab(n->file.exports);
+ inferstab(n->file.exports);
for (i = 0; i < n->file.nstmts; i++) {
d = n->file.stmts[i];
infernode(d, NULL, sawret);
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -142,7 +142,6 @@
Type *ty;
Tydefn *td;
- assert(t != NULL);
ty = gettype(st, n);
if (ty)
fatal(n->line, "Type %s already defined", namestr(n));