Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed AOT compilation of literal ranges (objects should be retained)

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2632 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 14423f11b1491e64d95cb45b47e4cddcec09e7b0 1 parent bb0b28c
Laurent Sansonetti authored
Showing with 28 additions and 12 deletions.
  1. +17 −11 compiler.cpp
  2. +1 −1  compiler.h
  3. +10 −0 range.c
View
28 compiler.cpp
@@ -242,7 +242,8 @@ RoxorCompiler::compile_protected_call(Function *func,
}
void
-RoxorCompiler::compile_single_when_argument(NODE *arg, Value *comparedToVal, BasicBlock *thenBB)
+RoxorCompiler::compile_single_when_argument(NODE *arg, Value *comparedToVal,
+ BasicBlock *thenBB)
{
Value *subnodeVal = compile_node(arg);
Value *condVal;
@@ -289,12 +290,14 @@ RoxorCompiler::compile_boolean_test(Value *condVal, BasicBlock *ifTrueBB,
}
void
-RoxorCompiler::compile_when_arguments(NODE *args, Value *comparedToVal, BasicBlock *thenBB)
+RoxorCompiler::compile_when_arguments(NODE *args, Value *comparedToVal,
+ BasicBlock *thenBB)
{
switch (nd_type(args)) {
case NODE_ARRAY:
while (args != NULL) {
- compile_single_when_argument(args->nd_head, comparedToVal, thenBB);
+ compile_single_when_argument(args->nd_head, comparedToVal,
+ thenBB);
args = args->nd_next;
}
break;
@@ -2666,19 +2669,22 @@ RoxorCompiler::compile_optimized_dispatch_call(SEL sel, int argc,
Instruction *
RoxorCompiler::compile_range(Value *beg, Value *end, bool exclude_end,
- bool add_to_bb)
+ bool retain, bool add_to_bb)
{
if (newRangeFunc == NULL) {
- // VALUE rb_range_new(VALUE beg, VALUE end, int exclude_end);
+ // VALUE rb_range_new2(VALUE beg, VALUE end, int exclude_end,
+ // int retain);
newRangeFunc = cast<Function>(module->getOrInsertFunction(
- "rb_range_new",
- RubyObjTy, RubyObjTy, RubyObjTy, RubyObjTy, NULL));
+ "rb_range_new2",
+ RubyObjTy, RubyObjTy, RubyObjTy, Int32Ty, Int32Ty,
+ NULL));
}
std::vector<Value *> params;
params.push_back(beg);
params.push_back(end);
- params.push_back(exclude_end ? trueVal : falseVal);
+ params.push_back(ConstantInt::get(Int32Ty, exclude_end ? 1 : 0));
+ params.push_back(ConstantInt::get(Int32Ty, retain ? 1 : 0));
if (add_to_bb) {
return compile_protected_call(newRangeFunc, params);
@@ -5045,7 +5051,8 @@ RoxorCompiler::compile_node(NODE *node)
case NODE_CASE:
{
Function *f = bb->getParent();
- BasicBlock *caseMergeBB = BasicBlock::Create(context, "case_merge", f);
+ BasicBlock *caseMergeBB = BasicBlock::Create(context,
+ "case_merge", f);
PHINode *pn = PHINode::Create(RubyObjTy, "case_tmp",
caseMergeBB);
@@ -5382,8 +5389,7 @@ RoxorAOTCompiler::compile_main_function(NODE *node)
Instruction *call = compile_range(
ConstantInt::get(RubyObjTy, beg),
ConstantInt::get(RubyObjTy, end),
- exclude_end,
- false);
+ exclude_end, true, false);
Instruction *assign = new StoreInst(call, gvar, "");
View
2  compiler.h
@@ -314,7 +314,7 @@ class RoxorCompiler {
Value *compile_arity(rb_vm_arity_t &arity);
Instruction *compile_range(Value *beg, Value *end, bool exclude_end,
- bool add_to_bb=true);
+ bool retain=false, bool add_to_bb=true);
Value *compile_literal(VALUE val);
virtual Value *compile_immutable_literal(VALUE val);
virtual Value *compile_global_entry(NODE *node);
View
10 range.c
@@ -69,6 +69,16 @@ rb_range_new(VALUE beg, VALUE end, int exclude_end)
return range;
}
+VALUE
+rb_range_new2(VALUE beg, VALUE end, int exclude_end, int retain)
+{
+ VALUE range = rb_range_new(beg, end, exclude_end);
+ if (retain) {
+ GC_RETAIN(range);
+ }
+ return range;
+}
+
/*
* call-seq:
* Range.new(start, end, exclusive=false) => range
Please sign in to comment.
Something went wrong with that request. Please try again.