shithub: mc

Download patch

ref: 3f65d0e80c706fb06d946512d69421209071694e
parent: 334532827595c538c638dcae7ebecb4d857573f5
author: Ori Bernstein <[email protected]>
date: Thu Dec 26 21:33:31 EST 2013

Allow for hidden exports to happen automatically.

--- a/libstd/alloc.myr
+++ b/libstd/alloc.myr
@@ -38,9 +38,6 @@
 	const bytealloc	: (sz:size	-> byte#)
 	const zbytealloc	: (sz:size	-> byte#)
 	const bytefree	: (m:byte#, sz:size	-> void)
-
-	/* FIXME: This should be automatically exported as a hidden decl. */
-	const samebucket
 ;;
 
 /* null pointers. only used internally. */
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -130,6 +130,7 @@
         tyinit(file->file.globls);
         for (i = optind; i < argc; i++)
             mergeuse(argv[i]);
+        infer(file);
         f = fopen(outfile, "w");
         writeuse(f, file);
         fclose(f);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1664,6 +1664,137 @@
     }
 }
 
+static void taghidden(Type *t)
+{
+    size_t i;
+
+    if (t->vis != Visintern)
+        return;
+    t->vis = Vishidden;
+    for (i = 0; i < t->nsub; i++)
+        taghidden(t->sub[i]);
+    switch (t->type) {
+        case Tystruct:
+            for (i = 0; i < t->nmemb; i++)
+                taghidden(decltype(t->sdecls[i]));
+            break;
+        case Tyunion:
+            for (i = 0; i < t->nmemb; i++)
+                if (t->udecls[i]->etype)
+                    taghidden(t->udecls[i]->etype);
+            break;
+        case Tyname:
+            for (i = 0; i < t->narg; i++)
+                taghidden(t->arg[i]);
+            for (i = 0; i < t->nparam; i++)
+                taghidden(t->param[i]);
+            break;
+        default:
+            break;
+    }
+}
+
+static void nodetag(Stab *st, Node *n, int ingeneric)
+{
+    size_t i;
+    Node *d;
+
+    if (!n)
+        return;
+    switch (n->type) {
+        case Nblock:
+            for (i = 0; i < n->block.nstmts; i++)
+                nodetag(st, n->block.stmts[i], ingeneric);
+            break;
+        case Nifstmt:
+            nodetag(st, n->ifstmt.cond, ingeneric);
+            nodetag(st, n->ifstmt.iftrue, ingeneric);
+            nodetag(st, n->ifstmt.iffalse, ingeneric);
+            break;
+        case Nloopstmt:
+            nodetag(st, n->loopstmt.init, ingeneric);
+            nodetag(st, n->loopstmt.cond, ingeneric);
+            nodetag(st, n->loopstmt.step, ingeneric);
+            nodetag(st, n->loopstmt.body, ingeneric);
+            break;
+        case Nmatchstmt:
+            nodetag(st, n->matchstmt.val, ingeneric);
+            for (i = 0; i < n->matchstmt.nmatches; i++)
+                nodetag(st, n->matchstmt.matches[i], ingeneric);
+            break;
+        case Nmatch:
+            nodetag(st, n->match.pat, ingeneric);
+            nodetag(st, n->match.block, ingeneric);
+            break;
+        case Nexpr:
+            nodetag(st, n->expr.idx, ingeneric);
+            taghidden(n->expr.type);
+            for (i = 0; i < n->expr.nargs; i++)
+                nodetag(st, n->expr.args[i], ingeneric);
+            /* generics need to have the decls they refer to exported. */
+            if (ingeneric && exprop(n) == Ovar) {
+                d = decls[n->expr.did];
+                if (d->decl.isglobl && d->decl.vis == Visintern) {
+                    d->decl.vis = Vishidden;
+                    putdcl(st, d);
+                }
+            }
+            break;
+        case Nlit:
+            taghidden(n->lit.type);
+            if (n->lit.littype == Lfunc)
+                nodetag(st, n->lit.fnval, ingeneric);
+            break;
+        case Ndecl:
+            taghidden(n->decl.type);
+            /* generics export their body. */
+            if (n->decl.isgeneric)
+                nodetag(st, n->decl.init, n->decl.isgeneric);
+            break;
+        case Nfunc:
+            taghidden(n->func.type);
+            for (i = 0; i < n->func.nargs; i++)
+                nodetag(st, n->func.args[i], ingeneric);
+            nodetag(st, n->func.body, ingeneric);
+            break;
+
+        case Nuse: case Nname:
+            break;
+        case Nfile: case Nnone:
+            die("Invalid node for type export\n");
+            break;
+    }
+}
+
+void tagexports(Stab *st)
+{
+    void **k;
+    Node *s;
+    Type *t;
+    size_t i, j, n;
+
+    /* get the explicitly exported symbols */
+    k = htkeys(st->ty, &n);
+    for (i = 0; i < n; i++) {
+        t = gettype(st, k[i]);
+        t->vis = Visexport;
+        taghidden(t);
+        for (j = 0; j < t->nsub; j++)
+            taghidden(t->sub[j]);
+        for (j = 0; j < t->narg; j++)
+            taghidden(t->arg[j]);
+        for (j = 0; j < t->nparam; j++)
+            taghidden(t->param[j]);
+    }
+    free(k);
+
+    k = htkeys(st->dcl, &n);
+    for (i = 0; i < n; i++) {
+        s = getdcl(st, k[i]);
+        nodetag(st, s, 0);
+    }
+}
+
 /* Take generics and build new versions of them
  * with the type parameters replaced with the
  * specialized types */
@@ -1693,4 +1824,5 @@
     postcheck(&st, file);
     typesub(&st, file);
     specialize(&st, file);
+    tagexports(file->file.exports);
 }
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -440,6 +440,7 @@
 int  loaduse(FILE *f, Stab *into);
 void readuse(Node *use, Stab *into);
 void writeuse(FILE *fd, Node *file);
+void tagexports(Stab *st);
 
 /* typechecking/inference */
 void infer(Node *file);
--- a/parse/use.c
+++ b/parse/use.c
@@ -753,138 +753,6 @@
         die("Could not load usefile %s", use->use.name);
 }
 
-static void taghidden(Type *t)
-{
-    size_t i;
-
-    if (t->vis != Visintern)
-        return;
-    t->vis = Vishidden;
-    for (i = 0; i < t->nsub; i++)
-        taghidden(t->sub[i]);
-    switch (t->type) {
-        case Tystruct:
-            for (i = 0; i < t->nmemb; i++)
-                taghidden(decltype(t->sdecls[i]));
-            break;
-        case Tyunion:
-            for (i = 0; i < t->nmemb; i++)
-                if (t->udecls[i]->etype)
-                    taghidden(t->udecls[i]->etype);
-            break;
-        case Tyname:
-            for (i = 0; i < t->narg; i++)
-                taghidden(t->arg[i]);
-            for (i = 0; i < t->nparam; i++)
-                taghidden(t->param[i]);
-            break;
-        default:
-            break;
-    }
-}
-
-static void nodetag(Stab *st, Node *n, int ingeneric)
-{
-    size_t i;
-    Node *d;
-
-    if (!n)
-        return;
-    switch (n->type) {
-        case Nblock:
-            for (i = 0; i < n->block.nstmts; i++)
-                nodetag(st, n->block.stmts[i], ingeneric);
-            break;
-        case Nifstmt:
-            nodetag(st, n->ifstmt.cond, ingeneric);
-            nodetag(st, n->ifstmt.iftrue, ingeneric);
-            nodetag(st, n->ifstmt.iffalse, ingeneric);
-            break;
-        case Nloopstmt:
-            nodetag(st, n->loopstmt.init, ingeneric);
-            nodetag(st, n->loopstmt.cond, ingeneric);
-            nodetag(st, n->loopstmt.step, ingeneric);
-            nodetag(st, n->loopstmt.body, ingeneric);
-            break;
-        case Nmatchstmt:
-            nodetag(st, n->matchstmt.val, ingeneric);
-            for (i = 0; i < n->matchstmt.nmatches; i++)
-                nodetag(st, n->matchstmt.matches[i], ingeneric);
-            break;
-        case Nmatch:
-            nodetag(st, n->match.pat, ingeneric);
-            nodetag(st, n->match.block, ingeneric);
-            break;
-        case Nexpr:
-            nodetag(st, n->expr.idx, ingeneric);
-            taghidden(n->expr.type);
-            for (i = 0; i < n->expr.nargs; i++)
-                nodetag(st, n->expr.args[i], ingeneric);
-            /* generics need to have the decls they refer to exported. */
-            if (ingeneric && exprop(n) == Ovar) {
-                d = decls[n->expr.did];
-                if (d->decl.isglobl && d->decl.vis == Visintern) {
-                    d->decl.vis = Vishidden;
-                    putdcl(st, d);
-                }
-            }
-            break;
-        case Nlit:
-            taghidden(n->lit.type);
-            if (n->lit.littype == Lfunc)
-                nodetag(st, n->lit.fnval, ingeneric);
-            break;
-        case Ndecl:
-            taghidden(n->decl.type);
-            /* generics export their body. */
-            if (n->decl.isgeneric)
-                nodetag(st, n->decl.init, n->decl.isgeneric);
-            break;
-        case Nfunc:
-            taghidden(n->func.type);
-            for (i = 0; i < n->func.nargs; i++)
-                nodetag(st, n->func.args[i], ingeneric);
-            nodetag(st, n->func.body, ingeneric);
-            break;
-
-        case Nuse: case Nname:
-            break;
-        case Nfile: case Nnone:
-            die("Invalid node for type export\n");
-            break;
-    }
-}
-
-static void tagexports(Stab *st)
-{
-    void **k;
-    Node *s;
-    Type *t;
-    size_t i, j, n;
-
-    /* get the explicitly exported symbols */
-    k = htkeys(st->ty, &n);
-    for (i = 0; i < n; i++) {
-        t = gettype(st, k[i]);
-        t->vis = Visexport;
-        taghidden(t);
-        for (j = 0; j < t->nsub; j++)
-            taghidden(t->sub[j]);
-        for (j = 0; j < t->narg; j++)
-            taghidden(t->arg[j]);
-        for (j = 0; j < t->nparam; j++)
-            taghidden(t->param[j]);
-    }
-    free(k);
-
-    k = htkeys(st->dcl, &n);
-    for (i = 0; i < n; i++) {
-        s = getdcl(st, k[i]);
-        nodetag(st, s, 0);
-    }
-}
-
-
 /* Usefile format:
  * U<pkgname>
  * T<pickled-type>
@@ -906,7 +774,6 @@
     else
         wrstr(f, NULL);
 
-    tagexports(st);
     for (i = 0; i < ntypes; i++) {
         if (types[i]->vis == Visexport || types[i]->vis == Vishidden) {
             wrbyte(f, 'T');