ruby-changes:67527
From: Nobuyoshi <ko1@a...>
Date: Wed, 1 Sep 2021 16:17:26 +0900 (JST)
Subject: [ruby-changes:67527] d7bba95eba (master): Extract compile_dots from iseq_compile_each0
https://git.ruby-lang.org/ruby.git/commit/?id=d7bba95eba From d7bba95eba62093b521cd112ff629f5fddb0f0f5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 12 Mar 2017 23:59:20 +0900 Subject: Extract compile_dots from iseq_compile_each0 --- compile.c | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/compile.c b/compile.c index bd2af90..00bc395 100644 --- a/compile.c +++ b/compile.c @@ -8776,6 +8776,32 @@ compile_colon3(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, https://github.com/ruby/ruby/blob/trunk/compile.c#L8776 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 https://github.com/ruby/ruby/blob/trunk/compile.c#L9414 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); -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/