From 10e9a1a167ea9a3359250c7040c2f61530946d68 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 19 Dec 2014 19:45:20 +0900 Subject: now retrieves number of arguments of blocks from OP_ENTER op code; close #2671 --- mrbgems/mruby-eval/src/eval.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'mrbgems/mruby-eval/src/eval.c') diff --git a/mrbgems/mruby-eval/src/eval.c b/mrbgems/mruby-eval/src/eval.c index bad084dd6..4a523018b 100644 --- a/mrbgems/mruby-eval/src/eval.c +++ b/mrbgems/mruby-eval/src/eval.c @@ -56,16 +56,11 @@ search_variable(mrb_state *mrb, mrb_sym vsym, int bnest) } static mrb_bool -potential_upvar_p(struct mrb_locals *lv, uint16_t v, uint16_t nlocals) +potential_upvar_p(struct mrb_locals *lv, uint16_t v, int argc, uint16_t nlocals) { - int i; - if (v >= nlocals) return FALSE; /* skip arguments */ - for (i=0; iilen; i++) { c = irep->iseq[i]; switch(GET_OPCODE(c)){ + case OP_ENTER: + { + mrb_aspec ax = GETARG_Ax(i); + /* extra 1 means a slot for block */ + argc = MRB_ASPEC_REQ(ax)+MRB_ASPEC_OPT(ax)+MRB_ASPEC_REST(ax)+MRB_ASPEC_POST(ax)+1; + } + break; + case OP_EPUSH: patch_irep(mrb, irep->reps[GETARG_Bx(c)], bnest + 1); break; @@ -106,7 +110,7 @@ patch_irep(mrb_state *mrb, mrb_irep *irep, int bnest) case OP_MOVE: /* src part */ - if (potential_upvar_p(irep->lv, GETARG_B(c), irep->nlocals)) { + if (potential_upvar_p(irep->lv, GETARG_B(c), argc, irep->nlocals)) { mrb_code arg = search_variable(mrb, irep->lv[GETARG_B(c) - 1].name, bnest); if (arg != 0) { /* must replace */ @@ -114,7 +118,7 @@ patch_irep(mrb_state *mrb, mrb_irep *irep, int bnest) } } /* dst part */ - if (potential_upvar_p(irep->lv, GETARG_A(c), irep->nlocals)) { + if (potential_upvar_p(irep->lv, GETARG_A(c), argc, irep->nlocals)) { mrb_code arg = search_variable(mrb, irep->lv[GETARG_A(c) - 1].name, bnest); if (arg != 0) { /* must replace */ -- cgit v1.2.3