summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--bootstraptest/test_literal.rb1
-rw-r--r--compile.c47
3 files changed, 36 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index fffc290..592f7bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/bootstraptest/test_literal.rb b/bootstraptest/test_literal.rb
index fea5bcd..2ef47a5 100644
--- a/bootstraptest/test_literal.rb
+++ b/bootstraptest/test_literal.rb
@@ -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'
diff --git a/compile.c b/compile.c
index 73b761c..3b6a0ed 100644
--- a/compile.c
+++ b/compile.c
@@ -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,