summaryrefslogtreecommitdiffstats
path: root/lib.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-07-07 06:46:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-07-07 06:46:22 -0700
commit623ce6c9829d9352d05f6dae3204c1705be95702 (patch)
tree383bc7d6127762ced11d2e80b0dfea7c3b91054d /lib.h
parent91b24fc71e53a0b356ef97708f467b9da37fbb6b (diff)
downloadtxr-623ce6c9829d9352d05f6dae3204c1705be95702.tar.gz
txr-623ce6c9829d9352d05f6dae3204c1705be95702.tar.bz2
txr-623ce6c9829d9352d05f6dae3204c1705be95702.zip
New: protocol for iteration with structs.
* lib.c (seq_iterable): Return t if argument is a structure supporting the iter-begin method. (seq_iter_get_oop, seq_iter_peek_oop, seq_iter_get_fast_oop, seq_iter_peek_fast_oop): New static functions. (seq_iter_init_with_info): Handle COBJ case. If the COBJ is a structure which suports the iter-begin method, then retrieve the iterator object by calling it, and then prepare the iterator structure for either the fast or the canonical protocol based on whether the iterator supports iter-more. (seq_iter_mark): Mark the iter member if the iterator is a struct object. (iter_begin): Rearrange tests here to check object type first before sequence kind. If the object is a structure supporting the iter-begin method, then call it and return its value. (iter_more, iter_step): Check for struct object with corresponding special methods and return. (iter_reset): Similar change like in iter_begin. We check for the iter-reset special method and try to use it, otherwise fall back on the regular iter_begin logic. * lib.h (struct seq_iter): New member next of the ul union for caching the result of a peek operation. * struct.c (iter_begin_s, iter_more_s, iter_item_s, iter_step_s, iter_reset_s): New symbol variables; (special_sym): Pointers to new symbol variables added to array. (struct_init): New symbol variables initialized. (get_special_required_slot): New function. * struct.h (iter_begin_s, iter_more_s, iter_item_s, iter_step_s, iter_reset_s): Declared. (enum special_slot): New enum members iter_begin_m, iter_more_m, iter_item_m, iter_step_m, iter_reset_m. (get_special_required_slot): Declared. * txr.1: Documented. * tests/012/oop-seq.expected: New file. * tests/012/oop-seq.tl: New file.
Diffstat (limited to 'lib.h')
-rw-r--r--lib.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib.h b/lib.h
index e50ba931..330ae34f 100644
--- a/lib.h
+++ b/lib.h
@@ -397,6 +397,7 @@ typedef struct seq_iter {
cnum len;
val vbound;
cnum cbound;
+ val next;
} ul;
int (*get)(struct seq_iter *, val *pval);
int (*peek)(struct seq_iter *, val *pval);