Currently the add, subtract, multiply and divide methods in perlnum.pmc
are all coded along the lines of:
void add (PMC * value, PMC* dest) {
if(value->vtable == &Parrot_base_vtables[enum_class_PerlInt]) {
* dest->vtable = &Parrot_base_vtables[enum_class_PerlNum];
* dest->vtable->set_number_native(INTERP, dest,
* SELF->cache.num_val +
* value->vtable->get_number(INTERP, value)
* );
}
else if(value->vtable == &Parrot_base_vtables[enum_class_PerlNum]){
* dest->vtable = &Parrot_base_vtables[enum_class_PerlNum];
* dest->vtable->set_number_native(INTERP, dest,
* SELF->cache.num_val +
* value->vtable->get_number(INTERP, value)
* );
}
etc.
In other words, we check the type of the value PMC, but then proceed to
execute exactly the same code (marked with *'s) in each case. Has this been
done for a reason, or could these functions be safely simplified?
Simon