ref: 3e73a19648bd78bb9defb1ccb458f21206450fe2
parent: 252e424842be2148b7f6326cf43be8af1c2e19b2
author: Ori Bernstein <[email protected]>
date: Sat Jun 23 18:49:18 EDT 2012
Make sure node ids are unique.
binary files /dev/null b/8/8m differ
--- a/parse/node.c
+++ b/parse/node.c
@@ -13,6 +13,7 @@
#include "parse.h"
int maxnid;
+int maxdid;
Node *mknode(int line, Ntype nt)
{
@@ -210,11 +211,10 @@
Node *mkdecl(int line, Node *name, Type *ty)
{
- static int nextdid;
Node *n;
n = mknode(line, Ndecl);
- n->decl.did = nextdid++;
+ n->decl.did = maxdid++;
n->decl.name = name;
n->decl.type = ty;
return n;
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -217,6 +217,7 @@
extern Cstr **cstrtab; /* int -> cstr map */
extern int ncstrs;
extern int maxnid; /* the maximum node id generated so far */
+extern int maxdid; /* the maximum decl id generated so far */
extern int ispureop[];
--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -412,6 +412,7 @@
n->lbl.name = rdstr(fd);
break;
case Ndecl:
+ n->decl.did = maxdid++; /* unique within file */
/* sym */
n->decl.name = unpickle(fd);
n->decl.type = rdtype(fd);
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -11,21 +11,21 @@
#include "parse.h"
-static ulong tidhash(void *p)
+static ulong tyhash(void *p)
{
Type *t;
t = p;
- return ptrhash((void*)(intptr_t)t->tid);
+ return strhash(t->pname);
}
-static int tideq(void *pa, void *pb)
+static int tyeq(void *pa, void *pb)
{
Type *a, *b;
a = pa;
b = pb;
- return a->tid == b->tid;
+ return streq(a->pname, b->pname);
}
static int hasparams(Type *t)
@@ -68,8 +68,10 @@
{
size_t i;
- printf("Specialize %s => %s\n", tystr(from), tystr(to));
- htput(tsmap, from, to);
+ if (from->type == Typaram) {
+ printf("Specialize %s => %s\n", tystr(from), tystr(to));
+ htput(tsmap, from, to);
+ }
if (to->nsub != from->nsub)
return;
for (i = 0; i < to->nsub; i++)
@@ -138,6 +140,7 @@
r->lbl.name = strdup(n->lbl.name);
break;
case Ndecl:
+ r->decl.did = maxdid++;
/* sym */
r->decl.name = specializenode(n->decl.name, tsmap);
r->decl.type = tysubst(n->decl.type, tsmap);
@@ -205,7 +208,7 @@
d = getdcl(file->file.globls, *name);
if (d)
return d;
- tsmap = mkht(tidhash, tideq);
+ tsmap = mkht(tyhash, tyeq);
fillsubst(tsmap, to, n->decl.type);
d = specializenode(n, tsmap);
d->decl.name = *name;
--- /dev/null
+++ b/test/match.myr
@@ -1,0 +1,13 @@
+const m = {v
+ match v
+ 1: -> 42;;
+ 2: -> 81;;
+ 3: -> 123;;
+ 4: -> 99;;
+ _: -> 8
+ ;;
+}
+
+const main = {
+ -> m(2)
+}