110static VALUE rb_cLazy;
111static ID id_rewind, id_new, id_to_enum;
112static ID id_next, id_result, id_receiver, id_arguments, id_memo, id_method, id_force;
113static ID id_begin, id_end, id_step, id_exclude_end;
114static VALUE sym_each, sym_cycle, sym_yield;
116static VALUE lazy_use_super_method;
118#define id_call idCall
119#define id_each idEach
121#define id_initialize idInitialize
122#define id_size idSize
141static VALUE rb_cGenerator, rb_cYielder, rb_cEnumProducer;
173static VALUE rb_cEnumChain;
186enumerator_mark(
void *p)
201enumerator_compact(
void *p)
215#define enumerator_free RUBY_TYPED_DEFAULT_FREE
218enumerator_memsize(
const void *p)
247proc_entry_mark(
void *p)
255proc_entry_compact(
void *p)
262#define proc_entry_free RUBY_TYPED_DEFAULT_FREE
265proc_entry_memsize(
const void *p)
379#define PASS_KW_SPLAT (rb_empty_keyword_given_p() ? RB_PASS_EMPTY_KEYWORDS : rb_keyword_given_p())
455 recv = generator_init(generator_allocate(rb_cGenerator),
rb_block_proc());
488 ptr0 = enumerator_ptr(orig);
606#if SIZEOF_INT < SIZEOF_LONG
621 return enumerator_block_call(
obj, 0,
obj);
627 struct MEMO *memo = (
struct MEMO *)m;
643 return enumerator_size(
obj);
666 return enumerator_block_call(
obj, enumerator_with_index_i, (
VALUE)
MEMO_NEW(memo, 0, 0));
680enumerator_each_with_index(
VALUE obj)
682 return enumerator_with_index(0,
NULL,
obj);
727 enumerator_block_call(
obj, enumerator_with_object_i, memo);
852 return get_next_values(
obj, e);
900 VALUE vs = enumerator_next_values(
obj);
901 return ary2sv(vs, 0);
974 VALUE vs = enumerator_peek_values(
obj);
975 return ary2sv(vs, 1);
1086 eobj = generator_ptr(e->
obj)->
obj;
1135 VALUE method, eargs;
1139 if (!
NIL_P(method)) {
1152 eargs = default_args;
1230 receiver = (*size_fn)(
proc, receiver);
1251yielder_mark(
void *p)
1258yielder_compact(
void *p)
1264#define yielder_free RUBY_TYPED_DEFAULT_FREE
1267yielder_memsize(
const void *p)
1269 return sizeof(
struct yielder);
1382 return yielder_init(yielder_allocate(rb_cYielder),
rb_proc_new(yielder_yield_i, 0));
1389generator_mark(
void *p)
1397generator_compact(
void *p)
1404#define generator_free RUBY_TYPED_DEFAULT_FREE
1407generator_memsize(
const void *p)
1481 "wrong argument type %"PRIsVALUE" (expected Proc)",
1485 rb_warn(
"given block not used");
1489 return generator_init(
obj,
proc);
1500 ptr0 = generator_ptr(orig);
1530enum_size(
VALUE self)
1539 return enum_size(
self);
1543lazy_size(
VALUE self)
1551 return lazy_size(lazy);
1587#define memo_value v2
1588#define memo_flags u3.state
1589#define LAZY_MEMO_BREAK 1
1590#define LAZY_MEMO_PACKED 2
1591#define LAZY_MEMO_BREAK_P(memo) ((memo)->memo_flags & LAZY_MEMO_BREAK)
1592#define LAZY_MEMO_PACKED_P(memo) ((memo)->memo_flags & LAZY_MEMO_PACKED)
1593#define LAZY_MEMO_SET_BREAK(memo) ((memo)->memo_flags |= LAZY_MEMO_BREAK)
1594#define LAZY_MEMO_SET_VALUE(memo, value) MEMO_V2_SET(memo, value)
1595#define LAZY_MEMO_SET_PACKED(memo) ((memo)->memo_flags |= LAZY_MEMO_PACKED)
1596#define LAZY_MEMO_RESET_PACKED(memo) ((memo)->memo_flags &= ~LAZY_MEMO_PACKED)
1605 struct MEMO *result;
1614 if (!(*entry->
fn->
proc)(
proc, result, memos,
i)) {
1626 return result->memo_value;
1656 generator = generator_allocate(rb_cGenerator);
1770 generator = generator_allocate(rb_cGenerator);
1772 enumerator_init(
self,
generator, sym_each, 0, 0, 0,
size, 0);
1810 lazy_set_args(lazy,
args);
1821 VALUE new_generator;
1826 &proc_entry_data_type, entry);
1833 lazy_set_args(entry_obj,
memo);
1836 new_generator = lazy_generator_init(
obj, new_procs);
1839 new_obj = enumerator_init_copy(enumerator_allocate(rb_cLazy),
obj);
1841 new_e->
obj = new_generator;
1842 new_e->
procs = new_procs;
1896 return enumerator_init(enumerator_allocate(rb_cLazy),
1926 VALUE lazy, meth = sym_each, super_meth;
1945 return enum_size(
self);
1956lazy_eager(
VALUE self)
1959 self, sym_each, 0, 0, lazy_eager_size,
Qnil, 0);
1974 const VALUE *
argv = &result->memo_value;
1999 lazy_map_proc, lazy_map_size,
2022 return lazy_add_method(
obj, 0, 0,
Qnil,
Qnil, &lazy_map_funcs);
2068 lazy_flat_map_each(result,
argv[0]);
2071 lazy_flat_map_to_ary(result,
argv[0]);
2108 lazy_flat_map_proc, 0),
2116 if (!
RTEST(chain))
return 0;
2121 lazy_select_proc, 0,
2139 return lazy_add_method(
obj, 0, 0,
Qnil,
Qnil, &lazy_select_funcs);
2153 lazy_filter_map_proc, 0,
2173 return lazy_add_method(
obj, 0, 0,
Qnil,
Qnil, &lazy_filter_map_funcs);
2180 if (
RTEST(chain))
return 0;
2185 lazy_reject_proc, 0,
2202 return lazy_add_method(
obj, 0, 0,
Qnil,
Qnil, &lazy_reject_funcs);
2210 if (!
RTEST(chain))
return 0;
2220 if (!
RTEST(chain))
return 0;
2229 lazy_grep_iter_proc, 0,
2248 &lazy_grep_iter_funcs : &lazy_grep_funcs;
2249 return lazy_add_method(
obj, 0, 0, pattern,
rb_ary_new3(1, pattern), funcs);
2257 if (
RTEST(chain))
return 0;
2267 if (
RTEST(chain))
return 0;
2276 lazy_grep_v_iter_proc, 0,
2280 lazy_grep_v_proc, 0,
2295 &lazy_grep_v_iter_funcs : &lazy_grep_v_funcs;
2296 return lazy_add_method(
obj, 0, 0, pattern,
rb_ary_new3(1, pattern), funcs);
2393 func = lazy_zip_func;
2401 ary, lazy_receiver_size);
2436 lazy_take_proc, lazy_take_size,
2458 argv[0] = sym_cycle;
2478 lazy_take_while_proc, 0,
2495 return lazy_add_method(
obj, 0, 0,
Qnil,
Qnil, &lazy_take_while_funcs);
2502 if (
NIL_P(receiver))
2532 lazy_drop_proc, lazy_drop_size,
2569 if (
RTEST(drop))
return 0;
2576 lazy_drop_while_proc, 0,
2593 return lazy_add_method(
obj, 0, 0,
Qfalse,
Qnil, &lazy_drop_while_funcs);
2597lazy_uniq_check(
VALUE chain,
VALUE memos,
long memo_index)
2612 if (lazy_uniq_check(result->memo_value, memos, memo_index))
return 0;
2621 if (lazy_uniq_check(chain, memos, memo_index))
return 0;
2626 lazy_uniq_iter_proc, 0,
2646 return lazy_add_method(
obj, 0, 0,
Qnil,
Qnil, funcs);
2660 argv[0] = result->memo_value;
2674 lazy_with_index_proc, 0,
2827stop_result(
VALUE self)
2837producer_mark(
void *p)
2845producer_compact(
void *p)
2852#define producer_free RUBY_TYPED_DEFAULT_FREE
2855producer_memsize(
const void *p)
3022enum_chain_mark(
void *p)
3029enum_chain_compact(
void *p)
3035#define enum_chain_free RUBY_TYPED_DEFAULT_FREE
3038enum_chain_memsize(
const void *p)
3114 ptr0 = enum_chain_ptr(orig);
3160 return enum_chain_total_size(enum_chain_ptr(
obj)->
enums);
3166 return enum_chain_size(
obj);
3196 objptr = enum_chain_ptr(
obj);
3277 return enum_chain_initialize(enum_chain_allocate(rb_cEnumChain),
enums);
3295 return enum_chain_initialize(enum_chain_allocate(rb_cEnumChain),
enums);
3328arith_seq_begin(
VALUE self)
3339arith_seq_end(
VALUE self)
3351arith_seq_step(
VALUE self)
3362arith_seq_exclude_end(
VALUE self)
3368arith_seq_exclude_end_p(
VALUE self)
3370 return RTEST(arith_seq_exclude_end(
self));
3377 component->
begin = arith_seq_begin(
obj);
3378 component->
end = arith_seq_end(
obj);
3379 component->
step = arith_seq_step(
obj);
3411 b = arith_seq_begin(
self);
3412 e = arith_seq_end(
self);
3413 s = arith_seq_step(
self);
3441 x = arith_seq_exclude_end_p(
self);
3473 while (
n > 0 &&
i < end) {
3475 if (
i + unit <
i)
break;
3486 while (
n > 0 &&
i > end) {
3488 if (
i + unit >
i)
break;
3516 else if (unit == 0) {
3519 for (
i = 0;
i <
len; ++
i) {
3525 for (
i = 0;
i <
n; ++
i) {
3526 double d =
i*unit+beg;
3527 if (unit >= 0 ? end < d : d < end) d = end;
3632 int last_is_adjusted;
3635 e = arith_seq_end(
self);
3638 "cannot get the last element of endless arithmetic sequence");
3641 b = arith_seq_begin(
self);
3642 s = arith_seq_step(
self);
3644 len_1 = num_idiv(num_minus(e, b), s);
3645 if (rb_num_negative_int_p(len_1)) {
3652 last = num_plus(b, num_mul(s, len_1));
3653 if ((last_is_adjusted = arith_seq_exclude_end_p(
self) &&
rb_equal(
last, e))) {
3661 if (last_is_adjusted) {
3698arith_seq_inspect(
VALUE self)
3768 if (!
rb_equal(arith_seq_begin(
self), arith_seq_begin(other))) {
3772 if (!
rb_equal(arith_seq_end(
self), arith_seq_end(other))) {
3776 if (!
rb_equal(arith_seq_step(
self), arith_seq_step(other))) {
3780 if (arith_seq_exclude_end_p(
self) != arith_seq_exclude_end_p(other)) {
3798arith_seq_hash(
VALUE self)
3804 v =
rb_hash(arith_seq_begin(
self));
3815#define NUM_GE(x, y) RTEST(rb_num_coerce_relop((x), (y), idGE))
3830arith_seq_each(
VALUE self)
3837 c = arith_seq_begin(
self);
3838 e = arith_seq_end(
self);
3839 s = arith_seq_step(
self);
3840 x = arith_seq_exclude_end_p(
self);
3863 len_1 = num_idiv(num_minus(e, c), s);
3864 last = num_plus(c, num_mul(s, len_1));
3869 if (rb_num_negative_int_p(s)) {
3886arith_seq_float_step_size(
double beg,
double end,
double step,
int excl)
3894 n = (end - beg) / step;
3897 return step > 0 ? beg <= end : beg >= end;
3899 if (
err > 0.5)
err = 0.5;
3901 if (
n <= 0)
return 0;
3908 if (
n < 0)
return 0;
3922arith_seq_size(
VALUE self)
3927 b = arith_seq_begin(
self);
3928 e = arith_seq_end(
self);
3929 s = arith_seq_step(
self);
3930 x = arith_seq_exclude_end_p(
self);
3936 if (rb_num_negative_int_p(s)) {
3966 if (rb_num_negative_int_p(len_1)) {
4018 rb_define_alias(rb_cLazy,
"_enumerable_collect_concat",
"collect_concat");
4121 rb_define_method(rb_cGenerator,
"initialize_copy", generator_init_copy, 1);
4142 rb_define_method(rb_cEnumChain,
"initialize_copy", enum_chain_init_copy, 1);
4186 id_exclude_end =
rb_intern(
"exclude_end");
#define rb_cmpint(cmp, a, b)
struct MEMO * lazyenum_proc_func(VALUE, struct MEMO *, VALUE, long)
VALUE rb_arith_seq_new(VALUE obj, VALUE meth, int argc, VALUE const *argv, rb_enumerator_size_func *size_fn, VALUE beg, VALUE end, VALUE step, int excl)
#define LAZY_MEMO_PACKED_P(memo)
#define LAZY_MEMO_SET_PACKED(memo)
#define LAZY_MEMO_SET_BREAK(memo)
VALUE rb_enumeratorize(VALUE obj, VALUE meth, int argc, const VALUE *argv)
void Init_Enumerator(void)
VALUE rb_enumeratorize_with_size(VALUE obj, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *size_fn)
#define LAZY_MEMO_RESET_PACKED(memo)
void InitVM_Enumerator(void)
VALUE rb_enumeratorize_with_size_kw(VALUE obj, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *size_fn, int kw_splat)
VALUE lazyenum_size_func(VALUE, VALUE)
#define LAZY_MEMO_SET_VALUE(memo, value)
int rb_arithmetic_sequence_extract(VALUE obj, rb_arithmetic_sequence_components_t *component)
#define LAZY_MEMO_BREAK_P(memo)
char str[HTML_ESCAPE_MAX_LEN+1]
void rb_include_module(VALUE, VALUE)
VALUE rb_define_class(const char *, VALUE)
Defines a top-level class.
VALUE rb_define_class_under(VALUE, const char *, VALUE)
Defines a class under the namespace of outer.
ID rb_frame_this_func(void)
The original name of the current method.
void rb_need_block(void)
Declares that the current method needs a block.
void rb_undef_method(VALUE, const char *)
void rb_define_alias(VALUE, const char *, const char *)
Defines an alias of a method.
int rb_block_given_p(void)
Determines if the current method is given a block.
VALUE rb_mKernel
Kernel module.
VALUE rb_cObject
Object class.
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_rescue2(VALUE(*)(VALUE), VALUE, VALUE(*)(VALUE, VALUE), VALUE,...)
An equivalent of rescue clause.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_warn(const char *fmt,...)
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
VALUE rb_obj_dup(VALUE)
Equivalent to Object#dup in Ruby.
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
VALUE rb_equal(VALUE, VALUE)
Same as Object#===, case equality.
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
VALUE rb_obj_freeze(VALUE)
Make the object unmodifiable.
VALUE rb_to_int(VALUE)
Converts val into Integer.
rb_enumerator_size_func * size_fn
lazyenum_size_func * size
lazyenum_proc_func * proc
const lazyenum_funcs * fn