diff options
author | Nobuyoshi Nakada <[email protected]> | 2017-03-12 23:59:20 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-09-01 15:19:10 +0900 |
commit | d7bba95eba62093b521cd112ff629f5fddb0f0f5 (patch) | |
tree | 26eb81fca2dfe1816548d33566e2ce30ee83e16c /compile.c | |
parent | d58143f3b501bdb0859435bee7589936aa1fef82 (diff) |
Extract compile_dots from iseq_compile_each0
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4795
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 53 |
1 files changed, 30 insertions, 23 deletions
@@ -8776,6 +8776,32 @@ compile_colon3(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, return COMPILE_OK; } +static int +compile_dots(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped, const int excl) +{ + VALUE flag = INT2FIX(excl); + const NODE *b = node->nd_beg; + const NODE *e = node->nd_end; + + if (optimizable_range_item_p(b) && optimizable_range_item_p(e)) { + if (!popped) { + VALUE bv = nd_type(b) == NODE_LIT ? b->nd_lit : Qnil; + VALUE ev = nd_type(e) == NODE_LIT ? e->nd_lit : Qnil; + VALUE val = rb_range_new(bv, ev, excl); + ADD_INSN1(ret, node, putobject, val); + RB_OBJ_WRITTEN(iseq, Qundef, val); + } + } + else { + CHECK(COMPILE_(ret, "min", b, popped)); + CHECK(COMPILE_(ret, "max", e, popped)); + if (!popped) { + ADD_INSN1(ret, node, newrange, flag); + } + } + return COMPILE_OK; +} + static int iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped); /** compile each node @@ -9388,30 +9414,11 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no CHECK(compile_colon3(iseq, ret, node, popped)); break; case NODE_DOT2: - case NODE_DOT3:{ - int excl = type == NODE_DOT3; - VALUE flag = INT2FIX(excl); - const NODE *b = node->nd_beg; - const NODE *e = node->nd_end; - - if (optimizable_range_item_p(b) && optimizable_range_item_p(e)) { - if (!popped) { - VALUE bv = nd_type(b) == NODE_LIT ? b->nd_lit : Qnil; - VALUE ev = nd_type(e) == NODE_LIT ? e->nd_lit : Qnil; - VALUE val = rb_range_new(bv, ev, excl); - ADD_INSN1(ret, node, putobject, val); - RB_OBJ_WRITTEN(iseq, Qundef, val); - } - } - else { - CHECK(COMPILE_(ret, "min", b, popped)); - CHECK(COMPILE_(ret, "max", e, popped)); - if (!popped) { - ADD_INSN1(ret, node, newrange, flag); - } - } + CHECK(compile_dots(iseq, ret, node, popped, FALSE)); + break; + case NODE_DOT3: + CHECK(compile_dots(iseq, ret, node, popped, TRUE)); break; - } case NODE_FLIP2: case NODE_FLIP3:{ LABEL *lend = NEW_LABEL(line); |