12#include "ruby/internal/config.h"
23#include "internal/array.h"
24#include "internal/class.h"
25#include "internal/compar.h"
26#include "internal/enum.h"
27#include "internal/enumerator.h"
28#include "internal/error.h"
29#include "internal/numeric.h"
30#include "internal/object.h"
31#include "internal/range.h"
36static ID id_beg, id_end, id_excl;
45#define RANGE_SET_BEG(r, v) (RSTRUCT_SET(r, 0, v))
46#define RANGE_SET_END(r, v) (RSTRUCT_SET(r, 1, v))
48#define EXCL(r) RTEST(FL_TEST(r, RANGE_FL_EXCL))
59 rb_raise(rb_eArgError,
"bad value for range");
62 if (
RTEST(exclude_end)) {
68 RANGE_SET_BEG(range, beg);
69 RANGE_SET_END(range, end);
81 range_init(range, beg, end, RBOOL(exclude_end));
87rb_zjit_range_new_fastpath(
bool exclude_end,
size_t *alloc_size_out,
VALUE *flags_out)
90 *alloc_size_out = offsetof(
struct RStruct, as.ary) + (
sizeof(
VALUE) *
len);
92 *alloc_size_out +=
sizeof(
VALUE);
96 if (exclude_end) *flags_out |= RANGE_FL_EXCL;
101range_modify(
VALUE range)
103 rb_check_frozen(range);
105 if (
FL_TEST(range, RANGE_FL_INIT)) {
106 rb_name_err_raise(
"'initialize' called twice", range,
ID2SYM(idInitialize));
126range_initialize(
int argc,
VALUE *argv,
VALUE range)
128 VALUE beg, end, flags;
132 range_init(range, beg, end, RBOOL(
RTEST(flags)));
142 rb_struct_init_copy(range, orig);
159range_exclude_end_p(
VALUE range)
161 return RBOOL(EXCL(range));
165recursive_equal(
VALUE range,
VALUE obj,
int recur)
167 if (recur)
return Qtrue;
168 if (!
rb_equal(RANGE_BEG(range), RANGE_BEG(obj)))
170 if (!
rb_equal(RANGE_END(range), RANGE_END(obj)))
173 return RBOOL(EXCL(range) == EXCL(obj));
228 return OPTIMIZED_CMP(a, b);
240#define rb_cmpint(cmp, a, b) (NIL_P(r = (cmp)) ? INT_MAX : rb_cmpint(r, (a), (b)))
241 return OPTIMIZED_CMP(a, b);
246recursive_eql(
VALUE range,
VALUE obj,
int recur)
248 if (recur)
return Qtrue;
249 if (!
rb_eql(RANGE_BEG(range), RANGE_BEG(obj)))
251 if (!
rb_eql(RANGE_END(range), RANGE_END(obj)))
254 return RBOOL(EXCL(range) == EXCL(obj));
309range_hash(
VALUE range)
311 st_index_t hash = EXCL(range);
315 v = rb_hash(RANGE_BEG(range));
317 v = rb_hash(RANGE_END(range));
329 VALUE b = RANGE_BEG(range);
330 VALUE e = RANGE_END(range);
334 while (r_less(v, e) < 0) {
335 if ((*func)(v, arg))
break;
340 while ((c = r_less(v, e)) <= 0) {
341 if ((*func)(v, arg))
break;
352step_i_iter(
VALUE arg)
357 iter[0] -=
INT2FIX(1) & ~FIXNUM_FLAG;
362 if (iter[0] !=
INT2FIX(0))
return false;
370 if (step_i_iter(arg)) {
379 if (step_i_iter(arg)) {
386discrete_object_p(
VALUE obj)
392linear_object_p(
VALUE obj)
409check_step_domain(
VALUE step)
416 cmp = rb_cmpint(
rb_funcallv(step, idCmp, 1, &zero), step, zero);
418 rb_raise(rb_eArgError,
"step can't be negative");
421 rb_raise(rb_eArgError,
"step can't be 0");
429 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
436 return ruby_num_interval_step_size(b, e, step, EXCL(range));
525 b = RANGE_BEG(range);
526 e = RANGE_END(range);
540 if (b_num_p || !
NIL_P(str_b) || !
NIL_P(sym_b) || (
NIL_P(b) && e_num_p))
543 rb_raise(rb_eArgError,
"step is required for non-numeric ranges");
549 rb_raise(rb_eArgError,
"step can't be 0");
556 if (step_num_p && ((b_num_p && (
NIL_P(e) || e_num_p)) || (
NIL_P(b) && e_num_p))) {
557 return rb_arith_seq_new(range,
ID2SYM(rb_frame_this_func()), argc, argv,
558 range_step_size, b, e, step, EXCL(range));
563 rb_raise(rb_eArgError,
"#step for non-numeric beginless ranges is meaningless");
570 rb_raise(rb_eArgError,
"#step iteration for beginless ranges is meaningless");
583 for (;; b = rb_big_plus(b, step))
610 else if (b_num_p && step_num_p && ruby_float_step(b, e, step, EXCL(range), TRUE)) {
620 rb_str_upto_endless_each(str_b, step_i, (
VALUE)iter);
623 rb_str_upto_each(str_b, e, EXCL(range), step_i, (
VALUE)iter);
632 rb_str_upto_endless_each(sym_b, sym_step_i, (
VALUE)iter);
635 rb_str_upto_each(sym_b,
rb_sym2str(e), EXCL(range), sym_step_i, (
VALUE)iter);
643 else if (b_num_p && step_num_p && r_less(step,
INT2FIX(0)) < 0) {
646 for (; r_less(e, v) < 0; v =
rb_funcall(v, id_plus, 1, step))
650 for (; (c = r_less(e, v)) <= 0; v =
rb_funcall(v, id_plus, 1, step)) {
657 else if ((dir = r_less(b, e)) == 0) {
662 else if (dir == r_less(b,
rb_funcall(b, id_plus, 1, step))) {
670 for (; r_less(v, e) == dir; v =
rb_funcall(v, id_plus, 1, step))
674 for (; (c = r_less(v, e)) == dir || c == 0; v =
rb_funcall(v, id_plus, 1, step)) {
708 return range_step(1, &step, range);
711#if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
718int64_as_double_to_num(int64_t i)
720 union int64_double convert;
732double_as_int64(
double d)
734 union int64_double convert;
736 return d < 0 ? -convert.i : convert.i;
751 return RTEST(is_int) && !UNDEF_P(is_int);
755bsearch_integer_range(
VALUE beg,
VALUE end,
int excl)
760#define BSEARCH_CHECK(expr) \
762 VALUE val = (expr); \
763 VALUE v = rb_yield(val); \
765 if (v == INT2FIX(0)) return val; \
766 smaller = (SIGNED_VALUE)v < 0; \
768 else if (v == Qtrue) { \
772 else if (!RTEST(v)) { \
775 else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \
776 int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \
777 if (!cmp) return val; \
781 rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE \
782 " (must be numeric, true, false or nil)", \
804 rb_cmpint(
rb_funcall(low, id_cmp, 1, mid), low, mid) < 0) {
827range_bsearch(
VALUE range)
852#define BSEARCH(conv, excl) \
854 RETURN_ENUMERATOR(range, 0, 0); \
855 if (!(excl)) high++; \
857 while (low + 1 < high) { \
858 mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
859 : (low + high) / 2; \
860 BSEARCH_CHECK(conv(mid)); \
871#define BSEARCH_FIXNUM(beg, end, excl) \
873 long low = FIX2LONG(beg); \
874 long high = FIX2LONG(end); \
876 BSEARCH(INT2FIX, (excl)); \
879 beg = RANGE_BEG(range);
880 end = RANGE_END(range);
883 BSEARCH_FIXNUM(beg, end, EXCL(range));
885#if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
890 BSEARCH(int64_as_double_to_num, EXCL(range));
893 else if (is_integer_p(beg) && is_integer_p(end)) {
895 return bsearch_integer_range(beg, end, EXCL(range));
897 else if (is_integer_p(beg) &&
NIL_P(end)) {
905 BSEARCH_FIXNUM(beg, mid,
false);
908 return bsearch_integer_range(beg, mid,
false);
915 else if (
NIL_P(beg) && is_integer_p(end)) {
923 BSEARCH_FIXNUM(mid, end,
false);
926 return bsearch_integer_range(mid, end,
false);
952#define CANT_ITERATE_FROM(x) \
953 rb_raise(rb_eTypeError, "can't iterate from %s", \
978range_size(
VALUE range)
980 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
984 return ruby_num_interval_step_size(b, e,
INT2FIX(1), EXCL(range));
991 if (!discrete_object_p(b)) {
992 CANT_ITERATE_FROM(b);
999range_reverse_size(
VALUE range)
1001 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
1004 CANT_ITERATE_FROM(e);
1009 return ruby_num_interval_step_size(b, e,
INT2FIX(1), EXCL(range));
1012 CANT_ITERATE_FROM(e);
1021 CANT_ITERATE_FROM(e);
1025 if (!discrete_object_p(b)) {
1026 CANT_ITERATE_FROM(e);
1032#undef CANT_ITERATE_FROM
1048range_to_a(
VALUE range)
1050 if (
NIL_P(RANGE_END(range))) {
1051 rb_raise(
rb_eRangeError,
"cannot convert endless range to an array");
1071range_to_set(
VALUE range)
1073 if (
NIL_P(RANGE_END(range))) {
1074 rb_raise(
rb_eRangeError,
"cannot convert endless range to a set");
1082 return range_size(range);
1088 return range_reverse_size(range);
1093range_each_bignum_endless(
VALUE beg)
1095 for (;; beg = rb_big_plus(beg,
INT2FIX(1))) {
1103range_each_fixnum_endless(
VALUE beg)
1116 long lim =
FIX2LONG(end) + !EXCL(range);
1117 for (
long i =
FIX2LONG(beg); i < lim; i++) {
1141range_each(
VALUE range)
1148 beg = RANGE_BEG(range);
1149 end = RANGE_END(range);
1152 range_each_fixnum_endless(beg);
1155 return range_each_fixnum_loop(beg, end, range);
1164 if (
NIL_P(end)) range_each_fixnum_endless(beg);
1165 if (
FIXNUM_P(end))
return range_each_fixnum_loop(beg, end, range);
1168 if (
NIL_P(end)) range_each_bignum_endless(beg);
1184 while (rb_big_cmp(beg, end) ==
INT2FIX(-1)) {
1186 beg = rb_big_plus(beg,
INT2FIX(1));
1191 while ((c = rb_big_cmp(beg, end)) !=
INT2FIX(1)) {
1194 beg = rb_big_plus(beg,
INT2FIX(1));
1202 rb_str_upto_endless_each(beg, sym_each_i, 0);
1205 rb_str_upto_each(beg,
rb_sym2str(end), EXCL(range), sym_each_i, 0);
1213 rb_str_upto_each(tmp, end, EXCL(range), each_i, 0);
1216 rb_str_upto_endless_each(tmp, each_i, 0);
1220 if (!discrete_object_p(beg)) {
1225 range_each_func(range, each_i, 0);
1236range_reverse_each_bignum_beginless(
VALUE end)
1240 for (;; end = rb_big_minus(end,
INT2FIX(1))) {
1247range_reverse_each_bignum(
VALUE beg,
VALUE end)
1252 while ((c = rb_big_cmp(beg, end)) !=
INT2FIX(1)) {
1255 end = rb_big_minus(end,
INT2FIX(1));
1260range_reverse_each_positive_bignum_section(
VALUE beg,
VALUE end)
1270 range_reverse_each_bignum(beg, end);
1274range_reverse_each_fixnum_section(
VALUE beg,
VALUE end)
1292 for (
long i = e; i >= b; --i) {
1298range_reverse_each_negative_bignum_section(
VALUE beg,
VALUE end)
1307 range_reverse_each_bignum_beginless(end);
1312 range_reverse_each_bignum(beg, end);
1335range_reverse_each(
VALUE range)
1339 VALUE beg = RANGE_BEG(range);
1340 VALUE end = RANGE_END(range);
1341 int excl = EXCL(range);
1352 end = rb_int_minus(end,
INT2FIX(1));
1355 range_reverse_each_fixnum_section(beg, end);
1359 end = rb_int_minus(end,
INT2FIX(1));
1361 range_reverse_each_positive_bignum_section(beg, end);
1362 range_reverse_each_fixnum_section(beg, end);
1363 range_reverse_each_negative_bignum_section(beg, end);
1435range_first(
int argc,
VALUE *argv,
VALUE range)
1439 if (
NIL_P(RANGE_BEG(range))) {
1440 rb_raise(
rb_eRangeError,
"cannot get the first element of beginless range");
1442 if (argc == 0)
return RANGE_BEG(range);
1453range_basic_each_p(
VALUE range)
1459integer_end_optimizable(
VALUE range)
1461 VALUE b = RANGE_BEG(range);
1463 VALUE e = RANGE_END(range);
1465 if (RB_LIKELY(range_basic_each_p(range)))
return true;
1470rb_int_range_last(
int argc,
VALUE *argv,
VALUE range)
1480 b = RANGE_BEG(range);
1481 e = RANGE_END(range);
1488 len_1 = rb_int_minus(e, b);
1490 e = rb_int_minus(e, ONE);
1494 len = rb_int_plus(len_1, ONE);
1499 e = rb_int_minus(e, ONE);
1503 if (!
NIL_P(
len) && (FIXNUM_ZERO_P(
len) || rb_num_negative_p(
len))) {
1510 rb_raise(rb_eArgError,
"negative array size");
1520 b = rb_int_minus(e, nv);
1522 b = rb_int_plus(b, ONE);
1566range_last(
int argc,
VALUE *argv,
VALUE range)
1568 if (
NIL_P(RANGE_END(range))) {
1569 rb_raise(
rb_eRangeError,
"cannot get the last element of endless range");
1571 if (argc == 0)
return RANGE_END(range);
1572 if (integer_end_optimizable(range)) {
1573 return rb_int_range_last(argc, argv, range);
1575 return rb_ary_last(argc, argv,
rb_Array(range));
1663 if (
NIL_P(RANGE_BEG(range))) {
1664 rb_raise(
rb_eRangeError,
"cannot get the minimum of beginless range");
1668 if (
NIL_P(RANGE_END(range))) {
1669 rb_raise(
rb_eRangeError,
"cannot get the minimum of endless range with custom comparison method");
1673 else if (argc != 0) {
1674 return range_first(argc, argv, range);
1677 VALUE b = RANGE_BEG(range);
1678 VALUE e = RANGE_END(range);
1679 int c =
NIL_P(e) ? -1 : OPTIMIZED_CMP(b, e);
1681 if (c > 0 || (c == 0 && EXCL(range)))
1771 VALUE e = RANGE_END(range);
1774 if (
NIL_P(RANGE_END(range))) {
1775 rb_raise(
rb_eRangeError,
"cannot get the maximum of endless range");
1778 VALUE b = RANGE_BEG(range);
1782 rb_raise(
rb_eRangeError,
"cannot get the maximum of beginless range with custom comparison method");
1789 CONST_ID(reverse_each,
"reverse_each");
1795 if (integer_end_optimizable(range)) {
1796 return rb_int_range_last(argc, argv, range,
true);
1802 int c =
NIL_P(b) ? -1 : OPTIMIZED_CMP(b, e);
1808 rb_raise(
rb_eTypeError,
"cannot exclude non Integer end value");
1810 if (c == 0)
return Qnil;
1812 rb_raise(
rb_eTypeError,
"cannot exclude end value with non Integer begin value");
1817 return rb_int_minus(e,
INT2FIX(1));
1870range_minmax(
VALUE range)
1888 b = RANGE_BEG(range);
1889 e = RANGE_END(range);
1898 if (UNDEF_P(b))
return (
int)
Qfalse;
1900 if (UNDEF_P(e))
return (
int)
Qfalse;
1902 if (UNDEF_P(x))
return (
int)
Qfalse;
1934rb_range_component_beg_len(
VALUE b,
VALUE e,
int excl,
1935 long *begp,
long *lenp,
long len,
int err)
1941 if (
NIL_P(e)) excl = 0;
1951 if (err == 0 || err == 2) {
1978 VALUE res = rb_range_component_beg_len(b, e, excl, begp, lenp,
len, err);
1979 if (
NIL_P(res) && err) {
2008range_to_s(
VALUE range)
2022inspect_range(
VALUE range,
VALUE dummy,
int recur)
2027 return rb_str_new2(EXCL(range) ?
"(... ... ...)" :
"(... .. ...)");
2029 if (!
NIL_P(RANGE_BEG(range)) ||
NIL_P(RANGE_END(range))) {
2036 if (
NIL_P(RANGE_BEG(range)) || !
NIL_P(RANGE_END(range))) {
2067range_inspect(
VALUE range)
2116 return r_cover_p(range, RANGE_BEG(range), RANGE_END(range), val);
2152 VALUE ret = range_include_internal(range, val);
2153 if (!UNDEF_P(ret))
return ret;
2174 if (linear_object_p(val))
return Qtrue;
2178 rb_raise(
rb_eTypeError,
"cannot determine inclusion in beginless/endless ranges");
2185range_include_internal(
VALUE range,
VALUE val)
2187 VALUE beg = RANGE_BEG(range);
2188 VALUE end = RANGE_END(range);
2190 linear_object_p(beg) || linear_object_p(end);
2192 if (nv || range_integer_edge_p(beg, end)) {
2193 return r_cover_p(range, beg, end, val);
2195 else if (range_string_range_p(beg, end)) {
2196 return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
2199 return range_include_fallback(beg, end, val);
2336 beg = RANGE_BEG(range);
2337 end = RANGE_END(range);
2340 return RBOOL(r_cover_range_p(range, beg, end, val));
2342 return r_cover_p(range, beg, end, val);
2354 VALUE val_beg, val_end, val_max;
2357 val_beg = RANGE_BEG(val);
2358 val_end = RANGE_END(val);
2360 if (!
NIL_P(end) &&
NIL_P(val_end))
return FALSE;
2361 if (!
NIL_P(beg) &&
NIL_P(val_beg))
return FALSE;
2362 if (!
NIL_P(val_beg) && !
NIL_P(val_end) && r_less(val_beg, val_end) > (EXCL(val) ? -1 : 0)) return FALSE;
2363 if (!
NIL_P(val_beg) && !r_cover_p(range, beg, end, val_beg))
return FALSE;
2368 if (
NIL_P(r_cmp_end))
return FALSE;
2369 cmp_end = rb_cmpint(r_cmp_end, end, val_end);
2372 cmp_end = r_less(end, val_end);
2376 if (EXCL(range) == EXCL(val)) {
2377 return cmp_end >= 0;
2379 else if (EXCL(range)) {
2382 else if (cmp_end >= 0) {
2387 if (
NIL_P(val_max))
return FALSE;
2389 return r_less(end, val_max) >= 0;
2395 if (
NIL_P(beg) || r_less(beg, val) <= 0) {
2396 int excl = EXCL(range);
2397 if (
NIL_P(end) || r_less(val, end) <= -excl)
2404range_dumper(
VALUE range)
2417 VALUE beg, end, excl;
2423 range_modify(range);
2428 range_init(range, beg, end, RBOOL(
RTEST(excl)));
2434range_alloc(
VALUE klass)
2473range_count(
int argc,
VALUE *argv,
VALUE range)
2486 VALUE beg = RANGE_BEG(range), end = RANGE_END(range);
2493 if (is_integer_p(beg)) {
2494 VALUE size = range_size(range);
2504empty_region_p(
VALUE beg,
VALUE end,
int excl)
2506 if (
NIL_P(beg))
return false;
2507 if (
NIL_P(end))
return false;
2508 int less = r_less(beg, end);
2510 if (less > 0)
return true;
2511 if (excl && less == 0)
return true;
2587 rb_raise(
rb_eTypeError,
"wrong argument type %"PRIsVALUE
" (expected Range)",
2591 VALUE self_beg = RANGE_BEG(range);
2592 VALUE self_end = RANGE_END(range);
2593 int self_excl = EXCL(range);
2594 VALUE other_beg = RANGE_BEG(other);
2595 VALUE other_end = RANGE_END(other);
2596 int other_excl = EXCL(other);
2598 if (empty_region_p(self_beg, other_end, other_excl))
return Qfalse;
2599 if (empty_region_p(other_beg, self_end, self_excl))
return Qfalse;
2605 if (rb_cmpint(cmp, self_beg, other_beg) == 0)
return Qtrue;
2609 return RBOOL(!
NIL_P(cmp));
2612 if (empty_region_p(self_beg, self_end, self_excl))
return Qfalse;
2613 if (empty_region_p(other_beg, other_end, other_excl))
return Qfalse;
2667range_clamp(
int argc,
VALUE *argv,
VALUE self)
2669 VALUE self_beg = RANGE_BEG(self);
2670 VALUE self_end = RANGE_END(self);
2671 int self_excl = EXCL(self);
2673 int clamp_beg = 0, clamp_end = 0, excl = 0;
2679 rb_raise(
rb_eTypeError,
"wrong argument type %s (expected Range)",
2680 rb_builtin_class_name(range));
2683 if (!
NIL_P(min) && !
NIL_P(max) && r_cmp(min, max) > 0) {
2684 rb_raise(rb_eArgError,
"min argument must be less than or equal to max argument");
2688 if (
NIL_P(self_beg) || r_cmp(self_beg, min) < 0) {
2692 if (!
NIL_P(self_end) && r_cmp(self_end, min) < 0) {
2698 if (clamp_beg == 0) {
2699 if (!
NIL_P(self_beg) && r_cmp(self_beg, max) > 0) {
2704 if (clamp_end == 0) {
2705 int cmp =
NIL_P(self_end) ? +1 : r_cmp(self_end, max);
2711 else if (cmp == 0) {
2716 if (clamp_beg && clamp_beg == clamp_end) {
2972 "begin",
"end", NULL);
2987 rb_struct_define_aref_method(
rb_cRange, id_beg, 0);
2988 rb_struct_define_aref_method(
rb_cRange, id_end, 1);
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
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_block_given_p(void)
Determines if the current method is given a block.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define RB_INTEGER_TYPE_P
Old name of rb_integer_type_p.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define T_STRING
Old name of RUBY_T_STRING.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define UNREACHABLE
Old name of RBIMPL_UNREACHABLE.
#define T_FLOAT
Old name of RUBY_T_FLOAT.
#define ID2SYM
Old name of RB_ID2SYM.
#define T_BIGNUM
Old name of RUBY_T_BIGNUM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define T_STRUCT
Old name of RUBY_T_STRUCT.
#define CLASS_OF
Old name of rb_class_of.
#define FIXABLE
Old name of RB_FIXABLE.
#define LONG2FIX
Old name of RB_INT2FIX.
#define ASSUME
Old name of RBIMPL_ASSUME.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define FIXNUM_MIN
Old name of RUBY_FIXNUM_MIN.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define ST2FIX
Old name of RB_ST2FIX.
#define FIXNUM_MAX
Old name of RUBY_FIXNUM_MAX.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define FIX2LONG
Old name of RB_FIX2LONG.
#define T_OBJECT
Old name of RUBY_T_OBJECT.
#define NIL_P
Old name of RB_NIL_P.
#define POSFIXABLE
Old name of RB_POSFIXABLE.
#define DBL2NUM
Old name of rb_float_new.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define FL_TEST
Old name of RB_FL_TEST.
#define FL_FREEZE
Old name of RUBY_FL_FREEZE.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define FL_SET_RAW
Old name of RB_FL_SET_RAW.
#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_cTime
Time class.
VALUE rb_Float(VALUE val)
This is the logic behind Kernel#Float.
VALUE rb_cObject
Object class.
VALUE rb_obj_alloc(VALUE klass)
Allocates an instance of the given class.
VALUE rb_mEnumerable
Enumerable module.
int rb_eql(VALUE lhs, VALUE rhs)
Checks for equality of the passed objects, in terms of Object#eql?.
VALUE rb_cNumeric
Numeric class.
VALUE rb_Array(VALUE val)
This is the logic behind Kernel#Array.
VALUE rb_obj_class(VALUE obj)
Queries the class of an 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_check_to_integer(VALUE val, const char *mid)
Identical to rb_check_convert_type(), except the return value type is fixed to rb_cInteger.
VALUE rb_to_int(VALUE val)
Identical to rb_check_to_int(), except it raises in case of conversion mismatch.
#define RUBY_FIXNUM_MAX
Maximum possible value that a fixnum can represent.
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_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
VALUE rb_ary_reverse(VALUE ary)
Destructively reverses the passed array in-place.
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_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Identical to rb_ary_new_from_values(), except it expects exactly two parameters.
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
This roughly resembles return enum_for(__callee__) unless block_given?.
#define RETURN_ENUMERATOR(obj, argc, argv)
Identical to RETURN_SIZED_ENUMERATOR(), except its size is unknown.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
Deconstructs a range into its components.
VALUE rb_range_new(VALUE beg, VALUE end, int excl)
Creates a new Range.
VALUE rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
Deconstructs a numerical range.
#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.
#define rb_str_new(str, len)
Allocates an instance of rb_cString.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
VALUE rb_struct_define_without_accessor(const char *name, VALUE super, rb_alloc_func_t func,...)
Identical to rb_struct_define(), except it does not define accessor methods.
VALUE rb_struct_alloc_noinit(VALUE klass)
Allocates an instance of the given class.
VALUE rb_exec_recursive(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h)
"Recursion" API entry point.
VALUE rb_exec_recursive_paired(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE p, VALUE h)
Identical to rb_exec_recursive(), except it checks for the recursion on the ordered pair of { g,...
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_name(VALUE obj)
Queries the name of the given object's class.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well... Let us hesitate from describing what a "basic definition" is.
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.
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(VALUE val)
Yields the block.
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
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_rescue2(type *q, VALUE w, type *e, VALUE r,...)
An equivalent of rescue clause.
#define RBIMPL_ATTR_NORETURN()
Wraps (or simulates) [[noreturn]]
#define RARRAY_AREF(a, i)
#define RBASIC(obj)
Convenient casting macro.
#define RBIGNUM_SIGN
Just another name of rb_big_sign.
static bool RBIGNUM_NEGATIVE_P(VALUE b)
Checks if the bignum is negative.
static bool RBIGNUM_POSITIVE_P(VALUE b)
Checks if the bignum is positive.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define RTEST
This is an old name of RB_TEST.
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 bool rb_integer_type_p(VALUE obj)
Queries if the object is an instance of rb_cInteger.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.