[macruby-changes] [3753] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 12 19:57:06 PST 2010


Revision: 3753
          http://trac.macosforge.org/projects/ruby/changeset/3753
Author:   lsansonetti at apple.com
Date:     2010-03-12 19:57:05 -0800 (Fri, 12 Mar 2010)
Log Message:
-----------
let's get rid of Fixnum and Float boxing classes and use NSNumbers

Modified Paths:
--------------
    MacRuby/trunk/class.c
    MacRuby/trunk/include/ruby/ruby.h
    MacRuby/trunk/numeric.c

Modified: MacRuby/trunk/class.c
===================================================================
--- MacRuby/trunk/class.c	2010-03-13 03:27:20 UTC (rev 3752)
+++ MacRuby/trunk/class.c	2010-03-13 03:57:05 UTC (rev 3753)
@@ -79,15 +79,9 @@
 static BOOL
 rb_obj_imp_isEqual(void *rcv, SEL sel, void *obj)
 {
-    if (obj == NULL)
+    if (obj == NULL) {
 	return false;
-
-    if (*(Class *)rcv == (Class)rb_cFixnum 
-	&& *(Class *)obj == (Class)rb_cFixnum) {
-	/* XXX check if Numeric#== is not overriden */
-	return RFIXNUM(rcv)->value == RFIXNUM(obj)->value;
     }
-
     VALUE arg = OC2RB(obj);
     return rb_vm_call((VALUE)rcv, selEq, 1, &arg, false) == Qtrue;
 }

Modified: MacRuby/trunk/include/ruby/ruby.h
===================================================================
--- MacRuby/trunk/include/ruby/ruby.h	2010-03-13 03:27:20 UTC (rev 3752)
+++ MacRuby/trunk/include/ruby/ruby.h	2010-03-13 03:57:05 UTC (rev 3753)
@@ -551,34 +551,10 @@
 void rb_class_ivar_set_dict(VALUE, CFMutableDictionaryRef);
 #endif
 
-struct RFloat {
-    struct RBasic basic;
-    double float_value;
-};
-
-static inline double
-__rb_float_value(VALUE v)
-{
-    return FIXFLOAT_P(v) ? FIXFLOAT2DBL(v) : ((struct RFloat *)v)->float_value;
-}
-#define RFLOAT_VALUE(v) (__rb_float_value((VALUE)v))
+#define RFLOAT_VALUE(v) FIXFLOAT2DBL(v)
 #define DOUBLE2NUM(dbl)  rb_float_new(dbl)
 #define DBL2NUM DOUBLE2NUM
 
-#if WITH_OBJC
-struct RFixnum {
-    VALUE klass;
-    long value;
-};
-
-struct RSymbol {
-    VALUE klass;
-    char *str;
-    unsigned int len;
-    ID id;
-};
-#endif
-
 #define ELTS_SHARED FL_USER2
 
 #if !WITH_OBJC
@@ -768,10 +744,6 @@
 #define R_CAST(st)   (struct st*)
 #define RBASIC(obj)  (R_CAST(RBasic)(obj))
 #define ROBJECT(obj) (R_CAST(RObject)(obj))
-#define RFLOAT(obj)  (R_CAST(RFloat)(obj))
-#if WITH_OBJC
-# define RFIXNUM(obj) (R_CAST(RFixnum)(obj))
-#endif
 #define RDATA(obj)   (R_CAST(RData)(obj))
 #define RSTRUCT(obj) (R_CAST(RStruct)(obj))
 #define RBIGNUM(obj) (R_CAST(RBignum)(obj))

Modified: MacRuby/trunk/numeric.c
===================================================================
--- MacRuby/trunk/numeric.c	2010-03-13 03:27:20 UTC (rev 3752)
+++ MacRuby/trunk/numeric.c	2010-03-13 03:57:05 UTC (rev 3753)
@@ -93,15 +93,12 @@
 VALUE rb_eZeroDivError;
 VALUE rb_eFloatDomainError;
 
-static CFMutableDictionaryRef fixnum_cache = NULL;
-
-static inline VALUE
-rb_box_fixfloat0(double v)
+static VALUE
+rb_box_fixfloat0(double value)
 {
-    NEWOBJ(val, struct RFloat);
-    OBJSETUP(val, rb_cFloat, T_FLOAT);
-    val->float_value = v;
-    return (VALUE)val;
+    CFNumberRef number = CFNumberCreate(NULL, kCFNumberDoubleType, &value);
+    CFMakeCollectable(number);
+    return (VALUE)number;
 }
 
 VALUE
@@ -110,25 +107,12 @@
     return rb_box_fixfloat0(NUM2DBL(fixfloat));
 }
 
-static inline VALUE
+static VALUE
 rb_box_fixnum0(long value)
 {
-    if (fixnum_cache == NULL) {
-	fixnum_cache = CFDictionaryCreateMutable(NULL, 0, NULL,
-		&kCFTypeDictionaryValueCallBacks);
-    }
-
-    struct RFixnum *val = (struct RFixnum *)CFDictionaryGetValue(fixnum_cache,
-	    (const void *)value);
-    if (val == NULL) {
-	NEWOBJ(fixval, struct RFixnum);
-	fixval->klass = rb_cFixnum;
-	fixval->value = value;
-	val = fixval;
-	CFDictionarySetValue(fixnum_cache, (const void *)value, val);
-    }
-
-    return (VALUE)val;
+    CFNumberRef number = CFNumberCreate(NULL, kCFNumberLongType, &value);
+    CFMakeCollectable(number);
+    return (VALUE)number;
 }
 
 VALUE
@@ -3298,58 +3282,6 @@
     return Qtrue;
 }
 
-static VALUE
-imp_rb_float_copyWithZone(void *rcv, SEL sel, void *zone)
-{
-    // XXX honor zone?
-    return rb_box_fixfloat0(RFLOAT_VALUE(rcv));
-}
-
-static VALUE
-imp_rb_fixnum_copyWithZone(void *rcv, SEL sel, void *zone)
-{
-    // XXX honor zone?
-    return rb_box_fixnum0(RFIXNUM(rcv)->value);
-}
-
-static const char *
-imp_rb_float_objCType(void *rcv, SEL sel)
-{
-    return "d";
-}
-
-static const char *
-imp_rb_fixnum_objCType(void *rcv, SEL sel)
-{
-    return "l";
-}
-
-static void
-imp_rb_float_getValue(void *rcv, SEL sel, void *buffer)
-{
-    double v = RFLOAT_VALUE(rcv);
-    *(double *)buffer = v;
-}
-
-static void
-imp_rb_fixnum_getValue(void *rcv, SEL sel, void *buffer)
-{
-    long v = RFIXNUM(rcv)->value;
-    *(long *)buffer = v;
-}
-
-static double
-imp_rb_float_doubleValue(void *rcv, SEL sel)
-{
-    return RFLOAT_VALUE(rcv);
-}
-
-static long long
-imp_rb_fixnum_longValue(void *rcv, SEL sel)
-{
-    return RFIXNUM(rcv)->value;
-}
-
 static void *
 imp_nsnumber_to_int(void *rcv, SEL sel)
 {
@@ -3365,37 +3297,6 @@
     return (void *)new_num;
 }
 
-static void
-rb_install_nsnumber_primitives(void)
-{
-    Class klass;
-  
-    klass = (Class)rb_cFloat;
-    rb_objc_install_method2(klass, "copyWithZone:",
-	    (IMP)imp_rb_float_copyWithZone);
-    rb_objc_install_method2(klass, "objCType", (IMP)imp_rb_float_objCType);
-    rb_objc_install_method2(klass, "getValue:", (IMP)imp_rb_float_getValue);
-    rb_objc_install_method2(klass, "doubleValue", 
-	    (IMP)imp_rb_float_doubleValue);
-
-    klass = (Class)rb_cFixnum;
-    rb_objc_install_method2(klass, "copyWithZone:",
-	    (IMP)imp_rb_fixnum_copyWithZone);
-    rb_objc_install_method2(klass, "objCType", (IMP)imp_rb_fixnum_objCType);
-    rb_objc_install_method2(klass, "getValue:", (IMP)imp_rb_fixnum_getValue);
-    rb_objc_install_method2(klass, "longValue", (IMP)imp_rb_fixnum_longValue);
-
-    klass = (Class)rb_cNSNumber;
-    class_replaceMethod(klass, sel_registerName("to_int"),
-	    (IMP)imp_nsnumber_to_int, "@@:");
-}
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
-# define NSCFNUMBER_CNAME "NSCFNumber"
-#else
-# define NSCFNUMBER_CNAME "__NSCFNumber"
-#endif
-
 void
 Init_Numeric(void)
 {
@@ -3577,6 +3478,7 @@
     rb_objc_define_method(rb_cFloat, "nan?",      flo_is_nan_p, 0);
     rb_objc_define_method(rb_cFloat, "infinite?", flo_is_infinite_p, 0);
     rb_objc_define_method(rb_cFloat, "finite?",   flo_is_finite_p, 0);
-	
-    rb_install_nsnumber_primitives();
+
+    class_replaceMethod((Class)rb_cNSNumber, sel_registerName("to_int"),
+	    (IMP)imp_nsnumber_to_int, "@@:");
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100312/e7466e8e/attachment-0001.html>


More information about the macruby-changes mailing list