Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make sure break makes yield return from its scope

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2506 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 7da28cbe262b80be1a4a9610ed0aefc1721ab6ff 1 parent e6209ec
Laurent Sansonetti authored
Showing with 33 additions and 3 deletions.
  1. +25 −2 compiler.cpp
  2. +1 −1  compiler.h
  3. +7 −0 vm.cpp
View
27 compiler.cpp
@@ -110,6 +110,7 @@ RoxorCompiler::RoxorCompiler(void)
newString2Func = NULL;
newString3Func = NULL;
yieldFunc = NULL;
+ getBrokenFunc = NULL;
blockEvalFunc = NULL;
gvarSetFunc = NULL;
gvarGetFunc = NULL;
@@ -123,7 +124,6 @@ RoxorCompiler::RoxorCompiler(void)
checkReturnFromBlockFunc = NULL;
longjmpFunc = NULL;
setjmpFunc = NULL;
- popBrokenValue = NULL;
setScopeFunc = NULL;
setCurrentClassFunc = NULL;
@@ -4847,7 +4847,30 @@ RoxorCompiler::compile_node(NODE *node)
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;
View
2  compiler.h
@@ -163,6 +163,7 @@ class RoxorCompiler {
Function *newString2Func;
Function *newString3Func;
Function *yieldFunc;
+ Function *getBrokenFunc;
Function *blockEvalFunc;
Function *gvarSetFunc;
Function *gvarGetFunc;
@@ -176,7 +177,6 @@ class RoxorCompiler {
Function *checkReturnFromBlockFunc;
Function *longjmpFunc;
Function *setjmpFunc;
- Function *popBrokenValue;
Function *setScopeFunc;
Function *setCurrentClassFunc;
View
7 vm.cpp
@@ -4394,6 +4394,13 @@ rb_vm_break(VALUE val)
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();
Please sign in to comment.
Something went wrong with that request. Please try again.