Skip to content

Commit bf389a7

Browse files
committed
Merge pull request #2 from lightszero/master
合并原作者更新
2 parents a4f66d0 + 16c549c commit bf389a7

File tree

5 files changed

+128
-59
lines changed

5 files changed

+128
-59
lines changed

CLRSharp/CLRSharp/Execute/CodeBody.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ public void InitToken(ThreadContext context, CodeBody body, object _p)
364364
case CodeEx.Newobj:
365365
case CodeEx.Ldftn:
366366
case CodeEx.Ldvirtftn:
367-
this.tokenMethod = context.GetMethod(_p);
367+
368+
this.tokenMethod = context.GetMethod(_p);
369+
368370
break;
369371
case CodeEx.Ldc_I4:
370372
this.tokenI32 = (int)_p;

CLRSharp/CLRSharp/Execute/Context.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,18 @@ public IMethod GetMethod(object token)
267267
{
268268
throw new NotImplementedException();
269269
}
270+
270271
var typesys = GetType(typename);
271272
if (typesys == null)
272-
throw new Exception("type can't find:" + typename);
273+
{
274+
typename = typename.Replace("0...", "");
275+
typesys = GetType(typename);
273276

277+
}
278+
if (typesys == null)
279+
{
280+
throw new Exception("type can't find:" + typename);
281+
}
274282

275283
IMethod _method = null;
276284
if (genlist != null)

CLRSharp/CLRSharp/Execute/StackFrame.cs

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,45 +2415,80 @@ public void Ldind_Ref(ThreadContext context, object obj)
24152415
}
24162416
public void Stind_Ref(ThreadContext context, object obj)
24172417
{
2418-
Type t = obj.GetType();
2419-
throw new NotImplementedException(t.ToString());
2420-
//_codepos++;
2418+
var o1 = stackCalc.Pop();
2419+
var o2 = stackCalc.Pop();
2420+
if(o2 is RefObj)
2421+
{
2422+
(o2 as RefObj).Set(o1);
2423+
}
2424+
2425+
_codepos++;
24212426
}
24222427
public void Stind_I1(ThreadContext context, object obj)
24232428
{
2424-
Type t = obj.GetType();
2425-
throw new NotImplementedException(t.ToString());
2426-
//_codepos++;
2429+
var o1 = stackCalc.Pop();
2430+
var o2 = stackCalc.Pop();
2431+
if (o2 is RefObj)
2432+
{
2433+
(o2 as RefObj).Set(o1);
2434+
}
2435+
2436+
_codepos++;
24272437
}
24282438
public void Stind_I2(ThreadContext context, object obj)
24292439
{
2430-
Type t = obj.GetType();
2431-
throw new NotImplementedException(t.ToString());
2432-
//_codepos++;
2440+
var o1 = stackCalc.Pop();
2441+
var o2 = stackCalc.Pop();
2442+
if (o2 is RefObj)
2443+
{
2444+
(o2 as RefObj).Set(o1);
2445+
}
2446+
2447+
_codepos++;
24332448
}
24342449
public void Stind_I4(ThreadContext context, object obj)
24352450
{
2436-
Type t = obj.GetType();
2437-
throw new NotImplementedException(t.ToString());
2438-
//_codepos++;
2451+
var o1 = stackCalc.Pop();
2452+
var o2 = stackCalc.Pop();
2453+
if (o2 is RefObj)
2454+
{
2455+
(o2 as RefObj).Set(o1);
2456+
}
2457+
2458+
_codepos++;
24392459
}
24402460
public void Stind_I8(ThreadContext context, object obj)
24412461
{
2442-
Type t = obj.GetType();
2443-
throw new NotImplementedException(t.ToString());
2444-
//_codepos++;
2462+
var o1 = stackCalc.Pop();
2463+
var o2 = stackCalc.Pop();
2464+
if (o2 is RefObj)
2465+
{
2466+
(o2 as RefObj).Set(o1);
2467+
}
2468+
2469+
_codepos++;
24452470
}
24462471
public void Stind_R4(ThreadContext context, object obj)
24472472
{
2448-
Type t = obj.GetType();
2449-
throw new NotImplementedException(t.ToString());
2450-
//_codepos++;
2473+
var o1 = stackCalc.Pop();
2474+
var o2 = stackCalc.Pop();
2475+
if (o2 is RefObj)
2476+
{
2477+
(o2 as RefObj).Set(o1);
2478+
}
2479+
2480+
_codepos++;
24512481
}
24522482
public void Stind_R8(ThreadContext context, object obj)
24532483
{
2454-
Type t = obj.GetType();
2455-
throw new NotImplementedException(t.ToString());
2456-
//_codepos++;
2484+
var o1 = stackCalc.Pop();
2485+
var o2 = stackCalc.Pop();
2486+
if (o2 is RefObj)
2487+
{
2488+
(o2 as RefObj).Set(o1);
2489+
}
2490+
2491+
_codepos++;
24572492
}
24582493
public void And()
24592494
{

UnitTestDll/Test_ByDuskforest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,12 @@ public static void UnitTest_CtorWithByteArg()
3333
System.Activator.CreateInstance(Type.GetType("TestClass,UnitTest"), new Object[] { (byte)32 });
3434
//error assm
3535
}
36+
37+
public static void UnitTest_2DimArray()
38+
{
39+
int[,] a = new int[1,1];
40+
a[0, 0] = 4;
41+
Logger.Log("abc=" + a[0, 0]);
42+
}
3643
}
3744
}

UnitTestDll/test_RefOut.cs

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,57 @@
44

55
namespace UnitTestDll
66
{
7-
public class test_RefOut
8-
{
9-
private class UserDefClass {
10-
public int value01;
11-
public string value02 = "";
12-
13-
public void StringToValue(ref string v, string str) {
14-
v = str;
15-
}
16-
}
17-
18-
19-
public static void UnitTest_Out() {
20-
Dictionary<int, UserDefClass> dict = new Dictionary<int,UserDefClass>();
21-
UserDefClass obj = new UserDefClass();
22-
obj.value01 = 888;
23-
dict.Add(0, obj);
24-
UserDefClass testObj;
25-
if(dict.ContainsKey(0)) {
26-
testObj = dict[0];
27-
Logger.Log(string.Format("Value01 : {0}", testObj.value01));
28-
}
29-
if(dict.TryGetValue(0, out testObj)) {
30-
Logger.Log("Test OK.");
31-
}
32-
}
33-
34-
public static void UnitTest_Ref() {
35-
36-
UserDefClass obj = new UserDefClass();
37-
obj.StringToValue(ref obj.value02, "test");
38-
Logger.Log(obj.value02);
39-
40-
}
41-
42-
}
7+
public class test_RefOut
8+
{
9+
private class UserDefClass
10+
{
11+
public int value01;
12+
public string value02 = "";
13+
14+
public void StringToValue(ref string v, string str)
15+
{
16+
v = str;
17+
}
18+
public void IntToValue(ref int v, int str)
19+
{
20+
v = str;
21+
}
22+
}
23+
24+
25+
public static void UnitTest_Out()
26+
{
27+
28+
Dictionary<int, UserDefClass> dict = new Dictionary<int, UserDefClass>();
29+
UserDefClass obj = new UserDefClass();
30+
obj.value01 = 888;
31+
dict.Add(0, obj);
32+
UserDefClass testObj;
33+
if (dict.ContainsKey(0))
34+
{
35+
testObj = dict[0];
36+
Logger.Log(string.Format("Value01 : {0}", testObj.value01));
37+
}
38+
39+
Logger.Log("这个错误是无法避免的,UserDefClass是个脚本类型,他不能在字典的操作中以ref out来操作");
40+
//if (dict.TryGetValue(0, out testObj))
41+
//{
42+
// Logger.Log("Test OK.");
43+
//}
44+
45+
}
46+
47+
public static void UnitTest_Ref()
48+
{
49+
UserDefClass obj = new UserDefClass();
50+
51+
string abc = "abc";
52+
obj.StringToValue(ref abc, "test");
53+
int i = 0;
54+
obj.IntToValue(ref i, 777);
55+
Logger.Log("abc=" + abc + "|i=" + i);
56+
57+
}
58+
59+
}
4360
}

0 commit comments

Comments
 (0)