Modified: MacRuby/branches/experimental/parse.y (1259 => 1260)
--- MacRuby/branches/experimental/parse.y 2009-03-30 03:02:03 UTC (rev 1259)
+++ MacRuby/branches/experimental/parse.y 2009-03-30 11:53:26 UTC (rev 1260)
@@ -2863,11 +2863,11 @@
* #=>
* e.each{|x| a, = x}
*/
- ID id = rb_intern("__i__"); //internal_id();
+ ID id = internal_id();
+ ID *tbl;
NODE *m = NEW_ARGS_AUX(0, 0);
NODE *args, *scope;
-#if 0
if (nd_type($2) == NODE_MASGN) {
/* if args.length == 1 && args[0].kind_of?(Array)
* args = args[0]
@@ -2883,37 +2883,33 @@
NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero),
rb_intern("kind_of?"), NEW_LIST(NEW_LIT(rb_cArray))),
0),
- NEW_DASGN_CURR(id,
- NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)),
- 0),
+ NEW_DASGN_CURR(id,
+ NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)),
+ 0),
node_assign($2, NEW_DVAR(id))));
+
+ args = new_args(m, 0, id, 0, 0);
}
else {
- GC_WB(&m->nd_next, node_assign(NEW_MASGN(NEW_LIST($2), 0), NEW_DVAR(id)));
+ if (nd_type($2) == NODE_LASGN ||
+ nd_type($2) == NODE_DASGN ||
+ nd_type($2) == NODE_DASGN_CURR) {
+ GC_WB(&$2->nd_value, NEW_DVAR(id));
+ m->nd_plen = 1;
+ GC_WB(&m->nd_next, $2);
+ args = new_args(m, 0, 0, 0, 0);
+ }
+ else {
+ GC_WB(&m->nd_next, node_assign(NEW_MASGN(NEW_LIST($2), 0), NEW_DVAR(id)));
+ args = new_args(m, 0, id, 0, 0);
+ }
}
-#endif
- // TODO this doesn't work in multiple iterator variables are
- // passed to 'for'.
+ tbl = ALLOC_N(ID, vtable_size(lvtbl->vars) + 3);
+ tbl[0] = 1; tbl[1] = id;
+ tbl[2] = vtable_size(lvtbl->vars);
+ vtable_tblcpy(tbl+3, lvtbl->vars);
- args = new_args(m, 0, id, 0, 0);
-
- NODE *block = $8;
- if (nd_type(block) != NODE_BLOCK) {
- block = NEW_BLOCK(block);
- }
- NODE *new_block = NEW_BLOCK(NEW_DASGN($2->nd_vid, NEW_DVAR(id)));
- GC_WB(&new_block->nd_next, block);
- $8 = new_block;
-
- int cnt = vtable_size(lvtbl->args) + 1 + vtable_size(lvtbl->vars);
- ID *tbl = ALLOC_N(ID, cnt + 2);
- tbl[0] = vtable_size(lvtbl->args) + 1;
- tbl[1] = id;
- vtable_tblcpy(tbl+2, lvtbl->args);
- tbl[vtable_size(lvtbl->args) + 2] = vtable_size(lvtbl->vars);
- vtable_tblcpy(tbl+vtable_size(lvtbl->args)+3, lvtbl->vars);
-
scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
$$ = NEW_FOR(0, $5, scope);
fixpos($$, $2);
Modified: MacRuby/branches/experimental/spec/frozen/language/for_spec.rb (1259 => 1260)
--- MacRuby/branches/experimental/spec/frozen/language/for_spec.rb 2009-03-30 03:02:03 UTC (rev 1259)
+++ MacRuby/branches/experimental/spec/frozen/language/for_spec.rb 2009-03-30 11:53:26 UTC (rev 1260)
@@ -12,20 +12,18 @@
j.should == 6
end
- # MacRuby TODO: This does not compile yet.
- #
- # it "iterates over an Hash passing each key-value pair to the block" do
- # k = 0
- # l = 0
- #
- # for i, j in { 1 => 10, 2 => 20 }
- # k += i
- # l += j
- # end
- #
- # k.should == 3
- # l.should == 30
- # end
+ it "iterates over an Hash passing each key-value pair to the block" do
+ k = 0
+ l = 0
+
+ for i, j in { 1 => 10, 2 => 20 }
+ k += i
+ l += j
+ end
+
+ k.should == 3
+ l.should == 30
+ end
it "iterates over any object responding to 'each'" do
class XYZ
@@ -41,17 +39,15 @@
j.should == 55
end
- # MacRuby TODO: This does not compile yet.
- #
- # it "allows an instance variable as an iterator name" do
- # m = [1,2,3]
- # n = 0
- # for @var in m
- # n += 1
- # end
- # @var.should == 3
- # n.should == 3
- # end
+ it "allows an instance variable as an iterator name" do
+ m = [1,2,3]
+ n = 0
+ for @var in m
+ n += 1
+ end
+ @var.should == 3
+ n.should == 3
+ end
# TODO: commented out due to a compiler error
#it "allows a class variable as an iterator name" do
@@ -112,12 +108,10 @@
a.should == 123
end
- # MacRuby TODO: This does not compile yet.
- #
- # it "returns expr" do
- # for i in 1..3; end.should == (1..3)
- # for i,j in { 1 => 10, 2 => 20 }; end.should == { 1 => 10, 2 => 20 }
- # end
+ it "returns expr" do
+ for i in 1..3; end.should == (1..3)
+ for i,j in { 1 => 10, 2 => 20 }; end.should == { 1 => 10, 2 => 20 }
+ end
it "breaks out of a loop upon 'break', returning nil" do
j = 0