It works with 2.08, but fails with current svn:
src/test/OverloadTestComplex.hx:23: characters 27-38 : Warning :
Overriding existing method +:
src/test/OverloadTestComplex.hx:32: characters 29-36 : Cannot add
deep.math.Complex and deep.math.Complex
I'm not sure what's going on there yet.
Simon
Please note however: Overloading assignment operators is a slippery
slope. Most importantly it will not work well on properties, i.e.:
class A {
public var float(default, set_float):Float;
public var point(default, set_point):Point;
}
class Point {
@op("++") static public inline function add(p:Point):Point {
p1.x += 1;
p1.y += 1;
return p1;
}
}
And now myA.float++ will call the accessor, while myA.point++ won't.
However, this can be circumvented by handling OpAssingOp(op)
differently, by examining the left hand side and acting accordingly.
Valid left hand expressions for assignment are EField, EType, EArray,
EConst(CIdent(id)) and EConst(CType(id)).
So what you basically do is this (+ stands for any operation here):
1. <owner>[<index>] += <value> becomes:
{
var owner = <owner>, index = <index>, value = <value>;
//declare variables to avoid duplicate evaluation, declare for *all*
subexpressions to avoid collision
owner[index] = owner[index] + value;
}
- owner.field += value becomes:
{
var owner = owner, value = value;
owner.field = owner.field + value;
}
- ident += y merely becomes ident = ident + y ... no magic here
And then feed the resulting expression into your normal
transformation. This should cover all cases by composing assignment
operations logically and thus would also work with properties. Also
one wouldn't have to define + and += separately ;)
Either way, great work so far! ;)
Regards,
Juraj
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en
hm, looks like macros api are changed or bug :)
If you need svn support I can test it and fix.
By the way Juraj, could tink's MemberTransformer be (ab)used to create
some sort of expression level preprocessor for this? I'm thinking
instead of using OverloadOperator.calc() with a block argument, have a
class implement IOperatorOverload<ComplexMath>, with IOperatorOverload
being an @:autoBuild that transforms all member function expressions to
support operator overloading.
Simon
That's exactly what MemberTransformer is for ;)
hm, looks like macros api are changed or bug :)If you need svn support I can test it and fix.
Valid left hand expressions for assignment are EField, EType, EArray,
EConst(CIdent(id)) and EConst(CType(id)).
Hi,
Please, this is an international list and as much as I'd like to understand and speak a lot of languages, I have to admit that I can only speak French and English fluently enough. So as I bet French is not really spoken by everybody, could you please switch back to English?
No offense here, this is with all due respect to everyone.
Regards,
If you discussed this in English, then we all could try to participate
and thus help you and learn from what you have to share ;)
Regards,
Juraj
Your English is fine, don't worry about it. It's definitely better than
our Russian! ;)
Simon