David Mitchell wrote:
> To get my head round PDD 2, I've just written the the outline
> for the body of the add() method for a hypophetical integer PMC class:
[... lots of complex code ...]
I think this example is a good reason to consider only having one
argument math ops. Instead of dst->add(arg1, arg2) why not just have
dst->add(arg)? Then the PVM can generate code that does the right
thing considering the types of all values in an expression.
It doesn't affect the ability to overload at all -- we just move
overloading to an earlier stage of compilation, i.e. before we emit
PVM instructions.
Examples:
Perl code: $x = 1 + 2
Parse tree: op_assign($x, op_add(1, 2))
PVM code: $x = 1; $x += 2
Perl code: $x = 1 + 2 + 3
Parse tree: op_assign($x, op_add(op_add(1, 2), 3))
PVM code: new $t; $t = 1; $t += 2; $x = $t; $t += 3
It will be more work for the optimizer, but I think it will produce
much more understandable PMC objects.
- Ken