[macruby-changes] [3009] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Nov 13 21:19:46 PST 2009


Revision: 3009
          http://trac.macosforge.org/projects/ruby/changeset/3009
Author:   lsansonetti at apple.com
Date:     2009-11-13 21:19:43 -0800 (Fri, 13 Nov 2009)
Log Message:
-----------
fixed a bug in super without argument, it should pass the method's &block argument

Modified Paths:
--------------
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/compiler.h

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2009-11-14 03:48:48 UTC (rev 3008)
+++ MacRuby/trunk/compiler.cpp	2009-11-14 05:19:43 UTC (rev 3009)
@@ -42,6 +42,7 @@
     current_self = NULL;
     current_var_uses = NULL;
     running_block = NULL;
+    current_block_arg = NULL;
     current_block = false;
     current_block_chain = false;
     current_block_node = NULL;
@@ -956,21 +957,23 @@
 }
 
 Value *
-RoxorCompiler::compile_block_create(NODE *node)
+RoxorCompiler::compile_block_get(Value *block_object)
 {
-    if (node != NULL) {
-	if (getBlockFunc == NULL) {
-	    // void *rb_vm_get_block(VALUE obj);
-	    getBlockFunc = cast<Function>
-		(module->getOrInsertFunction("rb_vm_get_block",
-					     PtrTy, RubyObjTy, NULL));
-	}
-
-	std::vector<Value *> params;
-	params.push_back(compile_node(node->nd_body));
-	return compile_protected_call(getBlockFunc, params);
+    if (getBlockFunc == NULL) {
+	// void *rb_vm_get_block(VALUE obj);
+	getBlockFunc = cast<Function>
+	    (module->getOrInsertFunction("rb_vm_get_block",
+					 PtrTy, RubyObjTy, NULL));
     }
 
+    std::vector<Value *> params;
+    params.push_back(block_object);
+    return compile_protected_call(getBlockFunc, params);
+}
+
+Value *
+RoxorCompiler::compile_block_create(void)
+{
     assert(current_block_func != NULL && current_block_node != NULL);
 
     if (prepareBlockFunc == NULL) {
@@ -3116,6 +3119,7 @@
 		    running_block = NULL;
 		}
 
+		current_block_arg = NULL;
 		if (node->nd_tbl != NULL) {
 		    bool has_vars_to_save = false;
 		    int i, args_count = (int)node->nd_tbl[0];
@@ -3142,6 +3146,7 @@
 					    RubyObjTy, NULL));
 			    }
 			    val = CallInst::Create(currentBlockObjectFunc, "", bb);
+			    current_block_arg = val;
 			}
 			Value *slot = new AllocaInst(RubyObjTy, "", bb);
 			new StoreInst(val, slot, bb);
@@ -4197,12 +4202,19 @@
 		Value *blockVal;
 		if (args != NULL && nd_type(args) == NODE_BLOCK_PASS) {
 		    assert(!block_given);
-		    blockVal = compile_block_create(args);
+		    assert(args->nd_body != NULL);
+		    blockVal = compile_block_get(compile_node(args->nd_body));
 		}
 		else {
-		    blockVal = block_given
-			? compile_block_create(NULL)
-			: compile_const_pointer(NULL);
+		    if (block_given) {
+			blockVal = compile_block_create();
+		    }
+		    else if (nd_type(node) == NODE_ZSUPER && current_block_arg != NULL) {
+			blockVal = compile_block_get(current_block_arg);	
+		    }
+		    else {
+			blockVal = compile_const_pointer(NULL);
+		    }
 		}
 		params[4] = blockVal;
 
@@ -5048,7 +5060,7 @@
 		    }
 
 		    params.push_back(compile_sel((is_lambda ? selLambda : selEach)));
-		    params.push_back(compile_block_create(NULL));
+		    params.push_back(compile_block_create());
 		    params.push_back(ConstantInt::get(Int8Ty, (is_lambda ? DISPATCH_FCALL : 0)));
 		    params.push_back(ConstantInt::get(Int32Ty, 0));
 
@@ -5241,7 +5253,7 @@
 		params.push_back(current_self);
 		params.push_back(compile_nsobject());
 		params.push_back(compile_sel(sel));
-		params.push_back(compile_block_create(NULL));
+		params.push_back(compile_block_create());
 		params.push_back(ConstantInt::get(Int8Ty, DISPATCH_FCALL));
 		params.push_back(ConstantInt::get(Int32Ty, 0));
 

Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h	2009-11-14 03:48:48 UTC (rev 3008)
+++ MacRuby/trunk/compiler.h	2009-11-14 05:19:43 UTC (rev 3009)
@@ -122,6 +122,7 @@
 	bool current_block_chain;
 	Value *current_var_uses;
 	Value *running_block;
+	Value *current_block_arg;
 	BasicBlock *begin_bb;
 	// block used in an invoke when an exception occurs
 	BasicBlock *rescue_invoke_bb;
@@ -287,7 +288,8 @@
 	Value *compile_fast_op_call(SEL sel, Value *selfVal, Value *comparedToVal);
 	Value *compile_attribute_assign(NODE *node, Value *extra_val);
 	virtual Value *compile_prepare_block_args(Function *func, int *flags);
-	Value *compile_block_create(NODE *node);
+	Value *compile_block_create(void);
+	Value *compile_block_get(Value *block_object);
 	Value *compile_binding(void);
 	Value *compile_optimized_dispatch_call(SEL sel, int argc,
 		std::vector<Value *> &params);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091113/1d686447/attachment.html>


More information about the macruby-changes mailing list