Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lrz committed Aug 4, 2008
1 parent bdbd92c commit 4265d64
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 38 deletions.
44 changes: 24 additions & 20 deletions class.c
Expand Up @@ -566,6 +566,8 @@ void
rb_include_module(VALUE klass, VALUE module)
{
#if WITH_OBJC
Method *methods;
unsigned int i, methods_count;
VALUE ary;

rb_frozen_class_p(klass);
Expand All @@ -580,6 +582,8 @@ rb_include_module(VALUE klass, VALUE module)
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);
Expand All @@ -591,9 +595,6 @@ rb_include_module(VALUE klass, VALUE module)

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];
Expand Down Expand Up @@ -668,23 +669,29 @@ rb_include_module(VALUE klass, VALUE module)
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
}
#endif
return ary;
}

Expand Down Expand Up @@ -745,19 +752,16 @@ VALUE
rb_mod_ancestors(VALUE mod)
{
VALUE p, ary = rb_ary_new();

for (p = mod; p; p = RCLASS_SUPER(p)) {

#if WITH_OBJC
VALUE inc_mods;

for (p = mod; p; p = RCLASS_SUPER(p)) {
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) {
Expand All @@ -766,8 +770,8 @@ rb_mod_ancestors(VALUE mod)
else {
rb_ary_push(ary, p);
}
#endif
}
#endif
return ary;
}

Expand Down
5 changes: 4 additions & 1 deletion hash.c
Expand Up @@ -3032,7 +3032,10 @@ Init_Hash(void)

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);
Expand Down
1 change: 1 addition & 0 deletions include/ruby/node.h
Expand Up @@ -509,6 +509,7 @@ void rb_add_method_direct(VALUE, ID, NODE *);
#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);

Expand Down
6 changes: 3 additions & 3 deletions include/ruby/ruby.h
Expand Up @@ -1203,15 +1203,15 @@ rb_type(VALUE obj)
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;
}
Expand Down
2 changes: 1 addition & 1 deletion objc.m
Expand Up @@ -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);
Expand Down
15 changes: 12 additions & 3 deletions object.c
Expand Up @@ -1329,9 +1329,7 @@ rb_mod_eqq(VALUE mod, VALUE arg)
VALUE
rb_class_inherited_p(VALUE mod, VALUE arg)
{
#if !WITH_OBJC
VALUE start = mod;
#endif

if (mod == arg) return Qtrue;
switch (TYPE(arg)) {
Expand All @@ -1341,7 +1339,18 @@ rb_class_inherited_p(VALUE mod, VALUE arg)
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))
Expand Down
4 changes: 2 additions & 2 deletions sample/test.rb
Expand Up @@ -1910,8 +1910,8 @@ module Const2
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"
Expand Down
2 changes: 1 addition & 1 deletion vm_eval.c
Expand Up @@ -210,7 +210,7 @@ rb_call0(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv,
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;
Expand Down
11 changes: 4 additions & 7 deletions vm_insnhelper.c
Expand Up @@ -531,12 +531,9 @@ mn = c_mn;
else {
#endif

NODE *rb_objc_method_node2(VALUE mod, SEL sel, IMP *pimp);

if (sel == 0)
mn = rb_objc_method_node(klass, id, &imp, &sel);
else
mn = rb_objc_method_node2(klass, sel, &imp);
mn = sel == 0
? rb_objc_method_node(klass, id, &imp, &sel)
: 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);
Expand Down Expand Up @@ -571,7 +568,7 @@ c_mn = (NODE*)mn;
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:
Expand Down

0 comments on commit 4265d64

Please sign in to comment.