shithub: mc

Download patch

ref: 4ceb01e5c364b6273cc58bd79a1563e39307d818
parent: 3b5f150788ac70ab6e9a1eea1017f1f00111ad5f
author: Ori Bernstein <[email protected]>
date: Fri Jun 8 06:51:30 EDT 2012

Remove Tyidxhack.

    We still have a hack in place, in the form of parametrized
    parametrized types (ugh), but it doesn't need quite the same
    contortions.

--- a/8/reduce.c
+++ b/8/reduce.c
@@ -136,7 +136,7 @@
         case Tyunion:
             die("Sizes for composite types not implemented yet");
             break;
-        case Tybad: case Tyvar: case Typaram: case Tyname: case Tyidxhack: case Ntypes:
+        case Tybad: case Tyvar: case Typaram: case Tyname: case Ntypes:
             die("Type %s does not have size; why did it get down to here?", tystr(t));
             break;
     }
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -171,16 +171,17 @@
     b = *pb;
     /* we want to unify Tyidxhack => concrete indexable. Flip 
      * to make this happen, if needed */
-    if (b->type == Tyidxhack) {
+    if (b->type == Tyvar && b->nsub > 0) {
         a = *pb;
         b = *pa;
     }
-    return a->type == Tyidxhack || a->type == Tyarray || a->type == Tyslice;
+    return (a->type == Tyvar && a->nsub > 0) || a->type == Tyarray || a->type == Tyslice;
 }
 
 static Type *unify(Node *ctx, Type *a, Type *b)
 {
     Type *t;
+    Type *r;
     int i;
 
     /* a ==> b */
@@ -194,11 +195,13 @@
         b = t;
     }
 
+    r = NULL;
     mergecstrs(ctx, a, b);
     if (a->type == Tyvar) {
         tytab[a->tid] = b;
-        return b;
-    } else if (a->type == b->type || idxhacked(&a, &b)) {
+        r = b;
+    }
+    if (a->type == b->type || idxhacked(&a, &b)) {
         for (i = 0; i < b->nsub; i++) {
             /* types must have same arity */
             if (i >= a->nsub)
@@ -206,11 +209,11 @@
 
             unify(ctx, a->sub[i], b->sub[i]);
         }
-        return b;
-    } else {
+        r = b;
+    } else if (a->type != Tyvar) {
         fatal(ctx->line, "%s incompatible with %s near %s", tystr(a), tystr(b), ctxstr(ctx));
-        return NULL;
     }
+    return r;
 }
 
 static void unifycall(Node *n)
@@ -495,7 +498,7 @@
         for (i = 0; i < t->nsub; i++)
             t->sub[i] = tyfin(ctx, t->sub[i]);
     }
-    if (t->type == Tyvar || t->type == Tyidxhack) {
+    if (t->type == Tyvar) {
         fatal(t->line, "underconstrained type %s near %s", tyfmt(buf, 1024, t), ctxstr(ctx));
     }
 
--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -267,7 +267,6 @@
             wrtype(fd, ty->sub[0]);
             break;
         case Tyvar:
-        case Tyidxhack:
             die("Attempting to pickle %s. This will not work.\n", tystr(ty));
             break;
         default:
--- a/parse/type.c
+++ b/parse/type.c
@@ -126,7 +126,7 @@
 {
     Type *t;
 
-    t = mkty(line, Tyidxhack);
+    t = mkty(line, Tyvar);
     t->nsub = 1;
     t->sub = xalloc(sizeof(Type*));
     t->sub[0] = base;
@@ -344,11 +344,6 @@
             p += tybfmt(p, end - p, t->sub[0]);
             p += snprintf(p, end - p, "[LEN]");
             break;
-        case Tyidxhack:
-	    p += snprintf(p, end - p, "Tyidxhack(");
-            p += tybfmt(p, end - p, t->sub[0]);
-            p += snprintf(p, end - p, ")[]");
-            break;
         case Tyfunc:
             p += snprintf(p, end - p, "(");
             for (i = 1; i < t->nsub; i++) {
@@ -371,6 +366,15 @@
             break;
         case Tyvar:
             p += snprintf(p, end - p, "@$%d", t->tid);
+            if (t->nsub) {
+                p += snprintf(p, end - p, "(");
+                for (i = 1; i < t->nsub; i++) {
+                    p += snprintf(p, end - p, "%s", sep);
+                    p += tybfmt(p, end - p, t->sub[i]);
+                    sep = ", ";
+                }
+                p += snprintf(p, end - p, ")[]");
+            }
             break;
         case Typaram:
             p += snprintf(p, end - p, "@%s", t->pname);
@@ -447,11 +451,6 @@
     /* array :: tcidx, tcslice */
     tycstrs[Tyarray][0] = cstrtab[Tcidx];
     tycstrs[Tyarray][1] = cstrtab[Tcslice];
-
-    /* index hack :: tcidx, tcslice, tctest */
-    tycstrs[Tyidxhack][0] = cstrtab[Tcidx];
-    tycstrs[Tyidxhack][1] = cstrtab[Tcslice];
-    tycstrs[Tyidxhack][2] = cstrtab[Tctest];
 
     /* ptr :: tcslice, tctest */
     tycstrs[Typtr][0] = cstrtab[Tcidx];
--- a/parse/types.def
+++ b/parse/types.def
@@ -31,7 +31,6 @@
 Ty(Typtr, NULL)
 Ty(Tyslice, NULL)
 Ty(Tyarray, NULL)
-Ty(Tyidxhack, NULL)
 Ty(Tyfunc, NULL)
 Ty(Tytuple, NULL)
 Ty(Tyvar, NULL)
--- a/test/test.sh
+++ b/test/test.sh
@@ -37,7 +37,7 @@
 done
 
 for i in `awk '/^F/{print $2}' tests`; do
-    build $i
+    build $i > /dev/null
     if [ $? -eq '1' ]; then
         echo "PASS: $i"
     else