shithub: mc

Download patch

ref: d438cbf5a395ddb1eb383afb44389832dda6ee5a
parent: 8c37b110a65ac1365ac9d0ae600a5cd368c11c34
author: Ori Bernstein <[email protected]>
date: Fri Dec 20 15:56:09 EST 2013

Add support for constraints in types.

--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -32,6 +32,15 @@
     return 0;
 }
 
+void addcstrs(Type *t, Bitset *cstrs)
+{
+    size_t b;
+
+    if (cstrs)
+        for (b = 0; bsiter(cstrs, &b); b++)
+            setcstr(t, cstrtab[b]);
+}
+
 /*
  * Duplicates the type 't', with all bound type
  * parameters substituted with the substitions
@@ -52,6 +61,7 @@
     switch (t->type) {
         case Typaram:
             ret = mktyvar(t->line);
+            addcstrs(ret, t->cstrs);
             htput(tsmap, t, ret);
             break;
         case Tyname:
@@ -66,6 +76,7 @@
                     if (subst[i]->type != Typaram || hthas(tsmap, subst[i]))
                         continue;
                     tmp = mktyvar(subst[i]->line);
+                    addcstrs(tmp, subst[i]->cstrs);
                     htput(tsmap, subst[i], tmp);
                 }
                 ret = mktyname(t->line, t->name, t->param, t->nparam, tyspecialize(t->sub[0], tsmap));
--- a/parse/type.c
+++ b/parse/type.c
@@ -465,12 +465,12 @@
             if (t->name->name.ns)
                 p += snprintf(p, end - p, "%s.", t->name->name.ns);
             p += snprintf(p, end - p, "%s", namestr(t->name));
-            if (t->isgeneric) {
-                arg = t->param;
-                narg = t->nparam;
-            } else {
+            if (t->narg) {
                 arg = t->arg;
                 narg = t->narg;
+            } else {
+                arg = t->param;
+                narg = t->nparam;
             }
             if (!narg)
                 break;
--- a/parse/use.c
+++ b/parse/use.c
@@ -184,7 +184,16 @@
     wrbyte(fd, ty->type);
     wrbyte(fd, ty->vis);
     /* tid is generated; don't write */
-    /* cstrs are left out for now: FIXME */
+    /* FIXME: since we only support hardcoded cstrs, we just write
+     * out the set of them. we should write out the cstr list as
+     * well */
+    if (!ty->cstrs) {
+        wrint(fd, 0);
+    } else {
+        wrint(fd, bscount(ty->cstrs));
+        for (i = 0; bsiter(ty->cstrs, &i); i++)
+            wrint(fd, i);
+    }
     wrint(fd, ty->nsub);
     switch (ty->type) {
         case Tyunres:
@@ -263,9 +272,10 @@
  * will not be meaningful in another file */
 static Type *tyunpickle(FILE *fd)
 {
+    size_t i, n;
+    size_t v;
     Type *ty;
     Ty t;
-    size_t i;
 
     t = rdbyte(fd);
     ty = mktype(-1, t);
@@ -272,7 +282,14 @@
     if (rdbyte(fd) == Vishidden)
         ty->ishidden = 1;
     /* tid is generated; don't write */
-    /* cstrs are left out for now: FIXME */
+    n = rdint(fd);
+    if (n > 0) {
+        ty->cstrs = mkbs();
+        for (i = 0; i < n; i++) {
+            v = rdint(fd);
+            setcstr(ty, cstrtab[v]);
+        }
+    }
     ty->nsub = rdint(fd);
     if (ty->nsub > 0)
         ty->sub = zalloc(ty->nsub * sizeof(Type*));