[macruby-changes] [1572] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Fri May 15 00:28:19 PDT 2009


Revision: 1572
          http://trac.macosforge.org/projects/ruby/changeset/1572
Author:   lsansonetti at apple.com
Date:     2009-05-15 00:28:06 -0700 (Fri, 15 May 2009)
Log Message:
-----------
implemented Method#to_proc, fixed Hash.new{}

Modified Paths:
--------------
    MacRuby/branches/experimental/hash.c
    MacRuby/branches/experimental/id.c
    MacRuby/branches/experimental/id.h
    MacRuby/branches/experimental/include/ruby/intern.h
    MacRuby/branches/experimental/proc.c
    MacRuby/branches/experimental/roxor.cpp

Modified: MacRuby/branches/experimental/hash.c
===================================================================
--- MacRuby/branches/experimental/hash.c	2009-05-13 05:31:53 UTC (rev 1571)
+++ MacRuby/branches/experimental/hash.c	2009-05-15 07:28:06 UTC (rev 1572)
@@ -279,7 +279,7 @@
  */
 
 static VALUE
-rb_hash_initialize(VALUE hash, SEL sel, int argc, VALUE *argv)
+rb_hash_initialize(VALUE hash, SEL sel, int argc, const VALUE *argv)
 {
     VALUE ifnone;
 
@@ -300,6 +300,14 @@
     return hash;
 }
 
+VALUE
+rb_hash_new2(int argc, const VALUE *argv)
+{
+    VALUE h = hash_alloc(0);
+    rb_hash_initialize(h, 0, argc, argv);
+    return h;
+}
+
 /*
  *  call-seq:
  *     Hash[ [key =>|, value]* ]   => hash

Modified: MacRuby/branches/experimental/id.c
===================================================================
--- MacRuby/branches/experimental/id.c	2009-05-13 05:31:53 UTC (rev 1571)
+++ MacRuby/branches/experimental/id.c	2009-05-15 07:28:06 UTC (rev 1572)
@@ -64,6 +64,7 @@
     selInit = sel_registerName("init");
     selInitialize = sel_registerName("initialize");
     selInitialize2 = sel_registerName("initialize:");
+    selNew = sel_registerName("new");
     selRespondTo = sel_registerName("respond_to?:");
     selMethodMissing = sel_registerName("method_missing:");
     selCopy = sel_registerName("copy");

Modified: MacRuby/branches/experimental/id.h
===================================================================
--- MacRuby/branches/experimental/id.h	2009-05-13 05:31:53 UTC (rev 1571)
+++ MacRuby/branches/experimental/id.h	2009-05-15 07:28:06 UTC (rev 1572)
@@ -74,6 +74,7 @@
 extern SEL selInit;
 extern SEL selInitialize;
 extern SEL selInitialize2;
+extern SEL selNew;
 extern SEL selRespondTo;
 extern SEL selMethodMissing;
 extern SEL selCopy;

Modified: MacRuby/branches/experimental/include/ruby/intern.h
===================================================================
--- MacRuby/branches/experimental/include/ruby/intern.h	2009-05-13 05:31:53 UTC (rev 1571)
+++ MacRuby/branches/experimental/include/ruby/intern.h	2009-05-15 07:28:06 UTC (rev 1572)
@@ -361,6 +361,7 @@
 void rb_hash_foreach(VALUE, int (*)(ANYARGS), VALUE);
 VALUE rb_hash(VALUE);
 VALUE rb_hash_new(void);
+VALUE rb_hash_new2(int argc, const VALUE *argv);
 VALUE rb_hash_dup(VALUE);
 VALUE rb_hash_freeze(VALUE);
 VALUE rb_hash_aref(VALUE, VALUE);

Modified: MacRuby/branches/experimental/proc.c
===================================================================
--- MacRuby/branches/experimental/proc.c	2009-05-13 05:31:53 UTC (rev 1571)
+++ MacRuby/branches/experimental/proc.c	2009-05-15 07:28:06 UTC (rev 1572)
@@ -1384,14 +1384,10 @@
 static VALUE
 method_proc(VALUE method, SEL sel)
 {
-#if 0
-    // TODO
     rb_vm_method_t *data;
     Data_Get_Struct(method, rb_vm_method_t, data);
     rb_vm_block_t *block = rb_vm_create_block_from_method(data);
     return rb_proc_alloc_with_block(rb_cProc, block);
-#endif
-    return Qnil;
 }
 
 /*

Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp	2009-05-13 05:31:53 UTC (rev 1571)
+++ MacRuby/branches/experimental/roxor.cpp	2009-05-15 07:28:06 UTC (rev 1572)
@@ -7880,7 +7880,25 @@
 	    goto recache;
 	}
 
-	if (sel == selClass) {
+	if (block != NULL) {
+	    if (self == rb_cNSMutableHash && sel == selNew) {
+		// Because Hash.new can accept a block.
+		GET_VM()->add_current_block(block);
+		VALUE h = Qnil;
+		try {
+		    h = rb_hash_new2(argc, argv);
+		}
+		catch (...) {
+		    GET_VM()->pop_current_block();
+		    throw;
+		}
+		GET_VM()->pop_current_block();
+		return h;
+	    }
+	    rb_warn("passing a block to an Objective-C method - " \
+		    "will be ignored");
+	}
+	else if (sel == selClass) {
 	    // Because +[NSObject class] returns self.
 	    if (RCLASS_META(klass)) {
 		return RCLASS_MODULE(self) ? rb_cModule : rb_cClass;
@@ -8152,7 +8170,7 @@
     }
 
     std::map<NODE *, rb_vm_block_t *>::iterator iter =
-	GET_VM()->blocks.find(node);
+	GET_VM()->blocks.find(cache_key);
 
     rb_vm_block_t *b;
     bool cached = false;
@@ -8532,8 +8550,9 @@
 
     GC_WB(&b->self, method->recv);
     b->node = method->node;
-    b->arity = rb_vm_node_arity(method->node);
-    b->imp = NULL; // TODO
+    b->arity = method->node == NULL
+	? rb_vm_arity(method->arity) : rb_vm_node_arity(method->node);
+    b->imp = (IMP)method;
     b->flags = VM_BLOCK_PROC | VM_BLOCK_METHOD;
     b->locals = NULL;
     b->parent_var_uses = NULL;
@@ -8608,8 +8627,15 @@
     b->flags |= VM_BLOCK_ACTIVE;
     VALUE v = Qnil;
     try {
-	v = __rb_vm_bcall(b->self, (VALUE)b->dvars, b, b->imp, b->arity,
-		argc, argv);
+	if (b->flags & VM_BLOCK_METHOD) {
+	    rb_vm_method_t *m = (rb_vm_method_t *)b->imp;
+	    v = rb_vm_call_with_cache2(m->cache, NULL, m->recv, m->oclass,
+		    m->sel, argc, argv);
+	}
+	else {
+	    v = __rb_vm_bcall(b->self, (VALUE)b->dvars, b, b->imp, b->arity,
+		    argc, argv);
+	}
     }
     catch (...) {
 	b->flags &= ~VM_BLOCK_ACTIVE;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090515/db062481/attachment.html>


More information about the macruby-changes mailing list