1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
ko1 2007-06-24 10:33:00 +00:00
parent 1757fc9927
commit 59202b7ab8
4 changed files with 73 additions and 61 deletions

View file

@ -1,3 +1,10 @@
Sun Jun 24 19:30:37 2007 Koichi Sasada <ko1@atdot.net>
* 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 <ko1@atdot.net> Sun Jun 24 19:02:33 2007 Koichi Sasada <ko1@atdot.net>
* vm.c, vm_macro.def : remove macro_eval_invoke_cfunc() and * vm.c, vm_macro.def : remove macro_eval_invoke_cfunc() and

View file

@ -41,10 +41,9 @@
#define REG_LFP (REG_CFP->lfp) #define REG_LFP (REG_CFP->lfp)
#define REG_DFP (REG_CFP->dfp) #define REG_DFP (REG_CFP->dfp)
#define RESTORE_REGS() \ #define RESTORE_REGS() do { \
{ \
REG_CFP = th->cfp; \ REG_CFP = th->cfp; \
} } while (0)
#define REG_A reg_a #define REG_A reg_a
#define REG_B reg_b #define REG_B reg_b

64
vm.c
View file

@ -372,6 +372,63 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, int num,
return val; 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 */ /* Env */
static void static void
@ -721,11 +778,14 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv,
th_set_finish_env(th); th_set_finish_env(th);
reg_cfp = th->cfp; reg_cfp = th->cfp;
CHECK_STACK_OVERFLOW(reg_cfp, argc);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
*reg_cfp->sp++ = argv[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); val = th_eval_body(th);
break; break;
} }

View file

@ -2,60 +2,6 @@
/* do not use C++ style comment */ /* 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) MACRO macro_eval_invoke_method(recv, klass, id, num, mn, blockptr)
{ {
/* method missing */ /* method missing */
@ -105,8 +51,8 @@ MACRO macro_eval_invoke_method(recv, klass, id, num, mn, blockptr)
node = mn->nd_body; node = mn->nd_body;
switch (nd_type(node)) { switch (nd_type(node)) {
case RUBY_VM_METHOD_NODE:{ case RUBY_VM_METHOD_NODE:{
macro_eval_invoke_func(node->nd_body, recv, klass, vm_setup_method(th, GET_CFP(), num, blockptr, flag, (VALUE)node->nd_body, recv, klass);
blockptr, num); RESTORE_REGS();
NEXT_INSN(); NEXT_INSN();
} }
case NODE_CFUNC:{ case NODE_CFUNC:{