|
@@ -26,9 +26,10 @@ import python.internal.Internal;
|
|
|
import python.lib.Builtin;
|
|
|
import python.lib.Inspect;
|
|
|
import python.Boot;
|
|
|
+import python.Syntax;
|
|
|
|
|
|
@:keepInit
|
|
|
-@:coreApi /*extern*/ class Std {
|
|
|
+@:coreApi class Std {
|
|
|
|
|
|
public static inline function instance<T:{}, S:T>( value : T, c : Class<S> ) : S {
|
|
|
try {
|
|
@@ -36,9 +37,8 @@ import python.Boot;
|
|
|
} catch (e:Dynamic) {
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
public static function is( v : Dynamic, t : Dynamic ) : Bool {
|
|
|
|
|
|
if (v == null && t == null) {
|
|
@@ -48,28 +48,28 @@ import python.Boot;
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
- if (t == (python.Syntax.pythonCode("Dynamic"))) {
|
|
|
+ if (t == Dynamic) {
|
|
|
return true;
|
|
|
}
|
|
|
- var isBool = Builtin.isinstance(v, (python.Syntax.pythonCode("bool")));
|
|
|
+ var isBool = Builtin.isinstance(v, Builtin.bool);
|
|
|
|
|
|
- if (t == (python.Syntax.pythonCode("Bool")) && isBool) {
|
|
|
+ if (t == Bool && isBool) {
|
|
|
return true;
|
|
|
}
|
|
|
- if (!isBool && t != (python.Syntax.pythonCode("Bool")) && t == (python.Syntax.pythonCode("Int")) && Builtin.isinstance(v, (python.Syntax.pythonCode("int")) )) {
|
|
|
+ if (!isBool && t != Bool && t == Int && Builtin.isinstance(v, Builtin.int )) {
|
|
|
return true;
|
|
|
}
|
|
|
- var vIsFloat = Builtin.isinstance(v, (python.Syntax.pythonCode("float")));
|
|
|
+ var vIsFloat = Builtin.isinstance(v, Builtin.float);
|
|
|
|
|
|
- if (!isBool && vIsFloat && t == (python.Syntax.pythonCode("Int")) && Math.isFinite(v) && v == Std.int(v)) {
|
|
|
+ if (!isBool && vIsFloat && t == Int && Math.isFinite(v) && v == Std.int(v)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- if (!isBool && t == (python.Syntax.pythonCode("Float")) && ( Builtin.isinstance(v, (python.Syntax.pythonCode("(float,int)"))))) {
|
|
|
+ if (!isBool && t == Float && ( Builtin.isinstance(v, python.Syntax.pythonCode("(float,int)")))) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- if ( t == (python.Syntax.pythonCode("str"))) {
|
|
|
+ if ( t == Builtin.str) {
|
|
|
return Builtin.isinstance(v, String);
|
|
|
}
|
|
|
if (t == Enum && Inspect.isclass(v) && Internal.hasConstructs(v)) return true;
|
|
@@ -82,9 +82,9 @@ import python.Boot;
|
|
|
|
|
|
if (Builtin.isinstance(v, Date)) return false;
|
|
|
|
|
|
- if (t == Class && !Builtin.isinstance(v, untyped Enum) && Inspect.isclass(v) && Internal.hasClassName(v) && !Internal.hasConstructs(v)) return true;
|
|
|
+ if (t == Class && !Builtin.isinstance(v, Enum) && Inspect.isclass(v) && Internal.hasClassName(v) && !Internal.hasConstructs(v)) return true;
|
|
|
|
|
|
- if (t == Class) return false; // && !Builtin.isinstance(v, untyped Enum) && Builtin.hasattr(v, "__class__") && untyped Builtin.hasattr(v.__class__, "_hx_class_name") && !untyped Builtin.hasattr(v.__class__, "_hx_constructs")) return true;
|
|
|
+ if (t == Class) return false;
|
|
|
|
|
|
if (try Builtin.isinstance(v, t) catch (e:Dynamic) false) {
|
|
|
return true;
|
|
@@ -110,7 +110,7 @@ import python.Boot;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- return loop(untyped v.__class__);
|
|
|
+ return loop(Syntax.field(v, "__class__"));
|
|
|
|
|
|
|
|
|
} else {
|
|
@@ -128,7 +128,7 @@ import python.Boot;
|
|
|
public static inline function int( x : Float ) : Int
|
|
|
{
|
|
|
try {
|
|
|
- return (python.Syntax.pythonCode("int"))(x);
|
|
|
+ return Builtin.int(x);
|
|
|
} catch (e:Dynamic) {
|
|
|
return null;
|
|
|
}
|
|
@@ -137,18 +137,17 @@ import python.Boot;
|
|
|
public static function parseInt( x : String ) : Null<Int> {
|
|
|
if (x == null) return null;
|
|
|
try {
|
|
|
- return (python.Syntax.pythonCode("int"))(x);
|
|
|
+ return Builtin.int(x);
|
|
|
} catch (e:Dynamic) {
|
|
|
try {
|
|
|
var prefix = x.substr(0,2).toLowerCase();
|
|
|
|
|
|
if (prefix == "0x") {
|
|
|
- return (python.Syntax.pythonCode("int"))(x,16);
|
|
|
+ return Builtin.int(x,16);
|
|
|
}
|
|
|
throw "fail";
|
|
|
} catch (e:Dynamic) {
|
|
|
|
|
|
-
|
|
|
var r = int(parseFloat(x));
|
|
|
|
|
|
if (r == null) {
|
|
@@ -190,7 +189,7 @@ import python.Boot;
|
|
|
public static function parseFloat( x : String ) : Float
|
|
|
{
|
|
|
try {
|
|
|
- return python.Syntax.pythonCode("float")(x);
|
|
|
+ return Builtin.float(x);
|
|
|
} catch (e:Dynamic) {
|
|
|
|
|
|
if (x != null) {
|
|
@@ -200,20 +199,14 @@ import python.Boot;
|
|
|
}
|
|
|
}
|
|
|
return Math.NaN;
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public static inline function random( x : Int ) : Int {
|
|
|
if (x <= 0) {
|
|
|
return 0;
|
|
|
} else {
|
|
|
return int(Math.random()*x);
|
|
|
}
|
|
|
-
|
|
|
- //return dart.Lib.random(x);
|
|
|
-// return untyped __cascade__(new dartt.math.Random(), nextInt(x));// //untyped x <= 0 ? 0 : Math.floor(Math.random()*x); import 'dart:marth'; new Random()..nextInt(x);
|
|
|
}
|
|
|
}
|