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"
164 static VALUE rb_cLazy;
165 static ID id_rewind, id_new, id_to_enum, id_each_entry;
166 static ID id_next, id_result, id_receiver, id_arguments, id_memo, id_method, id_force;
167 static ID id_begin, id_end, id_step, id_exclude_end;
168 static VALUE sym_each, sym_cycle, sym_yield;
170 static VALUE lazy_use_super_method;
172 extern ID ruby_static_id_cause;
174 #define id_call idCall
175 #define id_cause ruby_static_id_cause
176 #define id_each idEach
178 #define id_initialize idInitialize
179 #define id_size idSize
198 RUBY_REFERENCES(enumerator_refs) = {
211 static VALUE rb_cGenerator, rb_cYielder, rb_cEnumProducer;
231 lazyenum_proc_func *proc;
232 lazyenum_size_func *size;
233 lazyenum_precheck_func *precheck;
245 static VALUE rb_cEnumChain;
252 static VALUE rb_cEnumProduct;
263 RUBY_REFS_LIST_PTR(enumerator_refs),
268 0, NULL, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_DECL_MARKING | RUBY_TYPED_EMBEDDABLE
272 enumerator_ptr(
VALUE obj)
277 if (!
ptr || UNDEF_P(
ptr->obj)) {
284 proc_entry_mark(
void *p)
292 proc_entry_compact(
void *p)
307 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
398 enumerator_allocate(
VALUE klass)
414 rb_check_frozen(enum_obj);
430 ptr->size_fn = size_fn;
431 ptr->kw_splat = kw_splat;
437 convert_to_feasible_size_value(
VALUE obj)
479 enumerator_initialize(
int argc,
VALUE *argv,
VALUE obj)
482 VALUE recv = generator_init(generator_allocate(rb_cGenerator), iter);
484 VALUE size = convert_to_feasible_size_value(arg0);
486 return enumerator_init(obj, recv, sym_each, 0, 0, 0, size,
false);
496 ptr0 = enumerator_ptr(orig);
509 ptr1->meth = ptr0->meth;
515 ptr1->size_fn = ptr0->size_fn;
530 static int lazy_precheck(
VALUE procs);
538 base_class = rb_cLazy;
541 obj = enumerator_init(enumerator_allocate(
rb_cEnumerator), obj, sym_each, 0, 0, 0,
Qnil,
false);
544 return enumerator_init(enumerator_allocate(base_class),
545 obj, meth, argc, argv, size_fn,
Qnil, kw_splat);
558 const VALUE *argv = 0;
559 const struct enumerator *e = enumerator_ptr(obj);
562 VALUE args = e->args;
612 enumerator_each(
int argc,
VALUE *argv,
VALUE obj)
619 #if SIZEOF_INT < SIZEOF_LONG
635 if (!lazy_precheck(e->procs))
return Qnil;
637 return enumerator_block_call(obj, 0, obj);
643 struct MEMO *memo = (
struct MEMO *)m;
644 VALUE idx = memo->v1;
645 MEMO_V1_SET(memo, rb_int_succ(idx));
654 enumerator_size(
VALUE obj);
659 return enumerator_size(obj);
675 enumerator_with_index(
int argc,
VALUE *argv,
VALUE obj)
682 return enumerator_block_call(obj, enumerator_with_index_i, (
VALUE)MEMO_NEW(memo, 0, 0));
696 enumerator_each_with_index(
VALUE obj)
698 return enumerator_with_index(0, NULL, obj);
743 enumerator_block_call(obj, enumerator_with_object_i, memo);
755 if (!UNDEF_P(e->feedvalue)) {
756 feedvalue = e->feedvalue;
790 VALUE exc = e->stop_exc;
863 enumerator_next_values(
VALUE obj)
868 rb_check_frozen(obj);
870 if (!UNDEF_P(e->lookahead)) {
876 return get_next_values(obj, e);
880 ary2sv(
VALUE args,
int dup)
920 enumerator_next(
VALUE obj)
922 VALUE vs = enumerator_next_values(obj);
923 return ary2sv(vs, 0);
927 enumerator_peek_values(
VALUE obj)
931 rb_check_frozen(obj);
933 if (UNDEF_P(e->lookahead)) {
934 RB_OBJ_WRITE(obj, &e->lookahead, get_next_values(obj, e));
971 enumerator_peek_values_m(
VALUE obj)
973 return rb_ary_dup(enumerator_peek_values(obj));
1001 enumerator_peek(
VALUE obj)
1003 VALUE vs = enumerator_peek_values(obj);
1004 return ary2sv(vs, 1);
1058 rb_check_frozen(obj);
1060 if (!UNDEF_P(e->feedvalue)) {
1078 enumerator_rewind(
VALUE obj)
1082 rb_check_frozen(obj);
1098 inspect_enumerator(
VALUE obj,
VALUE dummy,
int recur)
1101 VALUE eobj, str, cname;
1107 if (!e || UNDEF_P(e->obj)) {
1119 eobj = generator_ptr(e->obj)->obj;
1128 str =
rb_sprintf(
"#<%"PRIsVALUE
": %"PRIsVALUE, cname, str);
1129 append_method(
RARRAY_AREF(e->procs, i), str, e->meth, e->args);
1142 append_method(obj, str, e->meth, e->args);
1152 if (
SYMBOL_P(key))
return ST_CONTINUE;
1153 *(
int *)arg = FALSE;
1161 rb_str_catf(str,
"% "PRIsVALUE
": %"PRIsVALUE
", ", key, val);
1168 VALUE method, eargs;
1172 if (!
NIL_P(method)) {
1185 eargs = default_args;
1199 if (all_key) kwds = argv[--argc];
1203 VALUE arg = *argv++;
1227 enumerator_inspect(
VALUE obj)
1244 enumerator_size(
VALUE obj)
1248 const VALUE *argv = NULL;
1252 struct generator *g = generator_ptr(e->obj);
1258 struct proc_entry *entry = proc_entry_ptr(proc);
1259 lazyenum_size_func *size_fn = entry->fn->size;
1263 receiver = (*size_fn)(proc, receiver);
1269 return (*e->size_fn)(e->obj, e->args, obj);
1276 if (!UNDEF_P(size))
return size;
1284 yielder_mark(
void *p)
1291 yielder_compact(
void *p)
1305 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
1309 yielder_ptr(
VALUE obj)
1314 if (!
ptr || UNDEF_P(
ptr->proc)) {
1322 yielder_allocate(
VALUE klass)
1351 yielder_initialize(
VALUE obj)
1391 yielder_to_proc(
VALUE obj)
1407 return yielder_init(yielder_allocate(rb_cYielder),
rb_proc_new(yielder_yield_i, 0));
1414 generator_mark(
void *p)
1422 generator_compact(
void *p)
1437 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
1441 generator_ptr(
VALUE obj)
1446 if (!
ptr || UNDEF_P(
ptr->proc)) {
1454 generator_allocate(
VALUE klass)
1470 rb_check_frozen(obj);
1484 generator_initialize(
int argc,
VALUE *argv,
VALUE obj)
1498 "wrong argument type %"PRIsVALUE
" (expected Proc)",
1502 rb_warn(
"given block not used");
1506 return generator_init(obj, proc);
1517 ptr0 = generator_ptr(orig);
1532 generator_each(
int argc,
VALUE *argv,
VALUE obj)
1547 enum_size(
VALUE self)
1550 return UNDEF_P(r) ?
Qnil : r;
1556 return enum_size(
self);
1559 #define lazy_receiver_size lazy_map_size
1590 rb_block_call(m, id_each, argc-1, argv+1, lazy_init_iterator, val);
1594 #define memo_value v2
1595 #define memo_flags u3.state
1596 #define LAZY_MEMO_BREAK 1
1597 #define LAZY_MEMO_PACKED 2
1598 #define LAZY_MEMO_BREAK_P(memo) ((memo)->memo_flags & LAZY_MEMO_BREAK)
1599 #define LAZY_MEMO_PACKED_P(memo) ((memo)->memo_flags & LAZY_MEMO_PACKED)
1600 #define LAZY_MEMO_SET_BREAK(memo) ((memo)->memo_flags |= LAZY_MEMO_BREAK)
1601 #define LAZY_MEMO_RESET_BREAK(memo) ((memo)->memo_flags &= ~LAZY_MEMO_BREAK)
1602 #define LAZY_MEMO_SET_VALUE(memo, value) MEMO_V2_SET(memo, value)
1603 #define LAZY_MEMO_SET_PACKED(memo) ((memo)->memo_flags |= LAZY_MEMO_PACKED)
1604 #define LAZY_MEMO_RESET_PACKED(memo) ((memo)->memo_flags &= ~LAZY_MEMO_PACKED)
1614 struct MEMO *result;
1617 argc > 1 ? LAZY_MEMO_PACKED : 0);
1618 return lazy_yielder_result(result,
yielder, procs_array, memos, 0);
1622 lazy_yielder_yield(
struct MEMO *result,
long memo_index,
int argc,
const VALUE *argv)
1624 VALUE m = result->v1;
1630 LAZY_MEMO_SET_PACKED(result);
1632 LAZY_MEMO_RESET_PACKED(result);
1633 return lazy_yielder_result(result,
yielder, procs_array, memos, memo_index);
1643 struct proc_entry *entry = proc_entry_ptr(proc);
1644 if (!(*entry->fn->proc)(proc, result, memos, i)) {
1653 if (LAZY_MEMO_BREAK_P(result)) {
1656 return result->memo_value;
1679 struct generator *old_gen_ptr = generator_ptr(e->obj);
1680 obj = old_gen_ptr->obj;
1686 generator = generator_allocate(rb_cGenerator);
1698 lazy_precheck(
VALUE procs)
1701 long num_procs =
RARRAY_LEN(procs), i = num_procs;
1704 struct proc_entry *entry = proc_entry_ptr(proc);
1705 lazyenum_precheck_func *precheck = entry->fn->precheck;
1706 if (precheck && !precheck(proc))
return FALSE;
1803 lazy_initialize(
int argc,
VALUE *argv,
VALUE self)
1816 generator = generator_allocate(rb_cGenerator);
1818 enumerator_init(
self,
generator, sym_each, 0, 0, 0, size, 0);
1834 lazy_to_a(
VALUE self)
1858 lazy_set_args(lazy, args);
1859 e->size_fn = size_fn;
1870 VALUE new_generator;
1875 &proc_entry_data_type, entry);
1882 lazy_set_args(entry_obj, memo);
1885 new_generator = lazy_generator_init(obj, new_procs);
1888 new_obj = enumerator_init_copy(enumerator_allocate(rb_cLazy), obj);
1889 new_e = RTYPEDDATA_GET_DATA(new_obj);
1898 new_e->meth = id_each;
1936 enumerable_lazy(
VALUE obj)
1947 return enumerator_init(enumerator_allocate(rb_cLazy),
1948 obj, meth, argc, argv, size_fn,
Qnil, kw_splat);
1975 lazy_to_enum(
int argc,
VALUE *argv,
VALUE self)
1977 VALUE lazy, meth = sym_each, super_meth;
1996 return enum_size(
self);
2007 lazy_eager(
VALUE self)
2010 self, sym_each, 0, 0, lazy_eager_size,
Qnil, 0);
2025 const VALUE *argv = &result->memo_value;
2026 if (LAZY_MEMO_PACKED_P(result)) {
2027 const VALUE args = *argv;
2034 static struct MEMO *
2038 LAZY_MEMO_SET_VALUE(result, value);
2039 LAZY_MEMO_RESET_PACKED(result);
2050 lazy_map_proc, lazy_map_size,
2073 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_map_funcs);
2077 struct MEMO *result;
2086 return lazy_yielder_yield(arg->result, arg->index, argc, argv);
2089 static struct MEMO *
2094 const long proc_index = memo_index + 1;
2095 int break_p = LAZY_MEMO_BREAK_P(result);
2101 struct flat_map_i_arg arg = {.result = result, .index = proc_index};
2102 LAZY_MEMO_RESET_BREAK(result);
2104 if (break_p) LAZY_MEMO_SET_BREAK(result);
2110 LAZY_MEMO_RESET_BREAK(result);
2113 lazy_yielder_yield(result, proc_index, 1, &argv);
2115 if (break_p) LAZY_MEMO_SET_BREAK(result);
2119 LAZY_MEMO_SET_VALUE(result, value);
2120 LAZY_MEMO_RESET_PACKED(result);
2125 lazy_flat_map_proc, 0,
2152 lazy_flat_map(
VALUE obj)
2158 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_flat_map_funcs);
2161 static struct MEMO *
2165 if (!
RTEST(chain))
return 0;
2170 lazy_select_proc, 0,
2182 lazy_select(
VALUE obj)
2188 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_select_funcs);
2191 static struct MEMO *
2195 if (!
RTEST(value))
return 0;
2196 LAZY_MEMO_SET_VALUE(result, value);
2197 LAZY_MEMO_RESET_PACKED(result);
2202 lazy_filter_map_proc, 0,
2216 lazy_filter_map(
VALUE obj)
2222 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_filter_map_funcs);
2225 static struct MEMO *
2229 if (
RTEST(chain))
return 0;
2234 lazy_reject_proc, 0,
2245 lazy_reject(
VALUE obj)
2251 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_reject_funcs);
2254 static struct MEMO *
2259 if (!
RTEST(chain))
return 0;
2263 static struct MEMO *
2267 VALUE value, chain =
rb_funcall(entry->memo, id_eqq, 1, result->memo_value);
2269 if (!
RTEST(chain))
return 0;
2271 LAZY_MEMO_SET_VALUE(result, value);
2272 LAZY_MEMO_RESET_PACKED(result);
2278 lazy_grep_iter_proc, 0,
2297 &lazy_grep_iter_funcs : &lazy_grep_funcs;
2298 return lazy_add_method(obj, 0, 0, pattern,
rb_ary_new3(1, pattern), funcs);
2301 static struct MEMO *
2306 if (
RTEST(chain))
return 0;
2310 static struct MEMO *
2314 VALUE value, chain =
rb_funcall(entry->memo, id_eqq, 1, result->memo_value);
2316 if (
RTEST(chain))
return 0;
2318 LAZY_MEMO_SET_VALUE(result, value);
2319 LAZY_MEMO_RESET_PACKED(result);
2325 lazy_grep_v_iter_proc, 0,
2329 lazy_grep_v_proc, 0,
2344 &lazy_grep_v_iter_funcs : &lazy_grep_v_funcs;
2345 return lazy_add_method(obj, 0, 0, pattern,
rb_ary_new3(1, pattern), funcs);
2349 call_next(
VALUE obj)
2360 static struct MEMO *
2364 VALUE ary, arrays = entry->memo;
2373 LAZY_MEMO_SET_VALUE(result, ary);
2378 static struct MEMO *
2383 VALUE zip_args = entry->memo;
2402 LAZY_MEMO_SET_VALUE(result, ary);
2407 {lazy_zip_func, lazy_receiver_size,},
2408 {lazy_zip_arrays_func, lazy_receiver_size,},
2431 for (i = 0; i < argc; i++) {
2434 for (; i < argc; i++) {
2441 funcs = &lazy_zip_funcs[0];
2447 return lazy_add_method(obj, 0, 0, ary, ary, funcs);
2450 static struct MEMO *
2462 if (--remain == 0) LAZY_MEMO_SET_BREAK(result);
2480 return entry->memo !=
INT2FIX(0);
2484 lazy_take_proc, lazy_take_size, lazy_take_precheck,
2505 return lazy_add_method(obj, 0, 0, n,
rb_ary_new3(1, n), &lazy_take_funcs);
2508 static struct MEMO *
2513 LAZY_MEMO_SET_BREAK(result);
2520 lazy_take_while_proc, 0,
2531 lazy_take_while(
VALUE obj)
2537 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_take_while_funcs);
2544 if (
NIL_P(receiver))
2553 static struct MEMO *
2574 lazy_drop_proc, lazy_drop_size,
2596 return lazy_add_method(obj, 2, argv, n,
rb_ary_new3(1, n), &lazy_drop_funcs);
2599 static struct MEMO *
2611 if (
RTEST(drop))
return 0;
2618 lazy_drop_while_proc, 0,
2629 lazy_drop_while(
VALUE obj)
2635 return lazy_add_method(obj, 0, 0,
Qfalse,
Qnil, &lazy_drop_while_funcs);
2639 lazy_uniq_check(
VALUE chain,
VALUE memos,
long memo_index)
2648 return rb_hash_add_new_element(hash, chain,
Qfalse);
2651 static struct MEMO *
2654 if (lazy_uniq_check(result->memo_value, memos, memo_index))
return 0;
2658 static struct MEMO *
2663 if (lazy_uniq_check(chain, memos, memo_index))
return 0;
2668 lazy_uniq_iter_proc, 0,
2684 lazy_uniq(
VALUE obj)
2688 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, funcs);
2691 static struct MEMO *
2694 if (
NIL_P(result->memo_value))
return 0;
2699 lazy_compact_proc, 0,
2710 lazy_compact(
VALUE obj)
2712 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_compact_funcs);
2715 static struct MEMO *
2726 argv[0] = result->memo_value;
2730 LAZY_MEMO_RESET_PACKED(result);
2734 LAZY_MEMO_SET_PACKED(result);
2741 lazy_with_index_size(
VALUE proc,
VALUE receiver)
2747 lazy_with_index_proc, lazy_with_index_size,
2768 lazy_with_index(
int argc,
VALUE *argv,
VALUE obj)
2788 lazy_chunk(
VALUE self)
2799 lazy_chunk_while(
VALUE self)
2811 lazy_slice_after(
VALUE self)
2823 lazy_slice_before(
VALUE self)
2834 lazy_slice_when(
VALUE self)
2840 lazy_super(
int argc,
VALUE *argv,
VALUE lazy)
2853 lazy_lazy(
VALUE obj)
2906 stop_result(
VALUE self)
2916 producer_mark(
void *p)
2924 producer_compact(
void *p)
2931 #define producer_free RUBY_TYPED_DEFAULT_FREE
2934 producer_memsize(
const void *p)
2947 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
2951 producer_ptr(
VALUE obj)
2956 if (!
ptr || UNDEF_P(
ptr->proc)) {
2964 producer_allocate(
VALUE klass)
2999 NORETURN(
static VALUE producer_each_i(
VALUE obj));
3002 producer_each_i(
VALUE obj)
3005 VALUE init, proc, curr;
3007 ptr = producer_ptr(obj);
3011 if (UNDEF_P(init)) {
3029 producer_each(
VALUE obj)
3078 enumerator_s_produce(
int argc,
VALUE *argv,
VALUE klass)
3104 enum_chain_mark(
void *p)
3111 enum_chain_compact(
void *p)
3117 #define enum_chain_free RUBY_TYPED_DEFAULT_FREE
3120 enum_chain_memsize(
const void *p)
3133 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3137 enum_chain_ptr(
VALUE obj)
3142 if (!
ptr || UNDEF_P(
ptr->enums)) {
3150 enum_chain_allocate(
VALUE klass)
3174 enum_chain_initialize(
VALUE obj,
VALUE enums)
3178 rb_check_frozen(obj);
3190 new_enum_chain(
VALUE enums)
3193 VALUE obj = enum_chain_initialize(enum_chain_allocate(rb_cEnumChain), enums);
3197 return enumerable_lazy(obj);
3211 ptr0 = enum_chain_ptr(orig);
3217 ptr1->enums = ptr0->enums;
3218 ptr1->pos = ptr0->pos;
3224 enum_chain_total_size(
VALUE enums)
3255 enum_chain_size(
VALUE obj)
3257 return enum_chain_total_size(enum_chain_ptr(obj)->enums);
3263 return enum_chain_size(obj);
3285 enum_chain_each(
int argc,
VALUE *argv,
VALUE obj)
3293 objptr = enum_chain_ptr(obj);
3294 enums = objptr->enums;
3314 enum_chain_rewind(
VALUE obj)
3316 struct enum_chain *objptr = enum_chain_ptr(obj);
3317 VALUE enums = objptr->enums;
3320 for (i = objptr->pos; 0 <= i && i <
RARRAY_LEN(enums); objptr->pos = --i) {
3328 inspect_enum_chain(
VALUE obj,
VALUE dummy,
int recur)
3335 if (!
ptr || UNDEF_P(
ptr->enums)) {
3353 enum_chain_inspect(
VALUE obj)
3373 return new_enum_chain(enums);
3426 enum_product_mark(
void *p)
3433 enum_product_compact(
void *p)
3439 #define enum_product_free RUBY_TYPED_DEFAULT_FREE
3442 enum_product_memsize(
const void *p)
3452 enum_product_memsize,
3453 enum_product_compact,
3455 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3459 enum_product_ptr(
VALUE obj)
3464 if (!
ptr || UNDEF_P(
ptr->enums)) {
3472 enum_product_allocate(
VALUE klass)
3495 enum_product_initialize(
int argc,
VALUE *argv,
VALUE obj)
3503 rb_exc_raise(rb_keyword_error_new(
"unknown", rb_hash_keys(options)));
3506 rb_check_frozen(obj);
3518 enum_product_init_copy(
VALUE obj,
VALUE orig)
3523 ptr0 = enum_product_ptr(orig);
3529 ptr1->enums = ptr0->enums;
3535 enum_product_total_size(
VALUE enums)
3575 enum_product_size(
VALUE obj)
3577 return enum_product_total_size(enum_product_ptr(obj)->enums);
3583 return enum_product_size(obj);
3600 pstate->argv[pstate->index++] = value;
3602 VALUE val = product_each(pstate->obj, pstate);
3613 if (pstate->index < pstate->argc) {
3638 return product_each(obj, &state);
3654 enum_product_each(
VALUE obj)
3670 enum_product_rewind(
VALUE obj)
3684 inspect_enum_product(
VALUE obj,
VALUE dummy,
int recur)
3691 if (!
ptr || UNDEF_P(
ptr->enums)) {
3709 enum_product_inspect(
VALUE obj)
3731 enumerator_s_product(
int argc,
VALUE *argv,
VALUE klass)
3735 rb_scan_args(argc, argv,
"*:&", &enums, &options, &block);
3738 rb_exc_raise(rb_keyword_error_new(
"unknown", rb_hash_keys(options)));
3741 VALUE obj = enum_product_initialize(argc, argv, enum_product_allocate(rb_cEnumProduct));
3743 if (!
NIL_P(block)) {
3744 enum_product_run(obj, block);
3768 VALUE aseq = enumerator_init(enumerator_allocate(rb_cArithSeq),
3784 arith_seq_begin(
VALUE self)
3795 arith_seq_end(
VALUE self)
3807 arith_seq_step(
VALUE self)
3818 arith_seq_exclude_end(
VALUE self)
3824 arith_seq_exclude_end_p(
VALUE self)
3826 return RTEST(arith_seq_exclude_end(
self));
3833 component->
begin = arith_seq_begin(obj);
3834 component->
end = arith_seq_end(obj);
3835 component->
step = arith_seq_step(obj);
3836 component->
exclude_end = arith_seq_exclude_end_p(obj);
3850 RBIMPL_NONNULL_ARG(begp);
3851 RBIMPL_NONNULL_ARG(lenp);
3852 RBIMPL_NONNULL_ARG(stepp);
3875 if (err == 0 && (step < -1 || step > 1)) {
3902 arith_seq_first(
int argc,
VALUE *argv,
VALUE self)
3910 b = arith_seq_begin(
self);
3911 e = arith_seq_end(
self);
3912 s = arith_seq_step(
self);
3940 x = arith_seq_exclude_end_p(
self);
3972 while (n > 0 && i < end) {
3974 if (i + unit < i)
break;
3985 while (n > 0 && i > end) {
3987 if (i + unit > i)
break;
3999 double end =
NIL_P(e) ? (unit < 0 ? -1 : 1)*HUGE_VAL :
NUM2DBL(e);
4000 double len = ruby_float_step_size(beg, end, unit, x);
4015 else if (unit == 0) {
4018 for (i = 0; i <
len; ++i) {
4024 for (i = 0; i < n; ++i) {
4025 double d = i*unit+beg;
4026 if (unit >= 0 ? end < d : d < end) d = end;
4041 return rb_int_plus(a, b);
4044 return rb_float_plus(a, b);
4047 return rb_rational_plus(a, b);
4058 return rb_int_minus(a, b);
4061 return rb_float_minus(a, b);
4064 return rb_rational_minus(a, b);
4075 return rb_int_mul(a, b);
4078 return rb_float_mul(a, b);
4081 return rb_rational_mul(a, b);
4093 q = rb_int_idiv(a, b);
4096 q = rb_float_div(a, b);
4099 q = rb_rational_div(a, b);
4109 return rb_float_floor(q, 0);
4112 return rb_rational_floor(q, 0);
4128 arith_seq_last(
int argc,
VALUE *argv,
VALUE self)
4130 VALUE b, e, s, len_1,
len, last, nv, ary;
4131 int last_is_adjusted;
4134 e = arith_seq_end(
self);
4137 "cannot get the last element of endless arithmetic sequence");
4140 b = arith_seq_begin(
self);
4141 s = arith_seq_step(
self);
4143 len_1 = num_idiv(num_minus(e, b), s);
4144 if (rb_num_negative_int_p(len_1)) {
4151 last = num_plus(b, num_mul(s, len_1));
4152 if ((last_is_adjusted = arith_seq_exclude_end_p(
self) &&
rb_equal(last, e))) {
4153 last = num_minus(last, s);
4160 if (last_is_adjusted) {
4180 b = rb_int_minus(last, rb_int_mul(s, nv));
4182 b = rb_int_plus(b, s);
4197 arith_seq_inspect(
VALUE self)
4200 VALUE eobj, str, eargs;
4211 str =
rb_sprintf(
"(%s%"PRIsVALUE
"%s.", range_p ?
"(" :
"", eobj, range_p ?
")" :
"");
4231 if (all_key) kwds = argv[--argc];
4235 VALUE arg = *argv++;
4267 if (!
rb_equal(arith_seq_begin(
self), arith_seq_begin(other))) {
4271 if (!
rb_equal(arith_seq_end(
self), arith_seq_end(other))) {
4275 if (!
rb_equal(arith_seq_step(
self), arith_seq_step(other))) {
4279 if (arith_seq_exclude_end_p(
self) != arith_seq_exclude_end_p(other)) {
4297 arith_seq_hash(
VALUE self)
4303 v =
rb_hash(arith_seq_begin(
self));
4305 v =
rb_hash(arith_seq_end(
self));
4307 v =
rb_hash(arith_seq_step(
self));
4314 #define NUM_GE(x, y) RTEST(rb_num_coerce_relop((x), (y), idGE))
4329 arith_seq_each(
VALUE self)
4331 VALUE c, e, s, len_1, last;
4336 c = arith_seq_begin(
self);
4337 e = arith_seq_end(
self);
4338 s = arith_seq_step(
self);
4339 x = arith_seq_exclude_end_p(
self);
4348 c = rb_int_plus(c, s);
4362 len_1 = num_idiv(num_minus(e, c), s);
4363 last = num_plus(c, num_mul(s, len_1));
4365 last = num_minus(last, s);
4368 if (rb_num_negative_int_p(s)) {
4369 while (NUM_GE(c, last)) {
4375 while (NUM_GE(last, c)) {
4392 arith_seq_size(
VALUE self)
4397 b = arith_seq_begin(
self);
4398 e = arith_seq_end(
self);
4399 s = arith_seq_step(
self);
4400 x = arith_seq_exclude_end_p(
self);
4406 if (rb_num_negative_int_p(s)) {
4418 if (isinf(n))
return DBL2NUM(n);
4435 len_1 = rb_int_idiv(rb_int_minus(e, b), s);
4436 if (rb_num_negative_int_p(len_1)) {
4440 last = rb_int_plus(b, rb_int_mul(s, len_1));
4451 #define sym(name) ID2SYM(rb_intern_const(name))
4453 InitVM_Enumerator(
void)
4489 rb_define_alias(rb_cLazy,
"_enumerable_collect_concat",
"collect_concat");
4505 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_map"));
4506 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_collect"));
4507 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_flat_map"));
4508 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_collect_concat"));
4509 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_select"));
4510 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_find_all"));
4511 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_filter"));
4512 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_filter_map"));
4513 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_reject"));
4514 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_grep"));
4515 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_grep_v"));
4516 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_zip"));
4517 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_take"));
4518 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_take_while"));
4519 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_drop"));
4520 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_drop_while"));
4521 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_uniq"));
4553 lazy_use_super_method = rb_hash_new_with_size(18);
4554 rb_hash_aset(lazy_use_super_method, sym(
"map"), sym(
"_enumerable_map"));
4555 rb_hash_aset(lazy_use_super_method, sym(
"collect"), sym(
"_enumerable_collect"));
4556 rb_hash_aset(lazy_use_super_method, sym(
"flat_map"), sym(
"_enumerable_flat_map"));
4557 rb_hash_aset(lazy_use_super_method, sym(
"collect_concat"), sym(
"_enumerable_collect_concat"));
4558 rb_hash_aset(lazy_use_super_method, sym(
"select"), sym(
"_enumerable_select"));
4559 rb_hash_aset(lazy_use_super_method, sym(
"find_all"), sym(
"_enumerable_find_all"));
4560 rb_hash_aset(lazy_use_super_method, sym(
"filter"), sym(
"_enumerable_filter"));
4561 rb_hash_aset(lazy_use_super_method, sym(
"filter_map"), sym(
"_enumerable_filter_map"));
4562 rb_hash_aset(lazy_use_super_method, sym(
"reject"), sym(
"_enumerable_reject"));
4563 rb_hash_aset(lazy_use_super_method, sym(
"grep"), sym(
"_enumerable_grep"));
4564 rb_hash_aset(lazy_use_super_method, sym(
"grep_v"), sym(
"_enumerable_grep_v"));
4565 rb_hash_aset(lazy_use_super_method, sym(
"zip"), sym(
"_enumerable_zip"));
4566 rb_hash_aset(lazy_use_super_method, sym(
"take"), sym(
"_enumerable_take"));
4567 rb_hash_aset(lazy_use_super_method, sym(
"take_while"), sym(
"_enumerable_take_while"));
4568 rb_hash_aset(lazy_use_super_method, sym(
"drop"), sym(
"_enumerable_drop"));
4569 rb_hash_aset(lazy_use_super_method, sym(
"drop_while"), sym(
"_enumerable_drop_while"));
4570 rb_hash_aset(lazy_use_super_method, sym(
"uniq"), sym(
"_enumerable_uniq"));
4571 rb_hash_aset(lazy_use_super_method, sym(
"with_index"), sym(
"_enumerable_with_index"));
4573 rb_vm_register_global_object(lazy_use_super_method);
4593 rb_define_method(rb_cGenerator,
"initialize_copy", generator_init_copy, 1);
4614 rb_define_method(rb_cEnumChain,
"initialize_copy", enum_chain_init_copy, 1);
4628 rb_define_method(rb_cEnumProduct,
"initialize", enum_product_initialize, -1);
4629 rb_define_method(rb_cEnumProduct,
"initialize_copy", enum_product_init_copy, 1);
4664 Init_Enumerator(
void)
4681 sym_each =
ID2SYM(id_each);
#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.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
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 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_class, const char *fmt,...)
Exception entry point.
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
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 unless $VERBOSE is nil.
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.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
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.
void rb_gc_mark_movable(VALUE obj)
Maybe this is the only function provided for C extensions to control the pinning of objects,...
VALUE rb_gc_location(VALUE obj)
Finds a new "location" of an object.
VALUE rb_ary_new_from_values(long n, const VALUE *elts)
Identical to rb_ary_new_from_args(), except how objects are passed.
VALUE rb_ary_dup(VALUE ary)
Duplicates an array.
VALUE rb_ary_cat(VALUE ary, const VALUE *train, long len)
Destructively appends multiple elements at the end of the array.
VALUE rb_check_array_type(VALUE obj)
Try converting an object to its array representation using its to_ary method, if any.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_resize(VALUE ary, long len)
Expands or shrinks the passed array to the passed length.
VALUE rb_ary_hidden_new(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_freeze(VALUE obj)
Freeze an array, preventing further modifications.
VALUE rb_ary_new_from_args(long n,...)
Constructs an array from the passed objects.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
void rb_ary_store(VALUE ary, long key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
VALUE rb_big_plus(VALUE x, VALUE y)
Performs addition of the passed two objects.
VALUE rb_dbl2big(double d)
Converts a C's double into a bignum.
int rb_cmpint(VALUE val, VALUE a, VALUE b)
Canonicalises the passed val, which is the return value of a <=> b, into C's {-1, 0,...
VALUE rb_fiber_current(void)
Queries the fiber which is calling this function.
VALUE rb_fiber_alive_p(VALUE fiber)
Queries the liveness of the passed fiber.
VALUE rb_fiber_new(rb_block_call_func_t func, VALUE callback_obj)
Creates a Fiber instance from a C-backended block.
VALUE rb_fiber_yield(int argc, const VALUE *argv)
Yields the control back to the point where the current fiber was resumed.
VALUE rb_fiber_resume(VALUE fiber, int argc, const VALUE *argv)
Resumes the execution of the passed fiber, either from the point at which the last rb_fiber_yield() w...
VALUE rb_enum_values_pack(int argc, const VALUE *argv)
Basically identical to rb_ary_new_form_values(), except it returns something different when argc < 2.
VALUE rb_arithmetic_sequence_beg_len_step(VALUE as, long *begp, long *lenp, long *stepp, long len, int err)
Identical to rb_range_beg_len(), except it takes an instance of Enumerator::ArithmericSequence.
VALUE rb_enumeratorize_with_size(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func)
Identical to rb_enumeratorize(), except you can additionally specify the size function of return valu...
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
This roughly resembles return enum_for(__callee__) unless block_given?.
VALUE rb_enumeratorize(VALUE recv, VALUE meth, int argc, const VALUE *argv)
Constructs an enumerator.
VALUE rb_enumeratorize_with_size_kw(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func, int kw_splat)
Identical to rb_enumeratorize_with_func(), except you can specify how to handle the last element of t...
int rb_arithmetic_sequence_extract(VALUE as, rb_arithmetic_sequence_components_t *buf)
Extracts components of the passed arithmetic sequence.
VALUE rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj)
This is the type of functions that rb_enumeratorize_with_size() expects.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
ID rb_frame_this_func(void)
Queries the name of the Ruby level method that is calling this function.
void rb_hash_foreach(VALUE hash, int(*func)(VALUE key, VALUE val, VALUE arg), VALUE arg)
Iterates over a hash.
VALUE rb_hash_aref(VALUE hash, VALUE key)
Queries the given key in the given hash table.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash(VALUE obj)
Calculates a message authentication code of the passed object.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
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_new(rb_block_call_func_t func, VALUE callback_arg)
This is an rb_iterate() + rb_block_proc() combo.
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_cat2(VALUE, const char *)
Just another name of rb_str_cat_cstr.
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 symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
ID rb_to_id(VALUE str)
Identical to rb_intern(), except it takes an instance of rb_cString.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a frozen Ruby String instead of a C String.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
int len
Length of the buffer.
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_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t proc, VALUE data2)
Identical to rb_funcallv(), except it additionally passes a function as a block.
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)
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
#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 RHASH_EMPTY_P(h)
Checks if the hash is empty.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
#define RUBY_TYPED_DEFAULT_FREE
This is a value you can set to rb_data_type_struct::dfree.
#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.