|
@@ -1,76 +1,90 @@
|
|
|
package python.internal;
|
|
|
|
|
|
+import python.Syntax;
|
|
|
+
|
|
|
+import python.Syntax.untypedPython in py;
|
|
|
+
|
|
|
@:keep
|
|
|
@:native("HxOverrides")
|
|
|
class HxOverrides {
|
|
|
static public function iterator(x) {
|
|
|
if (Std.is(x, Array)) {
|
|
|
- return untyped __python__(" _hx_c.python_internal_ArrayImpl.iterator(x)");
|
|
|
+ return Syntax.untypedPython(" _hx_c.python_internal_ArrayImpl.iterator(x)");
|
|
|
} else {
|
|
|
- return untyped __python__("x.iterator()");
|
|
|
+ return Syntax.untypedPython("x.iterator()");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static public function shift(x) {
|
|
|
if (Std.is(x, Array)) {
|
|
|
- return untyped __python__(" _hx_c.python_internal_ArrayImpl.shift(x)");
|
|
|
+ return Syntax.untypedPython(" _hx_c.python_internal_ArrayImpl.shift(x)");
|
|
|
} else {
|
|
|
- return untyped __python__("x.shift()");
|
|
|
+ return Syntax.untypedPython("x.shift()");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static public function filter(x, f) {
|
|
|
if (Std.is(x, Array)) {
|
|
|
- return untyped __python__(" _hx_c.python_internal_ArrayImpl.filter(x, f)");
|
|
|
+ return (x:Array<Dynamic>).filter(f);
|
|
|
} else {
|
|
|
- return untyped __python__("x.filter(f)");
|
|
|
+ return Syntax.untypedPython("x.filter(f)");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static public function map(x, f) {
|
|
|
if (Std.is(x, Array)) {
|
|
|
- return untyped __python__(" _hx_c.python_internal_ArrayImpl.map(x, f)");
|
|
|
+ return Syntax.untypedPython(" _hx_c.python_internal_ArrayImpl.map(x, f)");
|
|
|
} else {
|
|
|
- return untyped __python__("x.map(f)");
|
|
|
+ return Syntax.untypedPython("x.map(f)");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static public function length(x) {
|
|
|
- if (Std.is(x, Array) || Std.is(x, String)) {
|
|
|
- return untyped __python__(" _hx_builtin.len(x)");
|
|
|
- } else {
|
|
|
- return untyped __python__("x.length");
|
|
|
+ static public function length(x:Dynamic) {
|
|
|
+ return if (Std.is(x, Array))
|
|
|
+ {
|
|
|
+ (x:Array<Dynamic>).length;
|
|
|
+ }
|
|
|
+ else if (Std.is(x, String))
|
|
|
+ {
|
|
|
+ (x:String).length;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Reflect.field(x, "length");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static public function hx_rshift(val, n) {
|
|
|
- return untyped __python__("(val % 0x100000000) >> n");
|
|
|
+ return Syntax.binop(Syntax.binop(val, "%", Syntax.untypedPython("0x100000000")), ">>", n);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
static public function hx_modf(a, b) {
|
|
|
- return untyped __python__("float('nan') if (b == 0.0) else a % b if a > 0 else -(-a % b)");
|
|
|
+ return Syntax.untypedPython("float('nan') if (b == 0.0) else a % b if a > 0 else -(-a % b)");
|
|
|
}
|
|
|
|
|
|
- static public function hx_array_get(a, i) {
|
|
|
- return untyped __python__("a[i] if (i < len(a) and i > -1) else None");
|
|
|
+ static public function hx_array_get<T>(a:Array<T>, i:Int):T {
|
|
|
+ return if (i < a.length && i > -1) Syntax.arrayAccess(a, i) else null;
|
|
|
}
|
|
|
|
|
|
- static public function hx_array_set(a, i, v) {
|
|
|
- untyped __python__("
|
|
|
- l = len(a)
|
|
|
- while l < i:
|
|
|
- a.append(None)
|
|
|
- l+=1
|
|
|
- if l == i:
|
|
|
- a.append(v)
|
|
|
- else:
|
|
|
- a[i] = v
|
|
|
- return v");
|
|
|
+ static public function hx_array_set<X>(a:Array<X>, i:Int, v:X) {
|
|
|
+ var l = a.length;
|
|
|
+ while (l < i) {
|
|
|
+ a.push(null);
|
|
|
+ l+=1;
|
|
|
+ }
|
|
|
+ if (l == i) {
|
|
|
+ a.push(v);
|
|
|
+ } else {
|
|
|
+ Syntax.assign(Syntax.arrayAccess(a, i), v);
|
|
|
+ }
|
|
|
+ return v;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
static public function hx_toUpperCase(x) {
|
|
|
if (Std.is(x, String)) {
|
|
|
- return x.upper();
|
|
|
+ return (x:String).toUpperCase();
|
|
|
} else {
|
|
|
return x.toUpperCase();
|
|
|
}
|
|
@@ -78,7 +92,7 @@ class HxOverrides {
|
|
|
|
|
|
static public function hx_toLowerCase(x) {
|
|
|
if (Std.is(x, String)) {
|
|
|
- return x.lower();
|
|
|
+ return (x:String).toLowerCase();
|
|
|
} else {
|
|
|
return x.toLowerCase();
|
|
|
}
|