thautwarm / Traffy.UnityPython

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

design of abstract classes for fast `__getitem__`, etc #10

Closed thautwarm closed 2 years ago

thautwarm commented 2 years ago

NOTE: those builtin classes will implement corresponding __init_subclass__.

Lookup, for __getitem__, __setitem__

  class Lookup[K, T]:
      @abstractmethod
      def __setitem__(self, index: K, value: T): ...

      @abstractmethod
      def lookup(self, index: K, valueref: ref[T]): ... 

      #this is not abstract!
      def __getitem__(self, index: K) -> T: ... 

Order for __lt__,__gt__, ...

class Eq[V]:
     @abstractmethod
     def __eq__(self, other: V) -> bool: ...

     # not abstract
     def __ne__(self, other: V) -> bool: ...

class Order[V]:
    @abstractmethod
     def __lt__(self, other: V) -> bool: ...

     # not abstract
     def __gt__(...)
     def __ge__(...)
lfkdsk commented 2 years ago

it seems like __getitem__ which is injected by PolyIC, this proposal will use a subclass to fast these magic methods ?

thautwarm commented 2 years ago

@lfkdsk __getitem__ is not using IC.