瀏覽代碼

[java/cs] Fix special Lib functions

Cauê Waneck 11 年之前
父節點
當前提交
078d057574
共有 2 個文件被更改,包括 13 次插入2 次删除
  1. 13 0
      optimizer.ml
  2. 0 2
      tests/unit/TestCSharp.hx

+ 13 - 0
optimizer.ml

@@ -42,6 +42,13 @@ let has_side_effect e =
 	with Exit ->
 		true
 
+let mk_untyped_call name p params =
+	{
+		eexpr = TCall({ eexpr = TLocal(alloc_var name t_dynamic); etype = t_dynamic; epos = p }, params);
+		etype = t_dynamic;
+		epos = p;
+	}
+
 let api_inline ctx c field params p =
 	match c.cl_path, field, params with
 	| ([],"Type"),"enumIndex",[{ eexpr = TField (_,FEnum (en,f)) }] ->
@@ -127,6 +134,12 @@ let api_inline ctx c field params p =
 			None (* out range, keep platform-specific behavior *)
 		| _ ->
 			Some { eexpr = TConst (TInt (Int32.of_float f)); etype = ctx.t.tint; epos = p })
+	| (["cs"],"Lib"),("fixed" | "checked" | "unsafe"),[e] ->
+			Some (mk_untyped_call ("__" ^ field ^ "__") p [e])
+	| (["cs"],"Lib"),("lock"),[obj;block] ->
+			Some (mk_untyped_call ("__lock__") p [obj;block])
+	| (["java"],"Lib"),("lock"),[obj;block] ->
+			Some (mk_untyped_call ("__lock__") p [obj;block])
 	| _ ->
 		None
 

+ 0 - 2
tests/unit/TestCSharp.hx

@@ -52,7 +52,6 @@ class TestCSharp extends Test
 		eq(i, 40);
 	}
 
-	#if false // TODO: disabled test because of "Arguments and variables of type Void are not allowed" error
 	public function testChecked()
 	{
 		exc(function()
@@ -66,7 +65,6 @@ class TestCSharp extends Test
 			});
 		});
 	}
-	#end
 
 	#if unsafe