Sfoglia il codice sorgente

TestSerializer passing

Nicolas Cannasse 9 anni fa
parent
commit
57060682e7
3 ha cambiato i file con 13 aggiunte e 4 eliminazioni
  1. 8 2
      genhl.ml
  2. 1 1
      std/haxe/Serializer.hx
  3. 4 1
      std/hl/_std/String.hx

+ 8 - 2
genhl.ml

@@ -2153,6 +2153,7 @@ and eval_expr ctx e =
 				) next cases in
 				) next cases in
 				let re = eval_to ctx e rt in
 				let re = eval_to ctx e rt in
 				if rt <> HVoid then op ctx (OMov (r,re));
 				if rt <> HVoid then op ctx (OMov (r,re));
+				jends := jump ctx (fun n -> OJAlways n) :: !jends;
 				next
 				next
 			in
 			in
 			let j = List.fold_left loop (fun() -> ()) cases in
 			let j = List.fold_left loop (fun() -> ()) cases in
@@ -4418,6 +4419,12 @@ let interp code =
 				(function
 				(function
 				| [VDynObj o] ->
 				| [VDynObj o] ->
 					VArray (Array.of_list (Hashtbl.fold (fun n _ acc -> VBytes (caml_to_hl n) :: acc) o.dfields []), HBytes)
 					VArray (Array.of_list (Hashtbl.fold (fun n _ acc -> VBytes (caml_to_hl n) :: acc) o.dfields []), HBytes)
+				| [VObj o] ->
+					let rec loop p =
+						let fields = Array.map (fun (n,_,_) -> VBytes (caml_to_hl n)) p.pfields in
+						match p.psuper with None -> [fields] | Some p -> fields :: loop p
+					in
+					VArray (Array.concat (loop o.oproto.pclass), HBytes)
 				| _ ->
 				| _ ->
 					VNull)
 					VNull)
 			| "enum_parameters" ->
 			| "enum_parameters" ->
@@ -4492,8 +4499,7 @@ let interp code =
 						| VDynObj d -> Hashtbl.mem d.dfields f
 						| VDynObj d -> Hashtbl.mem d.dfields f
 						| VObj o ->
 						| VObj o ->
 							let rec loop p =
 							let rec loop p =
-								let f = PMap.mem f p.pindex in
-								if f then true else match p.psuper with None -> false | Some p -> loop p
+								if PMap.mem f p.pindex then let idx, _ = PMap.find f p.pindex in idx >= 0 else match p.psuper with None -> false | Some p -> loop p
 							in
 							in
 							loop o.oproto.pclass
 							loop o.oproto.pclass
 						| VVirtual v -> loop v.vvalue
 						| VVirtual v -> loop v.vvalue

+ 1 - 1
std/haxe/Serializer.hx

@@ -258,7 +258,7 @@ class Serializer {
 			case #if (neko || cs || python) "Array" #else cast Array #end:
 			case #if (neko || cs || python) "Array" #else cast Array #end:
 				var ucount = 0;
 				var ucount = 0;
 				buf.add("a");
 				buf.add("a");
-				#if (flash || python)
+				#if (flash || python || hl)
 				var v : Array<Dynamic> = v;
 				var v : Array<Dynamic> = v;
 				#end
 				#end
 				var l = #if (neko || flash || php || cs || java || python || hl) v.length #elseif cpp v.__length() #else __getField(v, "length") #end;
 				var l = #if (neko || flash || php || cs || java || python || hl) v.length #elseif cpp v.__length() #else __getField(v, "length") #end;

+ 4 - 1
std/hl/_std/String.hx

@@ -20,7 +20,10 @@ class String {
 
 
 	public function charAt(index : Int) : String {
 	public function charAt(index : Int) : String {
 		if( (index:UInt) >= (length:UInt) ) return "";
 		if( (index:UInt) >= (length:UInt) ) return "";
-		return __alloc__(bytes.sub(index<<1,2),1);
+		var b = new hl.types.Bytes(4);
+		b.setUI16(0, bytes.getUI16(index<<1));
+		b.setUI16(2,0);
+		return __alloc__(b,1);
 	}
 	}
 
 
 	public function charCodeAt( index : Int) : Null<Int> {
 	public function charCodeAt( index : Int) : Null<Int> {