Revision: 415 http://trac.macosforge.org/projects/ruby/changeset/415 Author: lsansonetti@apple.com Date: 2008-08-10 01:45:15 -0700 (Sun, 10 Aug 2008) Log Message: ----------- wip Modified Paths: -------------- MacRuby/branches/lrz_unstable/class.c MacRuby/branches/lrz_unstable/compile.c MacRuby/branches/lrz_unstable/hash.c MacRuby/branches/lrz_unstable/objc.m MacRuby/branches/lrz_unstable/object.c Modified: MacRuby/branches/lrz_unstable/class.c =================================================================== --- MacRuby/branches/lrz_unstable/class.c 2008-08-09 02:55:56 UTC (rev 414) +++ MacRuby/branches/lrz_unstable/class.c 2008-08-10 08:45:15 UTC (rev 415) @@ -152,17 +152,15 @@ #endif +#if !WITH_OBJC static VALUE class_alloc(VALUE flags, VALUE klass) { -#if WITH_OBJC - return rb_objc_alloc_class(NULL, 0, flags, klass); -#else NEWOBJ(obj, struct RClass); OBJSETUP(obj, klass, flags); return class_init((VALUE)obj); +} #endif -} VALUE rb_class_boot(VALUE super) @@ -480,9 +478,11 @@ VALUE rb_module_new(void) { +#if WITH_OBJC + VALUE mdl = rb_objc_alloc_class(NULL, 0, T_MODULE, rb_cModule); + objc_registerClassPair((Class)mdl); +#else VALUE mdl = class_alloc(T_MODULE, rb_cModule); - -#if !WITH_OBJC RCLASS_M_TBL(mdl) = st_init_numtable(); #endif Modified: MacRuby/branches/lrz_unstable/compile.c =================================================================== --- MacRuby/branches/lrz_unstable/compile.c 2008-08-09 02:55:56 UTC (rev 414) +++ MacRuby/branches/lrz_unstable/compile.c 2008-08-10 08:45:15 UTC (rev 415) @@ -700,11 +700,29 @@ mcache->as.rcall.klass = 0; mcache->as.rcall.node = NULL; if (FIX2INT(argc) > 0) { - char buf[512]; - strlcpy(buf, rb_sym2name(id), sizeof buf); - if (buf[strlen(buf) - 1] != ':') - strlcat(buf, ":", sizeof buf); - mcache->as.rcall.sel = sel_registerName(buf); + char *id_str; + size_t id_str_len; + char buf[100]; + + 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) { + buf[0] = 's'; + buf[1] = 'e'; + buf[2] = 't'; + buf[3] = toupper(id_str[0]); + strncpy(&buf[4], &id_str[1], id_str_len - 2); + buf[id_str_len + 2] = ':'; + buf[id_str_len + 3] = '\0'; + id_str = buf; + } + else if (id_str[id_str_len - 1] != ':') { + snprintf(buf, sizeof buf, "%s:", id_str); + id_str = buf; + } + + mcache->as.rcall.sel = sel_registerName(id_str); } else { mcache->as.rcall.sel = sel_registerName(rb_sym2name(id)); Modified: MacRuby/branches/lrz_unstable/hash.c =================================================================== --- MacRuby/branches/lrz_unstable/hash.c 2008-08-09 02:55:56 UTC (rev 414) +++ MacRuby/branches/lrz_unstable/hash.c 2008-08-10 08:45:15 UTC (rev 415) @@ -3041,8 +3041,6 @@ rb_include_module(rb_cHash, rb_mEnumerable); #if WITH_OBJC - /* required because Hash.new can accept a block */ - rb_define_singleton_method(rb_cHash, "new", rb_class_new_instance, -1); /* to return a mutable copy */ rb_define_method(rb_cHash, "dup", rb_hash_dup, 0); #else Modified: MacRuby/branches/lrz_unstable/objc.m =================================================================== --- MacRuby/branches/lrz_unstable/objc.m 2008-08-09 02:55:56 UTC (rev 414) +++ MacRuby/branches/lrz_unstable/objc.m 2008-08-10 08:45:15 UTC (rev 415) @@ -1007,6 +1007,11 @@ char buf[128]; id ocrcv; + /* XXX because Hash.new can accept a block */ + if (recv == rb_cNSMutableHash && sel == @selector(new)) { + return rb_class_new_instance(0, NULL, recv); + } + ocrcv = RB2OC(recv); DLOG("OCALL", "%c[<%s %p> %s]", class_isMetaClass((Class)klass) ? '+' : '-', class_getName((Class)klass), (void *)ocrcv, (char *)sel); @@ -1341,10 +1346,14 @@ *pimp = imp; if (imp == NULL) { - char buf[512]; - strlcpy(buf, (char *)sel, sizeof buf); - if (buf[strlen(buf) - 1] == ':') + char buf[100]; + size_t slen; + + slen = strlen((char *)sel); + if (((char *)sel)[slen - 1] == ':') { return NULL; + } + strlcpy(buf, (char *)sel, sizeof buf); strlcat(buf, ":", sizeof buf); return rb_objc_method_node2(mod, sel_registerName(buf), pimp); } @@ -1359,7 +1368,6 @@ Method method; char *types; int arity, oc_arity; - char *mid_str; IMP imp; bool direct_override; NODE *node; @@ -1402,30 +1410,47 @@ } if (mid == ID_ALLOCATOR) { - mid_str = "alloc"; + sel = @selector(alloc); } else { + char *mid_str; + size_t mid_str_len; + char buf[100]; + 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'; + sel = sel_registerName(buf); + } + 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(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); + } + } + } } included_in_classes = RCLASS_MODULE(mod) ? rb_ivar_get(mod, idIncludedInClasses) : Qnil; - if ((arity < 0 || arity > 0) && mid_str[strlen(mid_str) - 1] != ':') { - char buf[100]; - snprintf(buf, sizeof buf, "%s:", mid_str); - sel = sel_registerName(buf); - oc_arity = 1; - } - else { - sel = sel_registerName(mid_str); - } - - if (sel == sel_ignored) { - char buf[100]; - snprintf(buf, sizeof buf, "__rb_%s__", mid_str); - sel = sel_registerName(buf); - } - direct_override = false; method = class_getInstanceMethod((Class)mod, sel); @@ -2079,7 +2104,7 @@ { bs_element_function_t *bs_func = (bs_element_function_t *)value; ID name = rb_intern(bs_func->name); - if (1) { + if (!st_lookup(bs_functions, (st_data_t)name, NULL)) { st_insert(bs_functions, (st_data_t)name, (st_data_t)bs_func); do_not_free = true; } @@ -2093,8 +2118,13 @@ { bs_element_function_alias_t *bs_func_alias = (bs_element_function_alias_t *)value; - rb_define_alias(CLASS_OF(rb_mKernel), bs_func_alias->name, - bs_func_alias->original); + bs_element_function_t *bs_func_original; + if (st_lookup(bs_functions, (st_data_t)rb_intern(bs_func_alias->original), (st_data_t *)&bs_func_original)) { + st_insert(bs_functions, (st_data_t)rb_intern(bs_func_alias->name), (st_data_t)bs_func_original); + } + else { + rb_raise(rb_eRuntimeError, "cannot alias '%s' to '%s' because it doesn't exist", bs_func_alias->name, bs_func_alias->original); + } break; } @@ -2433,54 +2463,6 @@ } #endif -ID -rb_objc_missing_sel(ID mid, int arity) -{ - const char *name; - size_t len; - char buf[100]; - - if (mid == 0) - return mid; - - name = rb_id2name(mid); - if (name == NULL) - return mid; - - len = strlen(name); - if (len == 0) - return mid; - - if (arity == 1 && name[len - 1] == '=') { - strlcpy(buf, "set", sizeof buf); - buf[3] = toupper(name[0]); - buf[4] = '\0'; - strlcat(buf, &name[1], sizeof buf); - buf[len + 2] = ':'; - } - else if (arity == 0 && name[len - 1] == '?') { - strlcpy(buf, "is", sizeof buf); - buf[2] = toupper(name[0]); - buf[3] = '\0'; - strlcat(buf, &name[1], sizeof buf); - buf[len + 1] = '\0'; - } - else if (arity >= 1 && name[len - 1] != ':' && len < sizeof buf) { - strlcpy(buf, name, sizeof buf); - buf[len] = ':'; - buf[len + 1] = '\0'; - } - else if (arity == 1 && name[len - 1] == ':' && len < sizeof buf) { - strlcpy(buf, name, sizeof buf); - buf[len - 1] = '\0'; - } - else { - return mid; - } - - return rb_intern(buf); -} - static const char * resources_path(char *path, size_t len) { @@ -2865,6 +2847,7 @@ bs_const_magic_cookie = rb_str_new2("bs_const_magic_cookie"))); rb_cBoxed = rb_define_class("Boxed", (VALUE)objc_getClass("NSValue")); + RCLASS_SET_VERSION_FLAG(rb_cBoxed, RCLASS_IS_OBJECT_SUBCLASS); 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-08-09 02:55:56 UTC (rev 414) +++ MacRuby/branches/lrz_unstable/object.c 2008-08-10 08:45:15 UTC (rev 415) @@ -928,18 +928,21 @@ return Qfalse; } #if WITH_OBJC - if (NATIVE(obj)) { - return rb_objc_is_immutable(obj) - || rb_objc_flag_check((const void *)obj, FL_FREEZE) - ? Qtrue : Qfalse; + switch (TYPE(obj)) { + case T_NATIVE: + return rb_objc_is_immutable(obj) + || rb_objc_flag_check((const void *)obj, FL_FREEZE) + ? Qtrue : Qfalse; + case T_CLASS: + case T_MODULE: + return (RCLASS_VERSION(obj) & RCLASS_IS_FROZEN) == RCLASS_IS_FROZEN ? Qtrue : Qfalse; + default: + return FL_TEST(obj, FL_FREEZE) ? Qtrue : Qfalse; } - int type = TYPE(obj); - if (type == T_CLASS || type == T_MODULE) { - return (RCLASS_VERSION(obj) & RCLASS_IS_FROZEN) == RCLASS_IS_FROZEN ? Qtrue : Qfalse; - } -#endif +#else if (FL_TEST(obj, FL_FREEZE)) return Qtrue; return Qfalse; +#endif }
participants (1)
-
source_changes@macosforge.org