shithub: mc

Download patch

ref: 0a0f0610bf7164c4f56d321f8750c82b2001498c
parent: 04ebbd679e7eccb3ecd7104f651b9bbbdc396753
author: Ori Bernstein <[email protected]>
date: Fri Jan 6 15:48:02 EST 2012

Fix type inference:

    - Look up stuff from the stab using it's name, instead of the expr node
    - Format cstrs correctly
    - Don't use NULL params for cstr checking

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -264,7 +264,7 @@
             settype(n, mkty(-1, Tyvoid));
             break;
         case Ovar:      /* a:@a -> @a */
-            s = getdcl(curstab(), n);
+            s = getdcl(curstab(), args[0]);
             if (!s)
                 fatal(n->line, "Undeclared var");
             else
@@ -352,10 +352,14 @@
  * and default constraint selections */
 static Type *tyfin(Type *t)
 {
+    static Type *tyint;
+
     t = tf(t);
+    if (!tyint)
+        tyint = mkty(-1, Tyint);
     if (t->type == Tyvar) {
-        if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tytab[Tyint]))
-            return mkty(-1, Tyint);
+        if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint))
+            return tyint;
     }
     return t;
 }
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -48,9 +48,9 @@
     return strhash(name(n));
 }
 
-static int ptreq(void *a, void *b)
+static int nameeq(void *a, void *b)
 {
-    return a == b;
+    return a == b || !strcmp(name(a), name(b));
 }
 
 Sym *mksym(int line, Node *name, Type *ty)
@@ -70,9 +70,9 @@
 
     st = zalloc(sizeof(Stab));
     st->super = super;
-    st->ns = mkht(namehash, ptreq);
-    st->dcl = mkht(namehash, ptreq);
-    st->ty = mkht(namehash, ptreq);
+    st->ns = mkht(namehash, nameeq);
+    st->dcl = mkht(namehash, nameeq);
+    st->ty = mkht(namehash, nameeq);
     return st;
 }
 
--- a/parse/type.c
+++ b/parse/type.c
@@ -236,6 +236,7 @@
 {
     char *p;
     char *end;
+    char *sep;
     int first;
     int i;
 
@@ -247,13 +248,11 @@
     first = 1;
 
     p += snprintf(p, end - p, " :: ");
+    sep = "";
     for (i = 0; i < ncstrs; i++) {
         if (bshas(t->cstrs, i)) {
-            if (!first) {
-                first = 0;
-                p += snprintf(p, end - p, ", ");
-            }
-            p += snprintf(p, end - p, "%s", cstrtab[i]->name);
+            p += snprintf(p, end - p, "%s%s", sep, cstrtab[i]->name);
+            sep = ",";
         }
     }
     return end - p;
--- a/parse/types.def
+++ b/parse/types.def
@@ -26,7 +26,8 @@
 Ty(Tyfloat32)
 Ty(Tyfloat64)
 Ty(Tyvalist)
-/*end numerical types*/
+
+/*end atomic types*/
 Ty(Typtr)
 Ty(Tyslice)
 Ty(Tyarray)