2
0
Эх сурвалжийг харах

cleanup untyped, cleanup Math, add native Math class

frabbit 11 жил өмнө
parent
commit
5afef488ef

+ 12 - 13
std/python/_std/Math.hx

@@ -134,7 +134,7 @@ extern class Math
 		If `v` is NaN or infinite, the result is NaN.
 		If `v` is NaN or infinite, the result is NaN.
 	**/
 	**/
 	public static inline function sin(v:Float):Float {
 	public static inline function sin(v:Float):Float {
-		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else (Math:Dynamic).sin(v);
+		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else python.lib.Math.sin(v);
 	}
 	}
 
 
 	/**
 	/**
@@ -145,10 +145,10 @@ extern class Math
 		If `v` is NaN or infinite, the result is NaN.
 		If `v` is NaN or infinite, the result is NaN.
 	**/
 	**/
 	public static inline function cos(v:Float):Float {
 	public static inline function cos(v:Float):Float {
-		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else (Math:Dynamic).cos(v);
+		return if (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY) NaN else python.lib.Math.cos(v);
 	}
 	}
 
 
-	// TODO
+
 	static function tan(v:Float):Float;
 	static function tan(v:Float):Float;
 	static function asin(v:Float):Float;
 	static function asin(v:Float):Float;
 	static function acos(v:Float):Float;
 	static function acos(v:Float):Float;
@@ -191,7 +191,7 @@ extern class Math
 		holds.
 		holds.
 	**/
 	**/
 	public static inline function log(v:Float):Float {
 	public static inline function log(v:Float):Float {
-		return if (v == 0.0) NEGATIVE_INFINITY else if (v < 0.0) NaN else (Math:Dynamic).log(v);
+		return if (v == 0.0) NEGATIVE_INFINITY else if (v < 0.0) NaN else python.lib.Math.log(v);
 	}
 	}
 
 
 	// TODO
 	// TODO
@@ -210,7 +210,7 @@ extern class Math
 	**/
 	**/
 	public static inline function sqrt(v:Float):Float
 	public static inline function sqrt(v:Float):Float
 	{
 	{
-		return if (v < 0) NaN else (Math:Dynamic).sqrt(v);
+		return if (v < 0) NaN else python.lib.Math.sqrt(v);
 	}
 	}
 
 
 	/**
 	/**
@@ -295,17 +295,16 @@ extern class Math
 		NEGATIVE_INFINITY are not considered NaN.
 		NEGATIVE_INFINITY are not considered NaN.
 	**/
 	**/
 	static inline function isNaN( f : Float ) : Bool {
 	static inline function isNaN( f : Float ) : Bool {
-		return untyped _hx_math.isnan(f);
+
+		return python.lib.Math.isnan(f);
 	}
 	}
 
 
 	static function __init__():Void {
 	static function __init__():Void {
 		python.Syntax.importAs("math", "_hx_math");
 		python.Syntax.importAs("math", "_hx_math");
-		NEGATIVE_INFINITY = python.Syntax.pythonCode("float")('-inf');
-		POSITIVE_INFINITY = python.Syntax.pythonCode("float")('inf');
-		NaN = python.Syntax.pythonCode("float")('nan');
-		PI = python.Syntax.pythonCode("_hx_math.pi");
+		NEGATIVE_INFINITY = Builtin.float('-inf');
+		POSITIVE_INFINITY = Builtin.float('inf');
+		NaN = Builtin.float("nan");
+		PI = python.lib.Math.pi;
 	}
 	}
 
 
-}
-
-
+}

+ 11 - 11
std/python/_std/Xml.hx

@@ -164,7 +164,7 @@ enum XmlType {
 		var cur = 0;
 		var cur = 0;
 		var x = this._children;
 		var x = this._children;
 		return {
 		return {
-			
+
 			hasNext : function(){
 			hasNext : function(){
 				return cur < x.length;
 				return cur < x.length;
 			},
 			},
@@ -179,7 +179,7 @@ enum XmlType {
 		var cur = 0;
 		var cur = 0;
 		var x = this._children;
 		var x = this._children;
 		return {
 		return {
-			
+
 			hasNext : function() {
 			hasNext : function() {
 				var k = cur;
 				var k = cur;
 				var l = x.length;
 				var l = x.length;
@@ -212,7 +212,7 @@ enum XmlType {
 		var cur = 0;
 		var cur = 0;
 		var x = this._children;
 		var x = this._children;
 		return {
 		return {
-			
+
 			hasNext : function() {
 			hasNext : function() {
 				var k = cur;
 				var k = cur;
 				var l = x.length;
 				var l = x.length;
@@ -322,14 +322,14 @@ enum XmlType {
 		return s.toString();
 		return s.toString();
 	}
 	}
 
 
-	static function __init__() : Void untyped {
-		Xml.Element = "element";
-		Xml.PCData = "pcdata";
-		Xml.CData = "cdata";
-		Xml.Comment = "comment";
-		Xml.DocType = "doctype";
-		Xml.ProcessingInstruction = "processingInstruction";
-		Xml.Document = "document";
+	static function __init__() : Void {
+		Xml.Element = cast "element";
+		Xml.PCData = cast "pcdata";
+		Xml.CData = cast "cdata";
+		Xml.Comment = cast "comment";
+		Xml.DocType = cast "doctype";
+		Xml.ProcessingInstruction = cast "processingInstruction";
+		Xml.Document = cast "document";
 	}
 	}
 
 
 }
 }

+ 25 - 0
std/python/lib/Math.hx

@@ -0,0 +1,25 @@
+package python.lib;
+
+@:native("_hx_math")
+extern class Math {
+
+	public static function isnan (f:Float):Bool;
+
+	public static var pi:Float;
+
+	public static function sqrt(f:Float):Float;
+	public static function log(f:Float):Float;
+	public static function cos(f:Float):Float;
+	public static function sin(f:Float):Float;
+	public static function tan(f:Float):Float;
+	static function asin(v:Float):Float;
+	static function acos(v:Float):Float;
+	static function atan(v:Float):Float;
+	static function atan2(y:Float, x:Float):Float;
+
+	static function __init__():Void {
+		python.Syntax.importAs("math", "python.lib.Math");
+
+	}
+
+}

+ 9 - 3
std/python/lib/Re.hx

@@ -25,26 +25,32 @@ extern class MatchObject
 	public var string(default, null):String;
 	public var string(default, null):String;
 
 
 	public function expand(template:String):String;
 	public function expand(template:String):String;
+
+	@:overload(function (x:String):String {})
 	public function group(?i:Int = 0):String;
 	public function group(?i:Int = 0):String;
+
 	public function groups(defaultVal:String = null):Tuple<String>;
 	public function groups(defaultVal:String = null):Tuple<String>;
 	public function groupdict(defaultVal:Dict<String, String> = null):Dict<String, String>;
 	public function groupdict(defaultVal:Dict<String, String> = null):Dict<String, String>;
 
 
+	@:overload(function (x:String):Int {})
 	public function start (?i:Int = 0):Int;
 	public function start (?i:Int = 0):Int;
+
+	@:overload(function (x:String):Int {})
 	public function end (?i:Int = 0):Int;
 	public function end (?i:Int = 0):Int;
 
 
 	public function span (?i:Int):Tup2<Int, Int>;
 	public function span (?i:Int):Tup2<Int, Int>;
 
 
 
 
 	public inline function groupById(s:String):String {
 	public inline function groupById(s:String):String {
-		return group(untyped s);
+		return group(s);
 	}
 	}
 
 
 	public inline function startById(s:String):Int {
 	public inline function startById(s:String):Int {
-		return start(untyped s);
+		return start(s);
 	}
 	}
 
 
 	public inline function endById(s:String):Int {
 	public inline function endById(s:String):Int {
-		return end(untyped s);
+		return end(s);
 	}
 	}
 
 
 }
 }