[macruby-changes] [406] MacRuby/branches/lrz_unstable
source_changes at macosforge.org
source_changes at macosforge.org
Mon Aug 4 14:45:36 PDT 2008
Revision: 406
http://trac.macosforge.org/projects/ruby/changeset/406
Author: lsansonetti at apple.com
Date: 2008-08-04 14:45:36 -0700 (Mon, 04 Aug 2008)
Log Message:
-----------
wip
Modified Paths:
--------------
MacRuby/branches/lrz_unstable/class.c
MacRuby/branches/lrz_unstable/hash.c
MacRuby/branches/lrz_unstable/include/ruby/node.h
MacRuby/branches/lrz_unstable/include/ruby/ruby.h
MacRuby/branches/lrz_unstable/objc.m
MacRuby/branches/lrz_unstable/object.c
MacRuby/branches/lrz_unstable/sample/test.rb
MacRuby/branches/lrz_unstable/vm_eval.c
MacRuby/branches/lrz_unstable/vm_insnhelper.c
Modified: MacRuby/branches/lrz_unstable/class.c
===================================================================
--- MacRuby/branches/lrz_unstable/class.c 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/class.c 2008-08-04 21:45:36 UTC (rev 406)
@@ -566,6 +566,8 @@
rb_include_module(VALUE klass, VALUE module)
{
#if WITH_OBJC
+ Method *methods;
+ unsigned int i, methods_count;
VALUE ary;
rb_frozen_class_p(klass);
@@ -580,6 +582,8 @@
ary = rb_ary_new();
rb_ivar_set(klass, idIncludedModules, ary);
}
+ if (rb_ary_includes(ary, module))
+ return;
rb_ary_insert(ary, 0, module);
ary = rb_ivar_get(module, idIncludedInClasses);
@@ -591,9 +595,6 @@
DLOG("INCM", "%s <- %s", class_getName((Class)klass), class_getName((Class)module));
- Method *methods;
- unsigned int i, methods_count;
-
methods = class_copyMethodList((Class)module, &methods_count);
for (i = 0; i < methods_count; i++) {
Method method = methods[i];
@@ -668,23 +669,29 @@
VALUE
rb_mod_included_modules(VALUE mod)
{
- VALUE ary = rb_ary_new();
- VALUE p;
+ VALUE p, ary = rb_ary_new();
- for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
#if WITH_OBJC
+ for (p = mod; p; p = RCLASS_SUPER(p)) {
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));
+ for (i = 0; i < count; i++) {
+ VALUE imod = RARRAY_AT(inc_mods, i);
+ rb_ary_push(ary, imod);
+ rb_ary_concat(ary, rb_mod_included_modules(imod));
+ }
}
+ if (RCLASS_MODULE(p))
+ break;
+ }
#else
+ for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
if (BUILTIN_TYPE(p) == T_ICLASS) {
rb_ary_push(ary, RBASIC(p)->klass);
}
+ }
#endif
- }
return ary;
}
@@ -745,19 +752,16 @@
rb_mod_ancestors(VALUE mod)
{
VALUE p, ary = rb_ary_new();
-
+
+#if WITH_OBJC
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));
- }
+ rb_ary_concat(ary, rb_mod_included_modules(p));
+ if (RCLASS_MODULE(p))
+ break;
+ }
#else
+ for (p = mod; p; p = RCLASS_SUPER(p)) {
if (RCLASS_SINGLETON(p))
continue;
if (BUILTIN_TYPE(p) == T_ICLASS) {
@@ -766,8 +770,8 @@
else {
rb_ary_push(ary, p);
}
+ }
#endif
- }
return ary;
}
Modified: MacRuby/branches/lrz_unstable/hash.c
===================================================================
--- MacRuby/branches/lrz_unstable/hash.c 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/hash.c 2008-08-04 21:45:36 UTC (rev 406)
@@ -3032,7 +3032,10 @@
rb_include_module(rb_cHash, rb_mEnumerable);
-#if !WITH_OBJC
+#if WITH_OBJC
+ /* required because Hash.new can accept a block */
+ rb_define_singleton_method(rb_cHash, "new", rb_class_new_instance, -1);
+#else
rb_define_alloc_func(rb_cHash, hash_alloc);
#endif
rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
Modified: MacRuby/branches/lrz_unstable/include/ruby/node.h
===================================================================
--- MacRuby/branches/lrz_unstable/include/ruby/node.h 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/include/ruby/node.h 2008-08-04 21:45:36 UTC (rev 406)
@@ -509,6 +509,7 @@
#if WITH_OBJC
void rb_objc_register_ruby_method(VALUE, ID, NODE *);
NODE *rb_objc_method_node(VALUE, ID, IMP *, SEL *);
+NODE *rb_objc_method_node2(VALUE, SEL, IMP *);
#endif
NODE *rb_node_newnode(enum node_type,VALUE,VALUE,VALUE);
Modified: MacRuby/branches/lrz_unstable/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/lrz_unstable/include/ruby/ruby.h 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/include/ruby/ruby.h 2008-08-04 21:45:36 UTC (rev 406)
@@ -1203,15 +1203,15 @@
if (k == (Class)rb_cSymbol) return T_SYMBOL;
if (k == (Class)rb_cCFString
|| (RCLASS_VERSION(k) & RCLASS_IS_STRING_SUBCLASS)
- == RCLASS_IS_STRING_SUBCLASS)
+ == RCLASS_IS_STRING_SUBCLASS)
return T_STRING;
if (k == (Class)rb_cCFArray
|| (RCLASS_VERSION(k) & RCLASS_IS_ARRAY_SUBCLASS)
- == RCLASS_IS_ARRAY_SUBCLASS)
+ == RCLASS_IS_ARRAY_SUBCLASS)
return T_ARRAY;
if (k == (Class)rb_cCFHash
|| (RCLASS_VERSION(k) & RCLASS_IS_HASH_SUBCLASS)
- == RCLASS_IS_HASH_SUBCLASS)
+ == RCLASS_IS_HASH_SUBCLASS)
return T_HASH;
if (NATIVE(obj)) return T_NATIVE;
}
Modified: MacRuby/branches/lrz_unstable/objc.m
===================================================================
--- MacRuby/branches/lrz_unstable/objc.m 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/objc.m 2008-08-04 21:45:36 UTC (rev 406)
@@ -1020,7 +1020,7 @@
char buf[128];
void *imp;
- DLOG("OCALL", "[<%s %p> %s]", class_getName((Class)klass), (void *)ocrcv, (char *)ctx->selector);
+ DLOG("OCALL", "%c[<%s %p> %s]", class_isMetaClass(klass) ? '+' : '-', class_getName(klass), (void *)ocrcv, (char *)ctx->selector);
count = method_getNumberOfArguments(ctx->method);
assert(count >= 2);
Modified: MacRuby/branches/lrz_unstable/object.c
===================================================================
--- MacRuby/branches/lrz_unstable/object.c 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/object.c 2008-08-04 21:45:36 UTC (rev 406)
@@ -1329,9 +1329,7 @@
VALUE
rb_class_inherited_p(VALUE mod, VALUE arg)
{
-#if !WITH_OBJC
VALUE start = mod;
-#endif
if (mod == arg) return Qtrue;
switch (TYPE(arg)) {
@@ -1341,7 +1339,18 @@
default:
rb_raise(rb_eTypeError, "compared with non class/module");
}
-#if WITH_OBJC // TODO
+#if WITH_OBJC
+ while (mod) {
+ if (mod == arg)
+ return Qtrue;
+ mod = RCLASS_SUPER(mod);
+ }
+ /* not mod < arg; check if mod > arg */
+ while (arg) {
+ if (arg == start)
+ return Qfalse;
+ arg = RCLASS_SUPER(arg);
+ }
#else
while (mod) {
if (RCLASS_M_TBL(mod) == RCLASS_M_TBL(arg))
Modified: MacRuby/branches/lrz_unstable/sample/test.rb
===================================================================
--- MacRuby/branches/lrz_unstable/sample/test.rb 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/sample/test.rb 2008-08-04 21:45:36 UTC (rev 406)
@@ -1910,8 +1910,8 @@
test_ok([TEST1,TEST2,TEST3,TEST4] == [1,2,6,8])
-test_ok((String <=> Object) == -1)
-test_ok((Object <=> String) == 1)
+test_ok((String <=> NSObject) == -1)
+test_ok((NSObject <=> String) == 1)
test_ok((Array <=> String) == nil)
test_check "clone"
Modified: MacRuby/branches/lrz_unstable/vm_eval.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_eval.c 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/vm_eval.c 2008-08-04 21:45:36 UTC (rev 406)
@@ -210,7 +210,7 @@
if (imp != NULL && method == NULL)
return rb_objc_call(recv, sel, argc, (VALUE *)argv);
- DLOG("RCALL", "[<%s %p> %s] node=%p", class_getName((Class)klass), (void *)recv, (char *)sel, method);
+ DLOG("RCALL", "%c[<%s %p> %s] node=%p", class_isMetaClass((Class)klass) ? '+' : '-', class_getName((Class)klass), (void *)recv, (char *)sel, method);
if (method == NULL) {
int missing_scope = scope == 2 ? NOEX_VCALL : scope == 3 ? NOEX_SUPER : NOEX_VCALL;
Modified: MacRuby/branches/lrz_unstable/vm_insnhelper.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_insnhelper.c 2008-08-04 05:38:19 UTC (rev 405)
+++ MacRuby/branches/lrz_unstable/vm_insnhelper.c 2008-08-04 21:45:36 UTC (rev 406)
@@ -531,13 +531,10 @@
else {
#endif
- NODE *rb_objc_method_node2(VALUE mod, SEL sel, IMP *pimp);
+ mn = sel == 0
+ ? rb_objc_method_node(klass, id, &imp, &sel)
+ : rb_objc_method_node2(klass, sel, &imp);
- if (sel == 0)
- mn = rb_objc_method_node(klass, id, &imp, &sel);
- else
- mn = rb_objc_method_node2(klass, sel, &imp);
-
if (flag & VM_CALL_SEND_BIT) {
vm_send_optimize(cfp, (NODE **)&mn, (rb_num_t *)&flag, (rb_num_t *)&num, (ID *)&id, klass);
}
@@ -571,7 +568,7 @@
return val;
}
- DLOG("RCALL", "[<%s %p> %s] node=%p", class_getName((Class)klass), (void *)recv, (char *)sel, mn);
+ DLOG("RCALL", "%c[<%s %p> %s] node=%p", class_isMetaClass((Class)klass) ? '+' : '-', class_getName((Class)klass), (void *)recv, (char *)sel, mn);
#endif
start_method_dispatch:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080804/0f5acb23/attachment.html
More information about the macruby-changes
mailing list