浏览代码

more hl renames, added hl.Bytes.getArray

Nicolas Cannasse 8 年之前
父节点
当前提交
9152276548

+ 10 - 0
src/generators/genhl.ml

@@ -1666,6 +1666,16 @@ and eval_expr ctx e =
 			let r = eval_to ctx value et in
 			op ctx (OSetArray (arr, pos, r));
 			r
+		| "$abytes", [a] ->
+			(match follow a.etype with
+			| TInst ({ cl_path = [], "Array" },[t]) when is_number (to_type ctx t) ->
+				let a = eval_expr ctx a in
+				let r = alloc_tmp ctx HBytes in
+				op ctx (ONullCheck a);
+				op ctx (OField (r,a,1));
+				r
+			| t ->
+				abort ("Invalid array type " ^ s_type (print_context()) t) a.epos)
 		| "$ref", [v] ->
 			(match v.eexpr with
 			| TLocal v ->

+ 8 - 1
std/hl/Bytes.hx

@@ -164,10 +164,17 @@ package hl;
 	}
 
 	@:hlNative("std","value_to_string")
-	public static function ofValue( v : Dynamic, length : Ref<Int> ) : Bytes {
+	public static function fromValue( v : Dynamic, length : Ref<Int> ) : Bytes {
 		return null;
 	}
 
+	/**
+		Get the bytes reference from an array of basic types (no copy occurs)
+	**/
+	@:extern public static inline function getArray<T>( a : Array<T> ) : Bytes {
+		return untyped $abytes(a);
+	}
+
 	@:from
 	public static inline function fromBytes( bytes : haxe.io.Bytes ) {
 		return @:privateAccess bytes.b;

+ 2 - 2
std/hl/UI.hx

@@ -21,7 +21,7 @@
  */
 package hl;
 
-typedef SentinelHandle = hl.types.NativeAbstract<"ui_sentinel">;
+typedef SentinelHandle = hl.Abstract<"ui_sentinel">;
 
 abstract Sentinel(SentinelHandle) {
 
@@ -41,7 +41,7 @@ abstract Sentinel(SentinelHandle) {
 
 }
 
-typedef WinHandle = hl.types.NativeAbstract<"ui_window">;
+typedef WinHandle = hl.Abstract<"ui_window">;
 
 class Window {
 

+ 1 - 1
std/hl/_std/Std.hx

@@ -75,7 +75,7 @@ class Std {
 
 	@:keep public static function string( s : Dynamic ) : String {
 		var len = 0;
-		var bytes = hl.Bytes.ofValue(s,new hl.Ref(len));
+		var bytes = hl.Bytes.fromValue(s,new hl.Ref(len));
 		return @:privateAccess String.__alloc__(bytes,len);
 	}
 

+ 1 - 1
std/hl/_std/StringBuf.hx

@@ -53,7 +53,7 @@
 
 	public function add<T>( x : T ) : Void {
 		var slen = 0;
-		var sbytes = hl.Bytes.ofValue(x, new hl.Ref(slen));
+		var sbytes = hl.Bytes.fromValue(x, new hl.Ref(slen));
 		__add(sbytes, 0, slen<<1);
 	}
 

+ 2 - 2
std/hl/_std/haxe/zip/Compress.hx

@@ -21,7 +21,7 @@
  */
 package haxe.zip;
 
-private typedef Deflater = hl.types.NativeAbstract<"fmt_zip">;
+private typedef Deflater = hl.Abstract<"fmt_zip">;
 
 @:coreApi @:hlNative("fmt")
 class Compress {
@@ -61,7 +61,7 @@ class Compress {
 	}
 
 	static function deflate_init( level : Int ) : Deflater { return null; }
-	static function deflate_buffer( i : Deflater, bytes : hl.Bytes, bytesPos : Int, bytesLen : Int, dst : hl.Bytes, dstPos : Int, dstLen : Int, read : hl.types.Ref<Int>, write : hl.types.Ref<Int>) : Bool {
+	static function deflate_buffer( i : Deflater, bytes : hl.Bytes, bytesPos : Int, bytesLen : Int, dst : hl.Bytes, dstPos : Int, dstLen : Int, read : hl.Ref<Int>, write : hl.Ref<Int>) : Bool {
 		return false;
 	}
 	static function deflate_bound( i : Deflater, length : Int ) : Int { return 0; }

+ 2 - 2
std/hl/_std/haxe/zip/Uncompress.hx

@@ -21,7 +21,7 @@
  */
 package haxe.zip;
 
-private typedef Inflater = hl.types.NativeAbstract<"fmt_zip">;
+private typedef Inflater = hl.Abstract<"fmt_zip">;
 
 @:coreApi @:hlNative("fmt")
 class Uncompress {
@@ -65,7 +65,7 @@ class Uncompress {
 	}
 
 	static function inflate_init( bits : Int ) : Inflater { return null; }
-	static function inflate_buffer( i : Inflater, bytes : hl.Bytes, bytesPos : Int, bytesLen : Int, dst : hl.Bytes, dstPos : Int, dstLen : Int, read : hl.types.Ref<Int>, write : hl.types.Ref<Int>) : Bool {
+	static function inflate_buffer( i : Inflater, bytes : hl.Bytes, bytesPos : Int, bytesLen : Int, dst : hl.Bytes, dstPos : Int, dstLen : Int, read : hl.Ref<Int>, write : hl.Ref<Int>) : Bool {
 		return false;
 	}
 	static function zip_end( i : Inflater ) : Void { }

+ 3 - 3
std/hl/_std/sys/net/Socket.hx

@@ -22,7 +22,7 @@
 package sys.net;
 import haxe.io.Error;
 
-private typedef SocketHandle = hl.types.NativeAbstract<"hl_socket">;
+private typedef SocketHandle = hl.Abstract<"hl_socket">;
 
 private class SocketOutput extends haxe.io.Output {
 
@@ -206,8 +206,8 @@ class Socket {
 	@:hlNative("std", "socket_listen") static function socket_listen( s : SocketHandle, count : Int ) : Bool { return true; }
 	@:hlNative("std", "socket_bind") static function socket_bind( s : SocketHandle, host : Int, port : Int ) : Bool { return true; }
 	@:hlNative("std", "socket_accept") static function socket_accept( s : SocketHandle ) : SocketHandle { return null; }
-	@:hlNative("std", "socket_peer") static function socket_peer( s : SocketHandle, host : hl.types.Ref<Int>, port : hl.types.Ref<Int> ) : Bool { return true; }
-	@:hlNative("std", "socket_host") static function socket_host( s : SocketHandle, host : hl.types.Ref<Int>, port : hl.types.Ref<Int> ) : Bool { return true; }
+	@:hlNative("std", "socket_peer") static function socket_peer( s : SocketHandle, host : hl.Ref<Int>, port : hl.Ref<Int> ) : Bool { return true; }
+	@:hlNative("std", "socket_host") static function socket_host( s : SocketHandle, host : hl.Ref<Int>, port : hl.Ref<Int> ) : Bool { return true; }
 	@:hlNative("std", "socket_set_timeout") static function socket_set_timeout( s : SocketHandle, timeout : Float ) : Bool { return true; }
 	@:hlNative("std", "socket_shutdown") static function socket_shutdown( s : SocketHandle, read : Bool, write : Bool ) : Bool { return true; }
 	@:hlNative("std", "socket_set_blocking") static function socket_set_blocking( s : SocketHandle, b : Bool ) : Bool { return true; }