[macruby-changes] [1428] MacRuby/branches/experimental/roxor.cpp

source_changes at macosforge.org source_changes at macosforge.org
Sat Apr 18 18:53:34 PDT 2009


Revision: 1428
          http://trac.macosforge.org/projects/ruby/changeset/1428
Author:   vincent.isambart at gmail.com
Date:     2009-04-18 18:53:34 -0700 (Sat, 18 Apr 2009)
Log Message:
-----------
started refactoring multiple assignment

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

Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-04-19 01:21:07 UTC (rev 1427)
+++ MacRuby/branches/experimental/roxor.cpp	2009-04-19 01:53:34 UTC (rev 1428)
@@ -311,6 +311,7 @@
 	Value *compile_ivar_read(ID vid);
 	Value *compile_ivar_assignment(ID vid, Value *val);
 	Value *compile_cvar_assignment(ID vid, Value *val);
+	Value *compile_multiple_assignment(NODE *node, Value *val);
 	Value *compile_current_class(void);
 	Value *compile_class_path(NODE *node);
 	Value *compile_const(ID id, Value *outer);
@@ -974,6 +975,68 @@
 }
 
 Value *
+RoxorCompiler::compile_multiple_assignment(NODE *node, Value *val)
+{
+    assert(nd_type(node) == NODE_MASGN);
+    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));
+    }
+
+    NODE *lhsn = node->nd_head;
+    assert((lhsn == NULL) || (nd_type(lhsn) == NODE_ARRAY));
+    NODE *l = lhsn;
+    for (int i = 0; l != NULL; ++i) {
+	NODE *ln = l->nd_head;
+
+	std::vector<Value *> params;
+	params.push_back(val);
+	params.push_back(ConstantInt::get(Type::Int32Ty, i));
+	Value *elt = CallInst::Create(rhsnGetFunc, params.begin(),
+		params.end(), "", bb);
+
+	switch (nd_type(ln)) {
+	    case NODE_LASGN:
+	    case NODE_DASGN:
+	    case NODE_DASGN_CURR:
+		{
+		    Value *slot = compile_lvar_slot(ln->nd_vid);
+		    new StoreInst(elt, slot, bb);
+		}
+		break;
+
+	    case NODE_IASGN:
+	    case NODE_IASGN2:
+		compile_ivar_assignment(ln->nd_vid, elt);
+		break;
+
+	    case NODE_CVASGN:
+		compile_cvar_assignment(ln->nd_vid, elt);
+		break;
+
+	    case NODE_ATTRASGN:
+		compile_attribute_assign(ln, elt);
+		break;
+
+	    case NODE_MASGN:
+		compile_multiple_assignment(ln, elt);
+		break; 
+
+	    default:
+		compile_node_error("unimplemented MASGN subnode",
+				   ln);
+	}
+	l = l->nd_next;
+    }
+
+    // TODO: splat and what's after the splat
+
+    return val;
+}
+
+Value *
 RoxorCompiler::compile_block_create(NODE *node)
 {
     if (node != NULL) {
@@ -2947,72 +3010,7 @@
 
 		Value *ary = compile_node(rhsn);
 
-		NODE *lhsn = node->nd_head;
-
-		if (lhsn == NULL) {
-		    // * = 1, 2
-		    return ary;
-		}
-
-		assert(lhsn != NULL);
-		assert(nd_type(lhsn) == NODE_ARRAY);
-
-		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));
-		}
-
-		int i = 0;
-		NODE *l = lhsn;
-		while (l != NULL) {
-		    NODE *ln = l->nd_head;
-
-		    std::vector<Value *> params;
-		    params.push_back(ary);
-		    params.push_back(ConstantInt::get(Type::Int32Ty, i++));
-		    Value *elt = CallInst::Create(rhsnGetFunc, params.begin(),
-			    params.end(), "", bb);
-
-		    switch (nd_type(ln)) {
-			case NODE_LASGN:
-			case NODE_DASGN:
-			case NODE_DASGN_CURR:
-			    {			    
-				Value *slot = compile_lvar_slot(ln->nd_vid);
-				new StoreInst(elt, slot, bb);
-			    }
-			    break;
-
-			case NODE_IASGN:
-			case NODE_IASGN2:
-			    compile_ivar_assignment(ln->nd_vid, elt);
-			    break;
-
-			case NODE_CVASGN:
-			    compile_cvar_assignment(ln->nd_vid, elt);
-			    break;
-
-			case NODE_ATTRASGN:
-			    compile_attribute_assign(ln, elt);
-			    break;
-
-			case NODE_MASGN:
-			    // a,(*b),c = 1, 2, 3; b #=> [2]
-			    // This is a strange case but covered by the
-			    // RubySpecs.
-			    // TODO
-			    break; 
-
-			default:
-			    compile_node_error("unimplemented MASGN subnode",
-					       ln);
-		    }
-		    l = l->nd_next;
-		}
-
-		return ary;
+		return compile_multiple_assignment(node, ary);
 	    }
 	    break;
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090418/acd22b5d/attachment.html>


More information about the macruby-changes mailing list