* 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
Родитель 43bbe2841d
Коммит 04e9a81b8e
3 изменённых файлов: 36 добавлений и 19 удалений

Просмотреть файл

@ -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>
* compile.c (compile_array): ignore NODE_ZARRAY.

Просмотреть файл

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

Просмотреть файл

@ -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,23 +1854,33 @@ 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)
{
@ -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,