summaryrefslogtreecommitdiff
path: root/parse/use.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-01-14 13:25:47 -0800
committerOri Bernstein <ori@eigenstate.org>2018-01-14 13:46:18 -0800
commite7ebda38777e5251b3479c3fdced4cb108f252e4 (patch)
tree79f4c82d261879baa7a13cced78c3c0b67e25c1b /parse/use.c
parent8a53929e91acf351a11ec717c726833b2c703be1 (diff)
downloadmc-e7ebda38777e5251b3479c3fdced4cb108f252e4.tar.gz
Fix serializing trait specs in usefiles.
Diffstat (limited to 'parse/use.c')
-rw-r--r--parse/use.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/parse/use.c b/parse/use.c
index 7c7d48b..906e59b 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -218,7 +218,7 @@ rdsym(FILE *fd, Trait *ctx)
static void
typickle(FILE *fd, Type *ty)
{
- size_t i;
+ size_t i, j;
if (!ty) {
die("trying to pickle null type\n");
@@ -226,6 +226,16 @@ typickle(FILE *fd, Type *ty)
}
wrbyte(fd, ty->type);
wrbyte(fd, ty->vis);
+ wrint(fd, ty->nspec);
+ for (i = 0; i < ty->nspec; i++) {
+ wrint(fd, ty->spec[i]->ntrait);
+ for (j = 0; j < ty->spec[i]->ntrait; j++)
+ pickle(fd, ty->spec[i]->trait[j]);
+ wrtype(fd, ty->spec[i]->param);
+ wrbool(fd, ty->spec[i]->aux != NULL);
+ if (ty->spec[i]->aux)
+ wrtype(fd, ty->spec[i]->aux);
+ }
wrint(fd, ty->nsub);
switch (ty->type) {
case Tyunres:
@@ -350,7 +360,7 @@ rdtrait(FILE *fd, Trait **dest, Type *ty)
static Type *
tyunpickle(FILE *fd)
{
- size_t i, n;
+ size_t i, j, n;
Type *ty;
Ty t;
@@ -359,6 +369,19 @@ tyunpickle(FILE *fd)
ty->isimport = 1;
if (rdbyte(fd) == Vishidden)
ty->ishidden = 1;
+ ty->nspec = rdint(fd);
+ ty->spec = malloc(ty->nspec * sizeof(Traitspec*));
+ for (i = 0; i < ty->nspec; i++) {
+ ty->spec[i] = zalloc(sizeof(Traitspec));
+ n = rdint(fd);
+ ty->spec[i]->ntrait = n;
+ ty->spec[i]->trait = malloc(n * sizeof(Node*));
+ for (j = 0; j < ty->spec[i]->ntrait; j++)
+ ty->spec[i]->trait[j] = unpickle(fd);
+ rdtype(fd, &ty->spec[i]->param);
+ if (rdbool(fd))
+ rdtype(fd, &ty->spec[i]->aux);
+ }
ty->nsub = rdint(fd);
if (ty->nsub > 0)
ty->sub = zalloc(ty->nsub * sizeof(Type *));