[macruby-changes] [1260] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 30 04:53:30 PDT 2009


Revision: 1260
          http://trac.macosforge.org/projects/ruby/changeset/1260
Author:   vincent.isambart at gmail.com
Date:     2009-03-30 04:53:26 -0700 (Mon, 30 Mar 2009)
Log Message:
-----------
'for' now mostly works

I brought a few changes to parse.y from 1.9 and fixed it to work with MR.
I also uncommented the 'for' statements in the specs because they are
now compiling (and most are working fine). There is still one commented
out spec that does not compile (node not implemented).

Modified Paths:
--------------
    MacRuby/branches/experimental/parse.y
    MacRuby/branches/experimental/roxor.cpp
    MacRuby/branches/experimental/spec/frozen/language/for_spec.rb
    MacRuby/branches/experimental/spec/frozen/tags/macruby/language/for_tags.txt

Modified: MacRuby/branches/experimental/parse.y
===================================================================
--- 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/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-03-30 03:02:03 UTC (rev 1259)
+++ MacRuby/branches/experimental/roxor.cpp	2009-03-30 11:53:26 UTC (rev 1260)
@@ -293,6 +293,9 @@
 		       bool do_assert) {
 	    std::map<ID, Value *>::iterator iter = container.find(name);
 	    if (do_assert) {
+#if ROXOR_COMPILER_DEBUG
+		printf("get_var %s\n", rb_id2name(name));
+#endif
 		assert(iter != container.end());
 		return iter->second;
 	    }

Modified: MacRuby/branches/experimental/spec/frozen/language/for_spec.rb
===================================================================
--- 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

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/language/for_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/language/for_tags.txt	2009-03-30 03:02:03 UTC (rev 1259)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/language/for_tags.txt	2009-03-30 11:53:26 UTC (rev 1260)
@@ -1,8 +1,2 @@
-fails:The for expression iterates over an Enumerable passing each element to the block
 fails:The for expression iterates over any object responding to 'each'
-fails:The for expression splats multiple arguments together if there are fewer arguments than values
-fails:The for expression optionally takes a 'do' after the expression
-fails:The for expression allows body begin on the same line if do is used
-fails:The for expression breaks out of a loop upon 'break', returning nil
-fails:The for expression allows 'break' to have an argument which becomes the value of the for expression
-fails:The for expression starts the next iteration with 'next'
\ No newline at end of file
+fails:The for expression splats multiple arguments together if there are fewer arguments than values
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090330/27209716/attachment.html>


More information about the macruby-changes mailing list