14 #include "internal/thread.h"
26 static int vm_collect_local_variables_in_heap(
const VALUE *dfp,
const struct local_var_list *vars);
28 static VALUE rb_eUncaughtThrow;
29 static ID id_result, id_tag, id_value;
30 #define id_mesg idMesg
32 static VALUE send_internal(
int argc,
const VALUE *argv,
VALUE recv, call_type scope);
36 vm_argv_ruby_array(
VALUE *av,
const VALUE *argv,
int *flags,
int *argc,
int kw_splat)
38 *flags |= VM_CALL_ARGS_SPLAT;
49 *flags |= VM_CALL_KW_SPLAT;
61 return vm_call0_cc(ec, recv,
id, argc, argv, &cc, kw_splat);
68 rb_callable_method_entry_with_refinements(
CLASS_OF(recv),
id, NULL);
70 return rb_vm_call0(ec, recv,
id, argc, argv, me, kw_splat);
81 int flags = kw_splat ? VM_CALL_KW_SPLAT : 0;
85 if (UNLIKELY(vm_cc_cme(cc)->def->type == VM_METHOD_TYPE_ISEQ && argc > VM_ARGC_STACK_MAX)) {
86 use_argv = vm_argv_ruby_array(av, argv, &flags, &argc, kw_splat);
91 .ci = &VM_CI_ON_STACK(
id, flags, argc, NULL),
95 .block_handler = vm_passed_block_handler(ec),
101 return vm_call0_body(ec, &calling, use_argv);
107 calling->cc = &VM_CC_ON_STACK(
Qfalse, vm_call_general, {{ 0 }}, cme);
108 return vm_call0_body(ec, calling, argv);
114 ID mid = vm_ci_mid(calling->cd->ci);
121 RUBY_VM_CHECK_INTS(ec);
122 return vm_call0_cme(ec, calling, argv, cme);
126 vm_passed_block_handler_set(ec, calling->block_handler);
127 return method_missing(ec, calling->recv, mid, calling->argc, argv, ex, calling->kw_splat);
137 int len = cfunc->argc;
138 VALUE recv = calling->recv;
139 int argc = calling->argc;
140 ID mid = vm_ci_mid(ci);
141 VALUE block_handler = calling->block_handler;
142 int frame_flags = VM_FRAME_MAGIC_CFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL;
144 if (calling->kw_splat) {
149 frame_flags |= VM_FRAME_FLAG_CFRAME_KW;
153 RUBY_DTRACE_CMETHOD_ENTRY_HOOK(ec, me->owner, me->def->original_id);
158 vm_push_frame(ec, 0, frame_flags, recv,
159 block_handler, (
VALUE)me,
160 0, reg_cfp->sp, 0, 0);
164 val = (*cfunc->invoker)(recv, argc, argv, cfunc->func);
166 CHECK_CFP_CONSISTENCY(
"vm_call0_cfunc_with_frame");
170 RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, me->owner, me->def->original_id);
178 return vm_call0_cfunc_with_frame(ec, calling, argv);
184 if (calling->kw_splat &&
204 switch (vm_cc_cme(cc)->def->type) {
205 case VM_METHOD_TYPE_ISEQ:
210 CHECK_VM_STACK_OVERFLOW(reg_cfp, calling->argc + 1);
211 vm_check_canary(ec, reg_cfp->sp);
213 *reg_cfp->sp++ = calling->recv;
214 for (i = 0; i < calling->argc; i++) {
215 *reg_cfp->sp++ = argv[i];
218 if (ISEQ_BODY(def_iseq_ptr(vm_cc_cme(cc)->def))->param.flags.forwardable) {
219 vm_call_iseq_fwd_setup(ec, reg_cfp, calling);
222 vm_call_iseq_setup(ec, reg_cfp, calling);
224 VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);
227 case VM_METHOD_TYPE_NOTIMPLEMENTED:
228 case VM_METHOD_TYPE_CFUNC:
229 ret = vm_call0_cfunc(ec, calling, argv);
231 case VM_METHOD_TYPE_ATTRSET:
232 vm_call_check_arity(calling, 1, argv);
233 VM_CALL_METHOD_ATTR(ret,
234 rb_ivar_set(calling->recv, vm_cc_cme(cc)->def->body.attr.id, argv[0]),
237 case VM_METHOD_TYPE_IVAR:
238 vm_call_check_arity(calling, 0, argv);
239 VM_CALL_METHOD_ATTR(ret,
240 rb_attr_get(calling->recv, vm_cc_cme(cc)->def->body.attr.id),
243 case VM_METHOD_TYPE_BMETHOD:
244 ret = vm_call_bmethod_body(ec, calling, argv);
246 case VM_METHOD_TYPE_ZSUPER:
248 VALUE klass = RCLASS_ORIGIN(vm_cc_cme(cc)->defined_class);
249 return vm_call0_super(ec, calling, argv, klass, MISSING_SUPER);
251 case VM_METHOD_TYPE_REFINED:
255 if (cme->def->body.refined.orig_me) {
257 return vm_call0_cme(ec, calling, argv, orig_cme);
260 VALUE klass = cme->defined_class;
261 return vm_call0_super(ec, calling, argv, klass, 0);
263 case VM_METHOD_TYPE_ALIAS:
268 if (cme == orig_cme)
rb_bug(
"same!!");
270 if (vm_cc_markable(cc)) {
271 return vm_call0_cme(ec, calling, argv, orig_cme);
278 case VM_METHOD_TYPE_MISSING:
280 vm_passed_block_handler_set(ec, calling->block_handler);
281 return method_missing(ec, calling->recv, vm_ci_mid(ci), calling->argc,
282 argv, MISSING_NOENTRY, calling->kw_splat);
284 case VM_METHOD_TYPE_OPTIMIZED:
285 switch (vm_cc_cme(cc)->def->body.optimized.type) {
286 case OPTIMIZED_METHOD_TYPE_SEND:
287 ret = send_internal(calling->argc, argv, calling->recv, calling->kw_splat ? CALL_FCALL_KW : CALL_FCALL);
289 case OPTIMIZED_METHOD_TYPE_CALL:
292 GetProcPtr(calling->recv, proc);
293 ret = rb_vm_invoke_proc(ec, proc, calling->argc, argv, calling->kw_splat, calling->block_handler);
296 case OPTIMIZED_METHOD_TYPE_STRUCT_AREF:
297 vm_call_check_arity(calling, 0, argv);
298 VM_CALL_METHOD_ATTR(ret,
299 vm_call_opt_struct_aref0(ec, calling),
302 case OPTIMIZED_METHOD_TYPE_STRUCT_ASET:
303 vm_call_check_arity(calling, 1, argv);
304 VM_CALL_METHOD_ATTR(ret,
305 vm_call_opt_struct_aset0(ec, calling, argv[0]),
309 rb_bug(
"vm_call0: unsupported optimized method type (%d)", vm_cc_cme(cc)->def->body.optimized.type);
312 case VM_METHOD_TYPE_UNDEF:
315 rb_bug(
"vm_call0: unsupported method type (%d)", vm_cc_cme(cc)->def->type);
319 RUBY_VM_CHECK_INTS(ec);
326 return rb_vm_call0(ec, recv,
id, argc, argv, me, kw_splat);
332 VALUE recv = ec->cfp->self;
338 if (VM_FRAME_RUBYFRAME_P(cfp)) {
339 rb_bug(
"vm_call_super: should not be reached");
342 klass = RCLASS_ORIGIN(me->defined_class);
344 id = me->def->original_id;
345 me = rb_callable_method_entry(klass,
id);
348 return method_missing(ec, recv,
id, argc, argv, MISSING_SUPER, kw_splat);
350 return rb_vm_call_kw(ec, recv,
id, argc, argv, me, kw_splat);
357 PASS_PASSED_BLOCK_HANDLER_EC(ec);
358 return vm_call_super(ec, argc, argv, kw_splat);
372 if (!ec || !(cfp = ec->cfp)) {
381 if (!rb_ec_raised_p(ec, RAISED_STACKOVERFLOW) &&
382 rb_ec_stack_check(ec)) {
383 rb_ec_raised_set(ec, RAISED_STACKOVERFLOW);
384 rb_ec_stack_overflow(ec, FALSE);
389 rb_check_stack_overflow(
void)
391 #ifndef RB_THREAD_LOCAL_SPECIFIER
392 if (!ruby_current_ec_key)
return;
395 if (ec) stack_check(ec);
398 NORETURN(
static void uncallable_object(
VALUE recv,
ID mid));
403 gccct_hash(
VALUE klass,
ID mid)
405 return (klass >> 3) ^ (
VALUE)mid;
418 vm_search_method_slowpath0(vm->self, &cd, klass);
420 return vm->global_cc_cache_table[index] = cd.cc;
424 scope_to_ci(call_type scope,
ID mid,
int argc,
struct rb_callinfo *ci)
432 flags |= VM_CALL_FCALL;
435 flags |= VM_CALL_VCALL;
438 flags |= VM_CALL_KWARG;
441 flags |= (VM_CALL_KWARG | VM_CALL_FCALL);
444 *ci = VM_CI_ON_STACK(mid, flags, argc, NULL);
454 if (UNLIKELY(!klass)) uncallable_object(recv, mid);
461 unsigned int index = (
unsigned int)(gccct_hash(klass, mid) % VM_GLOBAL_CC_CACHE_TABLE_SIZE);
462 rb_vm_t *vm = rb_ec_vm_ptr(ec);
463 const struct rb_callcache *cc = vm->global_cc_cache_table[index];
466 if (LIKELY(vm_cc_class_check(cc, klass))) {
468 if (LIKELY(!METHOD_ENTRY_INVALIDATED(cme) &&
469 cme->called_id == mid)) {
471 VM_ASSERT(vm_cc_check_cme(cc, rb_callable_method_entry(klass, mid)));
472 RB_DEBUG_COUNTER_INC(gccct_hit);
479 RB_DEBUG_COUNTER_INC(gccct_null);
482 RB_DEBUG_COUNTER_INC(gccct_miss);
483 return gccct_method_search_slowpath(vm, klass, index, ci);
505 call_type call_scope,
VALUE self)
507 enum method_missing_reason call_status;
508 call_type scope = call_scope;
525 scope_to_ci(scope, mid, argc, &ci);
527 const struct rb_callcache *cc = gccct_method_search(ec, recv, mid, &ci);
529 if (scope == CALL_PUBLIC) {
530 RB_DEBUG_COUNTER_INC(call0_public);
534 call_status = rb_method_call_status(ec, cme, scope,
self);
536 if (UNLIKELY(call_status != MISSING_NONE)) {
537 return method_missing(ec, recv, mid, argc, argv, call_status, kw_splat);
539 else if (UNLIKELY(cc_cme != cme)) {
541 return rb_vm_call_kw(ec, recv, mid, argc, argv, cme, kw_splat);
545 RB_DEBUG_COUNTER_INC(call0_other);
546 call_status = rb_method_call_status(ec, cc ? vm_cc_cme(cc) : NULL, scope,
self);
548 if (UNLIKELY(call_status != MISSING_NONE)) {
549 return method_missing(ec, recv, mid, argc, argv, call_status, kw_splat);
554 return vm_call0_cc(ec, recv, mid, argc, argv, cc, kw_splat);
563 unsigned int respond: 1;
564 unsigned int respond_to_missing: 1;
571 check_funcall_exec(
VALUE v)
574 return call_method_entry(args->ec, args->defined_class,
575 args->recv, idMethodMissing,
576 args->cme, args->argc, args->argv, args->kw_splat);
583 int ret = args->respond;
585 switch (method_boundp(args->defined_class, args->mid,
586 BOUND_PRIVATE|BOUND_RESPONDS)) {
591 ret = args->respond_to_missing;
607 return vm_respond_to(ec, klass, recv, mid, TRUE);
613 return rb_method_call_status(ec, me, CALL_FCALL, ec->cfp->self) == MISSING_NONE;
623 ret = basic_obj_respond_to_missing(ec, klass, recv,
625 if (!
RTEST(ret))
return def;
626 args.respond = respond > 0;
627 args.respond_to_missing = !UNDEF_P(ret);
629 cme = callable_method_entry(klass, idMethodMissing, &args.defined_class);
631 if (cme && !METHOD_ENTRY_BASIC(cme)) {
634 new_args[0] =
ID2SYM(mid);
638 VM_ASSERT(argc == 0);
643 ec->method_missing_reason = MISSING_NOENTRY;
648 args.argc = argc + 1;
649 args.argv = new_args;
650 args.kw_splat = kw_splat;
652 check_funcall_failed, (
VALUE)&args,
659 static VALUE rb_check_funcall_default_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def,
int kw_splat);
664 return rb_check_funcall_default_kw(recv, mid, argc, argv,
Qundef, kw_splat);
674 rb_check_funcall_default_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def,
int kw_splat)
676 VM_ASSERT(ruby_thread_has_gvl_p());
681 int respond = check_funcall_respond_to(ec, klass, recv, mid);
686 me = rb_search_method_entry(recv, mid);
687 if (!check_funcall_callable(ec, me)) {
688 VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
689 respond, def, kw_splat);
690 if (UNDEF_P(ret)) ret = def;
694 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
698 rb_check_funcall_default(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE def)
700 return rb_check_funcall_default_kw(recv, mid, argc, argv, def,
RB_NO_KEYWORDS);
704 rb_check_funcall_with_hook_kw(
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
705 rb_check_funcall_hook *hook,
VALUE arg,
int kw_splat)
710 int respond = check_funcall_respond_to(ec, klass, recv, mid);
713 (*hook)(FALSE, recv, mid, argc, argv, arg);
717 me = rb_search_method_entry(recv, mid);
718 if (!check_funcall_callable(ec, me)) {
719 VALUE ret = check_funcall_missing(ec, klass, recv, mid, argc, argv,
720 respond,
Qundef, kw_splat);
721 (*hook)(!UNDEF_P(ret), recv, mid, argc, argv, arg);
725 (*hook)(TRUE, recv, mid, argc, argv, arg);
726 return rb_vm_call_kw(ec, recv, mid, argc, argv, me, kw_splat);
732 #define type_case(t) t: return #t
750 case type_case(
T_NIL);
768 uncallable_object(
VALUE recv,
ID mid)
777 "method '%"PRIsVALUE
"' called on unexpected immediate object (%p)",
778 mname, (
void *)recv);
780 else if ((flags =
RBASIC(recv)->flags) == 0) {
782 "method '%"PRIsVALUE
"' called on terminated object (%p)",
783 mname, (
void *)recv);
787 "method '%"PRIsVALUE
"' called on broken T_?""?""?(0x%02x) object"
788 " (%p flags=0x%"PRIxVALUE
")",
789 mname,
type, (
void *)recv, flags);
793 "method '%"PRIsVALUE
"' called on hidden %s object"
794 " (%p flags=0x%"PRIxVALUE
")",
795 mname, typestr, (
void *)recv, flags);
799 "method '%"PRIsVALUE
"' called on unexpected %s object"
800 " (%p flags=0x%"PRIxVALUE
")",
801 mname, typestr, (
void *)recv, flags);
806 rb_search_method_entry(
VALUE recv,
ID mid)
810 if (!klass) uncallable_object(recv, mid);
811 return rb_callable_method_entry(klass, mid);
814 static inline enum method_missing_reason
817 if (UNLIKELY(UNDEFINED_METHOD_ENTRY_P(me))) {
820 else if (UNLIKELY(me->def->type == VM_METHOD_TYPE_REFINED)) {
821 me = rb_resolve_refined_method_callable(
Qnil, me);
822 if (UNDEFINED_METHOD_ENTRY_P(me))
goto undefined;
825 rb_method_visibility_t visi = METHOD_ENTRY_VISI(me);
828 if (UNLIKELY(visi != METHOD_VISI_PUBLIC)) {
829 if (me->def->original_id == idMethodMissing) {
832 else if (visi == METHOD_VISI_PRIVATE &&
833 scope == CALL_PUBLIC) {
834 return MISSING_PRIVATE;
837 else if (visi == METHOD_VISI_PROTECTED &&
838 scope == CALL_PUBLIC) {
840 VALUE defined_class = me->owner;
842 defined_class =
RBASIC(defined_class)->klass;
846 return MISSING_PROTECTED;
854 return scope == CALL_VCALL ? MISSING_VCALL : MISSING_NOENTRY;
870 rb_call(
VALUE recv,
ID mid,
int argc,
const VALUE *argv, call_type scope)
873 return rb_call0(ec, recv, mid, argc, argv, scope, ec->cfp->self);
877 VALUE obj,
enum method_missing_reason call_status));
919 rb_method_missing(
int argc,
const VALUE *argv,
VALUE obj)
922 raise_method_missing(ec, argc, argv, obj, ec->method_missing_reason);
928 int argc,
const VALUE *argv,
int priv)
930 VALUE name = argv[0];
933 format = rb_fstring_lit(
"undefined method '%1$s' for %3$s%4$s");
937 return rb_nomethod_err_new(format, obj, name, args, priv);
940 return rb_name_err_new(format, obj, name);
946 enum method_missing_reason last_call_status)
951 if (UNLIKELY(argc == 0)) {
954 else if (UNLIKELY(!
SYMBOL_P(argv[0]))) {
956 rb_raise(e,
"method name must be a Symbol but %"PRIsVALUE
" is given",
962 if (last_call_status & MISSING_PRIVATE) {
963 format = rb_fstring_lit(
"private method '%1$s' called for %3$s%4$s");
965 else if (last_call_status & MISSING_PROTECTED) {
966 format = rb_fstring_lit(
"protected method '%1$s' called for %3$s%4$s");
968 else if (last_call_status & MISSING_VCALL) {
969 format = rb_fstring_lit(
"undefined local variable or method '%1$s' for %3$s%4$s");
972 else if (last_call_status & MISSING_SUPER) {
973 format = rb_fstring_lit(
"super: no superclass method '%1$s' for %3$s%4$s");
977 exc = rb_make_no_method_exception(exc, format, obj, argc, argv,
978 last_call_status & (MISSING_FCALL|MISSING_VCALL));
979 if (!(last_call_status & MISSING_MISSING)) {
980 rb_vm_pop_cfunc_frame();
988 VALUE obj,
int call_status)
990 vm_passed_block_handler_set(ec, VM_BLOCK_HANDLER_NONE);
991 raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
997 VALUE *nargv, result, work, klass;
998 VALUE block_handler = vm_passed_block_handler(ec);
1001 ec->method_missing_reason = call_status;
1003 if (
id == idMethodMissing) {
1012 VM_ASSERT(argc == 0);
1021 if (!klass)
goto missing;
1022 me = rb_callable_method_entry(klass, idMethodMissing);
1023 if (!me || METHOD_ENTRY_BASIC(me))
goto missing;
1024 vm_passed_block_handler_set(ec, block_handler);
1025 result = rb_vm_call_kw(ec, obj, idMethodMissing, argc, argv, me, kw_splat);
1029 raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
1034 rb_funcallv_scope(
VALUE recv,
ID mid,
int argc,
const VALUE *argv, call_type scope)
1039 scope_to_ci(scope, mid, argc, &ci);
1041 const struct rb_callcache *cc = gccct_method_search(ec, recv, mid, &ci);
1042 VALUE self = ec->cfp->self;
1045 LIKELY(rb_method_call_status(ec, vm_cc_cme(cc), scope,
self) == MISSING_NONE)) {
1047 return vm_call0_cc(ec, recv, mid, argc, argv, cc,
false);
1050 return rb_call0(ec, recv, mid, argc, argv, scope,
self);
1060 VM_ASSERT(ruby_thread_has_gvl_p());
1062 return rb_funcallv_scope(recv, mid, argc, argv, CALL_FCALL);
1068 VM_ASSERT(ruby_thread_has_gvl_p());
1070 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_FCALL_KW : CALL_FCALL);
1080 if (argc >= 0x100) {
1082 RBASIC_CLEAR_CLASS(args);
1111 for (i = 0; i < n; i++) {
1112 argv[i] = va_arg(ar,
VALUE);
1133 rb_check_funcall_basic_kw(
VALUE recv,
ID mid,
VALUE ancestor,
int argc,
const VALUE *argv,
int kw_splat)
1138 if (!klass)
return Qundef;
1140 cme = rb_callable_method_entry(klass, mid);
1141 if (cme && METHOD_ENTRY_BASIC(cme) &&
RBASIC_CLASS(cme->defined_class) == ancestor) {
1143 return rb_vm_call0(ec, recv, mid, argc, argv, cme, kw_splat);
1152 return rb_funcallv_scope(recv, mid, argc, argv, CALL_PUBLIC);
1158 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1164 PASS_PASSED_BLOCK_HANDLER();
1171 PASS_PASSED_BLOCK_HANDLER();
1172 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1178 if (!
NIL_P(passed_procval)) {
1179 vm_passed_block_handler_set(GET_EC(), passed_procval);
1188 if (!
NIL_P(passed_procval)) {
1189 vm_passed_block_handler_set(GET_EC(), passed_procval);
1192 return rb_call(recv, mid, argc, argv, kw_splat ? CALL_PUBLIC_KW : CALL_PUBLIC);
1199 if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, prev_cfp))
return NULL;
1200 if (prev_cfp->sp + 1 != argv)
return NULL;
1201 return prev_cfp->sp + 1;
1205 send_internal(
int argc,
const VALUE *argv,
VALUE recv, call_type scope)
1210 VALUE ret, vargv = 0;
1212 int public = scope == CALL_PUBLIC || scope == CALL_PUBLIC_KW;
1218 self = RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp)->self;
1236 VALUE *tmp_argv = current_vm_stack_arg(ec, argv);
1241 else if (argc > 1) {
1251 id = idMethodMissing;
1252 ec->method_missing_reason = MISSING_NOENTRY;
1257 PASS_PASSED_BLOCK_HANDLER_EC(ec);
1258 ret = rb_call0(ec, recv,
id, argc, argv, scope,
self);
1264 send_internal_kw(
int argc,
const VALUE *argv,
VALUE recv, call_type scope)
1269 scope = CALL_PUBLIC_KW;
1272 scope = CALL_FCALL_KW;
1278 return send_internal(argc, argv, recv, scope);
1310 return send_internal_kw(argc, argv, recv, CALL_FCALL);
1328 rb_f_public_send(
int argc,
VALUE *argv,
VALUE recv)
1330 return send_internal_kw(argc, argv, recv, CALL_PUBLIC);
1336 rb_yield_0_kw(
int argc,
const VALUE * argv,
int kw_splat)
1338 return vm_yield(GET_EC(), argc, argv, kw_splat);
1342 rb_yield_0(
int argc,
const VALUE * argv)
1348 rb_yield_1(
VALUE val)
1350 return rb_yield_0(1, &val);
1357 return rb_yield_0(0, NULL);
1360 return rb_yield_0(1, &val);
1364 #undef rb_yield_values
1369 return rb_yield_0(0, 0);
1378 for (i=0; i<n; i++) {
1379 argv[i] = va_arg(args,
VALUE);
1383 return rb_yield_0(n, argv);
1390 return rb_yield_0(argc, argv);
1396 return rb_yield_0_kw(argc, argv, kw_splat);
1426 rb_yield_force_blockarg(
VALUE values)
1428 return vm_yield_force_blockarg(GET_EC(), values);
1434 return vm_yield_with_block(GET_EC(), argc, argv,
1435 NIL_P(blockarg) ? VM_BLOCK_HANDLER_NONE : blockarg,
1446 const struct vm_ifunc *
const ifunc,
1449 enum ruby_tag_type state;
1454 state = EC_EXEC_TAG();
1458 VALUE block_handler;
1462 captured->code.ifunc = ifunc;
1463 block_handler = VM_BH_FROM_IFUNC_BLOCK(captured);
1466 block_handler = VM_CF_BLOCK_HANDLER(cfp);
1468 vm_passed_block_handler_set(ec, block_handler);
1470 retval = (*it_proc) (data1);
1472 else if (state == TAG_BREAK || state == TAG_RETRY) {
1476 if (cfp == escape_cfp) {
1477 rb_vm_rewind_cfp(ec, cfp);
1480 ec->tag->state = TAG_NONE;
1483 if (state == TAG_RETRY)
goto iter_retry;
1484 retval = THROW_DATA_VAL(err);
1487 SDR(); fprintf(stderr,
"%p, %p\n", (
void *)cfp, (
void *)escape_cfp);
1493 EC_JUMP_TAG(ec, state);
1502 return rb_iterate0(it_proc, data1,
1503 bl_proc ? rb_vm_ifunc_proc_new(bl_proc, (
void *)data2) : 0,
1511 return rb_iterate_internal(it_proc, data1, bl_proc, data2);
1523 iterate_method(
VALUE obj)
1528 return rb_call(arg->obj, arg->mid, arg->argc, arg->argv, arg->kw_splat ? CALL_FCALL_KW : CALL_FCALL);
1550 arg.kw_splat = kw_splat;
1551 return rb_iterate_internal(iterate_method, (
VALUE)&arg, bl_proc, data2);
1567 rb_block_call2(
VALUE obj,
ID mid,
int argc,
const VALUE *argv,
1576 arg.kw_splat = flags & 1;
1578 struct vm_ifunc *ifunc = rb_vm_ifunc_proc_new(bl_proc, (
void *)data2);
1579 if (flags & RB_BLOCK_NO_USE_PACKED_ARGS)
1580 ifunc->flags |= IFUNC_YIELD_OPTIMIZABLE;
1582 return rb_iterate0(iterate_method, (
VALUE)&arg, ifunc, GET_EC());
1586 rb_lambda_call(
VALUE obj,
ID mid,
int argc,
const VALUE *argv,
1599 block = rb_vm_ifunc_new(bl_proc, (
void *)data2, min_argc, max_argc);
1600 return rb_iterate0(iterate_method, (
VALUE)&arg, block, GET_EC());
1604 iterate_check_method(
VALUE obj)
1613 rb_check_block_call(
VALUE obj,
ID mid,
int argc,
const VALUE *argv,
1623 return rb_iterate_internal(iterate_check_method, (
VALUE)&arg, bl_proc, data2);
1629 return rb_call(obj, idEach, 0, 0, CALL_FCALL);
1634 #define EVAL_LOCATION_MARK "eval at "
1635 #define EVAL_LOCATION_MARK_LEN (int)rb_strlen_lit(EVAL_LOCATION_MARK)
1638 get_eval_default_path(
void)
1640 int location_lineno;
1641 VALUE location_path = rb_source_location(&location_lineno);
1642 if (!
NIL_P(location_path)) {
1643 return rb_fstring(
rb_sprintf(
"("EVAL_LOCATION_MARK
"%"PRIsVALUE
":%d)",
1644 location_path, location_lineno));
1647 if (!eval_default_path) {
1648 eval_default_path = rb_fstring_lit(
"(eval)");
1649 rb_vm_register_global_object(eval_default_path);
1651 return eval_default_path;
1655 pm_eval_make_iseq(
VALUE src,
VALUE fname,
int line,
1658 const rb_iseq_t *
const parent = vm_block_iseq(base_block);
1660 VALUE name = rb_fstring_lit(
"<compiled>");
1663 int coverage_enabled = ((rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) != 0) ? 1 : 0;
1666 fname = rb_source_location(&line);
1669 if (!UNDEF_P(fname)) {
1670 if (!
NIL_P(fname)) fname = rb_fstring(fname);
1673 fname = get_eval_default_path();
1674 coverage_enabled = 0;
1679 result.
node.coverage_enabled = coverage_enabled;
1682 int scopes_count = 0;
1685 }
while ((iseq = ISEQ_BODY(iseq)->parent_iseq));
1693 for (
int scopes_index = 0; scopes_index < scopes_count; scopes_index++) {
1694 int locals_count = ISEQ_BODY(iseq)->local_table_size;
1698 for (
int local_index = 0; local_index < locals_count; local_index++) {
1700 ID local = ISEQ_BODY(iseq)->local_table[local_index];
1704 size_t length = strlen(name);
1708 if (length == 2 && name[0] ==
'_' && name[1] >=
'1' && name[1] <=
'9') {
1716 iseq = ISEQ_BODY(iseq)->parent_iseq;
1724 VALUE error = pm_parse_string(&result, src, fname, ruby_vm_keep_script_lines ? &script_lines : NULL);
1727 if (error !=
Qnil) {
1728 pm_parse_result_free(&result);
1738 for (
int scopes_index = 0; scopes_index < scopes_count; scopes_index++) {
1743 parent_scope->coverage_enabled = coverage_enabled;
1744 parent_scope->parser = &result.
parser;
1745 parent_scope->index_lookup_table = st_init_numtable();
1747 int locals_count = ISEQ_BODY(iseq)->local_table_size;
1748 parent_scope->local_table_for_iseq_size = locals_count;
1751 for (
int local_index = 0; local_index < locals_count; local_index++) {
1759 st_insert(parent_scope->index_lookup_table, (st_data_t)constant_id, (st_data_t)local_index);
1764 node->previous = parent_scope;
1765 node = parent_scope;
1766 iseq = ISEQ_BODY(iseq)->parent_iseq;
1770 iseq = pm_iseq_new_eval(&result.
node, name, fname,
Qnil, line, parent, 0, &error_state);
1776 pm_scope_node_destroy(prev);
1781 pm_parse_result_free(&result);
1789 rb_exec_event_hook_script_compiled(GET_EC(), iseq, src);
1795 eval_make_iseq(
VALUE src,
VALUE fname,
int line,
1798 if (rb_ruby_prism_p()) {
1799 return pm_eval_make_iseq(src, fname, line, base_block);
1801 const VALUE parser = rb_parser_new();
1802 const rb_iseq_t *
const parent = vm_block_iseq(base_block);
1806 int isolated_depth = 0;
1809 int coverage_enabled = (rb_get_coverage_mode() & COVERAGE_TARGET_EVAL) != 0;
1813 const VALUE *ep = vm_block_ep(base_block);
1816 if (VM_ENV_FLAGS(ep, VM_ENV_FLAG_ISOLATED)) {
1817 isolated_depth = depth;
1820 else if (VM_ENV_LOCAL_P(ep)) {
1823 ep = VM_ENV_PREV_EP(ep);
1829 fname = rb_source_location(&line);
1832 if (!UNDEF_P(fname)) {
1833 if (!
NIL_P(fname)) fname = rb_fstring(fname);
1836 fname = get_eval_default_path();
1837 coverage_enabled = FALSE;
1840 rb_parser_set_context(parser, parent, FALSE);
1841 if (ruby_vm_keep_script_lines) rb_parser_set_script_lines(parser);
1842 ast_value = rb_parser_compile_string_path(parser, fname, src, line);
1844 ast = rb_ruby_ast_data_get(ast_value);
1846 if (ast->body.root) {
1847 ast->body.coverage_enabled = coverage_enabled;
1848 iseq = rb_iseq_new_eval(ast_value,
1849 ISEQ_BODY(parent)->location.label,
1851 parent, isolated_depth);
1853 rb_ast_dispose(ast);
1857 VALUE disasm = rb_iseq_disasm(iseq);
1861 rb_exec_event_hook_script_compiled(GET_EC(), iseq, src);
1878 block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(cfp);
1879 block.as.captured.self =
self;
1880 block.as.captured.code.iseq = cfp->iseq;
1881 block.type = block_type_iseq;
1883 iseq = eval_make_iseq(src, file, line, &block);
1889 if (!cref && block.as.captured.code.val) {
1890 rb_cref_t *orig_cref = vm_get_cref(vm_block_ep(&block));
1891 cref = vm_cref_dup(orig_cref);
1893 vm_set_eval_stack(ec, iseq, cref, &block);
1904 const rb_iseq_t *iseq = eval_make_iseq(src, file, line, &bind->block);
1909 vm_set_eval_stack(ec, iseq, NULL, &bind->block);
1912 if (ISEQ_BODY(iseq)->local_table_size > 0) {
1913 vm_bind_update_env(scope, bind, vm_make_env_object(ec, ec->cfp));
1939 rb_f_eval(
int argc,
const VALUE *argv,
VALUE self)
1941 VALUE src, scope, vfile, vline;
1945 rb_scan_args(argc, argv,
"13", &src, &scope, &vfile, &vline);
1958 return eval_string_with_cref(
self, src, NULL, file, line);
1960 return eval_string_with_scope(scope, src, file, line);
1965 ruby_eval_string_from_file(
const char *str,
const char *filename)
1970 VALUE self = cfp ? cfp->self : rb_vm_top_self();
1971 return eval_string_with_cref(
self,
rb_str_new2(str), NULL, file, 1);
1977 return ruby_eval_string_from_file(str,
"eval");
1981 eval_string_protect(
VALUE str)
1999 eval_string_wrap_protect(
VALUE data)
2002 rb_cref_t *cref = rb_vm_cref_new_toplevel();
2003 cref->klass_or_self = arg->klass;
2012 VALUE self = th->top_self;
2013 VALUE wrapper = th->top_wrapper;
2021 data.top_self = th->top_self;
2022 data.klass = th->top_wrapper;
2027 th->top_self =
self;
2028 th->top_wrapper = wrapper;
2033 else if (state != TAG_NONE) {
2034 EC_JUMP_TAG(th->ec, state);
2042 enum ruby_tag_type state;
2047 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
2053 val = eval_string_with_cref(rb_vm_top_self(), cmd, NULL, 0, 0);
2058 if (state) EC_JUMP_TAG(ec, state);
2065 yield_under(
VALUE self,
int singleton,
int argc,
const VALUE *argv,
int kw_splat)
2069 VALUE block_handler = VM_CF_BLOCK_HANDLER(cfp);
2070 VALUE new_block_handler = 0;
2073 const VALUE *ep = NULL;
2075 int is_lambda = FALSE;
2077 if (block_handler != VM_BLOCK_HANDLER_NONE) {
2079 switch (vm_block_handler_type(block_handler)) {
2080 case block_handler_type_iseq:
2081 captured = VM_BH_TO_CAPT_BLOCK(block_handler);
2082 new_captured = *captured;
2083 new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
2085 case block_handler_type_ifunc:
2086 captured = VM_BH_TO_CAPT_BLOCK(block_handler);
2087 new_captured = *captured;
2088 new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
2090 case block_handler_type_proc:
2092 block_handler = vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler));
2094 case block_handler_type_symbol:
2095 return rb_sym_proc_call(
SYM2ID(VM_BH_TO_SYMBOL(block_handler)),
2096 argc, argv, kw_splat,
2097 VM_BLOCK_HANDLER_NONE);
2100 new_captured.self =
self;
2103 VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
2107 cref = vm_cref_push(ec,
self, ep, TRUE, singleton);
2109 return vm_yield_with_cref(ec, argc, argv, kw_splat, cref, is_lambda);
2113 rb_yield_refine_block(
VALUE refinement,
VALUE refinements)
2116 VALUE block_handler = VM_CF_BLOCK_HANDLER(ec->cfp);
2118 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
2119 rb_bug(
"rb_yield_refine_block: an iseq block is required");
2124 const VALUE *
const argv = &new_captured.self;
2125 VALUE new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
2126 const VALUE *ep = captured->ep;
2127 rb_cref_t *cref = vm_cref_push(ec, refinement, ep, TRUE, FALSE);
2128 CREF_REFINEMENTS_SET(cref, refinements);
2129 VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
2130 new_captured.self = refinement;
2131 return vm_yield_with_cref(ec, 0, argv,
RB_NO_KEYWORDS, cref, FALSE);
2137 eval_under(
VALUE self,
int singleton,
VALUE src,
VALUE file,
int line)
2139 rb_cref_t *cref = vm_cref_push(GET_EC(),
self, NULL, FALSE, singleton);
2142 return eval_string_with_cref(
self, src, cref, file, line);
2146 specific_eval(
int argc,
const VALUE *argv,
VALUE self,
int singleton,
int kw_splat)
2150 return yield_under(
self, singleton, 1, &
self, kw_splat);
2168 file = get_eval_default_path();
2171 return eval_under(
self, singleton, code, file, line);
2209 rb_obj_instance_eval_internal(
int argc,
const VALUE *argv,
VALUE self)
2239 rb_obj_instance_exec_internal(
int argc,
const VALUE *argv,
VALUE self)
2278 rb_mod_module_eval_internal(
int argc,
const VALUE *argv,
VALUE mod)
2312 rb_mod_module_exec_internal(
int argc,
const VALUE *argv,
VALUE mod)
2337 uncaught_throw_init(
int argc,
const VALUE *argv,
VALUE exc)
2354 uncaught_throw_tag(
VALUE exc)
2367 uncaught_throw_value(
VALUE exc)
2380 uncaught_throw_to_s(
VALUE exc)
2383 VALUE tag = uncaught_throw_tag(exc);
2416 if (tt->tag == tag) {
2430 ec->errinfo = (
VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW);
2431 EC_JUMP_TAG(ec, TAG_THROW);
2443 return rb_yield_0(1, &tag);
2498 rb_f_catch(
int argc,
VALUE *argv,
VALUE self)
2515 enum ruby_tag_type state;
2523 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
2525 val = (*func)(tag, data, 1, (
const VALUE *)&tag,
Qnil);
2527 else if (state == TAG_THROW && THROW_DATA_VAL((
struct vm_throw_data *)ec->errinfo) == tag) {
2528 rb_vm_rewind_cfp(ec, saved_cfp);
2529 val = ec->tag->retval;
2543 return vm_catch_protect(t, func, data, stateptr, GET_EC());
2549 enum ruby_tag_type state;
2552 if (state) EC_JUMP_TAG(ec, state);
2559 vars->tbl = rb_ident_hash_new();
2560 RBASIC_CLEAR_CLASS(vars->tbl);
2567 VALUE ary = rb_hash_keys(vars->tbl);
2574 local_var_list_update(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
2576 if (existing)
return ST_STOP;
2577 *value = (st_data_t)
Qtrue;
2587 rb_hash_stlike_update(vars->tbl,
ID2SYM(lid), local_var_list_update, idx);
2605 rb_f_local_variables(
VALUE _)
2609 rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp));
2612 local_var_list_init(&vars);
2615 for (i = 0; i < ISEQ_BODY(cfp->iseq)->local_table_size; i++) {
2616 local_var_list_add(&vars, ISEQ_BODY(cfp->iseq)->local_table[i]);
2619 if (!VM_ENV_LOCAL_P(cfp->ep)) {
2621 const VALUE *ep = VM_CF_PREV_EP(cfp);
2623 if (vm_collect_local_variables_in_heap(ep, &vars)) {
2627 while (cfp->ep != ep) {
2628 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
2636 return local_var_list_finish(&vars);
2660 rb_f_block_given_p(
VALUE _)
2664 cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
2666 return RBOOL(cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE);
2677 rb_f_iterator_p(
VALUE self)
2679 rb_warn_deprecated(
"iterator?",
"block_given?");
2680 return rb_f_block_given_p(
self);
2684 rb_current_realfilepath(
void)
2688 cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
2690 VALUE path = rb_iseq_realpath(cfp->iseq);
2691 if (
RTEST(path))
return path;
2693 path = rb_iseq_path(cfp->iseq);
2694 if (path == eval_default_path) {
2700 if (
len > EVAL_LOCATION_MARK_LEN+1) {
2702 if (
ptr[
len - 1] ==
')' &&
2703 memcmp(
ptr,
"("EVAL_LOCATION_MARK, EVAL_LOCATION_MARK_LEN+1) == 0) {
2716 rb_current_ifunc(
void)
2741 VM_METHOD_TYPE_OPTIMIZED, (
void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2743 VM_METHOD_TYPE_OPTIMIZED, (
void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2756 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.
#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 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 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_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.
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_ary_cat(VALUE ary, const VALUE *train, long len)
Destructively appends multiple elements at the end of the array.
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(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
Obtains a part of the passed 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.
void rb_jump_tag(int state)
This function is to re-throw global escapes.
VALUE rb_hash_clear(VALUE hash)
Swipes everything out of the passed hash table.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
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.
const char * rb_id2name(ID id)
Retrieves the name mapped to the given id.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a Ruby's String instead of C's.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
int len
Length of the buffer.
VALUE rb_str_format(int argc, const VALUE *argv, VALUE fmt)
Formats a string.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
#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.
PRISM_EXPORTED_FUNCTION bool pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count)
Create a new options scope struct.
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line)
Set the line option on the given options struct.
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count)
Allocate and zero out the scopes array on the given options struct.
void pm_constant_id_list_init(pm_constant_id_list_t *list)
Initialize a list of constant ids.
void pm_constant_id_list_free(pm_constant_id_list_t *list)
Free the memory associated with a list of constant ids.
pm_constant_id_t pm_constant_pool_insert_constant(pm_constant_pool_t *pool, const uint8_t *start, size_t length)
Insert a constant into a constant pool from memory that is constant.
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
bool pm_constant_id_list_append(pm_constant_id_list_t *list, pm_constant_id_t id)
Append a constant id to a list of constant ids.
PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string)
Returns the length associated with the string.
void pm_string_constant_init(pm_string_t *string, const char *source, size_t length)
Initialize a constant string that doesn't own its memory source.
PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string)
Returns the start pointer associated with the string.
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*.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
#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.
A scope of locals surrounding the code that is being parsed.
pm_string_t * locals
The names of the locals in the scope.
pm_options_scope_t * scopes
The scopes surrounding the code that is being parsed.
pm_scope_node_t node
The resulting scope node that will hold the generated AST.
pm_parser_t parser
The parser that will do the actual parsing.
pm_options_t options
The options that will be passed to the parser.
pm_constant_pool_t constant_pool
This constant pool keeps all of the constants defined throughout the file so that we can reference th...
A generic string type that can have various ownership semantics.
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.
void ruby_xfree(void *ptr)
Deallocates a storage instance.
void * ruby_xcalloc(size_t nelems, size_t elemsiz)
Identical to ruby_xmalloc2(), except it returns a zero-filled storage instance.