15#include "ruby/internal/config.h"
24#include "internal/class.h"
25#include "internal/enumerator.h"
26#include "internal/error.h"
27#include "internal/hash.h"
28#include "internal/imemo.h"
29#include "internal/numeric.h"
30#include "internal/range.h"
31#include "internal/rational.h"
165static VALUE rb_cLazy;
166static ID id_rewind, id_new, id_to_enum, id_each_entry;
167static ID id_next, id_result, id_receiver, id_arguments, id_memo, id_method, id_force;
168static ID id_begin, id_end, id_step, id_exclude_end;
169static VALUE sym_each, sym_cycle, sym_yield;
171static VALUE lazy_use_super_method;
173extern ID ruby_static_id_cause;
175#define id_call idCall
176#define id_cause ruby_static_id_cause
177#define id_each idEach
179#define id_initialize idInitialize
180#define id_size idSize
199RUBY_REFERENCES(enumerator_refs) = {
212static VALUE rb_cGenerator, rb_cYielder, rb_cEnumProducer;
232 lazyenum_proc_func *proc;
233 lazyenum_size_func *size;
234 lazyenum_precheck_func *precheck;
246static VALUE rb_cEnumChain;
253static VALUE rb_cEnumProduct;
264 RUBY_REFS_LIST_PTR(enumerator_refs),
269 0, NULL, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_DECL_MARKING | RUBY_TYPED_EMBEDDABLE
273enumerator_ptr(
VALUE obj)
278 if (!ptr || UNDEF_P(ptr->obj)) {
279 rb_raise(rb_eArgError,
"uninitialized enumerator");
285proc_entry_mark(
void *p)
288 rb_gc_mark_movable(ptr->proc);
289 rb_gc_mark_movable(ptr->memo);
293proc_entry_compact(
void *p)
296 ptr->proc = rb_gc_location(ptr->proc);
297 ptr->memo = rb_gc_location(ptr->memo);
308 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
391 enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
399enumerator_allocate(
VALUE klass)
415 rb_check_frozen(enum_obj);
419 rb_raise(rb_eArgError,
"unallocated enumerator");
431 ptr->size_fn = size_fn;
432 ptr->kw_splat = kw_splat;
438convert_to_feasible_size_value(
VALUE obj)
480enumerator_initialize(
int argc,
VALUE *argv,
VALUE obj)
483 VALUE recv = generator_init(generator_allocate(rb_cGenerator), iter);
485 VALUE size = convert_to_feasible_size_value(arg0);
487 return enumerator_init(obj, recv, sym_each, 0, 0, 0, size,
false);
497 ptr0 = enumerator_ptr(orig);
506 rb_raise(rb_eArgError,
"unallocated enumerator");
510 ptr1->meth = ptr0->meth;
516 ptr1->size_fn = ptr0->size_fn;
527 return rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
531static int lazy_precheck(
VALUE procs);
539 base_class = rb_cLazy;
542 obj = enumerator_init(enumerator_allocate(
rb_cEnumerator), obj, sym_each, 0, 0, 0,
Qnil,
false);
545 return enumerator_init(enumerator_allocate(base_class),
546 obj, meth, argc, argv, size_fn,
Qnil, kw_splat);
552 return rb_enumeratorize_with_size_kw(obj, meth, argc, argv, size_fn,
rb_keyword_given_p());
559 const VALUE *argv = 0;
560 const struct enumerator *e = enumerator_ptr(obj);
563 VALUE args = e->args;
613enumerator_each(
int argc,
VALUE *argv,
VALUE obj)
620#if SIZEOF_INT < SIZEOF_LONG
624 args = rb_ary_dup(args);
625 rb_ary_cat(args, argv, argc);
636 if (!lazy_precheck(e->procs))
return Qnil;
638 return enumerator_block_call(obj, 0, obj);
644 struct MEMO *memo = (
struct MEMO *)m;
645 VALUE idx = memo->v1;
646 MEMO_V1_SET(memo, rb_int_succ(idx));
655enumerator_size(
VALUE obj);
660 return enumerator_size(obj);
676enumerator_with_index(
int argc,
VALUE *argv,
VALUE obj)
683 return enumerator_block_call(obj, enumerator_with_index_i, (
VALUE)MEMO_NEW(memo, 0, 0));
697enumerator_each_with_index(
VALUE obj)
699 return enumerator_with_index(0, NULL, obj);
744 enumerator_block_call(obj, enumerator_with_object_i, memo);
755 rb_fiber_yield(1, &args);
756 if (!UNDEF_P(e->feedvalue)) {
757 feedvalue = e->feedvalue;
773 return rb_fiber_yield(1, &nil);
791 VALUE exc = e->stop_exc;
792 VALUE result = rb_attr_get(exc, id_result);
793 VALUE mesg = rb_attr_get(exc, idMesg);
798 rb_exc_raise(stop_exc);
803 if (!e->fib || !rb_fiber_alive_p(e->fib)) {
807 vs = rb_fiber_resume(e->fib, 1, &curr);
813 rb_exc_raise(e->stop_exc);
864enumerator_next_values(
VALUE obj)
869 rb_check_frozen(obj);
871 if (!UNDEF_P(e->lookahead)) {
877 return get_next_values(obj, e);
881ary2sv(
VALUE args,
int dup)
895 return rb_ary_dup(args);
921enumerator_next(
VALUE obj)
923 VALUE vs = enumerator_next_values(obj);
924 return ary2sv(vs, 0);
928enumerator_peek_values(
VALUE obj)
932 rb_check_frozen(obj);
934 if (UNDEF_P(e->lookahead)) {
935 RB_OBJ_WRITE(obj, &e->lookahead, get_next_values(obj, e));
972enumerator_peek_values_m(
VALUE obj)
974 return rb_ary_dup(enumerator_peek_values(obj));
1002enumerator_peek(
VALUE obj)
1004 VALUE vs = enumerator_peek_values(obj);
1005 return ary2sv(vs, 1);
1059 rb_check_frozen(obj);
1061 if (!UNDEF_P(e->feedvalue)) {
1079enumerator_rewind(
VALUE obj)
1083 rb_check_frozen(obj);
1099inspect_enumerator(
VALUE obj,
VALUE dummy,
int recur)
1102 VALUE eobj, str, cname;
1108 if (!e || UNDEF_P(e->obj)) {
1109 return rb_sprintf(
"#<%"PRIsVALUE
": uninitialized>",
rb_class_path(cname));
1113 str = rb_sprintf(
"#<%"PRIsVALUE
": ...>",
rb_class_path(cname));
1120 eobj = generator_ptr(e->obj)->obj;
1126 str = rb_sprintf(
"#<%"PRIsVALUE
": %+"PRIsVALUE
">",
rb_class_path(cname), eobj);
1129 str = rb_sprintf(
"#<%"PRIsVALUE
": %"PRIsVALUE, cname, str);
1130 append_method(
RARRAY_AREF(e->procs, i), str, e->meth, e->args);
1136 eobj = rb_attr_get(obj, id_receiver);
1142 str = rb_sprintf(
"#<%"PRIsVALUE
": %+"PRIsVALUE,
rb_class_path(cname), eobj);
1143 append_method(obj, str, e->meth, e->args);
1153 if (
SYMBOL_P(key))
return ST_CONTINUE;
1154 *(
int *)arg = FALSE;
1162 rb_str_catf(str,
"% "PRIsVALUE
": %"PRIsVALUE
", ", key, val);
1169 VALUE method, eargs;
1171 method = rb_attr_get(obj, id_method);
1173 if (!
NIL_P(method)) {
1178 method = rb_id2str(default_method);
1184 eargs = rb_attr_get(obj, id_arguments);
1186 eargs = default_args;
1200 if (all_key) kwds = argv[--argc];
1204 VALUE arg = *argv++;
1228enumerator_inspect(
VALUE obj)
1245enumerator_size(
VALUE obj)
1249 const VALUE *argv = NULL;
1253 struct generator *g = generator_ptr(e->obj);
1259 struct proc_entry *entry = proc_entry_ptr(proc);
1260 lazyenum_size_func *size_fn = entry->fn->size;
1264 receiver = (*size_fn)(proc, receiver);
1270 return (*e->size_fn)(e->obj, e->args, obj);
1277 if (!UNDEF_P(size))
return size;
1285yielder_mark(
void *p)
1288 rb_gc_mark_movable(ptr->proc);
1292yielder_compact(
void *p)
1295 ptr->proc = rb_gc_location(ptr->proc);
1306 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
1310yielder_ptr(
VALUE obj)
1315 if (!ptr || UNDEF_P(ptr->proc)) {
1316 rb_raise(rb_eArgError,
"uninitialized yielder");
1323yielder_allocate(
VALUE klass)
1342 rb_raise(rb_eArgError,
"unallocated yielder");
1352yielder_initialize(
VALUE obj)
1363 struct yielder *ptr = yielder_ptr(obj);
1372 struct yielder *ptr = yielder_ptr(obj);
1392yielder_to_proc(
VALUE obj)
1408 return yielder_init(yielder_allocate(rb_cYielder),
rb_proc_new(yielder_yield_i, 0));
1415generator_mark(
void *p)
1418 rb_gc_mark_movable(ptr->proc);
1419 rb_gc_mark_movable(ptr->obj);
1423generator_compact(
void *p)
1426 ptr->proc = rb_gc_location(ptr->proc);
1427 ptr->obj = rb_gc_location(ptr->obj);
1438 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
1442generator_ptr(
VALUE obj)
1447 if (!ptr || UNDEF_P(ptr->proc)) {
1448 rb_raise(rb_eArgError,
"uninitialized generator");
1455generator_allocate(
VALUE klass)
1471 rb_check_frozen(obj);
1475 rb_raise(rb_eArgError,
"unallocated generator");
1485generator_initialize(
int argc,
VALUE *argv,
VALUE obj)
1499 "wrong argument type %"PRIsVALUE
" (expected Proc)",
1503 rb_warn(
"given block not used");
1507 return generator_init(obj, proc);
1518 ptr0 = generator_ptr(orig);
1523 rb_raise(rb_eArgError,
"unallocated generator");
1533generator_each(
int argc,
VALUE *argv,
VALUE obj)
1535 struct generator *ptr = generator_ptr(obj);
1538 rb_ary_push(args, yielder_new());
1540 rb_ary_cat(args, argv, argc);
1548enum_size(
VALUE self)
1551 return UNDEF_P(r) ?
Qnil : r;
1557 return enum_size(self);
1560#define lazy_receiver_size lazy_map_size
1591 rb_block_call(m, id_each, argc-1, argv+1, lazy_init_iterator, val);
1595#define memo_value v2
1596#define memo_flags u3.state
1597#define LAZY_MEMO_BREAK 1
1598#define LAZY_MEMO_PACKED 2
1599#define LAZY_MEMO_BREAK_P(memo) ((memo)->memo_flags & LAZY_MEMO_BREAK)
1600#define LAZY_MEMO_PACKED_P(memo) ((memo)->memo_flags & LAZY_MEMO_PACKED)
1601#define LAZY_MEMO_SET_BREAK(memo) ((memo)->memo_flags |= LAZY_MEMO_BREAK)
1602#define LAZY_MEMO_RESET_BREAK(memo) ((memo)->memo_flags &= ~LAZY_MEMO_BREAK)
1603#define LAZY_MEMO_SET_VALUE(memo, value) MEMO_V2_SET(memo, value)
1604#define LAZY_MEMO_SET_PACKED(memo) ((memo)->memo_flags |= LAZY_MEMO_PACKED)
1605#define LAZY_MEMO_RESET_PACKED(memo) ((memo)->memo_flags &= ~LAZY_MEMO_PACKED)
1615 struct MEMO *result;
1617 result = MEMO_NEW(m, rb_enum_values_pack(argc, argv),
1618 argc > 1 ? LAZY_MEMO_PACKED : 0);
1619 return lazy_yielder_result(result,
yielder, procs_array, memos, 0);
1623lazy_yielder_yield(
struct MEMO *result,
long memo_index,
int argc,
const VALUE *argv)
1625 VALUE m = result->v1;
1629 LAZY_MEMO_SET_VALUE(result, rb_enum_values_pack(argc, argv));
1631 LAZY_MEMO_SET_PACKED(result);
1633 LAZY_MEMO_RESET_PACKED(result);
1634 return lazy_yielder_result(result,
yielder, procs_array, memos, memo_index);
1644 struct proc_entry *entry = proc_entry_ptr(proc);
1645 if (!(*entry->fn->proc)(proc, result, memos, i)) {
1654 if (LAZY_MEMO_BREAK_P(result)) {
1657 return result->memo_value;
1680 struct generator *old_gen_ptr = generator_ptr(e->obj);
1681 obj = old_gen_ptr->obj;
1687 generator = generator_allocate(rb_cGenerator);
1699lazy_precheck(
VALUE procs)
1702 long num_procs =
RARRAY_LEN(procs), i = num_procs;
1705 struct proc_entry *entry = proc_entry_ptr(proc);
1706 lazyenum_precheck_func *precheck = entry->fn->precheck;
1707 if (precheck && !precheck(proc))
return FALSE;
1804lazy_initialize(
int argc,
VALUE *argv,
VALUE self)
1811 rb_raise(rb_eArgError,
"tried to call lazy new without a block");
1817 generator = generator_allocate(rb_cGenerator);
1819 enumerator_init(self,
generator, sym_each, 0, 0, 0, size, 0);
1835lazy_to_a(
VALUE self)
1859 lazy_set_args(lazy, args);
1860 e->size_fn = size_fn;
1871 VALUE new_generator;
1876 &proc_entry_data_type, entry);
1883 lazy_set_args(entry_obj, memo);
1885 new_procs =
RTEST(e->procs) ? rb_ary_dup(e->procs) : rb_ary_new();
1886 new_generator = lazy_generator_init(obj, new_procs);
1887 rb_ary_push(new_procs, entry_obj);
1889 new_obj = enumerator_init_copy(enumerator_allocate(rb_cLazy), obj);
1890 new_e = RTYPEDDATA_GET_DATA(new_obj);
1899 new_e->meth = id_each;
1937enumerable_lazy(
VALUE obj)
1948 return enumerator_init(enumerator_allocate(rb_cLazy),
1949 obj, meth, argc, argv, size_fn,
Qnil, kw_splat);
1976lazy_to_enum(
int argc,
VALUE *argv,
VALUE self)
1978 VALUE lazy, meth = sym_each, super_meth;
1984 if (
RTEST((super_meth = rb_hash_aref(lazy_use_super_method, meth)))) {
1997 return enum_size(self);
2008lazy_eager(
VALUE self)
2011 self, sym_each, 0, 0, lazy_eager_size,
Qnil, 0);
2026 const VALUE *argv = &result->memo_value;
2027 if (LAZY_MEMO_PACKED_P(result)) {
2028 const VALUE args = *argv;
2039 LAZY_MEMO_SET_VALUE(result, value);
2040 LAZY_MEMO_RESET_PACKED(result);
2051 lazy_map_proc, lazy_map_size,
2071 rb_raise(rb_eArgError,
"tried to call lazy map without a block");
2074 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_map_funcs);
2078 struct MEMO *result;
2087 return lazy_yielder_yield(arg->result, arg->index, argc, argv);
2095 const long proc_index = memo_index + 1;
2096 int break_p = LAZY_MEMO_BREAK_P(result);
2102 struct flat_map_i_arg arg = {.result = result, .index = proc_index};
2103 LAZY_MEMO_RESET_BREAK(result);
2105 if (break_p) LAZY_MEMO_SET_BREAK(result);
2109 if (ary || !
NIL_P(ary = rb_check_array_type(value))) {
2111 LAZY_MEMO_RESET_BREAK(result);
2114 lazy_yielder_yield(result, proc_index, 1, &argv);
2116 if (break_p) LAZY_MEMO_SET_BREAK(result);
2120 LAZY_MEMO_SET_VALUE(result, value);
2121 LAZY_MEMO_RESET_PACKED(result);
2126 lazy_flat_map_proc, 0,
2153lazy_flat_map(
VALUE obj)
2156 rb_raise(rb_eArgError,
"tried to call lazy flat_map without a block");
2159 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_flat_map_funcs);
2166 if (!
RTEST(chain))
return 0;
2171 lazy_select_proc, 0,
2183lazy_select(
VALUE obj)
2186 rb_raise(rb_eArgError,
"tried to call lazy select without a block");
2189 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_select_funcs);
2196 if (!
RTEST(value))
return 0;
2197 LAZY_MEMO_SET_VALUE(result, value);
2198 LAZY_MEMO_RESET_PACKED(result);
2203 lazy_filter_map_proc, 0,
2217lazy_filter_map(
VALUE obj)
2220 rb_raise(rb_eArgError,
"tried to call lazy filter_map without a block");
2223 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_filter_map_funcs);
2230 if (
RTEST(chain))
return 0;
2235 lazy_reject_proc, 0,
2246lazy_reject(
VALUE obj)
2249 rb_raise(rb_eArgError,
"tried to call lazy reject without a block");
2252 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_reject_funcs);
2260 if (!
RTEST(chain))
return 0;
2268 VALUE value, chain =
rb_funcall(entry->memo, id_eqq, 1, result->memo_value);
2270 if (!
RTEST(chain))
return 0;
2272 LAZY_MEMO_SET_VALUE(result, value);
2273 LAZY_MEMO_RESET_PACKED(result);
2279 lazy_grep_iter_proc, 0,
2298 &lazy_grep_iter_funcs : &lazy_grep_funcs;
2299 return lazy_add_method(obj, 0, 0, pattern,
rb_ary_new3(1, pattern), funcs);
2307 if (
RTEST(chain))
return 0;
2315 VALUE value, chain =
rb_funcall(entry->memo, id_eqq, 1, result->memo_value);
2317 if (
RTEST(chain))
return 0;
2319 LAZY_MEMO_SET_VALUE(result, value);
2320 LAZY_MEMO_RESET_PACKED(result);
2326 lazy_grep_v_iter_proc, 0,
2330 lazy_grep_v_proc, 0,
2345 &lazy_grep_v_iter_funcs : &lazy_grep_v_funcs;
2346 return lazy_add_method(obj, 0, 0, pattern,
rb_ary_new3(1, pattern), funcs);
2365 VALUE ary, arrays = entry->memo;
2366 VALUE memo = rb_ary_entry(memos, memo_index);
2370 rb_ary_push(ary, result->memo_value);
2372 rb_ary_push(ary, rb_ary_entry(
RARRAY_AREF(arrays, i), count));
2374 LAZY_MEMO_SET_VALUE(result, ary);
2375 rb_ary_store(memos, memo_index,
LONG2NUM(++count));
2383 VALUE arg = rb_ary_entry(memos, memo_index);
2384 VALUE zip_args = entry->memo;
2393 rb_ary_store(memos, memo_index, arg);
2397 rb_ary_push(ary, result->memo_value);
2401 rb_ary_push(ary, v);
2403 LAZY_MEMO_SET_VALUE(result, ary);
2408 {lazy_zip_func, lazy_receiver_size,},
2409 {lazy_zip_arrays_func, lazy_receiver_size,},
2432 for (i = 0; i < argc; i++) {
2433 v = rb_check_array_type(argv[i]);
2435 for (; i < argc; i++) {
2437 rb_raise(
rb_eTypeError,
"wrong argument type %"PRIsVALUE
" (must respond to :each)",
2442 funcs = &lazy_zip_funcs[0];
2445 rb_ary_push(ary, v);
2448 return lazy_add_method(obj, 0, 0, ary, ary, funcs);
2456 VALUE memo = rb_ary_entry(memos, memo_index);
2463 if (--remain == 0) LAZY_MEMO_SET_BREAK(result);
2464 rb_ary_store(memos, memo_index,
LONG2NUM(remain));
2481 return entry->memo !=
INT2FIX(0);
2485 lazy_take_proc, lazy_take_size, lazy_take_precheck,
2501 rb_raise(rb_eArgError,
"attempt to take negative size");
2506 return lazy_add_method(obj, 0, 0, n,
rb_ary_new3(1, n), &lazy_take_funcs);
2514 LAZY_MEMO_SET_BREAK(result);
2521 lazy_take_while_proc, 0,
2532lazy_take_while(
VALUE obj)
2535 rb_raise(rb_eArgError,
"tried to call lazy take_while without a block");
2538 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_take_while_funcs);
2545 if (
NIL_P(receiver))
2559 VALUE memo = rb_ary_entry(memos, memo_index);
2567 rb_ary_store(memos, memo_index,
LONG2NUM(remain));
2575 lazy_drop_proc, lazy_drop_size,
2594 rb_raise(rb_eArgError,
"attempt to drop negative size");
2597 return lazy_add_method(obj, 2, argv, n,
rb_ary_new3(1, n), &lazy_drop_funcs);
2604 VALUE memo = rb_ary_entry(memos, memo_index);
2612 if (
RTEST(drop))
return 0;
2613 rb_ary_store(memos, memo_index,
Qtrue);
2619 lazy_drop_while_proc, 0,
2630lazy_drop_while(
VALUE obj)
2633 rb_raise(rb_eArgError,
"tried to call lazy drop_while without a block");
2636 return lazy_add_method(obj, 0, 0,
Qfalse,
Qnil, &lazy_drop_while_funcs);
2640lazy_uniq_check(
VALUE chain,
VALUE memos,
long memo_index)
2642 VALUE hash = rb_ary_entry(memos, memo_index);
2646 rb_ary_store(memos, memo_index, hash);
2649 return rb_hash_add_new_element(hash, chain,
Qfalse);
2655 if (lazy_uniq_check(result->memo_value, memos, memo_index))
return 0;
2664 if (lazy_uniq_check(chain, memos, memo_index))
return 0;
2669 lazy_uniq_iter_proc, 0,
2689 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, funcs);
2695 if (
NIL_P(result->memo_value))
return 0;
2700 lazy_compact_proc, 0,
2711lazy_compact(
VALUE obj)
2713 return lazy_add_method(obj, 0, 0,
Qnil,
Qnil, &lazy_compact_funcs);
2720 VALUE memo = rb_ary_entry(memos, memo_index);
2727 argv[0] = result->memo_value;
2731 LAZY_MEMO_RESET_PACKED(result);
2734 LAZY_MEMO_SET_VALUE(result, rb_ary_new_from_values(2, argv));
2735 LAZY_MEMO_SET_PACKED(result);
2742lazy_with_index_size(
VALUE proc,
VALUE receiver)
2748 lazy_with_index_proc, lazy_with_index_size,
2769lazy_with_index(
int argc,
VALUE *argv,
VALUE obj)
2777 return lazy_add_method(obj, 0, 0, memo, rb_ary_new_from_values(1, &memo), &lazy_with_index_funcs);
2789lazy_chunk(
VALUE self)
2800lazy_chunk_while(
VALUE self)
2812lazy_slice_after(
VALUE self)
2824lazy_slice_before(
VALUE self)
2835lazy_slice_when(
VALUE self)
2907stop_result(
VALUE self)
2909 return rb_attr_get(self, id_result);
2917producer_mark(
void *p)
2920 rb_gc_mark_movable(ptr->init);
2921 rb_gc_mark_movable(ptr->proc);
2925producer_compact(
void *p)
2928 ptr->init = rb_gc_location(ptr->init);
2929 ptr->proc = rb_gc_location(ptr->proc);
2932#define producer_free RUBY_TYPED_DEFAULT_FREE
2935producer_memsize(
const void *p)
2948 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
2952producer_ptr(
VALUE obj)
2957 if (!ptr || UNDEF_P(ptr->proc)) {
2958 rb_raise(rb_eArgError,
"uninitialized producer");
2965producer_allocate(
VALUE klass)
2985 rb_raise(rb_eArgError,
"unallocated producer");
2997 return rb_attr_get(exc, id_result);
3000NORETURN(
static VALUE producer_each_i(
VALUE obj));
3003producer_each_i(
VALUE obj)
3006 VALUE init, proc, curr;
3008 ptr = producer_ptr(obj);
3012 if (UNDEF_P(init)) {
3030producer_each(
VALUE obj)
3079enumerator_s_produce(
int argc,
VALUE *argv,
VALUE klass)
3105enum_chain_mark(
void *p)
3108 rb_gc_mark_movable(ptr->enums);
3112enum_chain_compact(
void *p)
3115 ptr->enums = rb_gc_location(ptr->enums);
3118#define enum_chain_free RUBY_TYPED_DEFAULT_FREE
3121enum_chain_memsize(
const void *p)
3134 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3138enum_chain_ptr(
VALUE obj)
3143 if (!ptr || UNDEF_P(ptr->enums)) {
3144 rb_raise(rb_eArgError,
"uninitialized chain");
3151enum_chain_allocate(
VALUE klass)
3179 rb_check_frozen(obj);
3182 if (!ptr) rb_raise(rb_eArgError,
"unallocated chain");
3184 ptr->enums = rb_ary_freeze(enums);
3191new_enum_chain(
VALUE enums)
3194 VALUE obj = enum_chain_initialize(enum_chain_allocate(rb_cEnumChain), enums);
3198 return enumerable_lazy(obj);
3212 ptr0 = enum_chain_ptr(orig);
3216 if (!ptr1) rb_raise(rb_eArgError,
"unallocated chain");
3218 ptr1->enums = ptr0->enums;
3219 ptr1->pos = ptr0->pos;
3225enum_chain_total_size(
VALUE enums)
3256enum_chain_size(
VALUE obj)
3258 return enum_chain_total_size(enum_chain_ptr(obj)->enums);
3264 return enum_chain_size(obj);
3286enum_chain_each(
int argc,
VALUE *argv,
VALUE obj)
3294 objptr = enum_chain_ptr(obj);
3295 enums = objptr->enums;
3315enum_chain_rewind(
VALUE obj)
3317 struct enum_chain *objptr = enum_chain_ptr(obj);
3318 VALUE enums = objptr->enums;
3321 for (i = objptr->pos; 0 <= i && i <
RARRAY_LEN(enums); objptr->pos = --i) {
3329inspect_enum_chain(
VALUE obj,
VALUE dummy,
int recur)
3336 if (!ptr || UNDEF_P(ptr->enums)) {
3337 return rb_sprintf(
"#<%"PRIsVALUE
": uninitialized>",
rb_class_path(klass));
3341 return rb_sprintf(
"#<%"PRIsVALUE
": ...>",
rb_class_path(klass));
3344 return rb_sprintf(
"#<%"PRIsVALUE
": %+"PRIsVALUE
">",
rb_class_path(klass), ptr->enums);
3354enum_chain_inspect(
VALUE obj)
3372 VALUE enums = rb_ary_new_from_values(1, &obj);
3373 rb_ary_cat(enums, argv, argc);
3374 return new_enum_chain(enums);
3390 return new_enum_chain(rb_ary_new_from_args(2, obj, eobj));
3427enum_product_mark(
void *p)
3430 rb_gc_mark_movable(ptr->enums);
3434enum_product_compact(
void *p)
3437 ptr->enums = rb_gc_location(ptr->enums);
3440#define enum_product_free RUBY_TYPED_DEFAULT_FREE
3443enum_product_memsize(
const void *p)
3453 enum_product_memsize,
3454 enum_product_compact,
3456 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3460enum_product_ptr(
VALUE obj)
3465 if (!ptr || UNDEF_P(ptr->enums)) {
3466 rb_raise(rb_eArgError,
"uninitialized product");
3473enum_product_allocate(
VALUE klass)
3496enum_product_initialize(
int argc,
VALUE *argv,
VALUE obj)
3504 rb_exc_raise(rb_keyword_error_new(
"unknown", rb_hash_keys(options)));
3507 rb_check_frozen(obj);
3510 if (!ptr) rb_raise(rb_eArgError,
"unallocated product");
3512 ptr->enums = rb_ary_freeze(enums);
3524 ptr0 = enum_product_ptr(orig);
3528 if (!ptr1) rb_raise(rb_eArgError,
"unallocated product");
3530 ptr1->enums = ptr0->enums;
3536enum_product_total_size(
VALUE enums)
3545 rb_ary_resize(sizes, 0);
3548 rb_ary_push(sizes, size);
3576enum_product_size(
VALUE obj)
3578 return enum_product_total_size(enum_product_ptr(obj)->enums);
3584 return enum_product_size(obj);
3601 pstate->argv[pstate->index++] = value;
3603 VALUE val = product_each(pstate->obj, pstate);
3612 VALUE enums = ptr->enums;
3614 if (pstate->index < pstate->argc) {
3620 rb_funcall(pstate->block, id_call, 1, rb_ary_new_from_values(pstate->argc, pstate->argv));
3639 return product_each(obj, &state);
3655enum_product_each(
VALUE obj)
3671enum_product_rewind(
VALUE obj)
3674 VALUE enums = ptr->enums;
3685inspect_enum_product(
VALUE obj,
VALUE dummy,
int recur)
3692 if (!ptr || UNDEF_P(ptr->enums)) {
3693 return rb_sprintf(
"#<%"PRIsVALUE
": uninitialized>",
rb_class_path(klass));
3697 return rb_sprintf(
"#<%"PRIsVALUE
": ...>",
rb_class_path(klass));
3700 return rb_sprintf(
"#<%"PRIsVALUE
": %+"PRIsVALUE
">",
rb_class_path(klass), ptr->enums);
3710enum_product_inspect(
VALUE obj)
3732enumerator_s_product(
int argc,
VALUE *argv,
VALUE klass)
3736 rb_scan_args(argc, argv,
"*:&", &enums, &options, &block);
3739 rb_exc_raise(rb_keyword_error_new(
"unknown", rb_hash_keys(options)));
3742 VALUE obj = enum_product_initialize(argc, argv, enum_product_allocate(rb_cEnumProduct));
3744 if (!
NIL_P(block)) {
3745 enum_product_run(obj, block);
3769 VALUE aseq = enumerator_init(enumerator_allocate(rb_cArithSeq),
3785arith_seq_begin(
VALUE self)
3796arith_seq_end(
VALUE self)
3808arith_seq_step(
VALUE self)
3819arith_seq_exclude_end(
VALUE self)
3825arith_seq_exclude_end_p(
VALUE self)
3827 return RTEST(arith_seq_exclude_end(self));
3834 component->
begin = arith_seq_begin(obj);
3835 component->
end = arith_seq_end(obj);
3836 component->
step = arith_seq_step(obj);
3837 component->
exclude_end = arith_seq_exclude_end_p(obj);
3849rb_arithmetic_sequence_beg_len_step(
VALUE obj,
long *begp,
long *lenp,
long *stepp,
long len,
int err)
3851 RBIMPL_NONNULL_ARG(begp);
3852 RBIMPL_NONNULL_ARG(lenp);
3853 RBIMPL_NONNULL_ARG(stepp);
3856 if (!rb_arithmetic_sequence_extract(obj, &aseq)) {
3876 if (err == 0 && (step < -1 || step > 1)) {
3903arith_seq_first(
int argc,
VALUE *argv,
VALUE self)
3911 b = arith_seq_begin(self);
3912 e = arith_seq_end(self);
3913 s = arith_seq_step(self);
3935 rb_raise(rb_eArgError,
"attempt to take negative size");
3938 return rb_ary_new_capa(0);
3941 x = arith_seq_exclude_end_p(self);
3945 ary = rb_ary_new_capa(n);
3954 rb_ary_push(ary, b);
3955 b = rb_big_plus(b, s);
3972 ary = rb_ary_new_capa((n <
len) ? n :
len);
3973 while (n > 0 && i < end) {
3975 if (i > LONG_MAX - unit)
break;
3985 ary = rb_ary_new_capa((n <
len) ? n :
len);
3986 while (n > 0 && i > end) {
3988 if (i < LONG_MIN - unit)
break;
4000 double end =
NIL_P(e) ? (unit < 0 ? -1 : 1)*HUGE_VAL :
NUM2DBL(e);
4001 double len = ruby_float_step_size(beg, end, unit, x);
4009 ary = rb_ary_new_capa(1);
4010 rb_ary_push(ary,
DBL2NUM(beg));
4013 ary = rb_ary_new_capa(0);
4016 else if (unit == 0) {
4018 ary = rb_ary_new_capa(n);
4019 for (i = 0; i <
len; ++i) {
4020 rb_ary_push(ary, val);
4024 ary = rb_ary_new_capa(n);
4025 for (i = 0; i < n; ++i) {
4026 double d = i*unit+beg;
4027 if (unit >= 0 ? end < d : d < end) d = end;
4042 return rb_int_plus(a, b);
4045 return rb_float_plus(a, b);
4048 return rb_rational_plus(a, b);
4051 return rb_funcallv(a,
'+', 1, &b);
4059 return rb_int_minus(a, b);
4062 return rb_float_minus(a, b);
4065 return rb_rational_minus(a, b);
4068 return rb_funcallv(a,
'-', 1, &b);
4076 return rb_int_mul(a, b);
4079 return rb_float_mul(a, b);
4082 return rb_rational_mul(a, b);
4085 return rb_funcallv(a,
'*', 1, &b);
4094 q = rb_int_idiv(a, b);
4097 q = rb_float_div(a, b);
4100 q = rb_rational_div(a, b);
4103 q = rb_funcallv(a, idDiv, 1, &b);
4110 return rb_float_floor(q, 0);
4113 return rb_rational_floor(q, 0);
4129arith_seq_last(
int argc,
VALUE *argv,
VALUE self)
4131 VALUE b, e, s, len_1,
len, last, nv, ary;
4132 int last_is_adjusted;
4135 e = arith_seq_end(self);
4138 "cannot get the last element of endless arithmetic sequence");
4141 b = arith_seq_begin(self);
4142 s = arith_seq_step(self);
4144 len_1 = num_idiv(num_minus(e, b), s);
4145 if (rb_num_negative_int_p(len_1)) {
4149 return rb_ary_new_capa(0);
4152 last = num_plus(b, num_mul(s, len_1));
4153 if ((last_is_adjusted = arith_seq_exclude_end_p(self) &&
rb_equal(last, e))) {
4154 last = num_minus(last, s);
4161 if (last_is_adjusted) {
4177 rb_raise(rb_eArgError,
"negative array size");
4180 ary = rb_ary_new_capa(n);
4181 b = rb_int_minus(last, rb_int_mul(s, nv));
4183 b = rb_int_plus(b, s);
4184 rb_ary_push(ary, b);
4198arith_seq_inspect(
VALUE self)
4201 VALUE eobj, str, eargs;
4206 eobj = rb_attr_get(self, id_receiver);
4212 str = rb_sprintf(
"(%s%"PRIsVALUE
"%s.", range_p ?
"(" :
"", eobj, range_p ?
")" :
"");
4216 eargs = rb_attr_get(eobj, id_arguments);
4232 if (all_key) kwds = argv[--argc];
4236 VALUE arg = *argv++;
4268 if (!
rb_equal(arith_seq_begin(self), arith_seq_begin(other))) {
4272 if (!
rb_equal(arith_seq_end(self), arith_seq_end(other))) {
4276 if (!
rb_equal(arith_seq_step(self), arith_seq_step(other))) {
4280 if (arith_seq_exclude_end_p(self) != arith_seq_exclude_end_p(other)) {
4298arith_seq_hash(
VALUE self)
4304 v = rb_hash(arith_seq_begin(self));
4306 v = rb_hash(arith_seq_end(self));
4308 v = rb_hash(arith_seq_step(self));
4315#define NUM_GE(x, y) RTEST(rb_num_coerce_relop((x), (y), idGE))
4330arith_seq_each(
VALUE self)
4332 VALUE c, e, s, len_1, last;
4337 c = arith_seq_begin(self);
4338 e = arith_seq_end(self);
4339 s = arith_seq_step(self);
4340 x = arith_seq_exclude_end_p(self);
4349 c = rb_int_plus(c, s);
4363 len_1 = num_idiv(num_minus(e, c), s);
4364 last = num_plus(c, num_mul(s, len_1));
4366 last = num_minus(last, s);
4369 if (rb_num_negative_int_p(s)) {
4370 while (NUM_GE(c, last)) {
4376 while (NUM_GE(last, c)) {
4393arith_seq_size(
VALUE self)
4398 b = arith_seq_begin(self);
4399 e = arith_seq_end(self);
4400 s = arith_seq_step(self);
4401 x = arith_seq_exclude_end_p(self);
4407 if (rb_num_negative_int_p(s)) {
4419 if (isinf(n))
return DBL2NUM(n);
4421 return rb_dbl2big(n);
4436 len_1 = rb_int_idiv(rb_int_minus(e, b), s);
4437 if (rb_num_negative_int_p(len_1)) {
4441 last = rb_int_plus(b, rb_int_mul(s, len_1));
4452#define sym(name) ID2SYM(rb_intern_const(name))
4454InitVM_Enumerator(
void)
4490 rb_define_alias(rb_cLazy,
"_enumerable_collect_concat",
"collect_concat");
4506 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_map"));
4507 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_collect"));
4508 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_flat_map"));
4509 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_collect_concat"));
4510 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_select"));
4511 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_find_all"));
4512 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_filter"));
4513 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_filter_map"));
4514 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_reject"));
4515 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_grep"));
4516 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_grep_v"));
4517 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_zip"));
4518 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_take"));
4519 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_take_while"));
4520 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_drop"));
4521 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_drop_while"));
4522 rb_funcall(rb_cLazy, id_private, 1, sym(
"_enumerable_uniq"));
4554 lazy_use_super_method = rb_hash_new_with_size(18);
4555 rb_hash_aset(lazy_use_super_method, sym(
"map"), sym(
"_enumerable_map"));
4556 rb_hash_aset(lazy_use_super_method, sym(
"collect"), sym(
"_enumerable_collect"));
4557 rb_hash_aset(lazy_use_super_method, sym(
"flat_map"), sym(
"_enumerable_flat_map"));
4558 rb_hash_aset(lazy_use_super_method, sym(
"collect_concat"), sym(
"_enumerable_collect_concat"));
4559 rb_hash_aset(lazy_use_super_method, sym(
"select"), sym(
"_enumerable_select"));
4560 rb_hash_aset(lazy_use_super_method, sym(
"find_all"), sym(
"_enumerable_find_all"));
4561 rb_hash_aset(lazy_use_super_method, sym(
"filter"), sym(
"_enumerable_filter"));
4562 rb_hash_aset(lazy_use_super_method, sym(
"filter_map"), sym(
"_enumerable_filter_map"));
4563 rb_hash_aset(lazy_use_super_method, sym(
"reject"), sym(
"_enumerable_reject"));
4564 rb_hash_aset(lazy_use_super_method, sym(
"grep"), sym(
"_enumerable_grep"));
4565 rb_hash_aset(lazy_use_super_method, sym(
"grep_v"), sym(
"_enumerable_grep_v"));
4566 rb_hash_aset(lazy_use_super_method, sym(
"zip"), sym(
"_enumerable_zip"));
4567 rb_hash_aset(lazy_use_super_method, sym(
"take"), sym(
"_enumerable_take"));
4568 rb_hash_aset(lazy_use_super_method, sym(
"take_while"), sym(
"_enumerable_take_while"));
4569 rb_hash_aset(lazy_use_super_method, sym(
"drop"), sym(
"_enumerable_drop"));
4570 rb_hash_aset(lazy_use_super_method, sym(
"drop_while"), sym(
"_enumerable_drop_while"));
4571 rb_hash_aset(lazy_use_super_method, sym(
"uniq"), sym(
"_enumerable_uniq"));
4572 rb_hash_aset(lazy_use_super_method, sym(
"with_index"), sym(
"_enumerable_with_index"));
4574 rb_vm_register_global_object(lazy_use_super_method);
4594 rb_define_method(rb_cGenerator,
"initialize_copy", generator_init_copy, 1);
4615 rb_define_method(rb_cEnumChain,
"initialize_copy", enum_chain_init_copy, 1);
4629 rb_define_method(rb_cEnumProduct,
"initialize", enum_product_initialize, -1);
4630 rb_define_method(rb_cEnumProduct,
"initialize_copy", enum_product_init_copy, 1);
4665Init_Enumerator(
void)
4682 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_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_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_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.
VALUE rb_fiber_current(void)
Queries the fiber which is calling this function.
#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.
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.
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_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_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().
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
int len
Length of the buffer.
#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)
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
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.
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 RHASH_EMPTY_P(h)
Checks if the hash is empty.
#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.
struct rb_data_type_struct rb_data_type_t
This is the struct that holds necessary info for a struct.
#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.
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.