[svn:parrot] r48674 - trunk/src/pmc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Thu Aug 26 19:54:32 UTC 2010
Author: chromatic
Date: Thu Aug 26 19:54:32 2010
New Revision: 48674
URL: https://trac.parrot.org/parrot/changeset/48674
Log:
[PMC] Used more init_int() in Integer PMC.
Modified:
trunk/src/pmc/integer.pmc
Modified: trunk/src/pmc/integer.pmc
==============================================================================
--- trunk/src/pmc/integer.pmc Thu Aug 26 19:54:27 2010 (r48673)
+++ trunk/src/pmc/integer.pmc Thu Aug 26 19:54:32 2010 (r48674)
@@ -141,9 +141,8 @@
*/
VTABLE PMC *clone() {
- PMC * const clone = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
- VTABLE_set_integer_native(INTERP, clone, SELF.get_integer());
- return clone;
+ return Parrot_pmc_new_init_int(INTERP, SELF->vtable->base_type,
+ SELF.get_integer());
}
/*
@@ -321,18 +320,13 @@
const INTVAL b = VTABLE_get_integer(INTERP, value);
const INTVAL c = a + b;
- if ((c^a) >= 0 || (c^b) >= 0) {
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- /* need this for e.g. Undef PMC */
- VTABLE_set_integer_native(INTERP, dest, c);
- return dest;
- }
+ if ((c^a) >= 0 || (c^b) >= 0)
+ return Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, SELF), c);
else {
- PMC * temp;
+ PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, a);
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt, a);
return VTABLE_add(INTERP, temp, value, dest);
}
}
@@ -340,10 +334,9 @@
MULTI PMC *add(Complex value, PMC *dest) {
const INTVAL a = SELF.get_integer();
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, value));
-
- VTABLE_set_number_native(INTERP, dest,
- a + VTABLE_get_number_keyed_int(INTERP, value, 0));
+ dest = Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, value),
+ a + VTABLE_get_number_keyed_int(INTERP, value, 0));
VTABLE_set_number_keyed_int(INTERP, dest, 1,
VTABLE_get_number_keyed_int(INTERP, value, 1));
@@ -354,17 +347,16 @@
MULTI PMC *add(BigInt value, PMC *dest) {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, SELF.get_integer());
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt,
+ SELF.get_integer());
return VTABLE_add(INTERP, temp, value, dest);
}
MULTI PMC *add(DEFAULT value, PMC *dest) {
dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, value));
-
VTABLE_set_number_native(INTERP, dest,
- SELF.get_integer() + VTABLE_get_number(INTERP, value));
+ SELF.get_integer() + VTABLE_get_number(interp, value));
return dest;
}
@@ -373,17 +365,13 @@
const INTVAL a = VTABLE_get_integer(INTERP, SELF);
const INTVAL c = a + b;
- if ((c^a) >= 0 || (c^b) >= 0) {
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest, c);
- return dest;
- }
+ if ((c^a) >= 0 || (c^b) >= 0)
+ return Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, SELF), c);
else {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, a);
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt,a );
return VTABLE_add_int(INTERP, temp, b, dest);
}
}
@@ -463,17 +451,13 @@
const INTVAL b = VTABLE_get_integer(INTERP, value);
const INTVAL c = a - b;
- if ((c^a) >= 0 || (c^~b) >= 0) {
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest, c);
- return dest;
- }
+ if ((c^a) >= 0 || (c^~b) >= 0)
+ return Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, SELF), c);
else {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, a);
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt, a);
return VTABLE_subtract(INTERP, temp, value, dest);
}
}
@@ -495,8 +479,8 @@
MULTI PMC *subtract(BigInt value, PMC *dest) {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, SELF.get_integer());
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt,
+ SELF.get_integer());
return VTABLE_subtract(INTERP, temp, value, dest);
}
@@ -524,17 +508,13 @@
const INTVAL a = SELF.get_integer();
const INTVAL c = a - b;
- if ((c^a) >= 0 || (c^~b) >= 0) {
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest, c);
- return dest;
- }
+ if ((c^a) >= 0 || (c^~b) >= 0)
+ return Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, SELF), c);
else {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, a);
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt, a);
return VTABLE_subtract_int(INTERP, temp, b, dest);
}
}
@@ -624,17 +604,13 @@
const INTVAL c = a * b;
const double cf = (double)a * (double)b;
- if ((double) c == cf) {
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest, c);
- return dest;
- }
+ if ((double) c == cf)
+ return Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, SELF), c);
else {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, a);
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt, a);
return VTABLE_multiply(INTERP, temp, value, dest);
}
}
@@ -657,10 +633,8 @@
MULTI PMC *multiply(DEFAULT value, PMC *dest) {
const FLOATVAL valf = VTABLE_get_number(INTERP, value);
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_number_native(INTERP, dest, SELF.get_number() * valf);
- return dest;
+ return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
+ SELF.get_number() * valf);
}
@@ -669,17 +643,13 @@
const INTVAL c = a * b;
const double cf = (double)a * (double)b;
- if ((double) c == cf) {
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest, c);
- return dest;
- }
+ if ((double) c == cf)
+ return Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, SELF), c);
else {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, a);
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt, a);
return VTABLE_multiply_int(INTERP, temp, b, dest);
}
}
@@ -765,8 +735,8 @@
MULTI PMC *divide(BigInt value, PMC *dest) {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, SELF.get_integer());
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt,
+ SELF.get_integer());
return VTABLE_divide(INTERP, temp, value, dest);
}
@@ -777,9 +747,8 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
- VTABLE_set_number_native(INTERP, dest, SELF.get_number() / d);
- return dest;
+ return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
+ SELF.get_number() / d);
}
@@ -826,8 +795,8 @@
MULTI PMC *floor_divide(BigInt value, PMC *dest) {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, SELF.get_integer());
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt,
+ SELF.get_integer());
return VTABLE_floor_divide(INTERP, temp, value, dest);
}
@@ -840,11 +809,9 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- dest = Parrot_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_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
+ (INTVAL)f);
}
@@ -855,12 +822,9 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
f = floor(SELF.get_number() / value);
- VTABLE_set_integer_native(INTERP, dest, (INTVAL)f);
-
- return dest;
+ return Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, SELF), (INTVAL)f);
}
VTABLE PMC *floor_divide_float(FLOATVAL value, PMC *dest) {
@@ -870,12 +834,9 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"float division by zero");
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
f = floor(SELF.get_number() / value);
- VTABLE_set_integer_native(INTERP, dest, (INTVAL)f);
-
- return dest;
+ return Parrot_pmc_new_init_int(INTERP,
+ VTABLE_type(INTERP, SELF), (INTVAL)f);
}
MULTI void i_floor_divide(BigInt value) {
@@ -948,8 +909,8 @@
MULTI PMC *modulus(BigInt value, PMC *dest) {
PMC *temp;
maybe_throw_overflow_error(INTERP);
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, SELF.get_integer());
+ temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt,
+ SELF.get_integer());
return VTABLE_modulus(INTERP, temp, value, dest);
}
@@ -961,11 +922,8 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"int modulus by zero");
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest,
+ return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
intval_mod(SELF.get_integer(), d));
- return dest;
}
@@ -974,11 +932,8 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"int modulus by zero");
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest,
+ return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
intval_mod(SELF.get_integer(), value));
- return dest;
}
@@ -987,11 +942,8 @@
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
"int modulus by zero");
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest,
+ return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
intval_mod(SELF.get_integer(), (INTVAL)value));
- return dest;
}
@@ -1045,15 +997,16 @@
VTABLE INTVAL is_equal(PMC *value) {
INTVAL retval;
- PMC *temp;
switch (value->vtable->base_type) {
case enum_class_BigInt:
- temp = Parrot_pmc_new(INTERP, enum_class_BigInt);
- VTABLE_set_integer_native(INTERP, temp, SELF.get_integer());
+ {
+ PMC const *temp = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt,
+ SELF.get_integer());
Parrot_mmd_multi_dispatch_from_c_args(INTERP,
"is_equal", "PP->I", temp, value, &retval);
return retval;
+ }
break;
default:
return (VTABLE_get_integer(INTERP, SELF)
@@ -1210,11 +1163,7 @@
const INTVAL a = abs(SELF.get_integer());
/* TT # 1245 overflow for -maxint */
- dest = Parrot_pmc_new(INTERP, VTABLE_type(INTERP, SELF));
-
- VTABLE_set_integer_native(INTERP, dest, a);
- return dest;
-
+ return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF), a);
}
More information about the parrot-commits
mailing list