diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-31 15:48:59 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-31 15:48:59 +0000 |
commit | baabfa3fa22fde3f5b7a93711690b3341bde3501 (patch) | |
tree | 19ee2d5e006a2e84efa2cd71df82daeec72aae13 /compile.c | |
parent | 6b346a7c855bb6c9e5462ac64bad8e04344b1799 (diff) |
compile.c: compile_evstr
* compile.c (compile_evstr): extract from iseq_compile_each.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 40 |
1 files changed, 22 insertions, 18 deletions
@@ -5605,6 +5605,26 @@ compile_return(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, return COMPILE_OK; } +static int +compile_evstr(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped) +{ + CHECK(COMPILE_(ret, "nd_body", node, popped)); + + if (!popped && !all_string_result_p(node)) { + const int line = nd_line(node); + const unsigned int flag = VM_CALL_FCALL; + LABEL *isstr = NEW_LABEL(line); + ADD_INSN(ret, line, dup); + ADD_INSN2(ret, line, branchiftype, INT2FIX(T_STRING), isstr); + LABEL_REF(isstr); + ADD_INSN(ret, line, dup); + ADD_SEND_R(ret, line, idTo_s, INT2FIX(0), NULL, INT2FIX(flag), NULL); + ADD_INSN(ret, line, tostring); + ADD_LABEL(ret, isstr); + } + return COMPILE_OK; +} + static int iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, int popped); /** compile each node @@ -6769,25 +6789,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in } break; } - case NODE_EVSTR:{ - CHECK(COMPILE(ret, "nd_body", node->nd_body)); - - if (popped) { - ADD_INSN(ret, line, pop); - } - else if (!all_string_result_p(node->nd_body)) { - const unsigned int flag = VM_CALL_FCALL; - LABEL *isstr = NEW_LABEL(line); - ADD_INSN(ret, line, dup); - ADD_INSN2(ret, line, branchiftype, INT2FIX(T_STRING), isstr); - LABEL_REF(isstr); - ADD_INSN(ret, line, dup); - ADD_SEND_R(ret, line, idTo_s, INT2FIX(0), NULL, INT2FIX(flag), NULL); - ADD_INSN(ret, line, tostring); - ADD_LABEL(ret, isstr); - } + case NODE_EVSTR: + CHECK(compile_evstr(iseq, ret, node->nd_body, popped)); break; - } case NODE_DREGX:{ compile_dregx(iseq, ret, node); |