shithub: mc

Download patch

ref: 90a6c98e077f034a9a89e347a331bda92d7c5181
parent: 36d7c7517cb0a12a0d6ae69b1538dd5a008b07b7
author: Ori Bernstein <[email protected]>
date: Sun Oct 7 20:57:07 EDT 2012

More work towards making generic types work.

--- a/6/main.c
+++ b/6/main.c
@@ -57,7 +57,7 @@
     Stab *globls;
     char buf[1024];
 
-    lappend(&incpaths, &nincpaths, Instroot "include/myr");
+    lappend(&incpaths, &nincpaths, Instroot "lib/myr");
     while ((opt = getopt(argc, argv, "d::hSo:I:")) != -1) {
         switch (opt) {
             case 'o':
--- a/libstd/Makefile
+++ b/libstd/Makefile
@@ -44,6 +44,6 @@
 
 
 install:
-	mkdir -p  $(INST_ROOT)/myr/lib/
-	install libstd.a $(INST_ROOT)/myr/lib/
-	install std $(INST_ROOT)/myr/lib/
+	mkdir -p  $(INST_ROOT)/lib/myr
+	install libstd.a $(INST_ROOT)/lib/myr
+	install std $(INST_ROOT)/lib/myr
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -11,6 +11,8 @@
 
 #include "parse.h"
 
+#include "../config.h"
+
 /* FIXME: move into one place...? */
 Node *file;
 char *outfile;
@@ -87,6 +89,7 @@
     int opt;
     int i;
 
+    lappend(&incpaths, &nincpaths, Instroot "lib/myr");
     while ((opt = getopt(argc, argv, "d::hmo:I:")) != -1) {
         switch (opt) {
             case 'h':
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -123,27 +123,34 @@
     t = tf(st, t);
     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;
-    } else if (t->type == Tygeneric) {
-        for (i = 0; i < t->nparam; i++)
-            if (!hthas(ht, t->param[i]->pname))
-                htput(ht, t->param[i]->pname, mktyvar(t->param[i]->line));
-        ret = mktyname(t->line, t->name, tyfreshen(st, ht, t->sub[0]));
-        for (i = 0; i < t->nparam; i++)
-            lappend(&ret->param, &ret->nparam, tyfreshen(st, ht, t->param[i]));
-        return ret;
-    } else {
-        ret = tydup(t);
-        for (i = 0; i < t->nsub; i++)
-            ret->sub[i] = tyfreshen(st, ht, t->sub[i]);
-        return ret;
+    switch (t->type) {
+        case Typaram:
+            if (hthas(ht, t->pname))
+                return htget(ht, t->pname);
+            ret = mktyvar(t->line);
+            htput(ht, t->pname, ret);
+            break;
+        case Tygeneric:
+            for (i = 0; i < t->nparam; i++)
+                if (!hthas(ht, t->param[i]->pname))
+                    htput(ht, t->param[i]->pname, mktyvar(t->param[i]->line));
+            ret = mktyname(t->line, t->name, tyfreshen(st, ht, t->sub[0]));
+            for (i = 0; i < t->nparam; i++)
+                lappend(&ret->param, &ret->nparam, tyfreshen(st, ht, t->param[i]));
+            break;
+        case Tystruct:
+            die("Freshening structs is not yet implemented");
+            break;
+        case Tyunion:
+            die("Freshening unions is not yet implemented");
+            break;
+        default:
+            ret = tydup(t);
+            for (i = 0; i < t->nsub; i++)
+                ret->sub[i] = tyfreshen(st, ht, t->sub[i]);
+            break;
     }
+    return ret;
 }
 
 static Type *tyspecialize(Inferstate *st, Type *t)
@@ -227,7 +234,8 @@
             infernode(st, t->sdecls[i], NULL, NULL);
     } else if (t->type == Tyunion) {
         for (i = 0; i < t->nmemb; i++) {
-            tyresolve(st, t->udecls[i]->utype);
+            //tyresolve(st, t->udecls[i]->utype);
+            t->udecls[i]->utype = t;
             t->udecls[i]->utype = tf(st, t->udecls[i]->utype);
             if (t->udecls[i]->etype) {
                 tyresolve(st, t->udecls[i]->etype);
@@ -337,11 +345,11 @@
     args = n->expr.args;
     uc = getucon(curstab(), args[0]);
     if (!uc)
-        fatal(n->line, "No union constructor %s", ctxstr(st, args[0]));
+        fatal(n->line, "no union constructor `%s", ctxstr(st, args[0]));
     if (!uc->etype && n->expr.nargs > 1)
-        fatal(n->line, "nullary union constructor %s passed arg ", ctxstr(st, args[0]));
+        fatal(n->line, "nullary union constructor `%s passed arg ", ctxstr(st, args[0]));
     else if (uc->etype && n->expr.nargs != 2)
-        fatal(n->line, "union constructor %s needs arg ", ctxstr(st, args[0]));
+        fatal(n->line, "union constructor `%s needs arg ", ctxstr(st, args[0]));
     return uc;
 }