static VALUE make_curry_proc(VALUE proc, VALUE passed, VALUE arity) { VALUE args = rb_ary_new3(3, proc, passed, arity); rb_ary_freeze(passed); rb_ary_freeze(args); return rb_proc_new(curry, args); }
static VALUE make_curry_proc(VALUE proc, VALUE passed, VALUE arity) { #if WITH_OBJC VALUE args = rb_ary_new3(3, proc, passed, arity); #else VALUE args = rb_ary_new2(3); RARRAY_PTR(args)[0] = proc; RARRAY_PTR(args)[1] = passed; RARRAY_PTR(args)[2] = arity; RARRAY_LEN(args) = 3; #endif rb_ary_freeze(passed); rb_ary_freeze(args); return rb_proc_new(curry, args); }
static int coverage_peek_result_i(st_data_t key, st_data_t val, st_data_t h) { VALUE path = (VALUE)key; VALUE coverage = (VALUE)val; VALUE coverages = (VALUE)h; coverage = rb_ary_dup(coverage); rb_ary_freeze(coverage); rb_hash_aset(coverages, path, coverage); return ST_CONTINUE; }
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex) { rb_thread_t *th; rb_control_frame_t *cfp; int line; rb_method_entry_t *me = rb_method_entry_make(klass, mid, type, 0, noex); rb_method_definition_t *def = ALLOC(rb_method_definition_t); me->def = def; def->type = type; def->original_id = mid; def->alias_count = 0; switch (type) { case VM_METHOD_TYPE_ISEQ: def->body.iseq = (rb_iseq_t *)opts; break; case VM_METHOD_TYPE_CFUNC: def->body.cfunc = *(rb_method_cfunc_t *)opts; break; case VM_METHOD_TYPE_ATTRSET: case VM_METHOD_TYPE_IVAR: def->body.attr.id = (ID)opts; def->body.attr.location = Qfalse; th = GET_THREAD(); cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp); if (cfp && (line = rb_vm_get_sourceline(cfp))) { VALUE location = rb_ary_new3(2, cfp->iseq->filename, INT2FIX(line)); def->body.attr.location = rb_ary_freeze(location); } break; case VM_METHOD_TYPE_BMETHOD: def->body.proc = (VALUE)opts; break; case VM_METHOD_TYPE_NOTIMPLEMENTED: def->body.cfunc.func = rb_f_notimplement; def->body.cfunc.argc = -1; break; case VM_METHOD_TYPE_OPTIMIZED: def->body.optimize_type = (enum method_optimized_type)opts; break; case VM_METHOD_TYPE_ZSUPER: case VM_METHOD_TYPE_UNDEF: break; default: rb_bug("rb_add_method: unsupported method type (%d)\n", type); } if (type != VM_METHOD_TYPE_UNDEF) { method_added(klass, mid); } return me; }
static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv) { VALUE proc, passed, arity; proc = RARRAY_AT(args, 0); passed = RARRAY_AT(args, 1); arity = RARRAY_AT(args, 2); passed = rb_ary_plus(passed, rb_ary_new4(argc, argv)); rb_ary_freeze(passed); if(RARRAY_LEN(passed) < FIX2INT(arity)) { arity = make_curry_proc(proc, passed, arity); return arity; } arity = rb_proc_call(proc, passed); return arity; }
static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc) { VALUE proc, passed, arity; proc = RARRAY_PTR(args)[0]; passed = RARRAY_PTR(args)[1]; arity = RARRAY_PTR(args)[2]; passed = rb_ary_plus(passed, rb_ary_new4(argc, argv)); rb_ary_freeze(passed); if(RARRAY_LEN(passed) < FIX2INT(arity)) { if (!NIL_P(passed_proc)) { rb_warn("given block not used"); } arity = make_curry_proc(proc, passed, arity); return arity; } else { return rb_proc_call_with_block(proc, RARRAY_LEN(passed), RARRAY_PTR(passed), passed_proc); } }
static VALUE array_spec_rb_ary_freeze(VALUE self, VALUE ary) { return rb_ary_freeze(ary); }
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex) { rb_thread_t *th; rb_control_frame_t *cfp; int line; rb_method_entry_t *me = rb_method_entry_make(klass, mid, type, 0, noex, klass); rb_method_definition_t *def = ALLOC(rb_method_definition_t); if (me->def && me->def->type == VM_METHOD_TYPE_REFINED) { me->def->body.orig_me->def = def; } else { me->def = def; } def->type = type; def->original_id = mid; def->alias_count = 0; switch (type) { case VM_METHOD_TYPE_ISEQ: { rb_iseq_t *iseq = (rb_iseq_t *)opts; *(rb_iseq_t **)&def->body.iseq = iseq; RB_OBJ_WRITTEN(klass, Qundef, iseq->self); break; } case VM_METHOD_TYPE_CFUNC: { rb_method_cfunc_t *cfunc = (rb_method_cfunc_t *)opts; setup_method_cfunc_struct(&def->body.cfunc, cfunc->func, cfunc->argc); } break; case VM_METHOD_TYPE_ATTRSET: case VM_METHOD_TYPE_IVAR: def->body.attr.id = (ID)(VALUE)opts; RB_OBJ_WRITE(klass, &def->body.attr.location, Qfalse); th = GET_THREAD(); cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp); if (cfp && (line = rb_vm_get_sourceline(cfp))) { VALUE location = rb_ary_new3(2, cfp->iseq->location.path, INT2FIX(line)); RB_OBJ_WRITE(klass, &def->body.attr.location, rb_ary_freeze(location)); } break; case VM_METHOD_TYPE_BMETHOD: RB_OBJ_WRITE(klass, &def->body.proc, (VALUE)opts); break; case VM_METHOD_TYPE_NOTIMPLEMENTED: setup_method_cfunc_struct(&def->body.cfunc, rb_f_notimplement, -1); break; case VM_METHOD_TYPE_OPTIMIZED: def->body.optimize_type = (enum method_optimized_type)opts; break; case VM_METHOD_TYPE_ZSUPER: case VM_METHOD_TYPE_UNDEF: break; case VM_METHOD_TYPE_REFINED: def->body.orig_me = (rb_method_entry_t *) opts; break; default: rb_bug("rb_add_method: unsupported method type (%d)\n", type); } if (type != VM_METHOD_TYPE_UNDEF && type != VM_METHOD_TYPE_REFINED) { method_added(klass, mid); } return me; }