summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-02-27 23:42:20 -0800
committerOri Bernstein <ori@eigenstate.org>2016-02-27 23:42:20 -0800
commit5b7e3296ba57c446904ecd173ad9f3823a119851 (patch)
treecb4d4c3589e272761f8906f795ece6d522549891 /6
parent8e1b57e6cb50118d28a86115520b7331cc0fdf23 (diff)
downloadmc-5b7e3296ba57c446904ecd173ad9f3823a119851.tar.gz
Fix up type generation a bit.
Diffstat (limited to '6')
-rw-r--r--6/gen.c6
-rw-r--r--6/gengas.c30
-rw-r--r--6/genp9.c23
-rw-r--r--6/typeinfo.c3
4 files changed, 50 insertions, 12 deletions
diff --git a/6/gen.c b/6/gen.c
index 25df139..aac6c0b 100644
--- a/6/gen.c
+++ b/6/gen.c
@@ -127,17 +127,19 @@ char *tydescid(char *buf, size_t bufsz, Type *ty)
ns = "";
p = buf;
end = buf + bufsz;
+ ty = tydedup(ty);
if (ty->type == Tyname) {
if (ty->name->name.ns) {
ns = ty->name->name.ns;
sep = "$";
}
- if (ty->vis == Visexport || ty->isimport)
- p += bprintf(p, end - p, "_tydesc$%s%s%s", ns, sep, ty->name->name.name);
+ if (ty->vis != Visintern || ty->isimport)
+ p += bprintf(p, end - p, "_tydesc$%s%s%s", ns, sep, ty->name->name.name, ty->tid);
else
p += bprintf(p, end - p, "_tydesc$%s%s%s$%d", ns, sep, ty->name->name.name, ty->tid);
for (i = 0; i < ty->narg; i++)
p += tyidfmt(p, end - p, ty->arg[i]);
+ bprintf(p, end - p, "/* %zd */", ty->tid);
} else {
if (file->file.globls->name) {
ns = file->file.globls->name;
diff --git a/6/gengas.c b/6/gengas.c
index 7581e29..5307661 100644
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -346,17 +346,37 @@ static void genfunc(FILE *fd, Func *fn, Htab *globls, Htab *strtab)
writeasm(fd, &is, fn);
}
-void gentype(FILE *fd, Type *ty)
+static void gentype(FILE *fd, Type *ty)
{
Blob *b;
- if (ty->type == Tyvar)
+ ty = tydedup(ty);
+ if (ty->type == Tyvar || ty->isemitted)
return;
+
+ ty->isemitted = 1;
b = tydescblob(ty);
writeblob(fd, b);
blobfree(b);
}
+static void gentypes(FILE *fd)
+{
+ Type *ty;
+ size_t i;
+
+ for (i = Ntypes; i < ntypes; i++) {
+ if (!types[i]->isreflect)
+ continue;
+ ty = tydedup(types[i]);
+ if (ty->isemitted || ty->isimport)
+ continue;
+ gentype(fd, ty);
+ }
+ fprintf(fd, "\n");
+}
+
+
void genblob(FILE *fd, Node *blob, Htab *globls, Htab *strtab)
{
char *lbl;
@@ -436,14 +456,12 @@ void gengas(Node *file, char *out)
fprintf(fd, ".text\n");
for (i = 0; i < nfn; i++)
genfunc(fd, fn[i], globls, strtab);
+ gentypes(fd);
fprintf(fd, "\n");
- for (i = 0; i < ntypes; i++)
- if (types[i]->isreflect && (!types[i]->isimport || types[i]->ishidden))
- gentype(fd, types[i]);
+ genstrings(fd, strtab);
fprintf(fd, "\n");
- genstrings(fd, strtab);
fclose(fd);
}
diff --git a/6/genp9.c b/6/genp9.c
index d4c9e98..9042856 100644
--- a/6/genp9.c
+++ b/6/genp9.c
@@ -402,6 +402,23 @@ static void gentype(FILE *fd, Type *ty)
writeblob(fd, b, 0, lbl);
}
+static void gentypes(FILE *fd)
+{
+ Type *ty;
+ size_t i;
+
+ for (i = Ntypes; i < ntypes; i++) {
+ if (!types[i]->isreflect)
+ continue;
+ ty = tydedup(types[i]);
+ if (ty->isemitted || ty->isimport)
+ continue;
+ gentype(fd, ty);
+ }
+ fprintf(fd, "\n");
+}
+
+
static void genblob(FILE *fd, Node *blob, Htab *globls, Htab *strtab)
{
char *lbl;
@@ -471,11 +488,11 @@ void genp9(Node *file, char *out)
genblob(fd, blob[i], globls, strtab);
for (i = 0; i < nfn; i++)
genfunc(fd, fn[i], globls, strtab);
- for (i = 0; i < ntypes; i++)
- if (types[i]->isreflect && (!types[i]->isimport || types[i]->ishidden))
- gentype(fd, types[i]);
+ gentypes(fd);
fprintf(fd, "\n");
+
genstrings(fd, strtab);
+ fprintf(fd, "\n");
fclose(fd);
}
diff --git a/6/typeinfo.c b/6/typeinfo.c
index a16982c..be34b93 100644
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -114,6 +114,7 @@ Blob *tydescsub(Type *ty)
if (ty->type == Tyvar)
return NULL;
+ ty = tydedup(ty);
if (ty->type == Tyname)
tt |= Tdindirect;
sz = mkblobi(Btimin, 0);
@@ -220,7 +221,7 @@ Blob *tydescblob(Type *ty)
sz->ival = blobsz(sub);
lappend(&b->seq.sub, &b->seq.nsub, sz);
lappend(&b->seq.sub, &b->seq.nsub, sub);
- if (ty->vis == Visexport)
+ if (ty->vis != Visintern)
b->isglobl = 1;
} else {
b = tydescsub(ty);