diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-16 07:24:53 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-16 07:24:53 +0000 |
commit | 4b6f3bce2502e6bbe0a600aef61c8c129fa2af3e (patch) | |
tree | b5f5a66e14d6a0096fd8bf11bca56ee4db66437c /compile.c | |
parent | 56524df980f431116a00d0a0012700cbd8f4737f (diff) | |
download | ruby-4b6f3bce2502e6bbe0a600aef61c8c129fa2af3e.tar.gz |
node.c: Stop double meaning of NODE_FOR by introducing NODE_FOR_MASGN
NODE_FOR was used both for "for"-statement itself and for
multi-assignment of for-statement (for x, y, in...end).
This change separates the two purposes, NODE_FOR for the former, and
newly introduced NODE_FOR_MASGN for the latter.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 60 |
1 files changed, 28 insertions, 32 deletions
@@ -5019,38 +5019,33 @@ compile_iter(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, in } static int -compile_for(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped) +compile_for_masgn(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped) { + /* massign to var in "for" + * args.length == 1 && Array === (tmp = args[0]) ? tmp : args + */ const int line = nd_line(node); - if (node->nd_var) { - /* massign to var in "for" - * args.length == 1 && Array === (tmp = args[0]) ? tmp : args - */ - const NODE *var = node->nd_var; - LABEL *not_single = NEW_LABEL(nd_line(var)); - LABEL *not_ary = NEW_LABEL(nd_line(var)); - CHECK(COMPILE(ret, "for var", var)); - ADD_INSN(ret, line, dup); - ADD_CALL(ret, line, idLength, INT2FIX(0)); - ADD_INSN1(ret, line, putobject, INT2FIX(1)); - ADD_CALL(ret, line, idEq, INT2FIX(1)); - ADD_INSNL(ret, line, branchunless, not_single); - ADD_INSN(ret, line, dup); - ADD_INSN1(ret, line, putobject, INT2FIX(0)); - ADD_CALL(ret, line, idAREF, INT2FIX(1)); - ADD_INSN1(ret, line, putobject, rb_cArray); - ADD_INSN1(ret, line, topn, INT2FIX(1)); - ADD_CALL(ret, line, idEqq, INT2FIX(1)); - ADD_INSNL(ret, line, branchunless, not_ary); - ADD_INSN(ret, line, swap); - ADD_LABEL(ret, not_ary); - ADD_INSN(ret, line, pop); - ADD_LABEL(ret, not_single); - return COMPILE_OK; - } - else { - return compile_iter(iseq, ret, node, popped); - } + const NODE *var = node->nd_var; + LABEL *not_single = NEW_LABEL(nd_line(var)); + LABEL *not_ary = NEW_LABEL(nd_line(var)); + CHECK(COMPILE(ret, "for var", var)); + ADD_INSN(ret, line, dup); + ADD_CALL(ret, line, idLength, INT2FIX(0)); + ADD_INSN1(ret, line, putobject, INT2FIX(1)); + ADD_CALL(ret, line, idEq, INT2FIX(1)); + ADD_INSNL(ret, line, branchunless, not_single); + ADD_INSN(ret, line, dup); + ADD_INSN1(ret, line, putobject, INT2FIX(0)); + ADD_CALL(ret, line, idAREF, INT2FIX(1)); + ADD_INSN1(ret, line, putobject, rb_cArray); + ADD_INSN1(ret, line, topn, INT2FIX(1)); + ADD_CALL(ret, line, idEqq, INT2FIX(1)); + ADD_INSNL(ret, line, branchunless, not_ary); + ADD_INSN(ret, line, swap); + ADD_LABEL(ret, not_ary); + ADD_INSN(ret, line, pop); + ADD_LABEL(ret, not_single); + return COMPILE_OK; } static int @@ -5560,11 +5555,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in CHECK(compile_loop(iseq, ret, node, popped, type)); break; case NODE_FOR: - CHECK(compile_for(iseq, ret, node, popped)); - break; case NODE_ITER: CHECK(compile_iter(iseq, ret, node, popped)); break; + case NODE_FOR_MASGN: + CHECK(compile_for_masgn(iseq, ret, node, popped)); + break; case NODE_BREAK: CHECK(compile_break(iseq, ret, node, popped)); break; |