瀏覽代碼

fixes hlinterp unit tests

Nicolas Cannasse 8 年之前
父節點
當前提交
f610b6d4fc
共有 3 個文件被更改,包括 11 次插入7 次删除
  1. 7 5
      src/generators/hlinterp.ml
  2. 1 1
      src/optimization/filters.ml
  3. 3 1
      std/hl/_std/String.hx

+ 7 - 5
src/generators/hlinterp.ml

@@ -401,7 +401,7 @@ let rec to_virtual ctx v vp =
 
 let rec dyn_cast ctx v t rt =
 	let invalid() =
-		error ("Can't cast " ^ vstr_d ctx v ^ ":"  ^ tstr t ^ " to " ^ tstr rt)
+		throw_msg ctx ("Can't cast " ^ vstr_d ctx v ^ ":"  ^ tstr t ^ " to " ^ tstr rt)
 	in
 	let default() =
 		let v = default rt in
@@ -1238,14 +1238,16 @@ let load_native ctx lib name t =
 			| _ -> assert false)
 		| "alloc_enum" ->
 			(function
-			| [VType (HEnum e); VInt idx; VArray (vl,vt)] ->
+			| [VType (HEnum e); VInt idx; VArray (vl,vt); VInt len] ->
 				let idx = int idx in
+				let len = int len in
 				let _, _, args = e.efields.(idx) in
-				if Array.length args <> Array.length vl then
+				if Array.length args <> len then
 					VNull
 				else
-					VDyn (VEnum (idx,Array.mapi (fun i v -> dyn_cast ctx v vt args.(i)) vl),HEnum e)
-			| _ -> assert false)
+					VDyn (VEnum (idx,Array.mapi (fun i v -> dyn_cast ctx v vt args.(i)) (Array.sub vl 0 len)),HEnum e)
+			| vl ->
+				assert false)
 		| "array_blit" ->
 			(function
 			| [VArray (dst,_); VInt dp; VArray (src,_); VInt sp; VInt len] ->

+ 1 - 1
src/optimization/filters.ml

@@ -1129,7 +1129,7 @@ let run com tctx main =
 		apply_native_paths;
 		add_rtti;
 		(match com.platform with | Java | Cs -> (fun _ _ -> ()) | _ -> add_field_inits);
-		add_meta_field;
+		(match com.platform with Hl -> (fun _ _ -> ()) | _ -> add_meta_field);
 		check_void_field;
 		(match com.platform with | Cpp -> promote_first_interface_to_super | _ -> (fun _ _ -> ()) );
 		commit_features;

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

@@ -115,8 +115,10 @@ class String {
 		if( pos < 0 ) {
 			pos = sl + pos;
 			if( pos < 0 ) pos = 0;
-		} else if( len < 0 )
+		} else if( len < 0 ) {
 			len = sl + len - pos;
+			if( len < 0 ) return "";
+		}
 		if( ((pos + len) : UInt) > (sl:UInt) )
 			len = sl - pos;
 		if( pos < 0 || len <= 0 ) return "";