shithub: mc

Download patch

ref: e8489f8f73d3b4bffc9e33f7045cb8e0329bb067
parent: f560f4097c26ef03098785200460b7bad33788fa
author: Ori Bernstein <[email protected]>
date: Wed Aug 15 16:16:17 EDT 2012

Renamings.

--- a/6/simp.c
+++ b/6/simp.c
@@ -427,7 +427,7 @@
     Ucon *uc;
 
     if (exprop(n) != Ocons)
-        return load(addk(addr(n, mkty(n->line, Tyuint)), off));
+        return load(addk(addr(n, mktype(n->line, Tyuint)), off));
 
     uc = finducon(n);
     return word(uc->line, uc->id);
@@ -918,9 +918,9 @@
         tmp = temp(s, n);
 
     /* Set the tag on the ucon */
-    u = addr(tmp, mkty(n->line, Tyuint));
+    u = addr(tmp, mktype(n->line, Tyuint));
     tag = mkintlit(n->line, uc->id);
-    tag->expr.type = mkty(n->line, Tyuint);
+    tag->expr.type = mktype(n->line, Tyuint);
     append(s, set(deref(u), tag));
 
 
@@ -966,7 +966,7 @@
     /* if true */
     append(s, ltrue);
     u = mkexpr(n->line, Olit, mkbool(n->line, 1), NULL);
-    u->expr.type = mkty(n->line, Tybool);
+    u->expr.type = mktype(n->line, Tybool);
     t = set(r, u);
     append(s, t);
     jmp(s, ldone);
@@ -974,7 +974,7 @@
     /* if false */
     append(s, lfalse);
     u = mkexpr(n->line, Olit, mkbool(n->line, 0), NULL);
-    u->expr.type = mkty(n->line, Tybool);
+    u->expr.type = mktype(n->line, Tybool);
     t = set(r, u);
     append(s, t);
     jmp(s, ldone);
@@ -1352,9 +1352,9 @@
     FILE *fd;
 
     /* declare useful constants */
-    tyintptr = mkty(-1, Tyuint64);
-    tyword = mkty(-1, Tyuint);
-    tyvoid = mkty(-1, Tyvoid);
+    tyintptr = mktype(-1, Tyuint64);
+    tyword = mktype(-1, Tyuint);
+    tyvoid = mktype(-1, Tyvoid);
 
     fn = NULL;
     nfn = 0;
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -271,7 +271,7 @@
         | uniondef
         | compoundtype
         | generictype
-        | Tellipsis {$$ = mkty($1->line, Tyvalist);}
+        | Tellipsis {$$ = mktype($1->line, Tyvalist);}
         ;
 
 generictype
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -195,11 +195,16 @@
 static Type *tf(Inferstate *st, Type *t)
 {
     Type *lu;
+    Stab *ns;
 
     assert(t != NULL);
     lu = NULL;
     while (1) {
         if (!tytab[t->tid] && t->type == Tyunres) {
+            ns = curstab();
+            if (t->name->name.ns) {
+                ns = getns_str(ns, t->name->name.ns);
+            }
             if (!(lu = gettype(curstab(), t->name)))
                 fatal(t->name->line, "Could not resolve type %s", namestr(t->name));
             tytab[t->tid] = lu;
@@ -234,11 +239,11 @@
     if (n->lit.type)
         return n->lit.type;
     switch (n->lit.littype) {
-        case Lchr:      return mkty(n->line, Tychar);                           break;
-        case Lbool:     return mkty(n->line, Tybool);                           break;
+        case Lchr:      return mktype(n->line, Tychar);                           break;
+        case Lbool:     return mktype(n->line, Tybool);                           break;
         case Lint:      return tylike(mktyvar(n->line), Tyint);                 break;
         case Lflt:      return tylike(mktyvar(n->line), Tyfloat32);             break;
-        case Lstr:      return mktyslice(n->line, mkty(n->line, Tybyte));       break;
+        case Lstr:      return mktyslice(n->line, mktype(n->line, Tybyte));       break;
         case Lfunc:     return n->lit.fnval->func.type;                         break;
         case Lseq:      return NULL; break;
     };
@@ -712,7 +717,7 @@
             t = type(st, args[0]);
             for (i = 1; i < nargs; i++)
                 unify(st, n, t, type(st, args[i]));
-            settype(st, n, mkty(-1, Tybool));
+            settype(st, n, mktype(-1, Tybool));
             break;
 
         /* reach into a type and pull out subtypes */
@@ -759,11 +764,11 @@
             if (nargs)
                 t = unify(st, n, ret, type(st, args[0]));
             else
-                t =  unify(st, n, mkty(-1, Tyvoid), ret);
+                t =  unify(st, n, mktype(-1, Tyvoid), ret);
             settype(st, n, t);
             break;
         case Ojmp:     /* goto void* -> void */
-            settype(st, n, mkty(-1, Tyvoid));
+            settype(st, n, mktype(-1, Tyvoid));
             break;
         case Ovar:      /* a:@a -> @a */
             /* if we created this from a namespaced var, the type should be
@@ -819,7 +824,7 @@
             settype(st, n, type(st, args[0]));
             break;
         case Olbl:      /* :lbl -> void* */
-            settype(st, n, mktyptr(n->line, mkty(-1, Tyvoid)));
+            settype(st, n, mktyptr(n->line, mktype(-1, Tyvoid)));
         case Obad: case Ocjmp: case Oset:
         case Oslbase: case Osllen:
         case Oblit: case Numops:
@@ -840,7 +845,7 @@
     infernode(st, n->func.body, n->func.type->sub[0], &sawret);
     /* if there's no return stmt in the function, assume void ret */
     if (!sawret)
-        unify(st, n, type(st, n)->sub[0], mkty(-1, Tyvoid));
+        unify(st, n, type(st, n)->sub[0], mktype(-1, Tyvoid));
 }
 
 static void inferdecl(Inferstate *st, Node *n)
@@ -982,9 +987,9 @@
     char buf[1024];
 
     if (!tyint)
-        tyint = mkty(-1, Tyint);
+        tyint = mktype(-1, Tyint);
     if (!tyflt)
-        tyflt = mkty(-1, Tyfloat64);
+        tyflt = mktype(-1, Tyfloat64);
 
     t = tf(st, t);
     if (t->type == Tyvar) {
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -179,7 +179,6 @@
                 int      boolval;
                 Node    *fnval;
                 Node    **seqval;
-                Node    **tupval;
             };
         } lit;
 
@@ -198,8 +197,8 @@
 
         struct {
             Node *val;
-            Node **matches;
             size_t nmatches;
+            Node **matches;
         } matchstmt;
 
         struct {
@@ -220,7 +219,7 @@
         struct {
             size_t did;
             char  isglobl;
-	    char  isexport;
+            char  isexport;
             char  isconst;
             char  isgeneric;
             char  isextern;
@@ -319,6 +318,7 @@
 void putucon(Stab *st, Ucon *uc);
 
 Stab *getns(Stab *st, Node *n);
+Stab *getns_str(Stab *st, char *n);
 Node *getdcl(Stab *st, Node *n);
 Type *gettype(Stab *st, Node *n);
 Cstr *getcstr(Stab *st, Node *n);
@@ -331,7 +331,7 @@
 /* type creation */
 void tyinit(Stab *st); /* sets up built in types */
 
-Type *mkty(int line, Ty ty);
+Type *mktype(int line, Ty ty);
 Type *tydup(Type *t); /* shallow duplicate; all subtypes/members/... kept */
 Type *mktyvar(int line);
 Type *mktyparam(int line, char *name);
--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -214,7 +214,7 @@
     size_t i;
 
     t = rdbyte(fd);
-    ty = mkty(-1, t);
+    ty = mktype(-1, t);
     /* tid is generated; don't write */
     /* cstrs are left out for now: FIXME */
     ty->nsub = rdint(fd);
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -59,7 +59,7 @@
     Stab *st;
 
     st = zalloc(sizeof(Stab));
-    st->ns = mkht(namehash, nameeq);
+    st->ns = mkht(strhash, streq);
     st->dcl = mkht(namehash, nameeq);
     st->ty = mkht(namehash, nameeq);
     st->uc = mkht(namehash, nameeq);
@@ -90,7 +90,7 @@
 Type *gettype(Stab *st, Node *n)
 {
     Tydefn *t;
-    
+
     do {
         if ((t = htget(st->ty, n)))
             return t->type;
@@ -102,7 +102,7 @@
 Ucon *getucon(Stab *st, Node *n)
 {
     Ucon *uc;
-    
+
     do {
         if ((uc = htget(st->uc, n)))
             return uc;
@@ -114,7 +114,7 @@
 Cstr *getcstr(Stab *st, Node *n)
 {
     Cstrdefn *c;
-    
+
     do {
         if ((c = htget(st->ty, n)))
             return c->cstr;
@@ -123,14 +123,14 @@
     return NULL;
 }
 
-Stab *getns(Stab *st, Node *n)
+Stab *getns_str(Stab *st, char *name)
 {
     Stab *s;
 
-    if (nameeq(st->name, n))
+    if (!strcmp(namestr(st->name), name))
         return st;
     do {
-        if ((s = htget(st->ns, n)))
+        if ((s = htget(st->ns, name)))
             return s;
         st = st->super;
     } while (st);
@@ -137,6 +137,11 @@
     return NULL;
 }
 
+Stab *getns(Stab *st, Node *n)
+{
+    return getns_str(st, namestr(n));
+}
+
 void putdcl(Stab *st, Node *s)
 {
     Node *d;
@@ -199,7 +204,7 @@
     s = getns(st, scope->name);
     if (s)
         fatal(scope->name->line, "Ns %s already defined", namestr(s->name));
-    htput(st->ns, scope->name, scope);
+    htput(st->ns, namestr(scope->name), scope);
 }
 
 void updatens(Stab *st, char *name)
--- a/parse/type.c
+++ b/parse/type.c
@@ -24,7 +24,7 @@
 
 static Cstr *tycstrs[Ntypes + 1][4];
 
-Type *mkty(int line, Ty ty)
+Type *mktype(int line, Ty ty)
 {
     Type *t;
     int i;
@@ -46,7 +46,7 @@
 {
     Type *r;
 
-    r = mkty(t->line, t->type);
+    r = mktype(t->line, t->type);
     r->resolved = 0; /* re-resolving doesn't hurt */
     r->cstrs = bsdup(t->cstrs);
     r->nsub = t->nsub;
@@ -94,7 +94,7 @@
 {
     Type *t;
 
-    t = mkty(line, Tyvar);
+    t = mktype(line, Tyvar);
     return t;
 }
 
@@ -102,7 +102,7 @@
 {
     Type *t;
 
-    t = mkty(line, Typaram);
+    t = mktype(line, Typaram);
     t->pname = strdup(name);
     return t;
 }
@@ -112,7 +112,7 @@
     Type *t;
 
     /* resolve it in the type inference stage */
-    t = mkty(line, Tyunres);
+    t = mktype(line, Tyunres);
     t->name = name;
     return t;
 }
@@ -121,7 +121,7 @@
 {
     Type *t;
 
-    t = mkty(line, Tyname);
+    t = mktype(line, Tyname);
     t->name = name;
     t->nsub = 1;
     t->cstrs = bsdup(base->cstrs);
@@ -134,7 +134,7 @@
 {
     Type *t;
 
-    t = mkty(line, Tyarray);
+    t = mktype(line, Tyarray);
     t->nsub = 1;
     t->nmemb = 1; /* the size is a "member" */
     t->sub = xalloc(sizeof(Type*));
@@ -148,7 +148,7 @@
 {
     Type *t;
 
-    t = mkty(line, Tyslice);
+    t = mktype(line, Tyslice);
     t->nsub = 1;
     t->sub = xalloc(sizeof(Type*));
     t->sub[0] = base;
@@ -159,7 +159,7 @@
 {
     Type *t;
 
-    t = mkty(line, Tyvar);
+    t = mktype(line, Tyvar);
     t->nsub = 1;
     t->sub = xalloc(sizeof(Type*));
     t->sub[0] = base;
@@ -170,7 +170,7 @@
 {
     Type *t;
 
-    t = mkty(line, Typtr);
+    t = mktype(line, Typtr);
     t->nsub = 1;
     t->sub = xalloc(sizeof(Type*));
     t->sub[0] = base;
@@ -182,7 +182,7 @@
     Type *t;
     size_t i;
 
-    t = mkty(line, Tytuple);
+    t = mktype(line, Tytuple);
     t->nsub = nsub;
     t->sub = xalloc(nsub*sizeof(Type));
     for (i = 0; i < nsub; i++)
@@ -195,7 +195,7 @@
     Type *t;
     size_t i;
 
-    t = mkty(line, Tyfunc);
+    t = mktype(line, Tyfunc);
     t->nsub = nargs + 1;
     t->sub = xalloc((1 + nargs)*sizeof(Type));
     t->sub[0] = ret;
@@ -208,7 +208,7 @@
 {
     Type *t;
 
-    t = mkty(line, Tystruct);
+    t = mktype(line, Tystruct);
     t->nsub = 0;
     t->nmemb = ndecls;
     t->sdecls = memdup(decls, ndecls*sizeof(Node *));
@@ -219,7 +219,7 @@
 {
     Type *t;
 
-    t = mkty(line, Tyunion);
+    t = mktype(line, Tyunion);
     t->nmemb = ndecls;
     t->udecls = decls;
     return t;
@@ -515,7 +515,7 @@
  * constraints, otherwise they will have no constraints set on them. */
 #define Ty(t, n) \
     if (t != Ntypes) {\
-      ty = mkty(-1, t); \
+      ty = mktype(-1, t); \
       if (n) { \
           puttype(st, mkname(-1, n), ty); \
       } \