diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-24 10:33:00 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-24 10:33:00 +0000 |
commit | 59202b7ab8147f3947900a919fcf82bc5f3e74e7 (patch) | |
tree | 56356944527511a657285f6b175577c552fb8d23 | |
parent | 1757fc9927fe25b761fca9f2391d1982e7a781c3 (diff) |
* insnhelper.h (RESTORE_REGS): add do/while(0) around macro.
* vm.c, vm_macro.def: remove macro_eval_invoke_func() and
add vm_setup_method(). use it instead.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | insnhelper.h | 5 | ||||
-rw-r--r-- | vm.c | 64 | ||||
-rw-r--r-- | vm_macro.def | 58 |
4 files changed, 73 insertions, 61 deletions
@@ -1,3 +1,10 @@ +Sun Jun 24 19:30:37 2007 Koichi Sasada <[email protected]> + + * insnhelper.h (RESTORE_REGS): add do/while(0) around macro. + + * vm.c, vm_macro.def: remove macro_eval_invoke_func() and + add vm_setup_method(). use it instead. + Sun Jun 24 19:02:33 2007 Koichi Sasada <[email protected]> * vm.c, vm_macro.def : remove macro_eval_invoke_cfunc() and diff --git a/insnhelper.h b/insnhelper.h index 2eb071df5f..3801e5a41b 100644 --- a/insnhelper.h +++ b/insnhelper.h @@ -41,10 +41,9 @@ #define REG_LFP (REG_CFP->lfp) #define REG_DFP (REG_CFP->dfp) -#define RESTORE_REGS() \ -{ \ +#define RESTORE_REGS() do { \ REG_CFP = th->cfp; \ -} +} while (0) #define REG_A reg_a #define REG_B reg_b @@ -372,6 +372,63 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, int num, return val; } +static inline void +vm_setup_method(rb_thread_t *th, rb_control_frame_t *cfp, + int argc, rb_block_t *blockptr, VALUE flag, + VALUE iseqval, VALUE recv, VALUE klass) +{ + rb_iseq_t *iseq; + int opt_pc, i; + VALUE *rsp = cfp->sp - argc; + VALUE *sp; + + /* TODO: eliminate it */ + GetISeqPtr(iseqval, iseq); + + opt_pc = callee_setup_arg(th, iseq, argc, rsp, &blockptr); + sp = rsp + iseq->arg_size; + + /* stack overflow check */ + CHECK_STACK_OVERFLOW(cfp, iseq->stack_max + 0x10); + + if (flag & VM_CALL_TAILCALL_BIT) { + VALUE *p_rsp, *p_sp; + cfp = ++th->cfp; /* pop cf */ + p_rsp = th->cfp->sp; + + /* copy arguments */ + for (i=0; i < (sp - rsp); i++) { + p_rsp[i] = rsp[i]; + } + + sp -= rsp - p_rsp; + + /* clear local variables */ + for (i = 0; i < iseq->local_size - iseq->arg_size; i++) { + *sp++ = Qnil; + } + + push_frame(th, iseq, + FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, + iseq->iseq_encoded + opt_pc, sp, 0, 0); + } + else { + if (0) printf("local_size: %d, arg_size: %d\n", + iseq->local_size, iseq->arg_size); + + /* clear local variables */ + for (i = 0; i < iseq->local_size - iseq->arg_size; i++) { + *sp++ = Qnil; + } + + push_frame(th, iseq, + FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, + iseq->iseq_encoded + opt_pc, sp, 0, 0); + + cfp->sp = rsp - 1 /* recv */; + } +} + /* Env */ static void @@ -721,11 +778,14 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv, th_set_finish_env(th); reg_cfp = th->cfp; + + CHECK_STACK_OVERFLOW(reg_cfp, argc); + for (i = 0; i < argc; i++) { *reg_cfp->sp++ = argv[i]; } - macro_eval_invoke_func(body->nd_body, recv, klass, blockptr, - argc); + + vm_setup_method(th, reg_cfp, argc, blockptr, 0, (VALUE)body->nd_body, recv, klass); val = th_eval_body(th); break; } diff --git a/vm_macro.def b/vm_macro.def index cba36a51e6..7f3e366ce2 100644 --- a/vm_macro.def +++ b/vm_macro.def @@ -2,60 +2,6 @@ /* do not use C++ style comment */ /* */ -MACRO macro_eval_invoke_func(niseqval, recv, klass, blockptr, num) -{ - rb_iseq_t *niseq; - int opt_pc, i; - VALUE *rsp = GET_SP() - num; - VALUE *sp; - - /* TODO: eliminate it */ - GetISeqPtr(niseqval, niseq); - - opt_pc = callee_setup_arg(th, niseq, num, rsp, &blockptr); - sp = rsp + niseq->arg_size; - - /* stack overflow check */ - CHECK_STACK_OVERFLOW(GET_CFP(), niseq->stack_max + 0x10); - - if (flag & VM_CALL_TAILCALL_BIT) { - /* copy arguments */ - VALUE *p_rsp, *p_sp; - reg_cfp = ++th->cfp; - p_rsp = th->cfp->sp; - - for (i=0; i < (sp - rsp); i++) { - p_rsp[i] = rsp[i]; - } - - sp -= rsp - p_rsp; - - for (i = 0; i < niseq->local_size - niseq->arg_size; i++) { - *sp++ = Qnil; - } - - push_frame(th, niseq, - FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, - niseq->iseq_encoded + opt_pc, sp, 0, 0); - } - else { - 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; - } - - push_frame(th, niseq, - FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, - niseq->iseq_encoded + opt_pc, sp, 0, 0); - - reg_cfp->sp = rsp - 1 /* recv */; - } - - RESTORE_REGS(); -} - MACRO macro_eval_invoke_method(recv, klass, id, num, mn, blockptr) { /* method missing */ @@ -105,8 +51,8 @@ MACRO macro_eval_invoke_method(recv, klass, id, num, mn, blockptr) node = mn->nd_body; switch (nd_type(node)) { case RUBY_VM_METHOD_NODE:{ - macro_eval_invoke_func(node->nd_body, recv, klass, - blockptr, num); + vm_setup_method(th, GET_CFP(), num, blockptr, flag, (VALUE)node->nd_body, recv, klass); + RESTORE_REGS(); NEXT_INSN(); } case NODE_CFUNC:{ |