summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-22 00:58:18 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-22 00:58:18 -0800
commitaded325cb48f684b3a0849acde7ec31db48733ce (patch)
treeb87dce2ae9df01a1f66d3c2ff43af93e3047387e
parent9462f8c7b3d57ccaaa73fd0e891f8a82b41c4b84 (diff)
downloadtxr-aded325cb48f684b3a0849acde7ec31db48733ce.tar.gz
txr-aded325cb48f684b3a0849acde7ec31db48733ce.tar.bz2
txr-aded325cb48f684b3a0849acde7ec31db48733ce.zip
The C function nullp is being renamed to null, and the rarely
used global variable null which holds a symbol becomes null_s. A new macro called nilp is added that more efficiently checks whether an object is nil, producing a C boolean value rather than t or nil. Most of the uses of nullp in the codebase just become the more streamlined nilp. * debug.c (show_bindings): nullp to nilp * eval.c (lookup_var, lookup_var_l, lookup_fun, lookup_sym_lisp1, do_eval, expand_qquote, expand_quasi, expand_op): nullp to nilp. (op_modplace): nullp to null. (eval_init): Update registration of null and not from C function nullp to null. * filter.c (trie_compress, html_hex_continue): nullp to nil. (filter_string_tree): null to null_s. * hash.c (hash_next): nullp to nilp. * lib.c (null): Variable renamed to null_s. (code2type): null to null_s. (lazy_flatten_scan, chainv, lazy_str, lazy_str_force_upto, obj_print, obj_pprint): nullp to nilp. (obj_init): null to null_s; nullp to null. * lib.h (null): declaration changed to null_s. (nullp): Inline function renamed to null. (nilp): New macro. * match.c (do_match_line): nullp to nilp. * rand.c (make_random_state): Likewise. * regex.c (compile_regex): Likewise.
-rw-r--r--ChangeLog41
-rw-r--r--debug.c2
-rw-r--r--eval.c22
-rw-r--r--filter.c6
-rw-r--r--hash.c2
-rw-r--r--lib.c20
-rw-r--r--lib.h7
-rw-r--r--match.c2
-rw-r--r--rand.c2
-rw-r--r--regex.c2
10 files changed, 75 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index a6c26d3c..c5456ce9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,46 @@
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.
+
+ A new macro called nilp is added that more efficiently checks whether
+ an object is nil, producing a C boolean value rather than t or nil.
+
+ Most of the uses of nullp in the codebase just become the more
+ streamlined nilp.
+
+ * debug.c (show_bindings): nullp to nilp
+
+ * eval.c (lookup_var, lookup_var_l, lookup_fun, lookup_sym_lisp1,
+ do_eval, expand_qquote, expand_quasi, expand_op): nullp to nilp.
+ (op_modplace): nullp to null.
+ (eval_init): Update registration of null and not from C function
+ nullp to null.
+
+ * filter.c (trie_compress, html_hex_continue): nullp to nil.
+ (filter_string_tree): null to null_s.
+
+ * hash.c (hash_next): nullp to nilp.
+
+ * lib.c (null): Variable renamed to null_s.
+ (code2type): null to null_s.
+ (lazy_flatten_scan, chainv, lazy_str, lazy_str_force_upto,
+ obj_print, obj_pprint):
+ nullp to nilp.
+ (obj_init): null to null_s; nullp to null.
+
+ * lib.h (null): declaration changed to null_s.
+ (nullp): Inline function renamed to null.
+ (nilp): New macro.
+
+ * match.c (do_match_line): nullp to nilp.
+
+ * rand.c (make_random_state): Likewise.
+
+ * regex.c (compile_regex): Likewise.
+
+2014-02-22 Kaz Kylheku <kaz@kylheku.com>
+
* parser.y: Bugfix, I think. :) We do not need to call the expander
for a Lisp expression in a quasistring, and doing so leads to a
potentially incorrect double expansion because the whole thing
diff --git a/debug.c b/debug.c
index df8426fe..afef0835 100644
--- a/debug.c
+++ b/debug.c
@@ -71,7 +71,7 @@ static void show_bindings(val env, val stream)
put_string(lit("bindings:\n"), stream);
for (;; level = plus(level, one)) {
- if (nullp(env))
+ if (nilp(env))
break;
else if (consp(env)) {
format(stream, lit("~s: ~s\n"), level, env, nao);
diff --git a/eval.c b/eval.c
index d293feab..7448ba93 100644
--- a/eval.c
+++ b/eval.c
@@ -141,7 +141,7 @@ noreturn static val eval_error(val form, val fmt, ...)
val lookup_var(val env, val sym)
{
- if (nullp(env)) {
+ if (nilp(env)) {
val bind = gethash(top_vb, sym);
if (cobjp(bind)) {
struct c_var *cv = (struct c_var *) cptr_get(bind);
@@ -163,7 +163,7 @@ val lookup_var(val env, val sym)
val *lookup_var_l(val env, val sym)
{
- if (nullp(env)) {
+ if (nilp(env)) {
val bind = gethash(top_vb, sym);
if (cobjp(bind)) {
struct c_var *cv = (struct c_var *) cptr_get(bind);
@@ -186,7 +186,7 @@ val *lookup_var_l(val env, val sym)
val lookup_fun(val env, val sym)
{
- if (nullp(env)) {
+ if (nilp(env)) {
return gethash(top_fb, sym);
} else {
type_check(env, ENV);
@@ -204,7 +204,7 @@ static val lookup_sym_lisp1(val env, val sym)
{
uses_or2;
- if (nullp(env)) {
+ if (nilp(env)) {
val bind = gethash(top_vb, sym);
if (cobjp(bind)) {
struct c_var *cv = (struct c_var *) cptr_get(bind);
@@ -732,7 +732,7 @@ static val do_eval(val form, val env, val ctx_form,
type_check(env, ENV);
debug_check(consp(form) ? form : ctx_form, env, nil, nil, nil, nil);
- if (nullp(form)) {
+ if (nilp(form)) {
debug_return (nil);
} else if (symbolp(form)) {
if (!bindable(form)) {
@@ -1455,7 +1455,7 @@ static val op_modplace(val form, val env)
eval_error(form, lit("~s: superfluous argument"), op, nao);
return pop(loc);
} else if (op == flip_s) {
- return *loc = nullp(*loc);
+ return *loc = null(*loc);
} else if (op == del_s) {
eval_error(form, lit("~s: cannot delete ~a"), op, place, nao);
}
@@ -1809,7 +1809,7 @@ static val expand_place(val place)
static val expand_qquote(val qquoted_form)
{
- if (nullp(qquoted_form)) {
+ if (nilp(qquoted_form)) {
return nil;
} if (atom(qquoted_form)) {
return rlcp(cons(quote_s, cons(qquoted_form, nil)), qquoted_form);
@@ -1905,7 +1905,7 @@ static val expand_vars(val vars, val specials)
static val expand_quasi(val quasi_forms)
{
- if (nullp(quasi_forms)) {
+ if (nilp(quasi_forms)) {
return nil;
} else {
val form = first(quasi_forms);
@@ -2064,7 +2064,7 @@ static val expand_op(val sym, val body)
uses_or2;
val dwim_body = rlcp(cons(dwim_s,
if3(or4(is_op, has_rest, ssyms,
- nullp(proper_listp(body_trans))),
+ null(proper_listp(body_trans))),
body_trans,
append2(body_trans, rest_gensym))),
body_trans);
@@ -2896,8 +2896,8 @@ void eval_init(void)
reg_fun(intern(lit("typeof"), user_package), func_n1(typeof));
reg_fun(intern(lit("atom"), user_package), func_n1(atom));
- reg_fun(intern(lit("null"), user_package), func_n1(nullp));
- reg_fun(intern(lit("not"), user_package), func_n1(nullp));
+ reg_fun(intern(lit("null"), user_package), func_n1(null));
+ reg_fun(intern(lit("not"), user_package), func_n1(null));
reg_fun(intern(lit("consp"), user_package), func_n1(consp));
reg_fun(intern(lit("listp"), user_package), func_n1(listp));
reg_fun(intern(lit("proper-listp"), user_package), func_n1(proper_listp));
diff --git a/filter.c b/filter.c
index f8633b7b..29911ba9 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) && nullp(value)) {
+ } else if (eq(count, one) && nilp(value)) {
val iter = hash_begin(trie);
val cell = hash_next(iter);
set(*ptrie, cons(car(cell), cdr(cell)));
@@ -246,7 +246,7 @@ val filter_string_tree(val filter, val obj)
{
val type = typeof(filter);
- if (eq(type, null))
+ if (eq(type, null_s))
return obj;
if (eq(type, hash_s) || eq(type, cons_s))
return trie_filter_string(filter, obj);
@@ -553,7 +553,7 @@ static val html_hex_continue(val hexlist, val ch)
wchar_t out[2] = { 0 };
val iter;
- if (nullp(hexlist))
+ if (nilp(hexlist))
return nil;
for (iter = nreverse(hexlist); iter; iter = cdr(iter)) {
diff --git a/hash.c b/hash.c
index 55906c2e..48aa3cea 100644
--- a/hash.c
+++ b/hash.c
@@ -666,7 +666,7 @@ val hash_next(val iter)
struct hash *h = (struct hash *) hash->co.handle;
if (hi->cons)
hi->cons = cdr(hi->cons);
- while (nullp(hi->cons)) {
+ while (nilp(hi->cons)) {
if (++hi->chain >= h->modulus)
return nil;
set(hi->cons, vecref(h->table, num_fast(hi->chain)));
diff --git a/lib.c b/lib.c
index 82b1c6c8..b082c7fe 100644
--- a/lib.c
+++ b/lib.c
@@ -68,7 +68,7 @@ val packages;
val system_package, keyword_package, user_package;
-val null, t, cons_s, str_s, chr_s, fixnum_s, sym_s, pkg_s, fun_s, vec_s;
+val null_s, t, cons_s, str_s, chr_s, fixnum_s, sym_s, pkg_s, fun_s, vec_s;
val stream_s, hash_s, hash_iter_s, lcons_s, lstr_s, cobj_s, cptr_s;
val env_s, bignum_s, float_s;
val var_s, expr_s, regex_s, chset_s, set_s, cset_s, wild_s, oneplus_s;
@@ -110,7 +110,7 @@ val identity(val obj)
static val code2type(int code)
{
switch ((type_t) code) {
- case NIL: return null;
+ case NIL: return null_s;
case CONS: return cons_s;
case STR: return str_s;
case LIT: return str_s;
@@ -1101,7 +1101,7 @@ static val lazy_flatten_scan(val list, val *escape)
for (;;) {
if (list) {
val a = car(list);
- if (nullp(a)) {
+ if (nilp(a)) {
list = cdr(list);
} else if (atom(a)) {
return list;
@@ -3738,7 +3738,7 @@ val chainv(val funlist)
static val do_and(val fun1_list, val args)
{
for (; fun1_list; fun1_list = cdr(fun1_list))
- if (nullp(apply(car(fun1_list), args, nil)))
+ if (nilp(apply(car(fun1_list), args, nil)))
return nil;
return t;
@@ -4209,7 +4209,7 @@ val lazy_str(val lst, val term, val limit)
term = default_arg(term, lit("\n"));
limit = default_bool_arg(limit);
- if (nullp(lst)) {
+ if (nilp(lst)) {
obj->ls.prefix = null_string;
obj->ls.list = nil;
} else {
@@ -4251,7 +4251,7 @@ val lazy_str_force_upto(val lstr, val index)
lim = cdr(lstr->ls.opts);
while (ge(index, length_str(lstr->ls.prefix)) && lstr->ls.list &&
- or2(nullp(lim),gt(lim,zero)))
+ or2(null(lim),gt(lim,zero)))
{
val next = pop(&lstr->ls.list);
val term = car(lstr->ls.opts);
@@ -5074,7 +5074,7 @@ static void obj_init(void)
lit("t"), 0), make_sym(lit("t")));
set(t->s.package, user_package);
- null = intern(lit("null"), user_package);
+ null_s = intern(lit("null"), user_package);
cons_s = intern(lit("cons"), user_package);
str_s = intern(lit("str"), user_package);
chr_s = intern(lit("chr"), user_package);
@@ -5172,7 +5172,7 @@ static void obj_init(void)
identity_f = func_n1(identity);
car_f = func_n1(car);
cdr_f = func_n1(cdr);
- null_f = func_n1(nullp);
+ null_f = func_n1(null);
gensym_counter = zero;
prog_string = string(progname);
}
@@ -5220,7 +5220,7 @@ val obj_print(val obj, val out)
for (iter = obj; consp(iter); iter = cdr(iter)) {
obj_print(car(iter), out);
- if (nullp(cdr(iter))) {
+ if (nilp(cdr(iter))) {
put_char(closepar, out);
} else if (consp(cdr(iter))) {
put_char(chr(' '), out);
@@ -5386,7 +5386,7 @@ val obj_pprint(val obj, val out)
for (iter = obj; consp(iter); iter = cdr(iter)) {
obj_pprint(car(iter), out);
- if (nullp(cdr(iter))) {
+ if (nilp(cdr(iter))) {
put_char(closepar, out);
} else if (consp(cdr(iter))) {
put_char(chr(' '), out);
diff --git a/lib.h b/lib.h
index 0c5e2445..d817857d 100644
--- a/lib.h
+++ b/lib.h
@@ -315,7 +315,8 @@ INLINE val chr(wchar_t ch)
#define lit(strlit) lit_noex(strlit)
extern val keyword_package, system_package, user_package;
-extern val null, t, cons_s, str_s, chr_s, fixnum_s, sym_s, pkg_s, fun_s, vec_s;
+extern val null_s, t, cons_s, str_s, chr_s, fixnum_sl;
+extern val sym_s, pkg_s, fun_s, vec_s;
extern val stream_s, hash_s, hash_iter_s, lcons_s, lstr_s, cobj_s, cptr_s;
extern val env_s, bignum_s, float_s;
extern val var_s, expr_s, regex_s, chset_s, set_s, cset_s, wild_s, oneplus_s;
@@ -718,7 +719,9 @@ void breakpt(void);
INLINE val eq(val a, val b) { return a == b ? t : nil; }
-INLINE val nullp(val v) { return v ? nil : t; }
+INLINE val null(val v) { return v ? nil : t; }
+
+#define nilp(o) ((o) == nil)
#define nao ((obj_t *) (1 << TAG_SHIFT)) /* "not an object" sentinel value. */
diff --git a/match.c b/match.c
index 0da93ca8..d7ae2894 100644
--- a/match.c
+++ b/match.c
@@ -1145,7 +1145,7 @@ static val do_match_line(match_line_ctx *c)
if (regexp(directive)) {
val past = match_regex(c->dataline, directive, c->pos);
- if (nullp(past)) {
+ if (nilp(past)) {
LOG_MISMATCH("regex");
debug_return (nil);
}
diff --git a/rand.c b/rand.c
index 7951115a..6e4988a9 100644
--- a/rand.c
+++ b/rand.c
@@ -136,7 +136,7 @@ val make_random_state(val seed)
r->state[2] = (s >> 64) & 0xFFFFFFFFul;
r->state[3] = (s >> 96) & 0xFFFFFFFFul;
#endif
- } else if (nullp(seed)) {
+ } else if (nilp(seed)) {
val time = time_sec_usec();
r->state[0] = (rand32_t) c_num(car(time));
r->state[1] = (rand32_t) c_num(cdr(time));
diff --git a/regex.c b/regex.c
index 0c7e27b9..f0dcb85b 100644
--- a/regex.c
+++ b/regex.c
@@ -929,7 +929,7 @@ static nfa_t nfa_compile_list(val exp_list)
*/
static nfa_t nfa_compile_regex(val exp)
{
- if (nullp(exp)) {
+ if (nilp(exp)) {
nfa_state_t *acc = nfa_state_accept();
nfa_state_t *s = nfa_state_empty(acc, 0);
return nfa_make(s, acc);