summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-31 15:48:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-31 15:48:59 +0000
commitbaabfa3fa22fde3f5b7a93711690b3341bde3501 (patch)
tree19ee2d5e006a2e84efa2cd71df82daeec72aae13 /compile.c
parent6b346a7c855bb6c9e5462ac64bad8e04344b1799 (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.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/compile.c b/compile.c
index 786b055079..957737236d 100644
--- a/compile.c
+++ b/compile.c
@@ -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);