25 static int vm_collect_local_variables_in_heap(
const VALUE *dfp,
const struct local_var_list *vars);
27 static VALUE rb_eUncaughtThrow;
28 static ID id_result, id_tag, id_value;
29 #define id_mesg idMesg
31 typedef enum call_type {
40 static VALUE send_internal(
int argc,
const VALUE *argv,
VALUE recv, call_type scope);
45 MJIT_FUNC_EXPORTED
VALUE
49 .ci = &VM_CI_ON_STACK(
id, kw_splat ? VM_CALL_KW_SPLAT : 0, argc, NULL),
50 .cc = &VM_CC_ON_STACK(
Qfalse, vm_call_general, { 0 }, cme),
51 .block_handler = vm_passed_block_handler(ec),
57 return vm_call0_body(ec, &calling, argv);
60 MJIT_FUNC_EXPORTED
VALUE
64 rb_callable_method_entry_with_refinements(
CLASS_OF(recv),
id, NULL);
66 return rb_vm_call0(ec, recv,
id, argc, argv, me, kw_splat);
78 .ci = &VM_CI_ON_STACK(
id, kw_splat ? VM_CALL_KW_SPLAT : 0, argc, NULL),
80 .block_handler = vm_passed_block_handler(ec),
86 return vm_call0_body(ec, &calling, argv);
92 calling->cc = &VM_CC_ON_STACK(
Qfalse, vm_call_general, { 0 }, cme);
93 return vm_call0_body(ec, calling, argv);
99 ID mid = vm_ci_mid(calling->ci);
106 RUBY_VM_CHECK_INTS(ec);
107 return vm_call0_cme(ec, calling, argv, cme);
111 vm_passed_block_handler_set(ec, calling->block_handler);
112 return method_missing(ec, calling->recv, mid, calling->argc, argv, ex, calling->kw_splat);
122 int len = cfunc->argc;
123 VALUE recv = calling->recv;
124 int argc = calling->argc;
125 ID mid = vm_ci_mid(ci);
126 VALUE block_handler = calling->block_handler;
127 int frame_flags = VM_FRAME_MAGIC_CFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL;
129 if (calling->kw_splat) {
134 frame_flags |= VM_FRAME_FLAG_CFRAME_KW;
138 RUBY_DTRACE_CMETHOD_ENTRY_HOOK(ec, me->owner, me->def->original_id);
143 vm_push_frame(ec, 0, frame_flags, recv,
144 block_handler, (
VALUE)me,
145 0, reg_cfp->sp, 0, 0);
149 val = (*cfunc->invoker)(recv, argc, argv, cfunc->func);
151 CHECK_CFP_CONSISTENCY(
"vm_call0_cfunc_with_frame");
155 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
163 return vm_call0_cfunc_with_frame(ec, calling, argv);
169 if (calling->kw_splat &&
189 switch (vm_cc_cme(cc)->def->type) {
190 case VM_METHOD_TYPE_ISEQ:
195 CHECK_VM_STACK_OVERFLOW(reg_cfp, calling->argc + 1);
196 vm_check_canary(ec, reg_cfp->sp);
198 *reg_cfp->sp++ = calling->recv;
199 for (i = 0; i < calling->argc; i++) {
200 *reg_cfp->sp++ = argv[i];
203 vm_call_iseq_setup(ec, reg_cfp, calling);
204 VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);
205 return vm_exec(ec,
true);
207 case VM_METHOD_TYPE_NOTIMPLEMENTED:
208 case VM_METHOD_TYPE_CFUNC:
209 ret = vm_call0_cfunc(ec, calling, argv);
211 case VM_METHOD_TYPE_ATTRSET:
212 vm_call_check_arity(calling, 1, argv);
213 VM_CALL_METHOD_ATTR(ret,
214 rb_ivar_set(calling->recv, vm_cc_cme(cc)->def->body.attr.id, argv[0]),
217 case VM_METHOD_TYPE_IVAR:
218 vm_call_check_arity(calling, 0, argv);
219 VM_CALL_METHOD_ATTR(ret,
220 rb_attr_get(calling->recv, vm_cc_cme(cc)->def->body.attr.id),
223 case VM_METHOD_TYPE_BMETHOD:
224 ret = vm_call_bmethod_body(ec, calling, argv);
226 case VM_METHOD_TYPE_ZSUPER:
228 VALUE klass = RCLASS_ORIGIN(vm_cc_cme(cc)->defined_class);
229 return vm_call0_super(ec, calling, argv, klass, MISSING_SUPER);
231 case VM_METHOD_TYPE_REFINED:
235 if (cme->def->body.refined.orig_me) {
237 return vm_call0_cme(ec, calling, argv, orig_cme);
240 VALUE klass = cme->defined_class;
241 return vm_call0_super(ec, calling, argv, klass, 0);
243 case VM_METHOD_TYPE_ALIAS:
248 if (cme == orig_cme)
rb_bug(
"same!!");
250 if (vm_cc_markable(cc)) {
251 return vm_call0_cme(ec, calling, argv, orig_cme);
258 case VM_METHOD_TYPE_MISSING:
260 vm_passed_block_handler_set(ec, calling->block_handler);
261 return method_missing(ec, calling->recv, vm_ci_mid(ci), calling->argc,
262 argv, MISSING_NOENTRY, calling->kw_splat);
264 case VM_METHOD_TYPE_OPTIMIZED:
265 switch (vm_cc_cme(cc)->def->body.optimized.type) {
266 case OPTIMIZED_METHOD_TYPE_SEND:
267 ret = send_internal(calling->argc, argv, calling->recv, calling->kw_splat ? CALL_FCALL_KW : CALL_FCALL);
269 case OPTIMIZED_METHOD_TYPE_CALL:
272 GetProcPtr(calling->recv, proc);
273 ret = rb_vm_invoke_proc(ec, proc, calling->argc, argv, calling->kw_splat, calling->block_handler);
276 case OPTIMIZED_METHOD_TYPE_STRUCT_AREF:
277 vm_call_check_arity(calling, 0, argv);
278 ret = vm_call_opt_struct_aref0(ec, calling);
280 case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
281 vm_call_check_arity(calling, 1, argv);
282 ret = vm_call_opt_struct_aset0(ec, calling, argv[0]);
285 rb_bug(
"vm_call0: unsupported optimized method type (%d)", vm_cc_cme(cc)->def->body.optimized.type);
288 case VM_METHOD_TYPE_UNDEF:
291 rb_bug(
"vm_call0: unsupported method type (%d)", vm_cc_cme(cc)->def->type);
295 RUBY_VM_CHECK_INTS(ec);
299 MJIT_FUNC_EXPORTED
VALUE
302 return rb_vm_call0(ec, recv,
id, argc, argv, me, kw_splat);
308 VALUE recv = ec->cfp->self;
314 if (VM_FRAME_RUBYFRAME_P(cfp)) {
315 rb_bug(
"vm_call_super: should not be reached");
318 klass = RCLASS_ORIGIN(me->defined_class);
320 id = me->def->original_id;
321 me = rb_callable_method_entry(klass,
id);
324 return method_missing(ec, recv,
id, argc, argv, MISSING_SUPER, kw_splat);
326 return rb_vm_call_kw(ec, recv,
id, argc, argv, me, kw_splat);
333 PASS_PASSED_BLOCK_HANDLER_EC(ec);
334 return vm_call_super(ec, argc, argv, kw_splat);
348 if (!ec || !(cfp = ec->cfp)) {
359 if (!rb_ec_raised_p(ec, RAISED_STACKOVERFLOW) &&
360 rb_ec_stack_check(ec)) {
361 rb_ec_raised_set(ec, RAISED_STACKOVERFLOW);
362 rb_ec_stack_overflow(ec, FALSE);
369 rb_check_stack_overflow(
void)
371 #ifndef RB_THREAD_LOCAL_SPECIFIER
372 if (!ruby_current_ec_key)
return;
375 if (ec) stack_check(ec);
378 NORETURN(
static void uncallable_object(
VALUE recv,
ID mid));
393 if (rb_id_table_lookup(cc_tbl, mid, &ccs_data)) {
398 ccs = vm_ccs_create(klass, cme);
399 rb_id_table_insert(cc_tbl, mid, (
VALUE)ccs);
402 for (
int i=0; i<ccs->len; i++) {
403 cc = ccs->entries[i].cc;
404 if (vm_cc_cme(cc) == cme) {
411 const struct rb_callinfo *ci = vm_ci_new(mid, 0, argc,
false);
412 cc = vm_cc_new(klass, cme, vm_call_general);
414 vm_ccs_push(klass, ccs, ci, cc);
423 gccct_hash(
VALUE klass,
ID mid)
425 return (klass >> 3) ^ (
VALUE)mid;
428 NOINLINE(
static const struct rb_callcache *gccct_method_search_slowpath(
rb_vm_t *vm,
VALUE klass,
ID mid,
int argc,
unsigned int index));
431 gccct_method_search_slowpath(
rb_vm_t *vm,
VALUE klass,
ID mid,
int argc,
unsigned int index)
437 cc = cc_new(klass, mid, argc, cme);
443 return vm->global_cc_cache_table[index] = cc;
453 if (UNLIKELY(!klass)) uncallable_object(recv, mid);
460 unsigned int index = (
unsigned int)(gccct_hash(klass, mid) % VM_GLOBAL_CC_CACHE_TABLE_SIZE);
461 rb_vm_t *vm = rb_ec_vm_ptr(ec);
462 const struct rb_callcache *cc = vm->global_cc_cache_table[index];
465 if (LIKELY(vm_cc_class_check(cc, klass))) {
467 if (LIKELY(!METHOD_ENTRY_INVALIDATED(cme) &&
468 cme->called_id == mid)) {
470 VM_ASSERT(vm_cc_check_cme(cc, rb_callable_method_entry(klass, mid)));
471 RB_DEBUG_COUNTER_INC(gccct_hit);
478 RB_DEBUG_COUNTER_INC(gccct_null);
481 RB_DEBUG_COUNTER_INC(gccct_miss);
482 return gccct_method_search_slowpath(vm, klass, mid, argc, index);
504 call_type call_scope,
VALUE self)
506 enum method_missing_reason call_status;
507 call_type scope = call_scope;
523 const struct rb_callcache *cc = gccct_method_search(ec, recv, mid, argc);
525 if (scope == CALL_PUBLIC) {
526 RB_DEBUG_COUNTER_INC(call0_public);
530 call_status = rb_method_call_status(ec, cme, scope,
self);
532 if (UNLIKELY(call_status != MISSING_NONE)) {
533 return method_missing(ec, recv, mid, argc, argv, call_status, kw_splat);
535 else if (UNLIKELY(cc_cme != cme)) {
537 return rb_vm_call_kw(ec, recv, mid, argc, argv, cme, kw_splat);
541 RB_DEBUG_COUNTER_INC(call0_other);
542 call_status = rb_method_call_status(ec, cc ? vm_cc_cme(cc) : NULL, scope,
self);
544 if (UNLIKELY(call_status != MISSING_NONE)) {
545 return method_missing(ec, recv, mid, argc, argv, call_status, kw_splat);
550 return vm_call0_cc(ec, recv, mid, argc, argv, cc, kw_splat);
559 unsigned int respond: 1;
560 unsigned int respond_to_missing: 1;
567 check_funcall_exec(
VALUE v)
570 return call_method_entry(args->ec, args->defined_class,
571 args->recv, idMethodMissing,
572 args->cme, args->argc, args->argv, args->kw_splat);
579 int ret = args->respond;
581 switch (method_boundp(args->defined_class, args->mid,
582 BOUND_PRIVATE|BOUND_RESPONDS)) {
587 ret = args->respond_to_missing;
603 return vm_respond_to(ec, klass, recv, mid, TRUE);
609 return rb_method_call_status(ec, me, CALL_FCALL, ec->cfp->self) == MISSING_NONE;
619 ret = basic_obj_respond_to_missing(ec, klass, recv,
621 if (!
RTEST(ret))
return def;
622 args.respond = respond > 0;
623 args.respond_to_missing = (ret !=
Qundef);
625 cme = callable_method_entry(klass, idMethodMissing, &args.defined_class);
627 if (cme && !METHOD_ENTRY_BASIC(cme)) {
630 new_args[0] =
ID2SYM(mid);
634 VM_ASSERT(argc == 0);
639 ec->method_missing_reason = MISSING_NOENTRY;
644 args.argc = argc + 1;
645 args.argv = new_args;
646 args.kw_splat = kw_splat;
648 check_funcall_failed, (
VALUE)&args,
655 static VALUE rb_check_funcall_default_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def,
int kw_splat);
660 return rb_check_funcall_default_kw(recv, mid, argc, argv,
Qundef, kw_splat);
670 rb_check_funcall_default_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def,
int kw_splat)
672 VM_ASSERT(ruby_thread_has_gvl_p());
677 int respond = check_funcall_respond_to(ec, klass, recv, mid);
682 me = rb_search_method_entry(recv, mid);
683 if (!check_funcall_callable(ec, me)) {
684 VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
685 respond, def, kw_splat);
686 if (ret ==
Qundef) ret = def;
690 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
694 rb_check_funcall_default(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def)
696 return rb_check_funcall_default_kw(recv, mid, argc, argv, def,
RB_NO_KEYWORDS);
700 rb_check_funcall_with_hook_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
701 rb_check_funcall_hook *hook,
VALUE arg,
int kw_splat)
706 int respond = check_funcall_respond_to(ec, klass, recv, mid);
709 (*hook)(FALSE, recv, mid, argc, argv, arg);
713 me = rb_search_method_entry(recv, mid);
714 if (!check_funcall_callable(ec, me)) {
715 VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
716 respond,
Qundef, kw_splat);
717 (*hook)(ret !=
Qundef, recv, mid, argc, argv, arg);
721 (*hook)(TRUE, recv, mid, argc, argv, arg);
722 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
726 rb_check_funcall_with_hook(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
727 rb_check_funcall_hook *hook,
VALUE arg)
729 return rb_check_funcall_with_hook_kw(recv, mid, argc, argv, hook, arg,
RB_NO_KEYWORDS);
735 #define type_case(t) t: return #t
753 case type_case(
T_NIL);
771 uncallable_object(
VALUE recv,
ID mid)
780 "method `%"PRIsVALUE
"' called on unexpected immediate object (%p)",
781 mname, (
void *)recv);
783 else if ((flags =
RBASIC(recv)->flags) == 0) {
785 "method `%"PRIsVALUE
"' called on terminated object (%p)",
786 mname, (
void *)recv);
790 "method `%"PRIsVALUE
"' called on broken T_?""?""?(0x%02x) object"
791 " (%p flags=0x%"PRIxVALUE
")",
792 mname,
type, (
void *)recv, flags);
796 "method `%"PRIsVALUE
"' called on hidden %s object"
797 " (%p flags=0x%"PRIxVALUE
")",
798 mname, typestr, (
void *)recv, flags);
802 "method `%"PRIsVALUE
"' called on unexpected %s object"
803 " (%p flags=0x%"PRIxVALUE
")",
804 mname, typestr, (
void *)recv, flags);
809 rb_search_method_entry(
VALUE recv,
ID mid)
813 if (!klass) uncallable_object(recv, mid);
814 return rb_callable_method_entry(klass, mid);
817 static inline enum method_missing_reason
820 if (UNLIKELY(UNDEFINED_METHOD_ENTRY_P(me))) {
823 else if (UNLIKELY(me->def->type == VM_METHOD_TYPE_REFINED)) {
824 me = rb_resolve_refined_method_callable(
Qnil, me);
825 if (UNDEFINED_METHOD_ENTRY_P(me))
goto undefined;
828 rb_method_visibility_t visi = METHOD_ENTRY_VISI(me);
831 if (UNLIKELY(visi != METHOD_VISI_PUBLIC)) {
832 if (me->def->original_id == idMethodMissing) {
835 else if (visi == METHOD_VISI_PRIVATE &&
836 scope == CALL_PUBLIC) {
837 return MISSING_PRIVATE;
840 else if (visi == METHOD_VISI_PROTECTED &&
841 scope == CALL_PUBLIC) {
843 VALUE defined_class = me->owner;
845 defined_class =
RBASIC(defined_class)->klass;
849 return MISSING_PROTECTED;
857 return scope == CALL_VCALL ? MISSING_VCALL : MISSING_NOENTRY;
873 rb_call(
VALUE recv,
ID mid,
int argc,
const VALUE *argv, call_type scope)
876 return rb_call0(ec, recv, mid, argc, argv, scope, ec->cfp->self);
880 VALUE obj,
enum method_missing_reason call_status));
922 rb_method_missing(
int argc,
const VALUE *argv,
VALUE obj)
925 raise_method_missing(ec, argc, argv, obj, ec->method_missing_reason);
929 MJIT_FUNC_EXPORTED
VALUE
931 int argc,
const VALUE *argv,
int priv)
933 VALUE name = argv[0];
936 format = rb_fstring_lit(
"undefined method `%s' for %s%s%s");
940 return rb_nomethod_err_new(format, obj, name, args, priv);
943 return rb_name_err_new(format, obj, name);
951 enum method_missing_reason last_call_status)
956 if (UNLIKELY(argc == 0)) {
959 else if (UNLIKELY(!
SYMBOL_P(argv[0]))) {
961 rb_raise(e,
"method name must be a Symbol but %"PRIsVALUE
" is given",
967 if (last_call_status & MISSING_PRIVATE) {
968 format = rb_fstring_lit(
"private method `%s' called for %s%s%s");
970 else if (last_call_status & MISSING_PROTECTED) {
971 format = rb_fstring_lit(
"protected method `%s' called for %s%s%s");
973 else if (last_call_status & MISSING_VCALL) {
974 format = rb_fstring_lit(
"undefined local variable or method `%s' for %s%s%s");
977 else if (last_call_status & MISSING_SUPER) {
978 format = rb_fstring_lit(
"super: no superclass method `%s' for %s%s%s");
982 exc = rb_make_no_method_exception(exc, format, obj, argc, argv,
983 last_call_status & (MISSING_FCALL|MISSING_VCALL));
984 if (!(last_call_status & MISSING_MISSING)) {
985 rb_vm_pop_cfunc_frame();
993 VALUE obj,
int call_status)
995 vm_passed_block_handler_set(ec, VM_BLOCK_HANDLER_NONE);
996 raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
1002 VALUE *nargv, result, work, klass;
1003 VALUE block_handler = vm_passed_block_handler(ec);
1006 ec->method_missing_reason = call_status;
1008 if (
id == idMethodMissing) {
1017 VM_ASSERT(argc == 0);
1026 if (!klass)
goto missing;
1027 me = rb_callable_method_entry(klass, idMethodMissing);
1028 if (!me || METHOD_ENTRY_BASIC(me))
goto missing;
1029 vm_passed_block_handler_set(ec, block_handler);
1030 result = rb_vm_call_kw(ec, obj, idMethodMissing, argc, argv, me, kw_splat);
1034 raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
1041 rb_funcallv_scope(
VALUE recv,
ID mid,
int argc,
const VALUE *argv, call_type scope)
1044 const struct rb_callcache *cc = gccct_method_search(ec, recv, mid, argc);
1045 VALUE self = ec->cfp->self;
1048 LIKELY(rb_method_call_status(ec, vm_cc_cme(cc), scope,
self) == MISSING_NONE)) {
1050 return vm_call0_cc(ec, recv, mid, argc, argv, cc,
false);
1053 return rb_call0(ec, recv, mid, argc, argv, scope,
self);
1063 VM_ASSERT(ruby_thread_has_gvl_p());
1065 return rb_funcallv_scope(recv, mid, argc, argv, CALL_FCALL);
1071 VM_ASSERT(ruby_thread_has_gvl_p());
1073 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_FCALL_KW : CALL_FCALL);
1083 if (argc >= 0x100) {
1085 RBASIC_CLEAR_CLASS(args);
1114 for (i = 0; i < n; i++) {
1115 argv[i] = va_arg(ar,
VALUE);
1136 rb_check_funcall_basic_kw(
VALUE recv,
ID mid,
VALUE ancestor,
int argc,
const VALUE *argv,
int kw_splat)
1141 if (!klass)
return Qundef;
1143 cme = rb_callable_method_entry(klass, mid);
1144 if (cme && METHOD_ENTRY_BASIC(cme) &&
RBASIC_CLASS(cme->defined_class) == ancestor) {
1146 return rb_vm_call0(ec, recv, mid, argc, argv, cme, kw_splat);
1155 return rb_funcallv_scope(recv, mid, argc, argv, CALL_PUBLIC);
1161 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1167 PASS_PASSED_BLOCK_HANDLER();
1174 PASS_PASSED_BLOCK_HANDLER();
1175 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1181 if (!
NIL_P(passed_procval)) {
1182 vm_passed_block_handler_set(GET_EC(), passed_procval);
1191 if (!
NIL_P(passed_procval)) {
1192 vm_passed_block_handler_set(GET_EC(), passed_procval);
1195 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1202 if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, prev_cfp))
return NULL;
1203 if (prev_cfp->sp + 1 != argv)
return NULL;
1204 return prev_cfp->sp + 1;
1208 send_internal(
int argc,
const VALUE *argv,
VALUE recv, call_type scope)
1213 VALUE ret, vargv = 0;
1215 int public = scope == CALL_PUBLIC || scope == CALL_PUBLIC_KW;
1221 self = RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp)->self;
1239 VALUE *tmp_argv = current_vm_stack_arg(ec, argv);
1244 else if (argc > 1) {
1254 id = idMethodMissing;
1255 ec->method_missing_reason = MISSING_NOENTRY;
1260 PASS_PASSED_BLOCK_HANDLER_EC(ec);
1261 ret = rb_call0(ec, recv,
id, argc, argv, scope,
self);
1267 send_internal_kw(
int argc,
const VALUE *argv,
VALUE recv, call_type scope)
1272 scope = CALL_PUBLIC_KW;
1275 scope = CALL_FCALL_KW;
1281 return send_internal(argc, argv, recv, scope);
1313 return send_internal_kw(argc, argv, recv, CALL_FCALL);
1331 rb_f_public_send(
int argc,
VALUE *argv,
VALUE recv)
1333 return send_internal_kw(argc, argv, recv, CALL_PUBLIC);
1339 rb_yield_0_kw(
int argc,
const VALUE * argv,
int kw_splat)
1341 return vm_yield(GET_EC(), argc, argv, kw_splat);
1345 rb_yield_0(
int argc,
const VALUE * argv)
1351 rb_yield_1(
VALUE val)
1353 return rb_yield_0(1, &val);
1360 return rb_yield_0(0, NULL);
1363 return rb_yield_0(1, &val);
1367 #undef rb_yield_values
1372 return rb_yield_0(0, 0);
1381 for (i=0; i<n; i++) {
1382 argv[i] = va_arg(args,
VALUE);
1386 return rb_yield_0(n, argv);
1393 return rb_yield_0(argc, argv);
1399 return rb_yield_0_kw(argc, argv, kw_splat);
1429 rb_yield_force_blockarg(
VALUE values)
1431 return vm_yield_force_blockarg(GET_EC(), values);
1437 return vm_yield_with_block(GET_EC(), argc, argv,
1438 NIL_P(blockarg) ? VM_BLOCK_HANDLER_NONE : blockarg,
1494 rb_f_loop(
VALUE self)
1507 const struct vm_ifunc *
const ifunc,
1510 enum ruby_tag_type state;
1515 state = EC_EXEC_TAG();
1519 VALUE block_handler;
1523 captured->code.ifunc = ifunc;
1524 block_handler = VM_BH_FROM_IFUNC_BLOCK(captured);
1527 block_handler = VM_CF_BLOCK_HANDLER(cfp);
1529 vm_passed_block_handler_set(ec, block_handler);
1531 retval = (*it_proc) (data1);
1533 else if (state == TAG_BREAK || state == TAG_RETRY) {
1537 if (cfp == escape_cfp) {
1538 rb_vm_rewind_cfp(ec, cfp);
1541 ec->tag->state = TAG_NONE;
1544 if (state == TAG_RETRY)
goto iter_retry;
1545 retval = THROW_DATA_VAL(err);
1548 SDR(); fprintf(stderr,
"%p, %p\n", (
void *)cfp, (
void *)escape_cfp);
1554 EC_JUMP_TAG(ec, state);
1563 return rb_iterate0(it_proc, data1,
1564 bl_proc ? rb_vm_ifunc_proc_new(bl_proc, (
void *)data2) : 0,
1572 return rb_iterate_internal(it_proc, data1, bl_proc, data2);
1584 iterate_method(
VALUE obj)
1589 return rb_call(arg->obj, arg->mid, arg->argc, arg->argv, arg->kw_splat ? CALL_FCALL_KW : CALL_FCALL);
1611 arg.kw_splat = kw_splat;
1612 return rb_iterate_internal(iterate_method, (
VALUE)&arg, bl_proc, data2);
1616 rb_lambda_call(
VALUE obj,
ID mid,
int argc,
const VALUE *argv,
1629 block = rb_vm_ifunc_new(bl_proc, (
void *)data2, min_argc, max_argc);
1630 return rb_iterate0(iterate_method, (
VALUE)&arg, block, GET_EC());
1634 iterate_check_method(
VALUE obj)
1643 rb_check_block_call(
VALUE obj,
ID mid,
int argc,
const VALUE *argv,
1653 return rb_iterate_internal(iterate_check_method, (
VALUE)&arg, bl_proc, data2);
1659 return rb_call(obj, idEach, 0, 0, CALL_FCALL);
1662 void rb_parser_warn_location(
VALUE,
int);
1664 static VALUE eval_default_path;
1670 const VALUE parser = rb_parser_new();
1671 const rb_iseq_t *
const parent = vm_block_iseq(base_block);
1674 int isolated_depth = 0;
1677 const VALUE *ep = vm_block_ep(base_block);
1680 if (VM_ENV_FLAGS(ep, VM_ENV_FLAG_ISOLATED)) {
1681 isolated_depth = depth;
1684 else if (VM_ENV_LOCAL_P(ep)) {
1687 ep = VM_ENV_PREV_EP(ep);
1693 fname = rb_source_location(&line);
1697 if (!
NIL_P(fname)) fname = rb_fstring(fname);
1700 fname = rb_fstring_lit(
"(eval)");
1701 if (!eval_default_path) {
1702 eval_default_path = rb_fstring_lit(
"(eval)");
1705 fname = eval_default_path;
1708 rb_parser_set_context(parser, parent, FALSE);
1709 ast = rb_parser_compile_string_path(parser, fname, src, line);
1710 if (ast->body.root) {
1711 iseq = rb_iseq_new_eval(&ast->body,
1712 parent->body->location.label,
1714 parent, isolated_depth);
1716 rb_ast_dispose(ast);
1720 VALUE disasm = rb_iseq_disasm(iseq);
1724 rb_exec_event_hook_script_compiled(GET_EC(), iseq, src);
1741 block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(cfp);
1742 block.as.captured.self =
self;
1743 block.as.captured.code.iseq = cfp->iseq;
1744 block.type = block_type_iseq;
1746 iseq = eval_make_iseq(src, file, line, NULL, &block);
1752 if (!cref && block.as.captured.code.val) {
1753 rb_cref_t *orig_cref = vm_get_cref(vm_block_ep(&block));
1754 cref = vm_cref_dup(orig_cref);
1756 vm_set_eval_stack(ec, iseq, cref, &block);
1759 return vm_exec(ec,
true);
1767 const rb_iseq_t *iseq = eval_make_iseq(src, file, line, bind, &bind->block);
1772 vm_set_eval_stack(ec, iseq, NULL, &bind->block);
1775 if (iseq->body->local_table_size > 0) {
1776 vm_bind_update_env(scope, bind, vm_make_env_object(ec, ec->cfp));
1780 return vm_exec(ec,
true);
1802 rb_f_eval(
int argc,
const VALUE *argv,
VALUE self)
1804 VALUE src, scope, vfile, vline;
1808 rb_scan_args(argc, argv,
"13", &src, &scope, &vfile, &vline);
1821 return eval_string_with_cref(
self, src, NULL, file, line);
1823 return eval_string_with_scope(scope, src, file, line);
1828 ruby_eval_string_from_file(
const char *str,
const char *filename)
1831 return eval_string_with_cref(rb_vm_top_self(),
rb_str_new2(str), NULL, file, 1);
1837 return ruby_eval_string_from_file(str,
"eval");
1841 eval_string_protect(
VALUE str)
1859 eval_string_wrap_protect(
VALUE data)
1862 rb_cref_t *cref = rb_vm_cref_new_toplevel();
1863 cref->klass_or_self = arg->klass;
1872 VALUE self = th->top_self;
1873 VALUE wrapper = th->top_wrapper;
1881 data.top_self = th->top_self;
1882 data.klass = th->top_wrapper;
1887 th->top_self =
self;
1888 th->top_wrapper = wrapper;
1893 else if (state != TAG_NONE) {
1894 EC_JUMP_TAG(th->ec, state);
1902 enum ruby_tag_type state;
1907 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1913 val = eval_string_with_cref(rb_vm_top_self(), cmd, NULL, 0, 0);
1918 if (state) EC_JUMP_TAG(ec, state);
1925 yield_under(
VALUE self,
int singleton,
int argc,
const VALUE *argv,
int kw_splat)
1929 VALUE block_handler = VM_CF_BLOCK_HANDLER(cfp);
1930 VALUE new_block_handler = 0;
1933 const VALUE *ep = NULL;
1935 int is_lambda = FALSE;
1937 if (block_handler != VM_BLOCK_HANDLER_NONE) {
1939 switch (vm_block_handler_type(block_handler)) {
1940 case block_handler_type_iseq:
1941 captured = VM_BH_TO_CAPT_BLOCK(block_handler);
1942 new_captured = *captured;
1943 new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
1945 case block_handler_type_ifunc:
1946 captured = VM_BH_TO_CAPT_BLOCK(block_handler);
1947 new_captured = *captured;
1948 new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
1950 case block_handler_type_proc:
1952 block_handler = vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler));
1954 case block_handler_type_symbol:
1955 return rb_sym_proc_call(
SYM2ID(VM_BH_TO_SYMBOL(block_handler)),
1956 argc, argv, kw_splat,
1957 VM_BLOCK_HANDLER_NONE);
1960 new_captured.self =
self;
1963 VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
1967 cref = vm_cref_push(ec,
self, ep, TRUE, singleton);
1969 return vm_yield_with_cref(ec, argc, argv, kw_splat, cref, is_lambda);
1973 rb_yield_refine_block(
VALUE refinement,
VALUE refinements)
1976 VALUE block_handler = VM_CF_BLOCK_HANDLER(ec->cfp);
1978 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1979 rb_bug(
"rb_yield_refine_block: an iseq block is required");
1984 VALUE new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
1985 const VALUE *ep = captured->ep;
1986 rb_cref_t *cref = vm_cref_push(ec, refinement, ep, TRUE, FALSE);
1987 CREF_REFINEMENTS_SET(cref, refinements);
1988 VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
1989 new_captured.self = refinement;
1990 return vm_yield_with_cref(ec, 0, NULL,
RB_NO_KEYWORDS, cref, FALSE);
1996 eval_under(
VALUE self,
int singleton,
VALUE src,
VALUE file,
int line)
1998 rb_cref_t *cref = vm_cref_push(GET_EC(),
self, NULL, FALSE, singleton);
2001 return eval_string_with_cref(
self, src, cref, file, line);
2005 specific_eval(
int argc,
const VALUE *argv,
VALUE self,
int singleton,
int kw_splat)
2009 return yield_under(
self, singleton, 1, &
self, kw_splat);
2025 return eval_under(
self, singleton, code, file, line);
2063 rb_obj_instance_eval_internal(
int argc,
const VALUE *argv,
VALUE self)
2093 rb_obj_instance_exec_internal(
int argc,
const VALUE *argv,
VALUE self)
2132 rb_mod_module_eval_internal(
int argc,
const VALUE *argv,
VALUE mod)
2166 rb_mod_module_exec_internal(
int argc,
const VALUE *argv,
VALUE mod)
2191 uncaught_throw_init(
int argc,
const VALUE *argv,
VALUE exc)
2208 uncaught_throw_tag(
VALUE exc)
2221 uncaught_throw_value(
VALUE exc)
2234 uncaught_throw_to_s(
VALUE exc)
2237 VALUE tag = uncaught_throw_tag(exc);
2270 if (tt->tag == tag) {
2284 ec->errinfo = (
VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW);
2285 EC_JUMP_TAG(ec, TAG_THROW);
2297 return rb_yield_0(1, &tag);
2352 rb_f_catch(
int argc,
VALUE *argv,
VALUE self)
2369 enum ruby_tag_type state;
2377 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
2379 val = (*func)(tag, data, 1, (
const VALUE *)&tag,
Qnil);
2381 else if (state == TAG_THROW && THROW_DATA_VAL((
struct vm_throw_data *)ec->errinfo) == tag) {
2382 rb_vm_rewind_cfp(ec, saved_cfp);
2383 val = ec->tag->retval;
2397 return vm_catch_protect(t, func, data, stateptr, GET_EC());
2403 enum ruby_tag_type state;
2406 if (state) EC_JUMP_TAG(ec, state);
2413 vars->tbl = rb_ident_hash_new();
2414 RBASIC_CLEAR_CLASS(vars->tbl);
2421 VALUE ary = rb_hash_keys(vars->tbl);
2428 local_var_list_update(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
2430 if (existing)
return ST_STOP;
2431 *value = (st_data_t)
Qtrue;
2441 rb_hash_stlike_update(vars->tbl,
ID2SYM(lid), local_var_list_update, idx);
2459 rb_f_local_variables(
VALUE _)
2463 rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp));
2466 local_var_list_init(&vars);
2469 for (i = 0; i < cfp->iseq->body->local_table_size; i++) {
2470 local_var_list_add(&vars, cfp->iseq->body->local_table[i]);
2473 if (!VM_ENV_LOCAL_P(cfp->ep)) {
2475 const VALUE *ep = VM_CF_PREV_EP(cfp);
2477 if (vm_collect_local_variables_in_heap(ep, &vars)) {
2481 while (cfp->ep != ep) {
2482 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
2490 return local_var_list_finish(&vars);
2514 rb_f_block_given_p(
VALUE _)
2518 cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
2520 return RBOOL(cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE);
2531 rb_f_iterator_p(
VALUE self)
2533 rb_warn_deprecated(
"iterator?",
"block_given?");
2534 return rb_f_block_given_p(
self);
2538 rb_current_realfilepath(
void)
2542 cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
2544 VALUE path = rb_iseq_realpath(cfp->iseq);
2545 if (
RTEST(path))
return path;
2547 path = rb_iseq_path(cfp->iseq);
2548 if (path == eval_default_path) {
2577 VM_METHOD_TYPE_OPTIMIZED, (
void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2579 VM_METHOD_TYPE_OPTIMIZED, (
void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2592 rb_define_method(rb_eUncaughtThrow,
"initialize", uncaught_throw_init, -1);
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
#define RUBY_EVENT_C_CALL
A method, written in C, is called.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
VALUE rb_module_new(void)
Creates a new, anonymous module.
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.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
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.
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define T_COMPLEX
Old name of RUBY_T_COMPLEX.
#define T_FILE
Old name of RUBY_T_FILE.
#define T_STRING
Old name of RUBY_T_STRING.
#define T_MASK
Old name of RUBY_T_MASK.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define T_NIL
Old name of RUBY_T_NIL.
#define T_FLOAT
Old name of RUBY_T_FLOAT.
#define T_IMEMO
Old name of RUBY_T_IMEMO.
#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 OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define T_FIXNUM
Old name of RUBY_T_FIXNUM.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define SYM2ID
Old name of RB_SYM2ID.
#define T_DATA
Old name of RUBY_T_DATA.
#define CLASS_OF
Old name of rb_class_of.
#define T_NONE
Old name of RUBY_T_NONE.
#define T_NODE
Old name of RUBY_T_NODE.
#define rb_ary_new4
Old name of rb_ary_new_from_values.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define T_TRUE
Old name of RUBY_T_TRUE.
#define T_RATIONAL
Old name of RUBY_T_RATIONAL.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define T_HASH
Old name of RUBY_T_HASH.
#define T_FALSE
Old name of RUBY_T_FALSE.
#define T_UNDEF
Old name of RUBY_T_UNDEF.
#define Qtrue
Old name of RUBY_Qtrue.
#define NUM2INT
Old name of RB_NUM2INT.
#define T_ZOMBIE
Old name of RUBY_T_ZOMBIE.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define T_OBJECT
Old name of RUBY_T_OBJECT.
#define NIL_P
Old name of RB_NIL_P.
#define ALLOCV_N
Old name of RB_ALLOCV_N.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
#define DBL2NUM
Old name of rb_float_new.
#define T_MATCH
Old name of RUBY_T_MATCH.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define T_MOVED
Old name of RUBY_T_MOVED.
#define Check_TypedStruct(v, t)
Old name of rb_check_typeddata.
#define ALLOCV_END
Old name of RB_ALLOCV_END.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
#define T_REGEXP
Old name of RUBY_T_REGEXP.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
VALUE rb_eNotImpError
NotImplementedError exception.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
VALUE rb_eNameError
NameError exception.
VALUE rb_eNoMethodError
NoMethodError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_eStopIteration
StopIteration exception.
VALUE rb_eArgError
ArgumentError exception.
VALUE rb_mKernel
Kernel module.
VALUE rb_obj_alloc(VALUE klass)
Allocates an instance of the given class.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_cBasicObject
BasicObject class.
VALUE rb_cModule
Module class.
VALUE rb_obj_clone(VALUE obj)
Produces a shallow copy of the given object.
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_eval_string_wrap(const char *str, int *state)
Identical to rb_eval_string_protect(), except it evaluates the given string under a module binding in...
VALUE rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv_public(), except you can pass the passed block.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv(), except you can specify how to handle the last element of the given array.
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_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_eval_string_protect(const char *str, int *state)
Identical to rb_eval_string(), except it avoids potential global escapes.
VALUE rb_call_super_kw(int argc, const VALUE *argv, int kw_splat)
Identical to rb_call_super(), except you can specify how to handle the last element of the given arra...
VALUE rb_funcallv_public(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it only takes public methods into account.
VALUE rb_current_receiver(void)
This resembles ruby's self.
VALUE rb_funcall_passing_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv_passing_block(), except you can specify how to handle the last element of th...
VALUE rb_funcall_with_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE procval, int kw_splat)
Identical to rb_funcallv_with_block(), except you can specify how to handle the last element of the g...
VALUE rb_eval_string(const char *str)
Evaluates the given string in an isolated binding.
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
VALUE rb_funcallv_public_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv_public(), except you can specify how to handle the last element of the given...
void rb_gc_register_mark_object(VALUE object)
Inform the garbage collector that object is a live Ruby object that should not be moved.
VALUE rb_check_array_type(VALUE obj)
Try converting an object to its array representation using its to_ary method, if any.
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
Obtains a part of the passed array.
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
This roughly resembles return enum_for(__callee__) unless block_given?.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
VALUE rb_hash_clear(VALUE hash)
Swipes everything out of the passed hash table.
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
VALUE rb_proc_lambda_p(VALUE recv)
Queries if the given object is a lambda.
VALUE rb_protect(VALUE(*func)(VALUE args), VALUE args, int *state)
Protects a function call from potential global escapes from the function.
VALUE rb_str_new_cstr(const char *ptr)
Identical to rb_str_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
VALUE rb_attr_get(VALUE obj, ID name)
Identical to rb_ivar_get()
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.
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well...
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...
VALUE rb_mod_module_eval(int argc, const VALUE *argv, VALUE mod)
Identical to rb_obj_instance_eval(), except it evaluates within the context of module.
VALUE rb_mod_module_exec(int argc, const VALUE *argv, VALUE mod)
Identical to rb_obj_instance_exec(), except it evaluates within the context of module.
VALUE rb_obj_instance_exec(int argc, const VALUE *argv, VALUE recv)
Executes the given block within the context of the receiver.
VALUE rb_eval_cmd_kw(VALUE cmd, VALUE arg, int kw_splat)
This API is practically a variant of rb_proc_call_kw() now.
VALUE rb_apply(VALUE recv, ID mid, VALUE args)
Identical to rb_funcallv(), except it takes Ruby's array instead of C's.
VALUE rb_obj_instance_eval(int argc, const VALUE *argv, VALUE recv)
Evaluates a string containing Ruby source code, or the given block, within the context of the receive...
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a Ruby's String instead of C's.
VALUE rb_str_format(int argc, const VALUE *argv, VALUE fmt)
Formats a string.
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
VALUE rb_catch_obj(VALUE tag, rb_block_call_func_t func, VALUE data)
Identical to rb_catch(), except it catches arbitrary Ruby objects.
VALUE rb_each(VALUE obj)
This is a shorthand of calling obj.each.
VALUE rb_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t proc, VALUE data2)
Identical to rb_funcallv(), except it additionally passes a function as a block.
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_splat(VALUE ary)
Identical to rb_yield_values(), except it splats an array to generate the list of parameters.
void rb_throw(const char *tag, VALUE val)
Transfers control to the end of the active catch block waiting for tag.
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...
rb_block_call_func * rb_block_call_func_t
Shorthand type that represents an iterator-written-in-C function pointer.
VALUE rb_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
Pass a passed block.
void rb_throw_obj(VALUE tag, VALUE val)
Identical to rb_throw(), except it allows arbitrary Ruby object to become a tag.
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_iterate(VALUE(*func1)(VALUE), VALUE data1, rb_block_call_func_t proc, VALUE data2)
Old way to iterate a block.
VALUE rb_catch(const char *tag, rb_block_call_func_t func, VALUE data)
Executes the passed block and catches values thrown from inside of it.
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.
VALUE rb_yield_splat_kw(VALUE ary, int kw_splat)
Identical to rb_yield_splat(), except you can specify how to handle the last element of the given arr...
#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 type(ANYARGS)
ANYARGS-ed function type.
#define RARRAY_CONST_PTR_TRANSIENT
Just another name of rb_array_const_ptr_transient.
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
static VALUE RBASIC_CLASS(VALUE obj)
Queries the class of an object.
#define RBASIC(obj)
Convenient casting macro.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#define RHASH_EMPTY_P(h)
Checks if the hash is empty.
#define SafeStringValue(v)
#define StringValue(v)
Ensures that the parameter object is a String.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
#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.
IFUNC (Internal FUNCtion)
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_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
ruby_value_type
C-level type of an object.