summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-02-10 21:33:10 -0500
committerOri Bernstein <ori@eigenstate.org>2014-02-10 21:33:10 -0500
commitc158da43321893956e4be405ed04af37f86259fa (patch)
tree4af7fa3b6131b11da3149f1354b4af05c40440f8
parentdc335f52e7cd8526d3cc9d979057d3de593f94c6 (diff)
downloadmc-c158da43321893956e4be405ed04af37f86259fa.tar.gz
Split types and traits.
They used to live in the same hash table in the symtab. This was a bug. Now, they no longer live in the same hash table, but they do live in the same namespace; ie, var foo : bar::bar will not compile, since 'bar' can't be both a type and a trait.
-rw-r--r--parse/parse.h7
-rw-r--r--parse/stab.c9
-rw-r--r--test/tests2
3 files changed, 11 insertions, 7 deletions
diff --git a/parse/parse.h b/parse/parse.h
index bbd2850..acfc0ad 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -97,9 +97,10 @@ struct Stab {
* types and values are in separate namespaces. */
Htab *dcl;
Htab *closure; /* the syms we close over */
- Htab *ns;
- Htab *ty;
- Htab *uc;
+ Htab *ns; /* namespaces */
+ Htab *ty; /* types */
+ Htab *tr; /* traits */
+ Htab *uc; /* union constructors */
};
struct Type {
diff --git a/parse/stab.c b/parse/stab.c
index 679e1c6..34f9aaf 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -71,6 +71,7 @@ Stab *mkstab()
st->ns = mkht(strhash, streq);
st->dcl = mkht(nsnamehash, nsnameeq);
st->ty = mkht(nsnamehash, nsnameeq);
+ st->tr = mkht(nsnamehash, nsnameeq);
st->uc = mkht(nsnamehash, nsnameeq);
return st;
}
@@ -145,7 +146,7 @@ Trait *gettrait(Stab *st, Node *n)
Traitdefn *c;
do {
- if ((c = htget(st->ty, n)))
+ if ((c = htget(st->tr, n)))
return c->trait;
st = st->super;
} while (st);
@@ -224,13 +225,15 @@ void puttrait(Stab *st, Node *n, Trait *c)
{
Traitdefn *td;
+ if (gettrait(st, n))
+ fatal(n->line, "Trait %s already defined", namestr(n));
if (gettype(st, n))
- fatal(n->line, "Type %s already defined", namestr(n));
+ fatal(n->line, "Trait %s already defined as type", namestr(n));
td = xalloc(sizeof(Tydefn));
td->line = n->line;
td->name = n;
td->trait = c;
- htput(st->ty, td->name, td);
+ htput(st->tr, td->name, td);
}
void putns(Stab *st, Stab *scope)
diff --git a/test/tests b/test/tests
index 2c8cda7..82c905e 100644
--- a/test/tests
+++ b/test/tests
@@ -72,7 +72,7 @@ B str E 102
B generic E 42
B genericval E 42
B trait-builtin E 42
-# E emptytrait E 123 ## BUGGERED
+B emptytrait E 123
B nestucon P asdf
B mkunion E 0
B genericcall E 42