shithub: mc

Download patch

ref: a3b2adffd9eeb3d15e54cfcba7b1f1097ade002d
parent: fa136ee5b99cfcca3384a849578d168392ff2865
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Mar 8 15:59:55 EDT 2015

Add 'tygeneric' specifier.

--- a/6/simp.c
+++ b/6/simp.c
@@ -629,6 +629,8 @@
                 matchpattern(s, pat, val, uc->etype, iftrue, iffalse);
             }
             break;
+        case Tygeneric:
+            break;
     }
 }
 
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -83,7 +83,8 @@
                     sz = max(sz, tysize(t->udecls[i]->etype) + Wordsz);
             return align(sz, Ptrsz);
             break;
-        case Tybad: case Tyvar: case Typaram: case Tyunres: case Ntypes:
+        case Tygeneric: case Tybad: case Tyvar:
+        case Typaram: case Tyunres: case Ntypes:
             die("Type %s does not have size; why did it get down to here?", tystr(t));
             break;
     }
--- a/mi/match.c
+++ b/mi/match.c
@@ -43,9 +43,14 @@
  * out of memory, etc) long before getting to this code if we actually had that
  * many branches of the switch statements anyways.
  */
-static size_t nconstructors(Type *t) { if (!t) return 0; t = tybase(t); switch
-(t->type) { case Tyvoid:    return 0;               break;
+static size_t nconstructors(Type *t)
+{
+    if (!t)
+        return 0;
 
+    t = tybase(t);
+    switch (t->type) {
+        case Tyvoid:    return 0;               break;
         case Tybool:    return 2;               break;
         case Tychar:    return 0x10ffff;        break;
 
@@ -79,7 +84,7 @@
         case Tyunion:   return t->nmemb;        break;
         case Tyslice:   return ~0ULL;   break;
         case Tyvar: case Typaram: case Tyunres: case Tyname:
-        case Tybad: case Tyvalist: case Ntypes:
+        case Tybad: case Tyvalist: case Tygeneric: case Ntypes:
             die("Invalid constructor type %s in match", tystr(t));
             break;
     }
--- a/parse/type.c
+++ b/parse/type.c
@@ -606,6 +606,8 @@
             }
             p += snprintf(p, end - p, ")");
             break;
+        case Tygeneric:
+            break;
         case Tystruct:  p += fmtstruct(p, end - p, t);  break;
         case Tyunion:   p += fmtunion(p, end - p, t);   break;
         case Ntypes:
@@ -826,6 +828,8 @@
             else if (ty->param)
                 for (i = 0; i < ty->nparam; i++)
                     p += tyidfmt(p, end - p, ty->param[i]);
+            break;
+        case Tygeneric:
             break;
     }
     return p - buf;
--- a/parse/types.def
+++ b/parse/types.def
@@ -44,3 +44,4 @@
 Ty(Typaram, NULL)
 Ty(Tyunres, NULL) /* unresolved */
 Ty(Tyname, NULL)
+Ty(Tygeneric, NULL)
--- a/test/genericrec.myr
+++ b/test/genericrec.myr
@@ -8,4 +8,9 @@
 
 const main = {
 	var v : list(int)
+	var n
+
+	v.val = 123
+	v.next = std.alloc()
+	v.next.val = 234
 }