[macruby-changes] [1710] MacRuby/branches/fp-optimized-experimental

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 3 13:31:51 PDT 2009


Revision: 1710
          http://trac.macosforge.org/projects/ruby/changeset/1710
Author:   pthomson at apple.com
Date:     2009-06-03 13:31:50 -0700 (Wed, 03 Jun 2009)
Log Message:
-----------
Got rid of the FixFloat class and replaced with the Float#__immediate__? method.

Modified Paths:
--------------
    MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h
    MacRuby/branches/fp-optimized-experimental/numeric.c

Modified: MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h	2009-06-03 19:46:18 UTC (rev 1709)
+++ MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h	2009-06-03 20:31:50 UTC (rev 1710)
@@ -233,26 +233,13 @@
 
 #define IMMEDIATE_P(x) ((VALUE)(x) & IMMEDIATE_MASK)
 
-// We can't directly cast a void* to a double, so we cast it to a union
-// and then extract its double member. Hacky, but effective.
-// This doesn't work in C++, though. I need suggestions on how to do it there.
-typedef union {VALUE val; void* vd; double d;} hack_t;
 
-static inline double coerce_ptr_to_double(hack_t h)
-{
-	h.val ^= 3; // unset the last two bits.
-	return h.d;
-}
-
-
 #define VOODOO_DOUBLE(d) (*(VALUE*)(&d))
 #define DBL2FIXFLOAT(d) (VOODOO_DOUBLE(d) | FIXFLOAT_FLAG)
 #define FIXABLE_DBL(d) (!(VOODOO_DOUBLE(d) & FIXFLOAT_FLAG))
 #define FIXFLOAT_P(v)  (((VALUE)v & FIXFLOAT_FLAG) == FIXFLOAT_FLAG)
-#define FIXFLOAT2DBL(v) coerce_ptr_to_double((hack_t)v)
+#define FIXFLOAT2DBL(v) coerce_ptr_to_double((__coerced_value_double_t)v)
 
-
-
 #if WITH_OBJC
 # define SYMBOL_P(x) (TYPE(x) == T_SYMBOL)
 # define ID2SYM(x) (rb_id2str((ID)x))
@@ -279,6 +266,18 @@
     RUBY_SPECIAL_SHIFT  = 8,
 };
 
+// We can't directly cast a void* to a double, so we cast it to a union
+// and then extract its double member. Hacky, but effective.
+// This doesn't work in C++, though. I need suggestions on how to do it there.
+typedef union {VALUE val; void* vd; double d;} __coerced_value_double_t;
+
+static inline double coerce_ptr_to_double(__coerced_value_double_t h)
+{
+	h.val ^= RUBY_FIXFLOAT_FLAG; // unset the last two bits.
+	return h.d;
+}
+
+
 #define Qfalse ((VALUE)RUBY_Qfalse)
 #define Qtrue  ((VALUE)RUBY_Qtrue)
 #define Qnil   ((VALUE)RUBY_Qnil)
@@ -1044,7 +1043,6 @@
 RUBY_EXTERN VALUE rb_cEnumerator;
 RUBY_EXTERN VALUE rb_cFile;
 RUBY_EXTERN VALUE rb_cFixnum;
-RUBY_EXTERN VALUE rb_cFixFloat;
 RUBY_EXTERN VALUE rb_cFloat;
 RUBY_EXTERN VALUE rb_cHash;
 RUBY_EXTERN VALUE rb_cInteger;
@@ -1214,7 +1212,7 @@
     if (*(Class *)obj == (Class)rb_cFixnum) {
 	return LONG2FIX(RFIXNUM(obj)->value);
     }
-	if (*(Class *)obj == (Class)rb_cFixFloat) {
+	if (*(Class *)obj == (Class)rb_cFloat) {
 		extern VALUE rb_float_new(double);
 		return rb_float_new(RFLOAT(obj)->float_value);
 	}
@@ -1251,7 +1249,7 @@
 {
     if (IMMEDIATE_P(obj)) {
 	if (FIXNUM_P(obj)) return rb_cFixnum;
-	if (FIXFLOAT_P(obj)) return rb_cFixFloat;
+	if (FIXFLOAT_P(obj)) return rb_cFloat;
 	if (obj == Qtrue)  return rb_cTrueClass;
 #if !WITH_OBJC
 	if (SYMBOL_P(obj)) return rb_cSymbol;
@@ -1326,9 +1324,6 @@
 	if (k == (Class)rb_cFixnum) {
 	    return T_FIXNUM;
 	}
-	if (k == (Class)rb_cFixFloat) {
-		return T_FLOAT;
-	}
 	if (NATIVE(obj)) {
 	    return T_NATIVE;
 	}

Modified: MacRuby/branches/fp-optimized-experimental/numeric.c
===================================================================
--- MacRuby/branches/fp-optimized-experimental/numeric.c	2009-06-03 19:46:18 UTC (rev 1709)
+++ MacRuby/branches/fp-optimized-experimental/numeric.c	2009-06-03 20:31:50 UTC (rev 1710)
@@ -87,7 +87,6 @@
 VALUE rb_cFloat;
 VALUE rb_cInteger;
 VALUE rb_cFixnum;
-VALUE rb_cFixFloat;
 
 VALUE rb_eZeroDivError;
 VALUE rb_eFloatDomainError;
@@ -99,7 +98,7 @@
 rb_box_fixfloat(VALUE fixfloat)
 {
 	struct RFloat *val = malloc(sizeof(struct RFloat));
-	(val->basic).klass = rb_cFixFloat;
+	(val->basic).klass = rb_cFloat;
 	val->float_value = NUM2DBL(fixfloat);
 	return (VALUE)val;
 }
@@ -1389,7 +1388,19 @@
     return LONG2FIX(val);
 }
 
+/*
+ *  call-seq:
+ *     flt.__immediate__? -> true or false
+ *
+ *  Returns <code>true</code> if <i>fix</i> is an even number.
+ */
 
+static VALUE
+flo_immediate_p(VALUE num, SEL sel)
+{
+	return (FIXFLOAT_P(num) ? Qtrue : Qfalse);
+}
+
 /*
  *  call-seq:
  *     num.floor    => integer
@@ -3146,6 +3157,8 @@
     return Qtrue;
 }
 
+
+
 static const char *
 imp_rb_float_objCType(void *rcv, SEL sel)
 {
@@ -3379,9 +3392,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_objc_define_method(rb_cFloat, "__immediate__?", flo_immediate_p, 0);
 	
-	rb_cFixFloat  = rb_define_class("FixFloat", rb_cFloat);
-	rb_undef_method(CLASS_OF(rb_cFixFloat), "new");
-	
     rb_install_nsnumber_primitives();
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090603/60a0bfc4/attachment.html>


More information about the macruby-changes mailing list