[macruby-changes] [5012] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Dec 10 14:30:19 PST 2010


Revision: 5012
          http://trac.macosforge.org/projects/ruby/changeset/5012
Author:   lsansonetti at apple.com
Date:     2010-12-10 14:30:16 -0800 (Fri, 10 Dec 2010)
Log Message:
-----------
implement Module.nesting

Modified Paths:
--------------
    MacRuby/trunk/eval.c
    MacRuby/trunk/vm.cpp
    MacRuby/trunk/vm.h

Modified: MacRuby/trunk/eval.c
===================================================================
--- MacRuby/trunk/eval.c	2010-12-10 12:13:21 UTC (rev 5011)
+++ MacRuby/trunk/eval.c	2010-12-10 22:30:16 UTC (rev 5012)
@@ -229,22 +229,18 @@
  */
 
 static VALUE
-rb_mod_nesting(VALUE rcv, SEL sel)
+rb_mod_nesting(VALUE rcv, SEL sel, VALUE top, int argc, VALUE *argv)
 {
-#if 0 // TODO
-    VALUE ary = rb_ary_new();
-    const NODE *cref = vm_cref();
+    rb_scan_args(argc, argv, "00");
 
-    while (cref && cref->nd_next) {
-	VALUE klass = cref->nd_clss;
-	if (!NIL_P(klass)) {
-	    rb_ary_push(ary, klass);
-	}
-	cref = cref->nd_next;
+    switch (TYPE(top)) {
+	case T_CLASS:
+	case T_MODULE:
+	    return rb_vm_module_nesting(top);
+
+	default:
+	    return Qnil;
     }
-    return ary;
-#endif
-    return Qnil;
 }
 
 /*
@@ -870,7 +866,7 @@
     Init_vm_eval();
     Init_eval_method();
 
-    rb_objc_define_method(*(VALUE *)rb_cModule, "nesting", rb_mod_nesting, 0);
+    rb_objc_define_method(*(VALUE *)rb_cModule, "nesting", rb_mod_nesting, -3);
     rb_objc_define_method(*(VALUE *)rb_cModule, "constants", rb_mod_s_constants, -1);
 
     VALUE cTopLevel = *(VALUE *)rb_vm_top_self();    

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2010-12-10 12:13:21 UTC (rev 5011)
+++ MacRuby/trunk/vm.cpp	2010-12-10 22:30:16 UTC (rev 5012)
@@ -1320,6 +1320,19 @@
     return o == NULL ? Qundef : (VALUE)o->klass;
 }
 
+extern "C"
+VALUE
+rb_vm_module_nesting(VALUE mod)
+{
+    VALUE ary = rb_ary_new();
+    rb_vm_outer_t *o = GET_CORE()->get_outer((Class)mod);
+    while (o != NULL) {
+	rb_ary_push(ary, (VALUE)o->klass);
+	o = o->outer;
+    }
+    return ary;
+}
+
 static VALUE
 get_klass_const(VALUE outer, ID path, bool lexical)
 {

Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h	2010-12-10 12:13:21 UTC (rev 5011)
+++ MacRuby/trunk/vm.h	2010-12-10 22:30:16 UTC (rev 5012)
@@ -329,6 +329,7 @@
 	int (*filter) (VALUE, ID, VALUE));
 void rb_vm_set_outer(VALUE klass, VALUE under);
 VALUE rb_vm_get_outer(VALUE klass);
+VALUE rb_vm_module_nesting(VALUE mod);
 VALUE rb_vm_catch(VALUE tag);
 VALUE rb_vm_throw(VALUE tag, VALUE value);
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101210/db65981a/attachment.html>


More information about the macruby-changes mailing list