Pārlūkot izejas kodu

minor improvements

frabbit 11 gadi atpakaļ
vecāks
revīzija
fb1183b220

+ 1 - 1
genpy.ml

@@ -818,7 +818,7 @@ module Transformer = struct
 			let e = trans true [] e in
 			let r = { a_expr with eexpr = TField(e.a_expr, f) } in
 			lift_expr ~blocks:e.a_blocks r
-		| (is_value, TMeta(m,e)) ->
+		| (is_value, TMeta(m, e)) ->
 			let e = trans is_value [] e in
 			let r = { a_expr with eexpr = TMeta(m, e.a_expr); etype = e.a_expr.etype } in
 			lift_expr ~blocks:e.a_blocks r

+ 5 - 10
std/python/Syntax.hx

@@ -82,18 +82,13 @@ extern class Syntax {
 		} catch (e:Dynamic) {
 			macro $it.getNativeIterator();
 		};
-		var res = macro @:pos(it.pos) {
-			var $id = $iter.__next__();
-			$it;
-			$b;
-		}
-		try {
-			Context.typeof(res);
-		} catch (e:Dynamic) {
-			Context.error("cannot type the foreach expression", Context.currentPos());
-		}
+
+
 		return macro {
+			// the first 2 expressions are only used to create a typing context for the foreach construct
+			// TODO how can we get rid of them, so that they are not generated?
 			var $id = null;
+			if (false) $v = $iter.__next__();
 			$self._foreach($v, $it, $b);
 		}
 	}

+ 2 - 1
std/python/_std/haxe/ds/IntMap.hx

@@ -1,6 +1,7 @@
 package haxe.ds;
 
 import python.lib.Types.Dict;
+import python.Syntax;
 
 class IntMap<T> implements Map.IMap<Int, T> {
 	private var h : Dict<Int, T>;
@@ -24,7 +25,7 @@ class IntMap<T> implements Map.IMap<Int, T> {
 	public function remove( key : Int ) : Bool
 	{
 		if(!h.hasKey(key)) return false;
-		python.Syntax.pythonCode("del self.h[key]");
+		Syntax.delete(Syntax.arrayAccess(h, key));
 		return true;
 	}
 

+ 11 - 13
std/python/_std/haxe/ds/ObjectMap.hx

@@ -4,43 +4,41 @@ import python.lib.Builtin;
 import python.lib.Types;
 
 class ObjectMap<K:{},V> implements Map.IMap<K, V> {
-	
+
 	var h : Dict<K,V>;
-	
-	
+
+
 	public function new() : Void {
 		h = new Dict();
 	}
-	
+
 	public function set(key:K, value:V):Void {
 		h.set(key, value);
 	}
-	
+
 	public inline function get(key:K):Null<V> {
 		return h.get(key, null);
 	}
-	
+
 	public inline function exists(key:K):Bool {
 		return h.hasKey(key);
 	}
-	
-	public function remove( key : K ) : Bool 
+
+	public function remove( key : K ) : Bool
 	{
 		var r = h.hasKey(key);
-		
 		if (r) h.remove(key);
-		
 		return r;
 	}
-	
+
 	public function keys() : Iterator<K> {
 		return h.keys().iter();
 	}
-	
+
 	public function iterator() : Iterator<V> {
 		return h.values().iter();
 	}
-	
+
 	public function toString() : String {
 		var s = new StringBuf();
 		s.add("{");

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

@@ -1,12 +1,13 @@
 package haxe.ds;
 
 import python.lib.Types.Dict;
+import python.Syntax;
 
 class StringMap<T> implements Map.IMap<String, T> {
 	private var h : Dict<String,T>;
 
 	public function new() : Void {
-		h = python.Syntax.pythonCode("{}");
+		h = new Dict();
 	}
 
 	public inline function set( key : String, value : T ) : Void {
@@ -24,16 +25,15 @@ class StringMap<T> implements Map.IMap<String, T> {
 
 	public function remove( key : String ) : Bool {
 		var key = "$"+key;
-
-		if( !h.hasKey(key) ) return false;
-		python.Syntax.delete(python.Syntax.arrayAccess(h, key));
-		return true;
+		var has = h.hasKey(key);
+		if (has) h.remove(key);
+		return has;
 	}
 
 	public function keys() : Iterator<String> {
 		var a = [];
-		python.Syntax.foreach(key, h, {
-			a.push( python.Syntax.arrayAccessWithTrailingColon(key, 1) );
+		Syntax.foreach(key, h, {
+			a.push( key.substr(1));
 		});
 		return a.iterator();
 	}