diff options
author | Nobuyoshi Nakada <[email protected]> | 2017-03-12 19:36:23 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-09-01 15:19:09 +0900 |
commit | 270a674a79a4c62c16e2f619aa3e03bb94215f37 (patch) | |
tree | afa01e58e94eddaf28acf0b01a4f2ced917bbb23 /compile.c | |
parent | a92fdc90da26be883b71e1f225034237991c5929 (diff) |
Extract compile_match from iseq_compile_each0
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4795
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 74 |
1 files changed, 40 insertions, 34 deletions
@@ -8661,6 +8661,44 @@ compile_yield(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i return COMPILE_OK; } +static int +compile_match(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped, const enum node_type type) +{ + DECL_ANCHOR(recv); + DECL_ANCHOR(val); + + INIT_ANCHOR(recv); + INIT_ANCHOR(val); + switch ((int)type) { + case NODE_MATCH: + ADD_INSN1(recv, node, putobject, node->nd_lit); + ADD_INSN2(val, node, getspecial, INT2FIX(0), + INT2FIX(0)); + break; + case NODE_MATCH2: + CHECK(COMPILE(recv, "receiver", node->nd_recv)); + CHECK(COMPILE(val, "value", node->nd_value)); + break; + case NODE_MATCH3: + CHECK(COMPILE(recv, "receiver", node->nd_value)); + CHECK(COMPILE(val, "value", node->nd_recv)); + break; + } + + ADD_SEQ(ret, recv); + ADD_SEQ(ret, val); + ADD_SEND(ret, node, idEqTilde, INT2FIX(1)); + + if (node->nd_args) { + compile_named_capture_assign(iseq, ret, node->nd_args); + } + + if (popped) { + ADD_INSN(ret, node, pop); + } + 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 @@ -9019,41 +9057,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no } case NODE_MATCH: case NODE_MATCH2: - case NODE_MATCH3:{ - DECL_ANCHOR(recv); - DECL_ANCHOR(val); - - INIT_ANCHOR(recv); - INIT_ANCHOR(val); - switch (nd_type(node)) { - case NODE_MATCH: - ADD_INSN1(recv, node, putobject, node->nd_lit); - ADD_INSN2(val, node, getspecial, INT2FIX(0), - INT2FIX(0)); - break; - case NODE_MATCH2: - CHECK(COMPILE(recv, "receiver", node->nd_recv)); - CHECK(COMPILE(val, "value", node->nd_value)); - break; - case NODE_MATCH3: - CHECK(COMPILE(recv, "receiver", node->nd_value)); - CHECK(COMPILE(val, "value", node->nd_recv)); - break; - } - - ADD_SEQ(ret, recv); - ADD_SEQ(ret, val); - ADD_SEND(ret, node, idEqTilde, INT2FIX(1)); - - if (node->nd_args) { - compile_named_capture_assign(iseq, ret, node->nd_args); - } - - if (popped) { - ADD_INSN(ret, node, pop); - } + case NODE_MATCH3: + CHECK(compile_match(iseq, ret, node, popped, type)); break; - } case NODE_LIT:{ debugp_param("lit", node->nd_lit); if (!popped) { |