summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-22 01:21:46 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-22 01:21:46 -0800
commitdebcf6f76029eec890192e8ee5b040b47120f91b (patch)
tree5b6b5d72e43c3c342bf4d8fecdcc2631ff06c492
parentaded325cb48f684b3a0849acde7ec31db48733ce (diff)
downloadtxr-debcf6f76029eec890192e8ee5b040b47120f91b.tar.gz
txr-debcf6f76029eec890192e8ee5b040b47120f91b.tar.bz2
txr-debcf6f76029eec890192e8ee5b040b47120f91b.zip
Replacing uses of the eq function which are used only as C booleans,
with just using the == operator. Removing cobj_equal_op since it's indistinguishable from eq. Streamlining missingp and null_or_missing_p. * eval.c (transform_op): eq to ==. (c_var_ops): cobj_equal_op to eq. * filter.c (trie_compress, trie_lookup_feed_char, filter_string_tree, html_hex_continue, html_dec_continue): eq to ==. * hash.c (hash_iter_ops): cobj_equal to eq. * lib.c (countq, getplist, getplist_f, search_str_tree, posq): eq to ==. (cobj_equal_op): Function removed. * lib.h (cobj_equal_op): Declaration removed. (missingp): Becomes a simple macro that yields a C boolean instead of t/nil val, because it's only used that way. (null_or_missing_p): Becomes inline function returning int. * match.c (v_output): eq to ==. * rand.c (random_state_ops): cobj_equal_op to eq. * regex.c (char_set_obj_ops, regex_obj_ops): cobj_equal_op to eq. (reg_derivative): Silly if3 expression replaced by null. (regexp): Redundant if2 expression wrapped around eq removed. * stream.c (null_ops, stdio_ops, tail_ops, pipe_ops, string_in_ops, byte_in_ops, string_out_ops, strlist_out_ops, dir_ops, cat_stream_ops): cobj_equal_op to eq. * syslog.c (syslog_strm_ops): cobj_equal_op to eq.
-rw-r--r--ChangeLog40
-rw-r--r--eval.c4
-rw-r--r--filter.c14
-rw-r--r--hash.c2
-rw-r--r--lib.c15
-rw-r--r--lib.h10
-rw-r--r--match.c2
-rw-r--r--rand.c2
-rw-r--r--regex.c8
-rw-r--r--stream.c20
-rw-r--r--syslog.c2
11 files changed, 78 insertions, 41 deletions
diff --git a/ChangeLog b/ChangeLog
index c5456ce9..5caeed01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,45 @@
2014-02-22 Kaz Kylheku <kaz@kylheku.com>
+ Replacing uses of the eq function which are used only as C booleans,
+ with just using the == operator.
+
+ Removing cobj_equal_op since it's indistinguishable from eq.
+
+ Streamlining missingp and null_or_missing_p.
+
+ * eval.c (transform_op): eq to ==.
+ (c_var_ops): cobj_equal_op to eq.
+
+ * filter.c (trie_compress, trie_lookup_feed_char, filter_string_tree,
+ html_hex_continue, html_dec_continue): eq to ==.
+
+ * hash.c (hash_iter_ops): cobj_equal to eq.
+
+ * lib.c (countq, getplist, getplist_f, search_str_tree,
+ posq): eq to ==.
+ (cobj_equal_op): Function removed.
+
+ * lib.h (cobj_equal_op): Declaration removed.
+ (missingp): Becomes a simple macro that yields a C boolean instead
+ of t/nil val, because it's only used that way.
+ (null_or_missing_p): Becomes inline function returning int.
+
+ * match.c (v_output): eq to ==.
+
+ * rand.c (random_state_ops): cobj_equal_op to eq.
+
+ * regex.c (char_set_obj_ops, regex_obj_ops): cobj_equal_op to eq.
+ (reg_derivative): Silly if3 expression replaced by null.
+ (regexp): Redundant if2 expression wrapped around eq removed.
+
+ * stream.c (null_ops, stdio_ops, tail_ops, pipe_ops, string_in_ops,
+ byte_in_ops, string_out_ops, strlist_out_ops, dir_ops,
+ cat_stream_ops): cobj_equal_op to eq.
+
+ * syslog.c (syslog_strm_ops): cobj_equal_op to eq.
+
+2014-02-22 Kaz Kylheku <kaz@kylheku.com>
+
The C function nullp is being renamed to null, and the rarely
used global variable null which holds a symbol becomes null_s.
diff --git a/eval.c b/eval.c
index 7448ba93..4ef7c007 100644
--- a/eval.c
+++ b/eval.c
@@ -1996,7 +1996,7 @@ static val transform_op(val forms, val syms, val rg)
cdr(cell));
cons_bind (outsyms, outforms, transform_op(re, newsyms, rg));
return cons(outsyms, rlcp(cons(sym, outforms), outforms));
- } else if (eq(vararg, rest_s)) {
+ } else if (vararg == rest_s) {
cons_bind (outsyms, outforms, transform_op(re, syms, rg));
return cons(outsyms, rlcp(cons(rg, outforms), outforms));
}
@@ -2725,7 +2725,7 @@ static void c_var_mark(val obj)
}
static struct cobj_ops c_var_ops = {
- cobj_equal_op,
+ eq,
cobj_print_op,
cobj_destroy_free_op,
c_var_mark,
diff --git a/filter.c b/filter.c
index 29911ba9..4d8f27f2 100644
--- a/filter.c
+++ b/filter.c
@@ -93,7 +93,7 @@ static void trie_compress(val *ptrie)
if (zerop(count)) {
set(*ptrie, value);
- } else if (eq(count, one) && nilp(value)) {
+ } else if (count == one && nilp(value)) {
val iter = hash_begin(trie);
val cell = hash_next(iter);
set(*ptrie, cons(car(cell), cdr(cell)));
@@ -131,7 +131,7 @@ val trie_lookup_feed_char(val node, val ch)
return gethash(node, ch);
if (functionp(node))
return funcall1(node, ch);
- if (consp(node) && eq(ch,car(node)))
+ if (consp(node) && ch == car(node))
return cdr(node);
return nil;
}
@@ -246,9 +246,9 @@ val filter_string_tree(val filter, val obj)
{
val type = typeof(filter);
- if (eq(type, null_s))
+ if (type == null_s)
return obj;
- if (eq(type, hash_s) || eq(type, cons_s))
+ if (type == hash_s || type == cons_s)
return trie_filter_string(filter, obj);
else if (type == fun_s)
return funcall1(filter, obj);
@@ -549,7 +549,7 @@ static val html_hex_continue(val hexlist, val ch)
{
if (iswxdigit(c_chr(ch))) {
return func_f1(cons(ch, hexlist), html_hex_continue);
- } if (eq(ch, chr(';'))) {
+ } if (ch == chr(';')) {
wchar_t out[2] = { 0 };
val iter;
@@ -573,7 +573,7 @@ static val html_dec_continue(val declist, val ch)
{
if (iswdigit(c_chr(ch))) {
return func_f1(cons(ch, declist), html_dec_continue);
- } if (eq(ch, chr(';'))) {
+ } if (ch == chr(';')) {
wchar_t out[2] = { 0 };
val iter;
@@ -592,7 +592,7 @@ static val html_dec_continue(val declist, val ch)
static val html_numeric_handler(val ch)
{
- if (eq(ch, chr('x')))
+ if (ch == chr('x'))
return func_f1(nil, html_hex_continue);
if (!iswdigit(c_chr(ch)))
return nil;
diff --git a/hash.c b/hash.c
index 48aa3cea..96a4f802 100644
--- a/hash.c
+++ b/hash.c
@@ -637,7 +637,7 @@ static void hash_iter_mark(val hash_iter)
}
static struct cobj_ops hash_iter_ops = {
- cobj_equal_op,
+ eq,
cobj_print_op,
cobj_destroy_free_op,
hash_iter_mark,
diff --git a/lib.c b/lib.c
index b082c7fe..7037585f 100644
--- a/lib.c
+++ b/lib.c
@@ -1014,7 +1014,7 @@ val countq(val obj, val list)
val count = zero;
for (; list; list = cdr(list))
- if (eq(car(list), obj))
+ if (car(list) == obj)
count = plus(count, one);
return count;
@@ -1276,11 +1276,6 @@ val equal(val left, val right)
internal_error("unhandled case in equal function");
}
-val cobj_equal_op(val left, val right)
-{
- return eq(left, right);
-}
-
static mem_t *malloc_low_bound, *malloc_high_bound;
mem_t *chk_malloc(size_t size)
@@ -1444,7 +1439,7 @@ val getplist(val list, val key)
{
for (; list; list = cdr(cdr(list))) {
val ind = first(list);
- if (eq(ind, key))
+ if (ind == key)
return second(list);
}
@@ -1455,7 +1450,7 @@ val getplist_f(val list, val key, val *found)
{
for (; list; list = cdr(cdr(list))) {
val ind = first(list);
- if (eq(ind, key)) {
+ if (ind == key) {
*found = t;
return second(list);
}
@@ -1979,7 +1974,7 @@ val search_str_tree(val haystack, val tree, val start_num, val from_end)
val result = search_str_tree(haystack, car(tree), start_num, from_end);
if (result) {
cons_bind (pos, len, result);
- if (!it || lt(pos, minpos) || (eq(pos, minpos) && gt(len, maxlen))) {
+ if (!it || lt(pos, minpos) || (pos == minpos && gt(len, maxlen))) {
minpos = pos;
maxlen = len;
it = result;
@@ -4815,7 +4810,7 @@ val posq(val obj, val list)
val pos = zero;
for (; list; list = cdr(list), pos = plus(pos, one))
- if (eq(car(list), obj))
+ if (car(list) == obj)
return pos;
return nil;
diff --git a/lib.h b/lib.h
index d817857d..d3f251fc 100644
--- a/lib.h
+++ b/lib.h
@@ -193,8 +193,10 @@ struct cobj_ops {
cnum (*hash)(val self);
};
-/* Default operations for above structure. */
-val cobj_equal_op(val, val);
+/* Default operations for above structure.
+ * Default equal is eq
+ */
+
void cobj_print_op(val, val);
void cobj_destroy_stub_op(val);
void cobj_destroy_free_op(val);
@@ -725,9 +727,9 @@ INLINE val null(val v) { return v ? nil : t; }
#define nao ((obj_t *) (1 << TAG_SHIFT)) /* "not an object" sentinel value. */
-INLINE val missingp(val v) { return v == colon_k ? t : nil; }
+#define missingp(v) ((v) == colon_k)
-INLINE val null_or_missing_p(val v) { return (!v || v == colon_k) ? t : nil; }
+INLINE int null_or_missing_p(val v) { return (nilp(v) || missingp(v)); }
#define if2(a, b) ((a) ? (b) : nil)
diff --git a/match.c b/match.c
index d7ae2894..dd9cbc42 100644
--- a/match.c
+++ b/match.c
@@ -3047,7 +3047,7 @@ static val v_output(match_files_ctx *c)
val alist;
fpip_t fp;
- if (eq(first(dest_spec), nothrow_k)) {
+ if (first(dest_spec) == nothrow_k) {
if (rest(dest_spec))
sem_error(specline, lit("material after :nothrow in output"), nao);
} else if (!keywordp(first(dest_spec))) {
diff --git a/rand.c b/rand.c
index 6e4988a9..b5cf6586 100644
--- a/rand.c
+++ b/rand.c
@@ -63,7 +63,7 @@ val random_state;
val random_state_s;
static struct cobj_ops random_state_ops = {
- cobj_equal_op,
+ eq,
cobj_print_op,
cobj_destroy_free_op,
cobj_mark_op,
diff --git a/regex.c b/regex.c
index f0dcb85b..2e24338d 100644
--- a/regex.c
+++ b/regex.c
@@ -761,7 +761,7 @@ static void char_set_cobj_destroy(val chset)
}
static struct cobj_ops char_set_obj_ops = {
- cobj_equal_op,
+ eq,
cobj_print_op,
char_set_cobj_destroy,
cobj_mark_op,
@@ -1264,7 +1264,7 @@ static void regex_destroy(val regex)
}
static struct cobj_ops regex_obj_ops = {
- cobj_equal_op,
+ eq,
cobj_print_op,
regex_destroy,
cobj_mark_op,
@@ -1501,7 +1501,7 @@ static val reg_derivative(val exp, val ch)
if (exp == nil || exp == t) {
return t;
} else if (chrp(exp)) {
- return if3(eq(exp, ch), nil, t);
+ return null(eq(exp, ch));
} else if (typeof(exp) == chset_s) {
char_set_t *set = (char_set_t *) exp->co.handle;
return if3(char_set_contains(set, c_chr(ch)), nil, t);
@@ -1635,7 +1635,7 @@ val regex_compile(val regex_sexp, val error_stream)
val regexp(val obj)
{
if (consp(obj))
- return if2(eq(car(obj), compiled_regex_s), t);
+ return eq(car(obj), compiled_regex_s);
return typeof(obj) == regex_s ? t : nil;
}
diff --git a/stream.c b/stream.c
index 65fec6fd..a0bcf33e 100644
--- a/stream.c
+++ b/stream.c
@@ -87,7 +87,7 @@ static val null_get_prop(val stream, val ind)
}
static struct strm_ops null_ops = {
- { cobj_equal_op,
+ { eq,
null_stream_print,
cobj_destroy_stub_op,
cobj_mark_op,
@@ -419,7 +419,7 @@ static val stdio_close(val stream, val throw_on_error)
}
static struct strm_ops stdio_ops = {
- { cobj_equal_op,
+ { eq,
stdio_stream_print,
stdio_stream_destroy,
stdio_stream_mark,
@@ -599,7 +599,7 @@ static val tail_get_byte(val stream)
static struct strm_ops tail_ops = {
- { cobj_equal_op,
+ { eq,
stdio_stream_print,
stdio_stream_destroy,
stdio_stream_mark,
@@ -689,7 +689,7 @@ static val pipe_close(val stream, val throw_on_error)
}
static struct strm_ops pipe_ops = {
- { cobj_equal_op,
+ { eq,
stdio_stream_print,
stdio_stream_destroy,
stdio_stream_mark,
@@ -791,7 +791,7 @@ static val string_in_get_prop(val stream, val ind)
}
static struct strm_ops string_in_ops = {
- { cobj_equal_op,
+ { eq,
cobj_print_op,
cobj_destroy_stub_op,
string_in_stream_mark,
@@ -852,7 +852,7 @@ static val byte_in_unget_byte(val stream, int byte)
}
static struct strm_ops byte_in_ops = {
- { cobj_equal_op,
+ { eq,
cobj_print_op,
byte_in_stream_destroy,
cobj_mark_op,
@@ -980,7 +980,7 @@ static val string_out_put_byte(val stream, int ch)
}
static struct strm_ops string_out_ops = {
- { cobj_equal_op,
+ { eq,
cobj_print_op,
string_out_stream_destroy,
cobj_mark_op,
@@ -1053,7 +1053,7 @@ static val strlist_out_put_char(val stream, val ch)
}
static struct strm_ops strlist_out_ops = {
- { cobj_equal_op,
+ { eq,
cobj_print_op,
cobj_destroy_stub_op,
strlist_mark,
@@ -1127,7 +1127,7 @@ static val dir_close(val stream, val throw_on_error)
}
static struct strm_ops dir_ops = {
- { cobj_equal_op,
+ { eq,
cobj_print_op,
common_destroy,
cobj_mark_op,
@@ -2334,7 +2334,7 @@ static val cat_get_prop(val stream, val ind)
}
static struct strm_ops cat_stream_ops = {
- { cobj_equal_op,
+ { eq,
cat_stream_print,
cobj_destroy_stub_op,
cobj_mark_op,
diff --git a/syslog.c b/syslog.c
index e42ff0b8..d252f2f9 100644
--- a/syslog.c
+++ b/syslog.c
@@ -209,7 +209,7 @@ static val syslog_set_prop(val stream, val ind, val prop)
}
static struct strm_ops syslog_strm_ops = {
- { cobj_equal_op,
+ { eq,
cobj_print_op,
cobj_destroy_stub_op,
syslog_mark,