shithub: mc

Download patch

ref: 481445dc78bd2bbc733acfaf3f10ad0b8b4b2441
parent: 56ce21cc0b1dc9318da54e25b5cb2956066fc0ce
author: Ori Bernstein <[email protected]>
date: Mon Feb 24 15:08:01 EST 2014

Start implementing traits in usefiles.

--- a/parse/parse.h
+++ b/parse/parse.h
@@ -148,6 +148,7 @@
 
 struct Trait {
     int cid;            /* unique id */
+    Vis vis;
     int isproto;        /* is it a prototype (for exporting purposes) */
     Node *name;         /* the name of the trait */
     Type *param;        /* the type parameter */
--- a/parse/type.c
+++ b/parse/type.c
@@ -22,7 +22,7 @@
 Type **types = NULL;
 size_t ntypes;
 Trait **traittab;
-size_t ntraits;
+size_t ntraittab;
 
 /* Built in type constraints */
 static Trait *traits[Ntypes + 1][4];
@@ -123,9 +123,9 @@
     t->funcs = funcs;
     t->nfuncs = nfuncs;
     t->isproto = isproto;
-    t->cid = ntraits++;
+    t->cid = ntraittab++;
 
-    traittab = xrealloc(traittab, ntraits*sizeof(Trait*));
+    traittab = xrealloc(traittab, ntraittab*sizeof(Trait*));
     traittab[t->cid] = t;
     return t;
 }
@@ -374,7 +374,7 @@
 
     p += snprintf(p, end - p, " :: ");
     sep = "";
-    for (i = 0; i < ntraits; i++) {
+    for (i = 0; i < ntraittab; i++) {
         if (bshas(t->traits, i)) {
             p += snprintf(p, end - p, "%s%s", sep, namestr(traittab[i]->name));
             sep = ",";
--- a/parse/use.c
+++ b/parse/use.c
@@ -248,6 +248,11 @@
     }
 }
 
+ void traitpickle(FILE *fd, Trait *tr)
+{
+    die("Trait pickling not yet implemented");
+}
+
 static void wrtype(FILE *fd, Type *ty)
 {
     if (ty->tid >= Builtinmask)
@@ -830,6 +835,14 @@
             typickle(f, types[i]);
         }
     }
+    /*
+    for (i = 0; i < ntraittab; i++) {
+        if (traittab[i]->vis == Visexport || traittab[i]->vis == Vishidden) {
+            wrbyte(f, 'R');
+            traitpickle(f, traittab[i]);
+        }
+    }
+    */
     k = htkeys(st->dcl, &n);
     for (i = 0; i < n; i++) {
         s = getdcl(st, k[i]);