ref: dd2752bb02095b9852928da15d994940fd1af972
parent: 2956d456959512a3e8b550899465395e033f7929
author: Ori Bernstein <[email protected]>
date: Sat Dec 20 21:07:01 EST 2014
Traits are more worky.
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -394,6 +394,7 @@
$$ = $1;
d = mkdecl($2->loc, mkname($2->loc, $2->id), $4);
d->decl.isgeneric = 1;
+ d->decl.isconst = 1;
lappend(&$$.nl, &$$.nn, d);
}
;
--- a/parse/node.c
+++ b/parse/node.c
@@ -429,6 +429,7 @@
void setns(Node *n, char *ns)
{
+ assert(!n->name.ns || !strcmp(n->name.ns, ns));
n->name.ns = strdup(ns);
}
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -11,7 +11,7 @@
#include "parse.h"
-static Node *specializenode(Node *n, Htab *tsmap);
+static Node *specializenode(Node *g, Htab *tsmap);
void addtraits(Type *t, Bitset *traits)
{
@@ -382,29 +382,35 @@
* duplicate of it with type 'to'. It also generates
* a name for this specialized node, and returns it in '*name'.
*/
-Node *specializedcl(Node *n, Type *to, Node **name)
+Node *specializedcl(Node *g, Type *to, Node **name)
{
+ extern int stabstkoff;
+ Node *d, *ns, *n;
Htab *tsmap;
- Node *d;
- Node *ns;
Stab *st;
- extern int stabstkoff;
- assert(n->type == Ndecl);
- assert(n->decl.isgeneric);
-
- *name = genericname(n, to);
- d = getdcl(file->file.globls, *name);
+ assert(g->type == Ndecl);
+ assert(g->decl.isgeneric);
+
+ n = genericname(g, to);
+ *name = n;
+ if (n->name.ns)
+ st = getns_str(curstab(), n->name.ns);
+ if (!st)
+ printf("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, n->loc.line, namestr(n->decl.name), namestr(*name));
+ printf("depth[%d] specializing [%d]%s => %s\n", stabstkoff, g->loc.line, namestr(g->decl.name), namestr(n));
if (d)
return d;
- if (n->decl.trait)
- fatal(n, "No trait implemented for for %s\n", namestr(n->decl.name));
+ if (g->decl.trait) {
+ printf("%s\n", namestr(n));
+ fatal(g, "No trait implemented for for %s:%s", namestr(g->decl.name), tystr(to));
+ }
/* namespaced names need to be looked up in their correct
* context. */
- if (n->decl.name->name.ns) {
- ns = mkname(n->loc, n->decl.name->name.ns);
+ if (g->decl.name->name.ns) {
+ ns = mkname(g->loc, g->decl.name->name.ns);
st = getns(file->file.globls, ns);
pushstab(st);
}
@@ -411,12 +417,12 @@
/* specialize */
tsmap = mkht(tyhash, tyeq);
- fillsubst(tsmap, to, n->decl.type);
+ fillsubst(tsmap, to, g->decl.type);
- d = mkdecl(n->loc, *name, tysubst(n->decl.type, tsmap));
- d->decl.isconst = n->decl.isconst;
- d->decl.isextern = n->decl.isextern;
- d->decl.init = specializenode(n->decl.init, tsmap);
+ d = mkdecl(g->loc, n, tysubst(g->decl.type, tsmap));
+ 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);
fixup(d);
--- a/parse/type.c
+++ b/parse/type.c
@@ -746,7 +746,7 @@
case Tyint64: p += snprintf(p, end - p, "q"); break;
case Tylong: p += snprintf(p, end - p, "l"); break;
- case Tybyte: p += snprintf(p, end - p, "T"); break;
+ case Tybyte: p += snprintf(p, end - p, "H"); break;
case Tyuint8: p += snprintf(p, end - p, "B"); break;
case Tyuint16: p += snprintf(p, end - p, "S"); break;
case Tyuint: p += snprintf(p, end - p, "I"); break;
--- a/parse/use.c
+++ b/parse/use.c
@@ -405,7 +405,6 @@
/* create an empty trait */
tr = mktrait(Zloc, NULL, NULL, NULL, 0, NULL, 0, 0);
uid = rdint(fd);
- printf("loading trait for uid %d\n", (int)uid);
tr->ishidden = rdbool(fd);
tr->name = unpickle(fd);
tr->param = tyunpickle(fd);