[macruby-changes] [2604] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Sep 21 22:55:23 PDT 2009
Revision: 2604
http://trac.macosforge.org/projects/ruby/changeset/2604
Author: lsansonetti at apple.com
Date: 2009-09-21 22:55:23 -0700 (Mon, 21 Sep 2009)
Log Message:
-----------
added support for AOT compilation of the rb_eStandardError constant
Modified Paths:
--------------
MacRuby/trunk/compiler.cpp
MacRuby/trunk/compiler.h
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2009-09-22 05:54:57 UTC (rev 2603)
+++ MacRuby/trunk/compiler.cpp 2009-09-22 05:55:23 UTC (rev 2604)
@@ -156,7 +156,6 @@
falseVal = ConstantInt::get(RubyObjTy, Qfalse);
undefVal = ConstantInt::get(RubyObjTy, Qundef);
splatArgFollowsVal = ConstantInt::get(RubyObjTy, SPLAT_ARG_FOLLOWS);
- cObject = ConstantInt::get(RubyObjTy, rb_cObject);
PtrTy = PointerType::getUnqual(Type::Int8Ty);
PtrPtrTy = PointerType::getUnqual(PtrTy);
Int32PtrTy = PointerType::getUnqual(Type::Int32Ty);
@@ -170,6 +169,7 @@
: RoxorCompiler()
{
cObject_gvar = NULL;
+ cStandardError_gvar = NULL;
}
inline SEL
@@ -1273,7 +1273,7 @@
inline Value *
RoxorCompiler::compile_nsobject(void)
{
- return cObject;
+ return ConstantInt::get(RubyObjTy, rb_cObject);
}
inline Value *
@@ -1287,11 +1287,34 @@
zeroVal,
"NSObject",
RoxorCompiler::module);
+ class_gvars.push_back(cObject_gvar);
}
return new LoadInst(cObject_gvar, "", bb);
}
inline Value *
+RoxorCompiler::compile_standarderror(void)
+{
+ return ConstantInt::get(RubyObjTy, rb_eStandardError);
+}
+
+inline Value *
+RoxorAOTCompiler::compile_standarderror(void)
+{
+ if (cStandardError_gvar == NULL) {
+ cStandardError_gvar = new GlobalVariable(
+ RubyObjTy,
+ false,
+ GlobalValue::InternalLinkage,
+ zeroVal,
+ "StandardError",
+ RoxorCompiler::module);
+ class_gvars.push_back(cStandardError_gvar);
+ }
+ return new LoadInst(cStandardError_gvar, "", bb);
+}
+
+inline Value *
RoxorCompiler::compile_id(ID id)
{
return ConstantInt::get(IntTy, (long)id);
@@ -4623,9 +4646,7 @@
if (n->nd_args == NULL) {
// catch StandardError exceptions by default
- exceptions_to_catch.push_back(
- ConstantInt::get(RubyObjTy,
- (long)rb_eStandardError));
+ exceptions_to_catch.push_back(compile_standarderror());
}
else {
NODE *n2 = n->nd_args;
@@ -5439,19 +5460,25 @@
list.insert(list.begin(), load);
}
- // Compile NSObject reference.
+ // Compile constant class references.
Function *objcGetClassFunc = cast<Function>(module->getOrInsertFunction(
"objc_getClass",
RubyObjTy, PtrTy, NULL));
- if (cObject_gvar != NULL) {
- GlobalVariable *nsobject = compile_const_global_string("NSObject");
+ for (std::vector<GlobalVariable *>::iterator i = class_gvars.begin();
+ i != class_gvars.end();
+ ++i) {
+ GlobalVariable *gvar = *i;
+
+ GlobalVariable *str = compile_const_global_string(
+ gvar->getName().c_str());
+
std::vector<Value *> idxs;
idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
- Instruction *load = GetElementPtrInst::Create(nsobject,
+ Instruction *load = GetElementPtrInst::Create(str,
idxs.begin(), idxs.end(), "");
std::vector<Value *> params;
@@ -5460,7 +5487,7 @@
Instruction *call = CallInst::Create(objcGetClassFunc, params.begin(),
params.end(), "");
- Instruction *assign = new StoreInst(call, cObject_gvar, "");
+ Instruction *assign = new StoreInst(call, gvar, "");
list.insert(list.begin(), assign);
list.insert(list.begin(), call);
Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h 2009-09-22 05:54:57 UTC (rev 2603)
+++ MacRuby/trunk/compiler.h 2009-09-22 05:55:23 UTC (rev 2604)
@@ -212,7 +212,6 @@
Constant *falseVal;
Constant *undefVal;
Constant *splatArgFollowsVal;
- Constant *cObject;
Constant *defaultScope;
Constant *publicScope;
const Type *RubyObjTy;
@@ -276,6 +275,7 @@
void compile_multiple_assignment_element(NODE *node, Value *val);
Value *compile_current_class(void);
virtual Value *compile_nsobject(void);
+ virtual Value *compile_standarderror(void);
Value *compile_class_path(NODE *node, bool *outer);
Value *compile_const(ID id, Value *outer);
Value *compile_singleton_class(Value *obj);
@@ -366,6 +366,8 @@
std::map<VALUE, GlobalVariable *> literals;
GlobalVariable *cObject_gvar;
+ GlobalVariable *cStandardError_gvar;
+ std::vector<GlobalVariable *> class_gvars;
Value *compile_mcache(SEL sel, bool super);
Value *compile_ccache(ID id);
@@ -375,6 +377,7 @@
NODE *body);
Value *compile_prepare_block_args(Function *func, int *flags);
Value *compile_nsobject(void);
+ Value *compile_standarderror(void);
Value *compile_id(ID id);
Value *compile_immutable_literal(VALUE val);
Value *compile_global_entry(NODE *node);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090921/f2a898ac/attachment-0001.html>
More information about the macruby-changes
mailing list