* 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
This commit is contained in:
ko1 2007-07-03 19:35:09 +00:00
parent 43bbe2841d
commit 04e9a81b8e
3 changed files with 36 additions and 19 deletions

View File

@ -1,3 +1,10 @@
Wed Jul 4 04:30:32 2007 Koichi Sasada <ko1@atdot.net>
* 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.
Wed Jul 4 04:07:00 2007 Koichi Sasada <ko1@atdot.net> Wed Jul 4 04:07:00 2007 Koichi Sasada <ko1@atdot.net>
* compile.c (compile_array): ignore NODE_ZARRAY. * compile.c (compile_array): ignore NODE_ZARRAY.

View File

@ -112,6 +112,7 @@ assert_equal 'Array', 'a = [obj = Object.new]; a.class'
assert_equal '1', 'a = [obj = Object.new]; a.size' assert_equal '1', 'a = [obj = Object.new]; a.size'
assert_equal 'true', 'a = [obj = Object.new]; a[0] == obj' assert_equal 'true', 'a = [obj = Object.new]; a[0] == obj'
assert_equal '5', 'a = [1,2,3]; a[1] = 5; a[1]' assert_equal '5', 'a = [1,2,3]; a[1] = 5; a[1]'
assert_equal 'bar', '[*:foo];:bar'
# hash # hash
assert_equal 'Hash', '{}.class' assert_equal 'Hash', '{}.class'

View File

@ -1824,8 +1824,8 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond,
} }
static int static int
compile_array(rb_iseq_t *iseq, compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
LINK_ANCHOR *ret, NODE * node_root, VALUE opt_p) VALUE opt_p, int poped)
{ {
NODE *node = node_root; NODE *node = node_root;
int len = node->nd_alen, line = nd_line(node), i=0; 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) { if (opt_p && nd_type(node->nd_head) != NODE_LIT) {
opt_p = Qfalse; opt_p = Qfalse;
} }
COMPILE(anchor, "array element", node->nd_head); COMPILE_(anchor, "array element", node->nd_head, poped);
node = node->nd_next; node = node->nd_next;
} }
} }
@ -1854,23 +1854,33 @@ compile_array(rb_iseq_t *iseq,
} }
if (opt_p == Qtrue) { if (opt_p == Qtrue) {
VALUE ary = rb_ary_new(); if (!poped) {
node = node_root; VALUE ary = rb_ary_new();
while (node) { node = node_root;
rb_ary_push(ary, node->nd_head->nd_lit); while (node) {
node = node->nd_next; rb_ary_push(ary, node->nd_head->nd_lit);
} node = node->nd_next;
}
iseq_add_mark_object_compile_time(iseq, ary); iseq_add_mark_object_compile_time(iseq, ary);
ADD_INSN1(ret, nd_line(node_root), duparray, ary); ADD_INSN1(ret, nd_line(node_root), duparray, ary);
}
} }
else { else {
ADD_INSN1(anchor, line, newarray, INT2FIX(len)); if (!poped) {
ADD_INSN1(anchor, line, newarray, INT2FIX(len));
}
APPEND_LIST(ret, anchor); APPEND_LIST(ret, anchor);
} }
return len; 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 static VALUE
case_when_optimizable_literal(NODE * node) case_when_optimizable_literal(NODE * node)
{ {
@ -3618,10 +3628,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
break; break;
} }
case NODE_ARRAY:{ case NODE_ARRAY:{
compile_array(iseq, ret, node, Qtrue); compile_array_(iseq, ret, node, Qtrue, poped);
if (poped) {
ADD_INSN(ret, nd_line(node), pop);
}
break; break;
} }
case NODE_ZARRAY:{ case NODE_ZARRAY:{
@ -3952,9 +3959,11 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
break; break;
} }
case NODE_SPLAT:{ case NODE_SPLAT:{
COMPILE(ret, "splat", node->nd_head); COMPILE_(ret, "splat", node->nd_head, poped);
ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); if (!poped) {
break; ADD_INSN1(ret, nd_line(node), splatarray, Qfalse);
}
break;
} }
case NODE_DEFN:{ case NODE_DEFN:{
VALUE iseqval = NEW_ISEQVAL(node->nd_defn, VALUE iseqval = NEW_ISEQVAL(node->nd_defn,