diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-20 15:45:01 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-20 15:45:01 +0000 |
commit | a94ede7a5a7b2fbc031557e7b723cb9f61496491 (patch) | |
tree | f029f185614e43c9f55ac59ebe1fc63eda3bfe8e /compile.c | |
parent | e105ee2bedc1a40c66929846198dfb07b536c420 (diff) | |
download | ruby-a94ede7a5a7b2fbc031557e7b723cb9f61496491.tar.gz |
compile.c: branch on block param
* compile.c (compile_branch_condition): replace block param value
in branch conditions with `defined(yield)`, to get rid of
creating proc value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -3367,6 +3367,21 @@ compile_flip_flop(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const nod } static int +local_block_param_p(rb_iseq_t *iseq, ID vid) +{ + int idx = iseq->body->local_iseq->body->local_table_size - get_local_var_idx(iseq, vid); + int level = get_lvar_level(iseq); + return iseq_local_block_param_p(iseq, idx, level); +} + +static void +compile_defined_yield(rb_iseq_t *iseq, LINK_ANCHOR *const ret, int line, VALUE needstr) +{ + ADD_INSN(ret, line, putnil); + ADD_INSN3(ret, line, defined, INT2FIX(DEFINED_YIELD), 0, needstr); +} + +static int compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *cond, LABEL *then_label, LABEL *else_label) { @@ -3414,6 +3429,11 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *co case NODE_DEFINED: CHECK(compile_defined_expr(iseq, ret, cond, Qfalse)); goto branch; + case NODE_LVAR: + if (local_block_param_p(iseq, cond->nd_vid)) { + compile_defined_yield(iseq, ret, nd_line(cond), Qfalse); + goto branch; + } default: CHECK(COMPILE(ret, "branch condition", cond)); branch: @@ -4150,9 +4170,7 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, } case NODE_YIELD: - ADD_INSN(ret, nd_line(node), putnil); - ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_YIELD), 0, - needstr); + compile_defined_yield(iseq, ret, nd_line(node), needstr); return 1; case NODE_BACK_REF: |