瀏覽代碼

changed IMap to an interface (fixed issue #1629)

Simon Krajewski 12 年之前
父節點
當前提交
d59a168704

+ 2 - 1
main.ml

@@ -53,7 +53,7 @@ let global_cache = ref None
 
 let executable_path() =
 	Extc.executable_path()
-	
+
 let is_debug_run() =
 	try Sys.getenv "HAXEDEBUG" = "1" with _ -> false
 
@@ -822,6 +822,7 @@ try
 		if com.platform <> Cross then failwith "Multiple targets";
 		Common.init_platform com pf;
 		com.file <- file;
+		message ctx ("Compiling to " ^ (platform_name pf)) Ast.null_pos;
 		if (pf = Flash8 || pf = Flash) && file_extension file = "swc" then Common.define com Define.Swc;
 	in
 	let define f = Arg.Unit (fun () -> Common.define com f) in

+ 7 - 7
std/Map.hx

@@ -131,9 +131,9 @@ abstract Map< K, V > (IMap< K, V > ) {
 		return new IntMap<V>();
 	}
 
-	@:to static inline function toHashMap<K:Hashable>(t:IMap < K, V >):HashMap<K,V> {
-		return new HashMap<K, V>();
-	}
+	//@:to static inline function toHashMap<K:Hashable>(t:IMap < K, V >):HashMap<K,V> {
+		//return new HashMap<K, V>();
+	//}
 	
 	@:to static inline function toObjectMap<K:{ }>(t:IMap < K, V >):ObjectMap<K,V> {
 		return new ObjectMap<K, V>();
@@ -147,16 +147,16 @@ abstract Map< K, V > (IMap< K, V > ) {
 		return map;
 	}
 	
-	@:from static inline function fromHashMap < K:Hashable, V > (map:HashMap< K, V > ):Map< K, V > {
-		return map;
-	}
+	//@:from static inline function fromHashMap < K:Hashable, V > (map:HashMap< K, V > ):Map< K, V > {
+		//return map;
+	//}
 	
 	@:from static inline function fromObjectMap < K: { }, V > (map:ObjectMap< K, V > ):Map< K, V > {
 		return map;
 	}
 }
 
-typedef IMap < K, V > = {
+interface IMap < K, V > {
 	public function get(k:K):Null<V>;
 	public function set(k:K, v:V):Void;
 	public function exists(k:K):Bool;

+ 1 - 1
std/cpp/_std/haxe/ds/IntMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class IntMap<T> {
+@:coreApi class IntMap<T> implements Map.IMap<Int,T> {
 
 	private var h : Dynamic;
 

+ 2 - 2
std/cpp/_std/haxe/ds/ObjectMap.hx

@@ -22,11 +22,11 @@
 package haxe.ds;
 
 @:coreApi
-class ObjectMap<K,V> {
+class ObjectMap<K,V> implements Map.IMap<K,V> {
    // TODO: Might need to add separate hash to keep track of references to keys
 	private var __Internal : IntMap<V>;
 
-	public function new(?weakKeys:Bool = false) : Void {
+	public function new() : Void {
 		__Internal = new IntMap<V>();
 	}
 

+ 1 - 1
std/cpp/_std/haxe/ds/StringMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class StringMap<T>  {
+@:coreApi class StringMap<T> implements Map.IMap<String,T> {
 	private var __Internal : Dynamic;
 
 	public function new() : Void {

+ 1 - 1
std/cs/_std/haxe/ds/IntMap.hx

@@ -33,7 +33,7 @@ import cs.NativeArray;
  * Thanks also to Jonas Malaco Filho for his Haxe-written IntMap code inspired by Python tables.
  * (https://jonasmalaco.com/fossil/test/jonas-haxe/artifact/887b53126e237d6c68951111d594033403889304)
  */
-@:coreApi class IntMap<T>
+@:coreApi class IntMap<T> implements Map.IMap<Int,T>
 {
 	private static inline var HASH_UPPER = 0.7;
 

+ 2 - 2
std/cs/_std/haxe/ds/ObjectMap.hx

@@ -23,7 +23,7 @@ package haxe.ds;
 
 import cs.NativeArray;
 
-@:coreApi class ObjectMap<K, V>
+@:coreApi class ObjectMap<K, V> implements Map.IMap<K,V>
 {
 	@:extern private static inline var HASH_UPPER = 0.77;
 	@:extern private static inline var FLAG_EMPTY = 0;
@@ -56,7 +56,7 @@ import cs.NativeArray;
 	private var maxProbe:Int;
 #end
 
-	public function new(?weakKeys:Bool) : Void
+	public function new() : Void
 	{
 		cachedIndex = -1;
 	}

+ 1 - 1
std/cs/_std/haxe/ds/StringMap.hx

@@ -23,7 +23,7 @@ package haxe.ds;
 
 import cs.NativeArray;
 
-@:coreApi class StringMap<T>
+@:coreApi class StringMap<T> implements Map.IMap<String,T>
 {
 	@:extern private static inline var HASH_UPPER = 0.77;
 	@:extern private static inline var FLAG_EMPTY = 0;

+ 1 - 1
std/flash/_std/haxe/ds/IntMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class IntMap<T> {
+@:coreApi class IntMap<T> implements Map.IMap<Int,T> {
 
 	private var h : flash.utils.Dictionary;
 

+ 5 - 1
std/flash/_std/haxe/ds/ObjectMap.hx

@@ -1,8 +1,12 @@
 package haxe.ds;
 
 @:coreApi
-class ObjectMap<K,V> extends flash.utils.Dictionary {
+class ObjectMap<K,V> extends flash.utils.Dictionary implements Map.IMap<K,V> {
 
+	public function new() {
+		super(false);
+	}
+	
 	public inline function get( key : K ) : Null<V> {
 		return untyped this[key];
 	}

+ 1 - 1
std/flash/_std/haxe/ds/StringMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class StringMap<T> {
+@:coreApi class StringMap<T> implements Map.IMap<String,T> {
 
 	private var h :flash.utils.Dictionary;
 

+ 1 - 1
std/flash8/_std/haxe/ds/IntMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class IntMap<T> {
+@:coreApi class IntMap<T> implements Map.IMap<Int,T>{
 
 	private var h : Dynamic;
 

+ 2 - 2
std/flash8/_std/haxe/ds/ObjectMap.hx

@@ -23,7 +23,7 @@
 package haxe.ds;
 
 @:coreApi
-class ObjectMap <K:{ }, V> {
+class ObjectMap <K:{ }, V> implements Map.IMap<K,V> {
 	
 	static var count = 0;
 	
@@ -37,7 +37,7 @@ class ObjectMap <K:{ }, V> {
 	
 	var h: { };
 	
-	public function new(?weakKeys:Bool = false):Void {
+	public function new():Void {
 		h = untyped __new__(_global["Object"]);
 		untyped h.__keys__ = untyped __new__(_global["Object"]);
 	}

+ 1 - 1
std/flash8/_std/haxe/ds/StringMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class StringMap<T> {
+@:coreApi class StringMap<T> implements Map.IMap<String,T> {
 
 	private var h : Dynamic;
 

+ 1 - 1
std/haxe/ds/IntMap.hx

@@ -25,7 +25,7 @@ package haxe.ds;
 	Hashtable over a set of elements, using [Int] as keys.
 	On Flash and Javascript, the underlying structure is an Object.
 **/
-extern class IntMap<T> {
+extern class IntMap<T> implements Map.IMap<Int,T> {
 
 	/**
 		Creates a new empty hashtable.

+ 2 - 2
std/haxe/ds/ObjectMap.hx

@@ -22,8 +22,8 @@
 
 package haxe.ds;
 
-extern class ObjectMap < K: { }, V > {
-	public function new(?weakKeys:Bool = false):Void;
+extern class ObjectMap < K: { }, V > implements Map.IMap<K,V> {
+	public function new():Void;
 	public function set(key:K, value:V):Void;
 	public function get(key:K):Null<V>;
 	public function exists(key:K):Bool;

+ 1 - 1
std/haxe/ds/StringMap.hx

@@ -27,7 +27,7 @@ package haxe.ds;
 	Other kind of keys are not possible on all platforms since they
 	can't always be implemented efficiently.
 **/
-extern class StringMap<T> {
+extern class StringMap<T> implements Map.IMap<String,T> {
 
 	/**
 		Creates a new empty hashtable.

+ 1 - 1
std/java/_std/haxe/ds/IntMap.hx

@@ -31,7 +31,7 @@ import java.NativeArray;
  * (https://jonasmalaco.com/fossil/test/jonas-haxe/artifact/887b53126e237d6c68951111d594033403889304)
  */
 
-@:coreApi class IntMap<T>
+@:coreApi class IntMap<T> implements Map.IMap<Int,T>
 {
 	private static inline var HASH_UPPER = 0.7;
 

+ 2 - 2
std/java/_std/haxe/ds/ObjectMap.hx

@@ -23,7 +23,7 @@ package haxe.ds;
 
 import java.NativeArray;
 
-@:coreApi class ObjectMap<K, V>
+@:coreApi class ObjectMap<K, V> implements Map.IMap<K,V>
 {
 	@:extern private static inline var HASH_UPPER = 0.77;
 	@:extern private static inline var FLAG_EMPTY = 0;
@@ -56,7 +56,7 @@ import java.NativeArray;
 	private var maxProbe:Int;
 #end
 
-	public function new(?weakKeys:Bool = false) : Void
+	public function new() : Void
 	{
 		cachedIndex = -1;
 	}

+ 1 - 1
std/java/_std/haxe/ds/StringMap.hx

@@ -23,7 +23,7 @@ package haxe.ds;
 
 import java.NativeArray;
 
-@:coreApi class StringMap<T>
+@:coreApi class StringMap<T> implements Map.IMap<String,T>
 {
 	@:extern private static inline var HASH_UPPER = 0.77;
 	@:extern private static inline var FLAG_EMPTY = 0;

+ 1 - 1
std/js/_std/haxe/ds/IntMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class IntMap<T> {
+@:coreApi class IntMap<T> implements Map.IMap<Int,T> {
 
 	private var h : Dynamic;
 

+ 2 - 2
std/js/_std/haxe/ds/ObjectMap.hx

@@ -23,7 +23,7 @@
 package haxe.ds;
 
 @:coreApi
-class ObjectMap<K:{ }, V> {
+class ObjectMap<K:{ }, V> implements Map.IMap<K,V> {
 	
 	static var count = 0;
 	
@@ -37,7 +37,7 @@ class ObjectMap<K:{ }, V> {
 	
 	var h : { };
 	
-	public inline function new(weakKeys:Bool = false):Void {
+	public function new() : Void {
 		h = { };
 		untyped h.__keys__ = { };
 	}

+ 1 - 1
std/js/_std/haxe/ds/StringMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class StringMap<T> {
+@:coreApi class StringMap<T> implements Map.IMap<String,T> {
 
 	private var h : Dynamic;
 

+ 1 - 1
std/neko/_std/haxe/ds/IntMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class IntMap<T> {
+@:coreApi class IntMap<T> implements Map.IMap<Int,T> {
 
 	private var h : Dynamic;
 

+ 2 - 2
std/neko/_std/haxe/ds/ObjectMap.hx

@@ -22,7 +22,7 @@
 package haxe.ds;
 
 @:coreApi
-class ObjectMap<K:{},V> {
+class ObjectMap<K:{},V> implements Map.IMap<K,V> {
 
 	static var count = 0;
 	
@@ -39,7 +39,7 @@ class ObjectMap<K:{},V> {
 	var h : { };
 	var k : { };
 	
-	public function new(weakKeys:Bool = false) : Void {
+	public function new() : Void {
 		h = untyped __dollar__hnew(0);
 		k = untyped __dollar__hnew(0);
 	}

+ 1 - 1
std/neko/_std/haxe/ds/StringMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class StringMap<T> {
+@:coreApi class StringMap<T> implements Map.IMap<String,T> {
 
 	private var h : Dynamic;
 

+ 1 - 1
std/php/_std/haxe/ds/IntMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class IntMap<T> implements php.IteratorAggregate<T> {
+@:coreApi class IntMap<T> implements php.IteratorAggregate<T> implements Map.IMap<Int,T> {
 	private var h : ArrayAccess<Int>;
 	public function new() : Void {
 		h = untyped __call__('array');

+ 2 - 2
std/php/_std/haxe/ds/ObjectMap.hx

@@ -23,7 +23,7 @@
 package haxe.ds;
 
 @:coreApi
-class ObjectMap <K:{ }, V> {
+class ObjectMap <K:{ }, V> implements Map.IMap<K,V> {
 	static function getId(key: { } ):String {
 		return untyped __php__("spl_object_hash($key)");
 	}
@@ -31,7 +31,7 @@ class ObjectMap <K:{ }, V> {
 	var h : ArrayAccess<V>;
 	var hk : ArrayAccess<K>;
 	
-	public function new(weakKeys:Bool = false):Void {
+	public function new():Void {
 		h = untyped __call__('array');
 		hk = untyped __call__('array');
 	}

+ 1 - 1
std/php/_std/haxe/ds/StringMap.hx

@@ -21,7 +21,7 @@
  */
 package haxe.ds;
 
-@:coreApi class StringMap<T> implements php.IteratorAggregate<T> {
+@:coreApi class StringMap<T> implements php.IteratorAggregate<T> implements Map.IMap<String,T> {
 	private var h : ArrayAccess<T>;
 
 	public function new() : Void {