summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2017-06-28 03:24:57 -0700
committerOri Bernstein <ori@markovcorp.com>2017-06-28 10:59:54 -0700
commit567766b0cb773c76a9ec0d16246bd27b4a46b851 (patch)
tree47da5cff2284f691083c6b8445ded0047a174e85
parent6f5af8562ed5547ddaeb15ba7ed4a334318ca53f (diff)
downloadmc-567766b0cb773c76a9ec0d16246bd27b4a46b851.tar.gz
Remove unused memb from Trait and rename funcs -> proto
These are prototype declarations that must be implemented by the impl (not necessarily functions), so proto seems like a better name.
-rw-r--r--mi/flatten.c6
-rw-r--r--parse/export.c16
-rw-r--r--parse/gram.y10
-rw-r--r--parse/infer.c22
-rw-r--r--parse/parse.h9
-rw-r--r--parse/type.c14
-rw-r--r--parse/use.c29
7 files changed, 42 insertions, 64 deletions
diff --git a/mi/flatten.c b/mi/flatten.c
index d79ceb3..0733a12 100644
--- a/mi/flatten.c
+++ b/mi/flatten.c
@@ -751,10 +751,10 @@ static Node *itertraitfn(Srcloc loc, Trait *tr, char *fn, Type *ty)
char *name;
size_t i;
- for (i = 0; i < tr->nfuncs; i++) {
- name = declname(tr->funcs[i]);
+ for (i = 0; i < tr->nproto; i++) {
+ name = declname(tr->proto[i]);
if (!strcmp(fn, name)) {
- proto = tr->funcs[i];
+ proto = tr->proto[i];
dcl = htget(proto->decl.impls, ty);
var = mkexpr(loc, Ovar, dcl->decl.name, NULL);
var->expr.type = dcl->decl.type;
diff --git a/parse/export.c b/parse/export.c
index efe4650..0c9be87 100644
--- a/parse/export.c
+++ b/parse/export.c
@@ -60,10 +60,8 @@ static void tagtrait(Stab *st, Trait *tr, int ingeneric, int hidelocal)
tagtype(st, tr->param, ingeneric, hidelocal);
for (i = 0; i < tr->naux; i++)
tagtype(st, tr->aux[i], ingeneric, hidelocal);
- for (i = 0; i < tr->nmemb; i++)
- tagnode(st, tr->memb[i], ingeneric, hidelocal);
- for (i = 0; i < tr->nfuncs; i++)
- tagnode(st, tr->funcs[i], ingeneric, hidelocal);
+ for (i = 0; i < tr->nproto; i++)
+ tagnode(st, tr->proto[i], ingeneric, hidelocal);
}
static void tagtype(Stab *st, Type *t, int ingeneric, int hidelocal)
@@ -261,13 +259,9 @@ void tagexports(Node *file, int hidelocal)
tr->param->vis = tr->vis;
for (i = 0; i < tr->naux; i++)
tr->aux[i]->vis = tr->vis;
- for (i = 0; i < tr->nmemb; i++) {
- tr->memb[i]->decl.vis = tr->vis;
- tagnode(st, tr->memb[i], 0, hidelocal);
- }
- for (i = 0; i < tr->nfuncs; i++) {
- tr->funcs[i]->decl.vis = tr->vis;
- tagnode(st, tr->funcs[i], 0, hidelocal);
+ for (i = 0; i < tr->nproto; i++) {
+ tr->proto[i]->decl.vis = tr->vis;
+ tagnode(st, tr->proto[i], 0, hidelocal);
}
}
free(k);
diff --git a/parse/gram.y b/parse/gram.y
index 428bd4b..3839a92 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -229,8 +229,8 @@ toplev : package
| traitdef {
size_t i;
puttrait(file->file.globls, $1->name, $1);
- for (i = 0; i < $1->nfuncs; i++)
- putdcl(file->file.globls, $1->funcs[i]);
+ for (i = 0; i < $1->nproto; i++)
+ putdcl(file->file.globls, $1->proto[i]);
}
| tydef {
puttype(file->file.globls, mkname($1.loc, $1.name), $1.type);
@@ -344,8 +344,8 @@ pkgitem : decl {
size_t i;
$1->vis = Visexport;
puttrait(file->file.globls, $1->name, $1);
- for (i = 0; i < $1->nfuncs; i++)
- putdcl(file->file.globls, $1->funcs[i]);
+ for (i = 0; i < $1->nproto; i++)
+ putdcl(file->file.globls, $1->proto[i]);
}
| implstmt {
$1->impl.vis = Visexport;
@@ -411,7 +411,6 @@ traitdef: Ttrait Tident generictype optauxtypes { /* trait prototype */
mkname($2->loc, $2->id), $3,
$4.types, $4.ntypes,
NULL, 0,
- NULL, 0,
1);
}
| Ttrait Tident generictype optauxtypes Tasn traitbody Tendblk /* trait definition */ {
@@ -419,7 +418,6 @@ traitdef: Ttrait Tident generictype optauxtypes { /* trait prototype */
$$ = mktrait($1->loc,
mkname($2->loc, $2->id), $3,
$4.types, $4.ntypes,
- NULL, 0,
$6.nl, $6.nn,
0);
for (i = 0; i < $6.nn; i++) {
diff --git a/parse/infer.c b/parse/infer.c
index c48e700..87aae5d 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -248,13 +248,13 @@ static void additerspecializations(Inferstate *st, Node *n, Stab *stab)
return;
if (ty->type == Tyslice || ty->type == Tyarray || ty->type == Typtr)
return;
- for (i = 0; i < tr->nfuncs; i++) {
+ for (i = 0; i < tr->nproto; i++) {
ty = exprtype(n->iterstmt.seq);
- if (hthas(tr->funcs[i]->decl.impls, ty))
+ if (hthas(tr->proto[i]->decl.impls, ty))
continue;
lappend(&st->specializationscope, &st->nspecializationscope, stab);
lappend(&st->specializations, &st->nspecializations, n);
- lappend(&st->genericdecls, &st->ngenericdecls, tr->funcs[i]);
+ lappend(&st->genericdecls, &st->ngenericdecls, tr->proto[i]);
}
}
@@ -1779,9 +1779,9 @@ static void specializeimpl(Inferstate *st, Node *n)
*/
if (file->file.globls->name)
setns(dcl->decl.name, file->file.globls->name);
- for (j = 0; j < t->nfuncs; j++) {
- if (nsnameeq(dcl->decl.name, t->funcs[j]->decl.name)) {
- proto = t->funcs[j];
+ for (j = 0; j < t->nproto; j++) {
+ if (nsnameeq(dcl->decl.name, t->proto[j]->decl.name)) {
+ proto = t->proto[j];
break;
}
}
@@ -2493,16 +2493,16 @@ static void specialize(Inferstate *st, Node *f)
typesub(st, d, 0);
} else if (n->type == Niterstmt) {
tr = traittab[Tciter];
- assert(tr->nfuncs == 2);
+ assert(tr->nproto == 2);
ty = exprtype(n->iterstmt.seq);
it = itertype(st, n->iterstmt.seq, mktype(n->loc, Tybool));
- d = specializedcl(tr->funcs[0], it, &name);
- htput(tr->funcs[0]->decl.impls, ty, d);
+ d = specializedcl(tr->proto[0], it, &name);
+ htput(tr->proto[0]->decl.impls, ty, d);
it = itertype(st, n->iterstmt.seq, mktype(n->loc, Tyvoid));
- d = specializedcl(tr->funcs[1], it, &name);
- htput(tr->funcs[1]->decl.impls, ty, d);
+ d = specializedcl(tr->proto[1], it, &name);
+ htput(tr->proto[1]->decl.impls, ty, d);
} else {
die("unknown node for specialization\n");
}
diff --git a/parse/parse.h b/parse/parse.h
index cb89bfb..af4abb5 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -164,10 +164,8 @@ struct Trait {
Type *param; /* the type parameter */
Type **aux; /* auxiliary parameters */
size_t naux;
- Node **memb; /* type must have these members */
- size_t nmemb;
- Node **funcs; /* and declare these funcs */
- size_t nfuncs;
+ Node **proto; /* type must implement these prototypes */
+ size_t nproto;
char isproto; /* is it a prototype (for exporting purposes) */
char ishidden; /* should user code be able to use this? */
@@ -431,8 +429,7 @@ Type *mktyunion(Srcloc l, Ucon **decls, size_t ndecls);
Trait *mktrait(Srcloc l, Node *name,
Type *param,
Type **aux, size_t naux,
- Node **memb, size_t nmemb,
- Node **funcs, size_t nfuncs,
+ Node **proto, size_t nproto,
int isproto);
Type *mktylike(Srcloc l, Ty ty); /* constrains tyvar t like it was builtin ty */
Ucon *finducon(Type *t, Node *name);
diff --git a/parse/type.c b/parse/type.c
index 581b2b4..1d0db27 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -141,8 +141,7 @@ Type *mktylike(Srcloc loc, Ty like)
/* steals memb, funcs */
Trait *mktrait(Srcloc loc, Node *name, Type *param,
Type **aux, size_t naux,
- Node **memb, size_t nmemb,
- Node **funcs, size_t nfuncs,
+ Node **proto, size_t nproto,
int isproto)
{
Trait *t;
@@ -155,12 +154,10 @@ Trait *mktrait(Srcloc loc, Node *name, Type *param,
t->vis = Visintern;
t->name = name;
t->param = param;
- t->memb = memb;
- t->nmemb = nmemb;
+ t->proto = proto;
+ t->nproto = nproto;
t->aux = aux;
t->naux = naux;
- t->funcs = funcs;
- t->nfuncs = nfuncs;
t->isproto = isproto;
traittab = xrealloc(traittab, ntraittab * sizeof(Trait *));
@@ -924,7 +921,7 @@ void iterableinit(Stab *st, Trait *tr)
func->decl.isglobl = 1;
func->decl.isextern = 1;
- lappend(&tr->funcs, &tr->nfuncs, func);
+ lappend(&tr->proto, &tr->nproto, func);
putdcl(st, func);
/* __iterfin__ : (it : @a#, outval : @b# -> void) */
@@ -944,7 +941,7 @@ void iterableinit(Stab *st, Trait *tr)
func->decl.isglobl = 1;
func->decl.isextern = 1;
- lappend(&tr->funcs, &tr->nfuncs, func);
+ lappend(&tr->proto, &tr->nproto, func);
putdcl(st, func);
}
@@ -962,7 +959,6 @@ void tyinit(Stab *st)
mkname(Zloc, n), NULL, \
NULL, 0, \
NULL, 0, \
- NULL, 0, \
0); \
puttrait(st, tr->name, tr);
#include "trait.def"
diff --git a/parse/use.c b/parse/use.c
index c551738..1c02a6b 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -288,12 +288,9 @@ static void traitpickle(FILE *fd, Trait *tr)
wrint(fd, tr->naux);
for (i = 0; i < tr->naux; i++)
wrtype(fd, tr->aux[i]);
- wrint(fd, tr->nmemb);
- for (i = 0; i < tr->nmemb; i++)
- wrsym(fd, tr->memb[i]);
- wrint(fd, tr->nfuncs);
- for (i = 0; i < tr->nfuncs; i++)
- wrsym(fd, tr->funcs[i]);
+ wrint(fd, tr->nproto);
+ for (i = 0; i < tr->nproto; i++)
+ wrsym(fd, tr->proto[i]);
}
static void wrtype(FILE *fd, Type *ty)
@@ -407,7 +404,7 @@ static Type *tyunpickle(FILE *fd)
Trait *traitunpickle(FILE *fd)
{
Trait *tr;
- Node *fn;
+ Node *proto;
size_t i, n;
intptr_t uid;
@@ -415,7 +412,6 @@ Trait *traitunpickle(FILE *fd)
tr = mktrait(Zloc, NULL, NULL,
NULL, 0,
NULL, 0,
- NULL, 0,
0);
uid = rdint(fd);
if (rdint(fd) == Vishidden)
@@ -428,13 +424,10 @@ Trait *traitunpickle(FILE *fd)
for (i = 0; i < tr->naux; i++)
rdtype(fd, &tr->aux[i]);
n = rdint(fd);
- for (i = 0; i < n; i++)
- lappend(&tr->memb, &tr->nmemb, rdsym(fd, tr));
- n = rdint(fd);
for (i = 0; i < n; i++) {
- fn = rdsym(fd, tr);
- fn->decl.impls = mkht(tyhash, tyeq);
- lappend(&tr->funcs, &tr->nfuncs, fn);
+ proto = rdsym(fd, tr);
+ proto->decl.impls = mkht(tyhash, tyeq);
+ lappend(&tr->proto, &tr->nproto, proto);
}
htput(trmap, itop(uid), tr);
return tr;
@@ -837,8 +830,8 @@ static void protomap(Trait *tr, Type *ty, Node *dcl)
Node *proto;
dclname = declname(dcl);
- for (i = 0; i < tr->nfuncs; i++) {
- proto = tr->funcs[i];
+ for (i = 0; i < tr->nproto; i++) {
+ proto = tr->proto[i];
protoname = declname(proto);
len = strlen(protoname);
p = strstr(dclname, protoname);
@@ -979,8 +972,8 @@ foundextlib:
if (!tr->ishidden) {
tr->vis = vis;
puttrait(s, tr->name, tr);
- for (i = 0; i < tr->nfuncs; i++) {
- putdcl(s, tr->funcs[i]);
+ for (i = 0; i < tr->nproto; i++) {
+ putdcl(s, tr->proto[i]);
}
}
break;