From 68e02f2c2cc98e6ab736b3122aafe7a2398642f6 Mon Sep 17 00:00:00 2001 From: ko1 Date: Sun, 24 Jun 2007 07:29:21 +0000 Subject: * vm.c (callee_setup_arg): added. support correct post arg. * vm_macro.def (macro_eval_invoke_func): fix to use callee_setup_arg. * compile.c (set_arguments): adjust for above changes. * compile.c (iseq_compile_each): ditto. * iseq.c (ruby_iseq_disasm): ditto. * yarvcore.h: add rb_iseq_t#post_arg_start and arg_size. * bootstraptest/test_method.rb: add post arg tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm_macro.def | 120 ++++++----------------------------------------------------- 1 file changed, 11 insertions(+), 109 deletions(-) (limited to 'vm_macro.def') diff --git a/vm_macro.def b/vm_macro.def index adeaa52ac6..99351efdc5 100644 --- a/vm_macro.def +++ b/vm_macro.def @@ -2,7 +2,6 @@ /* do not use C++ style comment */ /* */ - MACRO macro_eval_setup_send_arguments(num, blockptr, flag, blockiseq) { if (flag & VM_CALL_ARGS_BLOCKARG_BIT) { @@ -83,115 +82,15 @@ MACRO macro_eval_invoke_cfunc(num, id, recv, klass, mn, blockptr) MACRO macro_eval_invoke_func(niseqval, recv, klass, blockptr, num) { rb_iseq_t *niseq; - VALUE *sp = GET_SP(); - VALUE *rsp = sp - num - 1; - int opt_pc = 0, clear_local_size, i; + int opt_pc, i; + VALUE *rsp = GET_SP() - num; + VALUE *sp; /* TODO: eliminate it */ GetISeqPtr(niseqval, niseq); - clear_local_size = niseq->local_size - num; - - /* simple (only mandatory) arguments */ - if (niseq->arg_simple) { - if (niseq->argc != num) { - rb_raise(rb_eArgError, "%d - wrong number of arguments (%lu for %d)", - 0, (unsigned long)num, niseq->argc); - } - } - else { - /* optional arguments */ - if (niseq->arg_opts) { - int iseq_argc = niseq->argc; - int opts = niseq->arg_opts - 1; - - if (num < iseq_argc || - (niseq->arg_rest == -1 && num > iseq_argc + opts)) { - if (0) { - printf("num: %lu, iseq_argc: %d, opts: %d\n", - (unsigned long)num, iseq_argc, opts); - } - rb_raise(rb_eArgError, - "%d - wrong number of arguments (%lu for %d)", - 1, (unsigned long)num, iseq_argc); - } - - if (0) printf("num: %lu, opts: %d, iseq_argc: %d\n", - (unsigned long)num, opts, iseq_argc); - - if (num - iseq_argc < opts) { - opt_pc = niseq->arg_opt_tbl[num - iseq_argc]; - sp += opts - (num - iseq_argc); - num += opts - (num - iseq_argc); - clear_local_size = niseq->local_size - (iseq_argc + opts); - } - else { - opt_pc = niseq->arg_opt_tbl[opts]; - } - } - - /* rest argument */ - if (niseq->arg_rest != -1) { - int rest = niseq->arg_rest - 1 /* spec val */; - int pack_size = num - rest; - - if (0) { - printf("num: %lu, rest: %d, ps: %d\n", - (unsigned long)num, rest, pack_size); - } - - if (pack_size < 0) { - rb_raise(rb_eArgError, - "%d - wrong number of arguments (%lu for %d)", - 2, (unsigned long)num, rest - niseq->arg_opts); - } - - /* - * def m(x, y, z, *a) (rest: 3) => - * x, y, z, a, b, c (num: 6, pack_size = 3) - * => x, y, z, [a,b,c] (num: 4) - */ - rsp[rest + 1] = rb_ary_new4(pack_size, &rsp[rest + 1]); - sp = &rsp[rest + 1 + 1]; - num = rest + 1; - clear_local_size = niseq->local_size - (rest + 1); - } - - /* block argument */ - if (niseq->arg_block != -1) { - VALUE arg_block_val = Qnil; - - if (!((num == niseq->arg_rest) || - (niseq->arg_opts && num == niseq->argc + niseq->arg_opts - 1) - || num == niseq->argc)) { - - if (0) printf("num: %d, rest: %d, opts: %d, argc: %d\n", - num, niseq->arg_rest, niseq->arg_opts, niseq->argc); - - rb_raise(rb_eArgError, - "%d - wrong number of arguments (%lu for %d)", - 3, (unsigned long)num, niseq->argc); - } - - if (blockptr) { - /* make Proc object */ - if (blockptr->proc == 0) { - rb_proc_t *proc; - reg_cfp->sp = sp; - arg_block_val = th_make_proc(th, GET_CFP(), blockptr); - GetProcPtr(arg_block_val, proc); - blockptr = &proc->block; - } - else { - arg_block_val = blockptr->proc; - } - } - - rsp[1 + niseq->arg_block - 1] = arg_block_val; - sp++; - clear_local_size--; - } - } + opt_pc = callee_setup_arg(th, niseq, num, rsp, &blockptr); + sp = rsp + niseq->arg_size; /* stack overflow check */ if (CHECK_STACK_OVERFLOW(th, GET_CFP(), niseq->stack_max + 0x100)) { @@ -210,7 +109,7 @@ MACRO macro_eval_invoke_func(niseqval, recv, klass, blockptr, num) sp -= rsp - p_rsp; - for (i = 0; i < clear_local_size; i++) { + for (i = 0; i < niseq->local_size - niseq->arg_size; i++) { *sp++ = Qnil; } @@ -219,7 +118,10 @@ MACRO macro_eval_invoke_func(niseqval, recv, klass, blockptr, num) niseq->iseq_encoded + opt_pc, sp, 0, 0); } else { - for (i = 0; i < clear_local_size; i++) { + if (0) printf("local_size: %d, arg_size: %d\n", + niseq->local_size, niseq->arg_size); + + for (i = 0; i < niseq->local_size - niseq->arg_size; i++) { *sp++ = Qnil; } @@ -227,7 +129,7 @@ MACRO macro_eval_invoke_func(niseqval, recv, klass, blockptr, num) FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, niseq->iseq_encoded + opt_pc, sp, 0, 0); - reg_cfp->sp = rsp; + reg_cfp->sp = rsp - 1 /* recv */; } RESTORE_REGS(); -- cgit v1.2.3