<aol>
On Tue, Feb 12, 2002 at 11:28:26PM +0000, Simon Glover wrote:
>
> 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?
</aol>
[except that now it seems Parrot_PerlNum_add has a 3 way PerlInt, PerlNum,
PerlString]
It's not obvious to me why there are 3 there, only 2 in -,*,/
Or why there isn't just 1 sort of code, as Simon suggests.
Nicholas Clark
--
EMCFT http://www.ccl4.org/~nick/CV.html