thautwarm / Traffy.UnityPython

An efficient Python implementation in C#, running on every platform via Unity IL2CPP.
MIT License
44 stars 0 forks source link

PEP 0207 #9

Open thautwarm opened 2 years ago

thautwarm commented 2 years ago

https://www.python.org/dev/peps/pep-0207/

But still we want to skip tedious tasks when implementing the whole system.

Plan: learn from CPython impl: builtin classes use __cmp__, and __eq__, __lt__ stuffs are generated.

thautwarm commented 2 years ago

Enhancement: The follow code illustrates a most efficient interface for structural ordering. We can provide a builtin abstract class, which asks the user to provide __eq__ and one of __fast_le__(other: _T , x: ref[bool]) and __fast_le__(other: _T , x: ref[bool]), for fast structural ordering..

public interface IFastOrder<T>
{
    public bool __le__(T other, ref bool isEqual);
    public bool __ge__(T other, ref bool isEqual);
}
thautwarm commented 2 years ago

Done, but so far comparisons must return boolean or a type error is thrown. This is because in Unity broadcast comparisons are not widely used. Returning bool is faster.