Jeff Clites <[EMAIL PROTECTED]> wrote:
>>
>> No. The binary operations in Python are opcodes, as well as in Parrot.
>> And both provide the snytax to override the opcode doing a method call,
>> that's it.
> I guess we'll just have to disagree here. I don't see any evidence of
> this
UTSL please. The code is even inlined:
,--[ Python/ceval.c ]--------------------------------
| case BINARY_ADD:
| w = POP();
| v = TOP();
| if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
| /* INLINE: int + int */
| register long a, b, i;
| a = PyInt_AS_LONG(v);
| b = PyInt_AS_LONG(w);
| i = a + b;
| if ((i^a) < 0 && (i^b) < 0)
| goto slow_add;
| x = PyInt_FromLong(i);
`----------------------------------------------------
> Not actually MMD in Python--behavior only depends on the left operand,
> it seems.
It's hard to say what Python actually does. It's a mess of nested if's.
>> null dest
>> dest = l + r
>>
>> should produce a *new* dest PMC.
> Yes, it's a separate issue, but it's pointing out a general design
> problem with these ops--their baseline behavior isn't useful.
It *is* useful. If the destination exists, you can use it. The
destination PMC acts as a reference then, changing the value in place.
But in case of Python it's not of much use, except for the inplace
(augmented) operations.
> ..., but for
> PMCs this could compile like "a = b.plus(c)".
> but you don't need add_p_p_p, just method invocation.
Why should we do method invocation with all it's overhead, if for the
normal case a plain function call we'll do it?
> For complex numbers and such, I'd want to be able to define classes for
> them in bytecode. For that to work, ops would eventually have to
> resolve to method calls anyway.
This is all working now already. You can do that. Again: if a method is
there it's used (or almost MMD not yet, vtables are fine):
.sub main @MAIN
.local pmc MyInt
getclass $P0, "Integer"
subclass MyInt, $P0, "MyInt"
.local pmc i, j, k
$I0 = find_type "MyInt"
# current hack - MMD overriding still missing
$P0 = find_global "MyInt", "__add"
.include "mmd.pasm"
mmdvtregister .MMD_ADD, $I0, $I0, $P0
# end hack
i = new $I0
j = new $I0
k = new $I0
j = 2
k = 3
i = j + k
print i
print "\n"
.end
.namespace [ "MyInt" ]
.sub __add
.param pmc l
.param pmc r
.param pmc d
$I0 = l
$I1 = r
$I2 = $I0 + $I1
$I2 = 42 # test
d = $I2
.end
> JEff
leo