[Python-Dev] Parrot -- should life imitate satire? (original) (raw)

Simon Cozens simon@netthink.co.uk
Thu, 2 Aug 2001 10:30:06 -0700


On Wed, Aug 01, 2001 at 12:42:42AM -0400, Tim Peters wrote:

case BINARYDIVIDE:

case? Wowsers. Hey, Ruby does that too. We use function pointers, FWIW.

Oh, and here's our divide, for comparison:

PP(pp_divide) { dSP; dATARGET; tryAMAGICbin(div,opASSIGN); { dPOPPOPnnrl; NV value; if (right == 0.0) DIE(aTHX_ "Illegal division by zero"); value = left / right; PUSHn( value ); RETURN; } }

See, this is why we need a new interpreter. :)

In slightly more pseudo code:

PP(pp_divide) { get_the_stack_pointer; find_somewhere_to_put_result; check_if_overloaded; { NV right = SvNV(POP); NV left = SvNV(POP); NV value; if (right == 0.0) DIE(aTHX_ "Illegal division by zero"); value = left / right; PUSHn( value ); RETURN; } }