ソースを参照

updated patch of Std.int to better support 32bit machines

Franco Ponticelli 12 年 前
コミット
13bddc6967
3 ファイル変更11 行追加6 行削除
  1. 0 4
      genphp.ml
  2. 5 2
      std/php/_std/Std.hx
  3. 6 0
      tests/unit/TestBasetypes.hx

+ 0 - 4
genphp.ml

@@ -580,10 +580,6 @@ and gen_call ctx e el =
 		spr ctx " === ";
 		gen_value ctx e2;
 		spr ctx ")"
-	| TLocal { v_name = "__int32__" },  [e1] ->
-		spr ctx "((";
-		gen_value ctx e1;
-		spr ctx " | 0) % 0x80000000)"
 	| TLocal _, []
 	| TFunction _, []
 	| TCall _, []

+ 5 - 2
std/php/_std/Std.hx

@@ -29,8 +29,11 @@
 		return untyped __call__("_hx_string_rec", s, '');
 	}
 
-	public inline static function int( x : Float ) : Int {
-		return untyped __int32__(x);
+	public static function int( x : Float ) : Int {
+		var i : Int = untyped __call__("fmod", x, 0x80000000) & 0xffffffff;
+		if (untyped i & 0x80000000)
+        	i = -((~i & 0xFFFFFFFF) + 1);
+        return i;
 	}
 
 	public static function parseInt( x : String ) : Null<Int> {

+ 6 - 0
tests/unit/TestBasetypes.hx

@@ -70,9 +70,15 @@ class TestBasetypes extends Test {
 		eq("hello" +null, "hellonull");
 		eq(null + "hello", "nullhello");
 		var x:Dynamic = null;
+		//String const + Dynamic var with null ref
 		eq("hello" +x, "hellonull");
 		eq(x + "hello", "nullhello");
+		var y:Dynamic = "hello";
+		//Dynamic var + Dynamic var, where one is null, the other is a string:
+		eq(x + y, "nullhello");
+		eq(y + x, "hellonull");
 		var x:String = null;
+		//String const + String var with null ref
 		eq("hello" +x, "hellonull");
 		eq(x + "hello", "nullhello");