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);
170 return (
NODE *)*svar;
245 rb_bug(
"unexpected back-ref");
263 else if (ep[-1] !=
Qnil) {
264 return (
NODE *)ep[-1];
276 rb_bug(
"rb_vm_get_cref: unreachable");
286 cref->nd_refinements =
Qnil;
287 cref->nd_visi = noex;
296 if (cref->nd_next && cref->nd_next != (
void *) 1 &&
297 !
NIL_P(cref->nd_next->nd_refinements)) {
311 if ((klass = cref->nd_clss) != 0) {
314 cref = cref->nd_next;
328 (klass = cref->nd_clss) != 0) {
331 cref = cref->nd_next;
364 VALUE orig_klass,
ID id,
int is_defined)
368 if (orig_klass ==
Qnil) {
372 VALUE klass = orig_klass;
375 root_cref = root_cref->nd_next;
378 while (cref && cref->nd_next) {
383 klass = cref->nd_clss;
385 cref = cref->nd_next;
395 if (am == klass)
break;
397 if (is_defined)
return 1;
400 goto search_continue;
415 if (root_cref && !
NIL_P(root_cref->nd_clss)) {
446 rb_bug(
"vm_get_cvar_base: no cref");
449 while (cref->nd_next &&
452 cref = cref->nd_next;
454 if (!cref->nd_next) {
455 rb_warn(
"class variable access from toplevel");
480 #ifndef USE_IC_FOR_IVAR
481 #define USE_IC_FOR_IVAR 1
509 if (
st_lookup(iv_index_tbl,
id, &index)) {
510 if ((
long)index < len) {
593 int state = (int)(throw_state & 0xff);
594 int flag = (int)(throw_state & 0x8000);
610 if (cfp->
iseq->
type != ISEQ_TYPE_BLOCK) {
611 if (cfp->
iseq->
type == ISEQ_TYPE_CLASS) {
625 rb_bug(
"VM (throw): can't find break base.");
647 entry->
start < epc && entry->
end >= epc) {
648 if (entry->
cont == epc) {
674 for (i = 0; i < level; i++) {
682 int in_class_frame = 0;
692 if (lep == target_lep && cfp->
iseq->
type == ISEQ_TYPE_CLASS) {
697 if (lep == target_lep) {
701 if (in_class_frame) {
707 while (target_lep != tep) {
708 if (cfp->
ep == tep) {
718 if (cfp->
ep == target_lep && cfp->
iseq->
type == ISEQ_TYPE_METHOD) {
732 rb_bug(
"isns(throw): unsupport throw type");
762 int is_splat = flag & 0x01;
763 rb_num_t space_size = num + is_splat;
772 cfp->
sp += space_size;
782 for (i=0; i<num-len; i++) {
786 for (j=0; i<num; i++, j++) {
787 VALUE v = ptr[len - j - 1];
797 VALUE *bptr = &base[space_size - 1];
799 for (i=0; i<num; i++) {
827 #if OPT_INLINE_METHOD_CACHE
837 #if OPT_INLINE_METHOD_CACHE
856 #ifndef NO_BIG_INLINE
938 rb_bug(
"check_match: unreachable");
943 #if defined(_MSC_VER) && _MSC_VER < 1300
944 #define CHECK_CMP_NAN(a, b) if (isnan(a) || isnan(b)) return Qfalse;
946 #define CHECK_CMP_NAN(a, b)
983 if (cfp->
iseq->
type == ISEQ_TYPE_METHOD) {
988 #if VM_DEBUG_BP_CHECK
989 if (bp != cfp->bp_check) {
990 fprintf(stderr,
"bp_check: %ld, bp: %ld\n",
993 rb_bug(
"vm_base_ptr: unreachable");
1005 #define SAVE_RESTORE_CI(expr, ci) do { \
1006 int saved_argc = (ci)->argc; rb_block_t *saved_blockptr = (ci)->blockptr; \
1008 (ci)->argc = saved_argc; (ci)->blockptr = saved_blockptr; \
1015 proc = *(--cfp->
sp);
1025 "wrong argument type %s (expected Proc)",
1061 for (i = 0; i < len; i++) {
1062 *cfp->
sp++ = ptr[i];
1072 VALUE keyword_hash = 0, orig_hash;
1087 orig_argv[argc-1] = orig_hash;
1094 if (!keyword_hash) {
1101 *kwd = keyword_hash;
1109 const int m = iseq->
argc;
1113 const int orig_argc = ci->
argc;
1114 int argc = orig_argc;
1136 if (!(orig_argc < iseq->arg_post_start)) {
1155 for (i =
argc; i<opts; i++) {
1156 orig_argv[i + m] =
Qnil;
1174 orig_argv[arg_keywords_end - i] =
Qnil;
1186 if (blockptr->
proc == 0) {
1193 blockval = blockptr->
proc;
1266 cfp->
sp = argv - 1 ;
1284 sp_orig = sp = cfp->
sp;
1291 for (i=0; i < iseq->
arg_size; i++) {
1292 *sp++ = src_argv[i];
1323 return (*
func)(recv);
1329 return (*
func)(recv, argv[0]);
1335 return (*
func)(recv, argv[0], argv[1]);
1341 return (*
func)(recv, argv[0], argv[1], argv[2]);
1347 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3]);
1353 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4]);
1359 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
1365 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
1371 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
1377 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
1383 return (*
func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]);
1389 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]);
1395 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]);
1401 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]);
1407 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]);
1413 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]);
1417 #define VM_PROFILE 0
1421 static int vm_profile_counter[4];
1422 #define VM_PROFILE_UP(x) (vm_profile_counter[x]++)
1423 #define VM_PROFILE_ATEXIT() atexit(vm_profile_show_result)
1425 vm_profile_show_result(
void)
1427 fprintf(stderr,
"VM Profile results: \n");
1428 fprintf(stderr,
"r->c call: %d\n", vm_profile_counter[0]);
1429 fprintf(stderr,
"r->c popf: %d\n", vm_profile_counter[1]);
1430 fprintf(stderr,
"c->c call: %d\n", vm_profile_counter[2]);
1431 fprintf(stderr,
"r->c popf: %d\n", vm_profile_counter[3]);
1434 #define VM_PROFILE_UP(x)
1435 #define VM_PROFILE_ATEXIT()
1442 #if VM_DEBUG_VERIFY_METHOD_CACHE
1447 # define METHOD_BUG(t) case VM_METHOD_TYPE_##t: rb_bug("wrong method type: " #t)
1449 METHOD_BUG(ATTRSET);
1451 METHOD_BUG(BMETHOD);
1454 METHOD_BUG(OPTIMIZED);
1455 METHOD_BUG(MISSING);
1456 METHOD_BUG(REFINED);
1471 int len = cfunc->
argc;
1487 reg_cfp->
sp -= argc + 1;
1489 val = (*cfunc->
invoker)(cfunc->
func, recv, argc, reg_cfp->
sp + 1);
1491 if (reg_cfp != th->
cfp + 1) {
1492 rb_bug(
"vm_call_cfunc - cfp consistency error");
1503 #if OPT_CALL_CFUNC_WITHOUT_FRAME
1513 reg_cfp->
sp -= argc + 1;
1519 if (reg_cfp == th->
cfp) {
1521 rb_bug(
"vm_call_cfunc_latter: passed_ci error (ci: %p, passed_ci: %p)", ci, th->
passed_ci);
1527 rb_bug(
"vm_call_cfunc_latter: cfp consistency error (%p, %p)", reg_cfp, th->
cfp+1);
1553 val = vm_call_cfunc_latter(th, reg_cfp, ci);
1618 cfp->
sp += - ci->
argc - 1;
1634 int i = ci->
argc - 1;
1638 if (ci->
argc == 0) {
1677 int argc = ci->
argc;
1681 cfp->
sp -= argc + 1;
1694 ci_entry.
mid = idMethodMissing;
1714 if (
NIL_P(refinements)) {
1736 }
while (cfp->
iseq != local_iseq);
1750 int enable_fastpath = 1;
1753 start_method_dispatch:
1755 if ((ci->
me->
flag == 0)) {
1758 normal_method_dispatch:
1792 zsuper_method_dispatch:
1796 goto start_method_dispatch;
1804 goto normal_method_dispatch;
1807 goto start_method_dispatch;
1812 case OPTIMIZED_METHOD_TYPE_SEND:
1815 case OPTIMIZED_METHOD_TYPE_CALL:
1819 rb_bug(
"vm_call_method: unsupported optimized method type (%d)",
1828 VALUE refinements = cref ? cref->nd_refinements :
Qnil;
1829 VALUE refinement, defined_class;
1834 if (
NIL_P(refinement)) {
1835 goto no_refinement_dispatch;
1843 goto no_refinement_dispatch;
1849 goto start_method_dispatch;
1853 no_refinement_dispatch:
1859 goto start_method_dispatch;
1863 goto zsuper_method_dispatch;
1867 rb_bug(
"vm_call_method: unsupported method type (%d)", ci->
me->
def->
type);
1882 enable_fastpath = 0;
1888 goto normal_method_dispatch;
1895 goto normal_method_dispatch;
1908 if (ci->
mid == idMethodMissing) {
1920 rb_bug(
"vm_call_method: unreachable");
1942 klass =
RBASIC(klass)->klass;
1957 while (iseq && !iseq->
klass) {
1976 while (lcfp->
iseq != iseq) {
1984 if (lcfp->
ep == tep) {
2008 VALUE current_defined_class;
2012 current_defined_class =
GET_CFP()->klass;
2013 if (
NIL_P(current_defined_class)) {
2026 RBASIC(current_defined_class)->klass : current_defined_class;
2029 "self has wrong type to call super in this context: "
2039 "implicit argument passing of super from method defined"
2040 " by define_method() is not supported."
2041 " Specify all arguments explicitly.");
2054 while (iseq && !iseq->
klass) {
2092 else if (argc == 0) {
2100 if (blockargptr->
proc) {
2101 blockarg = blockargptr->
proc;
2113 th->
cfp->
sp, 1, 0, 0);
2115 val = (*ifunc->nd_cfnc) (
arg, ifunc->nd_tval, argc, argv, blockarg);
2128 int argc,
VALUE *argv)
2132 const int m = iseq->
argc;
2136 int rsize = argc > m ? argc - m : 0;
2137 int psize = rsize > len ? len : rsize;
2145 const int opts = iseq->
arg_opts - 1;
2158 printf(
" argc: %d\n", argc);
2159 printf(
" len: %d\n", len);
2160 printf(
"start: %d\n", start);
2161 printf(
"rsize: %d\n", rsize);
2172 MEMMOVE(&argv[start], &argv[m+rsize+osize],
VALUE, psize);
2176 for (i=psize; i<len; i++) {
2177 argv[start + i] =
Qnil;
2185 int orig_argc,
VALUE *argv,
2189 int argc = orig_argc;
2190 const int m = iseq->
argc;
2231 for (i=argc; i<m; i++) {
2236 const int arg_size = iseq->
arg_size;
2237 if (arg_size < argc) {
2257 for (i=argc; i<r; i++) {
2274 argv[arg_keywords_end - i] =
Qnil;
2284 if (blockptr->
proc == 0) {
2288 procval = blockptr->
proc;
2304 printf(
" argc: %d\n", argc);
2305 printf(
"iseq argc: %d\n", iseq->
argc);
2306 printf(
"iseq opts: %d\n", iseq->
arg_opts);
2307 printf(
"iseq rest: %d\n", iseq->
arg_rest);
2309 printf(
"iseq blck: %d\n", iseq->
arg_block);
2311 printf(
" lambda: %s\n", lambda ?
"true" :
"false");
2335 if ((type != ISEQ_TYPE_METHOD && type != ISEQ_TYPE_CLASS) || block == 0) {
2346 const int arg_size = iseq->
arg_size;
2379 rb_bug(
"vm_make_proc_with_iseq: unreachable");
2383 blockptr->
iseq = blockiseq;