HxOverrides.hx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package python.internal;
  2. import python.Syntax;
  3. import python.Syntax.pythonCode in py;
  4. @:keep
  5. @:native("HxOverrides")
  6. @:access(python.internal.ArrayImpl)
  7. class HxOverrides {
  8. // this two cases iterator and shift are like all methods in String and Array and are already handled in Reflect
  9. // we need to modify the transformer to call Reflect directly
  10. static public function iterator(x) {
  11. return Reflect.callMethod(null, Reflect.field(x, "iterator"), []);
  12. }
  13. static public function shift(x) {
  14. return Reflect.callMethod(null, Reflect.field(x, "shift"), []);
  15. }
  16. static public function toUpperCase(x) {
  17. return Reflect.callMethod(null, Reflect.field(x, "toUpperCase"), []);
  18. }
  19. static public function toLowerCase(x) {
  20. return Reflect.callMethod(null, Reflect.field(x, "toLowerCase"), []);
  21. }
  22. static public function rshift(val:Int, n:Int) {
  23. return Syntax.binop(Syntax.binop(val, "%", Syntax.pythonCode("0x100000000")), ">>", n);
  24. }
  25. static public function modf(a:Float, b:Float) {
  26. return Syntax.pythonCode("float('nan') if (b == 0.0) else a % b if a > 0 else -(-a % b)");
  27. }
  28. static public function arrayGet<T>(a:Dynamic, i:Int):Dynamic {
  29. if (Std.is(a, Array)) {
  30. return ArrayImpl.__get(a, i);
  31. } else {
  32. return Syntax.arrayAccess(a, i);
  33. }
  34. }
  35. static public function arraySet(a:Dynamic, i:Int, v:Dynamic) {
  36. if (Std.is(a, Array)) {
  37. return ArrayImpl.__set(a, i, v);
  38. } else {
  39. Syntax.assign(Syntax.arrayAccess(a, i), v);
  40. return v;
  41. }
  42. }
  43. }