[macruby-changes] [4374] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jul 23 19:16:52 PDT 2010
Revision: 4374
http://trac.macosforge.org/projects/ruby/changeset/4374
Author: lsansonetti at apple.com
Date: 2010-07-23 19:16:49 -0700 (Fri, 23 Jul 2010)
Log Message:
-----------
added basic support to define/message ignored selectors (retain & friends), fixed a typo when compiling store instructions (they would be compiled as volatile, blocking some optimizations)
Modified Paths:
--------------
MacRuby/trunk/compiler.cpp
MacRuby/trunk/dispatcher.cpp
MacRuby/trunk/objc.h
MacRuby/trunk/objc.m
MacRuby/trunk/spec/macruby/language/objc_method_spec.rb
MacRuby/trunk/vm.cpp
MacRuby/trunk/vm.h
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2010-07-24 01:07:02 UTC (rev 4373)
+++ MacRuby/trunk/compiler.cpp 2010-07-24 02:16:49 UTC (rev 4374)
@@ -853,7 +853,7 @@
for (int i = 0; i < argc; i++) {
Value *idx = ConstantInt::get(Int32Ty, i);
Value *slot = GetElementPtrInst::Create(dispatch_argv, idx, "", bb);
- new StoreInst(params[offset + i], slot, "", bb);
+ new StoreInst(params[offset + i], slot, bb);
}
return dispatch_argv;
@@ -1093,7 +1093,7 @@
int flags = 0;
params.push_back(compile_prepare_block_args(current_block_func, &flags));
if (nd_type(current_block_node) == NODE_SCOPE
- && current_block_node->nd_body == NULL) {
+ && current_block_node->nd_body == NULL) {
flags |= VM_BLOCK_EMPTY;
}
params.push_back(ConstantInt::get(Int32Ty, flags));
@@ -2257,6 +2257,7 @@
return NULL;
}
SEL new_sel = mid_to_sel(SYM2ID(sym), argc - 1);
+ new_sel = rb_objc_ignored_sel(new_sel);
GlobalVariable *is_redefined = GET_CORE()->redefined_op_gvar(sel, true);
@@ -2974,6 +2975,7 @@
SEL sel;
if (mid != 0) {
sel = mid_to_sel(mid, positive_arity ? 1 : 0);
+ sel = rb_objc_ignored_sel(sel);
sel_val = compile_sel(sel);
if (block_declaration && super_call) {
// A super call inside a block. The selector cannot
@@ -4739,7 +4741,7 @@
Value *val = CallInst::Create(getConstCacheFunc,
compile_const_global_string(rb_id2name(name)), "", bb);
- new StoreInst(val, gvar, "", bb);
+ new StoreInst(val, gvar, bb);
}
// Compile selectors.
@@ -4756,7 +4758,7 @@
Value *val = CallInst::Create(registerSelFunc,
compile_const_global_string(sel_getName(sel)), "", bb);
val = new BitCastInst(val, PtrTy, "", bb);
- new StoreInst(val, gvar, "", bb);
+ new StoreInst(val, gvar, bb);
}
// Compile literals.
@@ -4862,7 +4864,7 @@
}
assert(lit_val != NULL);
- new StoreInst(lit_val, gvar, "", bb);
+ new StoreInst(lit_val, gvar, bb);
}
// Compile IDs.
@@ -4880,7 +4882,7 @@
Value *val = CallInst::Create(rbInternFunc,
compile_const_global_string(rb_id2name(name)), "", bb);
- new StoreInst(val, gvar, "", bb);
+ new StoreInst(val, gvar, bb);
}
// Compile global entries.
@@ -4899,7 +4901,7 @@
Value *val = CallInst::Create(rbInternFunc,
compile_const_global_string(rb_id2name(name)), "", bb);
val = CallInst::Create(globalEntryFunc, val, "", bb);
- new StoreInst(val, gvar, "", bb);
+ new StoreInst(val, gvar, bb);
}
// Compile constant class references.
@@ -4912,7 +4914,7 @@
Value *val = CallInst::Create(getClassFunc,
compile_const_global_string(gvar->getName().str().c_str()),
"",bb);
- new StoreInst(val, gvar, "", bb);
+ new StoreInst(val, gvar, bb);
}
// Instance variable slots.
@@ -4927,7 +4929,7 @@
GlobalVariable *gvar = *i;
Value *val = CallInst::Create(ivarSlotAlloc, "", bb);
- new StoreInst(val, gvar, "", bb);
+ new StoreInst(val, gvar, bb);
}
// Stubs.
@@ -5312,7 +5314,7 @@
"", bb);
Value *rval = compile_conversion_to_ruby(
arg_ctypes[i].c_str(), arg_types[i], arg++);
- new StoreInst(rval, aslot, "", bb);
+ new StoreInst(rval, aslot, bb);
}
}
@@ -6351,7 +6353,7 @@
for (int i = 0; i < arity; i++) {
Value *index = ConstantInt::get(Int32Ty, i);
Value *slot = GetElementPtrInst::Create(argv, index, "", bb);
- new StoreInst(arg++, slot, "", bb);
+ new StoreInst(arg++, slot, bb);
}
}
Modified: MacRuby/trunk/dispatcher.cpp
===================================================================
--- MacRuby/trunk/dispatcher.cpp 2010-07-24 01:07:02 UTC (rev 4373)
+++ MacRuby/trunk/dispatcher.cpp 2010-07-24 02:16:49 UTC (rev 4374)
@@ -1338,7 +1338,7 @@
}
else {
assert(b->dvars_size == dvars_size);
- assert((b->flags & flags) == flags);
+ assert((b->flags & flags) == (flags & ~VM_BLOCK_THREAD));
}
b->proc = Qnil;
Modified: MacRuby/trunk/objc.h
===================================================================
--- MacRuby/trunk/objc.h 2010-07-24 01:07:02 UTC (rev 4373)
+++ MacRuby/trunk/objc.h 2010-07-24 02:16:49 UTC (rev 4374)
@@ -216,7 +216,7 @@
void rb_objc_exception_raise(const char *name, const char *message);
-bool rb_objc_ignore_sel(SEL sel);
+SEL rb_objc_ignored_sel(SEL sel);
bool rb_objc_isEqual(VALUE x, VALUE y);
void rb_objc_force_class_initialize(Class klass);
void rb_objc_fix_relocatable_load_path(void);
Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m 2010-07-24 01:07:02 UTC (rev 4373)
+++ MacRuby/trunk/objc.m 2010-07-24 02:16:49 UTC (rev 4374)
@@ -639,14 +639,25 @@
return (VALUE)obj;
}
-bool
-rb_objc_ignore_sel(SEL sel)
+SEL
+rb_objc_ignored_sel(SEL sel)
{
- return sel == @selector(retain)
- || sel == @selector(release)
- || sel == @selector(autorelease)
- || sel == @selector(retainCount)
- || sel == @selector(dealloc);
+ if (sel == @selector(retain)) {
+ return @selector(__hidden__retain);
+ }
+ if (sel == @selector(release)) {
+ return @selector(__hidden__release);
+ }
+ if (sel == @selector(autorelease)) {
+ return @selector(__hidden__autorelease);
+ }
+ if (sel == @selector(retainCount)) {
+ return @selector(__hidden__retainCount);
+ }
+ if (sel == @selector(dealloc)) {
+ return @selector(__hidden__dealloc);
+ }
+ return sel;
}
bool
Modified: MacRuby/trunk/spec/macruby/language/objc_method_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/language/objc_method_spec.rb 2010-07-24 01:07:02 UTC (rev 4373)
+++ MacRuby/trunk/spec/macruby/language/objc_method_spec.rb 2010-07-24 02:16:49 UTC (rev 4374)
@@ -764,3 +764,19 @@
lambda { functionMultiplicatingByTwoViaFctPtr(42, Proc.new { |x, y| x * y }) }.should raise_error(ArgumentError)
end
end
+
+describe "Ignored Obj-C selectors" do
+ it "can be defined and messaged" do
+ o = Object.new
+ def o.retain; 1; end
+ def o.release; 2; end
+ def o.autorelease; 3; end
+ def o.retainCount; 4; end
+ def o.dealloc; 5; end
+ o.retain.should == 1
+ o.release.should == 2
+ o.autorelease.should == 3
+ o.retainCount.should == 4
+ o.dealloc.should == 5
+ end
+end
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2010-07-24 01:07:02 UTC (rev 4373)
+++ MacRuby/trunk/vm.cpp 2010-07-24 02:16:49 UTC (rev 4374)
@@ -1821,7 +1821,7 @@
#if MACRUBY_STATIC
if (objc_imp == NULL) {
- printf("can't define method `%s' because no Objective-C stub was pre-compiled", sel_getName(sel));
+ printf("can't define method `%s' because no Objective-C stub was pre-compiled for types `%s'\n", sel_getName(sel), types);
abort();
}
#else
@@ -1996,10 +1996,7 @@
flags |= VM_METHOD_PROTECTED;
}
- if (rb_objc_ignore_sel(sel)) {
- // TODO
- return;
- }
+ sel = rb_objc_ignored_sel(sel);
const char *sel_name = sel_getName(sel);
const bool genuine_selector = sel_name[strlen(sel_name) - 1] == ':';
@@ -2152,7 +2149,7 @@
static void
push_method(VALUE ary, SEL sel, int flags, int (*filter) (VALUE, ID, VALUE))
{
- if (rb_objc_ignore_sel(sel)) {
+ if (rb_objc_ignored_sel(sel) != sel) {
return;
}
@@ -2488,10 +2485,7 @@
{
assert(klass != NULL);
- if (rb_objc_ignore_sel(sel)) {
- // TODO
- return NULL;
- }
+ sel = rb_objc_ignored_sel(sel);
const char *sel_name = sel_getName(sel);
const bool genuine_selector = sel_name[strlen(sel_name) - 1] == ':';
Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h 2010-07-24 01:07:02 UTC (rev 4373)
+++ MacRuby/trunk/vm.h 2010-07-24 02:16:49 UTC (rev 4374)
@@ -596,9 +596,12 @@
argc, argv);
}
+SEL rb_objc_ignored_sel(SEL);
+
static inline VALUE
rb_vm_call(VALUE self, SEL sel, int argc, const VALUE *argv)
{
+ sel = rb_objc_ignored_sel(sel);
return rb_vm_call0(rb_vm_current_vm(), 0, self, (Class)CLASS_OF(self), sel,
NULL, DISPATCH_FCALL, argc, argv);
}
@@ -606,6 +609,7 @@
static inline VALUE
rb_vm_call_super(VALUE self, SEL sel, int argc, const VALUE *argv)
{
+ sel = rb_objc_ignored_sel(sel);
return rb_vm_call0(rb_vm_current_vm(), 0, self, (Class)CLASS_OF(self), sel,
NULL, DISPATCH_SUPER, argc, argv);
}
@@ -617,6 +621,7 @@
if (klass == 0) {
klass = CLASS_OF(self);
}
+ sel = rb_objc_ignored_sel(sel);
return rb_vm_call0(rb_vm_current_vm(), 0, self, (Class)klass, sel, block,
DISPATCH_FCALL, argc, argv);
}
@@ -1152,6 +1157,6 @@
#endif /* __cplusplus */
#define not_implemented_in_static(s) \
- rb_raise(rb_eRuntimeError, "%s is not supported in MacRuby static", sel_getName(s))
+ rb_raise(rb_eRuntimeError, "%s: not supported in static compilation", sel_getName(s))
#endif /* __VM_H_ */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100723/28bed289/attachment-0001.html>
More information about the macruby-changes
mailing list