summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-01-01 19:56:11 -0800
committerKaz Kylheku <kaz@kylheku.com>2018-01-01 19:56:11 -0800
commit6ac45e04ea817dcd6df3a749f523ed1b96ec0118 (patch)
treebfd8211f0d14cbc1978b231b3a2504209f72aa24
parent79a90b980192de7410a7e688e1c831f7878f8714 (diff)
downloadtxr-6ac45e04ea817dcd6df3a749f523ed1b96ec0118.tar.gz
txr-6ac45e04ea817dcd6df3a749f523ed1b96ec0118.tar.bz2
txr-6ac45e04ea817dcd6df3a749f523ed1b96ec0118.zip
Use rplaca and rplacd instead of set over car_l/cdr_l.
This reduces the proliferation of car_l and cdr_l. With this change, nreverse should work on chains of objects that implement rplacd. * combi.c (comb_gen_fun_common, rcomb_gen_fun_common): Use rplaca. * eval.c (mappendv, mapdov): Likewise * hash.c (hash_equal_op): Likewise. * lib.c (nreverse, acons_new, aconsql_new, sort_list): Use rplaca and rplacd. * match.c (dest_set, v_gather, v_collect, v_flatten, v_cat, v_output, v_filter): Likewise * parser.c (ensure_parser): Use sys_rplacd. * unwind.c (uw_register_subtype): Use rplacd.
-rw-r--r--combi.c12
-rw-r--r--eval.c4
-rw-r--r--hash.c8
-rw-r--r--lib.c12
-rw-r--r--match.c16
-rw-r--r--parser.c2
-rw-r--r--unwind.c2
7 files changed, 28 insertions, 28 deletions
diff --git a/combi.c b/combi.c
index c749b300..aea2032c 100644
--- a/combi.c
+++ b/combi.c
@@ -359,7 +359,7 @@ static void comb_gen_fun_common(val state)
val curr = first(iter);
val curr_rest = rest(curr);
if (curr_rest != prev && consp(curr_rest)) {
- set(car_l(iter), curr_rest);
+ rplaca(iter, curr_rest);
return;
} else if (rest(iter)) {
val next = second(iter);
@@ -367,11 +367,11 @@ static void comb_gen_fun_common(val state)
val next_rest_rest = rest(next_rest);
prev = curr;
if (next_rest != curr && consp(next_rest_rest))
- prev = set(car_l(iter), next_rest_rest);
+ prev = sys_rplaca(iter, next_rest_rest);
}
}
- deref(car_l(state)) = nil;
+ rplaca(state, nil);
}
static val comb_list_gen_fun(val state)
@@ -520,16 +520,16 @@ static void rcomb_gen_fun_common(val state)
if (consp(curr_rest)) {
val jter;
for (jter = state; jter != next; jter = cdr(jter))
- set(car_l(jter), curr_rest);
+ rplaca(jter, curr_rest);
return;
} else if (next) {
val next = second(iter);
if (curr != next)
- set(car_l(iter), rest(next));
+ rplaca(iter, rest(next));
}
}
- deref(car_l(state)) = nil;
+ rplaca(state, nil);
}
static val rcomb_list_gen_fun(val state)
diff --git a/eval.c b/eval.c
index 81c62d11..d82f2141 100644
--- a/eval.c
+++ b/eval.c
@@ -4706,7 +4706,7 @@ static val mappendv(val fun, struct args *lists)
return make_like(out, list_orig);
}
atail = list_collect(atail, car(list));
- deref(car_l(iter)) = cdr(list);
+ rplaca(iter, cdr(list));
}
otail = list_collect_append(otail, apply(fun, z(args)));
@@ -4801,7 +4801,7 @@ static val mapdov(val fun, struct args *lists)
return nil;
}
atail = list_collect(atail, car(list));
- deref(car_l(iter)) = cdr(list);
+ rplaca(iter, cdr(list));
}
apply(fun, z(args));
diff --git a/hash.c b/hash.c
index b0d76175..e2ea6a43 100644
--- a/hash.c
+++ b/hash.c
@@ -344,8 +344,8 @@ static val hash_equal_op(val left, val right)
free_conses = loc;
} else {
ncons = or2(pop(&free_conses), cons(nil, nil));
- set(car_l(ncons), lcell);
- set(cdr_l(ncons), pending);
+ rplaca(ncons, lcell);
+ rplaca(ncons, pending);
pending = ncons;
}
@@ -363,8 +363,8 @@ static val hash_equal_op(val left, val right)
free_conses = loc;
} else {
ncons = or2(pop(&free_conses), cons(nil, nil));
- set(car_l(ncons), rcell);
- set(cdr_l(ncons), pending);
+ rplaca(ncons, rcell);
+ rplaca(ncons, pending);
pending = ncons;
}
}
diff --git a/lib.c b/lib.c
index 55eba5f1..a48fb78a 100644
--- a/lib.c
+++ b/lib.c
@@ -1104,7 +1104,7 @@ val nreverse(val in)
while (in) {
val temp = cdr(in);
- set(cdr_l(in), rev);
+ rplacd(in, rev);
rev = in;
in = temp;
}
@@ -7803,7 +7803,7 @@ val acons_new(val key, val value, val list)
val existing = assoc(key, list);
if (existing) {
- set(cdr_l(existing), value);
+ rplacd(existing, value);
return list;
} else {
return cons(cons(key, value), list);
@@ -7832,7 +7832,7 @@ val aconsql_new(val key, val value, val list)
val existing = assql(key, list);
if (existing) {
- set(cdr_l(existing), value);
+ rplacd(existing, value);
return list;
} else {
return cons(cons(key, value), list);
@@ -8207,8 +8207,8 @@ static val sort_list(val list, val lessfun, val keyfun)
may contain mixtures of old and new objects, and
so we could be reversing a newer->older pointer
relationship. */
- set(cdr_l(cons2), list);
- deref(cdr_l(list)) = nil;
+ rplacd(cons2, list);
+ rplacd(list, nil);
return cons2;
} else {
return list;
@@ -8224,7 +8224,7 @@ static val sort_list(val list, val lessfun, val keyfun)
; /* empty */
list2 = cdr(bisect);
- deref(cdr_l(bisect)) = nil;
+ rplacd(bisect, nil);
return merge(sort_list(list, lessfun, keyfun),
sort_list(list2, lessfun, keyfun),
diff --git a/match.c b/match.c
index 6f151c7b..fb791e1d 100644
--- a/match.c
+++ b/match.c
@@ -255,7 +255,7 @@ static val dest_set(val spec, val bindings, val pattern, val value)
{
if (bindable(pattern)) {
val existing = tx_lookup_var_ubc(pattern, bindings, spec);
- set(cdr_l(existing), value);
+ rplacd(existing, value);
} else if (consp(pattern)) {
if (first(pattern) == var_s) {
uw_throwf(query_error_s,
@@ -3007,7 +3007,7 @@ static val v_gather(match_files_ctx *c)
match_files(mf_spec(*c, nested_spec)));
if (!success) {
- deref(cdr_l(iter)) = nil;
+ rplacd(iter, nil);
ptail = list_collect_nconc(ptail, iter);
} else if (success == t) {
c->bindings = new_bindings;
@@ -3403,7 +3403,7 @@ static val v_collect(match_files_ctx *c)
c->data = new_data;
c->data_lineno = new_line;
- deref(car_l(success)) = nil;
+ rplaca(success, nil);
} else {
debuglf(specline, lit("~s consumed entire file"), op_sym, nao);
c->data = nil;
@@ -3497,7 +3497,7 @@ static val v_flatten(match_files_ctx *c)
lit("flatten: ~s is not a bindable symbol"), sym, nao);
} else {
val existing = tx_lookup_var_ubc(sym, c->bindings, first_spec);
- set(cdr_l(existing), flatten(cdr(existing)));
+ rplacd(existing, flatten(cdr(existing)));
}
}
@@ -3655,7 +3655,7 @@ static val v_cat(match_files_ctx *c)
val existing = tx_lookup_var_ubc(sym, c->bindings, first_spec);
val sep = if3(sep_form, tleval_144(specline, sep_form, c->bindings),
lit(" "));
- set(cdr_l(existing), cat_str(flatten(cdr(existing)), sep));
+ rplacd(existing, cat_str(flatten(cdr(existing)), sep));
}
return next_spec_k;
@@ -3743,9 +3743,9 @@ static val v_output(match_files_ctx *c)
if (existing) {
if (append) {
- set(cdr_l(existing), append2(flatten(cdr(existing)), list_out));
+ rplacd(existing, append2(flatten(cdr(existing)), list_out));
} else {
- set(cdr_l(existing), list_out);
+ rplacd(existing, list_out);
}
} else {
c->bindings = acons(into_var, list_out, c->bindings);
@@ -4052,7 +4052,7 @@ static val v_filter(match_files_ctx *c)
for (; vars; vars = cdr(vars)) {
val var = car(vars);
val existing = tx_lookup_var_ubc(var, c->bindings, first_spec);
- set(cdr_l(existing), filter_string_tree(filter, cdr(existing)));
+ rplacd(existing, filter_string_tree(filter, cdr(existing)));
}
uw_env_end;
diff --git a/parser.c b/parser.c
index 4aa9fdeb..4f4bcdae 100644
--- a/parser.c
+++ b/parser.c
@@ -173,7 +173,7 @@ static val ensure_parser(val stream)
val pars = cdr(cell);
if (pars)
return pars;
- return set(cdr_l(cell), parser(stream, one));
+ return sys_rplacd(cell, parser(stream, one));
}
static void pushback_token(parser_t *p, struct yy_token *tok)
diff --git a/unwind.c b/unwind.c
index 80baf6ee..e422cf86 100644
--- a/unwind.c
+++ b/unwind.c
@@ -787,7 +787,7 @@ val uw_register_subtype(val sub, val sup)
/* Make sub an immediate subtype of sup.
If sub already registered, we just repoint it. */
if (sub_entry) {
- set(cdr_l(sub_entry), sup_entry);
+ rplacd(sub_entry, sup_entry);
} else {
sub_entry = cons(sub, sup_entry);
exception_subtypes = cons(sub_entry, exception_subtypes);