[macruby-changes] [2506] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun Sep 6 19:54:19 PDT 2009


Revision: 2506
          http://trac.macosforge.org/projects/ruby/changeset/2506
Author:   lsansonetti at apple.com
Date:     2009-09-06 19:54:19 -0700 (Sun, 06 Sep 2009)
Log Message:
-----------
make sure break makes yield return from its scope

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

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2009-09-07 01:52:17 UTC (rev 2505)
+++ MacRuby/trunk/compiler.cpp	2009-09-07 02:54:19 UTC (rev 2506)
@@ -110,6 +110,7 @@
     newString2Func = NULL;
     newString3Func = NULL;
     yieldFunc = NULL;
+    getBrokenFunc = NULL;
     blockEvalFunc = NULL;
     gvarSetFunc = NULL;
     gvarGetFunc = NULL;
@@ -123,7 +124,6 @@
     checkReturnFromBlockFunc = NULL;
     longjmpFunc = NULL;
     setjmpFunc = NULL;
-    popBrokenValue = NULL;
     setScopeFunc = NULL;
     setCurrentClassFunc = NULL;
 
@@ -4847,7 +4847,30 @@
 		params.insert(params.begin(),
 			ConstantInt::get(Type::Int32Ty, argc));
 
-		return compile_protected_call(yieldFunc, params);
+		Value *val = compile_protected_call(yieldFunc, params);
+
+		if (getBrokenFunc == NULL) {
+		    // VALUE rb_vm_pop_broken_value(void)
+		    getBrokenFunc = cast<Function>(module->getOrInsertFunction(
+				"rb_vm_get_broken_value",
+				RubyObjTy, NULL));
+		}
+
+		Value *broken = CallInst::Create(getBrokenFunc, "", bb);
+		Value *is_broken = new ICmpInst(ICmpInst::ICMP_NE, broken,
+			undefVal, "", bb);
+
+		Function *f = bb->getParent();
+		BasicBlock *broken_bb = BasicBlock::Create("broken", f);
+		BasicBlock *next_bb = BasicBlock::Create("", f);
+
+		BranchInst::Create(broken_bb, next_bb, is_broken, bb);
+
+		bb = broken_bb;
+		ReturnInst::Create(broken, bb);
+		
+		bb = next_bb;
+		return val;
 	    }
 	    break;
 

Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h	2009-09-07 01:52:17 UTC (rev 2505)
+++ MacRuby/trunk/compiler.h	2009-09-07 02:54:19 UTC (rev 2506)
@@ -163,6 +163,7 @@
 	Function *newString2Func;
 	Function *newString3Func;
 	Function *yieldFunc;
+	Function *getBrokenFunc;
 	Function *blockEvalFunc;
 	Function *gvarSetFunc;
 	Function *gvarGetFunc;
@@ -176,7 +177,6 @@
 	Function *checkReturnFromBlockFunc;
 	Function *longjmpFunc;
 	Function *setjmpFunc;
-	Function *popBrokenValue;
 	Function *setScopeFunc;
 	Function *setCurrentClassFunc;
 

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2009-09-07 01:52:17 UTC (rev 2505)
+++ MacRuby/trunk/vm.cpp	2009-09-07 02:54:19 UTC (rev 2506)
@@ -4394,6 +4394,13 @@
 
 extern "C"
 VALUE
+rb_vm_get_broken_value(void)
+{
+    return GET_VM()->get_broken_with();
+}
+
+extern "C"
+VALUE
 rb_vm_pop_broken_value(void)
 {
     return GET_VM()->pop_broken_with();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090906/c213cbd6/attachment.html>


More information about the macruby-changes mailing list