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

no longer makes difference between Int and Int32 if -D haxe3

Nicolas Cannasse 13 жил өмнө
parent
commit
baa92415f8

+ 11 - 0
std/haxe/io/BytesInput.hx

@@ -146,6 +146,14 @@ class BytesInput extends Input {
 		return try b.readUnsignedShort() catch( e : Dynamic ) throw new Eof();
 		return try b.readUnsignedShort() catch( e : Dynamic ) throw new Eof();
 	}
 	}
 
 
+	#if haxe3
+
+	override function readInt32() : Int {
+		return try b.readInt() catch( e : Dynamic ) throw new Eof();
+	}
+
+	#else
+
 	override function readInt31() {
 	override function readInt31() {
 		var n;
 		var n;
 		try n = b.readInt() catch( e : Dynamic ) throw new Eof();
 		try n = b.readInt() catch( e : Dynamic ) throw new Eof();
@@ -160,10 +168,13 @@ class BytesInput extends Input {
 		return n;
 		return n;
 	}
 	}
 
 
+
 	override function readInt32() : haxe.Int32 {
 	override function readInt32() : haxe.Int32 {
 		return try cast b.readInt() catch( e : Dynamic ) throw new Eof();
 		return try cast b.readInt() catch( e : Dynamic ) throw new Eof();
 	}
 	}
 
 
+	#end
+
 	override function readString( len : Int ) {
 	override function readString( len : Int ) {
 		return try b.readUTFBytes(len) catch( e : Dynamic ) throw new Eof();
 		return try b.readUTFBytes(len) catch( e : Dynamic ) throw new Eof();
 	}
 	}

+ 10 - 0
std/haxe/io/BytesOutput.hx

@@ -92,6 +92,14 @@ class BytesOutput extends Output {
 		b.writeShort(x);
 		b.writeShort(x);
 	}
 	}
 
 
+	#if haxe3
+
+	override function writeInt32( x : Int ) {
+		b.writeInt(x);
+	}
+
+	#else
+
 	override function writeInt31( x : Int ) {
 	override function writeInt31( x : Int ) {
 		#if !neko
 		#if !neko
 		if( x < -0x40000000 || x >= 0x40000000 ) throw Error.Overflow;
 		if( x < -0x40000000 || x >= 0x40000000 ) throw Error.Overflow;
@@ -108,6 +116,8 @@ class BytesOutput extends Output {
 		b.writeInt(cast x);
 		b.writeInt(cast x);
 	}
 	}
 
 
+	#end
+
 	override function prepare( size : Int ) {
 	override function prepare( size : Int ) {
 		if( size > 0 )
 		if( size > 0 )
 	#if cpp
 	#if cpp

+ 27 - 13
std/haxe/io/Input.hx

@@ -84,7 +84,7 @@ class Input {
 		#else
 		#else
 			bufsize = (1 << 14); // 16 Ko
 			bufsize = (1 << 14); // 16 Ko
 		#end
 		#end
-		
+
 		var buf = Bytes.alloc(bufsize);
 		var buf = Bytes.alloc(bufsize);
 		var total = new haxe.io.BytesBuffer();
 		var total = new haxe.io.BytesBuffer();
 		try {
 		try {
@@ -154,7 +154,7 @@ class Input {
 			return a[1];
 			return a[1];
 		#elseif cs
 		#elseif cs
 			if (helper == null) helper = new cs.NativeArray(8);
 			if (helper == null) helper = new cs.NativeArray(8);
-			
+
 			var helper = helper;
 			var helper = helper;
 			if (bigEndian == !cs.system.BitConverter.IsLittleEndian)
 			if (bigEndian == !cs.system.BitConverter.IsLittleEndian)
 			{
 			{
@@ -168,18 +168,18 @@ class Input {
 				helper[1] = readByte();
 				helper[1] = readByte();
 				helper[0] = readByte();
 				helper[0] = readByte();
 			}
 			}
-			
+
 			return cs.system.BitConverter.ToSingle(helper, 0);
 			return cs.system.BitConverter.ToSingle(helper, 0);
 		#elseif java
 		#elseif java
 			if (helper == null) helper = java.nio.ByteBuffer.allocateDirect(8);
 			if (helper == null) helper = java.nio.ByteBuffer.allocateDirect(8);
 			var helper = helper;
 			var helper = helper;
 			helper.order(bigEndian ? java.nio.ByteOrder.BIG_ENDIAN : java.nio.ByteOrder.LITTLE_ENDIAN);
 			helper.order(bigEndian ? java.nio.ByteOrder.BIG_ENDIAN : java.nio.ByteOrder.LITTLE_ENDIAN);
-			
+
 			helper.put(0, readByte());
 			helper.put(0, readByte());
 			helper.put(1, readByte());
 			helper.put(1, readByte());
 			helper.put(2, readByte());
 			helper.put(2, readByte());
 			helper.put(3, readByte());
 			helper.put(3, readByte());
-			
+
 			return helper.getFloat(0);
 			return helper.getFloat(0);
 		#else
 		#else
 			var bytes = [];
 			var bytes = [];
@@ -218,7 +218,7 @@ class Input {
 		bytes.push(readByte());
 		bytes.push(readByte());
 		if (bigEndian)
 		if (bigEndian)
 			bytes.reverse();
 			bytes.reverse();
-			
+
 		var sign = 1 - ((bytes[0] >> 7) << 1); // sign = bit 0
 		var sign = 1 - ((bytes[0] >> 7) << 1); // sign = bit 0
 		var exp = (((bytes[0] << 4) & 0x7FF) | (bytes[1] >> 4)) - 1023; // exponent = bits 1..11
 		var exp = (((bytes[0] << 4) & 0x7FF) | (bytes[1] >> 4)) - 1023; // exponent = bits 1..11
 		var sig = getDoubleSig(bytes);
 		var sig = getDoubleSig(bytes);
@@ -227,7 +227,7 @@ class Input {
 		return sign * (1.0 + Math.pow(2, -52) * sig) * Math.pow(2, exp);
 		return sign * (1.0 + Math.pow(2, -52) * sig) * Math.pow(2, exp);
 		#elseif cs
 		#elseif cs
 		if (helper == null) helper = new cs.NativeArray(8);
 		if (helper == null) helper = new cs.NativeArray(8);
-		
+
 		var helper = helper;
 		var helper = helper;
 		if (bigEndian == !cs.system.BitConverter.IsLittleEndian)
 		if (bigEndian == !cs.system.BitConverter.IsLittleEndian)
 		{
 		{
@@ -249,13 +249,13 @@ class Input {
 			helper[1] = readByte();
 			helper[1] = readByte();
 			helper[0] = readByte();
 			helper[0] = readByte();
 		}
 		}
-		
+
 		return cs.system.BitConverter.ToDouble(helper, 0);
 		return cs.system.BitConverter.ToDouble(helper, 0);
 		#elseif java
 		#elseif java
 		if (helper == null) helper = java.nio.ByteBuffer.allocateDirect(8);
 		if (helper == null) helper = java.nio.ByteBuffer.allocateDirect(8);
 		var helper = helper;
 		var helper = helper;
 		helper.order(bigEndian ? java.nio.ByteOrder.BIG_ENDIAN : java.nio.ByteOrder.LITTLE_ENDIAN);
 		helper.order(bigEndian ? java.nio.ByteOrder.BIG_ENDIAN : java.nio.ByteOrder.LITTLE_ENDIAN);
-		
+
 		helper.put(0, readByte());
 		helper.put(0, readByte());
 		helper.put(1, readByte());
 		helper.put(1, readByte());
 		helper.put(2, readByte());
 		helper.put(2, readByte());
@@ -264,7 +264,7 @@ class Input {
 		helper.put(5, readByte());
 		helper.put(5, readByte());
 		helper.put(6, readByte());
 		helper.put(6, readByte());
 		helper.put(7, readByte());
 		helper.put(7, readByte());
-		
+
 		return helper.getDouble(0);
 		return helper.getDouble(0);
 		#else
 		#else
 		return throw "not implemented";
 		return throw "not implemented";
@@ -310,6 +310,18 @@ class Input {
 		return bigEndian ? ch3 | (ch2 << 8) | (ch1 << 16) : ch1 | (ch2 << 8) | (ch3 << 16);
 		return bigEndian ? ch3 | (ch2 << 8) | (ch1 << 16) : ch1 | (ch2 << 8) | (ch3 << 16);
 	}
 	}
 
 
+	#if haxe3
+
+	public function readInt32() {
+		var ch1 = readByte();
+		var ch2 = readByte();
+		var ch3 = readByte();
+		var ch4 = readByte();
+		return bigEndian ? ch4 | (ch3 << 8) | (ch2 << 16) | (ch1 << 24) : ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
+	}
+
+	#else
+
 	public function readInt31() {
 	public function readInt31() {
 		var ch1,ch2,ch3,ch4;
 		var ch1,ch2,ch3,ch4;
 		if( bigEndian ) {
 		if( bigEndian ) {
@@ -351,6 +363,8 @@ class Input {
 #end
 #end
 	}
 	}
 
 
+	#end
+
 	public function readString( len : Int ) : String {
 	public function readString( len : Int ) : String {
 		var b = Bytes.alloc(len);
 		var b = Bytes.alloc(len);
 		readFullBytes(b,0,len);
 		readFullBytes(b,0,len);
@@ -375,7 +389,7 @@ class Input {
 #if flash
 #if flash
 	function getDoubleSig(bytes:Array<Int>) : Int
 	function getDoubleSig(bytes:Array<Int>) : Int
     {
     {
-        return untyped 
+        return untyped
         {
         {
             Std.int(((((bytes[1]&0xF) << 16) | (bytes[2] << 8) | bytes[3] ) * Math.pow(2, 32))) +
             Std.int(((((bytes[1]&0xF) << 16) | (bytes[2] << 8) | bytes[3] ) * Math.pow(2, 32))) +
             Std.int(((bytes[4] >> 7) * Math.pow(2,31))) +
             Std.int(((bytes[4] >> 7) * Math.pow(2,31))) +
@@ -385,12 +399,12 @@ class Input {
 #elseif js
 #elseif js
 	function getDoubleSig(bytes:Array<Int>) : Int
 	function getDoubleSig(bytes:Array<Int>) : Int
     {
     {
-        return untyped 
+        return untyped
         {
         {
             Std.parseInt(((((bytes[1]&0xF) << 16) | (bytes[2] << 8) | bytes[3] ) * Math.pow(2, 32)).toString()) +
             Std.parseInt(((((bytes[1]&0xF) << 16) | (bytes[2] << 8) | bytes[3] ) * Math.pow(2, 32)).toString()) +
             Std.parseInt(((bytes[4] >> 7) * Math.pow(2,31)).toString()) +
             Std.parseInt(((bytes[4] >> 7) * Math.pow(2,31)).toString()) +
             Std.parseInt((((bytes[4]&0x7F) << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7]).toString());
             Std.parseInt((((bytes[4]&0x7F) << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7]).toString());
         };
         };
-    }	
+    }
 #end
 #end
 }
 }

+ 26 - 6
std/haxe/io/Output.hx

@@ -33,7 +33,7 @@ package haxe.io;
 class Output {
 class Output {
 	private static var LN2 = Math.log(2);
 	private static var LN2 = Math.log(2);
 	public var bigEndian(default, setEndian) : Bool;
 	public var bigEndian(default, setEndian) : Bool;
-	
+
 	#if java
 	#if java
 	private var helper:java.nio.ByteBuffer;
 	private var helper:java.nio.ByteBuffer;
 	#end
 	#end
@@ -122,7 +122,7 @@ class Output {
 		if (helper == null) helper = java.nio.ByteBuffer.allocateDirect(8);
 		if (helper == null) helper = java.nio.ByteBuffer.allocateDirect(8);
 		var helper = helper;
 		var helper = helper;
 		helper.order(bigEndian ? java.nio.ByteOrder.BIG_ENDIAN : java.nio.ByteOrder.LITTLE_ENDIAN);
 		helper.order(bigEndian ? java.nio.ByteOrder.BIG_ENDIAN : java.nio.ByteOrder.LITTLE_ENDIAN);
-		
+
 		helper.putFloat(0, x);
 		helper.putFloat(0, x);
 		writeByte(helper.get(0));
 		writeByte(helper.get(0));
 		writeByte(helper.get(1));
 		writeByte(helper.get(1));
@@ -184,9 +184,9 @@ class Output {
 		if (helper == null) helper = java.nio.ByteBuffer.allocateDirect(8);
 		if (helper == null) helper = java.nio.ByteBuffer.allocateDirect(8);
 		var helper = helper;
 		var helper = helper;
 		helper.order(bigEndian ? java.nio.ByteOrder.BIG_ENDIAN : java.nio.ByteOrder.LITTLE_ENDIAN);
 		helper.order(bigEndian ? java.nio.ByteOrder.BIG_ENDIAN : java.nio.ByteOrder.LITTLE_ENDIAN);
-		
+
 		helper.putDouble(0, x);
 		helper.putDouble(0, x);
-	
+
 		writeByte(helper.get(0));
 		writeByte(helper.get(0));
 		writeByte(helper.get(1));
 		writeByte(helper.get(1));
 		writeByte(helper.get(2));
 		writeByte(helper.get(2));
@@ -196,13 +196,13 @@ class Output {
 		writeByte(helper.get(6));
 		writeByte(helper.get(6));
 		writeByte(helper.get(7));
 		writeByte(helper.get(7));
 		#else
 		#else
-		if (x == 0.0) 
+		if (x == 0.0)
 		{
 		{
 			writeByte(0); writeByte(0); writeByte(0); writeByte(0);
 			writeByte(0); writeByte(0); writeByte(0); writeByte(0);
 			writeByte(0); writeByte(0); writeByte(0); writeByte(0);
 			writeByte(0); writeByte(0); writeByte(0); writeByte(0);
 			return;
 			return;
 		}
 		}
-        
+
 		var exp = Math.floor(Math.log(Math.abs(x)) / LN2);
 		var exp = Math.floor(Math.log(Math.abs(x)) / LN2);
 		var sig : Int = Math.floor(Math.abs(x) / Math.pow(2, exp) * Math.pow(2, 52));
 		var sig : Int = Math.floor(Math.abs(x) / Math.pow(2, exp) * Math.pow(2, 52));
 		var sig_h = (sig & cast 34359738367);
 		var sig_h = (sig & cast 34359738367);
@@ -268,6 +268,24 @@ class Output {
 		}
 		}
 	}
 	}
 
 
+	#if haxe3
+
+	public function writeInt32( x : haxe.Int32 ) {
+		if( bigEndian ) {
+			writeByte( x >>> 24 );
+			writeByte( (x >> 16) & 0xFF );
+			writeByte( (x >> 8) & 0xFF );
+			writeByte( x & 0xFF );
+		} else {
+			writeByte( x & 0xFF );
+			writeByte( (x >> 8) & 0xFF );
+			writeByte( (x >> 16) & 0xFF );
+			writeByte( x >>> 24 );
+		}
+	}
+
+	#else
+
 	public function writeInt31( x : Int ) {
 	public function writeInt31( x : Int ) {
 		#if !neko
 		#if !neko
 		if( x < -0x40000000 || x >= 0x40000000 ) throw Error.Overflow;
 		if( x < -0x40000000 || x >= 0x40000000 ) throw Error.Overflow;
@@ -314,6 +332,8 @@ class Output {
 		}
 		}
 	}
 	}
 
 
+	#end
+
 	/**
 	/**
 		Inform that we are about to write at least a specified number of bytes.
 		Inform that we are about to write at least a specified number of bytes.
 		The underlying implementation can allocate proper working space depending
 		The underlying implementation can allocate proper working space depending