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

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 2 22:30:36 PDT 2009


Revision: 1294
          http://trac.macosforge.org/projects/ruby/changeset/1294
Author:   lsansonetti at apple.com
Date:     2009-04-02 22:30:36 -0700 (Thu, 02 Apr 2009)
Log Message:
-----------
implemented class variable assignment in the left side of a multiple assignment

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

Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-04-03 05:14:08 UTC (rev 1293)
+++ MacRuby/branches/experimental/roxor.cpp	2009-04-03 05:30:36 UTC (rev 1294)
@@ -281,6 +281,7 @@
 	Value *compile_optimized_dispatch_call(SEL sel, int argc, std::vector<Value *> &params);
 	Value *compile_ivar_read(ID vid);
 	Value *compile_ivar_assignment(ID vid, Value *val);
+	Value *compile_cvar_assignment(ID vid, Value *val);
 	Value *compile_current_class(void);
 	Value *compile_class_path(NODE *node);
 	Value *compile_const(ID id, Value *outer);
@@ -1043,7 +1044,8 @@
 	// void rb_vm_ivar_set(VALUE obj, ID name, VALUE val, int *slot_cache);
 	setIvarFunc = 
 	    cast<Function>(module->getOrInsertFunction("rb_vm_ivar_set",
-			Type::VoidTy, RubyObjTy, IntTy, RubyObjTy, PtrTy, NULL)); 
+			Type::VoidTy, RubyObjTy, IntTy, RubyObjTy, PtrTy,
+			NULL)); 
     }
 
     std::vector<Value *> params;
@@ -1061,6 +1063,26 @@
 }
 
 Value *
+RoxorCompiler::compile_cvar_assignment(ID name, Value *val)
+{
+    if (cvarSetFunc == NULL) {
+	// VALUE rb_vm_cvar_set(VALUE klass, ID id, VALUE val);
+	cvarSetFunc = cast<Function>(module->getOrInsertFunction(
+		    "rb_vm_cvar_set", 
+		    RubyObjTy, RubyObjTy, IntTy, RubyObjTy, NULL));
+    }
+
+    std::vector<Value *> params;
+
+    params.push_back(compile_current_class());
+    params.push_back(ConstantInt::get(IntTy, (long)name));
+    params.push_back(val);
+
+    return CallInst::Create(cvarSetFunc, params.begin(),
+	    params.end(), "", bb);
+}
+
+Value *
 RoxorCompiler::compile_current_class(void)
 {
     if (current_opened_class == NULL) {
@@ -2589,28 +2611,11 @@
 	    break;
 
 	case NODE_CVASGN:
-	    {
-		assert(node->nd_vid > 0);
-		assert(node->nd_value != NULL);
+	    assert(node->nd_vid > 0);
+	    assert(node->nd_value != NULL);
+	    return compile_cvar_assignment(node->nd_vid,
+		    compile_node(node->nd_value));
 
-		if (cvarSetFunc == NULL) {
-		    // VALUE rb_vm_cvar_set(VALUE klass, ID id, VALUE val);
-		    cvarSetFunc = cast<Function>(module->getOrInsertFunction(
-				"rb_vm_cvar_set", 
-				RubyObjTy, RubyObjTy, IntTy, RubyObjTy, NULL));
-		}
-
-		std::vector<Value *> params;
-
-		params.push_back(compile_current_class());
-		params.push_back(ConstantInt::get(IntTy, (long)node->nd_vid));
-		params.push_back(compile_node(node->nd_value));
-
-		return CallInst::Create(cvarSetFunc, params.begin(),
-			params.end(), "", bb);
-	    }
-	    break;
-
 	case NODE_MASGN:
 	    {
 		NODE *rhsn = node->nd_value;
@@ -2661,6 +2666,10 @@
 			    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;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090402/83847fb2/attachment.html>


More information about the macruby-changes mailing list