소스 검색

untypedPython -> pythonCode

Simon Krajewski 11 년 전
부모
커밋
a8610fafea

+ 3 - 2
genpy.ml

@@ -128,7 +128,8 @@ module Transformer = struct
 
 	let create_non_local n pos =
 		let s = "nonlocal " ^ n in
-		let id = mk (TLocal (to_tvar "__python__" t_dynamic ) ) !t_void pos in
+		(* TODO: this is a hack... *)
+		let id = mk (TLocal (to_tvar "python_Syntax.pythonCode" t_dynamic ) ) !t_void pos in
 		let id2 = mk (TLocal( to_tvar s t_dynamic )) !t_void pos in
 		mk (TCall(id, [id2])) t_dynamic pos
 
@@ -1187,7 +1188,7 @@ module Printer = struct
 				""
 			| "__define_feature__",[_;e1] ->
 				print_expr pctx e1
-			| ("__python__" | "python_Syntax.untypedPython"),[e1] ->
+			| ("python_Syntax.pythonCode"),[e1] ->
 				begin match e1.eexpr with
 					| TConst (TString s) -> s
 					| e -> print_expr pctx e1

+ 2 - 2
std/StringTools.hx

@@ -51,7 +51,7 @@ class StringTools {
 		#elseif cs
 			return cs.system.Uri.EscapeUriString(s);
 		#elseif python
-			__python__("from urllib.parse import quote");
+			python.Syntax.pythonCode("from urllib.parse import quote");
 			return untyped quote(s);
 		#else
 			return null;
@@ -79,7 +79,7 @@ class StringTools {
 		#elseif cs
 			return cs.system.Uri.UnescapeDataString(s);
 		#elseif python
-			__python__("from urllib.parse import unquote");
+			python.Syntax.pythonCode("from urllib.parse import unquote");
 			return untyped unquote(s);
 		#else
 			return null;

+ 1 - 1
std/haxe/Int32.hx

@@ -193,7 +193,7 @@ abstract Int32(Int) from Int to Int {
 		return (x << extraBits) >> extraBits;
 		#elseif python
 		// thx to http://stackoverflow.com/questions/385572/need-help-typecasting-in-python#385583
-		return untyped (x + __python__("2**31")) % __python__("2**32 - 2**31");
+		return (x + python.Syntax.pythonCode("2**31")) % python.Syntax.pythonCode("2**32 - 2**31");
 		#else
 		return (x);
 		#end

+ 1 - 1
std/haxe/Int64.hx

@@ -62,7 +62,7 @@ class Int64 {
 		#elseif php
 			return i32php(i); // handle overflow of 32-bit integers correctly
 		#elseif python
-			return untyped (i + __python__("2**31")) % __python__("2**32 - 2**31");
+			return (i + python.Syntax.pythonCode("2**31")) % python.Syntax.pythonCode("2**32 - 2**31");
 		#else
 			return i;
 		#end

+ 1 - 1
std/haxe/io/Bytes.hx

@@ -88,7 +88,7 @@ class Bytes {
 		#elseif cs
 		cs.system.Array.Copy(src.b, srcpos, b, pos, len);
 		#elseif python
-		untyped __python__("self.b[pos:pos+len] = src.b[srcpos:srcpos+len]");
+		python.Syntax.pythonCode("self.b[pos:pos+len] = src.b[srcpos:srcpos+len]");
 		#else
 		var b1 = b;
 		var b2 = src.b;

+ 6 - 6
std/python/Boot.hx

@@ -41,9 +41,9 @@ import math as _hx_math
 
 	@:keep static function __init__ () {
 		Syntax.importAs("inspect", "_hx_boot_inspect");
-		Boot.inspect = Syntax.untypedPython("_hx_boot_inspect");
+		Boot.inspect = Syntax.pythonCode("_hx_boot_inspect");
 
-		Boot.builtin = Syntax.untypedPython("_hx_builtin");
+		Boot.builtin = Syntax.pythonCode("_hx_builtin");
 	}
 
 	static function mkSet <T>(a:Array<T>):Set<T> return Syntax.callField(builtin, "set", a);
@@ -321,16 +321,16 @@ import math as _hx_math
 				var keys  = d.keys();
 				var handler = unhandleKeywords;
 
-				Syntax.untypedPython("for k in keys:");
-				Syntax.untypedPython("	a.append(handler(k))");
+				Syntax.pythonCode("for k in keys:");
+				Syntax.pythonCode("	a.append(handler(k))");
 			}
 			else if (builtinHasAttr(o, "__dict__"))
 			{
 				var a = [];
 				var d:Dynamic = Syntax.field(o, "__dict__");
 				var keys  = d.keys();
-				Syntax.untypedPython("for k in keys:");
-				Syntax.untypedPython("	a.append(k)");
+				Syntax.pythonCode("for k in keys:");
+				Syntax.pythonCode("	a.append(k)");
 
 			}
 		}

+ 6 - 6
std/python/Syntax.hx

@@ -17,7 +17,7 @@ extern class Syntax {
 	#end
 
 	@:noUsing macro public static function importModule (module:String):haxe.macro.Expr {
-		return macro ($self.untypedPython($v{"import " + module}):Void);
+		return macro ($self.pythonCode($v{"import " + module}):Void);
 	}
 
 	@:noUsing macro public static function importAs (module:String, className : String):haxe.macro.Expr
@@ -27,8 +27,8 @@ extern class Syntax {
 		var e1 = "_hx_c."+n+" = "+n;
 
 		return macro ({
-			$self.untypedPython($v{e});
-			$self.untypedPython($v{e1});
+			$self.pythonCode($v{e});
+			$self.pythonCode($v{e1});
 		}:Void);
 	}
 
@@ -52,7 +52,7 @@ extern class Syntax {
 	public static function assign(a:Dynamic, b:Dynamic):Void { }
 
 	@:noUsing
-	public static function untypedPython<T>(b:String):T { return null; };
+	public static function pythonCode<T>(b:String):T { return null; };
 
 	@:noUsing
 	macro public static function arrayAccess(x:Expr, rest:Array<Expr>):ExprOf<Dynamic> {
@@ -90,8 +90,8 @@ extern class Syntax {
 		var e = "from " + from + " import " + module + " as " + n;
 		var e1 = "_hx_c."+n+" = " + n;
 		return macro ({
-			$self.untypedPython($v{e});
-			$self.untypedPython($v{e1});
+			$self.pythonCode($v{e});
+			$self.pythonCode($v{e1});
 		}:Void);
 	}
 

+ 5 - 5
std/python/_std/Math.hx

@@ -298,12 +298,12 @@ extern class Math
 		return untyped _hx_math.isnan(f);
 	}
 
-	static function __init__():Void untyped {
+	static function __init__():Void {
 		python.Syntax.importAs("math", "_hx_math");
-		NEGATIVE_INFINITY = __python__("float")('-inf');
-		POSITIVE_INFINITY = __python__("float")('inf');
-		NaN = __python__("float")('nan');
-		PI = untyped __python__("_hx_math.pi");
+		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");
 	}
 
 }

+ 4 - 4
std/python/_std/Reflect.hx

@@ -116,8 +116,8 @@ class Reflect {
 				var d:Dict<String, Dynamic> = Builtin.getattr(o, "__dict__");
 				var keys  = d.keys();
 				var handler = unhandleKeywords;
-				Syntax.untypedPython("for k in keys:");
-				Syntax.untypedPython("	a.append(handler(k))");
+				Syntax.pythonCode("for k in keys:");
+				Syntax.pythonCode("	a.append(handler(k))");
 
 			}
 			else if (Builtin.hasattr(o, "__dict__"))
@@ -125,8 +125,8 @@ class Reflect {
 				var a = [];
 				var d:Dict<String, Dynamic> = Syntax.field(o, "__dict__");
 				var keys = Syntax.callField(d, "keys");
-				Syntax.untypedPython("for k in keys:");
-				Syntax.untypedPython("	a.append(k)");
+				Syntax.pythonCode("for k in keys:");
+				Syntax.pythonCode("	a.append(k)");
 
 			}
 		}

+ 12 - 12
std/python/_std/Std.hx

@@ -47,28 +47,28 @@ import python.Boot;
 
 			return false;
 		}
-		if (t == (untyped __python__("Dynamic"))) {
+		if (t == (python.Syntax.pythonCode("Dynamic"))) {
 			return true;
 		}
-		var isBool = Builtin.isinstance(v, (untyped __python__("bool")));
+		var isBool = Builtin.isinstance(v, (python.Syntax.pythonCode("bool")));
 
-		if (t == (untyped __python__("Bool")) && isBool) {
+		if (t == (python.Syntax.pythonCode("Bool")) && isBool) {
 			return true;
 		}
-		if (!isBool && t != (untyped __python__("Bool")) && t ==  (untyped __python__("Int")) && Builtin.isinstance(v, (untyped __python__("int")) )) {
+		if (!isBool && t != (python.Syntax.pythonCode("Bool")) && t ==  (python.Syntax.pythonCode("Int")) && Builtin.isinstance(v, (python.Syntax.pythonCode("int")) )) {
 			return true;
 		}
-		var vIsFloat = Builtin.isinstance(v, (untyped __python__("float")));
+		var vIsFloat = Builtin.isinstance(v, (python.Syntax.pythonCode("float")));
 
-		if (!isBool && vIsFloat && t == (untyped __python__("Int")) && Math.isFinite(v) && v == Std.int(v)) {
+		if (!isBool && vIsFloat && t == (python.Syntax.pythonCode("Int")) && Math.isFinite(v) && v == Std.int(v)) {
 			return true;
 		}
 
-		if (!isBool &&  t == (untyped __python__("Float")) && ( Builtin.isinstance(v, (untyped __python__("(float,int)"))))) {
+		if (!isBool &&  t == (python.Syntax.pythonCode("Float")) && ( Builtin.isinstance(v, (python.Syntax.pythonCode("(float,int)"))))) {
 			return true;
 		}
 
-		if ( t == (untyped __python__("str"))) {
+		if ( t == (python.Syntax.pythonCode("str"))) {
 			return Builtin.isinstance(v, String);
 		}
 		if (t == Enum && Inspect.isclass(v) && Builtin.hasattr(v, "_hx_constructs")) return true;
@@ -127,7 +127,7 @@ import python.Boot;
 	public static inline function int( x : Float ) : Int
 	{
 		try {
-			return (untyped __python__("int"))(x);
+			return (python.Syntax.pythonCode("int"))(x);
 		} catch (e:Dynamic) {
 			return null;
 		}
@@ -136,13 +136,13 @@ import python.Boot;
 	public static function parseInt( x : String ) : Null<Int> {
 		if (x == null) return null;
 		try {
-			return (untyped __python__("int"))(x);
+			return (python.Syntax.pythonCode("int"))(x);
 		} catch (e:Dynamic) {
 			try {
 				var prefix = x.substr(0,2).toLowerCase();
 
 				if (prefix == "0x") {
-					return (untyped __python__("int"))(x,16);
+					return (python.Syntax.pythonCode("int"))(x,16);
 				}
 				throw "fail";
 			} catch (e:Dynamic) {
@@ -189,7 +189,7 @@ import python.Boot;
 	public static function parseFloat( x : String ) : Float
 	{
 		try {
-			return untyped __python__("float")(x);
+			return python.Syntax.pythonCode("float")(x);
 		} catch (e:Dynamic) {
 
 			if (x != null) {

+ 7 - 7
std/python/_std/haxe/ds/IntMap.hx

@@ -21,19 +21,19 @@ class IntMap<T> implements Map.IMap<Int, T> {
 		return h.hasKey(key);
 	}
 
-	public function remove( key : Int ) : Bool 
+	public function remove( key : Int ) : Bool
 	{
 		if(!h.hasKey(key)) return false;
-		untyped __python__("del self.h[key]");
+		python.Syntax.pythonCode("del self.h[key]");
 		return true;
 	}
 
 	public function keys() : Iterator<Int> {
 		var a = [];
-		
-		untyped __python__("for key in self.h:");
-		untyped __python__("	a.append(key)");
-		
+
+		python.Syntax.pythonCode("for key in self.h:");
+		python.Syntax.pythonCode("	a.append(key)");
+
 		return a.iterator();
 	}
 
@@ -45,7 +45,7 @@ class IntMap<T> implements Map.IMap<Int, T> {
 			next : function() { var i = iter.next(); return ref.get(i, null); }
 		};
 	}
-	
+
 	public function toString() : String {
 		var s = new StringBuf();
 		s.add("{");

+ 4 - 4
std/python/_std/haxe/ds/StringMap.hx

@@ -6,7 +6,7 @@ class StringMap<T> implements Map.IMap<String, T> {
 	private var h : Dict<String,T>;
 
 	public function new() : Void {
-		h = untyped __python__("{}");
+		h = python.Syntax.pythonCode("{}");
 	}
 
 	public function set( key : String, value : T ) : Void {
@@ -26,7 +26,7 @@ class StringMap<T> implements Map.IMap<String, T> {
 		key = "$"+key;
 
 		if( !h.hasKey(key) ) return false;
-		untyped __python__("del self.h[key]");
+		python.Syntax.pythonCode("del self.h[key]");
 		return true;
 	}
 
@@ -34,8 +34,8 @@ class StringMap<T> implements Map.IMap<String, T> {
 
 		var a = [];
 
-		untyped __python__("for key in self.h:");
-		untyped __python__("	a.append(key[1:])");
+		python.Syntax.pythonCode("for key in self.h:");
+		python.Syntax.pythonCode("	a.append(key[1:])");
 
 		return a.iterator();
 	}

+ 1 - 1
std/python/internal/ArrayImpl.hx

@@ -31,7 +31,7 @@ private abstract Builtin(Dynamic) {}
 @:keep
 class ArrayImpl {
 
-	static inline function builtin():Builtin return Syntax.untypedPython("_hx_builtin");
+	static inline function builtin():Builtin return Syntax.pythonCode("_hx_builtin");
 
 	public static inline function get_length <T>(x:Array<T>):Int return Syntax.callField(builtin(), "len", x);
 

+ 3 - 3
std/python/internal/HxOverrides.hx

@@ -2,7 +2,7 @@ package python.internal;
 
 import python.Syntax;
 
-import python.Syntax.untypedPython in py;
+import python.Syntax.pythonCode in py;
 
 @:keep
 @:native("HxOverrides")
@@ -28,11 +28,11 @@ class HxOverrides {
 	}
 
 	static public function rshift(val:Int, n:Int) {
-		return Syntax.binop(Syntax.binop(val, "%", Syntax.untypedPython("0x100000000")), ">>", n);
+		return Syntax.binop(Syntax.binop(val, "%", Syntax.pythonCode("0x100000000")), ">>", n);
 	}
 
 	static public function modf(a:Float, b:Float) {
-		return Syntax.untypedPython("float('nan') if (b == 0.0) else a % b if a > 0 else -(-a % b)");
+		return Syntax.pythonCode("float('nan') if (b == 0.0) else a % b if a > 0 else -(-a % b)");
 	}
 
 	static public function arrayGet<T>(a:Dynamic, i:Int):Dynamic {

+ 1 - 1
std/python/internal/StringImpl.hx

@@ -7,7 +7,7 @@ class StringImpl {
 
 
 
-	static inline function builtin ():Dynamic return Syntax.untypedPython("_hx_builtin");
+	static inline function builtin ():Dynamic return Syntax.pythonCode("_hx_builtin");
 
 
 	public static function split (s:String, d:String) {

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

@@ -139,11 +139,11 @@ extern class Set <T>
 
 	public inline function minus (other:Set<T>):Set<T>
 	{
-		return untyped __python_binop__(this, "-", other);
+		return python.Syntax.binop(this, "-", other);
 	}
 	public inline function plus (other:Set<T>):Set<T>
 	{
-		return untyped __python_binop__(this, "+", other);
+		return python.Syntax.binop(this, "+", other);
 	}
 
 	static function __init__ ():Void