summaryrefslogtreecommitdiffstats
path: root/lib.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-08-29 06:31:49 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-08-29 06:31:49 -0700
commit9f142b398f53ab7844a0fdfc5b562e8bbccfebe2 (patch)
tree6ee512c1c5601bdc78db208f20e00eeaeb11a2fd /lib.h
parent729c5e17bb601d1325753cb9db6d5d87ffdc3f66 (diff)
downloadtxr-9f142b398f53ab7844a0fdfc5b562e8bbccfebe2.tar.gz
txr-9f142b398f53ab7844a0fdfc5b562e8bbccfebe2.tar.bz2
txr-9f142b398f53ab7844a0fdfc5b562e8bbccfebe2.zip
seq_iter: refactoring.
This is needed in preparation for fixing some gc bugs in iteration in a less hacky way. * lib.h (struct seq_iter): Members get and peek removed, replaced by ops pointer. (struct seq_iter_ops): New struct type. (seq_get, seq_peek): Call get and peek through ops table. * lib.c (seq_geti): Refer to get through ops. (si_null_ops, si_list_ops, si_vec_ops, si_hash_ops, si_tree_ops, si_range_cnum_ops, si_range_chr_ops, si_range_bignum_ops, si_range_str_ops, si_rev_range_cnum_ops, si_rev_range_chr_ops, si_rev_range_bignum_ops, si_rev_range_str_ops, si_chr_ops, si_num_ops, si_oop_ops, si_fast_oop_ops): New static structures. (seq_iter_init_with_info): Point new ops member of seq_iter to one of the new structures. Remove initializations of get and peek.
Diffstat (limited to 'lib.h')
-rw-r--r--lib.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib.h b/lib.h
index 5fa529e5..3365183c 100644
--- a/lib.h
+++ b/lib.h
@@ -415,9 +415,15 @@ typedef struct seq_iter {
cnum cbound;
val next;
} ul;
+ struct seq_iter_ops *ops;
+} seq_iter_t;
+
+struct seq_iter_ops {
int (*get)(struct seq_iter *, val *pval);
int (*peek)(struct seq_iter *, val *pval);
-} seq_iter_t;
+};
+
+#define seq_iter_ops_init(get, peek) { get, peek }
extern const seq_kind_t seq_kind_tab[MAXTYPE+1];
@@ -572,8 +578,8 @@ seq_info_t seq_info(val cobj);
void seq_iter_init_with_info(val self, seq_iter_t *it,
seq_info_t si, int support_rewind);
void seq_iter_init(val self, seq_iter_t *it, val obj);
-INLINE int seq_get(seq_iter_t *it, val *pval) { return it->get(it, pval); }
-INLINE int seq_peek(seq_iter_t *it, val *pval) { return it->peek(it, pval); }
+INLINE int seq_get(seq_iter_t *it, val *pval) { return it->ops->get(it, pval); }
+INLINE int seq_peek(seq_iter_t *it, val *pval) { return it->ops->peek(it, pval); }
val seq_geti(seq_iter_t *it);
val seq_getpos(val self, seq_iter_t *it);
void seq_setpos(val self, seq_iter_t *it, val pos);