[macruby-changes] [2402] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Aug 27 22:11:17 PDT 2009
Revision: 2402
http://trac.macosforge.org/projects/ruby/changeset/2402
Author: lsansonetti at apple.com
Date: 2009-08-27 22:11:13 -0700 (Thu, 27 Aug 2009)
Log Message:
-----------
added fixnum/float/complex support for the fast arithmetic primitives
Modified Paths:
--------------
MacRuby/trunk/complex.c
MacRuby/trunk/numeric.c
MacRuby/trunk/vm.cpp
Modified: MacRuby/trunk/complex.c
===================================================================
--- MacRuby/trunk/complex.c 2009-08-28 04:57:21 UTC (rev 2401)
+++ MacRuby/trunk/complex.c 2009-08-28 05:11:13 UTC (rev 2402)
@@ -683,6 +683,12 @@
return f_addsub(self, other, f_add, selPLUS);
}
+VALUE
+rb_nu_plus(VALUE x, VALUE y)
+{
+ return f_addsub(x, y, f_add, selPLUS);
+}
+
/*
* call-seq:
* cmp - numeric -> complex
@@ -695,6 +701,12 @@
return f_addsub(self, other, f_sub, selMINUS);
}
+VALUE
+rb_nu_minus(VALUE x, VALUE y)
+{
+ return f_addsub(x, y, f_sub, selMINUS);
+}
+
/*
* call-seq:
* cmp * numeric -> complex
@@ -726,6 +738,12 @@
return rb_objc_num_coerce_bin(self, other, selMULT);
}
+VALUE
+rb_nu_mul(VALUE x, VALUE y)
+{
+ return nucomp_mul(x, 0, y);
+}
+
inline static VALUE
f_divide(VALUE self, VALUE other,
VALUE (*func)(VALUE, VALUE), SEL op)
@@ -801,6 +819,12 @@
return f_divide(self, other, f_quo, sel_quo);
}
+VALUE
+rb_nu_div(VALUE x, VALUE y)
+{
+ return nucomp_div(x, 0, y);
+}
+
#define nucomp_quo nucomp_div
/*
Modified: MacRuby/trunk/numeric.c
===================================================================
--- MacRuby/trunk/numeric.c 2009-08-28 04:57:21 UTC (rev 2401)
+++ MacRuby/trunk/numeric.c 2009-08-28 05:11:13 UTC (rev 2402)
@@ -659,8 +659,8 @@
* and <code>other</code>.
*/
-static VALUE
-flo_plus(VALUE x, SEL sel, VALUE y)
+VALUE
+rb_flo_plus(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -674,6 +674,12 @@
}
}
+static VALUE
+flo_plus(VALUE x, SEL sel, VALUE y)
+{
+ return rb_flo_plus(x, y);
+}
+
/*
* call-seq:
* float + other => float
@@ -682,8 +688,8 @@
* and <code>other</code>.
*/
-static VALUE
-flo_minus(VALUE x, SEL sel, VALUE y)
+VALUE
+rb_flo_minus(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -697,6 +703,12 @@
}
}
+static VALUE
+flo_minus(VALUE x, SEL sel, VALUE y)
+{
+ return rb_flo_minus(x, y);
+}
+
/*
* call-seq:
* float * other => float
@@ -705,8 +717,8 @@
* and <code>other</code>.
*/
-static VALUE
-flo_mul(VALUE x, SEL sel, VALUE y)
+VALUE
+rb_flo_mul(VALUE x, VALUE y)
{
switch (TYPE(y)) {
case T_FIXNUM:
@@ -720,6 +732,12 @@
}
}
+static VALUE
+flo_mul(VALUE x, SEL sel, VALUE y)
+{
+ return rb_flo_mul(x, y);
+}
+
/*
* call-seq:
* float / other => float
@@ -728,8 +746,8 @@
* <code>float</code> by <code>other</code>.
*/
-static VALUE
-flo_div(VALUE x, SEL sel, VALUE y)
+VALUE
+rb_flo_div(VALUE x, VALUE y)
{
long f_y;
double d;
@@ -749,6 +767,12 @@
}
static VALUE
+flo_div(VALUE x, SEL sel, VALUE y)
+{
+ return rb_flo_div(x, y);
+}
+
+static VALUE
flo_quo(VALUE x, SEL sel, VALUE y)
{
return rb_vm_call(x, selDIV, 1, &y, false);
@@ -2183,8 +2207,8 @@
* result.
*/
-static VALUE
-fix_plus(VALUE x, SEL sel, VALUE y)
+VALUE
+rb_fix_plus(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
long a, b, c;
@@ -2207,6 +2231,12 @@
}
}
+static VALUE
+fix_plus(VALUE x, SEL sel, VALUE y)
+{
+ return rb_fix_plus(x, y);
+}
+
/*
* call-seq:
* fix - numeric => numeric_result
@@ -2216,8 +2246,8 @@
* result.
*/
-static VALUE
-fix_minus(VALUE x, SEL sel, VALUE y)
+VALUE
+rb_fix_minus(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
long a, b, c;
@@ -2241,6 +2271,12 @@
}
}
+static VALUE
+fix_minus(VALUE x, SEL sel, VALUE y)
+{
+ return rb_fix_minus(x, y);
+}
+
#define SQRT_LONG_MAX ((SIGNED_VALUE)1<<((SIZEOF_LONG*CHAR_BIT-1)/2))
/*tests if N*N would overflow*/
#define FIT_SQRT_LONG(n) (((n)<SQRT_LONG_MAX)&&((n)>=-SQRT_LONG_MAX))
@@ -2254,8 +2290,8 @@
* result.
*/
-static VALUE
-fix_mul(VALUE x, SEL sel, VALUE y)
+VALUE
+rb_fix_mul(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
#ifdef __HP_cc
@@ -2300,6 +2336,12 @@
}
}
+static VALUE
+fix_mul(VALUE x, SEL sel, VALUE y)
+{
+ return rb_fix_mul(x, y);
+}
+
static void
fixdivmod(long x, long y, long *divp, long *modp)
{
@@ -2406,6 +2448,12 @@
return fix_divide(x, y, selDIV);
}
+VALUE
+rb_fix_div(VALUE x, VALUE y)
+{
+ return fix_divide(x, y, selDIV);
+}
+
/*
* call-seq:
* fix.div(numeric) => numeric_result
Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp 2009-08-28 04:57:21 UTC (rev 2401)
+++ MacRuby/trunk/vm.cpp 2009-08-28 05:11:13 UTC (rev 2402)
@@ -2645,12 +2645,16 @@
}
#if ROXOR_VM_DEBUG
- const bool cached = cache->flag != 0;
+ bool cached = true;
#endif
bool do_rcache = true;
if (cache->flag == 0) {
recache:
+#if ROXOR_VM_DEBUG
+ cached = false;
+#endif
+
Method method;
if (opt == DISPATCH_SUPER) {
method = rb_vm_super_lookup((VALUE)klass, sel);
@@ -3041,6 +3045,21 @@
// not, because this is already handled by the compiler.
// Also, fixnums and floats are already handled.
+extern "C" {
+ VALUE rb_fix_plus(VALUE x, VALUE y);
+ VALUE rb_fix_minus(VALUE x, VALUE y);
+ VALUE rb_fix_div(VALUE x, VALUE y);
+ VALUE rb_fix_mul(VALUE x, VALUE y);
+ VALUE rb_flo_plus(VALUE x, VALUE y);
+ VALUE rb_flo_minus(VALUE x, VALUE y);
+ VALUE rb_flo_div(VALUE x, VALUE y);
+ VALUE rb_flo_mul(VALUE x, VALUE y);
+ VALUE rb_nu_plus(VALUE x, VALUE y);
+ VALUE rb_nu_minus(VALUE x, VALUE y);
+ VALUE rb_nu_div(VALUE x, VALUE y);
+ VALUE rb_nu_mul(VALUE x, VALUE y);
+}
+
extern "C"
VALUE
rb_vm_fast_plus(struct mcache *cache, VALUE self, VALUE other)
@@ -3049,6 +3068,12 @@
// TODO: Array, String
case T_BIGNUM:
return rb_big_plus(self, other);
+ case T_FIXNUM:
+ return rb_fix_plus(self, other);
+ case T_FLOAT:
+ return rb_flo_plus(self, other);
+ case T_COMPLEX:
+ return rb_nu_plus(self, other);
}
return rb_vm_dispatch(cache, self, selPLUS, NULL, 0, 1, other);
}
@@ -3061,6 +3086,12 @@
// TODO: Array, String
case T_BIGNUM:
return rb_big_minus(self, other);
+ case T_FIXNUM:
+ return rb_fix_minus(self, other);
+ case T_FLOAT:
+ return rb_flo_minus(self, other);
+ case T_COMPLEX:
+ return rb_nu_minus(self, other);
}
return rb_vm_dispatch(cache, self, selMINUS, NULL, 0, 1, other);
}
@@ -3072,6 +3103,12 @@
switch (TYPE(self)) {
case T_BIGNUM:
return rb_big_div(self, other);
+ case T_FIXNUM:
+ return rb_fix_div(self, other);
+ case T_FLOAT:
+ return rb_flo_div(self, other);
+ case T_COMPLEX:
+ return rb_nu_div(self, other);
}
return rb_vm_dispatch(cache, self, selDIV, NULL, 0, 1, other);
}
@@ -3084,6 +3121,12 @@
// TODO: Array, String
case T_BIGNUM:
return rb_big_mul(self, other);
+ case T_FIXNUM:
+ return rb_fix_mul(self, other);
+ case T_FLOAT:
+ return rb_flo_mul(self, other);
+ case T_COMPLEX:
+ return rb_nu_mul(self, other);
}
return rb_vm_dispatch(cache, self, selMULT, NULL, 0, 1, other);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090827/30bc177b/attachment.html>
More information about the macruby-changes
mailing list