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

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 31 15:22:07 PDT 2008


Revision: 390
          http://trac.macosforge.org/projects/ruby/changeset/390
Author:   lsansonetti at apple.com
Date:     2008-07-31 15:22:07 -0700 (Thu, 31 Jul 2008)
Log Message:
-----------
wip

Modified Paths:
--------------
    MacRuby/branches/lrz_unstable/array.c
    MacRuby/branches/lrz_unstable/class.c
    MacRuby/branches/lrz_unstable/eval.c
    MacRuby/branches/lrz_unstable/hash.c
    MacRuby/branches/lrz_unstable/id.c
    MacRuby/branches/lrz_unstable/id.h
    MacRuby/branches/lrz_unstable/include/ruby/intern.h
    MacRuby/branches/lrz_unstable/include/ruby/ruby.h
    MacRuby/branches/lrz_unstable/numeric.c
    MacRuby/branches/lrz_unstable/objc.m
    MacRuby/branches/lrz_unstable/object.c
    MacRuby/branches/lrz_unstable/string.c
    MacRuby/branches/lrz_unstable/variable.c
    MacRuby/branches/lrz_unstable/vm_eval.c

Modified: MacRuby/branches/lrz_unstable/array.c
===================================================================
--- MacRuby/branches/lrz_unstable/array.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/array.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -14,11 +14,13 @@
 #include "ruby/ruby.h"
 #include "ruby/util.h"
 #include "ruby/st.h"
+#include "id.h"
 
 VALUE rb_cArray;
 #if WITH_OBJC
 VALUE rb_cCFArray;
-VALUE rb_cArrayRuby;
+VALUE rb_cNSArray;
+VALUE rb_cNSMutableArray;
 #endif
 
 static ID id_cmp;
@@ -173,8 +175,7 @@
     rb_objc_release(v);
 }
 
-static void
-rb_ary_insert(VALUE ary, long idx, VALUE val);
+void rb_ary_insert(VALUE ary, long idx, VALUE val);
 #endif
 
 static VALUE
@@ -190,7 +191,7 @@
     cb.equal = rb_cfarray_equal_cb;
 
     ary = (VALUE)CFArrayCreateMutable(NULL, 0, &cb);
-    if (klass != 0 && klass != rb_cArray && klass != rb_cArrayRuby)
+    if (klass != 0 && klass != rb_cNSArray && klass != rb_cNSMutableArray)
         *(Class *)ary = (Class)klass;
 
     CFMakeCollectable((CFTypeRef)ary);
@@ -410,7 +411,12 @@
     long len;
     VALUE size, val;
 
+#if WITH_OBJC
+    ary = (VALUE)objc_msgSend((id)ary, selInit);
+#else
     rb_ary_modify(ary);
+#endif
+
     if (argc ==  0) {
 #if !WITH_OBJC
 	if (RARRAY_PTR(ary) && !ARY_SHARED_P(ary)) {
@@ -500,7 +506,7 @@
 }
 
 #if WITH_OBJC
-static void
+void
 rb_ary_insert(VALUE ary, long idx, VALUE val)
 {
     if (idx < 0) {
@@ -4129,17 +4135,19 @@
 Init_Array(void)
 {
 #if WITH_OBJC
-    rb_cCFArray = rb_objc_import_class((Class)objc_getClass("NSCFArray"));;
-    rb_cArray = rb_objc_import_class((Class)objc_getClass("NSArray"));
-    rb_cArrayRuby = 
-	rb_objc_import_class((Class)objc_getClass("NSMutableArray"));
-    rb_const_set(rb_cObject, rb_intern("Array"), rb_cArrayRuby);
+    rb_cCFArray = (VALUE)objc_getClass("NSCFArray");
+    rb_cArray = rb_cNSArray = (VALUE)objc_getClass("NSArray");
+    rb_cNSMutableArray = (VALUE)objc_getClass("NSMutableArray");
+    rb_set_class_path(rb_cNSMutableArray, rb_cObject, "NSMutableArray");
+    rb_const_set(rb_cObject, rb_intern("Array"), rb_cNSMutableArray);
 #else
     rb_cArray  = rb_define_class("Array", rb_cObject);
 #endif
     rb_include_module(rb_cArray, rb_mEnumerable);
 
+#if !WITH_OBJC
     rb_define_alloc_func(rb_cArray, ary_alloc);
+#endif
     rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
     rb_define_singleton_method(rb_cArray, "try_convert", rb_ary_s_try_convert, 1);
     rb_define_method(rb_cArray, "initialize", rb_ary_initialize, -1);

Modified: MacRuby/branches/lrz_unstable/class.c
===================================================================
--- MacRuby/branches/lrz_unstable/class.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/class.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -24,66 +24,6 @@
 
 #if WITH_OBJC
 
-VALUE
-rb_objc_import_class(Class ocklass)
-{
-#if 0
-    VALUE rbklass;
-    ID nameid;
-    VALUE super;
-
-    assert(ocklass != NULL);
-    assert(class_isMetaClass(ocklass) == 0);
-
-    {
-	NEWOBJ(obj, struct RClass);
-	OBJSETUP(obj, rb_cClass, T_CLASS);
-	rbklass = (VALUE)obj;
-    }
-
-    RBASIC(rbklass)->isa = ocklass->isa;
-    RCLASS(rbklass)->ocklass = ocklass;
-
-    RCLASS_M_TBL(rbklass) = st_init_numtable();
-
-    nameid = rb_intern(class_getName(ocklass));
-
-    if (rb_cObject != 0 && RCLASS_IV_TBL(rb_cObject) != NULL)
-	st_delete(RCLASS_IV_TBL(rb_cObject), (st_data_t*)&nameid, NULL);
-    rb_const_set((rb_cObject != 0 ? rb_cObject : rbklass), nameid, rbklass);   
-
-    /* FIXME do we need to maintain rb_class_tbl anymore? */
-    st_insert(rb_class_tbl, (st_data_t)nameid, (st_data_t)rbklass);
-
-    ocklass = class_getSuperclass(ocklass);
-
-    /* Hack: make sure that all classes that inherit from NSObject have their
-     * Ruby class counterpart inherit from Object first.
-     * This is because constants declared in Object are meant to be visible
-     * in all scopes, and we need to be able to access them in Ruby-written
-     * subclasses of Objective-C classes. 
-     */
-    if (rb_cBasicObject != 0
-	&& rb_cObject != 0
-	&& ocklass == RCLASS_OCID(rb_cBasicObject)) {
-	super = rb_cObject;
-    }
-    else {
-	super = ocklass == NULL ? 0 : rb_objc_import_class(ocklass);
-    }
-
-    RCLASS_SUPER(rbklass) = super;
-    OBJ_INFECT(rbklass, super);
-    FL_SET(rbklass, RCLASS_OBJC_IMPORTED);
-
-    if (super != 0)
-	rb_make_metaclass(rbklass, RBASIC(super)->klass);
-
-    return rbklass;
-#endif
-    return (VALUE)ocklass;
-}
-
 void rb_objc_install_array_primitives(Class);
 void rb_objc_install_hash_primitives(Class);
 void rb_objc_install_string_primitives(Class);
@@ -178,13 +118,6 @@
     return klass;
 }
 
-VALUE
-rb_objc_rename_class(VALUE klass, const char *name)
-{
-    /* TODO */
-    return klass;
-}
-
 #else /* WITH_OBJC */
 
 static VALUE
@@ -280,18 +213,17 @@
 rb_mod_init_copy(VALUE clone, VALUE orig)
 {
     rb_obj_init_copy(clone, orig);
-    if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
+    if (!RCLASS_SINGLETON(CLASS_OF(clone))) {
 	RBASIC(clone)->klass = rb_singleton_class_clone(orig);
     }
-#if !WITH_OBJC
-    RCLASS_SUPER(clone) = RCLASS_SUPER(orig);
-#endif
 #if WITH_OBJC
     {
 	Class ocsuper;
-	if (orig == rb_cStringRuby
-	    || orig == rb_cArrayRuby
-	    || orig == rb_cHashRuby) {
+	int version_flag;
+
+	if (orig == rb_cNSMutableString
+	    || orig == rb_cNSMutableArray
+	    || orig == rb_cNSMutableHash) {
 	    ocsuper = (Class)orig;
 	    rb_warn("cloning class `%s' is not supported, creating a " \
 		    "subclass instead", rb_class2name(orig));
@@ -300,7 +232,15 @@
 	    ocsuper = class_getSuperclass((Class)orig);
 	}
 	class_setSuperclass((Class)clone, ocsuper);
+
+	version_flag = RCLASS_IS_RUBY_CLASS;
+	if ((RCLASS_VERSION(ocsuper) & RCLASS_IS_OBJECT_SUBCLASS) == RCLASS_IS_OBJECT_SUBCLASS)
+	    version_flag |= RCLASS_IS_OBJECT_SUBCLASS;
+
+	class_setVersion((Class)clone, version_flag);
     }
+#else
+    RCLASS_SUPER(clone) = RCLASS_SUPER(orig);
 #endif
 #if 0 // TODO
     if (RCLASS_IV_TBL(orig)) {
@@ -329,10 +269,12 @@
 VALUE
 rb_class_init_copy(VALUE clone, VALUE orig)
 {
+#if !WITH_OBJC
     if (RCLASS_SUPER(clone) != 0) {
 	rb_raise(rb_eTypeError, "already initialized class");
     }
-    if (FL_TEST(orig, FL_SINGLETON)) {
+#endif
+    if (RCLASS_SINGLETON(orig)) {
 	rb_raise(rb_eTypeError, "can't copy singleton class");
     }
     clone =  rb_mod_init_copy(clone, orig);
@@ -635,7 +577,7 @@
 	ary = rb_ary_new();
 	rb_ivar_set(klass, idIncludedModules, ary);
     }
-    rb_ary_push(ary, module);
+    rb_ary_insert(ary, 0, module);
 
     ary = rb_ivar_get(module, idIncludedInClasses);
     if (ary == Qnil) {
@@ -727,9 +669,18 @@
     VALUE p;
 
     for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
+#if WITH_OBJC
+	VALUE inc_mods = rb_ivar_get(p, idIncludedModules);
+	if (inc_mods != Qnil) {
+	    int i, count = RARRAY_LEN(inc_mods);
+	    for (i = 0; i < count; i++)
+		rb_ary_push(ary, RARRAY_AT(inc_mods, i));
+	}
+#else
 	if (BUILTIN_TYPE(p) == T_ICLASS) {
 	    rb_ary_push(ary, RBASIC(p)->klass);
 	}
+#endif
     }
     return ary;
 }
@@ -756,6 +707,9 @@
 VALUE
 rb_mod_include_p(VALUE mod, VALUE mod2)
 {
+#if WITH_OBJC
+    return rb_ary_includes(rb_mod_included_modules(mod), mod2);
+#else
     VALUE p;
 
     Check_Type(mod2, T_MODULE);
@@ -765,6 +719,7 @@
 	}
     }
     return Qfalse;
+#endif
 }
 
 /*
@@ -790,7 +745,15 @@
 
     for (p = mod; p; p = RCLASS_SUPER(p)) {
 #if WITH_OBJC
+	VALUE inc_mods;
+
 	rb_ary_push(ary, p);
+	inc_mods = rb_ivar_get(p, idIncludedModules);
+	if (inc_mods != Qnil) {
+	    int i, count;
+	    for (i = 0, count = RARRAY_LEN(inc_mods); i < count; i++)
+		rb_ary_push(ary, RARRAY_AT(inc_mods, i));
+	}
 #else
 	if (RCLASS_SINGLETON(p))
 	    continue;

Modified: MacRuby/branches/lrz_unstable/eval.c
===================================================================
--- MacRuby/branches/lrz_unstable/eval.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/eval.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -857,11 +857,11 @@
     return module;
 }
 
-void
+VALUE
 rb_obj_call_init(VALUE obj, int argc, VALUE *argv)
 {
     PASS_PASSED_BLOCK();
-    rb_funcall2(obj, idInitialize, argc, argv);
+    return rb_funcall2(obj, idInitialize, argc, argv);
 }
 
 void

Modified: MacRuby/branches/lrz_unstable/hash.c
===================================================================
--- MacRuby/branches/lrz_unstable/hash.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/hash.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -15,6 +15,7 @@
 #include "ruby/st.h"
 #include "ruby/util.h"
 #include "ruby/signal.h"
+#include "id.h"
 
 #ifdef __APPLE__
 #include <crt_externs.h>
@@ -34,7 +35,8 @@
 VALUE rb_cHash;
 #if WITH_OBJC
 VALUE rb_cCFHash;
-VALUE rb_cHashRuby;
+VALUE rb_cNSHash;
+VALUE rb_cNSMutableHash;
 #endif
 
 static VALUE envtbl;
@@ -338,7 +340,7 @@
     values_cb.equal = rb_cfdictionary_equal_cb;
 
     hash = (VALUE)CFDictionaryCreateMutable(NULL, 0, &keys_cb, &values_cb);
-    if (klass != 0 && klass != rb_cHash && klass != rb_cHashRuby)
+    if (klass != 0 && klass != rb_cNSHash && klass != rb_cNSMutableHash)
 	*(Class *)hash = (Class)klass;
 
     CFMakeCollectable((CFTypeRef)hash);
@@ -453,7 +455,12 @@
 {
     VALUE ifnone;
 
+#if WITH_OBJC
+    hash = (VALUE)objc_msgSend((id)hash, selInit);
+#else
     rb_hash_modify(hash);
+#endif
+
     if (rb_block_given_p()) {
 	if (argc > 0) {
 	    rb_raise(rb_eArgError, "wrong number of arguments");
@@ -3056,17 +3063,20 @@
     id_default = rb_intern("default");
 
 #if WITH_OBJC
-    rb_cCFHash = rb_objc_import_class((Class)objc_getClass("NSCFDictionary"));
-    rb_cHash = rb_objc_import_class((Class)objc_getClass("NSDictionary"));
-    rb_cHashRuby = rb_objc_import_class((Class)objc_getClass("NSMutableDictionary"));
-    rb_const_set(rb_cObject, rb_intern("Hash"), rb_cHashRuby);
+    rb_cCFHash = (VALUE)objc_getClass("NSCFDictionary");
+    rb_cHash = rb_cNSHash = (VALUE)objc_getClass("NSDictionary");
+    rb_cNSMutableHash = (VALUE)objc_getClass("NSMutableDictionary");
+    rb_set_class_path(rb_cNSMutableHash, rb_cObject, "NSMutableDictionary");
+    rb_const_set(rb_cObject, rb_intern("Hash"), rb_cNSMutableHash);
 #else
     rb_cHash = rb_define_class("Hash", rb_cObject);
 #endif
 
     rb_include_module(rb_cHash, rb_mEnumerable);
 
+#if !WITH_OBJC
     rb_define_alloc_func(rb_cHash, hash_alloc);
+#endif
     rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
     rb_define_singleton_method(rb_cHash, "try_convert", rb_hash_s_try_convert, 1);
     rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);

Modified: MacRuby/branches/lrz_unstable/id.c
===================================================================
--- MacRuby/branches/lrz_unstable/id.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/id.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -58,6 +58,7 @@
     selLength = sel_registerName("length");
     selSucc = sel_registerName("succ");
     selNot = sel_registerName("!");
+    selInit = sel_registerName("init");
 #endif
 
     idAREF = rb_intern("[]");

Modified: MacRuby/branches/lrz_unstable/id.h
===================================================================
--- MacRuby/branches/lrz_unstable/id.h	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/id.h	2008-07-31 22:22:07 UTC (rev 390)
@@ -70,6 +70,7 @@
 extern SEL selLength;
 extern SEL selSucc;
 extern SEL selNot;
+extern SEL selInit;
 extern ID idIncludedModules;
 extern ID idIncludedInClasses;
 #endif

Modified: MacRuby/branches/lrz_unstable/include/ruby/intern.h
===================================================================
--- MacRuby/branches/lrz_unstable/include/ruby/intern.h	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/include/ruby/intern.h	2008-07-31 22:22:07 UTC (rev 390)
@@ -77,6 +77,7 @@
 VALUE rb_ary_cmp(VALUE, VALUE);
 VALUE rb_ary_replace(VALUE copy, VALUE orig);
 VALUE rb_get_values_at(VALUE, long, int, VALUE*, VALUE(*)(VALUE,long));
+void rb_ary_insert(VALUE, long, VALUE);
 #if WITH_OBJC
 VALUE rb_ary_elt(VALUE, long);
 bool rb_objc_ary_is_pure(VALUE);
@@ -147,9 +148,7 @@
 #define rb_Complex2(x,y) rb_Complex(x, y)
 /* class.c */
 #if WITH_OBJC
-VALUE rb_objc_import_class(Class);
 VALUE rb_objc_create_class(const char *name, VALUE super);
-VALUE rb_objc_rename_class(VALUE klass, const char *name);
 bool rb_objc_install_primitives(Class ocklass, Class ocsuper);
 #endif
 VALUE rb_class_boot(VALUE);
@@ -279,7 +278,7 @@
 void rb_provide(const char*);
 VALUE rb_f_require(VALUE, VALUE);
 VALUE rb_require_safe(VALUE, int);
-void rb_obj_call_init(VALUE, int, VALUE*);
+VALUE rb_obj_call_init(VALUE, int, VALUE*);
 VALUE rb_class_new_instance(int, VALUE*, VALUE);
 VALUE rb_block_proc(void);
 VALUE rb_f_lambda(void);

Modified: MacRuby/branches/lrz_unstable/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/lrz_unstable/include/ruby/ruby.h	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/include/ruby/ruby.h	2008-07-31 22:22:07 UTC (rev 390)
@@ -1008,11 +1008,14 @@
 
 #if WITH_OBJC
 RUBY_EXTERN VALUE rb_cCFString;
-RUBY_EXTERN VALUE rb_cStringRuby;
+RUBY_EXTERN VALUE rb_cNSString;
+RUBY_EXTERN VALUE rb_cNSMutableString;
 RUBY_EXTERN VALUE rb_cCFArray;
-RUBY_EXTERN VALUE rb_cArrayRuby;
+RUBY_EXTERN VALUE rb_cNSArray;
+RUBY_EXTERN VALUE rb_cNSMutableArray;
 RUBY_EXTERN VALUE rb_cCFHash;
-RUBY_EXTERN VALUE rb_cHashRuby;
+RUBY_EXTERN VALUE rb_cNSHash;
+RUBY_EXTERN VALUE rb_cNSMutableHash;
 #endif
 
 RUBY_EXTERN VALUE rb_eException;

Modified: MacRuby/branches/lrz_unstable/numeric.c
===================================================================
--- MacRuby/branches/lrz_unstable/numeric.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/numeric.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -3190,8 +3190,7 @@
     rb_eZeroDivError = rb_define_class("ZeroDivisionError", rb_eStandardError);
     rb_eFloatDomainError = rb_define_class("FloatDomainError", rb_eRangeError);
 #if WITH_OBJC
-    rb_cNumeric = rb_define_class("Numeric",
-        rb_objc_import_class((void*)objc_getClass("NSNumber")));
+    rb_cNumeric = rb_define_class("Numeric", (VALUE)objc_getClass("NSNumber"));
     // We need to redefine #class because otherwise NSObject#class will return NSCFNumber for all numeric types.
     rb_define_method(rb_cNumeric, "class", rb_obj_class, 0);
 #else

Modified: MacRuby/branches/lrz_unstable/objc.m
===================================================================
--- MacRuby/branches/lrz_unstable/objc.m	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/objc.m	2008-07-31 22:22:07 UTC (rev 390)
@@ -59,7 +59,6 @@
 static ID rb_ivar_type;
 
 static VALUE bs_const_magic_cookie = Qnil;
-static VALUE rb_objc_class_magic_cookie = Qnil;
 
 static struct st_table *bs_constants;
 static struct st_table *bs_functions;
@@ -894,7 +893,7 @@
 	    break;
 	
 	case _C_CLASS:
-	    *rbval = rb_objc_import_class(*(Class *)ocval);
+	    *rbval = (VALUE)*(Class *)ocval;
 	    break;
 
 	case _C_BOOL:
@@ -1729,10 +1728,7 @@
     void *sym;
     bs_element_constant_t *bs_const;
 
-    if (v == rb_objc_class_magic_cookie) {
-	v = rb_objc_import_class(objc_getClass(rb_id2name(id)));
-    }
-    else if (v == bs_const_magic_cookie) { 
+    if (v == bs_const_magic_cookie) { 
 	if (!st_lookup(bs_constants, (st_data_t)id, (st_data_t *)&bs_const))
 	    rb_bug("unresolved bridgesupport constant `%s' not in cache",
 		    rb_id2name(id));
@@ -2338,7 +2334,7 @@
 	if (name[0] != '_') {
 	    ID id = rb_intern(name);
 	    if (!rb_const_defined(rb_cObject, id))
-		rb_const_set(rb_cObject, id, rb_objc_class_magic_cookie);
+		rb_const_set(rb_cObject, id, (VALUE)buf[i]);
 	}
     }
 
@@ -2981,11 +2977,8 @@
 
     rb_objc_retain((const void *)(
 	bs_const_magic_cookie = rb_str_new2("bs_const_magic_cookie")));
-    rb_objc_retain((const void *)(
-	rb_objc_class_magic_cookie = rb_str_new2("rb_objc_class_magic_cookie")));
 
-    rb_cBoxed = rb_define_class("Boxed",
-	rb_objc_import_class(objc_getClass("NSValue")));
+    rb_cBoxed = rb_define_class("Boxed", (VALUE)objc_getClass("NSValue"));
     rb_define_singleton_method(rb_cBoxed, "objc_type", rb_boxed_objc_type, 0);
     rb_define_singleton_method(rb_cBoxed, "opaque?", rb_boxed_is_opaque, 0);
     rb_define_singleton_method(rb_cBoxed, "fields", rb_boxed_fields, 0);

Modified: MacRuby/branches/lrz_unstable/object.c
===================================================================
--- MacRuby/branches/lrz_unstable/object.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/object.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -289,6 +289,8 @@
  *  the class.
  */
 
+static VALUE rb_class_s_alloc(VALUE);
+
 VALUE
 rb_obj_clone(VALUE obj)
 {
@@ -298,19 +300,31 @@
         rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
     }
 #if WITH_OBJC
-    if (NATIVE(obj)) {
-        clone = rb_obj_alloc(rb_obj_class(obj));
-        init_copy(clone, obj);
-	if (OBJ_FROZEN(obj))
-	    OBJ_FREEZE(clone);
-	return clone;
+    switch (TYPE(obj)) {
+	case T_NATIVE:
+	    clone = rb_obj_alloc(rb_obj_class(obj));
+	    break;
+	case T_CLASS:
+	case T_MODULE:
+	    clone = rb_class_s_alloc(Qnil);
+	    break;
+	default:
+	    clone = rb_obj_alloc(rb_obj_class(obj));
+	    RBASIC(clone)->klass = rb_singleton_class_clone(obj);
+	    RBASIC(clone)->flags = (RBASIC(obj)->flags | FL_TEST(clone, FL_TAINT)) & ~(FL_FREEZE|FL_FINALIZE);
+	    break;
     }
-#endif
+
+    init_copy(clone, obj);
+    if (OBJ_FROZEN(obj))
+	OBJ_FREEZE(clone);
+#else
     clone = rb_obj_alloc(rb_obj_class(obj));
     RBASIC(clone)->klass = rb_singleton_class_clone(obj);
     RBASIC(clone)->flags = (RBASIC(obj)->flags | FL_TEST(clone, FL_TAINT)) & ~(FL_FREEZE|FL_FINALIZE);
     init_copy(clone, obj);
     RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
+#endif
 
     return clone;
 }
@@ -353,7 +367,11 @@
 {
     if (obj == orig) return obj;
     rb_check_frozen(obj);
+#if WITH_OBJC
+    if (TYPE(obj) != TYPE(orig)) {
+#else
     if (TYPE(obj) != TYPE(orig) || rb_obj_class(obj) != rb_obj_class(orig)) {
+#endif
 	rb_raise(rb_eTypeError, "initialize_copy should take same class object");
     }
     return obj;
@@ -1500,9 +1518,11 @@
 {
     VALUE super;
 
+#if !WITH_OBJC
     if (RCLASS_SUPER(klass) != 0) {
 	rb_raise(rb_eTypeError, "already initialized class");
     }
+#endif
     if (argc == 0) {
 	super = rb_cObject;
     }
@@ -1513,8 +1533,9 @@
     RCLASS_SUPER(klass) = super;
 #if WITH_OBJC
     rb_objc_install_primitives((Class)klass, (Class)super);
+#else
+    rb_make_metaclass(klass, RBASIC(super)->klass);
 #endif
-    rb_make_metaclass(klass, RBASIC(super)->klass);
     rb_class_inherited(super, klass);
     rb_mod_initialize(klass);
 
@@ -1573,19 +1594,16 @@
 VALUE
 rb_class_new_instance(int argc, VALUE *argv, VALUE klass)
 {
-    VALUE obj;
+    VALUE obj, init_obj, p;
 
-#if 0//WITH_OBJC
-    if (FL_TEST(klass, RCLASS_OBJC_IMPORTED)) {
-	static SEL sel_new = 0;
-	if (sel_new == 0)
-	    sel_new = sel_registerName("new");
-	obj = (VALUE)objc_msgSend((id)RCLASS_OCID(klass), sel_new);
-	return obj;
+    obj = rb_obj_alloc(klass);
+    init_obj = rb_obj_call_init(obj, argc, argv);
+    p = CLASS_OF(init_obj);
+    while (p != 0) {
+	if (p == klass)
+	    return init_obj;
+	p = RCLASS_SUPER(p);
     }
-#endif
-    obj = rb_obj_alloc(klass);
-    rb_obj_call_init(obj, argc, argv);
 
     return obj;
 }
@@ -1603,6 +1621,7 @@
  *     
  */
 
+#if !WITH_OBJC
 static VALUE
 rb_class_superclass(VALUE klass)
 {
@@ -1620,6 +1639,7 @@
     }
     return super;
 }
+#endif
 
 /*
  *  call-seq:
@@ -2719,7 +2739,9 @@
     rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
     rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
     rb_define_method(rb_cClass, "initialize_copy", rb_class_init_copy, 1); /* in class.c */
+#if !WITH_OBJC
     rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
+#endif
     rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
     rb_undef_method(rb_cClass, "extend_object");
     rb_undef_method(rb_cClass, "append_features");

Modified: MacRuby/branches/lrz_unstable/string.c
===================================================================
--- MacRuby/branches/lrz_unstable/string.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/string.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -14,6 +14,7 @@
 #include "ruby/ruby.h"
 #include "ruby/re.h"
 #include "ruby/encoding.h"
+#include "id.h"
 
 #define BEG(no) regs->beg[no]
 #define END(no) regs->end[no]
@@ -28,7 +29,8 @@
 VALUE rb_cString;
 #if WITH_OBJC
 VALUE rb_cCFString;
-VALUE rb_cStringRuby;
+VALUE rb_cNSString;
+VALUE rb_cNSMutableString;
 #endif
 VALUE rb_cSymbol;
 
@@ -475,8 +477,8 @@
 
     str = (VALUE)CFStringCreateMutable(NULL, 0);
     if (klass != 0 
-	&& klass != rb_cString 
-	&& klass != rb_cStringRuby 
+	&& klass != rb_cNSString 
+	&& klass != rb_cNSMutableString
 	&& klass != rb_cSymbol)
 	*(Class *)str = (Class)klass;
     CFMakeCollectable((CFTypeRef)str);
@@ -914,6 +916,10 @@
 {
     VALUE orig;
 
+#if WITH_OBJC
+    str = (VALUE)objc_msgSend((id)str, selInit);
+#endif
+
     if (argc > 0 && rb_scan_args(argc, argv, "01", &orig) == 1)
 	rb_str_replace(str, orig);
     return str;
@@ -8516,17 +8522,21 @@
 Init_String(void)
 {
 #if WITH_OBJC
-    rb_cCFString = rb_objc_import_class((Class)objc_getClass("NSCFString"));
-    rb_cString = rb_objc_import_class((Class)objc_getClass("NSString"));
-    rb_cStringRuby =
-        rb_objc_import_class((Class)objc_getClass("NSMutableString"));
-    rb_const_set(rb_cObject, rb_intern("String"), rb_cStringRuby);
+    rb_cCFString = (VALUE)objc_getClass("NSCFString");
+    rb_cString = rb_cNSString = (VALUE)objc_getClass("NSString");
+    rb_cNSMutableString = (VALUE)objc_getClass("NSMutableString");
+    rb_const_set(rb_cObject, rb_intern("String"), rb_cNSMutableString);
+    rb_set_class_path(rb_cNSMutableString, rb_cObject, "NSMutableString");
     rb_define_method(rb_cString, "__bytestring__?", rb_str_bytestring_m, 0);
 #else
     rb_cString  = rb_define_class("String", rb_cObject);
 #endif
+
     rb_include_module(rb_cString, rb_mComparable);
+
+#if !WITH_OBJC
     rb_define_alloc_func(rb_cString, str_alloc);
+#endif
     rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1);
     rb_define_method(rb_cString, "initialize", rb_str_init, -1);
     rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);

Modified: MacRuby/branches/lrz_unstable/variable.c
===================================================================
--- MacRuby/branches/lrz_unstable/variable.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/variable.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -16,6 +16,7 @@
 #include "ruby/st.h"
 #include "ruby/util.h"
 #include "debug.h"
+#include "id.h"
 
 void rb_vm_change_state(void);
 st_table *rb_global_tbl;
@@ -285,9 +286,6 @@
     }
     OBJ_FREEZE(str);
     rb_ivar_set(klass, classpath, str);
-#if WITH_OBJC
-    rb_objc_rename_class(klass, RSTRING_PTR(str));
-#endif
 }
 
 VALUE
@@ -2021,7 +2019,7 @@
   retry:
     while (RTEST(tmp)) {
 #if WITH_OBJC
-	CFDictionaryRef iv_dict = rb_class_ivar_dict(tmp);
+	CFDictionaryRef iv_dict;
 	while ((iv_dict = rb_class_ivar_dict(tmp)) != NULL
 	       && CFDictionaryGetValueIfPresent(iv_dict, (const void *)id, (const void **)&value)) {
 #else
@@ -2041,6 +2039,17 @@
 	    return value;
 	}
 	if (!recurse && klass != rb_cObject) break;
+#if WITH_OBJC
+	VALUE inc_mods = rb_ivar_get(tmp, idIncludedModules);
+	if (inc_mods != Qnil) {
+	    int i, count = RARRAY_LEN(inc_mods);
+	    for (i = 0; i < count; i++) {
+		iv_dict = rb_class_ivar_dict(RARRAY_AT(inc_mods, i));
+		if (CFDictionaryGetValueIfPresent(iv_dict, (const void *)id, (const void **)&value))
+		    return rb_objc_resolve_const_value(value, klass, id);
+	    }
+	}
+#endif
 	tmp = RCLASS_SUPER(tmp);
     }
     if (!exclude && !mod_retry && BUILTIN_TYPE(klass) == T_MODULE) {
@@ -2057,11 +2066,8 @@
      */
     {
 	Class k = (Class)objc_getClass(rb_id2name(id));
-	if (k != NULL) {
-	    tmp = rb_objc_import_class(k);
-	    if (!NIL_P(tmp))
-		return tmp;
-	}
+	if (k != NULL)
+	    return (VALUE)k;
     }
 #endif
 

Modified: MacRuby/branches/lrz_unstable/vm_eval.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_eval.c	2008-07-31 01:23:15 UTC (rev 389)
+++ MacRuby/branches/lrz_unstable/vm_eval.c	2008-07-31 22:22:07 UTC (rev 390)
@@ -197,6 +197,14 @@
     IMP imp;
     SEL sel;
 
+    if (argc > 0) {
+	char buf[512];
+	strncpy(buf, rb_id2name(mid), sizeof buf);
+	if (buf[strlen(buf) - 1] != ':')
+	    strlcat(buf, ":", sizeof buf);
+	mid = rb_intern(buf);
+    }
+
     method = rb_objc_method_node(klass, mid, &imp, &sel);    
 
     if (imp != NULL && method == NULL)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080731/18a4d2db/attachment-0001.html 


More information about the macruby-changes mailing list