Skip to content

Commit 4a3505b

Browse files
committed
数组
1 parent 96acd2a commit 4a3505b

5 files changed

Lines changed: 113 additions & 5 deletions

File tree

CLRSharp/CLRSharp/CLRSharp_Env.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public string version
1111
{
1212
get
1313
{
14-
return "0.39.5Beta";
14+
return "0.39.6Beta";
1515
}
1616
}
1717
public ICLRSharp_Logger logger

CLRSharp/CLRSharp/Execute/Context.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ object GetToken(object token)
370370
if (token is Mono.Cecil.FieldDefinition || token is Mono.Cecil.FieldReference)
371371
{
372372
var def = token as Mono.Cecil.FieldDefinition;
373-
if (def != null && def.Name[0] == '$') return null;
373+
if (def != null && def.Name[0] == '$') return def.InitialValue;
374374
//都是用来初始化数组的方法,忽略
375375

376376
return GetField(token);

CLRSharp/CLRSharp/Execute/StackFrame.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,110 @@ public object Return()
213213

214214
return ret;
215215
}
216+
void FillArray(object array,byte[] bytes)
217+
{
218+
if (array is byte[])
219+
{
220+
byte[] arr = array as byte[];
221+
for (int i = 0; i < bytes.Length; i++)
222+
{
223+
arr[i] = bytes[i];
224+
}
225+
}
226+
else if (array is sbyte[])
227+
{
228+
sbyte[] arr = array as sbyte[];
229+
for (int i = 0; i < bytes.Length; i++)
230+
{
231+
arr[i] = (sbyte)bytes[i];
232+
}
233+
}
234+
else if (array is Int16[])
235+
{
236+
int step = 2;
237+
Int16[] arr = array as Int16[];
238+
for (int i = 0; i < bytes.Length / step; i++)
239+
{
240+
arr[i] = BitConverter.ToInt16(bytes, i * step);
241+
}
242+
}
243+
else if (array is UInt16[])
244+
{
245+
int step = 2;
246+
UInt16[] arr = array as UInt16[];
247+
for (int i = 0; i < bytes.Length / step; i++)
248+
{
249+
arr[i] = BitConverter.ToUInt16(bytes, i * step);
250+
}
251+
}
252+
else if (array is char[])
253+
{
254+
int step = 2;
255+
char[] arr = array as char[];
256+
for (int i = 0; i < bytes.Length / step; i++)
257+
{
258+
arr[i] = (char)BitConverter.ToUInt16(bytes, i * step);
259+
}
260+
}
261+
else if(array is int[])
262+
{
263+
int step = 4;
264+
int[] arr = array as int[];
265+
for (int i = 0; i < bytes.Length / step; i++)
266+
{
267+
arr[i] = BitConverter.ToInt32(bytes, i * step);
268+
}
269+
}
270+
else if (array is uint[])
271+
{
272+
int step = 4;
273+
uint[] arr = array as uint[];
274+
for (int i = 0; i < bytes.Length / step; i++)
275+
{
276+
arr[i] = BitConverter.ToUInt32(bytes, i * step);
277+
}
278+
}
279+
else if (array is Int64[])
280+
{
281+
int step = 8;
282+
Int64[] arr = array as Int64[];
283+
for (int i = 0; i < bytes.Length / step; i++)
284+
{
285+
arr[i] = BitConverter.ToInt64(bytes, i * step);
286+
}
287+
}
288+
else if (array is UInt64[])
289+
{
290+
int step = 8;
291+
UInt64[] arr = array as UInt64[];
292+
for (int i = 0; i < bytes.Length / step; i++)
293+
{
294+
arr[i] = BitConverter.ToUInt64(bytes, i * step);
295+
}
296+
}
297+
else if (array is float[])
298+
{
299+
int step = 4;
300+
float[] arr = array as float[];
301+
for (int i = 0; i < bytes.Length / step; i++)
302+
{
303+
arr[i] = BitConverter.ToSingle(bytes, i * step);
304+
}
305+
}
306+
else if (array is double[])
307+
{
308+
int step = 8;
309+
double[] arr = array as double[];
310+
for (int i = 0; i < bytes.Length / step; i++)
311+
{
312+
arr[i] = BitConverter.ToDouble(bytes, i * step);
313+
}
314+
}
315+
else
316+
{
317+
throw new NotImplementedException("array=" + array.GetType());
318+
}
319+
}
216320
//流程控制
217321
public void Call(ThreadContext context, IMethod _clrmethod, bool bVisual)
218322
{
@@ -287,6 +391,7 @@ public void Call(ThreadContext context, IMethod _clrmethod, bool bVisual)
287391
}
288392
if (_clrmethod.DeclaringType.FullName.Contains("System.Runtime.CompilerServices.RuntimeHelpers") && _clrmethod.Name.Contains("InitializeArray"))
289393
{
394+
FillArray(_pp[0], _pp[1] as byte[]);
290395
_codepos++;
291396
return;
292397
}

UnitTestDll/LightTestor/ExpTest_70.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public class ExpTest_70
1010
//只要有一个静态函数包含UnitTest名称的,就作为单元测试
1111
public static void UnitTest_7001()
1212
{
13+
int[] ints3 = new int[] { 1, 2, 3 };
14+
int v = ints3[0];// = 44;
15+
Logger.Log("=" + v);
1316
//7001 array
1417
List<List<int>> list = new List<List<int>>();
1518
list.Add(new List<int>());
@@ -25,9 +28,7 @@ public static void UnitTest_7001()
2528
ints2[1] = 44;
2629
Logger.Log("=" + ints2[1]);
2730

28-
int[] ints3 = new int[] { 55, 55, 55 };
29-
ints3[1] = 44;
30-
Logger.Log("=" + ints3[1]);
31+
3132
}
3233
public static void UnitTest_7002()
3334
{

readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
用途,Unity3D热更(包括IOS平台)等
66
Beta阶段,有一定动手能力的小伙伴,已经可以将它用于实战
77
更新日志:
8+
2015-01-30 V0.39.6Beta
9+
修正了数值数组初始化的问题
810
2015-01-30 V0.39.5Beta
911
修正了脚本定义struct
1012
修正了使用 Type作为参数的函数调用问题

0 commit comments

Comments
 (0)