summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-10-17 20:17:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-10-17 20:17:22 -0700
commit9b18f519decaf0cd7f52571c3c44012e3fc23a3a (patch)
tree5848a0bfd530e51183dbbf1e201a56ccf437fbd1 /hash.c
parent9f158a44b7e88c1dcfb8d56f4f85d642fc423b59 (diff)
downloadtxr-9b18f519decaf0cd7f52571c3c44012e3fc23a3a.tar.gz
txr-9b18f519decaf0cd7f52571c3c44012e3fc23a3a.tar.bz2
txr-9b18f519decaf0cd7f52571c3c44012e3fc23a3a.zip
Converting cast expressions to macros that are retargetted
to C++ style casts when compiling as C++. * lib.h (strip_qual, convert, coerce): New casting macros. (TAG_MASK, tag, type, wli_noex, auto_str, static_str, litptr, num_fast, chr, lit_noex, nil, nao): Use cast macros. * arith.c (mul, isqrt_fixnum, bit): Use cast macros. * configure (INT_PTR_MAX): Define using cast macro. * debug.c (debug_init): Use cast macro. * eval.c (do_eval, expand_macro, reg_op, reg_mac, eval_init): Use cast macros. * filter.c (filter_init): Use cast macro. * gc.c (more, mark_obj, in_heap, mark, sweep_one, unmark): Use cast macros. * hash.c (hash_double, equal_hash, eql_hash, hash_equal_op, hash_hash_op, hash_print_op, hash_mark, make_hash, make_similar_hash, copy_hash, gethash_c, gethash, gethash_f, gethash_n, remhash, hash_count, get_hash_userdata, set_hash_userdata, hash_iter_destroy, hash_iter_mark, hash_begin, hash_uni, hash_diff, hash_isec): Use cast macros. * lib.c (code2type, chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc, chk_strdup, num, c_num, string, mkstring, mkustring, upcase_str, downcase_str, string_extend, sub_str, cat_str, trim_str, c_chr, vector, vec_set_length, copy_vec, sub_vec, cat_vec, cobj_print_op, obj_init): Likewise. * match.c (do_match_line, hv_trampoline, match_files, dir_tables_init): Likewise. * parser.l (grammar): Likewise. * parser.y (parse): Likewise. * rand.c (make_state, make_random_state, random_fixnum, random): Likewise. * regex.c (CHAR_SET_L2_LO, CHAR_SET_L2_HI, CHAR_SET_L1_LO, CHAR_SET_L1_HI, CHAR_SET_L0_LO, CHAR_SET_L0_HI, L0_full, L0_fill_range, L1_full, L1_fill_range, L1_contains, L1_free, L2_full, L2_fill_range, L2_contains, L2_free, L3_fill_range, L3_contains, L3_free, char_set_create, char_set_cobj_destroy, nfa_state_accept, nfa_state_empty, nfa_state_single, nfa_state_wild, nfa_state_set,
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c90
1 files changed, 45 insertions, 45 deletions
diff --git a/hash.c b/hash.c
index 25ad277d..a591afbf 100644
--- a/hash.c
+++ b/hash.c
@@ -105,7 +105,7 @@ static cnum hash_double(double n)
unsigned long h = 0;
#endif
- mem_t *p = (mem_t *) &n, *q = p + sizeof(double);
+ mem_t *p = coerce(mem_t *, &n), *q = p + sizeof(double);
while (p < q) {
h = h << 8 | h >> (8 * sizeof h - 1);
@@ -135,13 +135,13 @@ static cnum equal_hash(val obj)
case ENV:
switch (sizeof (mem_t *)) {
case 4:
- return (((cnum) obj) >> 4) & NUM_MAX;
+ return (coerce(cnum, obj) >> 4) & NUM_MAX;
case 8: default:
- return (((cnum) obj) >> 5) & NUM_MAX;
+ return (coerce(cnum, obj) >> 5) & NUM_MAX;
}
break;
case FUN:
- return ((cnum) obj->f.f.interp_fun + equal_hash(obj->f.env)) & NUM_MAX;
+ return (coerce(cnum, obj->f.f.interp_fun) + equal_hash(obj->f.env)) & NUM_MAX;
case VEC:
{
val length = obj->v.vec[vec_length];
@@ -183,9 +183,9 @@ static cnum eql_hash(val obj)
default:
switch (sizeof (mem_t *)) {
case 4:
- return (((cnum) obj) >> 4) & NUM_MAX;
+ return (coerce(cnum, obj) >> 4) & NUM_MAX;
case 8: default:
- return (((cnum) obj) >> 5) & NUM_MAX;
+ return (coerce(cnum, obj) >> 5) & NUM_MAX;
}
}
case TAG_CHR:
@@ -195,9 +195,9 @@ static cnum eql_hash(val obj)
case TAG_LIT:
switch (sizeof (mem_t *)) {
case 4:
- return (((cnum) obj) >> 2) & NUM_MAX;
+ return (coerce(cnum, obj) >> 2) & NUM_MAX;
case 8: default:
- return (((cnum) obj) >> 3) & NUM_MAX;
+ return (coerce(cnum, obj) >> 3) & NUM_MAX;
}
}
/* notreached */
@@ -208,9 +208,9 @@ cnum cobj_hash_op(val obj)
{
switch (sizeof (mem_t *)) {
case 4:
- return (((cnum) obj) >> 4) & NUM_MAX;
+ return (coerce(cnum, obj) >> 4) & NUM_MAX;
case 8: default:
- return (((cnum) obj) >> 5) & NUM_MAX;
+ return (coerce(cnum, obj) >> 5) & NUM_MAX;
}
/* notreached */
abort();
@@ -228,8 +228,8 @@ static val print_key_val(val out, val key, val value)
static val hash_equal_op(val left, val right)
{
uses_or2;
- struct hash *l = (struct hash *) left->co.handle;
- struct hash *r = (struct hash *) right->co.handle;
+ struct hash *l = coerce(struct hash *, left->co.handle);
+ struct hash *r = coerce(struct hash *, right->co.handle);
val liter, riter, lcell, rcell;
val free_conses = nil;
val pending = nil;
@@ -314,14 +314,14 @@ static val hash_equal_op(val left, val right)
static cnum hash_hash_op(val obj)
{
cnum out = 0;
- struct hash *h = (struct hash *) obj->co.handle;
+ struct hash *h = coerce(struct hash *, obj->co.handle);
val iter, cell;
switch (sizeof (mem_t *)) {
case 4:
- out += ((cnum) h->hash_fun) >> 4;
+ out += coerce(cnum, h->hash_fun) >> 4;
case 8: default:
- out += ((cnum) h->hash_fun) >> 5;
+ out += coerce(cnum, h->hash_fun) >> 5;
}
out += equal_hash(h->userdata);
@@ -339,7 +339,7 @@ static cnum hash_hash_op(val obj)
static void hash_print_op(val hash, val out)
{
- struct hash *h = (struct hash *) hash->co.handle;
+ struct hash *h = coerce(struct hash *, hash->co.handle);
int need_space = 0;
put_string(lit("#H(("), out);
@@ -371,7 +371,7 @@ static void hash_print_op(val hash, val out)
static void hash_mark(val hash)
{
- struct hash *h = (struct hash *) hash->co.handle;
+ struct hash *h = coerce(struct hash *, hash->co.handle);
cnum i;
gc_mark(h->userdata);
@@ -463,12 +463,12 @@ val make_hash(val weak_keys, val weak_vals, val equal_based)
nao);
} else {
int flags = ((weak_vals != nil) << 1) | (weak_keys != nil);
- struct hash *h = (struct hash *) chk_malloc(sizeof *h);
+ struct hash *h = coerce(struct hash *, chk_malloc(sizeof *h));
val mod = num_fast(256);
val table = vector(mod, nil);
- val hash = cobj((mem_t *) h, hash_s, &hash_ops);
+ val hash = cobj(coerce(mem_t *, h), hash_s, &hash_ops);
- h->flags = (hash_flags_t) flags;
+ h->flags = convert(hash_flags_t, flags);
h->modulus = c_num(mod);
h->count = 0;
h->table = table;
@@ -485,11 +485,11 @@ val make_hash(val weak_keys, val weak_vals, val equal_based)
val make_similar_hash(val existing)
{
- struct hash *ex = (struct hash *) cobj_handle(existing, hash_s);
- struct hash *h = (struct hash *) chk_malloc(sizeof *h);
+ struct hash *ex = coerce(struct hash *, cobj_handle(existing, hash_s));
+ struct hash *h = coerce(struct hash *, chk_malloc(sizeof *h));
val mod = num_fast(256);
val table = vector(mod, nil);
- val hash = cobj((mem_t *) h, hash_s, &hash_ops);
+ val hash = cobj(coerce(mem_t *, h), hash_s, &hash_ops);
h->modulus = c_num(mod);
h->count = 0;
@@ -507,9 +507,9 @@ val make_similar_hash(val existing)
val copy_hash(val existing)
{
- struct hash *ex = (struct hash *) cobj_handle(existing, hash_s);
- struct hash *h = (struct hash *) chk_malloc(sizeof *h);
- val hash = cobj((mem_t *) h, hash_s, &hash_ops);
+ struct hash *ex = coerce(struct hash *, cobj_handle(existing, hash_s));
+ struct hash *h = coerce(struct hash *, chk_malloc(sizeof *h));
+ val hash = cobj(coerce(mem_t *, h), hash_s, &hash_ops);
val mod = num_fast(ex->modulus);
val iter;
@@ -531,7 +531,7 @@ val copy_hash(val existing)
val gethash_c(val hash, val key, loc new_p)
{
- struct hash *h = (struct hash *) cobj_handle(hash, hash_s);
+ struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s));
loc pchain = vecref_l(h->table, num_fast(h->hash_fun(key) % h->modulus));
val old = deref(pchain);
val cell = h->acons_new_c_fun(key, new_p, pchain);
@@ -542,7 +542,7 @@ val gethash_c(val hash, val key, loc new_p)
val gethash(val hash, val key)
{
- struct hash *h = (struct hash *) cobj_handle(hash, hash_s);
+ struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s));
val chain = vecref(h->table, num_fast(h->hash_fun(key) % h->modulus));
val found = h->assoc_fun(key, chain);
return cdr(found);
@@ -566,7 +566,7 @@ val inhash(val hash, val key, val init)
val gethash_f(val hash, val key, loc found)
{
- struct hash *h = (struct hash *) cobj_handle(hash, hash_s);
+ struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s));
val chain = vecref(h->table, num_fast(h->hash_fun(key) % h->modulus));
set(found, h->assoc_fun(key, chain));
return cdr(deref(found));
@@ -574,7 +574,7 @@ val gethash_f(val hash, val key, loc found)
val gethash_n(val hash, val key, val notfound_val)
{
- struct hash *h = (struct hash *) cobj_handle(hash, hash_s);
+ struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s));
val chain = vecref(h->table, num_fast(h->hash_fun(key) % h->modulus));
val existing = h->assoc_fun(key, chain);
return if3(existing, cdr(existing), default_bool_arg(notfound_val));
@@ -596,7 +596,7 @@ val pushhash(val hash, val key, val value)
val remhash(val hash, val key)
{
- struct hash *h = (struct hash *) cobj_handle(hash, hash_s);
+ struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s));
loc pchain = vecref_l(h->table, num_fast(h->hash_fun(key) % h->modulus));
val existing = h->assoc_fun(key, deref(pchain));
@@ -612,19 +612,19 @@ val remhash(val hash, val key)
val hash_count(val hash)
{
- struct hash *h = (struct hash *) cobj_handle(hash, hash_s);
+ struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s));
return num_fast(h->count);
}
val get_hash_userdata(val hash)
{
- struct hash *h = (struct hash *) cobj_handle(hash, hash_s);
+ struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s));
return h->userdata;
}
val set_hash_userdata(val hash, val data)
{
- struct hash *h = (struct hash *) cobj_handle(hash, hash_s);
+ struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s));
val olddata = h->userdata;
set(mkloc(h->userdata, hash), data);
return olddata;
@@ -637,7 +637,7 @@ val hashp(val obj)
static void hash_iter_mark(val hash_iter)
{
- struct hash_iter *hi = (struct hash_iter *) hash_iter->co.handle;
+ struct hash_iter *hi = coerce(struct hash_iter *, hash_iter->co.handle);
gc_mark(hi->hash);
gc_mark(hi->cons);
}
@@ -656,20 +656,20 @@ val hash_begin(val hash)
struct hash_iter *hi;
class_check (hash, hash_s);
- hi = (struct hash_iter *) chk_malloc(sizeof *hi);
+ hi = coerce(struct hash_iter *, chk_malloc(sizeof *hi));
hi->hash = nil;
hi->chain = -1;
hi->cons = nil;
- hi_obj = cobj((mem_t *) hi, hash_iter_s, &hash_iter_ops);
+ hi_obj = cobj(coerce(mem_t *, hi), hash_iter_s, &hash_iter_ops);
hi->hash = hash;
return hi_obj;
}
val hash_next(val iter)
{
- struct hash_iter *hi = (struct hash_iter *) cobj_handle(iter, hash_iter_s);
+ struct hash_iter *hi = coerce(struct hash_iter *, cobj_handle(iter, hash_iter_s));
val hash = hi->hash;
- struct hash *h = (struct hash *) hash->co.handle;
+ struct hash *h = coerce(struct hash *, hash->co.handle);
if (hi->cons)
hi->cons = cdr(hi->cons);
while (nilp(hi->cons)) {
@@ -926,8 +926,8 @@ val hash_alist(val hash)
val hash_uni(val hash1, val hash2, val join_func)
{
- struct hash *h1 = (struct hash *) cobj_handle(hash1, hash_s);
- struct hash *h2 = (struct hash *) cobj_handle(hash2, hash_s);
+ struct hash *h1 = coerce(struct hash *, cobj_handle(hash1, hash_s));
+ struct hash *h2 = coerce(struct hash *, cobj_handle(hash2, hash_s));
if (h1->hash_fun != h2->hash_fun)
uw_throwf(error_s, lit("hash-uni: ~a and ~a are incompatible hashes"), hash1, hash2, nao);
@@ -961,8 +961,8 @@ val hash_uni(val hash1, val hash2, val join_func)
val hash_diff(val hash1, val hash2)
{
- struct hash *h1 = (struct hash *) cobj_handle(hash1, hash_s);
- struct hash *h2 = (struct hash *) cobj_handle(hash2, hash_s);
+ struct hash *h1 = coerce(struct hash *, cobj_handle(hash1, hash_s));
+ struct hash *h2 = coerce(struct hash *, cobj_handle(hash2, hash_s));
if (h1->hash_fun != h2->hash_fun)
uw_throwf(error_s, lit("hash-diff: ~a and ~a are incompatible hashes"), hash1, hash2, nao);
@@ -984,8 +984,8 @@ val hash_diff(val hash1, val hash2)
val hash_isec(val hash1, val hash2, val join_func)
{
- struct hash *h1 = (struct hash *) cobj_handle(hash1, hash_s);
- struct hash *h2 = (struct hash *) cobj_handle(hash2, hash_s);
+ struct hash *h1 = coerce(struct hash *, cobj_handle(hash1, hash_s));
+ struct hash *h2 = coerce(struct hash *, cobj_handle(hash2, hash_s));
if (h1->hash_fun != h2->hash_fun)
uw_throwf(error_s, lit("hash-uni: ~a and ~a are incompatible hashes"), hash1, hash2, nao);