Revision: 411 http://trac.macosforge.org/projects/ruby/changeset/411 Author: lsansonetti@apple.com Date: 2008-08-06 01:49:29 -0700 (Wed, 06 Aug 2008) Log Message: ----------- wip Modified Paths: -------------- MacRuby/branches/lrz_unstable/class.c MacRuby/branches/lrz_unstable/ext/syck/rubyext.c MacRuby/branches/lrz_unstable/include/ruby/ruby.h MacRuby/branches/lrz_unstable/insns.def MacRuby/branches/lrz_unstable/lib/fileutils.rb MacRuby/branches/lrz_unstable/numeric.c MacRuby/branches/lrz_unstable/objc.m MacRuby/branches/lrz_unstable/object.c MacRuby/branches/lrz_unstable/struct.c MacRuby/branches/lrz_unstable/vm_eval.c Modified: MacRuby/branches/lrz_unstable/class.c =================================================================== --- MacRuby/branches/lrz_unstable/class.c 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/class.c 2008-08-06 08:49:29 UTC (rev 411) @@ -56,21 +56,25 @@ } static VALUE +rb_class_allocate_instance(VALUE klass) +{ + NEWOBJ(obj, struct RObject); + OBJSETUP(obj, klass, T_OBJECT); + return (VALUE)obj; +} + +static VALUE rb_objc_alloc_class(const char *name, VALUE super, VALUE flags, VALUE klass) { - Class ocsuper, ocklass; + Class ocklass; char ocname[128]; + int version_flag; if (name == NULL) { static long anon_count = 1; snprintf(ocname, sizeof ocname, "RBAnonymous%ld", ++anon_count); } else { - if (super == rb_cNSObject && strcmp(name, "Object") != 0) { - rb_warn("Do not subclass NSObject directly, please subclass " \ - "Object instead."); - super = rb_cObject; - } if (objc_getClass(name) != NULL) { long count = 1; snprintf(ocname, sizeof ocname, "RB%s", name); @@ -84,24 +88,31 @@ } } - ocsuper = super == 0 ? (Class)rb_cObject : (Class)super; - ocklass = objc_allocateClassPair(ocsuper, ocname, sizeof(id)); + if (super == 0) + super = rb_cObject; + + ocklass = objc_allocateClassPair((Class)super, ocname, sizeof(id)); assert(ocklass != NULL); - int version_flag; - version_flag = RCLASS_IS_RUBY_CLASS; - if (flags == T_MODULE) + if (flags == T_MODULE) { version_flag |= RCLASS_IS_MODULE; - if ((RCLASS_VERSION(ocsuper) & RCLASS_IS_OBJECT_SUBCLASS) == RCLASS_IS_OBJECT_SUBCLASS) + } + if (super == rb_cObject) { version_flag |= RCLASS_IS_OBJECT_SUBCLASS; + rb_define_alloc_func((VALUE)ocklass, rb_class_allocate_instance); + rb_define_singleton_method((VALUE)ocklass, "new", rb_class_new_instance, -1); + } + else if ((RCLASS_VERSION(super) & RCLASS_IS_OBJECT_SUBCLASS) == RCLASS_IS_OBJECT_SUBCLASS) { + version_flag |= RCLASS_IS_OBJECT_SUBCLASS; + } class_setVersion(ocklass, version_flag); DLOG("DEFC", "%s < %s (version=%d)", ocname, class_getName(class_getSuperclass((Class)ocklass)), version_flag); if (klass != 0) - rb_objc_install_primitives(ocklass, ocsuper); + rb_objc_install_primitives(ocklass, (Class)super); return (VALUE)ocklass; } Modified: MacRuby/branches/lrz_unstable/ext/syck/rubyext.c =================================================================== --- MacRuby/branches/lrz_unstable/ext/syck/rubyext.c 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/ext/syck/rubyext.c 2008-08-06 08:49:29 UTC (rev 411) @@ -22,11 +22,11 @@ #endif struct RBasic basic; struct RObject object; - struct RClass klass; /*struct RFloat flonum;*/ /*struct RString string;*/ /*struct RRegexp regexp;*/ #if !WITH_OBJC + struct RClass klass; struct RArray array; struct RHash hash; #endif Modified: MacRuby/branches/lrz_unstable/include/ruby/ruby.h =================================================================== --- MacRuby/branches/lrz_unstable/include/ruby/ruby.h 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/include/ruby/ruby.h 2008-08-06 08:49:29 UTC (rev 411) @@ -1092,10 +1092,7 @@ static inline bool rb_is_native(VALUE obj) { Class k = *(Class *)obj; - return k != NULL - && k != (Class)rb_cBignum - && k != (Class)rb_cFloat - && (RCLASS_VERSION(k) & RCLASS_IS_OBJECT_SUBCLASS) != RCLASS_IS_OBJECT_SUBCLASS; + return k != NULL && (RCLASS_VERSION(k) & RCLASS_IS_OBJECT_SUBCLASS) != RCLASS_IS_OBJECT_SUBCLASS; } #define NATIVE(obj) (rb_is_native((VALUE)obj)) @@ -1213,6 +1210,7 @@ || (RCLASS_VERSION(k) & RCLASS_IS_HASH_SUBCLASS) == RCLASS_IS_HASH_SUBCLASS) return T_HASH; + if (k == (Class)rb_cFixnum) return T_FIXNUM; if (NATIVE(obj)) return T_NATIVE; } #endif Modified: MacRuby/branches/lrz_unstable/insns.def =================================================================== --- MacRuby/branches/lrz_unstable/insns.def 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/insns.def 2008-08-06 08:49:29 UTC (rev 411) @@ -812,9 +812,21 @@ break; case DEFINED_METHOD:{ VALUE klass = CLASS_OF(v); +#if WITH_OBJC + NODE *method; + IMP imp; + + method = rb_objc_method_node(klass, SYM2ID(obj), &imp, NULL); + + if (method == NULL && imp != NULL) { + expr_type = "method"; + } + else if (method != NULL) { +#else NODE *method = (NODE *) rb_method_node(klass, SYM2ID(obj)); if (method) { +#endif if (!(method->nd_noex & NOEX_PRIVATE)) { if (!((method->nd_noex & NOEX_PROTECTED) && !rb_obj_is_kind_of(GET_SELF(), Modified: MacRuby/branches/lrz_unstable/lib/fileutils.rb =================================================================== --- MacRuby/branches/lrz_unstable/lib/fileutils.rb 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/lib/fileutils.rb 2008-08-06 08:49:29 UTC (rev 411) @@ -1507,8 +1507,8 @@ end METHODS = singleton_methods() - [:private_module_function, - :commands, :options, :have_option?, :options_of, :collect_method] - METHODS -= NSObject.methods + :commands, :options, :have_option?, :options_of, + :collect_method] - NSObject.methods # # This module has all methods of FileUtils module, but it outputs messages Modified: MacRuby/branches/lrz_unstable/numeric.c =================================================================== --- MacRuby/branches/lrz_unstable/numeric.c 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/numeric.c 2008-08-06 08:49:29 UTC (rev 411) @@ -3216,6 +3216,7 @@ #if WITH_OBJC rb_cCFNumber = (VALUE)objc_getClass("NSCFNumber"); rb_cNumeric = rb_define_class("Numeric", (VALUE)objc_getClass("NSNumber")); + RCLASS_SET_VERSION_FLAG(rb_cNumeric, RCLASS_IS_OBJECT_SUBCLASS); /* overriding NSObject methods */ rb_define_method(rb_cNumeric, "class", rb_obj_class, 0); rb_define_method(rb_cNumeric, "dup", rb_obj_dup, 0); Modified: MacRuby/branches/lrz_unstable/objc.m =================================================================== --- MacRuby/branches/lrz_unstable/objc.m 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/objc.m 2008-08-06 08:49:29 UTC (rev 411) @@ -1522,27 +1522,23 @@ DLOG("DEFM", "%c[%s %s] types=%s arity=%d body=%p override=%d direct_override=%d", class_isMetaClass((Class)mod) ? '+' : '-', class_getName((Class)mod), (char *)sel, types, arity, body, method != NULL, direct_override); - if (node == NULL) { - assert(class_addMethod((Class)mod, sel, NULL, types)); - forward_method_definition(included_in_classes, sel, NULL, types); + imp = body == NULL ? NULL : rb_ruby_to_objc_closure(types, oc_arity, body); + + if (method != NULL && direct_override) { + method_setImplementation(method, imp); } else { + assert(class_addMethod((Class)mod, sel, imp, types)); + } + forward_method_definition(included_in_classes, sel, imp, types); + + if (node != NULL) { const char *sel_str = (const char *)sel; const size_t sel_len = strlen(sel_str); SEL new_sel; char *new_types; bool override; - imp = rb_ruby_to_objc_closure(types, oc_arity, body); - - if (method != NULL && direct_override) { - method_setImplementation(method, imp); - } - else { - assert(class_addMethod((Class)mod, sel, imp, types)); - } - forward_method_definition(included_in_classes, sel, imp, types); - if (sel_str[sel_len - 1] == ':') { char buf[512]; strlcpy(buf, sel_str, sizeof buf); @@ -1580,22 +1576,6 @@ } } -VALUE -rb_mod_objc_ancestors(VALUE recv) -{ - Class klass; - VALUE ary; - - ary = rb_ary_new(); - - for (klass = (Class)recv; klass != NULL; - klass = class_getSuperclass(klass)) { - rb_ary_push(ary, rb_str_new2(class_getName(klass))); - } - - return ary; -} - static bool rb_objc_resourceful(VALUE obj) { Modified: MacRuby/branches/lrz_unstable/object.c =================================================================== --- MacRuby/branches/lrz_unstable/object.c 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/object.c 2008-08-06 08:49:29 UTC (rev 411) @@ -1589,6 +1589,7 @@ return obj; } +#if !WITH_OBJC static VALUE rb_class_allocate_instance(VALUE klass) { @@ -1596,6 +1597,7 @@ OBJSETUP(obj, klass, T_OBJECT); return (VALUE)obj; } +#endif /* * call-seq: @@ -2583,10 +2585,9 @@ Init_Object(void) { #if WITH_OBJC - rb_cNSObject = (VALUE)objc_getClass("NSObject"); - rb_cObject = boot_defclass("Object", rb_cNSObject); + rb_cNSObject = rb_cObject = (VALUE)objc_getClass("NSObject"); + rb_const_set(rb_cObject, rb_intern("Object"), rb_cNSObject); rb_cBasicObject = rb_cObject; // TODO - RCLASS_SET_VERSION_FLAG(rb_cObject, RCLASS_IS_OBJECT_SUBCLASS); rb_cModule = boot_defclass("Module", rb_cObject); rb_cClass = boot_defclass("Class", rb_cModule); RCLASS_SUPER(*(Class *)rb_cNSObject) = rb_cClass; @@ -2605,17 +2606,13 @@ #endif rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_dummy, 0); - rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance); #if WITH_OBJC - // required because otherwise NSObject.new will be first in the method chain. - rb_define_singleton_method(rb_cBasicObject, "new", rb_class_new_instance, -1); -#endif -#if WITH_OBJC rb_define_method(rb_cNSObject, "==", rb_obj_equal, 1); rb_define_method(rb_cNSObject, "equal?", rb_obj_equal, 1); rb_define_method(rb_cNSObject, "!", rb_obj_not, 0); rb_define_method(rb_cNSObject, "!=", rb_obj_not_equal, 1); #else + rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance); rb_define_method(rb_cBasicObject, "==", rb_obj_equal, 1); rb_define_method(rb_cBasicObject, "equal?", rb_obj_equal, 1); rb_define_method(rb_cBasicObject, "!", rb_obj_not, 0); @@ -2627,11 +2624,7 @@ rb_define_private_method(rb_cBasicObject, "singleton_method_undefined", rb_obj_dummy, 1); rb_mKernel = rb_define_module("Kernel"); -#if WITH_OBJC - rb_include_module(rb_cNSObject, rb_mKernel); -#else rb_include_module(rb_cObject, rb_mKernel); -#endif rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1); rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1); rb_define_private_method(rb_cModule, "extended", rb_obj_dummy, 1); @@ -2646,7 +2639,7 @@ rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1); #if !WITH_OBJC - // #class is already defined in NSObject + /* NSObject#class already exists */ rb_define_method(rb_mKernel, "class", rb_obj_class, 0); #endif @@ -2730,7 +2723,6 @@ rb_define_method(rb_cModule, "name", rb_mod_name, 0); /* in variable.c */ rb_define_method(rb_cModule, "ancestors", rb_mod_ancestors, 0); /* in class.c */ #if WITH_OBJC - rb_define_method(rb_cModule, "objc_ancestors", rb_mod_objc_ancestors, 0); /* in objc.m */ rb_define_private_method(rb_cModule, "ib_outlet", rb_mod_objc_ib_outlet, -1); /* in objc.m */ #endif @@ -2770,6 +2762,7 @@ 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 + /* already defined */ rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0); #endif rb_define_alloc_func(rb_cClass, rb_class_s_alloc); Modified: MacRuby/branches/lrz_unstable/struct.c =================================================================== --- MacRuby/branches/lrz_unstable/struct.c 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/struct.c 2008-08-06 08:49:29 UTC (rev 411) @@ -181,7 +181,9 @@ OBJ_FREEZE(members); if (NIL_P(name)) { nstr = rb_class_new(klass); +#if !WITH_OBJC rb_make_metaclass(nstr, RBASIC(klass)->klass); +#endif rb_class_inherited(klass, nstr); } else { Modified: MacRuby/branches/lrz_unstable/vm_eval.c =================================================================== --- MacRuby/branches/lrz_unstable/vm_eval.c 2008-08-06 02:18:19 UTC (rev 410) +++ MacRuby/branches/lrz_unstable/vm_eval.c 2008-08-06 08:49:29 UTC (rev 411) @@ -197,7 +197,7 @@ IMP imp; SEL sel; - if (argc > 0) { + if (argc > 0 && mid != ID_ALLOCATOR) { char buf[512]; strncpy(buf, rb_id2name(mid), sizeof buf); if (buf[strlen(buf) - 1] != ':')
participants (1)
-
source_changes@macosforge.org