14#include "internal/thread.h"
15#include "prism_compile.h"
28static int vm_collect_local_variables_in_heap(
const VALUE *dfp,
const struct local_var_list *vars);
30static VALUE rb_eUncaughtThrow;
31static ID id_result, id_tag, id_value;
34static VALUE send_internal(
int argc,
const VALUE *argv,
VALUE recv, call_type scope);
38vm_argv_ruby_array(
VALUE *av,
const VALUE *argv,
int *flags,
int *argc,
int kw_splat)
40 *flags |= VM_CALL_ARGS_SPLAT;
51 *flags |= VM_CALL_KW_SPLAT;
52 av[1] = rb_hash_new();
63 return vm_call0_cc(ec, recv,
id, argc, argv, &cc, kw_splat);
70 rb_callable_method_entry_with_refinements(
CLASS_OF(recv),
id, NULL);
72 return rb_vm_call0(ec, recv,
id, argc, argv, me, kw_splat);
83 int flags = kw_splat ? VM_CALL_KW_SPLAT : 0;
87 if (UNLIKELY(vm_cc_cme(cc)->def->type == VM_METHOD_TYPE_ISEQ && argc > VM_ARGC_STACK_MAX)) {
88 use_argv = vm_argv_ruby_array(av, argv, &flags, &argc, kw_splat);
93 .ci = &VM_CI_ON_STACK(
id, flags, argc, NULL),
97 .block_handler = vm_passed_block_handler(ec),
100 .kw_splat = kw_splat,
103 return vm_call0_body(ec, &calling, use_argv);
109 calling->cc = &VM_CC_ON_STACK(
Qundef, vm_call_general, {{ 0 }}, cme);
110 return vm_call0_body(ec, calling, argv);
116 ID mid = vm_ci_mid(calling->cd->ci);
123 RUBY_VM_CHECK_INTS(ec);
124 return vm_call0_cme(ec, calling, argv, cme);
128 vm_passed_block_handler_set(ec, calling->block_handler);
129 return method_missing(ec, calling->recv, mid, calling->argc, argv, ex, calling->kw_splat);
139 int len = cfunc->argc;
140 VALUE recv = calling->recv;
141 int argc = calling->argc;
142 ID mid = vm_ci_mid(ci);
143 VALUE block_handler = calling->block_handler;
144 int frame_flags = VM_FRAME_MAGIC_CFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL;
146 if (calling->kw_splat) {
151 frame_flags |= VM_FRAME_FLAG_CFRAME_KW;
155 RUBY_DTRACE_CMETHOD_ENTRY_HOOK(ec, me->owner, me->def->original_id);
160 vm_push_frame(ec, 0, frame_flags, recv,
161 block_handler, (
VALUE)me,
162 0, reg_cfp->sp, 0, 0);
166 val = (*cfunc->invoker)(recv, argc, argv, cfunc->func);
168 CHECK_CFP_CONSISTENCY(
"vm_call0_cfunc_with_frame");
172 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
180 return vm_call0_cfunc_with_frame(ec, calling, argv);
186 if (calling->kw_splat &&
206 switch (vm_cc_cme(cc)->def->type) {
207 case VM_METHOD_TYPE_ISEQ:
212 CHECK_VM_STACK_OVERFLOW(reg_cfp, calling->argc + 1);
213 vm_check_canary(ec, reg_cfp->sp);
215 *reg_cfp->sp++ = calling->recv;
216 for (i = 0; i < calling->argc; i++) {
217 *reg_cfp->sp++ = argv[i];
220 if (ISEQ_BODY(def_iseq_ptr(vm_cc_cme(cc)->def))->param.flags.forwardable) {
221 vm_call_iseq_fwd_setup(ec, reg_cfp, calling);
224 vm_call_iseq_setup(ec, reg_cfp, calling);
226 VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);
229 case VM_METHOD_TYPE_NOTIMPLEMENTED:
230 case VM_METHOD_TYPE_CFUNC:
231 ret = vm_call0_cfunc(ec, calling, argv);
233 case VM_METHOD_TYPE_ATTRSET:
234 vm_call_check_arity(calling, 1, argv);
235 VM_CALL_METHOD_ATTR(ret,
236 rb_ivar_set(calling->recv, vm_cc_cme(cc)->def->body.attr.id, argv[0]),
239 case VM_METHOD_TYPE_IVAR:
240 vm_call_check_arity(calling, 0, argv);
241 VM_CALL_METHOD_ATTR(ret,
242 rb_attr_get(calling->recv, vm_cc_cme(cc)->def->body.attr.id),
245 case VM_METHOD_TYPE_BMETHOD:
246 ret = vm_call_bmethod_body(ec, calling, argv);
248 case VM_METHOD_TYPE_ZSUPER:
250 VALUE klass = RCLASS_ORIGIN(vm_cc_cme(cc)->defined_class);
251 return vm_call0_super(ec, calling, argv, klass, MISSING_SUPER);
253 case VM_METHOD_TYPE_REFINED:
257 if (cme->def->body.refined.orig_me) {
259 return vm_call0_cme(ec, calling, argv, orig_cme);
262 VALUE klass = cme->defined_class;
263 return vm_call0_super(ec, calling, argv, klass, 0);
265 case VM_METHOD_TYPE_ALIAS:
270 if (cme == orig_cme) rb_bug(
"same!!");
272 if (vm_cc_markable(cc)) {
273 return vm_call0_cme(ec, calling, argv, orig_cme);
280 case VM_METHOD_TYPE_MISSING:
282 vm_passed_block_handler_set(ec, calling->block_handler);
283 return method_missing(ec, calling->recv, vm_ci_mid(ci), calling->argc,
284 argv, MISSING_NOENTRY, calling->kw_splat);
286 case VM_METHOD_TYPE_OPTIMIZED:
287 switch (vm_cc_cme(cc)->def->body.optimized.type) {
288 case OPTIMIZED_METHOD_TYPE_SEND:
289 ret = send_internal(calling->argc, argv, calling->recv, calling->kw_splat ? CALL_FCALL_KW : CALL_FCALL);
291 case OPTIMIZED_METHOD_TYPE_CALL:
294 GetProcPtr(calling->recv, proc);
295 ret = rb_vm_invoke_proc(ec, proc, calling->argc, argv, calling->kw_splat, calling->block_handler,
296 rb_proc_refinements_cref_for_call(calling->recv));
299 case OPTIMIZED_METHOD_TYPE_STRUCT_AREF:
300 vm_call_check_arity(calling, 0, argv);
301 VM_CALL_METHOD_ATTR(ret,
302 vm_call_opt_struct_aref0(ec, calling),
305 case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
306 vm_call_check_arity(calling, 1, argv);
307 VM_CALL_METHOD_ATTR(ret,
308 vm_call_opt_struct_aset0(ec, calling, argv[0]),
312 rb_bug(
"vm_call0: unsupported optimized method type (%d)", vm_cc_cme(cc)->def->body.optimized.type);
315 case VM_METHOD_TYPE_UNDEF:
318 rb_bug(
"vm_call0: unsupported method type (%d)", vm_cc_cme(cc)->def->type);
322 RUBY_VM_CHECK_INTS(ec);
329 return rb_vm_call0(ec, recv,
id, argc, argv, me, kw_splat);
335 VALUE recv = ec->cfp->self;
341 if (VM_FRAME_RUBYFRAME_P(cfp)) {
342 rb_bug(
"vm_call_super: should not be reached");
345 klass = RCLASS_ORIGIN(me->defined_class);
347 id = me->def->original_id;
348 me = rb_callable_method_entry(klass,
id);
351 return method_missing(ec, recv,
id, argc, argv, MISSING_SUPER, kw_splat);
353 return rb_vm_call_kw(ec, recv,
id, argc, argv, me, kw_splat);
360 PASS_PASSED_BLOCK_HANDLER_EC(ec);
361 return vm_call_super(ec, argc, argv, kw_splat);
375 if (!ec || !(cfp = ec->cfp)) {
384 if (!rb_ec_raised_p(ec, RAISED_STACKOVERFLOW) &&
385 rb_ec_stack_check(ec)) {
386 rb_ec_raised_set(ec, RAISED_STACKOVERFLOW);
387 rb_ec_stack_overflow(ec, 0);
392rb_check_stack_overflow(
void)
394#ifndef RB_THREAD_LOCAL_SPECIFIER
395 if (!ruby_current_ec_key)
return;
398 if (ec) stack_check(ec);
401NORETURN(
static void uncallable_object(
VALUE recv,
ID mid));
408 return ((klass ^ box_value) >> 3) ^ (
VALUE)mid;
421 vm_search_method_slowpath0(vm->self, &cd, klass);
423 if (UNLIKELY(!vm->global_cc_cache_table_used)) {
424 vm->global_cc_cache_table_used =
true;
426 return vm->global_cc_cache_table[index] = cd.cc;
430scope_to_ci(call_type scope,
ID mid,
int argc,
struct rb_callinfo *ci)
438 flags |= VM_CALL_FCALL;
441 flags |= VM_CALL_VCALL;
444 flags |= VM_CALL_KWARG;
447 flags |= (VM_CALL_KWARG | VM_CALL_FCALL);
450 *ci = VM_CI_ON_STACK(mid, flags, argc, NULL);
456 VALUE klass, box_value;
457 const rb_box_t *box = rb_current_box();
461 if (UNLIKELY(!klass)) uncallable_object(recv, mid);
467 if (BOX_USER_P(box)) {
468 box_value = box->box_object;
474 unsigned int index = (
unsigned int)(gccct_hash(klass, box_value, mid) % VM_GLOBAL_CC_CACHE_TABLE_SIZE);
475 rb_vm_t *vm = rb_ec_vm_ptr(ec);
476 const struct rb_callcache *cc = vm->global_cc_cache_table[index];
479 if (LIKELY(vm_cc_class_check(cc, klass))) {
481 if (LIKELY(!METHOD_ENTRY_INVALIDATED(cme) &&
482 cme->called_id == mid)) {
484 VM_ASSERT(vm_cc_check_cme(cc, rb_callable_method_entry(klass, mid)));
485 RB_DEBUG_COUNTER_INC(gccct_hit);
492 RB_DEBUG_COUNTER_INC(gccct_null);
495 RB_DEBUG_COUNTER_INC(gccct_miss);
496 return gccct_method_search_slowpath(vm, klass, index, ci);
500rb_gccct_clear_table(
void)
503 if (vm->global_cc_cache_table_used) {
504 const struct rb_callcache **
const table = vm->global_cc_cache_table;
506 vm->global_cc_cache_table_used =
false;
530 call_type call_scope,
VALUE self)
532 enum method_missing_reason call_status;
533 call_type scope = call_scope;
550 scope_to_ci(scope, mid, argc, &ci);
552 const struct rb_callcache *cc = gccct_method_search(ec, recv, mid, &ci);
554 if (scope == CALL_PUBLIC) {
555 RB_DEBUG_COUNTER_INC(call0_public);
559 call_status = rb_method_call_status(ec, cme, scope, self);
561 if (UNLIKELY(call_status != MISSING_NONE)) {
562 return method_missing(ec, recv, mid, argc, argv, call_status, kw_splat);
564 else if (UNLIKELY(cc_cme != cme)) {
566 return rb_vm_call_kw(ec, recv, mid, argc, argv, cme, kw_splat);
570 RB_DEBUG_COUNTER_INC(call0_other);
571 call_status = rb_method_call_status(ec, cc ? vm_cc_cme(cc) : NULL, scope, self);
573 if (UNLIKELY(call_status != MISSING_NONE)) {
574 return method_missing(ec, recv, mid, argc, argv, call_status, kw_splat);
579 return vm_call0_cc(ec, recv, mid, argc, argv, cc, kw_splat);
588 unsigned int respond: 1;
589 unsigned int respond_to_missing: 1;
596check_funcall_exec(
VALUE v)
599 return call_method_entry(args->ec, args->defined_class,
600 args->recv, idMethodMissing,
601 args->cme, args->argc, args->argv, args->kw_splat);
608 int ret = args->respond;
610 switch (method_boundp(args->defined_class, args->mid,
611 BOUND_PRIVATE|BOUND_RESPONDS)) {
616 ret = args->respond_to_missing;
632 return vm_respond_to(ec, klass, recv, mid, TRUE);
638 return rb_method_call_status(ec, me, CALL_FCALL, ec->cfp->self) == MISSING_NONE;
648 ret = basic_obj_respond_to_missing(ec, klass, recv,
650 if (!
RTEST(ret))
return def;
651 args.respond = respond > 0;
652 args.respond_to_missing = !UNDEF_P(ret);
654 cme = callable_method_entry(klass, idMethodMissing, &args.defined_class);
656 if (cme && !METHOD_ENTRY_BASIC(cme)) {
659 new_args[0] =
ID2SYM(mid);
663 VM_ASSERT(argc == 0);
668 ec->method_missing_reason = MISSING_NOENTRY;
673 args.argc = argc + 1;
674 args.argv = new_args;
675 args.kw_splat = kw_splat;
677 check_funcall_failed, (
VALUE)&args,
684static VALUE rb_check_funcall_default_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def,
int kw_splat);
689 return rb_check_funcall_default_kw(recv, mid, argc, argv,
Qundef, kw_splat);
699rb_check_funcall_default_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def,
int kw_splat)
701 VM_ASSERT(ruby_thread_has_gvl_p());
706 int respond = check_funcall_respond_to(ec, klass, recv, mid);
711 me = rb_search_method_entry(recv, mid);
712 if (!check_funcall_callable(ec, me)) {
713 VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
714 respond, def, kw_splat);
715 if (UNDEF_P(ret)) ret = def;
719 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
723rb_check_funcall_default(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def)
725 return rb_check_funcall_default_kw(recv, mid, argc, argv, def,
RB_NO_KEYWORDS);
729rb_check_funcall_with_hook_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
730 rb_check_funcall_hook *hook,
VALUE arg,
int kw_splat)
735 int respond = check_funcall_respond_to(ec, klass, recv, mid);
738 (*hook)(FALSE, recv, mid, argc, argv, arg);
742 me = rb_search_method_entry(recv, mid);
743 if (!check_funcall_callable(ec, me)) {
744 VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
745 respond,
Qundef, kw_splat);
746 (*hook)(!UNDEF_P(ret), recv, mid, argc, argv, arg);
750 (*hook)(TRUE, recv, mid, argc, argv, arg);
751 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
757#define type_case(t) t: return #t
775 case type_case(
T_NIL);
793uncallable_object(
VALUE recv,
ID mid)
798 VALUE mname = rb_id2str(mid);
802 "method '%"PRIsVALUE
"' called on unexpected immediate object (%p)",
803 mname, (
void *)recv);
805 else if ((flags =
RBASIC(recv)->flags) == 0) {
807 "method '%"PRIsVALUE
"' called on terminated object (%p)",
808 mname, (
void *)recv);
812 "method '%"PRIsVALUE
"' called on broken T_?""?""?(0x%02x) object"
813 " (%p flags=0x%"PRIxVALUE
")",
814 mname,
type, (
void *)recv, flags);
818 "method '%"PRIsVALUE
"' called on hidden %s object"
819 " (%p flags=0x%"PRIxVALUE
")",
820 mname, typestr, (
void *)recv, flags);
824 "method '%"PRIsVALUE
"' called on unexpected %s object"
825 " (%p flags=0x%"PRIxVALUE
")",
826 mname, typestr, (
void *)recv, flags);
831rb_search_method_entry(
VALUE recv,
ID mid)
835 if (!klass) uncallable_object(recv, mid);
836 return rb_callable_method_entry(klass, mid);
839static inline enum method_missing_reason
842 if (UNLIKELY(UNDEFINED_METHOD_ENTRY_P(me))) {
845 else if (UNLIKELY(me->def->type == VM_METHOD_TYPE_REFINED)) {
846 me = rb_resolve_refined_method_callable(
Qnil, me);
847 if (UNDEFINED_METHOD_ENTRY_P(me))
goto undefined;
850 rb_method_visibility_t visi = METHOD_ENTRY_VISI(me);
853 if (UNLIKELY(visi != METHOD_VISI_PUBLIC)) {
854 if (me->def->original_id == idMethodMissing) {
857 else if (visi == METHOD_VISI_PRIVATE &&
858 scope == CALL_PUBLIC) {
859 return MISSING_PRIVATE;
862 else if (visi == METHOD_VISI_PROTECTED &&
863 scope == CALL_PUBLIC) {
865 VALUE defined_class = me->owner;
867 defined_class =
RBASIC(defined_class)->klass;
871 return MISSING_PROTECTED;
879 return scope == CALL_VCALL ? MISSING_VCALL : MISSING_NOENTRY;
895rb_call(
VALUE recv,
ID mid,
int argc,
const VALUE *argv, call_type scope)
898 return rb_call0(ec, recv, mid, argc, argv, scope, ec->cfp->self);
902 VALUE obj,
enum method_missing_reason call_status));
944rb_method_missing(
int argc,
const VALUE *argv,
VALUE obj)
947 raise_method_missing(ec, argc, argv, obj, ec->method_missing_reason);
953 int argc,
const VALUE *argv,
int priv)
955 VALUE name = argv[0];
958 format = rb_fstring_lit(
"undefined method '%1$s' for %3$s%4$s");
962 return rb_nomethod_err_new(format, obj, name, args, priv);
965 return rb_name_err_new(format, obj, name);
971 enum method_missing_reason last_call_status)
976 if (UNLIKELY(argc == 0)) {
977 rb_raise(rb_eArgError,
"no method name given");
979 else if (UNLIKELY(!
SYMBOL_P(argv[0]))) {
980 const VALUE e = rb_eArgError;
981 rb_raise(e,
"method name must be a Symbol but %"PRIsVALUE
" is given",
987 if (last_call_status & MISSING_PRIVATE) {
988 format = rb_fstring_lit(
"private method '%1$s' called for %3$s%4$s");
990 else if (last_call_status & MISSING_PROTECTED) {
991 format = rb_fstring_lit(
"protected method '%1$s' called for %3$s%4$s");
993 else if (last_call_status & MISSING_VCALL) {
994 format = rb_fstring_lit(
"undefined local variable or method '%1$s' for %3$s%4$s");
997 else if (last_call_status & MISSING_SUPER) {
998 format = rb_fstring_lit(
"super: no superclass method '%1$s' for %3$s%4$s");
1002 exc = rb_make_no_method_exception(exc, format, obj, argc, argv,
1003 last_call_status & (MISSING_FCALL|MISSING_VCALL));
1004 if (!(last_call_status & MISSING_MISSING)) {
1005 rb_vm_pop_cfunc_frame();
1013 VALUE obj,
int call_status)
1015 vm_passed_block_handler_set(ec, VM_BLOCK_HANDLER_NONE);
1016 raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
1022 VALUE *nargv, result, work, klass;
1023 VALUE block_handler = vm_passed_block_handler(ec);
1026 ec->method_missing_reason = call_status;
1028 if (
id == idMethodMissing) {
1037 VM_ASSERT(argc == 0);
1046 if (!klass)
goto missing;
1047 me = rb_callable_method_entry(klass, idMethodMissing);
1048 if (!me || METHOD_ENTRY_BASIC(me))
goto missing;
1049 vm_passed_block_handler_set(ec, block_handler);
1050 result = rb_vm_call_kw(ec, obj, idMethodMissing, argc, argv, me, kw_splat);
1054 raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
1059rb_funcallv_scope(
VALUE recv,
ID mid,
int argc,
const VALUE *argv, call_type scope)
1064 scope_to_ci(scope, mid, argc, &ci);
1066 const struct rb_callcache *cc = gccct_method_search(ec, recv, mid, &ci);
1067 VALUE self = ec->cfp->self;
1070 LIKELY(rb_method_call_status(ec, vm_cc_cme(cc), scope, self) == MISSING_NONE)) {
1072 return vm_call0_cc(ec, recv, mid, argc, argv, cc,
false);
1075 return rb_call0(ec, recv, mid, argc, argv, scope, self);
1085 VM_ASSERT(ruby_thread_has_gvl_p());
1088 return rb_funcallv_scope(recv, mid, argc, argv, CALL_FCALL);
1094 VM_ASSERT(ruby_thread_has_gvl_p());
1096 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_FCALL_KW : CALL_FCALL);
1106 if (argc >= 0x100) {
1108 RBASIC_CLEAR_CLASS(args);
1137 for (i = 0; i < n; i++) {
1138 argv[i] = va_arg(ar,
VALUE);
1159rb_check_funcall_basic_kw(
VALUE recv,
ID mid,
VALUE ancestor,
int argc,
const VALUE *argv,
int kw_splat)
1164 if (!klass)
return Qundef;
1166 cme = rb_callable_method_entry(klass, mid);
1167 if (cme && METHOD_ENTRY_BASIC(cme) &&
RBASIC_CLASS(cme->defined_class) == ancestor) {
1169 return rb_vm_call0(ec, recv, mid, argc, argv, cme, kw_splat);
1178 return rb_funcallv_scope(recv, mid, argc, argv, CALL_PUBLIC);
1184 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1190 PASS_PASSED_BLOCK_HANDLER();
1197 PASS_PASSED_BLOCK_HANDLER();
1198 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1204 if (!
NIL_P(passed_procval)) {
1205 vm_passed_block_handler_set(GET_EC(), passed_procval);
1214 if (!
NIL_P(passed_procval)) {
1215 vm_passed_block_handler_set(GET_EC(), passed_procval);
1218 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1225 if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, prev_cfp))
return NULL;
1226 if (prev_cfp->sp + 1 != argv)
return NULL;
1227 return prev_cfp->sp + 1;
1231send_internal(
int argc,
const VALUE *argv,
VALUE recv, call_type scope)
1236 VALUE ret, vargv = 0;
1238 int public = scope == CALL_PUBLIC || scope == CALL_PUBLIC_KW;
1244 self = RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp)->self;
1248 rb_raise(rb_eArgError,
"no method name given");
1262 VALUE *tmp_argv = current_vm_stack_arg(ec, argv);
1267 else if (argc > 1) {
1277 id = idMethodMissing;
1278 ec->method_missing_reason = MISSING_NOENTRY;
1283 PASS_PASSED_BLOCK_HANDLER_EC(ec);
1284 ret = rb_call0(ec, recv,
id, argc, argv, scope, self);
1290send_internal_kw(
int argc,
const VALUE *argv,
VALUE recv, call_type scope)
1295 scope = CALL_PUBLIC_KW;
1298 scope = CALL_FCALL_KW;
1304 return send_internal(argc, argv, recv, scope);
1336 return send_internal_kw(argc, argv, recv, CALL_FCALL);
1354rb_f_public_send(
int argc,
VALUE *argv,
VALUE recv)
1356 return send_internal_kw(argc, argv, recv, CALL_PUBLIC);
1362rb_yield_0_kw(
int argc,
const VALUE * argv,
int kw_splat)
1364 return vm_yield(GET_EC(), argc, argv, kw_splat);
1368rb_yield_0(
int argc,
const VALUE * argv)
1374rb_yield_1(
VALUE val)
1376 return rb_yield_0(1, &val);
1383 return rb_yield_0(0, NULL);
1386 return rb_yield_0(1, &val);
1401#undef rb_yield_values
1406 return rb_yield_0(0, 0);
1415 for (i=0; i<n; i++) {
1416 argv[i] = va_arg(args,
VALUE);
1420 return rb_yield_0(n, argv);
1427 return rb_yield_0(argc, argv);
1433 return rb_yield_0_kw(argc, argv, kw_splat);
1442 rb_raise(rb_eArgError,
"not an array");
1455 rb_raise(rb_eArgError,
"not an array");
1463rb_yield_force_blockarg(
VALUE values)
1465 return vm_yield_force_blockarg(GET_EC(), values);
1471 return vm_yield_with_block(GET_EC(), argc, argv,
1472 NIL_P(blockarg) ? VM_BLOCK_HANDLER_NONE : blockarg,
1483 const struct vm_ifunc *
const ifunc,
1486 enum ruby_tag_type state;
1492 state = EC_EXEC_TAG();
1496 VALUE block_handler;
1500 captured->code.ifunc = ifunc;
1501 block_handler = VM_BH_FROM_IFUNC_BLOCK(captured);
1504 block_handler = VM_CF_BLOCK_HANDLER(cfp);
1506 vm_passed_block_handler_set(ec, block_handler);
1508 retval = (*it_proc) (data1);
1510 else if (state == TAG_BREAK || state == TAG_RETRY) {
1514 if (cfp == escape_cfp) {
1515 rb_vm_rewind_cfp(ec, cfp);
1518 ec->tag->state = TAG_NONE;
1521 if (state == TAG_RETRY)
goto iter_retry;
1522 retval = THROW_DATA_VAL(err);
1525 SDR(); fprintf(stderr,
"%p, %p\n", (
void *)cfp, (
void *)escape_cfp);
1531 EC_JUMP_TAG(ec, state);
1540 return rb_iterate0(it_proc, data1,
1541 bl_proc ? rb_vm_ifunc_proc_new(bl_proc, (
void *)data2) : 0,
1554iterate_method(
VALUE obj)
1559 return rb_call(arg->obj, arg->mid, arg->argc, arg->argv, arg->kw_splat ? CALL_FCALL_KW : CALL_FCALL);
1581 arg.kw_splat = kw_splat;
1582 return rb_iterate_internal(iterate_method, (
VALUE)&arg, bl_proc, data2);
1598rb_block_call2(
VALUE obj,
ID mid,
int argc,
const VALUE *argv,
1607 arg.kw_splat = flags & 1;
1609 struct vm_ifunc *ifunc = rb_vm_ifunc_proc_new(bl_proc, (
void *)data2);
1610 if (flags & RB_BLOCK_NO_USE_PACKED_ARGS)
1611 ifunc->flags |= IFUNC_YIELD_OPTIMIZABLE;
1613 return rb_iterate0(iterate_method, (
VALUE)&arg, ifunc, GET_EC());
1617rb_lambda_call(
VALUE obj,
ID mid,
int argc,
const VALUE *argv,
1624 if (!bl_proc) rb_raise(rb_eArgError,
"NULL lambda function");
1630 block = rb_vm_ifunc_new(bl_proc, (
void *)data2, min_argc, max_argc);
1631 return rb_iterate0(iterate_method, (
VALUE)&arg, block, GET_EC());
1635iterate_check_method(
VALUE obj)
1644rb_check_block_call(
VALUE obj,
ID mid,
int argc,
const VALUE *argv,
1654 return rb_iterate_internal(iterate_check_method, (
VALUE)&arg, bl_proc, data2);
1660 return rb_call(obj, idEach, 0, 0, CALL_FCALL);
1665#define EVAL_LOCATION_MARK "eval at "
1666#define EVAL_LOCATION_MARK_LEN (int)rb_strlen_lit(EVAL_LOCATION_MARK)
1669get_eval_default_path(
void)
1671 int location_lineno;
1672 VALUE location_path = rb_source_location(&location_lineno);
1673 if (!
NIL_P(location_path)) {
1674 return rb_fstring(rb_sprintf(
"("EVAL_LOCATION_MARK
"%"PRIsVALUE
":%d)",
1675 location_path, location_lineno));
1678 if (!eval_default_path) {
1679 eval_default_path = rb_fstring_lit(
"(eval)");
1680 rb_vm_register_global_object(eval_default_path);
1682 return eval_default_path;
1686compute_isolated_depth_from_ep(
const VALUE *ep)
1690 if (VM_ENV_FLAGS(ep, VM_ENV_FLAG_ISOLATED))
return depth;
1691 if (VM_ENV_LOCAL_P(ep))
return 0;
1692 ep = VM_ENV_PREV_EP(ep);
1698compute_isolated_depth_from_block(
const struct rb_block *blk)
1700 return compute_isolated_depth_from_ep(vm_block_ep(blk));
1704pm_eval_make_iseq(
VALUE src,
VALUE fname,
int line,
1707 const rb_iseq_t *
const parent = vm_block_iseq(base_block);
1709 VALUE name = rb_fstring_lit(
"<compiled>");
1711 int coverage_enabled = ((rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) != 0) ? 1 : 0;
1712 int isolated_depth = compute_isolated_depth_from_block(base_block);
1715 fname = rb_source_location(&line);
1718 if (!UNDEF_P(fname)) {
1719 if (!
NIL_P(fname)) fname = rb_fstring(fname);
1722 fname = get_eval_default_path();
1723 coverage_enabled = 0;
1727 pm_parse_result_init(&result);
1728 pm_options_line_set(result.
options, line);
1729 result.
node.coverage_enabled = coverage_enabled;
1732 int scopes_count = 0;
1735 }
while ((iseq = ISEQ_BODY(iseq)->parent_iseq));
1736 pm_options_scopes_init(result.
options, scopes_count + 1);
1744#define FORWARDING_POSITIONALS_CHR '*'
1745#define FORWARDING_POSITIONALS_STR "*"
1746#define FORWARDING_KEYWORDS_CHR ':'
1747#define FORWARDING_KEYWORDS_STR ":"
1748#define FORWARDING_BLOCK_CHR '&'
1749#define FORWARDING_BLOCK_STR "&"
1750#define FORWARDING_ALL_CHR '.'
1751#define FORWARDING_ALL_STR "."
1753 for (
int scopes_index = 0; scopes_index < scopes_count; scopes_index++) {
1755 int locals_count = ISEQ_BODY(iseq)->local_table_size;
1758 pm_options_scope_init(options_scope, locals_count);
1762 for (
int local_index = 0; local_index < locals_count; local_index++) {
1763 pm_string_t *scope_local = pm_options_scope_local_mut(options_scope, local_index);
1764 ID local = ISEQ_BODY(iseq)->local_table[local_index];
1767 VALUE name_obj = rb_id2str(local);
1768 const char *name = RSTRING_PTR(name_obj);
1769 size_t length = RSTRING_LEN(name_obj);
1774 char *name_dup =
xmalloc(length);
1775 MEMCPY(name_dup, name,
char, length);
1779 pm_string_owned_init(scope_local, (uint8_t *) name_dup, length);
1781 else if (local == idMULT) {
1783 pm_string_constant_init(scope_local, FORWARDING_POSITIONALS_STR, 1);
1785 else if (local == idPow) {
1787 pm_string_constant_init(scope_local, FORWARDING_KEYWORDS_STR, 1);
1789 else if (local == idAnd) {
1791 pm_string_constant_init(scope_local, FORWARDING_BLOCK_STR, 1);
1793 else if (local == idDot3) {
1795 pm_string_constant_init(scope_local, FORWARDING_ALL_STR, 1);
1799 pm_options_scope_forwarding_set(options_scope, forwarding);
1800 iseq = ISEQ_BODY(iseq)->parent_iseq;
1810 pm_options_scope_init(pm_options_scope_mut(result.
options, scopes_count), 0);
1813 VALUE error = pm_parse_string(&result, src, fname, ruby_vm_keep_script_lines ? &script_lines : NULL);
1816 if (error !=
Qnil) {
1817 pm_parse_result_free(&result);
1827 for (
int scopes_index = 0; scopes_index < scopes_count; scopes_index++) {
1832 parent_scope->coverage_enabled = coverage_enabled;
1833 parent_scope->parser = result.
parser;
1834 int locals_count = ISEQ_BODY(iseq)->local_table_size;
1836 parent_scope->local_table_for_iseq_size = locals_count;
1837 pm_constant_id_list_init(&parent_scope->locals);
1839 for (
int local_index = 0; local_index < locals_count; local_index++) {
1840 const pm_string_t *scope_local = pm_options_scope_local(options_scope, local_index);
1843 const uint8_t *source = pm_string_source(scope_local);
1844 size_t length = pm_string_length(scope_local);
1849 case FORWARDING_POSITIONALS_CHR:
1850 constant_id = PM_CONSTANT_MULT;
1852 case FORWARDING_KEYWORDS_CHR:
1853 constant_id = PM_CONSTANT_POW;
1855 case FORWARDING_BLOCK_CHR:
1856 constant_id = PM_CONSTANT_AND;
1858 case FORWARDING_ALL_CHR:
1859 constant_id = PM_CONSTANT_DOT3;
1862 constant_id = pm_parser_constant_find(result.
parser, source, length);
1867 constant_id = pm_parser_constant_find(result.
parser, source, length);
1870 pm_index_lookup_table_insert(&parent_scope->
index_lookup_table, constant_id, local_index);
1873 pm_constant_id_list_append(result.
arena, &parent_scope->locals, constant_id);
1876 node->previous = parent_scope;
1877 node = parent_scope;
1878 iseq = ISEQ_BODY(iseq)->parent_iseq;
1881#undef FORWARDING_POSITIONALS_CHR
1882#undef FORWARDING_POSITIONALS_STR
1883#undef FORWARDING_KEYWORDS_CHR
1884#undef FORWARDING_KEYWORDS_STR
1885#undef FORWARDING_BLOCK_CHR
1886#undef FORWARDING_BLOCK_STR
1887#undef FORWARDING_ALL_CHR
1888#undef FORWARDING_ALL_STR
1891 iseq = pm_iseq_new_eval(&result.
node, name, fname,
Qnil, line, parent, isolated_depth, &error_state);
1896 pm_scope_node_destroy(prev);
1901 pm_parse_result_free(&result);
1906 rb_jump_tag(error_state);
1909 rb_exec_event_hook_script_compiled(GET_EC(), iseq, src);
1915eval_make_iseq(
VALUE src,
VALUE fname,
int line,
1918 if (rb_ruby_prism_p()) {
1919 return pm_eval_make_iseq(src, fname, line, base_block);
1921 const VALUE parser = rb_parser_new();
1922 const rb_iseq_t *
const parent = vm_block_iseq(base_block);
1927 int coverage_enabled = (rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) != 0;
1928 int isolated_depth = compute_isolated_depth_from_block(base_block);
1931 fname = rb_source_location(&line);
1934 if (!UNDEF_P(fname)) {
1935 if (!
NIL_P(fname)) fname = rb_fstring(fname);
1938 fname = get_eval_default_path();
1939 coverage_enabled = FALSE;
1942 rb_parser_set_context(parser, parent, FALSE);
1943 if (ruby_vm_keep_script_lines) rb_parser_set_script_lines(parser);
1944 ast_value = rb_parser_compile_string_path(parser, fname, src, line);
1946 ast = rb_ruby_ast_data_get(ast_value);
1948 if (ast->body.root) {
1949 ast->body.coverage_enabled = coverage_enabled;
1950 iseq = rb_iseq_new_eval(ast_value,
1951 ISEQ_BODY(parent)->location.label,
1953 parent, isolated_depth);
1955 rb_ast_dispose(ast);
1959 VALUE disasm = rb_iseq_disasm(iseq);
1963 rb_exec_event_hook_script_compiled(GET_EC(), iseq, src);
1980 block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(cfp);
1981 block.as.captured.self = self;
1982 block.as.captured.code.iseq = CFP_ISEQ(cfp);
1983 block.type = block_type_iseq;
1987 if (rb_zjit_enabled_p) rb_zjit_invalidate_no_ep_escape(CFP_ISEQ(cfp));
1989 iseq = eval_make_iseq(src, file, line, &block);
1995 if (!cref && block.as.captured.code.val) {
1996 rb_cref_t *orig_cref = vm_get_cref(vm_block_ep(&block));
1997 cref = rb_vm_cref_dup(orig_cref);
1999 vm_set_eval_stack(ec, iseq, cref, &block);
2010 const rb_iseq_t *iseq = eval_make_iseq(src, file, line, &bind->block);
2015 vm_set_eval_stack(ec, iseq, NULL, &bind->block);
2018 if (ISEQ_BODY(iseq)->local_table_size > 0) {
2019 vm_bind_update_env(scope, bind, vm_make_env_object(ec, ec->cfp));
2062rb_f_eval(
int argc,
const VALUE *argv,
VALUE self)
2064 VALUE src, scope, vfile, vline;
2068 rb_scan_args(argc, argv,
"13", &src, &scope, &vfile, &vline);
2081 return eval_string_with_cref(self, src, NULL, file, line);
2083 return eval_string_with_scope(scope, src, file, line);
2088ruby_eval_string_from_file(
const char *str,
const char *filename)
2093 VALUE self = cfp ? cfp->self : rb_vm_top_self();
2094 return eval_string_with_cref(self,
rb_str_new2(str), NULL, file, 1);
2100 return ruby_eval_string_from_file(str,
"eval");
2104eval_string_protect(
VALUE str)
2112 return rb_protect(eval_string_protect, (
VALUE)str, pstate);
2122eval_string_wrap_protect(
VALUE data)
2125 rb_cref_t *cref = rb_vm_cref_new_toplevel();
2126 cref->klass_or_self = arg->klass;
2135 VALUE self = th->top_self;
2136 VALUE wrapper = th->top_wrapper;
2144 data.top_self = th->top_self;
2145 data.klass = th->top_wrapper;
2148 val = rb_protect(eval_string_wrap_protect, (
VALUE)&data, &state);
2150 th->top_self = self;
2151 th->top_wrapper = wrapper;
2156 else if (state != TAG_NONE) {
2157 EC_JUMP_TAG(th->ec, state);
2168 VALUE val = rb_eval_cmd_call_kw(cmd, argc, argv, kw_splat);
2174rb_eval_cmd_call_kw(
VALUE cmd,
int argc,
const VALUE *argv,
int kw_splat)
2176 enum ruby_tag_type state;
2181 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
2186 val = eval_string_with_cref(rb_vm_top_self(), cmd, NULL, 0, 0);
2191 if (state) EC_JUMP_TAG(ec, state);
2198yield_under(
VALUE self,
int singleton,
int argc,
const VALUE *argv,
int kw_splat)
2202 VALUE block_handler = VM_CF_BLOCK_HANDLER(cfp);
2203 VALUE new_block_handler = 0;
2206 const VALUE *ep = NULL;
2208 int is_lambda = FALSE;
2211 if (block_handler != VM_BLOCK_HANDLER_NONE) {
2213 switch (vm_block_handler_type(block_handler)) {
2214 case block_handler_type_iseq:
2215 captured = VM_BH_TO_CAPT_BLOCK(block_handler);
2216 new_captured = *captured;
2217 new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
2219 case block_handler_type_ifunc:
2220 captured = VM_BH_TO_CAPT_BLOCK(block_handler);
2221 new_captured = *captured;
2222 new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
2224 case block_handler_type_proc:
2226 VALUE procval = VM_BH_TO_PROC(block_handler);
2228 GetProcPtr(procval, po);
2229 is_lambda = po->header.is_lambda;
2230 if (po->header.is_refined) proc_cref = rb_proc_refinements_cref_for_call(procval);
2231 block_handler = vm_block_to_block_handler(&po->block);
2234 case block_handler_type_symbol:
2235 return rb_sym_proc_call(
SYM2ID(VM_BH_TO_SYMBOL(block_handler)),
2236 argc, argv, kw_splat,
2237 VM_BLOCK_HANDLER_NONE);
2240 new_captured.self = self;
2243 VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
2247 cref = vm_cref_push(ec, self, ep, TRUE, singleton);
2249 if (proc_cref && !
NIL_P(CREF_REFINEMENTS(proc_cref))) {
2250 CREF_REFINEMENTS_SET(cref, rb_hash_dup(CREF_REFINEMENTS(proc_cref)));
2251 CREF_REFINED_PROC_SET(cref);
2254 return vm_yield_with_cref(ec, argc, argv, kw_splat, cref, is_lambda);
2258rb_yield_refine_block(
VALUE refinement,
VALUE refinements)
2261 VALUE block_handler = VM_CF_BLOCK_HANDLER(ec->cfp);
2263 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
2264 rb_bug(
"rb_yield_refine_block: an iseq block is required");
2269 const VALUE *
const argv = &new_captured.self;
2270 VALUE new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
2271 const VALUE *ep = captured->ep;
2272 rb_cref_t *cref = vm_cref_push(ec, refinement, ep, TRUE, FALSE);
2273 CREF_REFINEMENTS_SET(cref, refinements);
2274 VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
2275 new_captured.self = refinement;
2276 return vm_yield_with_cref(ec, 0, argv,
RB_NO_KEYWORDS, cref, FALSE);
2284 rb_cref_t *cref = vm_cref_push(GET_EC(), self, NULL, FALSE, singleton);
2287 return eval_string_with_cref(self, src, cref, file, line);
2291specific_eval(
int argc,
const VALUE *argv,
VALUE self,
int singleton,
int kw_splat)
2295 return yield_under(self, singleton, 1, &self, kw_splat);
2313 file = get_eval_default_path();
2316 return eval_under(self, singleton, code, file, line);
2354rb_obj_instance_eval_internal(
int argc,
const VALUE *argv,
VALUE self)
2384rb_obj_instance_exec_internal(
int argc,
const VALUE *argv,
VALUE self)
2460rb_mod_module_eval_internal(
int argc,
const VALUE *argv,
VALUE mod)
2494rb_mod_module_exec_internal(
int argc,
const VALUE *argv,
VALUE mod)
2519uncaught_throw_init(
int argc,
const VALUE *argv,
VALUE exc)
2536uncaught_throw_tag(
VALUE exc)
2549uncaught_throw_value(
VALUE exc)
2562uncaught_throw_to_s(
VALUE exc)
2564 VALUE mesg = rb_attr_get(exc, id_mesg);
2565 VALUE tag = uncaught_throw_tag(exc);
2598 if (tt->tag == tag) {
2612 ec->errinfo = (
VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW);
2613 EC_JUMP_TAG(ec, TAG_THROW);
2625 return rb_yield_0(1, &tag);
2697 enum ruby_tag_type state;
2700 enum ruby_tag_type *
volatile stateptr = stateptr_arg;
2706 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
2708 val = (*func)(tag, data, 1, (
const VALUE *)&tag,
Qnil);
2710 else if (state == TAG_THROW && THROW_DATA_VAL((
struct vm_throw_data *)ec->errinfo) == tag) {
2711 rb_vm_rewind_cfp(ec, saved_cfp);
2712 val = ec->tag->retval;
2726 return vm_catch_protect(t, func, data, stateptr, GET_EC());
2732 enum ruby_tag_type state;
2735 if (state) EC_JUMP_TAG(ec, state);
2742 vars->tbl = rb_ident_hash_new();
2743 RBASIC_CLEAR_CLASS(vars->tbl);
2750 VALUE ary = rb_hash_keys(vars->tbl);
2751 rb_hash_clear(vars->tbl);
2757local_var_list_update(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
2759 if (existing)
return ST_STOP;
2760 *value = (st_data_t)
Qtrue;
2764extern int rb_numparam_id_p(
ID id);
2774 if (rb_numparam_id_p(lid))
return;
2777 rb_hash_stlike_update(vars->tbl,
ID2SYM(lid), local_var_list_update, idx);
2788 if (rb_numparam_id_p(lid)) {
2790 rb_hash_stlike_update(vars->tbl,
ID2SYM(lid), local_var_list_update, idx);
2808rb_f_local_variables(
VALUE _)
2812 rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp));
2815 local_var_list_init(&vars);
2817 if (CFP_ISEQ(cfp)) {
2818 for (i = 0; i < ISEQ_BODY(CFP_ISEQ(cfp))->local_table_size; i++) {
2819 local_var_list_add(&vars, ISEQ_BODY(CFP_ISEQ(cfp))->local_table[i]);
2822 if (!VM_ENV_LOCAL_P(cfp->ep)) {
2824 const VALUE *ep = VM_CF_PREV_EP(cfp);
2826 if (vm_collect_local_variables_in_heap(ep, &vars)) {
2830 while (cfp->ep != ep) {
2831 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
2839 return local_var_list_finish(&vars);
2863rb_f_block_given_p(
VALUE _)
2867 cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
2869 return RBOOL(cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE);
2880rb_f_iterator_p(
VALUE self)
2882 rb_warn_deprecated(
"iterator?",
"block_given?");
2883 return rb_f_block_given_p(self);
2887rb_current_realfilepath(
void)
2891 cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
2894 VALUE path = rb_iseq_realpath(iseq);
2895 if (
RTEST(path))
return path;
2897 path = rb_iseq_path(iseq);
2898 if (path == eval_default_path) {
2904 if (
len > EVAL_LOCATION_MARK_LEN+1) {
2905 const char *
const ptr = RSTRING_PTR(path);
2906 if (ptr[
len - 1] ==
')' &&
2907 memcmp(ptr,
"("EVAL_LOCATION_MARK, EVAL_LOCATION_MARK_LEN+1) == 0) {
2920rb_current_ifunc(
void)
2923 VALUE ifunc = (
VALUE)CFP_ISEQ(GET_EC()->cfp);
2945 VM_METHOD_TYPE_OPTIMIZED, (
void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2947 VM_METHOD_TYPE_OPTIMIZED, (
void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2959 rb_eUncaughtThrow = rb_define_class(
"UncaughtThrowError", rb_eArgError);
2960 rb_define_method(rb_eUncaughtThrow,
"initialize", uncaught_throw_init, -1);
#define RUBY_ASSERT_ALWAYS(expr,...)
A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
#define RUBY_EVENT_C_CALL
A method, written in C, is called.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
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.
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.
#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 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 xmalloc
Old name of ruby_xmalloc.
#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 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.
VALUE rb_eNotImpError
NotImplementedError exception.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
VALUE rb_eNameError
NameError exception.
VALUE rb_eNoMethodError
NoMethodError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_mKernel
Kernel module.
VALUE rb_cObject
Object class.
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.
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...
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_pop(VALUE ary)
Destructively deletes an element from the end of the passed array and returns what was deleted.
VALUE rb_ary_hidden_new(rb_len_t capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_subseq(VALUE ary, rb_len_t beg, rb_len_t len)
Obtains a part of the passed array.
VALUE rb_ary_cat(VALUE ary, const VALUE *train, rb_len_t len)
Destructively appends multiple elements at the end of the array.
#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.
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
#define rb_str_new_cstr(str)
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_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... 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.
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.
int len
Length of the buffer.
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_each(VALUE obj)
This is a shorthand of calling obj.each.
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_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 MEMZERO(p, type, n)
Handy macro to erase a region of memory.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE rb_catch_obj(VALUE q, type *w, VALUE e)
An equivalent of Kernel#catch.
VALUE rb_catch(const char *q, type *w, VALUE e)
An equivalent of Kernel#catch.
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE type(ANYARGS)
ANYARGS-ed function type.
VALUE rb_rescue2(type *q, VALUE w, type *e, VALUE r,...)
An equivalent of rescue clause.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_NONE
The default value for parameters.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_ALL
When the scope is forwarding with the ... parameter.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_POSITIONALS
When the scope is forwarding with the * parameter.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_KEYWORDS
When the scope is forwarding with the ** parameter.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_BLOCK
When the scope is forwarding with the & parameter.
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 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.
pm_parser_t * parser
The parser that will do the actual parsing.
pm_scope_node_t node
The resulting scope node that will hold the generated AST.
pm_options_t * options
The options that will be passed to the parser.
pm_arena_t * arena
The arena allocator for AST-lifetime memory.
pm_index_lookup_table_t index_lookup_table
A flat lookup table mapping constant IDs (or special IDs) to local variable indices.
A generic string type that can have various ownership semantics.
Internal header for Ruby Box.
IFUNC (Internal FUNCtion)
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
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.