shithub: mc

Download patch

ref: 5c8e36a766776886cca1bc86f980d313ef4e7ce8
parent: af8f9cee7dcaec8c8b3bc3c5299b643a99e35cb0
author: Ori Bernstein <[email protected]>
date: Mon Jun 18 19:57:29 EDT 2012

Remove enums from the language.

    Unions should take their place. Or consts if you really care
    about the integer value.

--- a/8/reduce.c
+++ b/8/reduce.c
@@ -204,8 +204,7 @@
             return 2;
         case Tyint: case Tyint32:
         case Tyuint: case Tyuint32:
-        case Typtr: case Tyenum:
-        case Tyfunc:
+        case Typtr: case Tyfunc:
             return 4;
 
         case Tyint64: case Tylong:
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -83,7 +83,6 @@
 %token<tok> Tchrlit
 %token<tok> Tboollit
 
-%token<tok> Tenum    /* enum */
 %token<tok> Tstruct  /* struct */
 %token<tok> Tunion   /* union */
 %token<tok> Ttyparam /* @typename */
@@ -113,7 +112,7 @@
 
 %start module
 
-%type <ty> type structdef uniondef enumdef compoundtype functype funcsig
+%type <ty> type structdef uniondef compoundtype functype funcsig
 %type <ty> generictype
 
 %type <tok> asnop cmpop addop mulop shiftop
@@ -123,11 +122,11 @@
 %type <node> exprln retexpr expr atomicexpr literal asnexpr lorexpr landexpr borexpr
 %type <node> bandexpr cmpexpr addexpr mulexpr shiftexpr prefixexpr postfixexpr
 %type <node> funclit arraylit name block blockbody stmt label use
-%type <node> decl declbody declcore structelt enumelt unionelt
+%type <node> decl declbody declcore structelt unionelt
 %type <node> ifstmt forstmt whilestmt elifs optexprln
 %type <node> castexpr
 
-%type <nodelist> arglist argdefs structbody enumbody unionbody params
+%type <nodelist> arglist argdefs structbody unionbody params
 
 %union {
     struct {
@@ -248,7 +247,6 @@
 
 type    : structdef
         | uniondef
-        | enumdef
         | compoundtype
         | generictype
         | Tellipsis {$$ = mkty($1->line, Tyvalist);}
@@ -323,24 +321,6 @@
             {$$ = NULL; die("unionelt impl");}
         | visdef Tendln
             {$$ = NULL;}
-        | Tendln
-            {$$ = NULL;}
-        ;
-
-enumdef : Tenum enumbody Tendblk
-            {$$ = mktyenum($1->line, $2.nl, $2.nn);}
-        ;
-
-enumbody: enumelt
-            {$$.nl = NULL; $$.nn = 0; if ($1) lappend(&$$.nl, &$$.nn, $1);}
-        | enumbody enumelt
-            {if ($2) {lappend(&$$.nl, &$$.nn, $2);}}
-        ;
-
-enumelt : Tident Tendln
-            {$$ = NULL; die("enumelt impl");}
-        | Tident Tasn exprln
-            {$$ = NULL; die("enumelt impl");}
         | Tendln
             {$$ = NULL;}
         ;
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -564,21 +564,16 @@
 static Type *tyfix(Node *ctx, Type *t)
 {
     static Type *tyint;
-    static Type *tyfloat;
     size_t i;
     char buf[1024];
 
     if (!tyint)
         tyint = mkty(-1, Tyint);
-    if (!tyfloat)
-        tyfloat = mkty(-1, Tyfloat64);
 
     t = tf(t);
     if (t->type == Tyvar) {
         if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint))
             return tyint;
-        if (hascstr(t, cstrtab[Tcnum]) && cstrcheck(t, tyfloat))
-            return tyfloat;
     } else {
         if (t->type == Tyarray)
             typesub(t->asize);
--- a/parse/node.c
+++ b/parse/node.c
@@ -279,7 +279,6 @@
     switch (t->type) {
         case Tystruct: return t->sdecls; break;
         case Tyunion: return t->udecls; break;
-        case Tyenum: return t->edecls; break;
         case Tyarray: return &t->asize; break;
         default: return NULL;
     }
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -94,7 +94,7 @@
     int resolved;     /* Have we resolved the subtypes? Idempotent, but slow to repeat. */
     Bitset *cstrs;    /* the type constraints matched on this type */
     size_t nsub;      /* For compound types */
-    size_t nmemb;     /* for aggregate types (struct, union, enum) */
+    size_t nmemb;     /* for aggregate types (struct, union) */
     Type **sub;       /* sub-types; shared by all composite types */
     union {
         Node *name;    /* Tyname: unresolved name */
@@ -102,7 +102,6 @@
         char *pname;   /* Typaram: name of type parameter */
         Node **sdecls; /* Tystruct: decls in struct */
         Node **udecls; /* Tyunion: decls in union */
-        Node **edecls; /* Tyenum: decls in enum */
     };
 };
 
@@ -297,7 +296,6 @@
 Type *mktyfunc(int line, Node **args, size_t nargs, Type *ret);
 Type *mktystruct(int line, Node **decls, size_t ndecls);
 Type *mktyunion(int line, Node **decls, size_t ndecls);
-Type *mktyenum(int line, Node **decls, size_t ndecls);
 Cstr *mkcstr(int line, char *name, Node **memb, size_t nmemb, Node **funcs, size_t nfuncs);
 Type *tylike(Type *t, Ty ty); /* constrains tyvar t like it was builtin ty */
 int   istysigned(Type *t);
--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -152,11 +152,6 @@
             for (i = 0; i < ty->nmemb; i++)
                 pickle(ty->udecls[i], fd);
             break;
-        case Tyenum:
-            wrint(fd, ty->nmemb);
-            for (i = 0; i < ty->nmemb; i++)
-                pickle(ty->edecls[i], fd);
-            break;
         case Tyarray:
             wrtype(fd, ty->sub[0]);
             pickle(ty->asize, fd);
@@ -205,12 +200,6 @@
             ty->udecls = xalloc(ty->nmemb * sizeof(Node*));
             for (i = 0; i < ty->nmemb; i++)
                 ty->udecls[i] = unpickle(fd);
-            break;
-        case Tyenum:
-            ty->nmemb = rdint(fd);
-            ty->edecls = xalloc(ty->nmemb * sizeof(Node*));
-            for (i = 0; i < ty->nmemb; i++)
-                ty->edecls[i] = unpickle(fd);
             break;
         case Tyarray:
             ty->sub[0] = rdtype(fd);
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -141,7 +141,6 @@
         {"match",       Tmatch},
         {"default",     Tdefault},
         {"goto",        Tgoto},
-        {"enum",        Tenum},
         {"struct",      Tstruct},
         {"union",       Tunion},
         {"const",       Tconst},
--- a/parse/type.c
+++ b/parse/type.c
@@ -177,16 +177,6 @@
     return t;
 }
 
-Type *mktyenum(int line, Node **decls, size_t ndecls)
-{
-    Type *t;
-
-    t = mkty(line, Tyenum);
-    t->nmemb = ndecls;
-    t->edecls = decls;
-    return t;
-}
-
 int istysigned(Type *t)
 {
     switch (t->type) {
@@ -258,8 +248,8 @@
     end = p + len;
     p += snprintf(p, end - p, "struct ");
     for (i = 0; i < t->nmemb; i++) {
-        name = declname(t->edecls[i]);
-        ty = tystr(decltype(t->edecls[i]));
+        name = declname(t->sdecls[i]);
+        ty = tystr(decltype(t->sdecls[i]));
         p += snprintf(p, end - p, "%s:%s; ", name, ty);
         free(ty);
     }
@@ -272,19 +262,10 @@
     size_t i;
     *buf = 0;
     for (i = 0; i < t->nmemb; i++)
-        dump(t->sdecls[i], stdout);
+        dump(t->udecls[i], stdout);
     return 0;
 }
 
-static int fmtenum(char *buf, size_t len, Type *t)
-{
-    size_t i;
-    *buf = 0;
-    for (i = 0; i < t->nmemb; i++)
-        dump(t->sdecls[i], stdout);
-    return 0;
-}
-
 static int tybfmt(char *buf, size_t len, Type *t)
 {
     size_t i;
@@ -374,7 +355,6 @@
             break;
         case Tystruct:  p += fmtstruct(p, end - p, t);  break;
         case Tyunion:   p += fmtunion(p, end - p, t);   break;
-        case Tyenum:    p += fmtenum(p, end - p, t);    break;
         case Ntypes:
             die("Ntypes is not a type");
             break;
@@ -432,10 +412,6 @@
     tycstrs[Tyslice][0] = cstrtab[Tctest];
     tycstrs[Tyslice][1] = cstrtab[Tcslice];
     tycstrs[Tyslice][2] = cstrtab[Tcidx];
-
-    /* enum :: tcint, tcnum */
-    tycstrs[Tyenum][0] = cstrtab[Tcint];
-    tycstrs[Tyenum][1] = cstrtab[Tcnum];
 
     /* array :: tcidx, tcslice */
     tycstrs[Tyarray][0] = cstrtab[Tcidx];
--- a/parse/types.def
+++ b/parse/types.def
@@ -38,5 +38,4 @@
 Ty(Tyname, NULL)
 Ty(Tystruct, NULL)
 Ty(Tyunion, NULL)
-Ty(Tyenum, NULL)
 Ty(Ntypes, NULL)