diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-01-22 23:39:45 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-01-22 23:39:45 -0800 |
commit | 9fa70b67bad4f95c22fa0e7a1148b88c82f375e1 (patch) | |
tree | faeb229bbdf434c599a7ddaf2e09e8a48d32475a /lib.h | |
parent | 8ced687d65438141be8a1305fa4058a76fa3cc59 (diff) | |
download | txr-9fa70b67bad4f95c22fa0e7a1148b88c82f375e1.tar.gz txr-9fa70b67bad4f95c22fa0e7a1148b88c82f375e1.tar.bz2 txr-9fa70b67bad4f95c22fa0e7a1148b88c82f375e1.zip |
Changes to the list collection mechanism to improve
the extension of list operations over vectors and strings.
* eval.c (do_eval_args, bindings_helper, op_each,
subst_vars, supplement_op_syms, mapcarv, mappendv): Switch from
list_collect_* macros to functions.
* lib.c (copy_list): Switch from list_collect* macros to functions.
Use list_collect_nconc for the final terminator. Doing a copy
there with list_collect_append was actually wasteful, and now
that list_collect_append calls copy_list in places, it triggered
runaway recursion.
(make_like): Bugfix: list_vector was used instead of vector_list.
(to_seq, list_collect, list_collect_nconc, list_collect_append): New
functions.
(append2, appendv, nappend2, sub_list, replace_list, ldiff, remq,
remql, remqual, remove_if, keep_if, proper_plist_to_alist,
improper_plist_to_alist, split_str, split_str_set, tok_str,
list_str, chain, andf, orf, lis_vector, mapcar, mapcon, mappend,
merge, set_diff, env): Switch from list_collect* macros to functions.
(replace_str, replace_vec): Allow single item replacement sequence.
* lib.h (to_seq): Declared.
(list_collect, list_collect_nconc, list_collect_append): Macros
removed, replaced by function declarations of the same name.
These functions return the new ptail since they cannot assign
to it, requiring all uses to be updated to do the assignment
of the returned value.
(list_collect_decl): Use val rather than obj_t *.
* match.c (vars_to_bindings, h_coll, subst_vars, extract_vars,
extract_bindings, do_output_line, do_output, v_gather, v_collect):
Switch from list_collect* macros to functions.
* parser.y (o_elems_transform): Likewise.
* regex.c (dv_compile_regex, regsub): Likewise.
* txr.c (txr_main): Likewise.
Diffstat (limited to 'lib.h')
-rw-r--r-- | lib.h | 32 |
1 files changed, 5 insertions, 27 deletions
@@ -374,6 +374,7 @@ val pop(val *plist); val push(val v, val *plist); val copy_list(val list); val make_like(val list, val thatobj); +val to_seq(val obj); val nreverse(val in); val reverse(val in); val append2(val list1, val list2); @@ -724,38 +725,16 @@ INLINE val eq(val a, val b) { return ((a) == (b) ? t : nil); } #define c_true(c_cond) ((c_cond) ? t : nil) #define list_collect_decl(OUT, PTAIL) \ - obj_t *OUT = nil, **PTAIL = &OUT + val OUT = nil, *PTAIL = &OUT -#define list_collect(PTAIL, OBJ) \ - do { \ - if (*PTAIL) \ - PTAIL = tail(*PTAIL); \ - set(*PTAIL, cons(OBJ, nil)); \ - PTAIL = cdr_l(*PTAIL); \ - } while(0) - -#define list_collect_nconc(PTAIL, OBJ) \ - do { \ - if (*PTAIL) { \ - PTAIL = tail(*PTAIL); \ - } \ - set(*PTAIL, OBJ); \ - } while (0) - -#define list_collect_append(PTAIL, OBJ) \ - do { \ - if (*PTAIL) { \ - set(*PTAIL, copy_list(*PTAIL)); \ - PTAIL = tail(*PTAIL); \ - } \ - set(*PTAIL, OBJ); \ - } while (0) +val *list_collect(val *pptail, val obj); +val *list_collect_nconc(val *pptail, val obj); +val *list_collect_append(val *pptail, val obj); #define cons_bind(CAR, CDR, CONS) \ obj_t *c_o_n_s ## CAR ## CDR = CONS; \ obj_t *CAR = car(c_o_n_s ## CAR ## CDR); \ obj_t *CDR = cdr(c_o_n_s ## CAR ## CDR) - #define cons_set(CAR, CDR, CONS) \ do { \ obj_t *c_o_n_s ## CAR ## CDR = CONS; \ @@ -763,7 +742,6 @@ INLINE val eq(val a, val b) { return ((a) == (b) ? t : nil); } CDR = cdr(c_o_n_s ## CAR ## CDR); \ } while (0) - #define zero num_fast(0) #define one num_fast(1) #define two num_fast(2) |