diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-03 19:35:09 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-03 19:35:09 +0000 |
commit | 04e9a81b8e969dd4827219572880c05e5fbac2f8 (patch) | |
tree | 04b26fb1f94a836e46a16d0be8a0ee3c5910084b /compile.c | |
parent | 43bbe2841daf838111aa3f2687c23506191e76e7 (diff) | |
download | ruby-04e9a81b8e969dd4827219572880c05e5fbac2f8.tar.gz |
* compile.c (compile_array, iseq_compile_each): fix about array
generation in void context. [ruby-dev:31102]
* bootstraptest/test_literal.rb: add a test for above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 47 |
1 files changed, 28 insertions, 19 deletions
@@ -1824,8 +1824,8 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond, } static int -compile_array(rb_iseq_t *iseq, - LINK_ANCHOR *ret, NODE * node_root, VALUE opt_p) +compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root, + VALUE opt_p, int poped) { NODE *node = node_root; int len = node->nd_alen, line = nd_line(node), i=0; @@ -1842,7 +1842,7 @@ compile_array(rb_iseq_t *iseq, if (opt_p && nd_type(node->nd_head) != NODE_LIT) { opt_p = Qfalse; } - COMPILE(anchor, "array element", node->nd_head); + COMPILE_(anchor, "array element", node->nd_head, poped); node = node->nd_next; } } @@ -1854,24 +1854,34 @@ compile_array(rb_iseq_t *iseq, } if (opt_p == Qtrue) { - VALUE ary = rb_ary_new(); - node = node_root; - while (node) { - rb_ary_push(ary, node->nd_head->nd_lit); - node = node->nd_next; - } + if (!poped) { + VALUE ary = rb_ary_new(); + node = node_root; + while (node) { + rb_ary_push(ary, node->nd_head->nd_lit); + node = node->nd_next; + } - iseq_add_mark_object_compile_time(iseq, ary); - ADD_INSN1(ret, nd_line(node_root), duparray, ary); + iseq_add_mark_object_compile_time(iseq, ary); + ADD_INSN1(ret, nd_line(node_root), duparray, ary); + } } else { - ADD_INSN1(anchor, line, newarray, INT2FIX(len)); + if (!poped) { + ADD_INSN1(anchor, line, newarray, INT2FIX(len)); + } APPEND_LIST(ret, anchor); } return len; } static VALUE +compile_array(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root, VALUE opt_p) +{ + return compile_array_(iseq, ret, node_root, opt_p, 0); +} + +static VALUE case_when_optimizable_literal(NODE * node) { if (nd_type(node) == NODE_LIT) { @@ -3618,10 +3628,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) break; } case NODE_ARRAY:{ - compile_array(iseq, ret, node, Qtrue); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } + compile_array_(iseq, ret, node, Qtrue, poped); break; } case NODE_ZARRAY:{ @@ -3952,9 +3959,11 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) break; } case NODE_SPLAT:{ - COMPILE(ret, "splat", node->nd_head); - ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); - break; + COMPILE_(ret, "splat", node->nd_head, poped); + if (!poped) { + ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); + } + break; } case NODE_DEFN:{ VALUE iseqval = NEW_ISEQVAL(node->nd_defn, |