shithub: mc

Download patch

ref: 7194b269261dae309e23a8c1639d35d536fea361
parent: fa7c9a073813587594aaced70309fb7f7d133a7a
parent: 00f032bd89766baaafb5cadc59fea2fb22ef934c
author: Ori Bernstein <[email protected]>
date: Thu Jun 21 16:59:28 EDT 2012

Merge branch 'master' of git+ssh://mimir.eigenstate.org/git/ori/mc2

Conflicts:
	parse/infer.c

--- a/8/reduce.c
+++ b/8/reduce.c
@@ -969,8 +969,10 @@
         for (i = 0; i < nfn; i++)
             genasm(stdout, fn[i], globls);
     }
+    fprintf(fd, ".data\n");
     for (i = 0; i < nblob; i++)
         genblob(fd, blob[i], globls);
+    fprintf(fd, ".text\n");
     for (i = 0; i < nfn; i++)
         genasm(fd, fn[i], globls);
     fclose(fd);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -45,27 +45,42 @@
     return 0;
 }
 
-static Type *freshen(Type *t)
+static Type *tyfreshen(Htab *ht, Type *t)
 {
     Type *ret;
     size_t i;
 
     t = tf(t);
-    if (t->type == Typaram && !isbound(t))
-        return mktyvar(t->line);
-    if (t->nsub == 0)
+    if (t->type != Typaram && t->nsub == 0)
         return t;
 
+    if (t->type == Typaram) {
+        if (hthas(ht, t->pname))
+            return htget(ht, t->pname);
+        ret = mktyvar(t->line);
+        htput(ht, t->pname, ret);
+        return ret;
+    }
+
     ret = zalloc(sizeof(Type));
     *ret = *t;
     ret->sub = zalloc(t->nsub * sizeof(Type *));
     for (i = 0; i < t->nsub; i++)
-        ret->sub[i] = freshen(t->sub[i]);
+        ret->sub[i] = tyfreshen(ht, t->sub[i]);
     printf("Freshened %s to %s\n", tystr(t), tystr(ret));
     return ret;
 }
 
+static Type *freshen(Type *t)
+{
+    Htab *ht;
 
+    ht = mkht(strhash, streq);
+    t = tyfreshen(ht, t);
+    htfree(ht);
+    return t;
+}
+
 static void tyresolve(Type *t)
 {
     size_t i, nn;
@@ -175,9 +190,9 @@
 {
     char *s;
     switch (n->type) {
-        default:        s = nodestr(n->type); 	break;
-        case Ndecl:     s = declname(n); 	break;
-        case Nname:     s = namestr(n); 	break;
+        default:        s = nodestr(n->type);   break;
+        case Ndecl:     s = declname(n);        break;
+        case Nname:     s = namestr(n);         break;
         case Nexpr:
             if (exprop(n) == Ovar)
                 s = namestr(n->expr.args[0]);
@@ -574,15 +589,15 @@
              * need to patch the types in if they don't have a definition */
             inferstab(n->file.globls);
             inferstab(n->file.exports);
-	    for (i = 0; i < n->file.nstmts; i++) {
-		d  = n->file.stmts[i];
-		infernode(d, NULL, sawret);
-		if (d->type == Ndecl)  {
-		    s = getdcl(file->file.exports, d->decl.name);
-		    if (s)
-			unify(d, type(d), s->decl.type);
-		}
-	    }
+            for (i = 0; i < n->file.nstmts; i++) {
+                d  = n->file.stmts[i];
+                infernode(d, NULL, sawret);
+                if (d->type == Ndecl)  {
+                    s = getdcl(file->file.exports, d->decl.name);
+                    if (s)
+                        unify(d, type(d), s->decl.type);
+                }
+            }
             popstab();
             break;
         case Ndecl:
@@ -730,8 +745,8 @@
 
     k = htkeys(s->dcl, &n);
     for (i = 0; i < n; i++) {
-	d = getdcl(s, k[i]);
-	d->decl.type = tyfix(d->decl.name, d->decl.type);
+        d = getdcl(s, k[i]);
+        d->decl.type = tyfix(d->decl.name, d->decl.type);
     }
     free(k);
 }
@@ -745,8 +760,8 @@
     switch (n->type) {
         case Nfile:
             pushstab(n->file.globls);
-	    stabsub(n->file.globls);
-	    stabsub(n->file.exports);
+            stabsub(n->file.globls);
+            stabsub(n->file.exports);
             for (i = 0; i < n->file.nstmts; i++)
                 typesub(n->file.stmts[i]);
             popstab();
--- a/test/hello/syscall.s
+++ b/test/hello/syscall.s
@@ -12,7 +12,7 @@
 	.long .a3
 	.long .a4
 	.long .a5
-	.long .a5 
+	.long .a6
 	/*
 	   hack: 6 args uses %ebp, so we index
 	   relative to %esp. This means that if