[macruby-changes] [2409] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Aug 28 15:32:41 PDT 2009
Revision: 2409
http://trac.macosforge.org/projects/ruby/changeset/2409
Author: lsansonetti at apple.com
Date: 2009-08-28 15:32:41 -0700 (Fri, 28 Aug 2009)
Log Message:
-----------
added support for AOT compilation of literal ranges
Modified Paths:
--------------
MacRuby/trunk/compiler.cpp
MacRuby/trunk/compiler.h
MacRuby/trunk/include/ruby/intern.h
MacRuby/trunk/range.c
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2009-08-28 21:33:00 UTC (rev 2408)
+++ MacRuby/trunk/compiler.cpp 2009-08-28 22:32:41 UTC (rev 2409)
@@ -197,8 +197,9 @@
return new ICmpInst(ICmpInst::ICMP_EQ, andOp, oneVal, "", bb);
}
-Value *
-RoxorCompiler::compile_protected_call(Function *func, std::vector<Value *> ¶ms)
+Instruction *
+RoxorCompiler::compile_protected_call(Function *func,
+ std::vector<Value *> ¶ms)
{
if (rescue_bb == NULL) {
CallInst *dispatch = CallInst::Create(func,
@@ -206,7 +207,7 @@
params.end(),
"",
bb);
- return cast<Value>(dispatch);
+ return dispatch;
}
else {
BasicBlock *normal_bb = BasicBlock::Create("normal", bb->getParent());
@@ -221,7 +222,7 @@
bb = normal_bb;
- return cast<Value>(dispatch);
+ return dispatch;
}
}
@@ -2631,6 +2632,28 @@
return NULL;
}
+Instruction *
+RoxorCompiler::compile_range(Value *beg, Value *end, bool exclude_end,
+ bool add_to_bb)
+{
+ if (newRangeFunc == NULL) {
+ // VALUE rb_range_new(VALUE beg, VALUE end, int exclude_end);
+ newRangeFunc = cast<Function>(module->getOrInsertFunction(
+ "rb_range_new",
+ RubyObjTy, RubyObjTy, RubyObjTy, RubyObjTy, NULL));
+ }
+
+ std::vector<Value *> params;
+ params.push_back(beg);
+ params.push_back(end);
+ params.push_back(exclude_end ? trueVal : falseVal);
+
+ if (add_to_bb) {
+ return compile_protected_call(newRangeFunc, params);
+ }
+ return CallInst::Create(newRangeFunc, params.begin(), params.end(), "");
+}
+
Value *
RoxorCompiler::compile_literal(VALUE val)
{
@@ -4180,22 +4203,12 @@
case NODE_DOT2:
case NODE_DOT3:
{
- if (newRangeFunc == NULL) {
- // VALUE rb_range_new(VALUE beg, VALUE end, int exclude_end);
- newRangeFunc = cast<Function>(module->getOrInsertFunction("rb_range_new",
- RubyObjTy, RubyObjTy, RubyObjTy, RubyObjTy, NULL));
- }
-
assert(node->nd_beg != NULL);
assert(node->nd_end != NULL);
- std::vector<Value *> params;
- params.push_back(compile_node(node->nd_beg));
- params.push_back(compile_node(node->nd_end));
- params.push_back(nd_type(node) == NODE_DOT2 ? falseVal : trueVal);
-
- return cast<Value>(CallInst::Create(newRangeFunc,
- params.begin(), params.end(), "", bb));
+ return compile_range(compile_node(node->nd_beg),
+ compile_node(node->nd_end),
+ nd_type(node) == NODE_DOT3);
}
break;
@@ -5181,11 +5194,30 @@
break;
default:
- printf("unrecognized literal `%s' (class `%s' type %d)\n",
- RSTRING_PTR(rb_inspect(val)),
- rb_obj_classname(val),
- TYPE(val));
- abort();
+ if (rb_obj_is_kind_of(val, rb_cRange)) {
+ VALUE beg = 0, end = 0;
+ bool exclude_end = false;
+ rb_range_extract(val, &beg, &end, &exclude_end);
+
+ Instruction *call = compile_range(
+ ConstantInt::get(RubyObjTy, beg),
+ ConstantInt::get(RubyObjTy, end),
+ exclude_end,
+ false);
+
+ Instruction *assign = new StoreInst(call, gvar, "");
+
+ list.insert(list.begin(), assign);
+ list.insert(list.begin(), call);
+ }
+ else {
+ printf("unrecognized literal `%s' (class `%s' type %d)\n",
+ RSTRING_PTR(rb_inspect(val)),
+ rb_obj_classname(val),
+ TYPE(val));
+ abort();
+ }
+ break;
}
}
Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h 2009-08-28 21:33:00 UTC (rev 2408)
+++ MacRuby/trunk/compiler.h 2009-08-28 22:32:41 UTC (rev 2409)
@@ -219,7 +219,7 @@
return compile_const_pointer(ptr, PtrPtrTy, insert_to_bb);
}
- Value *compile_protected_call(Function *func,
+ Instruction *compile_protected_call(Function *func,
std::vector<Value *> ¶ms);
void compile_dispatch_arguments(NODE *args,
std::vector<Value *> &arguments, int *pargc);
@@ -279,6 +279,8 @@
const size_t str_len, CFHashCode hash);
Value *compile_arity(rb_vm_arity_t &arity);
+ Instruction *compile_range(Value *beg, Value *end, bool exclude_end,
+ bool add_to_bb=true);
Value *compile_literal(VALUE val);
virtual Value *compile_immutable_literal(VALUE val);
virtual Value *compile_global_entry(NODE *node);
Modified: MacRuby/trunk/include/ruby/intern.h
===================================================================
--- MacRuby/trunk/include/ruby/intern.h 2009-08-28 21:33:00 UTC (rev 2408)
+++ MacRuby/trunk/include/ruby/intern.h 2009-08-28 22:32:41 UTC (rev 2409)
@@ -492,6 +492,7 @@
rb_pid_t rb_spawn(int, VALUE*);
VALUE rb_detach_process(rb_pid_t pid);
/* range.c */
+void rb_range_extract(VALUE range, VALUE *begp, VALUE *endp, bool *exclude);
VALUE rb_range_new(VALUE, VALUE, int);
VALUE rb_range_beg_len(VALUE, long*, long*, long, int);
/* random.c */
Modified: MacRuby/trunk/range.c
===================================================================
--- MacRuby/trunk/range.c 2009-08-28 21:33:00 UTC (rev 2408)
+++ MacRuby/trunk/range.c 2009-08-28 22:32:41 UTC (rev 2409)
@@ -604,6 +604,15 @@
}
}
+void
+rb_range_extract(VALUE range, VALUE *begp, VALUE *endp, bool *exclude)
+{
+ assert(begp != NULL && endp != NULL && exclude != NULL);
+ *begp = RANGE_BEG(range);
+ *endp = RANGE_END(range);
+ *exclude = EXCL(range);
+}
+
VALUE
rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
{
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090828/e2156093/attachment-0001.html>
More information about the macruby-changes
mailing list