summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-11-03 10:49:27 -0700
committerOri Bernstein <ori@markovcorp.com>2017-11-03 10:49:27 -0700
commita71830b132d331ce7ef82058a8f3bdab8aa5d400 (patch)
tree0c981818b4e5353b361bbabf1cc4ef2d96edf5ac
parentda847fae9a4f2d3f6ed974a7b14912a8f66fc8b3 (diff)
downloadmc-hashtraits.tar.gz
Rename comparable => equatablehashtraits
-rw-r--r--lib/date/parse.myr2
-rw-r--r--lib/fileutil/loopcheck+posixy.myr4
-rw-r--r--lib/inifile/types.myr8
-rw-r--r--lib/std/bitset.myr6
-rw-r--r--lib/std/hashfuncs.myr12
-rw-r--r--lib/std/htab.myr4
-rw-r--r--lib/std/test/hashfuncs.myr12
-rw-r--r--lib/std/test/htab.myr4
-rw-r--r--lib/std/test/striter.myr2
-rw-r--r--lib/std/traits.myr4
-rw-r--r--parse/use.c9
11 files changed, 36 insertions, 31 deletions
diff --git a/lib/date/parse.myr b/lib/date/parse.myr
index 559edc3..96a7b2f 100644
--- a/lib/date/parse.myr
+++ b/lib/date/parse.myr
@@ -164,7 +164,7 @@ const eatspace = {s
const indexof = {dst, s, set, err
for var i = 0; i < set.len; i++
- if s.len >= set[i].len && std.cmp(s[:set[i].len], set[i])
+ if s.len >= set[i].len && std.eq(s[:set[i].len], set[i])
dst# = i
-> s[set[i].len:]
;;
diff --git a/lib/fileutil/loopcheck+posixy.myr b/lib/fileutil/loopcheck+posixy.myr
index 0a311bf..c01e109 100644
--- a/lib/fileutil/loopcheck+posixy.myr
+++ b/lib/fileutil/loopcheck+posixy.myr
@@ -57,8 +57,8 @@ impl std.hashable (int64, int64) =
}
;;
-impl std.comparable (int64, int64) =
- cmp = {a, b
+impl std.equatable (int64, int64) =
+ eq = {a, b
var adev, aino
var bdev, bino
diff --git a/lib/inifile/types.myr b/lib/inifile/types.myr
index f2736e0..d91f7e1 100644
--- a/lib/inifile/types.myr
+++ b/lib/inifile/types.myr
@@ -13,7 +13,7 @@ pkg inifile =
;;
impl std.hashable (byte[:], byte[:])
- impl std.comparable (byte[:], byte[:])
+ impl std.equatable (byte[:], byte[:])
;;
impl std.hashable (byte[:], byte[:]) =
@@ -25,13 +25,13 @@ impl std.hashable (byte[:], byte[:]) =
}
;;
-impl std.comparable (byte[:], byte[:]) =
- cmp = {a, b
+impl std.equatable (byte[:], byte[:]) =
+ eq = {a, b
var s1, k1
var s2, k2
(s1, k1) = a
(s2, k2) = a
- -> std.cmp(s1, s2) && std.cmp(k1, k2)
+ -> std.eq(s1, s2) && std.eq(k1, k2)
}
;;
diff --git a/lib/std/bitset.myr b/lib/std/bitset.myr
index 3786758..ce750db 100644
--- a/lib/std/bitset.myr
+++ b/lib/std/bitset.myr
@@ -31,7 +31,7 @@ pkg std =
const bsunion : (a : bitset#, b : bitset# -> void)
const bsissubset : (a : bitset#, b : bitset# -> bool)
- impl comparable bitset#
+ impl equatable bitset#
impl hashable bitset#
type bsiter = struct
@@ -147,8 +147,8 @@ const bsissubset = {a, b
-> true
}
-impl comparable bitset# =
- cmp = {a, b
+impl equatable bitset# =
+ eq = {a, b
eqsz(a, b)
for var i = 0; i < a.bits.len; i++
if a.bits[i] != b.bits[i]
diff --git a/lib/std/hashfuncs.myr b/lib/std/hashfuncs.myr
index fa72f90..5ad1180 100644
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -11,8 +11,8 @@ use "utf"
pkg std =
const siphash24 : (data : byte[:], seed : byte[16] -> uint64)
- impl comparable @a[:] =
- cmp = {a, b
+ impl equatable @a[:] =
+ eq = {a, b
-> sleq(a, b)
}
;;
@@ -23,8 +23,8 @@ pkg std =
}
;;
- impl comparable @a::(integral,numeric) =
- cmp = {a, b
+ impl equatable @a::(integral,numeric) =
+ eq = {a, b
-> a == b
}
;;
@@ -35,8 +35,8 @@ pkg std =
}
;;
- impl comparable @a# =
- cmp = {a, b
+ impl equatable @a# =
+ eq = {a, b
-> a == b
}
;;
diff --git a/lib/std/htab.myr b/lib/std/htab.myr
index 368389f..771f47f 100644
--- a/lib/std/htab.myr
+++ b/lib/std/htab.myr
@@ -93,7 +93,7 @@ generic idx = {ht, k
if ht.hashes[i] == 0
-> `None
;;
- if ht.hashes[i] == h && !ht.dead[i] && cmp(ht.keys[i], k)
+ if ht.hashes[i] == h && !ht.dead[i] && eq(ht.keys[i], k)
break
;;
di++
@@ -138,7 +138,7 @@ generic htput = {ht, k, v
i = h & (ht.keys.len - 1)
neltincr = 1
while ht.hashes[i] != 0 && !ht.dead[i]
- if ht.hashes[i] == h && cmp(ht.keys[i], k)
+ if ht.hashes[i] == h && eq(ht.keys[i], k)
neltincr = 0
break
;;
diff --git a/lib/std/test/hashfuncs.myr b/lib/std/test/hashfuncs.myr
index 5813663..35cf20c 100644
--- a/lib/std/test/hashfuncs.myr
+++ b/lib/std/test/hashfuncs.myr
@@ -5,19 +5,19 @@ const main = {
testr.run([
[.name="string hash and equality", .fn={ctx
testr.check(ctx, std.hash("abc") == 0x5dbcfa53aa2007a5, "wrong hash\n")
- testr.check(ctx, std.cmp("abc\0def", "abc\0def"), "equal strings not equal\n")
- testr.check(ctx, !std.cmp("abc\0def", "abcdef"), "unequal strings are equal\n")
+ testr.check(ctx, std.eq("abc\0def", "abc\0def"), "equal strings not equal\n")
+ testr.check(ctx, !std.eq("abc\0def", "abcdef"), "unequal strings are equal\n")
}],
[.name="pointer equality", .fn={ctx
var x, y: int
/* can't sanely test ptrhash; it will change every time */
- testr.check(ctx, std.cmp(&x, &x), "equal pointers not equal")
- testr.check(ctx, !std.cmp(&x, &y), "unequal pointers are equal")
+ testr.check(ctx, std.eq(&x, &x), "equal pointers not equal")
+ testr.check(ctx, !std.eq(&x, &y), "unequal pointers are equal")
}],
[.name="int hash and equality", .fn={ctx
testr.check(ctx, std.hash(123) == 0x5671db246859d5b6, "wrong int hash")
- testr.check(ctx, std.cmp(123, 123), "equal integers not equal")
- testr.check(ctx, !std.cmp(123, 456), "unequal integers are equal")
+ testr.check(ctx, std.eq(123, 123), "equal integers not equal")
+ testr.check(ctx, !std.eq(123, 456), "unequal integers are equal")
}],
[.name="siphash test", .fn={ctx
siphashreferencetestvector(ctx)
diff --git a/lib/std/test/htab.myr b/lib/std/test/htab.myr
index b2612c4..16040f0 100644
--- a/lib/std/test/htab.myr
+++ b/lib/std/test/htab.myr
@@ -103,8 +103,8 @@ impl std.hashable collisionprone =
}
;;
-impl std.comparable collisionprone =
- cmp = {a, b
+impl std.equatable collisionprone =
+ eq = {a, b
-> a == b
}
;;
diff --git a/lib/std/test/striter.myr b/lib/std/test/striter.myr
index 8a4397e..b54e580 100644
--- a/lib/std/test/striter.myr
+++ b/lib/std/test/striter.myr
@@ -13,7 +13,7 @@ const main = {
i = 0
for sp : std.bysplit("foo+++bar", "++")
- std.assert(std.cmp(splits[i++], sp), "wrong split {}", sp)
+ std.assert(std.eq(splits[i++], sp), "wrong split {}", sp)
;;
std.assert(i == splits.len, "wrong split count")
}
diff --git a/lib/std/traits.myr b/lib/std/traits.myr
index 1c5678b..3c69fed 100644
--- a/lib/std/traits.myr
+++ b/lib/std/traits.myr
@@ -1,6 +1,6 @@
pkg std =
- trait comparable @a =
- cmp : (a : @a, b : @a -> bool)
+ trait equatable @a =
+ eq : (a : @a, b : @a -> bool)
;;
trait hashable @a =
diff --git a/parse/use.c b/parse/use.c
index 3163b2f..3fb7118 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -852,11 +852,16 @@ protomap(Trait *tr, Type *ty, Node *dcl)
{
size_t i, len;
char *protoname, *dclname, *p;
- Node *proto;
+ Node *proto, *n;
+ Stab *st;
dclname = declname(dcl);
for (i = 0; i < tr->nproto; i++) {
- proto = getdcl(curstab(), tr->proto[i]->decl.name);
+ n = tr->proto[i]->decl.name;
+ st = file->file.globls;
+ if (n->name.ns)
+ st = getns(n->name.ns);
+ proto = getdcl(st, n);
if (!proto)
proto = tr->proto[i];
protoname = declname(proto);