[svn:parrot] r38986 - branches/tt452_reduce_mmd/src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Wed May 20 14:23:37 UTC 2009
Author: bacek
Date: Wed May 20 14:23:37 2009
New Revision: 38986
URL: https://trac.parrot.org/parrot/changeset/38986
Log:
[pmc] Rework Integer.divide methods without MULTIs.
Modified:
branches/tt452_reduce_mmd/src/pmc/integer.pmc
Modified: branches/tt452_reduce_mmd/src/pmc/integer.pmc
==============================================================================
--- branches/tt452_reduce_mmd/src/pmc/integer.pmc Wed May 20 14:23:17 2009 (r38985)
+++ branches/tt452_reduce_mmd/src/pmc/integer.pmc Wed May 20 14:23:37 2009 (r38986)
@@ -692,43 +692,39 @@
*/
- MULTI PMC *divide(BigInt value, PMC *dest) {
- PMC *temp;
- maybe_throw_overflow_error(INTERP);
- temp = VTABLE_get_bignum(INTERP, SELF);
- return VTABLE_divide(INTERP, temp, value, dest);
- }
-
- MULTI PMC *divide(DEFAULT value, PMC *dest) {
- const FLOATVAL d = VTABLE_get_number(INTERP, value);
-
- if (FLOAT_IS_ZERO(d))
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
- "float division by zero");
-
- dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
- VTABLE_set_number_native(INTERP, dest, SELF.get_number() / d);
+ VTABLE PMC *divide(PMC *value, PMC *dest) {
+ dest = VTABLE_clone(INTERP, SELF);
+ VTABLE_i_divide(INTERP, dest, value);
return dest;
}
-
- MULTI void i_divide(BigInt value) {
- maybe_throw_overflow_error(INTERP);
- SELF = upgrade_self_to_bignum(INTERP, SELF);
- VTABLE_i_divide(INTERP, SELF, value);
+ /* Register in MMD to allow override */
+ MULTI PMC *divide(DEFAULT value, PMC *dest) {
+ return Parrot_Integer_divide(INTERP, SELF, value, dest);
}
- MULTI void i_divide(DEFAULT value) {
- const FLOATVAL d = VTABLE_get_number(INTERP, value);
+ VTABLE void i_divide(PMC *value) {
+ if (VTABLE_type(INTERP, value) == enum_class_BigInt) {
+ maybe_throw_overflow_error(INTERP);
+ SELF = upgrade_self_to_bignum(INTERP, SELF);
+ VTABLE_i_divide(INTERP, SELF, value);
+ }
+ else {
+ const FLOATVAL d = VTABLE_get_number(INTERP, value);
- if (FLOAT_IS_ZERO(d))
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
+ if (FLOAT_IS_ZERO(d))
+ Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- VTABLE_set_number_native(INTERP, SELF, SELF.get_number() / d);
+ VTABLE_set_number_native(INTERP, SELF, SELF.get_number() / d);
+ }
}
+ /* Register in MMD to allow override */
+ MULTI void i_divide(DEFAULT value) {
+ Parrot_Integer_i_divide(INTERP, SELF, value);
+ }
/*
@@ -752,30 +748,17 @@
*/
- MULTI PMC *floor_divide(BigInt value, PMC *dest) {
- PMC *temp;
- maybe_throw_overflow_error(INTERP);
- temp = VTABLE_get_bignum(INTERP, SELF);
- return VTABLE_floor_divide(INTERP, temp, value, dest);
+ VTABLE PMC *floor_divide(PMC *value, PMC *dest) {
+ dest = VTABLE_clone(INTERP, SELF);
+ VTABLE_i_floor_divide(INTERP, dest, value);
+ return dest;
}
-
+ /* Register in MMD to allow override */
MULTI PMC *floor_divide(DEFAULT value, PMC *dest) {
- const FLOATVAL d = VTABLE_get_number(INTERP, value);
- FLOATVAL f;
-
- if (FLOAT_IS_ZERO(d))
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
- "float division by zero");
-
- dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- f = floor(SELF.get_number() / d);
- VTABLE_set_integer_native(INTERP, dest, (INTVAL)f);
- return dest;
+ return Parrot_Integer_floor_divide(INTERP, SELF, value, dest);
}
-
VTABLE PMC *floor_divide_int(INTVAL value, PMC *dest) {
FLOATVAL f;
@@ -806,22 +789,28 @@
return dest;
}
- MULTI void i_floor_divide(BigInt value) {
- maybe_throw_overflow_error(INTERP);
- SELF = upgrade_self_to_bignum(INTERP, SELF);
- VTABLE_i_floor_divide(INTERP, SELF, value);
- }
-
- MULTI void i_floor_divide(DEFAULT value) {
- const FLOATVAL d = VTABLE_get_number(INTERP, value);
- FLOATVAL f;
+ VTABLE void i_floor_divide(PMC *value) {
+ if (VTABLE_type(INTERP, value) == enum_class_BigInt) {
+ maybe_throw_overflow_error(INTERP);
+ SELF = upgrade_self_to_bignum(INTERP, SELF);
+ VTABLE_i_floor_divide(INTERP, SELF, value);
+ }
+ else {
+ const FLOATVAL d = VTABLE_get_number(INTERP, value);
+ FLOATVAL f;
- if (FLOAT_IS_ZERO(d))
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
+ if (FLOAT_IS_ZERO(d))
+ Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- f = floor(SELF.get_number() / d);
- VTABLE_set_integer_native(INTERP, SELF, (INTVAL)f);
+ f = floor(SELF.get_number() / d);
+ VTABLE_set_integer_native(INTERP, SELF, (INTVAL)f);
+ }
+ }
+
+ /* Register in MMD to allow override */
+ MULTI void i_floor_divide(DEFAULT value) {
+ Parrot_Integer_i_floor_divide(INTERP, SELF, value);
}
More information about the parrot-commits
mailing list