[macruby-changes] [2782] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sun Oct 11 22:35:06 PDT 2009
Revision: 2782
http://trac.macosforge.org/projects/ruby/changeset/2782
Author: lsansonetti at apple.com
Date: 2009-10-11 22:35:03 -0700 (Sun, 11 Oct 2009)
Log Message:
-----------
added support for AOT compilation of literal bignums
Modified Paths:
--------------
MacRuby/trunk/bignum.c
MacRuby/trunk/compiler.cpp
Modified: MacRuby/trunk/bignum.c
===================================================================
--- MacRuby/trunk/bignum.c 2009-10-12 05:09:01 UTC (rev 2781)
+++ MacRuby/trunk/bignum.c 2009-10-12 05:35:03 UTC (rev 2782)
@@ -688,6 +688,14 @@
return rb_str_to_inum(str, base, base==0);
}
+VALUE
+rb_bignum_new_retained(const char *str)
+{
+ VALUE v = rb_cstr2inum(str, 10);
+ GC_RETAIN(v);
+ return v;
+}
+
const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
static VALUE bigsqr(VALUE x);
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2009-10-12 05:09:01 UTC (rev 2781)
+++ MacRuby/trunk/compiler.cpp 2009-10-12 05:35:03 UTC (rev 2782)
@@ -5294,6 +5294,10 @@
cast<Function>(module->getOrInsertFunction("rb_reg_new_retained",
RubyObjTy, PtrTy, Int32Ty, Int32Ty, NULL));
+ Function *newBignumFunc =
+ cast<Function>(module->getOrInsertFunction("rb_bignum_new_retained",
+ RubyObjTy, PtrTy, NULL));
+
Function *getClassFunc =
cast<Function>(module->getOrInsertFunction("objc_getClass",
RubyObjTy, PtrTy, NULL));
@@ -5399,6 +5403,33 @@
}
break;
+ case T_BIGNUM:
+ {
+ const char *bigstr = RSTRING_PTR(rb_big2str(val, 10));
+
+ GlobalVariable *bigstr_gvar =
+ compile_const_global_string(bigstr);
+
+ std::vector<Value *> idxs;
+ idxs.push_back(ConstantInt::get(Int32Ty, 0));
+ idxs.push_back(ConstantInt::get(Int32Ty, 0));
+ Instruction *load = GetElementPtrInst::Create(bigstr_gvar,
+ idxs.begin(), idxs.end(), "");
+
+ std::vector<Value *> params;
+ params.push_back(load);
+
+ Instruction *call = CallInst::Create(newBignumFunc,
+ params.begin(), params.end(), "");
+
+ Instruction *assign = new StoreInst(call, gvar, "");
+
+ list.insert(list.begin(), assign);
+ list.insert(list.begin(), call);
+ list.insert(list.begin(), load);
+ }
+ break;
+
default:
if (rb_obj_is_kind_of(val, rb_cRange)) {
VALUE beg = 0, end = 0;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091011/de1b5601/attachment.html>
More information about the macruby-changes
mailing list