shithub: mc

Download patch

ref: b12bf0009ed8fc457347c0ebc615a54254731b48
parent: 47d7e2b1035c7061eae7b46e174ebc7522729cb3
author: Ori Bernstein <[email protected]>
date: Wed Jun 6 12:03:18 EDT 2012

Work on fixing pickling.

    It's broken with arrays. Ow.

--- a/8/main.c
+++ b/8/main.c
@@ -58,26 +58,26 @@
         yyparse();
 
         if (debug) {
-          /* before we do anything to the parse */
-          dump(file, stdout);
+            /* before we do anything to the parse */
+            dump(file, stdout);
         }
 
         infer(file);
 
-        /* test storing tree to file */
-        tmp = fopen("a.pkl", "w");
-        pickle(file, tmp);
-        fclose(tmp);
-
         if (debug) {
-          /* and reading it back */
-          tmp = fopen("test.pkl", "r");
-          rdback = unpickle(tmp);
-          dump(rdback, stdout);
-          fclose(tmp);
+            /* test storing tree to file */
+            tmp = fopen("a.pkl", "w");
+            pickle(file, tmp);
+            fclose(tmp);
 
-          /* after all processing */
-          dump(file, stdout);
+            /* and reading it back */
+            tmp = fopen("test.pkl", "r");
+            rdback = unpickle(tmp);
+            dump(rdback, stdout);
+            fclose(tmp);
+
+            /* after all processing */
+            dump(file, stdout);
         }
         gen(file, "a.s");
     }
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -23,7 +23,7 @@
 static void setsuper(Stab *st, Stab *super)
 {
     Stab *s;
-    
+
     /* verify that we don't accidentally create loops */
     for (s = super; s; s = s->super)
         assert(s->super != st);
@@ -491,18 +491,14 @@
     static Type *tyint;
     int i;
     char buf[1024];
-    Type *orig;
 
-    orig = t;
     if (!tyint)
         tyint = mkty(-1, Tyint);
 
     t = tf(t);
     if (t->type == Tyvar) {
-        if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint)) {
-            printf("int\n");
+        if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint))
             return tyint;
-        }
     } else {
         if (t->type == Tyarray)
             typesub(t->asize);
@@ -514,7 +510,6 @@
         fatal(t->line, "underconstrained type %s near %s", tyfmt(buf, 1024, t), ctxstr(ctx));
     }
 
-    printf("fixing %s to %s\n", tystr(orig), tystr(t));
     return t;
 }
 
--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -229,9 +229,10 @@
     int i;
 
     if (!ty) {
-        wrbyte(fd, Tybad);
+        die("trying to pickle null type\n");
         return;
     }
+    printf("Writing %s\n", tystr(ty));
     wrbyte(fd, ty->type);
     /* tid is generated; don't write */
     /* cstrs are left out for now: FIXME */
@@ -283,8 +284,6 @@
     int i;
 
     t = rdbyte(fd);
-    if (t == Tybad)
-        return NULL;
     ty = mkty(-1, t);
     /* tid is generated; don't write */
     /* cstrs are left out for now: FIXME */
@@ -295,22 +294,22 @@
         case Tyname:
             ty->name = unpickle(fd);
             break;
-        case Typaram:   
+        case Typaram:
             ty->pname = rdstr(fd);
             break;
-        case Tystruct: 
+        case Tystruct:
             ty->nmemb = rdint(fd);
             ty->sdecls = xalloc(ty->nmemb * sizeof(Node*));
             for (i = 0; i < ty->nmemb; i++)
                 ty->sdecls[i] = unpickle(fd);
             break;
-        case Tyunion: 
+        case Tyunion:
             ty->nmemb = rdint(fd);
             ty->udecls = xalloc(ty->nmemb * sizeof(Node*));
             for (i = 0; i < ty->nmemb; i++)
                 ty->udecls[i] = unpickle(fd);
             break;
-        case Tyenum: 
+        case Tyenum:
             ty->nmemb = rdint(fd);
             ty->edecls = xalloc(ty->nmemb * sizeof(Node*));
             for (i = 0; i < ty->nmemb; i++)
@@ -328,6 +327,7 @@
                 ty->sub[i] = rdtype(fd);
             break;
     }
+    printf("Read %s\n", tystr(ty));
     return ty;
 }