[macruby-changes] [452] MacRuby/branches/lrz_unstable

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 18 17:49:28 PDT 2008


Revision: 452
          http://trac.macosforge.org/projects/ruby/changeset/452
Author:   lsansonetti at apple.com
Date:     2008-08-18 17:49:27 -0700 (Mon, 18 Aug 2008)
Log Message:
-----------
wip

Modified Paths:
--------------
    MacRuby/branches/lrz_unstable/class.c
    MacRuby/branches/lrz_unstable/compile.c
    MacRuby/branches/lrz_unstable/lib/delegate.rb
    MacRuby/branches/lrz_unstable/lib/fileutils.rb
    MacRuby/branches/lrz_unstable/objc.m
    MacRuby/branches/lrz_unstable/object.c
    MacRuby/branches/lrz_unstable/sample-macruby/OutlineView/DataSource.rb
    MacRuby/branches/lrz_unstable/vm_eval.c
    MacRuby/branches/lrz_unstable/vm_insnhelper.c
    MacRuby/branches/lrz_unstable/vm_method.c

Modified: MacRuby/branches/lrz_unstable/class.c
===================================================================
--- MacRuby/branches/lrz_unstable/class.c	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/class.c	2008-08-19 00:49:27 UTC (rev 452)
@@ -647,7 +647,7 @@
 }
 
 static void
-rb_objc_push_methods(VALUE ary, VALUE mod)
+rb_objc_push_methods(VALUE ary, VALUE mod, VALUE objc_methods)
 {
     Method *methods;
     unsigned int i, count;
@@ -660,7 +660,10 @@
 	    char *sel_name, *p;
 	    VALUE sym;
 	    ID mid;
-
+	    char buf[100];
+	    BOOL is_ruby_method;
+	    size_t len;
+	   
 	    method = methods[i];
 
 	    sel = method_getName(method);
@@ -668,35 +671,52 @@
 		continue; 
 
 	    sel_name = (char *)sel;
+	    is_ruby_method = rb_objc_method_node3(method_getImplementation(method)) != NULL;
 
-	    if (rb_objc_method_node3(method_getImplementation(method)) == NULL
-		&& *sel_name == '_')
+	    if (!is_ruby_method && objc_methods == Qfalse)
 		continue;
 
+	    len = strlen(sel_name);
+
+	    if (is_ruby_method && len >= 3 && sel_name[len - 1] == ':' && isalpha(sel_name[len - 3])) {
+		assert(len + 3 < sizeof(buf));
+		if (sel_name[len - 2] == '=') {
+		    /* skip foo=: (ruby) -> setFoo: (objc) shortcuts */
+		    snprintf(buf, sizeof buf, "set%s", sel_name);
+		    buf[4] = toupper(buf[4]);
+		    buf[len + 1] = ':';
+		    buf[len + 2] = '\0';
+
+		    method = class_getInstanceMethod((Class)mod, sel_registerName(buf));
+		    if (method != NULL && rb_objc_method_node3(method_getImplementation(method)) == NULL)
+			continue;
+		}
+		else if (sel_name[len - 2] == '?') {
+		    /* skip foo?: (ruby) -> isFoo: (objc) shortcuts */
+
+		    snprintf(buf, sizeof buf, "is%s", sel_name);
+		    buf[3] = toupper(buf[3]);
+		    buf[len] = ':';
+		    buf[len + 1] = '\0';
+		    
+		    method = class_getInstanceMethod((Class)mod, sel_registerName(buf));
+		    if (method != NULL && rb_objc_method_node3(method_getImplementation(method)) == NULL)
+			continue;
+		}
+	    }
 	    p = strchr(sel_name, ':');
 	    if (p != NULL && strchr(p + 1, ':') == NULL) {
-		size_t len = strlen(sel_name);
-		char buf[100];
+		/* remove trailing ':' for methods with arity 1 */
 
 		assert(len < sizeof(buf));
 
-		if (len > 4 && sel_name[0] == 's' && sel_name[1] == 'e' 
-		    && sel_name[2] == 't' && isupper(sel_name[3])) {
-		    snprintf(buf, sizeof buf, "%s", &sel_name[3]);
-		    buf[len - 4] = '=';
-		    buf[0] = tolower(buf[0]);
-		}
-		else {
-		    strncpy(buf, sel_name, len);
-		    buf[len - 1] = '\0';
-		}
+		strncpy(buf, sel_name, len);
+		buf[len - 1] = '\0';
 
-		mid = rb_intern(buf);
+		sel_name = buf;
 	    }
-	    else {
-		mid = rb_intern(sel_name);
-	    }
 
+	    mid = rb_intern(sel_name);
 	    sym = ID2SYM(mid);
 
 	    if (rb_ary_includes(ary, sym) == Qfalse)
@@ -710,22 +730,25 @@
 class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, long, VALUE))
 {
     VALUE ary;
-    bool recur;
+    VALUE recur, objc_methods;
 
     ary = rb_ary_new();
 
     if (argc == 0) {
-	recur = true;
+	recur = Qtrue;
+	objc_methods = Qfalse;
     }
     else {
-	VALUE r;
-	rb_scan_args(argc, argv, "01", &r);
-	recur = RTEST(r);
+	rb_scan_args(argc, argv, "02", &recur, &objc_methods);
+	if (NIL_P(recur))
+	    recur = Qtrue;
+	if (NIL_P(objc_methods))
+	    objc_methods = Qfalse;
     }
 
     while (mod != 0) {
-	rb_objc_push_methods(ary, mod);
-	if (!recur)
+	rb_objc_push_methods(ary, mod, objc_methods);
+	if (recur == Qfalse)
 	   break;	   
 	mod = (VALUE)class_getSuperclass((Class)mod); 
     } 
@@ -854,13 +877,14 @@
 VALUE
 rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
 {
-    VALUE recur, klass, ary;
+    VALUE recur, objc_methods, klass, ary;
 
     if (argc == 0) {
 	recur = Qtrue;
+	objc_methods = Qfalse;
     }
     else {
-	rb_scan_args(argc, argv, "01", &recur);
+	rb_scan_args(argc, argv, "02", &recur, &objc_methods);
     }
 
     klass = CLASS_OF(obj);
@@ -868,7 +892,7 @@
 
     do {
 	if (RCLASS_SINGLETON(klass))
-	    rb_objc_push_methods(ary, klass);
+	    rb_objc_push_methods(ary, klass, objc_methods);
 	klass = RCLASS_SUPER(klass);
     }
     while (recur == Qtrue && klass != 0);

Modified: MacRuby/branches/lrz_unstable/compile.c
===================================================================
--- MacRuby/branches/lrz_unstable/compile.c	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/compile.c	2008-08-19 00:49:27 UTC (rev 452)
@@ -707,14 +707,7 @@
 	id_str = (char *)rb_sym2name(id);
 	id_str_len = strlen(id_str);
 
-	if (id_str[id_str_len - 1] == '=' && isalpha(id_str[id_str_len - 2]) 
-	    && FIX2INT(argc) == 1) {
-	    snprintf(buf, sizeof buf, "set%s", id_str);
-	    buf[3] = toupper(id_str[0]);
-	    buf[id_str_len + 2] = ':';
-	    id_str = buf;
-	}
-	else if (id_str[id_str_len - 1] != ':') {
+	if (id_str[id_str_len - 1] != ':') {
 	    snprintf(buf, sizeof buf, "%s:", id_str);
 	    id_str = buf;
 	}

Modified: MacRuby/branches/lrz_unstable/lib/delegate.rb
===================================================================
--- MacRuby/branches/lrz_unstable/lib/delegate.rb	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/lib/delegate.rb	2008-08-19 00:49:27 UTC (rev 452)
@@ -117,9 +117,8 @@
 class Delegator
   preserved = [
     :__id__, :object_id, :__send__, :public_send, :respond_to?, :send,
-    :instance_eval, :instance_exec, :extend,
+    :instance_eval, :instance_exec, :extend, :initialize
   ]
-  preserved.concat(NSObject.instance_methods)
   instance_methods.each do |m|
     next if preserved.include?(m)
     undef_method m
@@ -279,7 +278,6 @@
     :clone, :dup, :marshal_dump, :marshal_load, :instance_eval, :instance_exec,
     :extend,
   ]
-  methods -= NSObject.methods
   klass.module_eval {
     include Delegator::MethodDelegation
     def __getobj__  # :nodoc:

Modified: MacRuby/branches/lrz_unstable/lib/fileutils.rb
===================================================================
--- MacRuby/branches/lrz_unstable/lib/fileutils.rb	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/lib/fileutils.rb	2008-08-19 00:49:27 UTC (rev 452)
@@ -1508,7 +1508,7 @@
 
   METHODS = singleton_methods() - [:private_module_function,
       :commands, :options, :have_option?, :options_of, 
-      :collect_method] - NSObject.methods
+      :collect_method]
 
   # 
   # This module has all methods of FileUtils module, but it outputs messages

Modified: MacRuby/branches/lrz_unstable/objc.m
===================================================================
--- MacRuby/branches/lrz_unstable/objc.m	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/objc.m	2008-08-19 00:49:27 UTC (rev 452)
@@ -1151,14 +1151,7 @@
 	if (def_str[len - 1] != ':') {
 	    char buf[100];
 
-	    if (def_str[len - 1] == '=' && isalpha(def_str[len - 2])) {
-		snprintf(buf, sizeof buf, "set%s", def_str);
-		buf[3] = toupper(buf[3]);
-		buf[len + 2] = ':';
-	    }
-	    else {
-		snprintf(buf, sizeof buf, "%s:", def_str);
-	    }
+	    snprintf(buf, sizeof buf, "%s:", def_str);
 	    def_sel = sel_registerName(buf);
 	    method = class_getInstanceMethod((Class)klass, def_sel);
 	    if (method == NULL) {
@@ -1166,14 +1159,7 @@
 	    }
 	    len = strlen(name_str);
 	    if (name_str[len - 1] != ':') {
-		if (name_str[len - 1] == '=' && isalpha(name_str[len - 2])) {
-		    snprintf(buf, sizeof buf, "set%s", name_str);
-		    buf[3] = toupper(buf[3]);
-		    buf[len + 2] = ':';
-		}
-		else {
-		    snprintf(buf, sizeof buf, "%s:", name_str);
-		}
+		snprintf(buf, sizeof buf, "%s:", name_str);
 		name_sel = sel_registerName(buf);
 	    }
 	}
@@ -1444,32 +1430,19 @@
 	mid_str = (char *)rb_id2name(mid);
 	mid_str_len = strlen(mid_str);
 
-	if (arity == 1 && mid_str[mid_str_len - 1] == '=' && isalpha(mid_str[mid_str_len - 2])) {
-	    assert(sizeof(buf) > mid_str_len + 3);
-	    buf[0] = 's';
-	    buf[1] = 'e';
-	    buf[2] = 't';
-	    buf[3] = toupper(mid_str[0]);
-	    strncpy(&buf[4], &mid_str[1], mid_str_len - 2);
-	    buf[mid_str_len + 2] = ':';
-	    buf[mid_str_len + 3] = '\0';
+	if ((arity < 0 || arity > 0) && mid_str[mid_str_len - 1] != ':') {
+	    assert(sizeof(buf) > mid_str_len + 1);
+	    snprintf(buf, sizeof buf, "%s:", mid_str);
 	    sel = sel_registerName(buf);
+	    oc_arity = 1;
 	}
 	else {
-	    if ((arity < 0 || arity > 0) && mid_str[mid_str_len - 1] != ':') {
-		assert(sizeof(buf) > mid_str_len + 1);
-		snprintf(buf, sizeof buf, "%s:", mid_str);
+	    sel = sel_registerName(mid_str);
+	    if (sel == sel_ignored) {
+		assert(sizeof(buf) > mid_str_len + 7);
+		snprintf(buf, sizeof buf, "__rb_%s__", mid_str);
 		sel = sel_registerName(buf);
-		oc_arity = 1;
 	    }
-	    else {
-		sel = sel_registerName(mid_str);
-		if (sel == sel_ignored) {
-		    assert(sizeof(buf) > mid_str_len + 7);
-		    snprintf(buf, sizeof buf, "__rb_%s__", mid_str);
-		    sel = sel_registerName(buf);
-		}
-	    }
 	}
     }
 
@@ -1748,21 +1721,13 @@
     size_t len;
 
     frame_str = rb_id2name(rb_frame_this_func());
-    if (strlen(frame_str) >= 5
-	&& frame_str[0] == 's'
-	&& frame_str[1] == 'e'
-	&& frame_str[2] == 't'
-	&& isupper(frame_str[3])) {
-
-	len = snprintf(ivar_name, sizeof ivar_name, "@%s", &frame_str[3]);
-	ivar_name[1] = tolower(ivar_name[1]);
-    }
-    else {
-	len = snprintf(ivar_name, sizeof ivar_name, "@%s", frame_str);
-    }
+    len = snprintf(ivar_name, sizeof ivar_name, "@%s", frame_str);
 	
-    if (ivar_name[len - 1] == '=' || ivar_name[len - 1] == ':')
-	ivar_name[len - 1] = '\0';
+    if (ivar_name[len - 1] == ':')
+	len--;
+    if (ivar_name[len - 1] == '=')
+	len--;
+    ivar_name[len] = '\0';
 
     return rb_intern(ivar_name);
 }
@@ -2594,7 +2559,7 @@
 rb_mod_objc_ib_outlet(int argc, VALUE *argv, VALUE recv)
 {
     int i;
-    char buf[128];
+    char buf[100];
 
     buf[0] = 's'; buf[1] = 'e'; buf[2] = 't';
 

Modified: MacRuby/branches/lrz_unstable/object.c
===================================================================
--- MacRuby/branches/lrz_unstable/object.c	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/object.c	2008-08-19 00:49:27 UTC (rev 452)
@@ -1699,25 +1699,21 @@
 static VALUE
 rb_obj_methods(int argc, VALUE *argv, VALUE obj)
 {
-  retry:
-    if (argc == 0) {
-	VALUE args[1];
-	VALUE ary;
+    VALUE recur, objc_methods;
+    VALUE args[2];
 
-	args[0] = Qtrue;
-	ary = rb_class_instance_methods(1, args, CLASS_OF(obj));
-	return ary;
+    if (argc == 0) {
+	recur = Qtrue;
+	objc_methods = Qfalse;
     }
     else {
-	VALUE recur;
-
-	rb_scan_args(argc, argv, "1", &recur);
-	if (RTEST(recur)) {
-	    argc = 0;
-	    goto retry;
-	}
-	return rb_obj_singleton_methods(argc, argv, obj);
+	rb_scan_args(argc, argv, "02", &recur, &objc_methods);
     }
+
+    args[0] = recur;
+    args[1] = objc_methods;
+
+    return rb_class_instance_methods(2, args, CLASS_OF(obj));
 }
 
 /*

Modified: MacRuby/branches/lrz_unstable/sample-macruby/OutlineView/DataSource.rb
===================================================================
--- MacRuby/branches/lrz_unstable/sample-macruby/OutlineView/DataSource.rb	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/sample-macruby/OutlineView/DataSource.rb	2008-08-19 00:49:27 UTC (rev 452)
@@ -14,10 +14,7 @@
   
   def outlineView outlineView, objectValueForTableColumn:tableColumn, byItem:item
     if item
-      # relativePath returns an ASCII-8BIT file name
-      s = item.relativePath.dup
-      s.force_encoding('utf-8')
-      s
+      s = item.relativePath
     else
       '/'
     end

Modified: MacRuby/branches/lrz_unstable/vm_eval.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_eval.c	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/vm_eval.c	2008-08-19 00:49:27 UTC (rev 452)
@@ -204,18 +204,7 @@
 
 	mid_str = rb_id2name(mid);
 	len = strlen(mid_str);
-	if (argc == 1 && len > 1 && mid_str[len - 1] == '=' && isalpha(mid_str[len - 2])) {
-	    assert(len + 3 < sizeof(buf));
-	    buf[0] = 's'; 
-	    buf[1] = 'e'; 
-	    buf[2] = 't'; 
-	    buf[3] = toupper(mid_str[0]);
-	    strlcpy(&buf[4], &mid_str[1], len - 1);
-	    buf[len + 2] = ':';
-	    buf[len + 3] = '\0';
-	    mid = rb_intern(buf);
-	}
-	else if (mid_str[len - 1] != ':') {
+	if (mid_str[len - 1] != ':') {
 	    snprintf(buf, sizeof buf, "%s:", mid_str);
 	    mid = rb_intern(buf);
 	}

Modified: MacRuby/branches/lrz_unstable/vm_insnhelper.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_insnhelper.c	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/vm_insnhelper.c	2008-08-19 00:49:27 UTC (rev 452)
@@ -530,7 +530,7 @@
 
     if (mcache != NULL) {
 	if (mcache->flags & RB_MCACHE_RCALL_FLAG) {
-	    if (mcache->as.rcall.klass == klass) {
+	    if (mcache->as.rcall.klass == klass && mcache->as.rcall.node != NULL) {
 		mn = mcache->as.rcall.node;
 #if ENABLE_DEBUG_LOGGING
 		cached = true;
@@ -808,6 +808,45 @@
 		}
 	    }
 	}
+	else if (mcache != NULL) {
+	    const char *p = (const char *)mcache->as.rcall.sel;
+	    size_t len = strlen(p);
+	    if (len >= 3) {
+		char buf[100];
+		SEL sel = 0;
+		if (isalpha(p[len - 3]) && p[len - 2] == '=' && p[len - 1] == ':') {
+		    /* foo=: -> setFoo: shortcut */
+		    snprintf(buf, sizeof buf, "set%s", p);
+		    buf[3] = toupper(buf[3]);
+		    buf[len + 1] = ':';
+		    buf[len + 2] = '\0';
+		    sel = sel_registerName(buf);
+		}
+		else if (isalpha(p[len - 2]) && p[len - 1] == '?') {
+		    /* foo?: -> isFoo: shortcut */
+		    snprintf(buf, sizeof buf, "is%s", p);
+		    buf[2] = toupper(buf[2]);
+		    buf[len + 1] = '\0';
+		    sel = sel_registerName(buf);
+		}
+		if (sel != 0) {
+		    Method method = class_getInstanceMethod((Class)klass, sel);
+		    if (method != NULL) {
+			IMP imp = method_getImplementation(method);
+			if (rb_objc_method_node3(imp) == NULL) {
+			    assert(class_addMethod((Class)klass, mcache->as.rcall.sel, imp,
+					method_getTypeEncoding(method)));
+			    mcache->flags = RB_MCACHE_OCALL_FLAG;
+			    mcache->as.ocall.klass = klass;
+			    mcache->as.ocall.imp = imp;
+			    mcache->as.ocall.method = class_getInstanceMethod((Class)klass, mcache->as.rcall.sel);
+			    mcache->as.ocall.bs_method = rb_bs_find_method((Class)klass, mcache->as.rcall.sel);
+			    goto ocall_dispatch;
+			}
+		    }
+		}
+	    }
+	}
 #endif
 	/* method missing */
 	if (id == idMethodMissing) {

Modified: MacRuby/branches/lrz_unstable/vm_method.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_method.c	2008-08-18 20:32:29 UTC (rev 451)
+++ MacRuby/branches/lrz_unstable/vm_method.c	2008-08-19 00:49:27 UTC (rev 452)
@@ -202,7 +202,7 @@
 {
     Check_Type(klass, T_CLASS);
     rb_add_method(rb_singleton_class(klass), ID_ALLOCATOR, NEW_CFUNC(func, 0),
-		  NOEX_PRIVATE);
+		  NOEX_PUBLIC);
 }
 
 void
@@ -325,14 +325,7 @@
 	}
 	else {
 	    char buf[100];
-	    if (id_str[slen - 1] == '=' && isalpha(id_str[slen - 2])) {
-		snprintf(buf, sizeof buf, "set%s", id_str);
-		buf[3] = toupper(buf[3]);
-		buf[slen + 2] = ':';
-	    }
-	    else {
-		snprintf(buf, sizeof buf, "%s:", id_str);
-	    }
+	    snprintf(buf, sizeof buf, "%s:", id_str);
 	    return rb_method_node(klass, rb_intern(buf));
 	}
     }
@@ -578,15 +571,9 @@
     if (id == object_id || id == __send__ || id == idInitialize) {
 	rb_warn("undefining `%s' may cause serious problem", rb_id2name(id));
     }
-#if WITH_OBJC
-    /* TODO: we should only warn regarding important NSObject methods that
-       are necessary by the GC to call finalizers. */
-    if (class_respondsToSelector((Class)rb_cBasicObject,
-				 sel_registerName(rb_id2name(id)))) {
-	rb_warn("undefining `NSObject#%s' may cause serious problem", 
-		rb_id2name(id));
-    }
-#endif
+    /* TODO: warn if a very important method of NSObject is undefined 
+     * by default, pure objc methods are not exposed by introspections API 
+     */
     body = search_method(klass, id, &origin);
     if (!body || !body->nd_body) {
 	const char *s0 = " class";
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080818/bb0d37ad/attachment-0001.html 


More information about the macruby-changes mailing list