[macruby-changes] [890] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 11 19:32:41 PDT 2009
Revision: 890
http://trac.macosforge.org/projects/ruby/changeset/890
Author: lsansonetti at apple.com
Date: 2009-03-11 19:32:40 -0700 (Wed, 11 Mar 2009)
Log Message:
-----------
fixed a bug in UnboundMethod/bind, added tests
Modified Paths:
--------------
MacRuby/branches/experimental/proc.c
MacRuby/branches/experimental/roxor.cpp
MacRuby/branches/experimental/roxor.h
MacRuby/branches/experimental/test_roxor.rb
Modified: MacRuby/branches/experimental/proc.c
===================================================================
--- MacRuby/branches/experimental/proc.c 2009-03-12 02:32:17 UTC (rev 889)
+++ MacRuby/branches/experimental/proc.c 2009-03-12 02:32:40 UTC (rev 890)
@@ -1119,8 +1119,8 @@
}
}
- VALUE result = rb_vm_call_with_cache(data->cache, data->recv, data->sel,
- argc, argv);
+ VALUE result = rb_vm_call_with_cache2(data->cache, data->recv,
+ data->oclass, data->sel, argc, argv);
if (safe >= 0) {
rb_set_safe_level_force(safe);
Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp 2009-03-12 02:32:17 UTC (rev 889)
+++ MacRuby/branches/experimental/roxor.cpp 2009-03-12 02:32:40 UTC (rev 890)
@@ -4282,12 +4282,14 @@
}
static inline VALUE
-__rb_vm_dispatch(struct mcache *cache, VALUE self, SEL sel, bool super,
- int argc, const VALUE *argv)
+__rb_vm_dispatch(struct mcache *cache, VALUE self, Class klass, SEL sel,
+ bool super, int argc, const VALUE *argv)
{
assert(cache != NULL);
- Class klass = (Class)CLASS_OF(self);
+ if (klass == NULL) {
+ klass = (Class)CLASS_OF(self);
+ }
#if ROXOR_DEBUG
const bool cached = cache->flag != 0;
@@ -4450,12 +4452,12 @@
if (block != NULL) {
GET_VM()->push_block((rb_vm_block_t *)block);
- VALUE retval = __rb_vm_dispatch(cache, self, sel, super, argc, argv);
+ VALUE retval = __rb_vm_dispatch(cache, self, NULL, sel, super, argc, argv);
GET_VM()->pop_block();
return retval;
}
- return __rb_vm_dispatch(cache, self, sel, super, argc, argv);
+ return __rb_vm_dispatch(cache, self, NULL, sel, super, argc, argv);
}
extern "C"
@@ -4491,7 +4493,7 @@
rb_ary_push(obj, other);
return other;
}
- return __rb_vm_dispatch(cache, obj, selLTLT, false, 1, &other);
+ return __rb_vm_dispatch(cache, obj, NULL, selLTLT, false, 1, &other);
}
extern "C"
@@ -4506,7 +4508,7 @@
extern VALUE rb_ary_aref(VALUE ary, SEL sel, int argc, VALUE *argv);
return rb_ary_aref(obj, 0, 1, &other);
}
- return __rb_vm_dispatch(cache, obj, selAREF, false, 1, &other);
+ return __rb_vm_dispatch(cache, obj, NULL, selAREF, false, 1, &other);
}
extern "C"
@@ -4523,7 +4525,7 @@
VALUE args[2];
args[0] = other1;
args[1] = other2;
- return __rb_vm_dispatch(cache, obj, selASET, false, 2, args);
+ return __rb_vm_dispatch(cache, obj, NULL, selASET, false, 2, args);
}
extern "C"
@@ -4576,7 +4578,7 @@
if (super) {
struct mcache cache;
cache.flag = 0;
- VALUE retval = __rb_vm_dispatch(&cache, self, sel, true, argc, argv);
+ VALUE retval = __rb_vm_dispatch(&cache, self, NULL, sel, true, argc, argv);
if (cache.flag == MCACHE_OCALL) {
free(cache.as.ocall.helper);
}
@@ -4584,7 +4586,7 @@
}
else {
struct mcache *cache = GET_VM()->method_cache_get(sel, false);
- return __rb_vm_dispatch(cache, self, sel, false, argc, argv);
+ return __rb_vm_dispatch(cache, self, NULL, sel, false, argc, argv);
}
}
@@ -4593,11 +4595,20 @@
rb_vm_call_with_cache(void *cache, VALUE self, SEL sel, int argc,
const VALUE *argv)
{
- return __rb_vm_dispatch((struct mcache *)cache, self, sel, false, argc,
- argv);
+ return __rb_vm_dispatch((struct mcache *)cache, self, NULL, sel, false,
+ argc, argv);
}
extern "C"
+VALUE
+rb_vm_call_with_cache2(void *cache, VALUE self, VALUE klass, SEL sel, int argc,
+ const VALUE *argv)
+{
+ return __rb_vm_dispatch((struct mcache *)cache, self, (Class)klass, sel,
+ false, argc, argv);
+}
+
+extern "C"
void *
rb_vm_get_call_cache(SEL sel)
{
@@ -4646,13 +4657,12 @@
rb_print_undef(klass, mid, 0);
}
- Class k, oklass;
- k = oklass = (Class)klass;
- while ((k = class_getSuperclass(k)) != NULL) {
+ Class k, oklass = (Class)klass;
+ while ((k = class_getSuperclass(oklass)) != NULL) {
if (!rb_vm_lookup_method(k, sel, NULL, NULL)) {
- oklass = k;
break;
}
+ oklass = k;
}
int arity;
Modified: MacRuby/branches/experimental/roxor.h
===================================================================
--- MacRuby/branches/experimental/roxor.h 2009-03-12 02:32:17 UTC (rev 889)
+++ MacRuby/branches/experimental/roxor.h 2009-03-12 02:32:40 UTC (rev 890)
@@ -23,6 +23,7 @@
void rb_vm_alias(VALUE klass, ID name, ID def);
VALUE rb_vm_call(VALUE self, SEL sel, int argc, const VALUE *args, bool super);
VALUE rb_vm_call_with_cache(void *cache, VALUE self, SEL sel, int argc, const VALUE *argv);
+VALUE rb_vm_call_with_cache2(void *cache, VALUE self, VALUE klass, SEL sel, int argc, const VALUE *argv);
void *rb_vm_get_call_cache(SEL sel);
VALUE rb_vm_yield(int argc, const VALUE *argv);
bool rb_vm_respond_to(VALUE obj, SEL sel, bool priv);
Modified: MacRuby/branches/experimental/test_roxor.rb
===================================================================
--- MacRuby/branches/experimental/test_roxor.rb 2009-03-12 02:32:17 UTC (rev 889)
+++ MacRuby/branches/experimental/test_roxor.rb 2009-03-12 02:32:40 UTC (rev 890)
@@ -960,3 +960,33 @@
}
end
+
+test "method" do
+
+ assert ":ok", %{
+ def foo; :ok; end
+ p method(:foo).call
+ }
+
+ assert "42", %{
+ def foo(x); x; end
+ p method(:foo).call(42)
+ }
+
+ assert ":ok", %{
+ begin
+ method(:does_not_exist)
+ rescue NameError
+ p :ok
+ end
+ }
+
+ assert ":b\n:a", %{
+ class A; def foo() :a end end
+ class B < A; def foo() :b end end
+ m = A.instance_method(:foo)
+ b = B.new
+ p b.foo, m.bind(b).call
+ }
+
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090311/0776eeaf/attachment-0001.html>
More information about the macruby-changes
mailing list