shithub: mc

Download patch

ref: 2433e863b1b3e802f38dd6db534b52867f670269
parent: dd2752bb02095b9852928da15d994940fd1af972
author: Ori Bernstein <[email protected]>
date: Sat Dec 20 21:28:19 EST 2014

Traits seem to be working. Whee!

--- a/parse/gram.y
+++ b/parse/gram.y
@@ -280,7 +280,7 @@
         ;
 
 package : Tpkg optident Tasn pkgbody Tendblk {
-                if (file->file.globls->name)
+                if (file->file.globls->_name)
                     lfatal($1->loc, "Package already declared\n");
                 if ($2) {
                     updatens(file->file.globls, $2->id);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1329,8 +1329,8 @@
            to do namespace dependent comparisons for specializing, we need to set the
            namespace here.
          */
-        if (file->file.globls->name)
-            setns(dcl->decl.name, namestr(file->file.globls->name));
+        if (file->file.globls->_name)
+            setns(dcl->decl.name, file->file.globls->_name);
         for (j = 0; j < t->nfuncs; j++) {
             if (nameeq(dcl->decl.name, t->funcs[j]->decl.name)) {
                 proto = t->funcs[j];
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -113,7 +113,7 @@
 
 struct Stab {
     Stab *super;
-    Node *name;
+    char *_name;
 
     /* Contents of stab.
      * types and values are in separate namespaces. */
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -385,7 +385,7 @@
 Node *specializedcl(Node *g, Type *to, Node **name)
 {
     extern int stabstkoff;
-    Node *d, *ns, *n;
+    Node *d, *n;
     Htab *tsmap;
     Stab *st;
 
@@ -396,8 +396,10 @@
     *name = n;
     if (n->name.ns)
         st = getns_str(curstab(), n->name.ns);
+    else
+        st = file->file.globls;
     if (!st)
-        printf("Can't find symbol table for %s.%s", n->name.ns, n->name.name);
+        fatal(n, "Can't find symbol table for %s.%s", n->name.ns, n->name.name);
     d = getdcl(st, n);
     if (debugopt['S'])
         printf("depth[%d] specializing [%d]%s => %s\n", stabstkoff, g->loc.line, namestr(g->decl.name), namestr(n));
@@ -409,11 +411,8 @@
     }
     /* namespaced names need to be looked up in their correct
      * context. */
-    if (g->decl.name->name.ns) {
-        ns = mkname(g->loc, g->decl.name->name.ns);
-        st = getns(file->file.globls, ns);
+    if (n->name.ns)
         pushstab(st);
-    }
 
     /* specialize */
     tsmap = mkht(tyhash, tyeq);
@@ -423,7 +422,7 @@
     d->decl.isconst = g->decl.isconst;
     d->decl.isextern = g->decl.isextern;
     d->decl.init = specializenode(g->decl.init, tsmap);
-    putdcl(file->file.globls, d);
+    putdcl(st, d);
 
     fixup(d);
 
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -190,9 +190,9 @@
 {
     Stab *s;
 
-    if (!strcmp(namestr(st->name), name))
-        return st;
     do {
+        if (streq(st->_name, name))
+            return st;
         if ((s = htget(st->ns, name)))
             return s;
         st = st->super;
@@ -263,8 +263,8 @@
 }
 
 void forcedcl (Stab *st, Node *s) {
-    if (st->name)
-        setns(s->decl.name, namestr(st->name));
+    if (st->_name)
+        setns(s->decl.name, st->_name);
     htput(st->dcl, s->decl.name, s);
     assert(htget(st->dcl, s->decl.name) != NULL);
 }
@@ -302,10 +302,10 @@
     Tydefn *td;
     Type *ty;
 
-    if (st->name)
-        setns(n, namestr(st->name));
-    if (st->name && t && t->type == Tyname)
-        setns(t->name, namestr(st->name));
+    if (st->_name)
+        setns(n, st->_name);
+    if (st->_name && t && t->type == Tyname)
+        setns(t->name, st->_name);
 
     ty = gettype(st, n);
     if (!ty) {
@@ -385,8 +385,8 @@
         fatal(n, "Trait %s already implemented over %s at %s:%d",
               namestr(n->impl.traitname), tystr(n->impl.type),
               fname(n->loc), lnum(n->loc));
-    if (st->name)
-        setns(n->impl.traitname, namestr(st->name));
+    if (st->_name)
+        setns(n->impl.traitname, st->_name);
     htput(st->impl, n, n);
 }
 
@@ -406,10 +406,10 @@
 {
     Stab *s;
 
-    s = getns(st, scope->name);
+    s = getns_str(st, scope->_name);
     if (s)
-        fatal(scope->name, "Namespace %s already defined at %s:%d", namestr(s->name), fname(s->name->loc), lnum(s->name->loc));
-    htput(st->ns, namestr(scope->name), scope);
+        lfatal(Zloc, "Namespace %s already defined", st->_name);
+    htput(st->ns, scope->_name, scope);
 }
 
 /*
@@ -423,9 +423,9 @@
     size_t i, nk;
     Tydefn *td;
 
-    if (st->name)
-        die("Stab %s already has namespace; Can't set to %s", namestr(st->name), name);
-    st->name = mkname(Zloc, name);
+    if (st->_name)
+        die("Stab %s already has namespace; Can't set to %s", st->_name, name);
+    st->_name = strdup(name);
     k = htkeys(st->dcl, &nk);
     for (i = 0; i < nk; i++)
         setns(k[i], name);
--- a/parse/use.c
+++ b/parse/use.c
@@ -47,7 +47,7 @@
     size_t n, i;
     void **keys;
 
-    pickle(fd, val->name);
+    wrstr(fd, val->_name);
 
     /* write decls */
     keys = htkeys(val->dcl, &n);
@@ -85,7 +85,7 @@
 
     /* read dcls */
     st = mkstab();
-    st->name = unpickle(fd);
+    st->_name = rdstr(fd);
     n = rdint(fd);
     for (i = 0; i < n; i++)
         putdcl(st, rdsym(fd, NULL));
@@ -696,22 +696,19 @@
 
 static Stab *findstab(Stab *st, char *pkg)
 {
-    Node *n;
     Stab *s;
 
     if (!pkg) {
-        if (!st->name)
+        if (!st->_name)
             return st;
         else
             return NULL;
     }
 
-    n = mkname(Zloc, pkg);
-    if (getns(st, n)) {
-        s = getns(st, n);
-    } else {
+    s = getns_str(st, pkg);
+    if (!s) {
         s = mkstab();
-        s->name = n;
+        s->_name = strdup(pkg);
         putns(st, s);
     }
     return s;
@@ -809,8 +806,8 @@
     /* if the package names match up, or the usefile has no declared
      * package, then we simply add to the current stab. Otherwise,
      * we add a new stab under the current one */
-    if (st->name) {
-        if (pkg && !strcmp(pkg, namestr(st->name))) {
+    if (st->_name) {
+        if (pkg && !strcmp(pkg, st->_name)) {
             s = st;
         } else {
             s = findstab(st, pkg);
@@ -941,8 +938,8 @@
 
     /* usefile name */
     wrbyte(f, 'U');
-    if (st->name)
-        wrstr(f, namestr(st->name));
+    if (st->_name)
+        wrstr(f, st->_name);
     else
         wrstr(f, NULL);