[macruby-changes] [5202] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jan 27 21:41:24 PST 2011


Revision: 5202
          http://trac.macosforge.org/projects/ruby/changeset/5202
Author:   lsansonetti at apple.com
Date:     2011-01-27 21:41:23 -0800 (Thu, 27 Jan 2011)
Log Message:
-----------
implement #define_method when passing Method

Modified Paths:
--------------
    MacRuby/trunk/proc.c
    MacRuby/trunk/vm.cpp
    MacRuby/trunk/vm.h

Modified: MacRuby/trunk/proc.c
===================================================================
--- MacRuby/trunk/proc.c	2011-01-28 04:53:40 UTC (rev 5201)
+++ MacRuby/trunk/proc.c	2011-01-28 05:41:23 UTC (rev 5202)
@@ -1002,29 +1002,17 @@
     }
 
     if (rb_obj_is_method(body)) {
-	// TODO
-	abort();
-#if 0
-	struct METHOD *method = (struct METHOD *)DATA_PTR(body);
-	VALUE rclass = method->rclass;
-	if (rclass != mod) {
-	    if (RCLASS_SINGLETON(rclass)) {
-		rb_raise(rb_eTypeError,
-			 "can't bind singleton method to a different class");
-	    }
-	    if (!RTEST(rb_class_inherited_p(mod, rclass))) {
-		rb_raise(rb_eTypeError,
-			 "bind argument must be a subclass of %s",
-			 rb_class2name(rclass));
-	    }
+	rb_vm_method_t *data;
+	Data_Get_Struct(body, rb_vm_method_t, data);
+	if (data->node == NULL) {
+	    rb_raise(rb_eArgError, "cannot use Method object of pure Objective-C method");
 	}
-	node = method->body;
-#endif
+	SEL msel = rb_vm_id_to_sel(id, data->arity);
+	rb_vm_define_method2((Class)mod, msel, data->node, data->node->flags, false);
     }
     else {
 	rb_vm_block_t *proc;
 	GetProcPtr(body, proc);
-
 	rb_vm_define_method3((Class)mod, id, proc);
     }
 

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2011-01-28 04:53:40 UTC (rev 5201)
+++ MacRuby/trunk/vm.cpp	2011-01-28 05:41:23 UTC (rev 5202)
@@ -2645,17 +2645,8 @@
 {
     assert(block != NULL);
 
-    SEL sel;
     const int arity = rb_vm_arity_n(block->arity);
-    const char *mid_name = rb_id2name(mid);
-    if (arity > 0 && mid_name[strlen(mid_name) - 1] != ':') {
-	char buf[100];
-	snprintf(buf, sizeof buf, "%s:", mid_name);
-	sel = sel_registerName(buf);
-    }
-    else {
-	sel = sel_registerName(mid_name);
-    }
+    SEL sel = rb_vm_id_to_sel(mid, arity);
 
     Function *func = RoxorCompiler::shared->compile_block_caller(block);
     IMP imp = GET_CORE()->compile(func);

Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h	2011-01-28 04:53:40 UTC (rev 5201)
+++ MacRuby/trunk/vm.h	2011-01-28 05:41:23 UTC (rev 5202)
@@ -98,6 +98,27 @@
     return flags;
 }
 
+static inline SEL
+rb_vm_name_to_sel(const char *name, int arity)
+{
+    SEL sel;
+    if (arity > 0 && name[strlen(name) - 1] != ':') {
+	char buf[100];
+	snprintf(buf, sizeof buf, "%s:", name);
+	sel = sel_registerName(buf);
+    }
+    else {
+	sel = sel_registerName(name);
+    }
+    return sel;
+}
+
+static inline SEL
+rb_vm_id_to_sel(ID mid, int arity)
+{
+    return rb_vm_name_to_sel(rb_id2name(mid), arity);
+}
+
 typedef struct rb_vm_method_node {
     rb_vm_arity_t arity;
     Class klass;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110127/cd66b09c/attachment.html>


More information about the macruby-changes mailing list