summaryrefslogtreecommitdiffstats
path: root/match.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-10-04 14:40:08 -0700
committerKaz Kylheku <kaz@kylheku.com>2011-10-04 14:40:08 -0700
commitb5d5dcb8dcde90bb1766eb88a36e962f8e43fd33 (patch)
tree93788d6da3020c898b7261edc7e8b6d0154aeab9 /match.c
parentea991039e9f7e9254a283e4eca92b6f8a9090425 (diff)
downloadtxr-b5d5dcb8dcde90bb1766eb88a36e962f8e43fd33.tar.gz
txr-b5d5dcb8dcde90bb1766eb88a36e962f8e43fd33.tar.bz2
txr-b5d5dcb8dcde90bb1766eb88a36e962f8e43fd33.zip
Bugfixes to the semantics of binding environments, which
were broken in the face of deletions (local, forget). For some stupid reason, I had written a destructive routine for removing elements from an association list, and used it as the basis for the local and forget directives. * lib.c (eq_f, car_f): New variables. (identity_tramp, equal_tramp): Obsolete functions removed. (apply): Broken function disabled at run time. (funcall, funcall1, funcall2): Throw meaningful error instead of aborting. (alist_remove_test): New static function. (alist_remove, alist_remove1): Rewritten to be functional rather than destructive. (alist_nremove, alist_nremove1): Destructive functions, using previous implementations of alist and alist_nremove. (do_sort): Recurses directly rather than via sort. That was probably why this helper was introduced! (find, set_diff): New functions. (obj_init): gc-protect new variables eq_f and car_f, and initialize them. Initializations for equal_f and identity_f changed to use equal and identity directly, without the obsolete wrappers. * lib.h (eq_f, car_f, alist_nremove, alist_nremove1, find, set_diff): Declared. * match.c (match_line): Use set_diff to determine what bindings are new, rather than ldiff and ldiff-like logic which break when the new bindings do not share structure with the old. (match_files): Likewise.
Diffstat (limited to 'match.c')
-rw-r--r--match.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/match.c b/match.c
index 592685f3..75e3bb0f 100644
--- a/match.c
+++ b/match.c
@@ -519,7 +519,8 @@ static val match_line(val bindings, val specline, val dataline,
if (until_pos) {
LOG_MATCH("until/last", until_pos);
if (sym == last_s) {
- last_bindings = ldiff(until_last_bindings, new_bindings);
+ last_bindings = set_diff(until_last_bindings,
+ new_bindings, eq_f, car_f);
pos = until_pos;
}
break;
@@ -529,10 +530,11 @@ static val match_line(val bindings, val specline, val dataline,
}
if (new_pos) {
+ val strictly_new_bindings = set_diff(new_bindings,
+ bindings, eq_f, car_f);
LOG_MATCH("coll", new_pos);
- for (iter = new_bindings; iter && iter != bindings;
- iter = cdr(iter))
+ for (iter = strictly_new_bindings; iter; iter = cdr(iter))
{
val binding = car(iter);
val existing = assoc(bindings_coll, car(binding));
@@ -1541,8 +1543,8 @@ repeat_spec_same_data:
first(files), num(data_lineno), nao);
/* Until discards bindings and position, last keeps them. */
if (sym == last_s) {
- last_bindings = ldiff(until_last_bindings, new_bindings);
-
+ last_bindings = set_diff(until_last_bindings,
+ new_bindings, eq_f, car_f);
if (success == t) {
data = t;
} else {
@@ -1556,11 +1558,13 @@ repeat_spec_same_data:
}
if (success) {
+ val strictly_new_bindings = set_diff(new_bindings,
+ bindings, eq_f, car_f);
+
debuglf(spec_linenum, lit("collect matched ~a:~a"),
first(files), num(data_lineno), nao);
- for (iter = new_bindings; iter && iter != bindings;
- iter = cdr(iter))
+ for (iter = strictly_new_bindings; iter; iter = cdr(iter))
{
val binding = car(iter);
val existing = assoc(bindings_coll, car(binding));