Project

General

Profile

Feature #10318 ยป convert_tabs_to_spaces.patch

gogotanaka (Kazuki Tanaka), 10/05/2014 10:46 PM

View differences:

enumerator.c
static const rb_data_type_t enumerator_data_type = {
"enumerator",
{
enumerator_mark,
enumerator_free,
enumerator_memsize,
enumerator_mark,
enumerator_free,
enumerator_memsize,
},
NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
};
......
TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, ptr);
if (!ptr || ptr->obj == Qundef) {
rb_raise(rb_eArgError, "uninitialized enumerator");
rb_raise(rb_eArgError, "uninitialized enumerator");
}
return ptr;
}
......
VALUE enumerator, meth = sym_each;
if (argc > 0) {
--argc;
meth = *argv++;
--argc;
meth = *argv++;
}
enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
if (rb_block_given_p()) {
enumerator_ptr(enumerator)->size = rb_block_proc();
enumerator_ptr(enumerator)->size = rb_block_proc();
}
return enumerator;
}
......
TypedData_Get_Struct(enum_obj, struct enumerator, &enumerator_data_type, ptr);
if (!ptr) {
rb_raise(rb_eArgError, "unallocated enumerator");
rb_raise(rb_eArgError, "unallocated enumerator");
}
ptr->obj = obj;
......
VALUE size = Qnil;
if (rb_block_given_p()) {
rb_check_arity(argc, 0, 1);
recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
if (argc) {
rb_check_arity(argc, 0, 1);
recv = generator_init(generator_allocate(rb_cGenerator), rb_block_proc());
if (argc) {
if (NIL_P(argv[0]) || rb_respond_to(argv[0], id_call) ||
(RB_TYPE_P(argv[0], T_FLOAT) && RFLOAT_VALUE(argv[0]) == INFINITY)) {
size = argv[0];
......
}
}
else {
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
recv = *argv++;
if (--argc) {
meth = *argv++;
--argc;
}
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
rb_warn("Enumerator.new without a block is deprecated; use Object#to_enum");
recv = *argv++;
if (--argc) {
meth = *argv++;
--argc;
}
}
return enumerator_init(obj, recv, meth, argc, argv, 0, size);
......
if (!OBJ_INIT_COPY(obj, orig)) return obj;
ptr0 = enumerator_ptr(orig);
if (ptr0->fib) {
/* Fibers cannot be copied */
rb_raise(rb_eTypeError, "can't copy execution context");
/* Fibers cannot be copied */
rb_raise(rb_eTypeError, "can't copy execution context");
}
TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, ptr1);
if (!ptr1) {
rb_raise(rb_eArgError, "unallocated enumerator");
rb_raise(rb_eArgError, "unallocated enumerator");
}
ptr1->obj = ptr0->obj;
......
/* Similar effect as calling obj.to_enum, i.e. dispatching to either
Kernel#to_enum vs Lazy#to_enum */
if (RTEST(rb_obj_is_kind_of(obj, rb_cLazy)))
return lazy_to_enum_i(obj, meth, argc, argv, size_fn);
return lazy_to_enum_i(obj, meth, argc, argv, size_fn);
else
return enumerator_init(enumerator_allocate(rb_cEnumerator),
obj, meth, argc, argv, size_fn, Qnil);
return enumerator_init(enumerator_allocate(rb_cEnumerator),
obj, meth, argc, argv, size_fn, Qnil);
}
static VALUE
......
ID meth = e->meth;
if (e->args) {
argc = RARRAY_LENINT(e->args);
argv = RARRAY_CONST_PTR(e->args);
argc = RARRAY_LENINT(e->args);
argv = RARRAY_CONST_PTR(e->args);
}
return rb_block_call(e->obj, meth, argc, argv, func, arg);
}
......
enumerator_each(int argc, VALUE *argv, VALUE obj)
{
if (argc > 0) {
struct enumerator *e = enumerator_ptr(obj = rb_obj_dup(obj));
VALUE args = e->args;
if (args) {
struct enumerator *e = enumerator_ptr(obj = rb_obj_dup(obj));
VALUE args = e->args;
if (args) {
#if SIZEOF_INT < SIZEOF_LONG
/* check int range overflow */
rb_long2int(RARRAY_LEN(args) + argc);
/* check int range overflow */
rb_long2int(RARRAY_LEN(args) + argc);
#endif
args = rb_ary_dup(args);
rb_ary_cat(args, argv, argc);
}
else {
args = rb_ary_new4(argc, argv);
}
e->args = args;
args = rb_ary_dup(args);
rb_ary_cat(args, argv, argc);
}
else {
args = rb_ary_new4(argc, argv);
}
e->args = args;
}
if (!rb_block_given_p()) return obj;
return enumerator_block_call(obj, 0, obj);
......
memo->u1.value = rb_int_succ(idx);
if (argc <= 1)
return rb_yield_values(2, val, idx);
return rb_yield_values(2, val, idx);
return rb_yield_values(2, rb_ary_new4(argc, argv), idx);
}
......
rb_scan_args(argc, argv, "01", &memo);
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_enum_size);
if (NIL_P(memo))
memo = INT2FIX(0);
memo = INT2FIX(0);
else
memo = rb_to_int(memo);
memo = rb_to_int(memo);
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)NEW_MEMO(memo, 0, 0));
}
......
enumerator_with_object_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, memo))
{
if (argc <= 1)
return rb_yield_values(2, val, memo);
return rb_yield_values(2, val, memo);
return rb_yield_values(2, rb_ary_new4(argc, argv), memo);
}
......
VALUE curr, vs;
if (e->stop_exc)
rb_exc_raise(e->stop_exc);
rb_exc_raise(e->stop_exc);
curr = rb_fiber_current();
if (!e->fib || !rb_fiber_alive_p(e->fib)) {
next_init(obj, e);
next_init(obj, e);
}
vs = rb_fiber_resume(e->fib, 1, &curr);
if (e->stop_exc) {
e->fib = 0;
e->dst = Qnil;
e->lookahead = Qundef;
e->feedvalue = Qundef;
rb_exc_raise(e->stop_exc);
e->fib = 0;
e->dst = Qnil;
e->lookahead = Qundef;
e->feedvalue = Qundef;
rb_exc_raise(e->stop_exc);
}
return vs;
}
......
struct enumerator *e = enumerator_ptr(obj);
if (e->feedvalue != Qundef) {
rb_raise(rb_eTypeError, "feed value already set");
rb_raise(rb_eTypeError, "feed value already set");
}
e->feedvalue = v;
......
cname = rb_obj_class(obj);
if (!e || e->obj == Qundef) {
return rb_sprintf("#<%"PRIsVALUE": uninitialized>", rb_class_path(cname));
return rb_sprintf("#<%"PRIsVALUE": uninitialized>", rb_class_path(cname));
}
if (recur) {
str = rb_sprintf("#<%"PRIsVALUE": ...>", rb_class_path(cname));
OBJ_TAINT(str);
return str;
str = rb_sprintf("#<%"PRIsVALUE": ...>", rb_class_path(cname));
OBJ_TAINT(str);
return str;
}
eobj = rb_attr_get(obj, id_receiver);
if (NIL_P(eobj)) {
eobj = e->obj;
eobj = e->obj;
}
/* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */
......
method = rb_attr_get(obj, id_method);
if (method != Qfalse) {
if (!NIL_P(method)) {
Check_Type(method, T_SYMBOL);
method = rb_sym2str(method);
}
else {
method = rb_id2str(default_method);
}
rb_str_buf_cat2(str, ":");
rb_str_buf_append(str, method);
if (!NIL_P(method)) {
Check_Type(method, T_SYMBOL);
method = rb_sym2str(method);
}
else {
method = rb_id2str(default_method);
}
rb_str_buf_cat2(str, ":");
rb_str_buf_append(str, method);
}
eargs = rb_attr_get(obj, id_arguments);
if (NIL_P(eargs)) {
eargs = default_args;
eargs = default_args;
}
if (eargs != Qfalse) {
long argc = RARRAY_LEN(eargs);
const VALUE *argv = RARRAY_CONST_PTR(eargs); /* WB: no new reference */
long argc = RARRAY_LEN(eargs);
const VALUE *argv = RARRAY_CONST_PTR(eargs); /* WB: no new reference */
if (argc > 0) {
rb_str_buf_cat2(str, "(");
if (argc > 0) {
rb_str_buf_cat2(str, "(");
while (argc--) {
VALUE arg = *argv++;
while (argc--) {
VALUE arg = *argv++;
rb_str_append(str, rb_inspect(arg));
rb_str_buf_cat2(str, argc > 0 ? ", " : ")");
OBJ_INFECT(str, arg);
}
}
rb_str_append(str, rb_inspect(arg));
rb_str_buf_cat2(str, argc > 0 ? ", " : ")");
OBJ_INFECT(str, arg);
}
}
}
return str;
......
VALUE size;
if (e->size_fn) {
return (*e->size_fn)(e->obj, e->args, obj);
return (*e->size_fn)(e->obj, e->args, obj);
}
if (e->args) {
argc = (int)RARRAY_LEN(e->args);
argv = RARRAY_CONST_PTR(e->args);
argc = (int)RARRAY_LEN(e->args);
argv = RARRAY_CONST_PTR(e->args);
}
size = rb_check_funcall(e->size, id_call, argc, argv);
if (size != Qundef) return size;
......
static const rb_data_type_t yielder_data_type = {
"yielder",
{
yielder_mark,
yielder_free,
yielder_memsize,
yielder_mark,
yielder_free,
yielder_memsize,
},
NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
};
......
TypedData_Get_Struct(obj, struct yielder, &yielder_data_type, ptr);
if (!ptr || ptr->proc == Qundef) {
rb_raise(rb_eArgError, "uninitialized yielder");
rb_raise(rb_eArgError, "uninitialized yielder");
}
return ptr;
}
......
TypedData_Get_Struct(obj, struct yielder, &yielder_data_type, ptr);
if (!ptr) {
rb_raise(rb_eArgError, "unallocated yielder");
rb_raise(rb_eArgError, "unallocated yielder");
}
ptr->proc = proc;
......
static const rb_data_type_t generator_data_type = {
"generator",
{
generator_mark,
generator_free,
generator_memsize,
generator_mark,
generator_free,
generator_memsize,
},
NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
};
......
TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr);
if (!ptr || ptr->proc == Qundef) {
rb_raise(rb_eArgError, "uninitialized generator");
rb_raise(rb_eArgError, "uninitialized generator");
}
return ptr;
}
......
TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr);
if (!ptr) {
rb_raise(rb_eArgError, "unallocated generator");
rb_raise(rb_eArgError, "unallocated generator");
}
ptr->proc = proc;
......
VALUE proc;
if (argc == 0) {
rb_need_block();
rb_need_block();
proc = rb_block_proc();
proc = rb_block_proc();
}
else {
rb_scan_args(argc, argv, "1", &proc);
rb_scan_args(argc, argv, "1", &proc);
if (!rb_obj_is_proc(proc))
rb_raise(rb_eTypeError,
"wrong argument type %s (expected Proc)",
rb_obj_classname(proc));
if (!rb_obj_is_proc(proc))
rb_raise(rb_eTypeError,
"wrong argument type %s (expected Proc)",
rb_obj_classname(proc));
if (rb_block_given_p()) {
rb_warn("given block not used");
}
if (rb_block_given_p()) {
rb_warn("given block not used");
}
}
return generator_init(obj, proc);
......
TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr1);
if (!ptr1) {
rb_raise(rb_eArgError, "unallocated generator");
rb_raise(rb_eArgError, "unallocated generator");
}
ptr1->proc = ptr0->proc;
......
rb_ary_push(args, yielder_new());
if (argc > 0) {
rb_ary_cat(args, argv, argc);
rb_ary_cat(args, argv, argc);
}
return rb_proc_call(ptr->proc, args);
......
{
VALUE result;
if (argc == 1) {
VALUE args[2];
args[0] = m;
args[1] = val;
result = rb_yield_values2(2, args);
VALUE args[2];
args[0] = m;
args[1] = val;
result = rb_yield_values2(2, args);
}
else {
VALUE args;
int len = rb_long2int((long)argc + 1);
VALUE args;
int len = rb_long2int((long)argc + 1);
args = rb_ary_tmp_new(len);
rb_ary_push(args, m);
if (argc > 0) {
rb_ary_cat(args, argv, argc);
}
result = rb_yield_values2(len, RARRAY_CONST_PTR(args));
RB_GC_GUARD(args);
args = rb_ary_tmp_new(len);
rb_ary_push(args, m);
if (argc > 0) {
rb_ary_cat(args, argv, argc);
}
result = rb_yield_values2(len, RARRAY_CONST_PTR(args));
RB_GC_GUARD(args);
}
if (result == Qundef) rb_iter_break();
return Qnil;
......
rb_check_arity(argc, 1, 2);
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy new without a block");
rb_raise(rb_eArgError, "tried to call lazy new without a block");
}
obj = argv[0];
if (argc > 1) {
size = argv[1];
size = argv[1];
}
generator = generator_allocate(rb_cGenerator);
rb_block_call(generator, id_initialize, 0, 0, lazy_init_block_i, obj);
......
struct enumerator *e = enumerator_ptr(lazy);
rb_ivar_set(lazy, id_method, ID2SYM(id));
if (NIL_P(args)) {
/* Qfalse indicates that the arguments are empty */
rb_ivar_set(lazy, id_arguments, Qfalse);
/* Qfalse indicates that the arguments are empty */
rb_ivar_set(lazy, id_arguments, Qfalse);
}
else {
rb_ivar_set(lazy, id_arguments, args);
rb_ivar_set(lazy, id_arguments, args);
}
e->size_fn = size_fn;
return lazy;
......
lazy_to_enum_i(VALUE obj, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *size_fn)
{
return enumerator_init(enumerator_allocate(rb_cLazy),
obj, meth, argc, argv, size_fn, Qnil);
obj, meth, argc, argv, size_fn, Qnil);
}
/*
......
VALUE lazy, meth = sym_each;
if (argc > 0) {
--argc;
meth = *argv++;
--argc;
meth = *argv++;
}
lazy = lazy_to_enum_i(self, meth, argc, argv, 0);
if (rb_block_given_p()) {
enumerator_ptr(lazy)->size = rb_block_proc();
enumerator_ptr(lazy)->size = rb_block_proc();
}
return lazy;
}
......
lazy_map(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy map without a block");
rb_raise(rb_eArgError, "tried to call lazy map without a block");
}
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_map_func, 0),
Qnil, lazy_receiver_size);
lazy_map_func, 0),
Qnil, lazy_receiver_size);
}
static VALUE
......
{
VALUE ary = rb_check_array_type(obj);
if (NIL_P(ary)) {
rb_funcall(yielder, id_yield, 1, obj);
rb_funcall(yielder, id_yield, 1, obj);
}
else {
long i;
for (i = 0; i < RARRAY_LEN(ary); i++) {
rb_funcall(yielder, id_yield, 1, RARRAY_AREF(ary, i));
}
long i;
for (i = 0; i < RARRAY_LEN(ary); i++) {
rb_funcall(yielder, id_yield, 1, RARRAY_AREF(ary, i));
}
}
return Qnil;
}
......
{
VALUE result = rb_yield_values2(argc - 1, &argv[1]);
if (RB_TYPE_P(result, T_ARRAY)) {
long i;
for (i = 0; i < RARRAY_LEN(result); i++) {
rb_funcall(argv[0], id_yield, 1, RARRAY_AREF(result, i));
}
long i;
for (i = 0; i < RARRAY_LEN(result); i++) {
rb_funcall(argv[0], id_yield, 1, RARRAY_AREF(result, i));
}
}
else {
if (rb_respond_to(result, id_force) && rb_respond_to(result, id_each)) {
lazy_flat_map_each(result, argv[0]);
}
else {
lazy_flat_map_to_ary(result, argv[0]);
}
if (rb_respond_to(result, id_force) && rb_respond_to(result, id_each)) {
lazy_flat_map_each(result, argv[0]);
}
else {
lazy_flat_map_to_ary(result, argv[0]);
}
}
return Qnil;
}
......
lazy_flat_map(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy flat_map without a block");
rb_raise(rb_eArgError, "tried to call lazy flat_map without a block");
}
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_flat_map_func, 0),
Qnil, 0);
lazy_flat_map_func, 0),
Qnil, 0);
}
static VALUE
......
VALUE element = rb_enum_values_pack(argc - 1, argv + 1);
if (RTEST(rb_yield(element))) {
return rb_funcall(argv[0], id_yield, 1, element);
return rb_funcall(argv[0], id_yield, 1, element);
}
return Qnil;
}
......
lazy_select(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy select without a block");
rb_raise(rb_eArgError, "tried to call lazy select without a block");
}
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_select_func, 0),
Qnil, 0);
lazy_select_func, 0),
Qnil, 0);
}
static VALUE
......
VALUE element = rb_enum_values_pack(argc - 1, argv + 1);
if (!RTEST(rb_yield(element))) {
return rb_funcall(argv[0], id_yield, 1, element);
return rb_funcall(argv[0], id_yield, 1, element);
}
return Qnil;
}
......
lazy_reject(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy reject without a block");
rb_raise(rb_eArgError, "tried to call lazy reject without a block");
}
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_reject_func, 0),
Qnil, 0);
lazy_reject_func, 0),
Qnil, 0);
}
static VALUE
......
VALUE result = rb_funcall(m, id_eqq, 1, i);
if (RTEST(result)) {
rb_funcall(argv[0], id_yield, 1, i);
rb_funcall(argv[0], id_yield, 1, i);
}
return Qnil;
}
......
VALUE result = rb_funcall(m, id_eqq, 1, i);
if (RTEST(result)) {
rb_funcall(argv[0], id_yield, 1, rb_yield(i));
rb_funcall(argv[0], id_yield, 1, rb_yield(i));
}
return Qnil;
}
......
lazy_grep(VALUE obj, VALUE pattern)
{
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
rb_block_given_p() ?
lazy_grep_iter : lazy_grep_func,
pattern),
rb_ary_new3(1, pattern), 0);
rb_block_given_p() ?
lazy_grep_iter : lazy_grep_func,
pattern),
rb_ary_new3(1, pattern), 0);
}
static VALUE
......
ary = rb_ary_new2(RARRAY_LEN(arrays) + 1);
rb_ary_push(ary, argv[1]);
for (i = 0; i < RARRAY_LEN(arrays); i++) {
rb_ary_push(ary, rb_ary_entry(RARRAY_AREF(arrays, i), count));
rb_ary_push(ary, rb_ary_entry(RARRAY_AREF(arrays, i), count));
}
rb_funcall(yielder, id_yield, 1, ary);
rb_ivar_set(yielder, id_memo, LONG2NUM(++count));
......
yielder = argv[0];
arg = rb_attr_get(yielder, id_memo);
if (NIL_P(arg)) {
arg = rb_ary_new2(RARRAY_LEN(zip_args));
for (i = 0; i < RARRAY_LEN(zip_args); i++) {
rb_ary_push(arg, rb_funcall(RARRAY_AREF(zip_args, i), id_to_enum, 0));
}
rb_ivar_set(yielder, id_memo, arg);
arg = rb_ary_new2(RARRAY_LEN(zip_args));
for (i = 0; i < RARRAY_LEN(zip_args); i++) {
rb_ary_push(arg, rb_funcall(RARRAY_AREF(zip_args, i), id_to_enum, 0));
}
rb_ivar_set(yielder, id_memo, arg);
}
ary = rb_ary_new2(RARRAY_LEN(arg) + 1);
v = Qnil;
if (--argc > 0) {
++argv;
v = argc > 1 ? rb_ary_new_from_values(argc, argv) : *argv;
++argv;
v = argc > 1 ? rb_ary_new_from_values(argc, argv) : *argv;
}
rb_ary_push(ary, v);
for (i = 0; i < RARRAY_LEN(arg); i++) {
v = rb_rescue2(call_next, RARRAY_AREF(arg, i), next_stopped, 0,
rb_eStopIteration, (VALUE)0);
rb_ary_push(ary, v);
v = rb_rescue2(call_next, RARRAY_AREF(arg, i), next_stopped, 0,
rb_eStopIteration, (VALUE)0);
rb_ary_push(ary, v);
}
rb_funcall(yielder, id_yield, 1, ary);
return Qnil;
......
rb_block_call_func *func = lazy_zip_arrays_func;
if (rb_block_given_p()) {
return rb_call_super(argc, argv);
return rb_call_super(argc, argv);
}
ary = rb_ary_new2(argc);
for (i = 0; i < argc; i++) {
v = rb_check_array_type(argv[i]);
if (NIL_P(v)) {
for (; i < argc; i++) {
if (!rb_respond_to(argv[i], id_each)) {
rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)",
rb_obj_classname(argv[i]));
}
}
ary = rb_ary_new4(argc, argv);
func = lazy_zip_func;
break;
}
rb_ary_push(ary, v);
v = rb_check_array_type(argv[i]);
if (NIL_P(v)) {
for (; i < argc; i++) {
if (!rb_respond_to(argv[i], id_each)) {
rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)",
rb_obj_classname(argv[i]));
}
}
ary = rb_ary_new4(argc, argv);
func = lazy_zip_func;
break;
}
rb_ary_push(ary, v);
}
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
func, ary),
ary, lazy_receiver_size);
func, ary),
ary, lazy_receiver_size);
}
static VALUE
......
long remain;
VALUE memo = rb_attr_get(argv[0], id_memo);
if (NIL_P(memo)) {
memo = args;
memo = args;
}
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
if ((remain = NUM2LONG(memo)-1) == 0) {
return Qundef;
return Qundef;
}
else {
rb_ivar_set(argv[0], id_memo, LONG2NUM(remain));
return Qnil;
rb_ivar_set(argv[0], id_memo, LONG2NUM(remain));
return Qnil;
}
}
......
VALUE receiver = lazy_size(lazy);
long len = NUM2LONG(RARRAY_AREF(rb_ivar_get(lazy, id_arguments), 0));
if (NIL_P(receiver) || (FIXNUM_P(receiver) && FIX2LONG(receiver) < len))
return receiver;
return receiver;
return LONG2NUM(len);
}
......
VALUE lazy;
if (len < 0) {
rb_raise(rb_eArgError, "attempt to take negative size");
rb_raise(rb_eArgError, "attempt to take negative size");
}
if (len == 0) {
VALUE len = INT2FIX(0);
lazy = lazy_to_enum_i(obj, sym_cycle, 1, &len, 0);
VALUE len = INT2FIX(0);
lazy = lazy_to_enum_i(obj, sym_cycle, 1, &len, 0);
}
else {
lazy = rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_take_func, n);
lazy = rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_take_func, n);
}
return lazy_set_method(lazy, rb_ary_new3(1, n), lazy_take_size);
}
......
lazy_take_while(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy take_while without a block");
rb_raise(rb_eArgError, "tried to call lazy take_while without a block");
}
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_take_while_func, 0),
Qnil, 0);
lazy_take_while_func, 0),
Qnil, 0);
}
static VALUE
......
long len = NUM2LONG(RARRAY_AREF(rb_ivar_get(lazy, id_arguments), 0));
VALUE receiver = lazy_size(lazy);
if (NIL_P(receiver))
return receiver;
return receiver;
if (FIXNUM_P(receiver)) {
len = FIX2LONG(receiver) - len;
return LONG2FIX(len < 0 ? 0 : len);
len = FIX2LONG(receiver) - len;
return LONG2FIX(len < 0 ? 0 : len);
}
return rb_funcall(receiver, '-', 1, LONG2NUM(len));
}
......
long remain;
VALUE memo = rb_attr_get(argv[0], id_memo);
if (NIL_P(memo)) {
memo = args;
memo = args;
}
if ((remain = NUM2LONG(memo)) == 0) {
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
}
else {
rb_ivar_set(argv[0], id_memo, LONG2NUM(--remain));
rb_ivar_set(argv[0], id_memo, LONG2NUM(--remain));
}
return Qnil;
}
......
long len = NUM2LONG(n);
if (len < 0) {
rb_raise(rb_eArgError, "attempt to drop negative size");
rb_raise(rb_eArgError, "attempt to drop negative size");
}
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_drop_func, n),
rb_ary_new3(1, n), lazy_drop_size);
lazy_drop_func, n),
rb_ary_new3(1, n), lazy_drop_size);
}
static VALUE
......
{
VALUE memo = rb_attr_get(argv[0], id_memo);
if (NIL_P(memo) && !RTEST(rb_yield_values2(argc - 1, &argv[1]))) {
rb_ivar_set(argv[0], id_memo, memo = Qtrue);
rb_ivar_set(argv[0], id_memo, memo = Qtrue);
}
if (memo == Qtrue) {
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
rb_funcall2(argv[0], id_yield, argc - 1, argv + 1);
}
return Qnil;
}
......
lazy_drop_while(VALUE obj)
{
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
}
return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
lazy_drop_while_func, 0),
Qnil, 0);
lazy_drop_while_func, 0),
Qnil, 0);
}
static VALUE
......
rb_define_method(rb_cYielder, "yield", yielder_yield, -2);
rb_define_method(rb_cYielder, "<<", yielder_yield_push, -2);
rb_provide("enumerator.so"); /* for backward compatibility */
rb_provide("enumerator.so"); /* for backward compatibility */
}
#undef rb_intern
    (1-1/1)