15#include "ruby/internal/config.h"
23#include "internal/class.h"
24#include "internal/enumerator.h"
25#include "internal/error.h"
26#include "internal/hash.h"
27#include "internal/imemo.h"
28#include "internal/numeric.h"
29#include "internal/range.h"
30#include "internal/rational.h"
159static VALUE rb_cLazy;
160static ID id_rewind, id_new, id_to_enum, id_each_entry;
161static ID id_next, id_result, id_receiver, id_arguments, id_memo, id_method, id_force;
162static ID id_begin, id_end, id_step, id_exclude_end;
163static VALUE sym_each, sym_cycle, sym_yield;
165static VALUE lazy_use_super_method;
167extern ID ruby_static_id_cause;
169#define id_call idCall
170#define id_cause ruby_static_id_cause
171#define id_each idEach
173#define id_initialize idInitialize
174#define id_size idSize
193static VALUE rb_cGenerator, rb_cYielder, rb_cEnumProducer;
213 lazyenum_proc_func *proc;
214 lazyenum_size_func *size;
215 lazyenum_precheck_func *precheck;
227static VALUE rb_cEnumChain;
234static VALUE rb_cEnumProduct;
246enumerator_mark(
void *p)
249 rb_gc_mark_movable(ptr->obj);
250 rb_gc_mark_movable(ptr->args);
251 rb_gc_mark_movable(ptr->fib);
252 rb_gc_mark_movable(ptr->dst);
253 rb_gc_mark_movable(ptr->lookahead);
254 rb_gc_mark_movable(ptr->feedvalue);
255 rb_gc_mark_movable(ptr->stop_exc);
256 rb_gc_mark_movable(ptr->size);
257 rb_gc_mark_movable(ptr->procs);
261enumerator_compact(
void *p)
264 ptr->obj = rb_gc_location(ptr->obj);
265 ptr->args = rb_gc_location(ptr->args);
266 ptr->fib = rb_gc_location(ptr->fib);
267 ptr->dst = rb_gc_location(ptr->dst);
268 ptr->lookahead = rb_gc_location(ptr->lookahead);
269 ptr->feedvalue = rb_gc_location(ptr->feedvalue);
270 ptr->stop_exc = rb_gc_location(ptr->stop_exc);
271 ptr->size = rb_gc_location(ptr->size);
272 ptr->procs = rb_gc_location(ptr->procs);
275#define enumerator_free RUBY_TYPED_DEFAULT_FREE
278enumerator_memsize(
const void *p)
291 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
295enumerator_ptr(
VALUE obj)
300 if (!ptr || UNDEF_P(ptr->obj)) {
307proc_entry_mark(
void *p)
310 rb_gc_mark_movable(ptr->proc);
311 rb_gc_mark_movable(ptr->memo);
315proc_entry_compact(
void *p)
318 ptr->proc = rb_gc_location(ptr->proc);
319 ptr->memo = rb_gc_location(ptr->memo);
322#define proc_entry_free RUBY_TYPED_DEFAULT_FREE
325proc_entry_memsize(
const void *p)
420 enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
428enumerator_allocate(
VALUE klass)
460 ptr->size_fn = size_fn;
461 ptr->kw_splat = kw_splat;
467convert_to_feasible_size_value(
VALUE obj)
509enumerator_initialize(
int argc,
VALUE *argv,
VALUE obj)
512 VALUE recv = generator_init(generator_allocate(rb_cGenerator), iter);
514 VALUE size = convert_to_feasible_size_value(arg0);
516 return enumerator_init(obj, recv, sym_each, 0, 0, 0, size,
false);
526 ptr0 = enumerator_ptr(orig);
538 ptr1->obj = ptr0->obj;
539 ptr1->meth = ptr0->meth;
540 ptr1->args = ptr0->args;
544 ptr1->size = ptr0->size;
545 ptr1->size_fn = ptr0->size_fn;
556 return rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
560static int lazy_precheck(
VALUE procs);
568 base_class = rb_cLazy;
571 obj = enumerator_init(enumerator_allocate(
rb_cEnumerator), obj, sym_each, 0, 0, 0,
Qnil,
false);
574 return enumerator_init(enumerator_allocate(base_class),
575 obj, meth, argc, argv, size_fn,
Qnil, kw_splat);
581 return rb_enumeratorize_with_size_kw(obj, meth, argc, argv, size_fn,
rb_keyword_given_p());
588 const VALUE *argv = 0;
589 const struct enumerator *e = enumerator_ptr(obj);
636enumerator_each(
int argc,
VALUE *argv,
VALUE obj)
643#if SIZEOF_INT < SIZEOF_LONG
647 args = rb_ary_dup(args);
648 rb_ary_cat(args, argv, argc);
659 if (!lazy_precheck(e->procs))
return Qnil;
661 return enumerator_block_call(obj, 0, obj);
667 struct MEMO *memo = (
struct MEMO *)m;
668 VALUE idx = memo->v1;
669 MEMO_V1_SET(memo, rb_int_succ(idx));
678enumerator_size(
VALUE obj);
683 return enumerator_size(obj);
699enumerator_with_index(
int argc,
VALUE *argv,
VALUE obj)
706 return enumerator_block_call(obj, enumerator_with_index_i, (
VALUE)MEMO_NEW(memo, 0, 0));
720enumerator_each_with_index(
VALUE obj)
722 return enumerator_with_index(0, NULL, obj);
767 enumerator_block_call(obj, enumerator_with_object_i, memo);
778 rb_fiber_yield(1, &args);
779 if (!UNDEF_P(e->feedvalue)) {
780 feedvalue = e->feedvalue;
796 return rb_fiber_yield(1, &nil);
802 VALUE curr = rb_fiber_current();
814 VALUE exc = e->stop_exc;
824 curr = rb_fiber_current();
826 if (!e->fib || !rb_fiber_alive_p(e->fib)) {
830 vs = rb_fiber_resume(e->fib, 1, &curr);
887enumerator_next_values(
VALUE obj)
892 if (!UNDEF_P(e->lookahead)) {
898 return get_next_values(obj, e);
902ary2sv(
VALUE args,
int dup)
916 return rb_ary_dup(args);
942enumerator_next(
VALUE obj)
944 VALUE vs = enumerator_next_values(obj);
945 return ary2sv(vs, 0);
949enumerator_peek_values(
VALUE obj)
953 if (UNDEF_P(e->lookahead)) {
954 e->lookahead = get_next_values(obj, e);
990enumerator_peek_values_m(
VALUE obj)
992 return rb_ary_dup(enumerator_peek_values(obj));
1020enumerator_peek(
VALUE obj)
1022 VALUE vs = enumerator_peek_values(obj);
1023 return ary2sv(vs, 1);
1077 if (!UNDEF_P(e->feedvalue)) {
1095enumerator_rewind(
VALUE obj)
1113inspect_enumerator(
VALUE obj,
VALUE dummy,
int recur)
1116 VALUE eobj, str, cname;
1122 if (!e || UNDEF_P(e->obj)) {
1134 eobj = generator_ptr(e->obj)->obj;
1143 str =
rb_sprintf(
"#<%"PRIsVALUE
": %"PRIsVALUE, cname, str);
1144 append_method(
RARRAY_AREF(e->procs, i), str, e->meth, e->args);
1157 append_method(obj, str, e->meth, e->args);
1167 if (
SYMBOL_P(key))
return ST_CONTINUE;
1168 *(
int *)arg = FALSE;
1176 rb_str_catf(str,
"% "PRIsVALUE
": %"PRIsVALUE
", ", key, val);
1183 VALUE method, eargs;
1187 if (!
NIL_P(method)) {
1192 method = rb_id2str(default_method);
1200 eargs = default_args;
1214 if (all_key) kwds = argv[--argc];
1218 VALUE arg = *argv++;
1242enumerator_inspect(
VALUE obj)
1259enumerator_size(
VALUE obj)
1263 const VALUE *argv = NULL;
1267 struct generator *g = generator_ptr(e->obj);
1273 struct proc_entry *entry = proc_entry_ptr(proc);
1274 lazyenum_size_func *size_fn = entry->fn->size;
1278 receiver = (*size_fn)(proc, receiver);
1284 return (*e->size_fn)(e->obj, e->args, obj);
1291 if (!UNDEF_P(size))
return size;
1299yielder_mark(
void *p)
1302 rb_gc_mark_movable(ptr->proc);
1306yielder_compact(
void *p)
1309 ptr->proc = rb_gc_location(ptr->proc);
1312#define yielder_free RUBY_TYPED_DEFAULT_FREE
1315yielder_memsize(
const void *p)
1317 return sizeof(
struct yielder);
1328 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
1332yielder_ptr(
VALUE obj)
1337 if (!ptr || UNDEF_P(ptr->proc)) {
1345yielder_allocate(
VALUE klass)
1374yielder_initialize(
VALUE obj)
1385 struct yielder *ptr = yielder_ptr(obj);
1394 struct yielder *ptr = yielder_ptr(obj);
1414yielder_to_proc(
VALUE obj)
1430 return yielder_init(yielder_allocate(rb_cYielder),
rb_proc_new(yielder_yield_i, 0));
1437generator_mark(
void *p)
1440 rb_gc_mark_movable(ptr->proc);
1441 rb_gc_mark_movable(ptr->obj);
1445generator_compact(
void *p)
1448 ptr->proc = rb_gc_location(ptr->proc);
1449 ptr->obj = rb_gc_location(ptr->obj);
1452#define generator_free RUBY_TYPED_DEFAULT_FREE
1455generator_memsize(
const void *p)
1468 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
1472generator_ptr(
VALUE obj)
1477 if (!ptr || UNDEF_P(ptr->proc)) {
1485generator_allocate(
VALUE klass)
1515generator_initialize(
int argc,
VALUE *argv,
VALUE obj)
1529 "wrong argument type %"PRIsVALUE
" (expected Proc)",
1533 rb_warn(
"given block not used");
1537 return generator_init(obj, proc);
1548 ptr0 = generator_ptr(orig);
1556 ptr1->proc = ptr0->proc;
1563generator_each(
int argc,
VALUE *argv,
VALUE obj)
1565 struct generator *ptr = generator_ptr(obj);
1568 rb_ary_push(args, yielder_new());
1570 rb_ary_cat(args, argv, argc);
1578enum_size(
VALUE self)
1581 return UNDEF_P(r) ?
Qnil : r;
1587 return enum_size(self);
1590#define lazy_receiver_size lazy_map_size
1621 rb_block_call(m, id_each, argc-1, argv+1, lazy_init_iterator, val);
1625#define memo_value v2
1626#define memo_flags u3.state
1627#define LAZY_MEMO_BREAK 1
1628#define LAZY_MEMO_PACKED 2
1629#define LAZY_MEMO_BREAK_P(memo) ((memo)->memo_flags & LAZY_MEMO_BREAK)
1630#define LAZY_MEMO_PACKED_P(memo) ((memo)->memo_flags & LAZY_MEMO_PACKED)
1631#define LAZY_MEMO_SET_BREAK(memo) ((memo)->memo_flags |= LAZY_MEMO_BREAK)
1632#define LAZY_MEMO_RESET_BREAK(memo) ((memo)->memo_flags &= ~LAZY_MEMO_BREAK)
1633#define LAZY_MEMO_SET_VALUE(memo, value) MEMO_V2_SET(memo, value)
1634#define LAZY_MEMO_SET_PACKED(memo) ((memo)->memo_flags |= LAZY_MEMO_PACKED)
1635#define LAZY_MEMO_RESET_PACKED(memo) ((memo)->memo_flags &= ~LAZY_MEMO_PACKED)
1645 struct MEMO *result;
1647 result = MEMO_NEW(m, rb_enum_values_pack(argc, argv),
1648 argc > 1 ? LAZY_MEMO_PACKED : 0);
1649 return lazy_yielder_result(result,
yielder, procs_array, memos, 0);
1653lazy_yielder_yield(
struct MEMO *result,
long memo_index,
int argc,
const VALUE *argv)
1655 VALUE m = result->v1;
1659 LAZY_MEMO_SET_VALUE(result, rb_enum_values_pack(argc, argv));
1661 LAZY_MEMO_SET_PACKED(result);
1663 LAZY_MEMO_RESET_PACKED(result);
1664 return lazy_yielder_result(result,
yielder, procs_array, memos, memo_index);
1674 struct proc_entry *entry = proc_entry_ptr(proc);
1675 if (!(*entry->fn->proc)(proc, result, memos, i)) {
1684 if (LAZY_MEMO_BREAK_P(result)) {
1687 return result->memo_value;
1710 struct generator *old_gen_ptr = generator_ptr(e->obj);
1711 obj = old_gen_ptr->obj;
1717 generator = generator_allocate(rb_cGenerator);
1729lazy_precheck(
VALUE procs)
1732 long num_procs =
RARRAY_LEN(procs), i = num_procs;
1735 struct proc_entry *entry = proc_entry_ptr(proc);
1736 lazyenum_precheck_func *precheck = entry->fn->precheck;
1737 if (precheck && !precheck(proc))
return FALSE;
1834lazy_initialize(
int argc,
VALUE *argv,
VALUE self)
1847 generator = generator_allocate(rb_cGenerator);
1849 enumerator_init(self,
generator, sym_each, 0, 0, 0, size, 0);
1865lazy_to_a(
VALUE self)
1873 ID id = rb_frame_this_func();
1889 lazy_set_args(lazy, args);
1890 e->size_fn = size_fn;
1901 VALUE new_generator;
1906 &proc_entry_data_type, entry);
1913 lazy_set_args(entry_obj, memo);
1915 new_procs =
RTEST(e->procs) ? rb_ary_dup(e->procs) : rb_ary_new();
1916 new_generator = lazy_generator_init(obj, new_procs);
1917 rb_ary_push(new_procs, entry_obj);
1919 new_obj = enumerator_init_copy(enumerator_allocate(rb_cLazy), obj);
1921 new_e->obj = new_generator;
1922 new_e->procs = new_procs;
1929 new_e->meth = id_each;
1965enumerable_lazy(
VALUE obj)
1976 return enumerator_init(enumerator_allocate(rb_cLazy),
1977 obj, meth, argc, argv, size_fn,
Qnil, kw_splat);
2004lazy_to_enum(
int argc,
VALUE *argv,
VALUE self)
2006 VALUE lazy, meth = sym_each, super_meth;
2012 if (
RTEST((super_meth = rb_hash_aref(lazy_use_super_method, meth)))) {
2025 return enum_size(self);
2036lazy_eager(
VALUE self)
2039 self, sym_each, 0, 0, lazy_eager_size,
Qnil, 0);
2054 const VALUE *argv = &result->memo_value;
2055 if (LAZY_MEMO_PACKED_P(result)) {
2056 const VALUE args = *argv;
2067 LAZY_MEMO_SET_VALUE(result, value);
2068 LAZY_MEMO_RESET_PACKED(result);
2079 lazy_map_proc, lazy_map_size,
2102 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_map_funcs);
2106 struct MEMO *result;
2115 return lazy_yielder_yield(arg->result, arg->index, argc, argv);
2123 const long proc_index = memo_index + 1;
2124 int break_p = LAZY_MEMO_BREAK_P(result);
2130 struct flat_map_i_arg arg = {.result = result, .index = proc_index};
2131 LAZY_MEMO_RESET_BREAK(result);
2133 if (break_p) LAZY_MEMO_SET_BREAK(result);
2137 if (ary || !
NIL_P(ary = rb_check_array_type(value))) {
2139 LAZY_MEMO_RESET_BREAK(result);
2142 lazy_yielder_yield(result, proc_index, 1, &argv);
2144 if (break_p) LAZY_MEMO_SET_BREAK(result);
2148 LAZY_MEMO_SET_VALUE(result, value);
2149 LAZY_MEMO_RESET_PACKED(result);
2154 lazy_flat_map_proc, 0,
2181lazy_flat_map(
VALUE obj)
2187 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_flat_map_funcs);
2194 if (!
RTEST(chain))
return 0;
2199 lazy_select_proc, 0,
2211lazy_select(
VALUE obj)
2217 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_select_funcs);
2224 if (!
RTEST(value))
return 0;
2225 LAZY_MEMO_SET_VALUE(result, value);
2226 LAZY_MEMO_RESET_PACKED(result);
2231 lazy_filter_map_proc, 0,
2245lazy_filter_map(
VALUE obj)
2251 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_filter_map_funcs);
2258 if (
RTEST(chain))
return 0;
2263 lazy_reject_proc, 0,
2274lazy_reject(
VALUE obj)
2280 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_reject_funcs);
2288 if (!
RTEST(chain))
return 0;
2296 VALUE value, chain =
rb_funcall(entry->memo, id_eqq, 1, result->memo_value);
2298 if (!
RTEST(chain))
return 0;
2300 LAZY_MEMO_SET_VALUE(result, value);
2301 LAZY_MEMO_RESET_PACKED(result);
2307 lazy_grep_iter_proc, 0,
2326 &lazy_grep_iter_funcs : &lazy_grep_funcs;
2327 return lazy_add_method(obj, 0, 0, pattern,
rb_ary_new3(1, pattern), funcs);
2335 if (
RTEST(chain))
return 0;
2343 VALUE value, chain =
rb_funcall(entry->memo, id_eqq, 1, result->memo_value);
2345 if (
RTEST(chain))
return 0;
2347 LAZY_MEMO_SET_VALUE(result, value);
2348 LAZY_MEMO_RESET_PACKED(result);
2354 lazy_grep_v_iter_proc, 0,
2358 lazy_grep_v_proc, 0,
2373 &lazy_grep_v_iter_funcs : &lazy_grep_v_funcs;
2374 return lazy_add_method(obj, 0, 0, pattern,
rb_ary_new3(1, pattern), funcs);
2393 VALUE ary, arrays = entry->memo;
2394 VALUE memo = rb_ary_entry(memos, memo_index);
2398 rb_ary_push(ary, result->memo_value);
2400 rb_ary_push(ary, rb_ary_entry(
RARRAY_AREF(arrays, i), count));
2402 LAZY_MEMO_SET_VALUE(result, ary);
2403 LAZY_MEMO_SET_PACKED(result);
2404 rb_ary_store(memos, memo_index,
LONG2NUM(++count));
2412 VALUE arg = rb_ary_entry(memos, memo_index);
2413 VALUE zip_args = entry->memo;
2422 rb_ary_store(memos, memo_index, arg);
2426 rb_ary_push(ary, result->memo_value);
2430 rb_ary_push(ary, v);
2432 LAZY_MEMO_SET_VALUE(result, ary);
2433 LAZY_MEMO_SET_PACKED(result);
2438 {lazy_zip_func, lazy_receiver_size,},
2439 {lazy_zip_arrays_func, lazy_receiver_size,},
2462 for (i = 0; i < argc; i++) {
2463 v = rb_check_array_type(argv[i]);
2465 for (; i < argc; i++) {
2472 funcs = &lazy_zip_funcs[0];
2475 rb_ary_push(ary, v);
2478 return lazy_add_method(obj, 0, 0, ary, ary, funcs);
2486 VALUE memo = rb_ary_entry(memos, memo_index);
2493 if (--remain == 0) LAZY_MEMO_SET_BREAK(result);
2494 rb_ary_store(memos, memo_index,
LONG2NUM(remain));
2511 return entry->memo !=
INT2FIX(0);
2515 lazy_take_proc, lazy_take_size, lazy_take_precheck,
2536 return lazy_add_method(obj, 0, 0, n,
rb_ary_new3(1, n), &lazy_take_funcs);
2544 LAZY_MEMO_SET_BREAK(result);
2551 lazy_take_while_proc, 0,
2562lazy_take_while(
VALUE obj)
2568 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_take_while_funcs);
2575 if (
NIL_P(receiver))
2579 return LONG2FIX(len < 0 ? 0 : len);
2589 VALUE memo = rb_ary_entry(memos, memo_index);
2597 rb_ary_store(memos, memo_index,
LONG2NUM(remain));
2605 lazy_drop_proc, lazy_drop_size,
2627 return lazy_add_method(obj, 2, argv, n,
rb_ary_new3(1, n), &lazy_drop_funcs);
2634 VALUE memo = rb_ary_entry(memos, memo_index);
2642 if (
RTEST(drop))
return 0;
2643 rb_ary_store(memos, memo_index,
Qtrue);
2649 lazy_drop_while_proc, 0,
2660lazy_drop_while(
VALUE obj)
2666 return lazy_add_method(obj, 0, 0,
Qfalse,
Qnil, &lazy_drop_while_funcs);
2670lazy_uniq_check(
VALUE chain,
VALUE memos,
long memo_index)
2672 VALUE hash = rb_ary_entry(memos, memo_index);
2676 rb_ary_store(memos, memo_index, hash);
2679 return rb_hash_add_new_element(hash, chain,
Qfalse);
2685 if (lazy_uniq_check(result->memo_value, memos, memo_index))
return 0;
2694 if (lazy_uniq_check(chain, memos, memo_index))
return 0;
2699 lazy_uniq_iter_proc, 0,
2719 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, funcs);
2725 if (
NIL_P(result->memo_value))
return 0;
2730 lazy_compact_proc, 0,
2741lazy_compact(
VALUE obj)
2743 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_compact_funcs);
2750 VALUE memo = rb_ary_entry(memos, memo_index);
2757 argv[0] = result->memo_value;
2761 LAZY_MEMO_RESET_PACKED(result);
2764 LAZY_MEMO_SET_VALUE(result, rb_ary_new_from_values(2, argv));
2765 LAZY_MEMO_SET_PACKED(result);
2772lazy_with_index_size(
VALUE proc,
VALUE receiver)
2778 lazy_with_index_proc, lazy_with_index_size,
2799lazy_with_index(
int argc,
VALUE *argv,
VALUE obj)
2807 return lazy_add_method(obj, 0, 0, memo, rb_ary_new_from_values(1, &memo), &lazy_with_index_funcs);
2819lazy_chunk(
VALUE self)
2830lazy_chunk_while(
VALUE self)
2842lazy_slice_after(
VALUE self)
2854lazy_slice_before(
VALUE self)
2865lazy_slice_when(
VALUE self)
2937stop_result(
VALUE self)
2947producer_mark(
void *p)
2950 rb_gc_mark_movable(ptr->init);
2951 rb_gc_mark_movable(ptr->proc);
2955producer_compact(
void *p)
2958 ptr->init = rb_gc_location(ptr->init);
2959 ptr->proc = rb_gc_location(ptr->proc);
2962#define producer_free RUBY_TYPED_DEFAULT_FREE
2965producer_memsize(
const void *p)
2978 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
2982producer_ptr(
VALUE obj)
2987 if (!ptr || UNDEF_P(ptr->proc)) {
2995producer_allocate(
VALUE klass)
3030NORETURN(
static VALUE producer_each_i(
VALUE obj));
3033producer_each_i(
VALUE obj)
3036 VALUE init, proc, curr;
3038 ptr = producer_ptr(obj);
3042 if (UNDEF_P(init)) {
3060producer_each(
VALUE obj)
3109enumerator_s_produce(
int argc,
VALUE *argv,
VALUE klass)
3135enum_chain_mark(
void *p)
3138 rb_gc_mark_movable(ptr->enums);
3142enum_chain_compact(
void *p)
3145 ptr->enums = rb_gc_location(ptr->enums);
3148#define enum_chain_free RUBY_TYPED_DEFAULT_FREE
3151enum_chain_memsize(
const void *p)
3164 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3168enum_chain_ptr(
VALUE obj)
3173 if (!ptr || UNDEF_P(ptr->enums)) {
3181enum_chain_allocate(
VALUE klass)
3221new_enum_chain(
VALUE enums)
3224 VALUE obj = enum_chain_initialize(enum_chain_allocate(rb_cEnumChain), enums);
3228 return enumerable_lazy(obj);
3242 ptr0 = enum_chain_ptr(orig);
3248 ptr1->enums = ptr0->enums;
3249 ptr1->pos = ptr0->pos;
3255enum_chain_total_size(
VALUE enums)
3286enum_chain_size(
VALUE obj)
3288 return enum_chain_total_size(enum_chain_ptr(obj)->enums);
3294 return enum_chain_size(obj);
3316enum_chain_each(
int argc,
VALUE *argv,
VALUE obj)
3324 objptr = enum_chain_ptr(obj);
3325 enums = objptr->enums;
3345enum_chain_rewind(
VALUE obj)
3347 struct enum_chain *objptr = enum_chain_ptr(obj);
3348 VALUE enums = objptr->enums;
3351 for (i = objptr->pos; 0 <= i && i <
RARRAY_LEN(enums); objptr->pos = --i) {
3359inspect_enum_chain(
VALUE obj,
VALUE dummy,
int recur)
3366 if (!ptr || UNDEF_P(ptr->enums)) {
3384enum_chain_inspect(
VALUE obj)
3402 VALUE enums = rb_ary_new_from_values(1, &obj);
3403 rb_ary_cat(enums, argv, argc);
3404 return new_enum_chain(enums);
3420 return new_enum_chain(rb_ary_new_from_args(2, obj, eobj));
3457enum_product_mark(
void *p)
3460 rb_gc_mark_movable(ptr->enums);
3464enum_product_compact(
void *p)
3467 ptr->enums = rb_gc_location(ptr->enums);
3470#define enum_product_free RUBY_TYPED_DEFAULT_FREE
3473enum_product_memsize(
const void *p)
3483 enum_product_memsize,
3484 enum_product_compact,
3486 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3490enum_product_ptr(
VALUE obj)
3495 if (!ptr || UNDEF_P(ptr->enums)) {
3503enum_product_allocate(
VALUE klass)
3526enum_product_initialize(
int argc,
VALUE *argv,
VALUE obj)
3534 rb_exc_raise(rb_keyword_error_new(
"unknown", rb_hash_keys(options)));
3554 ptr0 = enum_product_ptr(orig);
3560 ptr1->enums = ptr0->enums;
3566enum_product_total_size(
VALUE enums)
3597enum_product_size(
VALUE obj)
3599 return enum_product_total_size(enum_product_ptr(obj)->enums);
3605 return enum_product_size(obj);
3622 pstate->argv[pstate->index++] = value;
3624 VALUE val = product_each(pstate->obj, pstate);
3633 VALUE enums = ptr->enums;
3635 if (pstate->index < pstate->argc) {
3641 rb_funcall(pstate->block, id_call, 1, rb_ary_new_from_values(pstate->argc, pstate->argv));
3660 return product_each(obj, &state);
3676enum_product_each(
VALUE obj)
3692enum_product_rewind(
VALUE obj)
3695 VALUE enums = ptr->enums;
3706inspect_enum_product(
VALUE obj,
VALUE dummy,
int recur)
3713 if (!ptr || UNDEF_P(ptr->enums)) {
3731enum_product_inspect(
VALUE obj)
3753enumerator_s_product(
int argc,
VALUE *argv,
VALUE klass)
3757 rb_scan_args(argc, argv,
"*:&", &enums, &options, &block);
3760 rb_exc_raise(rb_keyword_error_new(
"unknown", rb_hash_keys(options)));
3763 VALUE obj = enum_product_initialize(argc, argv, enum_product_allocate(rb_cEnumProduct));
3765 if (!
NIL_P(block)) {
3766 enum_product_run(obj, block);
3790 VALUE aseq = enumerator_init(enumerator_allocate(rb_cArithSeq),
3806arith_seq_begin(
VALUE self)
3817arith_seq_end(
VALUE self)
3829arith_seq_step(
VALUE self)
3840arith_seq_exclude_end(
VALUE self)
3846arith_seq_exclude_end_p(
VALUE self)
3848 return RTEST(arith_seq_exclude_end(self));
3855 component->
begin = arith_seq_begin(obj);
3856 component->
end = arith_seq_end(obj);
3857 component->
step = arith_seq_step(obj);
3858 component->
exclude_end = arith_seq_exclude_end_p(obj);
3870rb_arithmetic_sequence_beg_len_step(
VALUE obj,
long *begp,
long *lenp,
long *stepp,
long len,
int err)
3872 RBIMPL_NONNULL_ARG(begp);
3873 RBIMPL_NONNULL_ARG(lenp);
3874 RBIMPL_NONNULL_ARG(stepp);
3877 if (!rb_arithmetic_sequence_extract(obj, &aseq)) {
3897 if (err == 0 && (step < -1 || step > 1)) {
3907 return rb_range_component_beg_len(aseq.
begin, aseq.
end, aseq.
exclude_end, begp, lenp, len, err);
3924arith_seq_first(
int argc,
VALUE *argv,
VALUE self)
3932 b = arith_seq_begin(self);
3933 e = arith_seq_end(self);
3934 s = arith_seq_step(self);
3959 return rb_ary_new_capa(0);
3962 x = arith_seq_exclude_end_p(self);
3966 ary = rb_ary_new_capa(n);
3975 rb_ary_push(ary, b);
3976 b = rb_big_plus(b, s);
3992 if (len < 0) len = 0;
3993 ary = rb_ary_new_capa((n < len) ? n : len);
3994 while (n > 0 && i < end) {
3996 if (i + unit < i)
break;
4005 if (len < 0) len = 0;
4006 ary = rb_ary_new_capa((n < len) ? n : len);
4007 while (n > 0 && i > end) {
4009 if (i + unit > i)
break;
4021 double end =
NIL_P(e) ? (unit < 0 ? -1 : 1)*HUGE_VAL :
NUM2DBL(e);
4022 double len = ruby_float_step_size(beg, end, unit, x);
4030 ary = rb_ary_new_capa(1);
4031 rb_ary_push(ary,
DBL2NUM(beg));
4034 ary = rb_ary_new_capa(0);
4037 else if (unit == 0) {
4039 ary = rb_ary_new_capa(n);
4040 for (i = 0; i < len; ++i) {
4041 rb_ary_push(ary, val);
4045 ary = rb_ary_new_capa(n);
4046 for (i = 0; i < n; ++i) {
4047 double d = i*unit+beg;
4048 if (unit >= 0 ? end < d : d < end) d = end;
4063 return rb_int_plus(a, b);
4066 return rb_float_plus(a, b);
4069 return rb_rational_plus(a, b);
4072 return rb_funcallv(a,
'+', 1, &b);
4080 return rb_int_minus(a, b);
4083 return rb_float_minus(a, b);
4086 return rb_rational_minus(a, b);
4089 return rb_funcallv(a,
'-', 1, &b);
4097 return rb_int_mul(a, b);
4100 return rb_float_mul(a, b);
4103 return rb_rational_mul(a, b);
4106 return rb_funcallv(a,
'*', 1, &b);
4115 q = rb_int_idiv(a, b);
4118 q = rb_float_div(a, b);
4121 q = rb_rational_div(a, b);
4124 q = rb_funcallv(a, idDiv, 1, &b);
4131 return rb_float_floor(q, 0);
4134 return rb_rational_floor(q, 0);
4150arith_seq_last(
int argc,
VALUE *argv,
VALUE self)
4152 VALUE b, e, s, len_1, len, last, nv, ary;
4153 int last_is_adjusted;
4156 e = arith_seq_end(self);
4159 "cannot get the last element of endless arithmetic sequence");
4162 b = arith_seq_begin(self);
4163 s = arith_seq_step(self);
4165 len_1 = num_idiv(num_minus(e, b), s);
4166 if (rb_num_negative_int_p(len_1)) {
4170 return rb_ary_new_capa(0);
4173 last = num_plus(b, num_mul(s, len_1));
4174 if ((last_is_adjusted = arith_seq_exclude_end_p(self) &&
rb_equal(last, e))) {
4175 last = num_minus(last, s);
4182 if (last_is_adjusted) {
4186 len = rb_int_plus(len_1,
INT2FIX(1));
4193 if (
RTEST(rb_int_gt(nv, len))) {
4201 ary = rb_ary_new_capa(n);
4202 b = rb_int_minus(last, rb_int_mul(s, nv));
4204 b = rb_int_plus(b, s);
4205 rb_ary_push(ary, b);
4219arith_seq_inspect(
VALUE self)
4222 VALUE eobj, str, eargs;
4233 str =
rb_sprintf(
"(%s%"PRIsVALUE
"%s.", range_p ?
"(" :
"", eobj, range_p ?
")" :
"");
4253 if (all_key) kwds = argv[--argc];
4257 VALUE arg = *argv++;
4289 if (!
rb_equal(arith_seq_begin(self), arith_seq_begin(other))) {
4293 if (!
rb_equal(arith_seq_end(self), arith_seq_end(other))) {
4297 if (!
rb_equal(arith_seq_step(self), arith_seq_step(other))) {
4301 if (arith_seq_exclude_end_p(self) != arith_seq_exclude_end_p(other)) {
4319arith_seq_hash(
VALUE self)
4325 v = rb_hash(arith_seq_begin(self));
4327 v = rb_hash(arith_seq_end(self));
4329 v = rb_hash(arith_seq_step(self));
4336#define NUM_GE(x, y) RTEST(rb_num_coerce_relop((x), (y), idGE))
4351arith_seq_each(
VALUE self)
4353 VALUE c, e, s, len_1, last;
4358 c = arith_seq_begin(self);
4359 e = arith_seq_end(self);
4360 s = arith_seq_step(self);
4361 x = arith_seq_exclude_end_p(self);
4370 c = rb_int_plus(c, s);
4384 len_1 = num_idiv(num_minus(e, c), s);
4385 last = num_plus(c, num_mul(s, len_1));
4387 last = num_minus(last, s);
4390 if (rb_num_negative_int_p(s)) {
4391 while (NUM_GE(c, last)) {
4397 while (NUM_GE(last, c)) {
4414arith_seq_size(
VALUE self)
4416 VALUE b, e, s, len_1, len, last;
4419 b = arith_seq_begin(self);
4420 e = arith_seq_end(self);
4421 s = arith_seq_step(self);
4422 x = arith_seq_exclude_end_p(self);
4428 if (rb_num_negative_int_p(s)) {
4440 if (isinf(n))
return DBL2NUM(n);
4442 return rb_dbl2big(n);
4457 len_1 = rb_int_idiv(rb_int_minus(e, b), s);
4458 if (rb_num_negative_int_p(len_1)) {
4462 last = rb_int_plus(b, rb_int_mul(s, len_1));
4467 len = rb_int_plus(len_1,
INT2FIX(1));
4473#define sym(name) ID2SYM(rb_intern_const(name))
4475InitVM_Enumerator(
void)
4511 rb_define_alias(rb_cLazy,
"_enumerable_collect_concat",
"collect_concat");
4527 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_map"));
4528 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_collect"));
4529 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_flat_map"));
4530 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_collect_concat"));
4531 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_select"));
4532 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_find_all"));
4533 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_filter"));
4534 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_filter_map"));
4535 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_reject"));
4536 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_grep"));
4537 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_grep_v"));
4538 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_zip"));
4539 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_take"));
4540 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_take_while"));
4541 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_drop"));
4542 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_drop_while"));
4543 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_uniq"));
4575 lazy_use_super_method = rb_hash_new_with_size(18);
4576 rb_hash_aset(lazy_use_super_method, sym(
"map"), sym(
"_enumerable_map"));
4577 rb_hash_aset(lazy_use_super_method, sym(
"collect"), sym(
"_enumerable_collect"));
4578 rb_hash_aset(lazy_use_super_method, sym(
"flat_map"), sym(
"_enumerable_flat_map"));
4579 rb_hash_aset(lazy_use_super_method, sym(
"collect_concat"), sym(
"_enumerable_collect_concat"));
4580 rb_hash_aset(lazy_use_super_method, sym(
"select"), sym(
"_enumerable_select"));
4581 rb_hash_aset(lazy_use_super_method, sym(
"find_all"), sym(
"_enumerable_find_all"));
4582 rb_hash_aset(lazy_use_super_method, sym(
"filter"), sym(
"_enumerable_filter"));
4583 rb_hash_aset(lazy_use_super_method, sym(
"filter_map"), sym(
"_enumerable_filter_map"));
4584 rb_hash_aset(lazy_use_super_method, sym(
"reject"), sym(
"_enumerable_reject"));
4585 rb_hash_aset(lazy_use_super_method, sym(
"grep"), sym(
"_enumerable_grep"));
4586 rb_hash_aset(lazy_use_super_method, sym(
"grep_v"), sym(
"_enumerable_grep_v"));
4587 rb_hash_aset(lazy_use_super_method, sym(
"zip"), sym(
"_enumerable_zip"));
4588 rb_hash_aset(lazy_use_super_method, sym(
"take"), sym(
"_enumerable_take"));
4589 rb_hash_aset(lazy_use_super_method, sym(
"take_while"), sym(
"_enumerable_take_while"));
4590 rb_hash_aset(lazy_use_super_method, sym(
"drop"), sym(
"_enumerable_drop"));
4591 rb_hash_aset(lazy_use_super_method, sym(
"drop_while"), sym(
"_enumerable_drop_while"));
4592 rb_hash_aset(lazy_use_super_method, sym(
"uniq"), sym(
"_enumerable_uniq"));
4593 rb_hash_aset(lazy_use_super_method, sym(
"with_index"), sym(
"_enumerable_with_index"));
4595 rb_gc_register_mark_object(lazy_use_super_method);
4615 rb_define_method(rb_cGenerator,
"initialize_copy", generator_init_copy, 1);
4636 rb_define_method(rb_cEnumChain,
"initialize_copy", enum_chain_init_copy, 1);
4650 rb_define_method(rb_cEnumProduct,
"initialize", enum_product_initialize, -1);
4651 rb_define_method(rb_cEnumProduct,
"initialize_copy", enum_product_init_copy, 1);
4686Init_Enumerator(
void)
4703 sym_each =
ID2SYM(id_each);
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
void rb_need_block(void)
Declares that the current method needs a block.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
int rb_keyword_given_p(void)
Determines if the current method is given a keyword argument.
int rb_block_given_p(void)
Determines if the current method is given a block.
#define T_COMPLEX
Old name of RUBY_T_COMPLEX.
#define RB_INTEGER_TYPE_P
Old name of rb_integer_type_p.
#define rb_str_buf_cat2
Old name of rb_usascii_str_new_cstr.
#define OBJ_INIT_COPY(obj, orig)
Old name of RB_OBJ_INIT_COPY.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define T_FLOAT
Old name of RUBY_T_FLOAT.
#define ID2SYM
Old name of RB_ID2SYM.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define CLASS_OF
Old name of rb_class_of.
#define rb_ary_new4
Old name of rb_ary_new_from_values.
#define FIXABLE
Old name of RB_FIXABLE.
#define rb_exc_new2
Old name of rb_exc_new_cstr.
#define LONG2FIX
Old name of RB_INT2FIX.
#define T_RATIONAL
Old name of RUBY_T_RATIONAL.
#define T_HASH
Old name of RUBY_T_HASH.
#define NUM2DBL
Old name of rb_num2dbl.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define Qtrue
Old name of RUBY_Qtrue.
#define ST2FIX
Old name of RB_ST2FIX.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define FIX2LONG
Old name of RB_FIX2LONG.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define ALLOCV_N
Old name of RB_ALLOCV_N.
#define POSFIXABLE
Old name of RB_POSFIXABLE.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
#define DBL2NUM
Old name of rb_float_new.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define ALLOCV_END
Old name of RB_ALLOCV_END.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_iter_break(void)
Breaks from a block.
VALUE rb_eRangeError
RangeError exception.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_eStopIteration
StopIteration exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports always regardless of runtime -W flag.
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Identical to rb_exc_new_cstr(), except it takes a Ruby's string instead of C's.
VALUE rb_eArgError
ArgumentError exception.
VALUE rb_eIndexError
IndexError exception.
VALUE rb_mKernel
Kernel module.
VALUE rb_mEnumerable
Enumerable module.
VALUE rb_cEnumerator
Enumerator class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_cNumeric
Numeric class.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_obj_dup(VALUE obj)
Duplicates the given object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_cRange
Range class.
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given class.
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
VALUE rb_to_int(VALUE val)
Identical to rb_check_to_int(), except it raises in case of conversion mismatch.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE procval)
Identical to rb_funcallv_public(), except you can pass a block.
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
This roughly resembles return enum_for(__callee__) unless block_given?.
VALUE rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj)
This is the type of functions that rb_enumeratorize_with_size() expects.
#define rb_check_frozen
Just another name of rb_check_frozen.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
VALUE rb_num_coerce_cmp(VALUE lhs, VALUE rhs, ID op)
Identical to rb_num_coerce_bin(), except for return values.
VALUE rb_obj_method(VALUE recv, VALUE mid)
Creates a method object.
VALUE rb_block_proc(void)
Constructs a Proc object from implicitly passed components.
VALUE rb_proc_call_with_block(VALUE recv, int argc, const VALUE *argv, VALUE proc)
Identical to rb_proc_call(), except you can additionally pass another proc object,...
VALUE rb_proc_call_kw(VALUE recv, VALUE args, int kw_splat)
Identical to rb_proc_call(), except you can specify how to handle the last element of the given array...
VALUE rb_obj_is_proc(VALUE recv)
Queries if the given object is a proc.
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
Deconstructs a range into its components.
#define rb_hash_uint(h, i)
Just another name of st_hash_uint.
#define rb_hash_end(h)
Just another name of st_hash_end.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
VALUE rb_str_buf_append(VALUE dst, VALUE src)
Identical to rb_str_cat_cstr(), except it takes Ruby's string instead of C's.
void rb_str_set_len(VALUE str, long len)
Overwrites the length of the string.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
VALUE rb_exec_recursive(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h)
"Recursion" API entry point.
VALUE rb_attr_get(VALUE obj, ID name)
Identical to rb_ivar_get()
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
VALUE rb_check_funcall_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_check_funcall(), except you can specify how to handle the last element of the given a...
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_sym2str(VALUE id)
Identical to rb_id2str(), except it takes an instance of rb_cSymbol rather than an ID.
ID rb_to_id(VALUE str)
Identical to rb_intern(), except it takes an instance of rb_cString.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
VALUE rb_str_catf(VALUE dst, const char *fmt,...)
Identical to rb_sprintf(), except it renders the output to the specified object rather than creating ...
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
VALUE rb_yield_values(int n,...)
Identical to rb_yield(), except it takes variadic number of parameters and pass them to the block.
VALUE rb_yield_values2(int n, const VALUE *argv)
Identical to rb_yield_values(), except it takes the parameters as a C array instead of variadic argum...
VALUE rb_yield(VALUE val)
Yields the block.
VALUE rb_yield_values_kw(int n, const VALUE *argv, int kw_splat)
Identical to rb_yield_values2(), except you can specify how to handle the last element of the given a...
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
This is the type of a function that the interpreter expect for C-backended blocks.
VALUE rb_block_call_kw(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t proc, VALUE data2, int kw_splat)
Identical to rb_funcallv_kw(), except it additionally passes a function as a block.
#define rb_long2int
Just another name of rb_long2int_inline.
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#define ALLOCA_N(type, n)
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE rb_proc_new(type *q, VALUE w)
Creates a rb_cProc instance.
VALUE rb_fiber_new(type *q, VALUE w)
Creates a rb_cFiber instance.
void rb_hash_foreach(VALUE q, int_type *w, VALUE e)
Iteration over the given hash.
VALUE rb_rescue2(type *q, VALUE w, type *e, VALUE r,...)
An equivalent of rescue clause.
#define RARRAY_LEN
Just another name of rb_array_len.
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define DATA_PTR(obj)
Convenient getter macro.
#define RHASH_EMPTY_P(h)
Checks if the hash is empty.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
#define InitVM(ext)
This macro is for internal use.
#define RB_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
#define RB_NO_KEYWORDS
Do not pass keywords.
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
Decomposed Enumerator::ArithmeicSequence.
int exclude_end
Whether the endpoint is open or closed.
VALUE end
"Right" or "highest" endpoint of the sequence.
VALUE step
Step between a sequence.
VALUE begin
"Left" or "lowest" endpoint of the sequence.
This is the struct that holds necessary info for a struct.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_FLOAT_TYPE_P(VALUE obj)
Queries if the object is an instance of rb_cFloat.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.