Types.hx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package python.lib;
  2. import python.lib.Builtin;
  3. import python.lib.io.IOBase;
  4. abstract Choice <A,B>(Dynamic) {
  5. @:from public static inline function fromA <A,B>(x:A):Choice<A,B> return cast x;
  6. @:from public static inline function fromB <A,B>(x:B):Choice<A,B> return cast x;
  7. }
  8. typedef Variant<A,B> = Dynamic;
  9. typedef Variant3<A,B,C> = Dynamic;
  10. typedef Variant4<A,B,C,D> = Dynamic;
  11. abstract PyIterator <T>(NativeIterator<T>) to NativeIterator<T> to PyIterable<T> {
  12. public inline function new (p:NativeIterator<T>) this = p;
  13. @:to public static inline function toHaxeIterator <T>(p:NativeIterator<T>):HaxeIterator<T> return new HaxeIterator(p);
  14. @:to public static inline function toPyIterable <T>(p:NativeIterator<T>):PyIterable<T> return p;
  15. public function getNativeIterator <T>():NativeIterator<T> return this;
  16. }
  17. abstract PyIterable <T>(NativeIterable<T>) to NativeIterable<T> from NativeIterable<T> {
  18. @:to public static inline function toHaxeIterable <T>(p:NativeIterable<T>):HaxeIterable<T> return new HaxeIterable(p);
  19. //@:from public static inline function fromArray <T>(p:Array<T>):PyIterable<T> return cast p;
  20. public inline function iterator <T>() return IterHelper.iterableToIterator(this);
  21. public function getNativeIterable <T>():NativeIterable<T> return this;
  22. public function getNativeIterator <T>():NativeIterator<T> return this.__iter__();
  23. }
  24. class IterHelper {
  25. public static inline function iterableToIterator <T>(it:PyIterable<T>):Iterator<T>
  26. {
  27. return it.toHaxeIterable().iterator();
  28. }
  29. }
  30. typedef NativeIterator<T> = {
  31. function __next__ ():T;
  32. function __iter__ ():PyIterator<T>;
  33. }
  34. typedef NativeIterable<T> = {
  35. function __iter__():PyIterator<T>;
  36. }
  37. typedef NativeHashable = {
  38. public function __hash__():Int;
  39. }
  40. typedef NativeEqual = {
  41. public function __eq__(other:Dynamic):Int;
  42. }
  43. typedef NativeComparable = {
  44. public function __cmp__(other:Dynamic):Int;
  45. }
  46. typedef FileObject = IOBase;
  47. extern class FileDescriptor {
  48. }
  49. //typedef DictKey<T> = {
  50. // function __hash__():Int;
  51. // function __eq__(other:Dynamic):Int;
  52. // function __cmp__(other:Dynamic):Int;
  53. //}
  54. //@:native("set")
  55. extern class TB {}
  56. extern class Frame {}