[svn:parrot] r39346 - in trunk: include/parrot src src/pmc t/op
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Jun 2 23:42:17 UTC 2009
Author: bacek
Date: Tue Jun 2 23:42:17 2009
New Revision: 39346
URL: https://trac.parrot.org/parrot/changeset/39346
Log:
Merge no_pmc_reuse branch into trunk.
Added:
trunk/t/op/arithmetics_pmc.t
Modified:
trunk/include/parrot/pmc.h
trunk/src/pmc.c
trunk/src/pmc/bigint.pmc
trunk/src/pmc/bignum.pmc
trunk/src/pmc/integer.pmc
trunk/src/pmc/scalar.pmc
Modified: trunk/include/parrot/pmc.h
==============================================================================
--- trunk/include/parrot/pmc.h Tue Jun 2 23:31:33 2009 (r39345)
+++ trunk/include/parrot/pmc.h Tue Jun 2 23:42:17 2009 (r39346)
@@ -49,16 +49,6 @@
__attribute__nonnull__(1);
PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-PARROT_WARN_UNUSED_RESULT
-PMC* Parrot_pmc_try_reuse(PARROT_INTERP,
- ARGIN(PMC *self),
- ARGIN_NULLOK(PMC * value),
- ARGIN_NULLOK(PMC *dest))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_EXPORT
INTVAL PMC_is_null(SHIM_INTERP, ARGIN_NULLOK(const PMC *pmc));
PARROT_EXPORT
@@ -143,9 +133,6 @@
|| PARROT_ASSERT_ARG(pmc)
#define ASSERT_ARGS_Parrot_create_mro __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_pmc_try_reuse __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(self)
#define ASSERT_ARGS_PMC_is_null __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_pmc_new __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
Modified: trunk/src/pmc.c
==============================================================================
--- trunk/src/pmc.c Tue Jun 2 23:31:33 2009 (r39345)
+++ trunk/src/pmc.c Tue Jun 2 23:42:17 2009 (r39346)
@@ -227,56 +227,6 @@
/*
-=item C<PMC* Parrot_pmc_try_reuse(PARROT_INTERP, PMC *self, PMC * value, PMC
-*dest)>
-
-Try to reuse dest PMC if possible. We are going to kill C<dest> anyway. So try
-to reuse it before.
-
-TODO Write nice POD about sideeffects here.
-
-=cut
-*/
-
-PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-PARROT_WARN_UNUSED_RESULT
-PMC*
-Parrot_pmc_try_reuse(PARROT_INTERP, ARGIN(PMC *self), ARGIN_NULLOK(PMC * value),
- ARGIN_NULLOK(PMC *dest))
-{
- ASSERT_ARGS(Parrot_pmc_try_reuse)
- /* Can't reuse dest because we'll lost value */
- if (dest == value)
- return pmc_new(interp, VTABLE_type(interp, self));
-
- /* Can't reuse Null */
- if (PMC_IS_NULL(dest))
- return pmc_new(interp, VTABLE_type(interp, self));
-
- /* Can't reuse read-only variables */
- if (dest->vtable->flags & VTABLE_IS_READONLY_FLAG)
- return pmc_new(interp, VTABLE_type(interp, self));
-
- /* It's safe in this case. Caller want to replace us anyway */
- if (dest == self)
- return dest;
-
- /* Morph to self type is required */
- {
- INTVAL type = VTABLE_type(interp, self);
- if (type >= enum_class_core_max)
- /* We are not core PMC. Just clone self to preserve semantic of VTABLEs */
- dest = VTABLE_clone(interp, self);
- else
- pmc_reuse(interp, dest, type, 0);
- }
-
- return dest;
-}
-
-
-/*
=item C<static void check_pmc_reuse_flags(PARROT_INTERP, UINTVAL srcflags,
UINTVAL destflags)>
Modified: trunk/src/pmc/bigint.pmc
==============================================================================
--- trunk/src/pmc/bigint.pmc Tue Jun 2 23:31:33 2009 (r39345)
+++ trunk/src/pmc/bigint.pmc Tue Jun 2 23:42:17 2009 (r39346)
@@ -311,7 +311,6 @@
static void
bigint_abs(PARROT_INTERP, PMC *self, PMC *dest) {
BIGINT *bi_self, *bi_dest;
- pmc_reuse(interp, dest, enum_class_BigInt, 0);
GETATTR_BigInt_bi(interp, self, bi_self);
GETATTR_BigInt_bi(interp, dest, bi_dest);
mpz_abs(bi_dest->b, bi_self->b);
@@ -320,7 +319,6 @@
static void
bigint_neg(PARROT_INTERP, PMC *self, PMC *dest) {
BIGINT *bi_self, *bi_dest;
- pmc_reuse(interp, dest, enum_class_BigInt, 0);
GETATTR_BigInt_bi(interp, self, bi_self);
GETATTR_BigInt_bi(interp, dest, bi_dest);
mpz_neg(bi_dest->b, bi_self->b);
@@ -837,14 +835,14 @@
}
MULTI PMC *add(BigInt value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_add_bigint(INTERP, SELF, value, dest);
return dest;
}
MULTI PMC *add(Integer value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_add_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -859,7 +857,7 @@
}
VTABLE PMC *add_int(INTVAL value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_add_bigint_int(INTERP, SELF, value, dest);
return dest;
@@ -893,14 +891,14 @@
MULTI PMC *subtract(BigInt value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_sub_bigint(INTERP, SELF, value, dest);
return dest;
}
MULTI PMC *subtract(Integer value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_sub_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -915,7 +913,7 @@
}
VTABLE PMC *subtract_int(INTVAL value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_sub_bigint_int(INTERP, SELF, value, dest);
return dest;
@@ -949,14 +947,14 @@
MULTI PMC *multiply(BigInt value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_mul_bigint(INTERP, SELF, value, dest);
return dest;
}
MULTI PMC *multiply(Integer value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_mul_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -971,7 +969,7 @@
}
VTABLE PMC *multiply_int(INTVAL value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_mul_bigint_int(INTERP, SELF, value, dest);
return dest;
@@ -1002,7 +1000,7 @@
}
VTABLE PMC *pow_int(INTVAL value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_pow_bigint_int(INTERP, SELF, value, dest);
return dest;
@@ -1011,7 +1009,7 @@
MULTI PMC *pow(PMC *value, PMC *dest) {
/* XXX only Integer RHS currently */
const INTVAL r = VTABLE_get_integer(INTERP, value);
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_pow_bigint_int(INTERP, SELF, r, dest);
return dest;
@@ -1019,7 +1017,7 @@
MULTI PMC *divide(BigInt value, PMC *dest) {
BIGINT *bi;
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_div_bigint(INTERP, SELF, value, dest);
#if 0
@@ -1035,7 +1033,7 @@
}
MULTI PMC *divide(Integer value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_div_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -1050,7 +1048,7 @@
}
VTABLE PMC *divide_int(INTVAL value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_div_bigint_int(INTERP, SELF, value, dest);
return dest;
@@ -1074,14 +1072,14 @@
}
MULTI PMC *floor_divide(BigInt value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_fdiv_bigint(INTERP, SELF, value, dest);
return dest;
}
MULTI PMC *floor_divide(Integer value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_fdiv_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -1096,7 +1094,7 @@
}
VTABLE PMC *floor_divide_int(INTVAL value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_fdiv_bigint_int(INTERP, SELF, value, dest);
return dest;
@@ -1122,14 +1120,14 @@
}
MULTI PMC *modulus(BigInt value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_mod_bigint(INTERP, SELF, value, dest);
return dest;
}
MULTI PMC *modulus(Integer value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_mod_bigint_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -1199,7 +1197,7 @@
*/
VTABLE PMC *absolute(PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_abs(INTERP, SELF, dest);
return dest;
@@ -1223,7 +1221,7 @@
*/
VTABLE PMC *neg(PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_neg(INTERP, SELF, dest);
return dest;
@@ -1252,7 +1250,7 @@
*/
MULTI PMC *bitwise_shl(BigInt value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_bitwise_shl_bigint_int(INTERP, SELF,
VTABLE_get_integer(INTERP, value),
@@ -1261,7 +1259,7 @@
}
MULTI PMC *bitwise_shl(Integer value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_bitwise_shl_bigint_int(INTERP, SELF,
VTABLE_get_integer(interp, value), dest);
@@ -1276,7 +1274,7 @@
}
VTABLE PMC *bitwise_shl_int(INTVAL value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_bitwise_shl_bigint_int(INTERP, SELF, value, dest);
return dest;
@@ -1324,7 +1322,7 @@
*/
MULTI PMC *bitwise_shr(BigInt value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_bitwise_shr_bigint_int(INTERP, SELF,
VTABLE_get_integer(INTERP, value),
@@ -1333,7 +1331,7 @@
}
MULTI PMC *bitwise_shr(Integer value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_bitwise_shr_bigint_int(INTERP, SELF,
VTABLE_get_integer(interp, value), dest);
@@ -1349,7 +1347,7 @@
}
VTABLE PMC *bitwise_shr_int(INTVAL value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bigint_bitwise_shr_bigint_int(INTERP, SELF, value, dest);
return dest;
Modified: trunk/src/pmc/bignum.pmc
==============================================================================
--- trunk/src/pmc/bignum.pmc Tue Jun 2 23:31:33 2009 (r39345)
+++ trunk/src/pmc/bignum.pmc Tue Jun 2 23:42:17 2009 (r39346)
@@ -546,7 +546,6 @@
static void
bignum_abs(PARROT_INTERP, PMC *self, PMC *dest) {
BIGNUM *bn_self, *bn_dest;
- pmc_reuse(interp, dest, enum_class_BigNum, 0);
GETATTR_BigNum_bn(interp, self, bn_self);
GETATTR_BigNum_bn(interp, dest, bn_dest);
mpf_abs(bn_dest->b, bn_self->b);
@@ -555,7 +554,6 @@
static void
bignum_neg(PARROT_INTERP, PMC *self, PMC *dest) {
BIGNUM *bn_self, *bn_dest;
- pmc_reuse(interp, dest, enum_class_BigNum, 0);
GETATTR_BigNum_bn(interp, self, bn_self);
GETATTR_BigNum_bn(interp, dest, bn_dest);
mpf_neg(bn_dest->b, bn_self->b);
@@ -1165,20 +1163,14 @@
*/
MULTI PMC *subtract(BigNum value, PMC *dest) {
- if (dest)
- pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
- else
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_sub_bignum(INTERP, SELF, value, dest);
return dest;
}
MULTI PMC *subtract(Integer value, PMC *dest) {
- if (dest)
- pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
- else
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_sub_bignum_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -1192,10 +1184,7 @@
}
VTABLE PMC *subtract_int(INTVAL value, PMC *dest) {
- if (dest)
- pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
- else
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_sub_bignum_int(INTERP, SELF, value, dest);
return dest;
@@ -1300,10 +1289,7 @@
*/
VTABLE PMC *pow_int(INTVAL value, PMC *dest) {
- if (dest)
- pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
- else
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_pow_bignum_int(INTERP, SELF, value, dest);
return dest;
@@ -1328,10 +1314,7 @@
MULTI PMC *divide(BigNum value, PMC *dest) {
BIGNUM *bn;
- if (dest)
- pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
- else
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_div_bignum(INTERP, SELF, value, dest);
#if 0
@@ -1347,10 +1330,7 @@
}
MULTI PMC *divide(Integer value, PMC *dest) {
- if (dest)
- pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
- else
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_div_bignum_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -1364,10 +1344,7 @@
}
VTABLE PMC *divide_int(INTVAL value, PMC *dest) {
- if (dest)
- pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
- else
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_div_bignum_int(INTERP, SELF, value, dest);
return dest;
@@ -1402,14 +1379,14 @@
*/
MULTI PMC *floor_divide(BigNum value, PMC *dest) {
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_fdiv_bignum(INTERP, SELF, value, dest);
return dest;
}
MULTI PMC *floor_divide(Integer value, PMC *dest) {
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_fdiv_bignum_int(INTERP, SELF, VTABLE_get_integer(interp, value), dest);
return dest;
@@ -1423,10 +1400,7 @@
}
VTABLE PMC *floor_divide_int(INTVAL value, PMC *dest) {
- if (dest)
- pmc_reuse(interp, dest, SELF->vtable->base_type, 0);
- else
- dest = pmc_new(INTERP, SELF->vtable->base_type);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
bignum_fdiv_bignum_int(INTERP, SELF, value, dest);
return dest;
Modified: trunk/src/pmc/integer.pmc
==============================================================================
--- trunk/src/pmc/integer.pmc Tue Jun 2 23:31:33 2009 (r39345)
+++ trunk/src/pmc/integer.pmc Tue Jun 2 23:42:17 2009 (r39346)
@@ -43,7 +43,6 @@
return self;
}
-
pmclass Integer extends scalar provides integer provides scalar {
ATTR INTVAL iv; /* the value of this Integer */
@@ -348,7 +347,7 @@
const INTVAL c = a + b;
if ((c^a) >= 0 || (c^b) >= 0) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(interp, SELF));
/* need this for e.g. Undef PMC */
VTABLE_set_integer_native(INTERP, dest, c);
@@ -385,7 +384,7 @@
MULTI PMC *add(DEFAULT value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(interp, value));
VTABLE_set_number_native(INTERP, dest,
SELF.get_integer() + VTABLE_get_number(INTERP, value));
@@ -398,7 +397,7 @@
const INTVAL c = a + b;
if ((c^a) >= 0 || (c^b) >= 0) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest, c);
return dest;
@@ -487,7 +486,7 @@
const INTVAL c = a - b;
if ((c^a) >= 0 || (c^~b) >= 0) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest, c);
return dest;
@@ -523,7 +522,7 @@
MULTI PMC *subtract(DEFAULT value, PMC *dest) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, value));
VTABLE_set_number_native(INTERP, dest,
SELF.get_integer() - VTABLE_get_number(INTERP, value));
@@ -546,7 +545,7 @@
const INTVAL c = a - b;
if ((c^a) >= 0 || (c^~b) >= 0) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest, c);
return dest;
@@ -645,7 +644,7 @@
const double cf = (double)a * (double)b;
if ((double) c == cf) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(interp, SELF));
VTABLE_set_integer_native(INTERP, dest, c);
return dest;
@@ -676,7 +675,7 @@
MULTI PMC *multiply(DEFAULT value, PMC *dest) {
const FLOATVAL valf = VTABLE_get_number(INTERP, value);
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_number_native(INTERP, dest, SELF.get_number() * valf);
return dest;
@@ -689,7 +688,7 @@
const double cf = (double)a * (double)b;
if ((double) c == cf) {
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest, c);
return dest;
@@ -794,7 +793,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_number_native(INTERP, dest, SELF.get_number() / d);
return dest;
}
@@ -856,7 +855,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
f = floor(SELF.get_number() / d);
VTABLE_set_integer_native(INTERP, dest, (INTVAL)f);
@@ -871,7 +870,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
f = floor(SELF.get_number() / value);
VTABLE_set_integer_native(INTERP, dest, (INTVAL)f);
@@ -886,7 +885,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
f = floor(SELF.get_number() / value);
VTABLE_set_integer_native(INTERP, dest, (INTVAL)f);
@@ -977,7 +976,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"int modulus by zero");
- dest = Parrot_pmc_try_reuse(INTERP, SELF, value, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest,
intval_mod(SELF.get_integer(), d));
@@ -990,7 +989,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"int modulus by zero");
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest,
intval_mod(SELF.get_integer(), value));
@@ -1003,7 +1002,7 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"int modulus by zero");
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest,
intval_mod(SELF.get_integer(), (INTVAL)value));
@@ -1122,7 +1121,7 @@
}
}
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest, r);
return dest;
@@ -1309,7 +1308,7 @@
const INTVAL a = abs(SELF.get_integer());
/* RT #46635 overflow for -maxint */
- dest = Parrot_pmc_try_reuse(INTERP, SELF, NULL, dest);
+ dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
VTABLE_set_integer_native(INTERP, dest, a);
return dest;
Modified: trunk/src/pmc/scalar.pmc
==============================================================================
--- trunk/src/pmc/scalar.pmc Tue Jun 2 23:31:33 2009 (r39345)
+++ trunk/src/pmc/scalar.pmc Tue Jun 2 23:42:17 2009 (r39346)
@@ -76,7 +76,7 @@
dest = pmc_new(interp, enum_class_BigInt);
VTABLE_set_integer_native(interp, dest, base);
- interp->vtables[enum_class_BigInt]->bitwise_shl_int(interp, dest, shift_amount, dest);
+ VTABLE_i_bitwise_shl_int(interp, dest, shift_amount);
}
return dest;
Added: trunk/t/op/arithmetics_pmc.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/t/op/arithmetics_pmc.t Tue Jun 2 23:42:17 2009 (r39346)
@@ -0,0 +1,109 @@
+#!perl
+# Copyright (C) 2001-2009, Parrot Foundation.
+# $Id$
+
+use strict;
+use warnings;
+use lib qw( . lib ../lib ../../lib );
+
+use Test::More;
+use Parrot::Test;
+
+# test for GMP
+use Parrot::Config;
+
+=head1 NAME
+
+t/op/arithmetics_pmc.t - Arithmetic Ops involving PMCs
+
+=head1 SYNOPSIS
+
+ % prove t/op/arithmetics_pmc.t
+
+=head1 DESCRIPTION
+
+Test handling C<dest> arg in 3-args arithmetic.
+
+=cut
+
+# We don't check BigInt and BigNum ops
+if ( $PConfig{gmp} ) {
+ plan tests => 68;
+}
+else {
+ plan tests => 34;
+}
+
+
+# Map vtable method to op
+my %methods = qw{
+ add add
+ subtract sub
+ multiply mul
+ divide div
+
+ floor_divide fdiv
+ modulus mod
+ pow pow
+
+ bitwise_or bor
+ bitwise_and band
+ bitwise_xor bxor
+
+ bitwise_shr shr
+ bitwise_shl shl
+ bitwise_lsr lsr
+
+ concatenate concat
+
+ logical_or or
+ logical_and and
+ logical_xor xor
+};
+
+# XXX Put BigInt and BigNum here
+my @pmcs = qw{
+ Integer Float
+};
+
+if ($PConfig{gmp}) {
+ push @pmcs, qw{ BigInt BigNum};
+}
+
+foreach my $pmc (@pmcs) {
+ while(my($vtable, $op) = each(%methods)) {
+
+# We should generate more tests for all possible combinations
+pir_output_is( <<"CODE", <<OUTPUT, "Original dest is untouched in $pmc.$vtable " );
+.sub 'test' :main
+ \$P0 = new '$pmc'
+ \$P0 = 40
+ \$P1 = new '$pmc'
+ \$P1 = 2
+ \$P2 = new '$pmc'
+ \$P2 = 115200
+
+ \$P99 = \$P2
+ # ignore exceptions
+ push_eh done
+ $op \$P2, \$P0, \$P1
+
+ \$I0 = cmp \$P99, 115200
+ unless \$I0 goto done
+ print " not "
+ done:
+ say "ok"
+.end
+CODE
+ok
+OUTPUT
+
+ }
+}
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
More information about the parrot-commits
mailing list