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

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 19 23:41:20 PDT 2009


Revision: 1007
          http://trac.macosforge.org/projects/ruby/changeset/1007
Author:   lsansonetti at apple.com
Date:     2009-03-19 23:41:13 -0700 (Thu, 19 Mar 2009)
Log Message:
-----------
do not assume that the right part of a multiple assignment is an array of the same size as the number of operands in the left part

Modified Paths:
--------------
    MacRuby/branches/experimental/roxor.cpp
    MacRuby/branches/experimental/test_roxor.rb

Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-03-20 05:58:52 UTC (rev 1006)
+++ MacRuby/branches/experimental/roxor.cpp	2009-03-20 06:41:13 UTC (rev 1007)
@@ -235,7 +235,7 @@
 	Function *newRangeFunc;
 	Function *newRegexpFunc;
 	Function *strInternFunc;
-	Function *aryGetFunc;
+	Function *rhsnGetFunc;
 	Function *newStringFunc;
 	Function *yieldFunc;
 	Function *gvarSetFunc;
@@ -554,7 +554,7 @@
     newRangeFunc = NULL;
     newRegexpFunc = NULL;
     strInternFunc = NULL;
-    aryGetFunc = NULL;
+    rhsnGetFunc = NULL;
     newStringFunc = NULL;
     yieldFunc = NULL;
     gvarSetFunc = NULL;
@@ -2318,9 +2318,9 @@
 		Value *ary = compile_node(rhsn); // XXX should always build as an array
 		NODE *l = lhsn;
 
-		if (aryGetFunc == NULL) {
-		    // VALUE rb_ary_get_fast(VALUE ary, int offset);
-		    aryGetFunc = cast<Function>(module->getOrInsertFunction("rb_ary_get_fast", 
+		if (rhsnGetFunc == NULL) {
+		    // VALUE rb_vm_rhsn_get(VALUE ary, int offset);
+		    rhsnGetFunc = cast<Function>(module->getOrInsertFunction("rb_vm_rhsn_get", 
 				RubyObjTy, RubyObjTy, Type::Int32Ty, NULL));
 		}
 
@@ -2331,7 +2331,7 @@
 		    std::vector<Value *> params;
 		    params.push_back(ary);
 		    params.push_back(ConstantInt::get(Type::Int32Ty, i++));
-		    Value *elt = CallInst::Create(aryGetFunc, params.begin(), params.end(), "", bb);
+		    Value *elt = CallInst::Create(rhsnGetFunc, params.begin(), params.end(), "", bb);
 
 		    switch (nd_type(ln)) {
 			case NODE_LASGN:
@@ -4324,9 +4324,17 @@
 
 extern "C"
 VALUE
-rb_ary_get_fast(VALUE ary, int offset)
+rb_vm_rhsn_get(VALUE obj, int offset)
 {
-    return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)ary, offset));
+    if (TYPE(obj) == T_ARRAY) {
+	if (offset < RARRAY_LEN(obj)) {
+	    return OC2RB(CFArrayGetValueAtIndex((CFArrayRef)obj, offset));
+	}
+    }
+    else if (offset == 0) {
+	return obj;
+    }
+    return Qnil;
 }
 
 static inline VALUE

Modified: MacRuby/branches/experimental/test_roxor.rb
===================================================================
--- MacRuby/branches/experimental/test_roxor.rb	2009-03-20 05:58:52 UTC (rev 1006)
+++ MacRuby/branches/experimental/test_roxor.rb	2009-03-20 06:41:13 UTC (rev 1007)
@@ -309,6 +309,11 @@
   assert '[1, 2, 3]', "a=[1,2]; x=*a,3; p x"
   assert '[1, 2, 3]', "a=[2]; x=1,*a,3; p x"
 
+  assert ':ok', "a, b, c = 42; p :ok if a == 42 and b == nil and c == nil"
+  assert ':ok', "a, b, c = [1, 2, 3, 4]; p :ok if a == 1 and b == 2 and c == 3"
+  assert ':ok', "a, b, c = [1, 2]; p :ok if a == 1 and b == 2 and c == nil"
+  assert ':ok', "a, b, c = nil; p :ok if a == nil and b == nil and c == nil"
+
   # TODO add more multiple assignments test
 
   assert '42', "a=[20]; a[0] += 22; p a[0]"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090319/c85fa988/attachment.html>


More information about the macruby-changes mailing list