49 if ((
void *)(sp + local_size) >= (
void *)cfp) {
57 for (i=0; i < local_size; i++) {
69 cfp->bp_check = sp + 1;
114 err_mess =
rb_sprintf(
"wrong number of arguments (%d for %d)", argc, min);
117 err_mess =
rb_sprintf(
"wrong number of arguments (%d for %d+)", argc, min);
120 err_mess =
rb_sprintf(
"wrong number of arguments (%d for %d..%d)", argc, min, max);
185 return (
NODE *)*svar;
260 rb_bug(
"unexpected back-ref");
278 else if (ep[-1] !=
Qnil) {
279 return (
NODE *)ep[-1];
291 rb_bug(
"rb_vm_get_cref: unreachable");
301 cref->nd_refinements =
Qnil;
302 cref->nd_visi = noex;
311 if (cref->nd_next && cref->nd_next != (
void *) 1 &&
312 !
NIL_P(cref->nd_next->nd_refinements)) {
326 if ((klass = cref->nd_clss) != 0) {
329 cref = cref->nd_next;
343 (klass = cref->nd_clss) != 0) {
346 cref = cref->nd_next;
379 VALUE orig_klass,
ID id,
int is_defined)
383 if (orig_klass ==
Qnil) {
387 VALUE klass = orig_klass;
390 root_cref = root_cref->nd_next;
393 while (cref && cref->nd_next) {
398 klass = cref->nd_clss;
400 cref = cref->nd_next;
410 if (am == klass)
break;
412 if (is_defined)
return 1;
415 goto search_continue;
430 if (root_cref && !
NIL_P(root_cref->nd_clss)) {
461 rb_bug(
"vm_get_cvar_base: no cref");
464 while (cref->nd_next &&
467 cref = cref->nd_next;
469 if (!cref->nd_next) {
470 rb_warn(
"class variable access from toplevel");
495 #ifndef USE_IC_FOR_IVAR
496 #define USE_IC_FOR_IVAR 1
524 if (
st_lookup(iv_index_tbl,
id, &index)) {
525 if ((
long)index < len) {
614 int state = (int)(throw_state & 0xff);
615 int flag = (int)(throw_state & 0x8000);
631 if (cfp->
iseq->
type != ISEQ_TYPE_BLOCK) {
632 if (cfp->
iseq->
type == ISEQ_TYPE_CLASS) {
646 rb_bug(
"VM (throw): can't find break base.");
668 entry->
start < epc && entry->
end >= epc) {
669 if (entry->
cont == epc) {
695 for (i = 0; i < level; i++) {
703 int in_class_frame = 0;
713 if (lep == target_lep && cfp->
iseq->
type == ISEQ_TYPE_CLASS) {
718 if (lep == target_lep) {
722 if (in_class_frame) {
728 while (target_lep != tep) {
729 if (cfp->
ep == tep) {
739 if (cfp->
ep == target_lep && cfp->
iseq->
type == ISEQ_TYPE_METHOD) {
753 rb_bug(
"isns(throw): unsupport throw type");
783 int is_splat = flag & 0x01;
784 rb_num_t space_size = num + is_splat;
792 cfp->
sp += space_size;
802 for (i=0; i<num-len; i++) {
806 for (j=0; i<num; i++, j++) {
807 VALUE v = ptr[len - j - 1];
817 VALUE *bptr = &base[space_size - 1];
819 for (i=0; i<num; i++) {
847 #if OPT_INLINE_METHOD_CACHE
877 #ifndef NO_BIG_INLINE
936 rb_bug(
"check_match: unreachable");
941 #if defined(_MSC_VER) && _MSC_VER < 1300
942 #define CHECK_CMP_NAN(a, b) if (isnan(a) || isnan(b)) return Qfalse;
944 #define CHECK_CMP_NAN(a, b)
981 if (cfp->
iseq->
type == ISEQ_TYPE_METHOD) {
986 #if VM_DEBUG_BP_CHECK
987 if (bp != cfp->bp_check) {
988 fprintf(stderr,
"bp_check: %ld, bp: %ld\n",
991 rb_bug(
"vm_base_ptr: unreachable");
1003 #define SAVE_RESTORE_CI(expr, ci) do { \
1004 int saved_argc = (ci)->argc; rb_block_t *saved_blockptr = (ci)->blockptr; \
1006 (ci)->argc = saved_argc; (ci)->blockptr = saved_blockptr; \
1013 proc = *(--cfp->
sp);
1023 "wrong argument type %s (expected Proc)",
1059 for (i = 0; i < len; i++) {
1060 *cfp->
sp++ = ptr[
i];
1081 VALUE parthash[2] = {0, 0};
1089 *orighash = parthash[1];
1096 VALUE keyword_hash, orig_hash;
1106 orig_argv[argc-1] = orig_hash;
1112 if (
RHASH_TBL(keyword_hash)->num_entries > (
unsigned int) j) {
1121 *kwd = keyword_hash;
1129 const int m = iseq->
argc;
1133 const int orig_argc = ci->
argc;
1134 int argc = orig_argc;
1156 if (!(orig_argc < iseq->arg_post_start)) {
1175 for (i =
argc; i<opts; i++) {
1176 orig_argv[i + m] =
Qnil;
1201 if (blockptr->
proc == 0) {
1208 blockval = blockptr->
proc;
1223 #define VM_CALLEE_SETUP_ARG(th, ci, iseq, argv, is_lambda) \
1224 if (LIKELY((iseq)->arg_simple & 0x01)) { \
1226 if ((ci)->argc != (iseq)->argc) { \
1227 argument_error((iseq), ((ci)->argc), (iseq)->argc, (iseq)->argc); \
1229 (ci)->aux.opt_pc = 0; \
1230 CI_SET_FASTPATH((ci), UNLIKELY((ci)->flag & VM_CALL_TAILCALL) ? vm_call_iseq_setup_tailcall : vm_call_iseq_setup_normal, !(is_lambda) && !((ci)->me->flag & NOEX_PROTECTED)); \
1233 (ci)->aux.opt_pc = vm_callee_setup_arg_complex((th), (ci), (iseq), (argv)); \
1273 cfp->
sp = argv - 1 ;
1292 sp_orig = sp = cfp->
sp;
1299 for (i=0; i < iseq->
arg_size; i++) {
1300 *sp++ = src_argv[
i];
1331 return (*
func)(recv);
1337 return (*
func)(recv, argv[0]);
1343 return (*
func)(recv, argv[0], argv[1]);
1349 return (*
func)(recv, argv[0], argv[1], argv[2]);
1355 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3]);
1361 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4]);
1367 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
1373 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
1379 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
1385 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
1391 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
1397 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]);
1403 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]);
1409 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12]);
1415 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]);
1421 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14]);
1425 #define VM_PROFILE 0
1429 static int vm_profile_counter[4];
1430 #define VM_PROFILE_UP(x) (vm_profile_counter[x]++)
1431 #define VM_PROFILE_ATEXIT() atexit(vm_profile_show_result)
1432 static void vm_profile_show_result(
void)
1434 fprintf(stderr,
"VM Profile results: \n");
1435 fprintf(stderr,
"r->c call: %d\n", vm_profile_counter[0]);
1436 fprintf(stderr,
"r->c popf: %d\n", vm_profile_counter[1]);
1437 fprintf(stderr,
"c->c call: %d\n", vm_profile_counter[2]);
1438 fprintf(stderr,
"r->c popf: %d\n", vm_profile_counter[3]);
1441 #define VM_PROFILE_UP(x)
1442 #define VM_PROFILE_ATEXIT()
1451 int len = cfunc->
argc;
1467 reg_cfp->
sp -= argc + 1;
1469 val = (*cfunc->
invoker)(cfunc->
func, recv, argc, reg_cfp->
sp + 1);
1471 if (reg_cfp != th->
cfp + 1) {
1472 rb_bug(
"vm_call_cfunc - cfp consistency error");
1483 #if OPT_CALL_CFUNC_WITHOUT_FRAME
1493 reg_cfp->
sp -= argc + 1;
1499 if (reg_cfp == th->
cfp) {
1501 rb_bug(
"vm_call_cfunc_latter: passed_ci error (ci: %p, passed_ci: %p)", ci, th->
passed_ci);
1507 rb_bug(
"vm_call_cfunc_latter: cfp consistency error (%p, %p)", reg_cfp, th->
cfp+1);
1533 val = vm_call_cfunc_latter(th, reg_cfp, ci);
1604 cfp->
sp += - ci->
argc - 1;
1620 int i = ci->
argc - 1;
1624 if (ci->
argc == 0) {
1663 int argc = ci->
argc;
1667 cfp->
sp -= argc + 1;
1680 ci_entry.
mid = idMethodMissing;
1700 if (
NIL_P(refinements)) {
1722 }
while (cfp->
iseq != local_iseq);
1736 int enable_fastpath = 1;
1739 start_method_dispatch:
1741 if ((ci->
me->
flag == 0)) {
1742 normal_method_dispatch:
1776 zsuper_method_dispatch:
1784 goto normal_method_dispatch;
1787 goto start_method_dispatch;
1792 case OPTIMIZED_METHOD_TYPE_SEND:
1795 case OPTIMIZED_METHOD_TYPE_CALL:
1799 rb_bug(
"vm_call_method: unsupported optimized method type (%d)",
1808 VALUE refinements = cref ? cref->nd_refinements :
Qnil;
1809 VALUE refinement, defined_class;
1814 if (
NIL_P(refinement)) {
1815 goto no_refinement_dispatch;
1823 goto no_refinement_dispatch;
1829 goto normal_method_dispatch;
1833 no_refinement_dispatch:
1836 goto normal_method_dispatch;
1839 goto zsuper_method_dispatch;
1843 rb_bug(
"vm_call_method: unsupported method type (%d)", ci->
me->
def->
type);
1858 enable_fastpath = 0;
1864 goto normal_method_dispatch;
1871 goto normal_method_dispatch;
1884 if (ci->
mid == idMethodMissing) {
1896 rb_bug(
"vm_call_method: unreachable");
1918 klass =
RBASIC(klass)->klass;
1933 while (iseq && !iseq->
klass) {
1952 while (lcfp->
iseq != iseq) {
1960 if (lcfp->
ep == tep) {
1984 VALUE current_defined_class;
1988 current_defined_class =
GET_CFP()->klass;
1989 if (
NIL_P(current_defined_class)) {
2000 RBASIC(current_defined_class)->klass : current_defined_class;
2003 "self has wrong type to call super in this context: "
2013 "implicit argument passing of super from method defined"
2014 " by define_method() is not supported."
2015 " Specify all arguments explicitly.");
2022 while (iseq && !iseq->
klass) {
2061 else if (argc == 0) {
2069 if (blockargptr->
proc) {
2070 blockarg = blockargptr->
proc;
2087 val = (*ifunc->nd_cfnc) (
arg, ifunc->nd_tval, argc, argv, blockarg);
2100 int argc,
VALUE *argv)
2104 const int m = iseq->
argc;
2108 int rsize = argc > m ? argc - m : 0;
2109 int psize = rsize > len ? len : rsize;
2117 const int opts = iseq->
arg_opts - 1;
2130 printf(
" argc: %d\n", argc);
2131 printf(
" len: %d\n", len);
2132 printf(
"start: %d\n", start);
2133 printf(
"rsize: %d\n", rsize);
2144 MEMMOVE(&argv[start], &argv[m+rsize+osize],
VALUE, psize);
2148 for (i=psize; i<len; i++) {
2149 argv[start +
i] =
Qnil;
2157 int orig_argc,
VALUE *argv,
2161 int argc = orig_argc;
2162 const int m = iseq->
argc;
2193 for (i=argc; i<m; i++) {
2198 const int arg_size = iseq->
arg_size;
2199 if (arg_size < argc) {
2219 for (i=argc; i<r; i++) {
2242 if (blockptr->
proc == 0) {
2246 procval = blockptr->
proc;
2262 printf(
" argc: %d\n", argc);
2263 printf(
"iseq argc: %d\n", iseq->
argc);
2264 printf(
"iseq opts: %d\n", iseq->
arg_opts);
2265 printf(
"iseq rest: %d\n", iseq->
arg_rest);
2267 printf(
"iseq blck: %d\n", iseq->
arg_block);
2269 printf(
" lambda: %s\n", lambda ?
"true" :
"false");
2293 if ((type != ISEQ_TYPE_METHOD && type != ISEQ_TYPE_CLASS) || block == 0) {
2304 const int arg_size = iseq->
arg_size;