[macruby-changes] [384] MacRuby/branches/lrz_unstable

source_changes at macosforge.org source_changes at macosforge.org
Wed Jul 30 00:26:14 PDT 2008


Revision: 384
          http://trac.macosforge.org/projects/ruby/changeset/384
Author:   lsansonetti at apple.com
Date:     2008-07-30 00:26:13 -0700 (Wed, 30 Jul 2008)
Log Message:
-----------
wip

Modified Paths:
--------------
    MacRuby/branches/lrz_unstable/debug.h
    MacRuby/branches/lrz_unstable/objc.m
    MacRuby/branches/lrz_unstable/object.c
    MacRuby/branches/lrz_unstable/version.c
    MacRuby/branches/lrz_unstable/version.h
    MacRuby/branches/lrz_unstable/vm_insnhelper.c

Modified: MacRuby/branches/lrz_unstable/debug.h
===================================================================
--- MacRuby/branches/lrz_unstable/debug.h	2008-07-30 06:17:41 UTC (rev 383)
+++ MacRuby/branches/lrz_unstable/debug.h	2008-07-30 07:26:13 UTC (rev 384)
@@ -33,7 +33,8 @@
 static inline bool dlog_enabled(void) {
     static int flag = -1;
     if (flag == -1) {
-        flag = getenv("MACRUBY_DEBUG") != NULL;
+	char *s = getenv("MACRUBY_DEBUG");
+	flag = !(s == NULL || *s == '0');
     }
     return (bool)flag;
 }

Modified: MacRuby/branches/lrz_unstable/objc.m
===================================================================
--- MacRuby/branches/lrz_unstable/objc.m	2008-07-30 06:17:41 UTC (rev 383)
+++ MacRuby/branches/lrz_unstable/objc.m	2008-07-30 07:26:13 UTC (rev 384)
@@ -850,39 +850,7 @@
 		 RSTRING_PTR(rb_inspect(rval)), octype);
 }
 
-VALUE
-rb_objc_boot_ocid(id ocid)
-{
-    if (NATIVE((VALUE)ocid)) {
-        /* Make sure the ObjC class is imported in Ruby. */ 
-        rb_objc_import_class(object_getClass(ocid)); 
-    }
-    else if (RBASIC(ocid)->klass == 0) {
-	/* This pure-Ruby object was created from Objective-C, we need to 
-	 * initialize the Ruby bits. 
-	 */
-	VALUE klass;
-        
-	klass = rb_objc_import_class(object_getClass(ocid)); 
-
-	RBASIC(ocid)->klass = klass;
-	RBASIC(ocid)->flags = 
-	    klass == rb_cString
-	    ? T_STRING
-	    : klass == rb_cArray
-	    ? T_ARRAY
-	    : klass == rb_cHash
-	    ? T_HASH
-	    : T_OBJECT;
-    }
-
-    return (VALUE)ocid;
-}
-
-static void
-rb_objc_ocval_to_rbval(void **ocval, const char *octype, VALUE *rbval);
-
-bool 
+static inline bool 
 rb_objc_ocid_to_rval(void **ocval, VALUE *rbval)
 {
     id ocid = *(id *)ocval;
@@ -891,7 +859,7 @@
 	*rbval = Qnil;
     }
     else {
-	*rbval = rb_objc_boot_ocid(ocid);
+	*rbval = (VALUE)ocid;
     }
 
     return true;

Modified: MacRuby/branches/lrz_unstable/object.c
===================================================================
--- MacRuby/branches/lrz_unstable/object.c	2008-07-30 06:17:41 UTC (rev 383)
+++ MacRuby/branches/lrz_unstable/object.c	2008-07-30 07:26:13 UTC (rev 384)
@@ -2548,6 +2548,7 @@
     RCLASS_SET_VERSION_FLAG(rb_cObject, RCLASS_IS_OBJECT_SUBCLASS);
     rb_cModule = boot_defclass("Module", rb_cObject);
     rb_cClass =  boot_defclass("Class",  rb_cModule);
+    RCLASS_SUPER(*(Class *)rb_cNSObject) = rb_cClass;
 #else
     VALUE metaclass;
 
@@ -2555,11 +2556,7 @@
     rb_cObject = boot_defclass("Object", rb_cBasicObject);
     rb_cModule = boot_defclass("Module", rb_cObject);
     rb_cClass =  boot_defclass("Class",  rb_cModule);
-#endif
 
-#if WITH_OBJC
-    RCLASS_SUPER(*(Class *)rb_cNSObject) = rb_cClass;
-#else
     metaclass = rb_make_metaclass(rb_cBasicObject, rb_cClass);
     metaclass = rb_make_metaclass(rb_cObject, metaclass);
     metaclass = rb_make_metaclass(rb_cModule, metaclass);
@@ -2600,7 +2597,8 @@
     rb_define_method(rb_mKernel, "!~", rb_obj_not_match, 1);
     rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
 
-#if !WITH_OBJC // defined in NSObject
+#if !WITH_OBJC 
+    // #class is already defined in NSObject
     rb_define_method(rb_mKernel, "class", rb_obj_class, 0);
 #endif
     rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);

Modified: MacRuby/branches/lrz_unstable/version.c
===================================================================
--- MacRuby/branches/lrz_unstable/version.c	2008-07-30 06:17:41 UTC (rev 383)
+++ MacRuby/branches/lrz_unstable/version.c	2008-07-30 07:26:13 UTC (rev 384)
@@ -23,6 +23,7 @@
 const int ruby_patchlevel = RUBY_PATCHLEVEL;
 const char ruby_description[] = RUBY_DESCRIPTION;
 const char ruby_copyright[] = RUBY_COPYRIGHT;
+const char ruby_engine[] = RUBY_ENGINE;
 
 void
 Init_version(void)
@@ -34,6 +35,7 @@
     rb_define_global_const("RUBY_REVISION", INT2FIX(RUBY_REVISION));
     rb_define_global_const("RUBY_DESCRIPTION", MKSTR(description));
     rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
+    rb_define_global_const("RUBY_ENGINE", MKSTR(engine));
 #if WITH_OBJC
     rb_define_global_const("MACRUBY_VERSION", rb_float_new(MACRUBY_VERSION));
 #endif

Modified: MacRuby/branches/lrz_unstable/version.h
===================================================================
--- MacRuby/branches/lrz_unstable/version.h	2008-07-30 06:17:41 UTC (rev 383)
+++ MacRuby/branches/lrz_unstable/version.h	2008-07-30 07:26:13 UTC (rev 384)
@@ -46,9 +46,9 @@
 #endif
 
 #if WITH_OBJC
-# define RUBY_IMPL_NAME "MacRuby"
+# define RUBY_ENGINE "macruby"
 #else
-# define RUBY_IMPL_NAME "ruby"
+# define RUBY_ENGINE "ruby"
 #endif
 
 #if WITH_OBJC

Modified: MacRuby/branches/lrz_unstable/vm_insnhelper.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_insnhelper.c	2008-07-30 06:17:41 UTC (rev 383)
+++ MacRuby/branches/lrz_unstable/vm_insnhelper.c	2008-07-30 07:26:13 UTC (rev 384)
@@ -479,6 +479,33 @@
     }
 }
 
+static inline void
+vm_send_optimize(rb_control_frame_t * const reg_cfp, NODE ** const mn,
+		 rb_num_t * const flag, rb_num_t * const num,
+		 ID * const id, const VALUE klass)
+{
+    if (*mn && nd_type((*mn)->nd_body) == NODE_CFUNC) {
+	NODE *node = (*mn)->nd_body;
+	extern VALUE rb_f_send(int argc, VALUE *argv, VALUE recv);
+
+	if (node->nd_cfnc == rb_f_send) {
+	    int i = *num - 1;
+	    VALUE sym = TOPN(i);
+	    *id = SYMBOL_P(sym) ? SYM2ID(sym) : rb_to_id(sym);
+
+	    /* shift arguments */
+	    if (i > 0) {
+		MEMMOVE(&TOPN(i), &TOPN(i-1), VALUE, i);
+	    }
+
+	    *mn = rb_method_node(klass, *id);
+	    *num -= 1;
+	    DEC_SP(1);
+	    *flag |= VM_CALL_FCALL_BIT;
+	}
+    }
+}
+
 static inline VALUE
 vm_call_method(rb_thread_t * const th, rb_control_frame_t * const cfp,
 	       const int num, rb_block_t * const blockptr, const VALUE flag,
@@ -511,6 +538,10 @@
     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);  
+    }
+
 #if STUPID_CACHE
 c_klass = klass;
 c_sel = sel;
@@ -521,12 +552,12 @@
 
     if (mn == NULL && imp != NULL) {
 	rb_control_frame_t *reg_cfp = cfp;
-	rb_control_frame_t *cfp =
+	rb_control_frame_t *_cfp =
 	    vm_push_frame(th, 0, FRAME_MAGIC_CFUNC | (flag << FRAME_MAGIC_MASK_BITS),
-		    recv, (VALUE) blockptr, 0, reg_cfp->sp, 0, 1);
+			  recv, (VALUE) blockptr, 0, reg_cfp->sp, 0, 1);
 
-	cfp->method_id = id;
-	cfp->method_class = klass;
+	_cfp->method_id = id;
+	_cfp->method_class = klass;
 
 	reg_cfp->sp -= num + 1;
 
@@ -659,33 +690,6 @@
     return val;
 }
 
-static inline void
-vm_send_optimize(rb_control_frame_t * const reg_cfp, NODE ** const mn,
-		 rb_num_t * const flag, rb_num_t * const num,
-		 ID * const id, const VALUE klass)
-{
-    if (*mn && nd_type((*mn)->nd_body) == NODE_CFUNC) {
-	NODE *node = (*mn)->nd_body;
-	extern VALUE rb_f_send(int argc, VALUE *argv, VALUE recv);
-
-	if (node->nd_cfnc == rb_f_send) {
-	    int i = *num - 1;
-	    VALUE sym = TOPN(i);
-	    *id = SYMBOL_P(sym) ? SYM2ID(sym) : rb_to_id(sym);
-
-	    /* shift arguments */
-	    if (i > 0) {
-		MEMMOVE(&TOPN(i), &TOPN(i-1), VALUE, i);
-	    }
-
-	    *mn = rb_method_node(klass, *id);
-	    *num -= 1;
-	    DEC_SP(1);
-	    *flag |= VM_CALL_FCALL_BIT;
-	}
-    }
-}
-
 /* yield */
 
 static inline int
@@ -1166,66 +1170,6 @@
     INC_VM_STATE_VERSION();
 }
 
-#if 0//TODO WITH_OBJC
-static inline void
-vm_method_process_named_args(ID *pid, NODE **pmn, VALUE recv, rb_num_t *pnum, 
-			     rb_control_frame_t *cfp) 
-{
-    VALUE *argv = cfp->sp - *pnum;
-    NODE *mn;
-    ID id;
-
-    if (*pmn == NULL) {
-	const char *p, *mname;
-	long i;
-	mn = rb_objc_define_objc_mid_closure(recv, *pid, 0);
-	if (mn != NULL) {
-	    *pmn = mn;
-	    return;
-	}
-	mname = rb_id2name(*pid);
-	if (*pid > 1 && (p = strchr(mname, ':')) != NULL) {
-	    char buf[512];
-	    strlcpy(buf, mname, sizeof buf);
-	    buf[p - mname] = '\0';
-	    mname = p + 1;
-	    id = rb_intern(buf);
-	    mn = rb_method_node(CLASS_OF(recv), id);
-	    if (mn != NULL) {
-		VALUE h = rb_hash_new();
-		VALUE new_argv[2];
-		for (i = 1; i < *pnum; i++) {
-		    p = strchr(mname, ':');
-		    if (p == NULL)
-			return;
-		    strlcpy(buf, mname, sizeof buf);
-		    buf[p - mname] = '\0';
-		    mname = p + 1;
-		    rb_hash_aset(h, ID2SYM(rb_intern(buf)), argv[i]);
-		}
-		new_argv[0] = argv[0];
-		new_argv[1] = h;
-		memcpy(cfp->sp - 2, new_argv, sizeof(void *) * 2);
-		cfp->bp -= 2 - *pnum;
-		*pmn = mn;
-		*pid = id;
-		*pnum = 2;
-		return;
-	    }
-	}
-	id = rb_objc_missing_sel(*pid, *pnum);
-	if (id != *pid) {
-	    mn = rb_objc_define_objc_mid_closure(recv, id, *pid);
-	    if (mn != NULL) {
-		*pmn = mn;
-		*pid = id;
-		return;
-	    }
-	}
-    }
-}
-#endif
-
 static inline NODE *
 vm_method_search(VALUE id, VALUE klass, IC ic)
 {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080730/211fca52/attachment.html 


More information about the macruby-changes mailing list