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

renamed and moved PyIterator => NativeIterator, PyIterable => NativeIterable, the underlying typedefs are now suffixed with Raw

frabbit 11 жил өмнө
parent
commit
4a4f1455a6

+ 4 - 3
std/python/HaxeIterable.hx

@@ -1,12 +1,13 @@
 package python;
 
-import python.lib.Types;
+
+import python.NativeIterable.NativeIterableRaw;
 
 class HaxeIterable<T> {
 
-	var x : NativeIterable<T>;
+	var x : NativeIterableRaw<T>;
 
-	public inline function new (x:NativeIterable<T>) {
+	public inline function new (x:NativeIterableRaw<T>) {
 		this.x = x;
 	}
 

+ 3 - 3
std/python/HaxeIterator.hx

@@ -1,17 +1,17 @@
 package python;
 
 import python.lib.Exceptions.StopIteration;
-import python.lib.Types.NativeIterator;
+import python.NativeIterator;
 
 
 class HaxeIterator<T>
 {
-	var it :NativeIterator<T>;
+	var it :NativeIteratorRaw<T>;
 	var x:Null<T> = null;
 	var has = false;
 	var checked = false;
 
-	public function new (it:NativeIterator<T>) {
+	public function new (it:NativeIteratorRaw<T>) {
 		this.it = it;
 	}
 

+ 3 - 3
std/python/Lib.hx

@@ -21,12 +21,12 @@ class Lib {
 		PySys.stdout.flush();
 	}
 
-	public static function toPythonIterable <T>(it:Iterable<T>):python.lib.Types.NativeIterable<T> {
+	public static function toPythonIterable <T>(it:Iterable<T>):python.NativeIterable<T> {
 		return {
 			__iter__ : function () {
 				var it1 = it.iterator();
-				var self:PyIterator<T> = null;
-				self = new PyIterator({
+				var self:NativeIterator<T> = null;
+				self = new NativeIterator({
 					__next__ : function ():T {
 					if (it1.hasNext()) {
 						return it1.next();

+ 20 - 0
std/python/NativeIterable.hx

@@ -0,0 +1,20 @@
+
+package python;
+
+import python.HaxeIterable;
+import python.NativeIterator;
+
+abstract NativeIterable <T>(NativeIterableRaw<T>) to NativeIterableRaw<T> from NativeIterableRaw<T> {
+	@:to public static inline function toHaxeIterable <T>(p:NativeIterableRaw<T>):HaxeIterable<T> return new HaxeIterable(p);
+
+	//@:from public static inline function fromArray <T>(p:Array<T>):PyIterable<T> return cast p;
+
+	public inline function iterator <T>() return toHaxeIterable().iterator();
+
+	public function getNativeIterable <T>():NativeIterableRaw<T> return this;
+	public function getNativeIterator <T>():NativeIteratorRaw<T> return this.__iter__();
+
+}
+typedef NativeIterableRaw<T> = {
+	function __iter__():NativeIterator<T>;
+}

+ 19 - 0
std/python/NativeIterator.hx

@@ -0,0 +1,19 @@
+
+package python;
+
+import python.NativeIterable.NativeIterableRaw;
+
+abstract NativeIterator <T>(NativeIteratorRaw<T>) to NativeIteratorRaw<T> to NativeIterable<T> {
+	public inline function new (p:NativeIteratorRaw<T>) this = p;
+
+	@:to public static inline function toHaxeIterator <T>(p:NativeIteratorRaw<T>):HaxeIterator<T> return new HaxeIterator(p);
+	@:to public static inline function toNativeIterable <T>(p:NativeIteratorRaw<T>):NativeIterable<T> return p;
+
+	public function getNativeIteratorRaw <T>():NativeIteratorRaw<T> return this;
+}
+
+typedef NativeIteratorRaw<T> = {
+	> NativeIterableRaw<T>,
+	function __next__ ():T;
+	//function __iter__ ():NativeIterator<T>;
+}

+ 2 - 2
std/python/Syntax.hx

@@ -78,9 +78,9 @@ extern class Syntax {
 		}
 		var iter = try {
 			Context.typeof(macro $it.__iter__());
-			macro $it.__iter__().getNativeIterator();
+			macro $it.__iter__().getNativeIteratorRaw();
 		} catch (e:Dynamic) {
-			macro $it.getNativeIterator();
+			macro $it.getNativeIteratorRaw();
 		};
 
 

+ 2 - 2
std/python/_std/Array.hx

@@ -21,7 +21,7 @@
  */
 #if !macro
 import python.internal.ArrayImpl;
-import python.lib.Types.PyIterator;
+import python.NativeIterator;
 #end
 
 @:native("list")
@@ -137,5 +137,5 @@ extern class Array<T> implements ArrayAccess<T> extends ArrayImpl {
 		return ArrayImpl.__unsafe_set(this, idx,val);
 	}
 
-	@:noCompletion private function __iter__ ():PyIterator<T>;
+	@:noCompletion private function __iter__ ():NativeIterator<T>;
 }

+ 7 - 5
std/python/lib/Builtin.hx

@@ -5,6 +5,8 @@ package python.lib;
 import python.lib.io.IOBase;
 import python.lib.Types;
 import python.lib.Dict;
+import python.NativeIterable;
+import python.NativeIterator;
 
 
 
@@ -70,7 +72,7 @@ extern class Builtin {
 	//public static function super():Void;
 	//public static function bin():Void;
 	//public static function file():Void;
-	public static function iter<X>(d:DictView<X>):PyIterator<X>;
+	public static function iter<X>(d:DictView<X>):NativeIterator<X>;
 	//public static function property():Void;
 
 
@@ -85,7 +87,7 @@ extern class Builtin {
 
 	public static function type():Void;
 	@:overload(function (it:Array<Int>):python.lib.ByteArray {})
-	@:overload(function (it:PyIterable<Int>):python.lib.ByteArray {})
+	@:overload(function (it:NativeIterable<Int>):python.lib.ByteArray {})
 	@:overload(function (size:Int):python.lib.ByteArray {})
 	public static function bytearray(source:String,encoding:String,?errors:Dynamic):python.lib.ByteArray;
 	public static function float(x:Dynamic):Float;
@@ -93,9 +95,9 @@ extern class Builtin {
 	@:overload(function <T>(f:Array<T>):Array<T> {})
 	@:overload(function (f:String):Array<String> {})
 	@:overload(function <G>(f:Tuple<G>):Array<G> {})
-	public static function list<T>(i:PyIterable<T>):Array<T>;
+	public static function list<T>(i:NativeIterable<T>):Array<T>;
 
-	public static function filter<A>(f:A->Bool, i:Choice<Array<A>, PyIterable<A>>):PyIterator<A>;
+	public static function filter<A>(f:A->Bool, i:Choice<Array<A>, NativeIterable<A>>):NativeIterator<A>;
 	//public static function raw_input():Void;
 	//public static function unichr():Void;
 
@@ -110,7 +112,7 @@ extern class Builtin {
 	//public static function vars():Void;
 	//public static function classmethod():Void;
 
-	public static function map<A,B>(fn:A->B, it:PyIterable<A>):PyIterator<B>;
+	public static function map<A,B>(fn:A->B, it:NativeIterable<A>):NativeIterator<B>;
 	//public static function repr():Void;
 	//public static function xrange():Void;
 	//public static function cmp():Void;

+ 1 - 1
std/python/lib/Codecs.hx

@@ -5,7 +5,7 @@ import python.lib.io.IOBase;
 import python.lib.io.RawIOBase;
 import python.lib.io.TextIOBase;
 import python.lib.Bytes;
-import python.lib.Types.FileObject;
+import python.lib.FileObject;
 import python.lib.Tuple.Tup2;
 
 extern interface Codec {

+ 3 - 2
std/python/lib/Dict.hx

@@ -4,11 +4,12 @@ package python.lib;
 import python.lib.Builtin;
 import python.lib.Tuple;
 import python.lib.Types;
+import python.NativeIterator;
 import python.Syntax;
 
 
 extern class DictView<T> {
-	public inline function iter ():PyIterator<T>
+	public inline function iter ():NativeIterator<T>
 	{
 		return Builtin.iter(this);
 	}
@@ -62,7 +63,7 @@ extern class Dict <K, V>
 	{
 		return values().iter();
 	}
-	public function __iter__():PyIterator<K>;
+	public function __iter__():NativeIterator<K>;
 
 	static function __init__ ():Void
 	{

+ 6 - 0
std/python/lib/FileDescriptor.hx

@@ -0,0 +1,6 @@
+
+package python.lib;
+
+extern class FileDescriptor {
+
+}

+ 6 - 0
std/python/lib/FileObject.hx

@@ -0,0 +1,6 @@
+
+package python.lib;
+
+import python.lib.io.IOBase;
+
+typedef FileObject = IOBase;

+ 2 - 1
std/python/lib/Glob.hx

@@ -2,11 +2,12 @@
 package python.lib;
 
 import python.lib.Types;
+import python.NativeIterator;
 
 extern class Glob {
 
 	public static function glob (pathname:String):Array<String>;
-	public static function iglob (pathname:String):PyIterator<String>;
+	public static function iglob (pathname:String):NativeIterator<String>;
 
 
 

+ 2 - 2
std/python/lib/Re.hx

@@ -99,7 +99,7 @@ extern class Regex
 		return findallTuple(string, pos, endpos).map(function (t) return t.toArray());
 	}
 
-	public function finditer(string:String, ?pos:Int, ?endpos:Int):PyIterator<MatchObject>;
+	public function finditer(string:String, ?pos:Int, ?endpos:Int):NativeIterator<MatchObject>;
 
 	public function sub(repl:Repl, string:String, count:Int=0):String;
 	public function subn(repl:Repl, string:String, count:Int=0):String;
@@ -167,7 +167,7 @@ extern class Re
 		return findallTuple(pattern, string,flags).map(function (t) return t.toArray());
 	}
 
-	public static function finditer(pattern:Pattern, string:String,   flags:Int=0):PyIterator<MatchObject>;
+	public static function finditer(pattern:Pattern, string:String,   flags:Int=0):NativeIterator<MatchObject>;
 
 
 	@:overload(function (pattern:Pattern, repl:String, string:String,  ?count:Int=0, ?flags:Int=0):String {})

+ 5 - 4
std/python/lib/Set.hx

@@ -1,12 +1,13 @@
 
 package python.lib;
 
-import python.lib.Types.PyIterator;
+import python.NativeIterator;
+import python.NativeIterable;
 
 extern class Set <T>
 {
 	@:overload(function (?array:Array<T>):Void {})
-	public function new (?iterable:python.lib.Types.PyIterable<T>):Void;
+	public function new (?iterable:NativeIterable<T>):Void;
 
 	public inline function length ():Int
 	{
@@ -33,9 +34,9 @@ extern class Set <T>
 		Syntax.importFromAs("builtins", "set", "python.lib.Set");
 	}
 
-	function __iter__ ():PyIterator<T>;
+	function __iter__ ():NativeIterator<T>;
 
-	public inline function iterator ():Iterator<T>
+	public inline function iterator ():NativeIterator<T>
 	{
 		return __iter__();
 	}

+ 0 - 60
std/python/lib/Types.hx

@@ -10,51 +10,11 @@ abstract Choice <A,B>(Dynamic) {
 	@:from public static inline function fromB <A,B>(x:B):Choice<A,B> return cast x;
 }
 
-
-
-
-
-
-
-
-
 typedef Variant<A,B> = Dynamic;
 typedef Variant3<A,B,C> = Dynamic;
 typedef Variant4<A,B,C,D> = Dynamic;
 
-abstract PyIterator <T>(NativeIterator<T>) to NativeIterator<T> to PyIterable<T> {
-	public inline function new (p:NativeIterator<T>) this = p;
-	@:to public static inline function toHaxeIterator <T>(p:NativeIterator<T>):HaxeIterator<T> return new HaxeIterator(p);
-	@:to public static inline function toPyIterable <T>(p:NativeIterator<T>):PyIterable<T> return p;
-	public function getNativeIterator <T>():NativeIterator<T> return this;
-}
-
-abstract PyIterable <T>(NativeIterable<T>) to NativeIterable<T> from NativeIterable<T> {
-	@:to public static inline function toHaxeIterable <T>(p:NativeIterable<T>):HaxeIterable<T> return new HaxeIterable(p);
-
-	//@:from public static inline function fromArray <T>(p:Array<T>):PyIterable<T> return cast p;
-
-	public inline function iterator <T>() return IterHelper.iterableToIterator(this);
-	public function getNativeIterable <T>():NativeIterable<T> return this;
-	public function getNativeIterator <T>():NativeIterator<T> return this.__iter__();
 
-}
-
-class IterHelper {
-	public static inline function iterableToIterator <T>(it:PyIterable<T>):Iterator<T>
-	{
-		return it.toHaxeIterable().iterator();
-	}
-}
-
-typedef NativeIterator<T> = {
-	function __next__ ():T;
-	function __iter__ ():PyIterator<T>;
-}
-
-typedef NativeIterable<T> = {
-	function __iter__():PyIterator<T>;
-}
 
 
 
@@ -73,26 +33,6 @@ typedef NativeComparable = {
 	public function __cmp__(other:Dynamic):Int;
 }
 
-typedef FileObject = IOBase;
-
-extern class FileDescriptor {
-
-}
-
-
-//typedef DictKey<T> = {
-//	function __hash__():Int;
-//	function __eq__(other:Dynamic):Int;
-//	function __cmp__(other:Dynamic):Int;
-//}
-
-//@:native("set")
-
-
-
-
-
-
 
 
 extern class TB {}

+ 5 - 3
std/python/lib/xml/etree/ElementTree.hx

@@ -4,6 +4,8 @@ package python.lib.xml.etree;
 import python.lib.Tuple.Tup2;
 
 import python.lib.Types;
+import python.NativeIterable;
+import python.NativeIterator;
 
 extern class XMLParser {
 
@@ -24,8 +26,8 @@ extern class Element {
 	public function keys ():Array<String>;
 	public function items ():Array<Tup2<String, String>>;
 
-	public function iter (tag:String):PyIterable<Element>;
-	public function iterfind (tag:String, namespaces:Dict<String,String> = null):PyIterator<Element>;
+	public function iter (tag:String):NativeIterable<Element>;
+	public function iterfind (tag:String, namespaces:Dict<String,String> = null):NativeIterator<Element>;
 	public function find (match:String, namespaces:Dict<String,String> = null):Null<Element>;
 	public function findall (match:String, namespaces:Dict<String,String> = null):Array<Element>;
 
@@ -42,7 +44,7 @@ extern class ElementTree {
 	public static function XML(text:String, ?parser:XMLParser):Element;
 	public static function parse(xml:String):ElementTree;
 
-	public function iter (tag:String):PyIterable<Element>;
+	public function iter (tag:String):NativeIterable<Element>;
 	public function find (match:String, namespaces:Dict<String,String> = null):Null<Element>;
 	public function getroot ():Element;