Ruby: range.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Functions | Variables
range.c File Reference
`#include "ruby/internal/config.h"`
`#include <assert.h>`
`#include <math.h>`
`#include "id.h"`
`#include "internal.h"`
`#include "internal/array.h"`
`#include "internal/compar.h"`
`#include "internal/enum.h"`
`#include "internal/enumerator.h"`
`#include "internal/error.h"`
`#include "internal/numeric.h"`
`#include "internal/range.h"`

Go to the source code of this file.

## Macros
#define | id_cmp idCmp
#define | id_succ idSucc
#define | id_min idMin
#define | id_max idMax
#define | RANGE_SET_BEG(r, v) (RSTRUCT_SET(r, 0, v))
#define | RANGE_SET_END(r, v) (RSTRUCT_SET(r, 1, v))
#define | RANGE_SET_EXCL(r, v) (RSTRUCT_SET(r, 2, v))
#define | RBOOL(v) ((v) ? Qtrue : Qfalse)
#define | EXCL(r) RTEST(RANGE_EXCL(r))
#define | BSEARCH_CHECK(expr)
#define | BSEARCH(conv)

## Functions
VALUE | rb_range_new (VALUE beg, VALUE end, int exclude_end)
int | rb_range_values (VALUE range, VALUE *begp, VALUE *endp, int *exclp)
VALUE | rb_range_component_beg_len (VALUE b, VALUE e, int excl, long *begp, long *lenp, long len, int err)
VALUE | rb_range_beg_len (VALUE range, long *begp, long *lenp, long len, int err)
void | Init_Range (void)

## Variables
VALUE | rb_cRange

## Macro Definition Documentation

## ◆ BSEARCH

#define BSEARCH | ( |  | conv | ) |

Value:
do { \
RETURN_ENUMERATOR(range, 0, 0); \
if (EXCL(range)) high--; \
org_high = high; \
while (low < high) { \
mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
: (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \
BSEARCH_CHECK(conv(mid)); \
if (smaller) { \
high = mid; \
} \
else { \
low = mid + 1; \
} \
} \
if (low == org_high) { \
BSEARCH_CHECK(conv(low)); \
if (!smaller) return Qnil; \
} \
return satisfied; \
} while (0)
range
#define range(low, item, hi)
Definition: date_strftime.c:21
EXCL
#define EXCL(r)
Definition: range.c:45
Qnil
#define Qnil
Definition: special_consts.h:51
smaller
#define smaller(tree, n, m, depth)
Definition: trees.c:441

## ◆ BSEARCH_CHECK

#define BSEARCH_CHECK | ( |  | expr | ) |

Value:
do { \
VALUE val = (expr); \
VALUE v = rb_yield(val); \
if (FIXNUM_P(v)) { \
if (v == INT2FIX(0)) return val; \
smaller = (SIGNED_VALUE)v < 0; \
} \
else if (v == Qtrue) { \
satisfied = val; \
smaller = 1; \
} \
else if (v == Qfalse || v == Qnil) { \
smaller = 0; \
} \
else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \
int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \
if (!cmp) return val; \
smaller = cmp < 0; \
} \
else { \
rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE \
" (must be numeric, true, false or nil)", \
rb_obj_class(v)); \
} \
} while (0)
rb_cmpint
#define rb_cmpint(cmp, a, b)
PRIsVALUE
#define PRIsVALUE
Definition: function.c:10
rb_cNumeric
VALUE rb_cNumeric
Definition: numeric.c:189
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:1057
rb_obj_class
VALUE rb_obj_class(VALUE)
Definition: object.c:245
rb_obj_is_kind_of
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
Definition: object.c:724
rb_funcall
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:1077
rb_yield
VALUE rb_yield(VALUE)
Definition: vm_eval.c:1341
INT2FIX
#define INT2FIX
Definition: long.h:48
id_cmp
#define id_cmp
Definition: range.c:33
Qtrue
#define Qtrue
Definition: special_consts.h:52
Qfalse
#define Qfalse
Definition: special_consts.h:50
FIXNUM_P
#define FIXNUM_P
Definition: special_consts.h:44
VALUE
unsigned long VALUE
Definition: value.h:38
SIGNED_VALUE
#define SIGNED_VALUE
Definition: value.h:40
if
if((ID)(DISPID) nameid !=nameid)
Definition: win32ole.c:357

## ◆ EXCL

#define EXCL | ( |  | r | ) | RTEST(RANGE_EXCL(r))

Definition at line 45 of file range.c.

## ◆ id_cmp

#define id_cmp idCmp

Definition at line 33 of file range.c.

## ◆ id_max

#define id_max idMax

Definition at line 36 of file range.c.

## ◆ id_min

#define id_min idMin

Definition at line 35 of file range.c.

## ◆ id_succ

#define id_succ idSucc

Definition at line 34 of file range.c.

## ◆ RANGE_SET_BEG

#define RANGE_SET_BEG | ( |  | r,
|  |  | v
| ) |  | (RSTRUCT_SET(r, 0, v))

Definition at line 40 of file range.c.

## ◆ RANGE_SET_END

#define RANGE_SET_END | ( |  | r,
|  |  | v
| ) |  | (RSTRUCT_SET(r, 1, v))

Definition at line 41 of file range.c.

## ◆ RANGE_SET_EXCL

#define RANGE_SET_EXCL | ( |  | r,
|  |  | v
| ) |  | (RSTRUCT_SET(r, 2, v))

Definition at line 42 of file range.c.

## ◆ RBOOL

#define RBOOL | ( |  | v | ) | ((v) ? Qtrue : Qfalse)

Definition at line 43 of file range.c.

## Function Documentation

## ◆ Init_Range()

void Init_Range | ( | void |  | ) |

Definition at line 1844 of file range.c.

References NULL, rb_cObject, rb_cRange, rb_define_method, rb_include_module(), rb_marshal_define_compat(), rb_mEnumerable, and rb_struct_define_without_accessor().

## ◆ rb_range_beg_len()

VALUE rb_range_beg_len | ( | VALUE | range,
|  | long * | begp,
|  | long * | lenp,
|  | long | len,
|  | int | err
| ) |  |

Definition at line 1398 of file range.c.

References err, len, NIL_P, PRIsVALUE, Qfalse, range, rb_eRangeError, rb_raise(), rb_range_component_beg_len(), and rb_range_values().

Referenced by rb_get_values_at().

## ◆ rb_range_component_beg_len()

VALUE rb_range_component_beg_len | ( | VALUE | b,
|  | VALUE | e,
|  | int | excl,
|  | long * | begp,
|  | long * | lenp,
|  | long | len,
|  | int | err
| ) |  |

Definition at line 1362 of file range.c.

References err, len, NIL_P, NUM2LONG, Qnil, and Qtrue.

Referenced by rb_arithmetic_sequence_beg_len_step(), and rb_range_beg_len().

## ◆ rb_range_new()

VALUE rb_range_new | ( | VALUE | beg,
|  | VALUE | end,
|  | int | exclude_end
| ) |  |

Definition at line 68 of file range.c.

References range, rb_cRange, rb_obj_alloc(), and RBOOL.

## ◆ rb_range_values()

int rb_range_values | ( | VALUE | range,
|  | VALUE * | begp,
|  | VALUE * | endp,
|  | int * | exclp
| ) |  |

Definition at line 1310 of file range.c.

References EXCL, Qfalse, Qtrue, Qundef, range, rb_cArithSeq, rb_check_funcall(), rb_cRange, rb_intern(), rb_obj_is_kind_of(), and RTEST.

Referenced by rb_arithmetic_sequence_extract(), and rb_range_beg_len().

## Variable Documentation

## ◆ rb_cRange

VALUE rb_cRange

Definition at line 31 of file range.c.

Referenced by Init_Range(), rb_range_new(), and rb_range_values().