Jelajahi Sumber

升级ILRuntime到1.3版本

tanghai 8 tahun lalu
induk
melakukan
844d2ddd6a
100 mengubah file dengan 1360 tambahan dan 366 penghapusan
  1. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Method/CLRMethod.cs.meta
  2. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Method/ExceptionHandler.cs.meta
  3. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Method/ILMethod.cs.meta
  4. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Method/IMethod.cs.meta
  5. 82 5
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/CLRType.cs
  6. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/CLRType.cs.meta
  7. 7 2
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/ILGenericParameterType.cs
  8. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/ILGenericParameterType.cs.meta
  9. 39 12
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/ILType.cs
  10. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/ILType.cs.meta
  11. 20 3
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/IType.cs
  12. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/IType.cs.meta
  13. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Utils/Extensions.cs.meta
  14. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/ByReferenceKeyComparer.cs.meta
  15. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/DelegateExportAttribute.cs.meta
  16. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/NeedAdaptorAttribute.cs.meta
  17. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/ThreadSafeDictionary.cs.meta
  18. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/UncheckedList.cs.meta
  19. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/Extensions.cs.meta
  20. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeConstructorInfo.cs.meta
  21. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeFieldInfo.cs.meta
  22. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeMethodInfo.cs.meta
  23. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeParameterInfo.cs.meta
  24. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimePropertyInfo.cs.meta
  25. 2 2
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeType.cs
  26. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeType.cs.meta
  27. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeWrapperType.cs.meta
  28. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Adaptors/CLRCrossBindingAdaptors.cs.meta
  29. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/BindingCodeGenerator.cs.meta
  30. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/BindingGeneratorExtensions.cs.meta
  31. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/CommonBindingGenerator.cs.meta
  32. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/ConstructorBindingGenerator.cs.meta
  33. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/FieldBindingGenerator.cs.meta
  34. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/MethodBindingGenerator.cs.meta
  35. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/ValueTypeBindingGenerator.cs.meta
  36. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/BreakPointContext.cs.meta
  37. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/BreakpointInfo.cs.meta
  38. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebugMessageType.cs.meta
  39. 143 0
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebugService.cs
  40. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebugService.cs.meta
  41. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebugSocket.cs.meta
  42. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebuggerServer/DebuggerServer.cs.meta
  43. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSBindBreakpoint.cs.meta
  44. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSDeleteBreakpoint.cs.meta
  45. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSExecute.cs.meta
  46. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSResolveVariable.cs.meta
  47. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSStep.cs.meta
  48. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCAttachResult.cs.meta
  49. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCBindBreakpointResult.cs.meta
  50. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCBreakpointHit.cs.meta
  51. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCModuleLoaded.cs.meta
  52. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCResolveVariableResult.cs.meta
  53. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCStepComplete.cs.meta
  54. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCThreadStarted.cs.meta
  55. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/StackFrameInfo.cs.meta
  56. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/StepTypes.cs.meta
  57. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/VariableInfo.cs.meta
  58. 13 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/AppDomain.cs
  59. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/AppDomain.cs.meta
  60. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/CLRRedirections.cs.meta
  61. 12 4
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/CrossBindingAdaptor.cs
  62. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/CrossBindingAdaptor.cs.meta
  63. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/DelegateManager.cs.meta
  64. 114 0
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/ValueTypeBinder.cs
  65. 2 2
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/ValueTypeBinder.cs.meta
  66. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Extensions.cs.meta
  67. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/DelegateAdapter.cs.meta
  68. 439 237
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILIntepreter.cs
  69. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILIntepreter.cs.meta
  70. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILRuntimeException.cs.meta
  71. 82 5
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILTypeInstance.cs
  72. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILTypeInstance.cs.meta
  73. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/OpCodes/OpCode.cs.meta
  74. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/OpCodes/OpCodeEnum.cs.meta
  75. 294 6
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/RuntimeStack.cs
  76. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/RuntimeStack.cs.meta
  77. 1 0
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/StackFrame.cs
  78. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/StackFrame.cs.meta
  79. 25 2
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/StackObject.cs
  80. 1 1
      Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/StackObject.cs.meta
  81. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Code.cs.meta
  82. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeReader.cs.meta
  83. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeWriter.cs.meta
  84. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Document.cs.meta
  85. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ExceptionHandler.cs.meta
  86. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ILProcessor.cs.meta
  87. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Instruction.cs.meta
  88. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/MethodBody.cs.meta
  89. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCode.cs.meta
  90. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCodes.cs.meta
  91. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/SequencePoint.cs.meta
  92. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Symbols.cs.meta
  93. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableDefinition.cs.meta
  94. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableReference.cs.meta
  95. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/BlobHeap.cs.meta
  96. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Buffers.cs.meta
  97. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/CodedIndex.cs.meta
  98. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/ElementType.cs.meta
  99. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/GuidHeap.cs.meta
  100. 1 1
      Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Heap.cs.meta

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Method/CLRMethod.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: e3a93984f12c9da43b98d43930dd8c49
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Method/ExceptionHandler.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 99ef6f3b1f4f7894ebd5e1878c08fcb5
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Method/ILMethod.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 4d61dbf18ea786940ad2dda2466cde64
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Method/IMethod.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 3ee73b411c3d8c34cbcc5578441c854a
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 82 - 5
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/CLRType.cs

@@ -14,6 +14,7 @@ namespace ILRuntime.CLR.TypeSystem
     public class CLRType : IType
     {
         Type clrType;
+        bool isPrimitive, isValueType;
         Dictionary<string, List<CLRMethod>> methods;
         ILRuntime.Runtime.Enviorment.AppDomain appdomain;
         List<CLRMethod> constructors;
@@ -23,6 +24,9 @@ namespace ILRuntime.CLR.TypeSystem
         Dictionary<int, FieldInfo> fieldInfoCache;
         Dictionary<int, CLRFieldGetterDelegate> fieldGetterCache;
         Dictionary<int, CLRFieldSetterDelegate> fieldSetterCache;
+        Dictionary<int, int> fieldIdxMapping;
+        IType[] orderedFieldTypes;
+
         CLRMemberwiseCloneDelegate memberwiseCloneDelegate;
         CLRCreateDefaultInstanceDelegate createDefaultInstanceDelegate;
         CLRCreateArrayInstanceDelegate createArrayInstanceDelegate;
@@ -31,8 +35,9 @@ namespace ILRuntime.CLR.TypeSystem
         IType[] interfaces;
         bool isDelegate;
         IType baseType;
-        bool isBaseTypeInitialized = false, interfaceInitialized = false;
+        bool isBaseTypeInitialized = false, interfaceInitialized = false, valueTypeBinderGot = false;
         ILRuntimeWrapperType wraperType;
+        ValueTypeBinder valueTypeBinder;
 
         int hashCode = -1;
         static int instance_id = 0x20000000;
@@ -46,6 +51,32 @@ namespace ILRuntime.CLR.TypeSystem
                 return fieldInfoCache;
             }
         }
+
+        public Dictionary<int, int> FieldIndexMapping
+        {
+            get { return fieldIdxMapping; }
+        }
+
+        public IType[] OrderedFieldTypes
+        {
+            get
+            {
+                if (fieldMapping == null)
+                    InitializeFields();
+                return orderedFieldTypes;
+            }
+        }
+
+        public int TotalFieldCount
+        {
+            get
+            {
+                if (fieldMapping == null)
+                    InitializeFields();
+                return fieldIdxMapping.Count;
+            }
+        }
+
         public ILRuntime.Runtime.Enviorment.AppDomain AppDomain
         {
             get
@@ -58,6 +89,8 @@ namespace ILRuntime.CLR.TypeSystem
         {
             this.clrType = clrType;
             this.appdomain = appdomain;
+            isPrimitive = clrType.IsPrimitive;
+            isValueType = clrType.IsValueType;
             isDelegate = clrType.BaseType == typeof(MulticastDelegate);
         }
 
@@ -128,7 +161,7 @@ namespace ILRuntime.CLR.TypeSystem
         {
             get
             {
-                return clrType.IsValueType;
+                return isValueType;
             }
         }
         public bool IsDelegate
@@ -138,6 +171,14 @@ namespace ILRuntime.CLR.TypeSystem
                 return isDelegate;
             }
         }
+
+        public bool IsPrimitive
+        {
+            get
+            {
+                return isPrimitive;
+            }
+        }
         public string FullName
         {
             get
@@ -173,6 +214,25 @@ namespace ILRuntime.CLR.TypeSystem
             }
         }
 
+        public ValueTypeBinder ValueTypeBinder
+        {
+            get
+            {
+                if (clrType.IsValueType)
+                {
+                    if (!valueTypeBinderGot)
+                    {
+                        valueTypeBinderGot = true;
+                        if (appdomain.ValueTypeBinders.TryGetValue(clrType, out valueTypeBinder))
+                            valueTypeBinder.CLRType = this;
+                    }
+                    return valueTypeBinder;
+                }
+                else
+                    return null;
+            }
+        }
+
         public object PerformMemberwiseClone(object target)
         {
             if (memberwiseCloneDelegate == null)
@@ -366,15 +426,27 @@ namespace ILRuntime.CLR.TypeSystem
             fieldInfoCache = new Dictionary<int, FieldInfo>();
 
             var fields = clrType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
+            int idx = 0;
+            bool hasValueTypeBinder = ValueTypeBinder != null;
+            if (hasValueTypeBinder)
+            {
+                fieldIdxMapping = new Dictionary<int, int>();
+                orderedFieldTypes = new IType[fields.Length];
+            }
             foreach (var i in fields)
             {
                 int hashCode = i.GetHashCode();
 
-                if (i.IsPublic || i.IsFamily)
+                if (i.IsPublic || i.IsFamily || hasValueTypeBinder)
                 {
                     fieldMapping[i.Name] = hashCode;
                     fieldInfoCache[hashCode] = i;
                 }
+                if (hasValueTypeBinder && !i.IsStatic)
+                {
+                    orderedFieldTypes[idx] = appdomain.GetType(i.FieldType);
+                    fieldIdxMapping[hashCode] = idx++;
+                }
 
                 CLRFieldGetterDelegate getter;
                 if (AppDomain.FieldGetterMap.TryGetValue(i, out getter))
@@ -422,7 +494,7 @@ namespace ILRuntime.CLR.TypeSystem
             }
             return null;
         }
-        public IMethod GetMethod(string name, int paramCount)
+        public IMethod GetMethod(string name, int paramCount, bool declaredOnly = false)
         {
             if (methods == null)
                 InitializeMethods();
@@ -438,7 +510,7 @@ namespace ILRuntime.CLR.TypeSystem
             return null;
         }
 
-        public IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null)
+        public IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null, bool declaredOnly = false)
         {
             if (methods == null)
                 InitializeMethods();
@@ -661,5 +733,10 @@ namespace ILRuntime.CLR.TypeSystem
                 hashCode = System.Threading.Interlocked.Add(ref instance_id, 1);
             return hashCode;
         }
+
+        public override string ToString()
+        {
+            return clrType.ToString();
+        }
     }
 }

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/CLRType.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 77e1f51e465e9e24ba3a42bb88b7ad34
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 7 - 2
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/ILGenericParameterType.cs

@@ -45,12 +45,12 @@ namespace ILRuntime.CLR.TypeSystem
             get { return null; }
         }
 
-        public Method.IMethod GetMethod(string name, int paramCount)
+        public Method.IMethod GetMethod(string name, int paramCount, bool declaredOnly = false)
         {
             return null;
         }
 
-        public Method.IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null)
+        public Method.IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null, bool declaredOnly = false)
         {
             return null;
         }
@@ -122,6 +122,11 @@ namespace ILRuntime.CLR.TypeSystem
             get { throw new NotImplementedException(); }
         }
 
+        public bool IsPrimitive
+        {
+            get { return false; }
+        }
+
         public string Name
         {
             get

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/ILGenericParameterType.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: ea169e3908d84da4088fc6eae41d3c41
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 39 - 12
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/ILType.cs

@@ -278,19 +278,18 @@ namespace ILRuntime.CLR.TypeSystem
             }
         }
 
+        public bool IsPrimitive
+        {
+            get { return false; }
+        }
+
         public Type TypeForCLR
         {
             get
             {
                 if (!baseTypeInitialized)
                     InitializeBaseType();
-                if (definition.IsEnum)
-                {
-                    if (enumType == null)
-                        InitializeFields();
-                    return enumType.TypeForCLR;
-                }
-                else if (typeRef is ArrayType)
+                if (typeRef is ArrayType)
                 {
                     return arrayCLRType;
                 }
@@ -298,6 +297,12 @@ namespace ILRuntime.CLR.TypeSystem
                 {
                     return byRefCLRType;
                 }
+                else if (definition.IsEnum)
+                {
+                    if (enumType == null)
+                        InitializeFields();
+                    return enumType.TypeForCLR;
+                }
                 else if (FirstCLRBaseType != null && FirstCLRBaseType is CrossBindingAdaptor)
                 {
                     return ((CrossBindingAdaptor)FirstCLRBaseType).RuntimeType.TypeForCLR;
@@ -505,7 +510,7 @@ namespace ILRuntime.CLR.TypeSystem
             return null;
         }
 
-        public IMethod GetMethod(string name, int paramCount)
+        public IMethod GetMethod(string name, int paramCount, bool declaredOnly = false)
         {
             if (methods == null)
                 InitializeMethods();
@@ -518,7 +523,16 @@ namespace ILRuntime.CLR.TypeSystem
                         return i;
                 }
             }
-            return null;
+            if (declaredOnly)
+                return null;
+            else
+            {
+                //skip clr base type, this doesn't make any sense
+                if (BaseType != null && !(BaseType is CrossBindingAdaptor))
+                    return BaseType.GetMethod(name, paramCount, false);
+                else
+                    return null;
+            }
         }
 
         void InitializeMethods()
@@ -568,7 +582,7 @@ namespace ILRuntime.CLR.TypeSystem
                 }
             }
 
-            var m = GetMethod(method.Name, method.Parameters, genericArguments, method.ReturnType);
+            var m = GetMethod(method.Name, method.Parameters, genericArguments, method.ReturnType, true);
             if (m == null)
             {
                 if (BaseType != null)
@@ -584,7 +598,7 @@ namespace ILRuntime.CLR.TypeSystem
                 return method;
         }
 
-        public IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null)
+        public IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null, bool declaredOnly = false)
         {
             if (methods == null)
                 InitializeMethods();
@@ -632,7 +646,15 @@ namespace ILRuntime.CLR.TypeSystem
                 lst.Add((ILMethod)m);
                 return m;
             }
-            return null;
+            if (declaredOnly)
+                return null;
+            else
+            {
+                if (BaseType != null)
+                    return BaseType.GetMethod(name, param, genericArguments, returnType, false);
+                else
+                    return null;
+            }
         }
 
         bool CheckGenericArguments(ILMethod i, IType[] genericArguments)
@@ -1002,5 +1024,10 @@ namespace ILRuntime.CLR.TypeSystem
                 hashCode = System.Threading.Interlocked.Add(ref instance_id, 1);
             return hashCode;
         }
+
+        public override string ToString()
+        {
+            return FullName;
+        }
     }
 }

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/ILType.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: a657d8c53554fdb498c23061939379d5
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 20 - 3
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/IType.cs

@@ -32,13 +32,30 @@ namespace ILRuntime.CLR.TypeSystem
 
         bool IsDelegate { get; }
 
+        bool IsPrimitive { get; }
+
         bool HasGenericParameter { get; }
 
         ILRuntime.Runtime.Enviorment.AppDomain AppDomain { get; }
 
-        IMethod GetMethod(string name, int paramCount);
-
-        IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null);
+        /// <summary>
+        /// Get a specified Method in this type
+        /// </summary>
+        /// <param name="name">Name of the Type</param>
+        /// <param name="paramCount">Parameter count</param>
+        /// <param name="declaredOnly">True to search the methods decleared in this type only, false to search base types.</param>
+        /// <returns></returns>
+        IMethod GetMethod(string name, int paramCount, bool declaredOnly = false);
+        /// <summary>
+        ///  Get a specified Method in this type
+        /// </summary>
+        /// <param name="name">Name of the Type</param>
+        /// <param name="param">List of parameter's types</param>
+        /// <param name="genericArguments">List of Generic Arguments</param>
+        /// <param name="returnType">Return Type</param>
+        /// <param name="declaredOnly">True to search the methods decleared in this type only, false to search base types.</param>
+        /// <returns></returns>
+        IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null, bool declaredOnly = false);
         IMethod GetVirtualMethod(IMethod method);
 
         List<IMethod> GetMethods();

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/TypeSystem/IType.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 2d59f9c8b6bc1b542a95502fa20ddea8
-timeCreated: 1503890050
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/CLR/Utils/Extensions.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: ed1e47ba193179f4b9f21caedbc1b605
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/ByReferenceKeyComparer.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 85b57f58903421241b65cd2ffbcac7bf
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/DelegateExportAttribute.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: eb007a85cca9ce54ea6e3b32ab7ddceb
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/NeedAdaptorAttribute.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: fd1e000bd78872247b5ee948842785e9
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/ThreadSafeDictionary.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: e45123ef096e7a446a6ccd805feaf05e
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Other/UncheckedList.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: d923aa25f3f74d0489a9082f6a6c9942
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/Extensions.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: ccb5490caeef4b7419ab1fc0690f19bd
-timeCreated: 1503890052
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeConstructorInfo.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 205a4012c9bebf742b9ebdc7fcb24bff
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeFieldInfo.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 05340a76bcd08e843b481e980988b984
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeMethodInfo.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: e975e373cbb39824c9dbf99b5b834f76
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeParameterInfo.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: fb4bb43a033c2ee45b6957d7b7ae8b28
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimePropertyInfo.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 15c350fc8adaa6d43b32f054dacecead
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 2 - 2
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeType.cs

@@ -409,8 +409,8 @@ namespace ILRuntime.Reflection
                         param.Add(t);
                     }
                 }
-
-                res = type.GetMethod(name, param, null);
+                bool declearedOnly = (bindingAttr & BindingFlags.DeclaredOnly) == BindingFlags.DeclaredOnly;
+                res = type.GetMethod(name, param, null, null, declearedOnly);
             }
             if (res != null)
                 return ((ILMethod)res).ReflectionMethodInfo;

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeType.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: f3a1f2fbaeb2b8446a4001bf4537351d
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Reflection/ILRuntimeWrapperType.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: eaefbb07ad715ce489ab00dd2080222f
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Adaptors/CLRCrossBindingAdaptors.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 9c62df830a323ae4185db20e52d0a559
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/BindingCodeGenerator.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 4e7ba7f4b3e5e4843a17ebdf3ff249ef
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/BindingGeneratorExtensions.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 3e91768ea7d0ed240bd26b8251c32ee8
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/CommonBindingGenerator.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: d2c990d8ba791ea41bdf7f8a58a4a713
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/ConstructorBindingGenerator.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 531c09b4001f4574dbe7f989aef71c18
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/FieldBindingGenerator.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 9c0373a996c429f46ac5a2a2711f1793
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/MethodBindingGenerator.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 3e7a4b0b251e3c24bbc7fbb93dc9d799
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/CLRBinding/ValueTypeBindingGenerator.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 668af796108e80c408d8997b279d5728
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/BreakPointContext.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: bfeefe6a2f833e2459c51dec09120b28
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/BreakpointInfo.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: c1e1d9861d746594485e121a90ef9c38
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebugMessageType.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: a564f69cbf727c844bb66d4ef14055b8
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 143 - 0
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebugService.cs

@@ -496,5 +496,148 @@ namespace ILRuntime.Runtime.Debugger
                 j.Value.Resume();
             }
         }
+
+        internal unsafe void DumpStack(StackObject* esp, RuntimeStack stack)
+        {
+#if !UNITY_5 && !UNITY_2017 && !UNITY_4
+            var start = stack.StackBase;
+            var end = esp + 10;
+            var frames = stack.Frames;
+            var mStack = stack.ManagedStack;
+            var valuePointerEnd = stack.ValueTypeStackPointer;
+            HashSet<long> leakVObj = new HashSet<long>();
+            for (var i = stack.ValueTypeStackBase; i > stack.ValueTypeStackPointer;)
+            {
+                leakVObj.Add((long)i);
+                i = Minus(i, i->ValueLow + 1);
+            }
+            for (var i = start; i <= end; i++)
+            {
+                StringBuilder sb = new StringBuilder();
+                ILMethod localMethod = null, baseMethod = null;
+                bool isLocal = false;
+                bool isBase = false;
+                int localIdx = 0;
+                if (i == esp)
+                    sb.Append("->");
+                foreach (var j in frames)
+                {
+                    if (i >= j.LocalVarPointer && i < j.BasePointer)
+                    {
+                        isLocal = true;
+                        localIdx = (int)(i - j.LocalVarPointer);
+                        localMethod = j.Method;
+                    }
+                    else if (i == j.BasePointer)
+                    {
+                        isBase = true;
+                        baseMethod = j.Method;
+                    }
+                }
+                sb.Append(string.Format("(0x{0:X8}) Type:{1} ", (long)i, i->ObjectType));
+                GetStackObjectText(sb, i, mStack, valuePointerEnd);
+                if (i < esp)
+                {
+                    if (i->ObjectType == ObjectTypes.ValueTypeObjectReference)
+                        VisitValueTypeReference(*(StackObject**)&i->Value, leakVObj);
+                }
+                if (isLocal)
+                {
+                    sb.Append(string.Format("|Loc:{0}", localIdx));
+                    if (localIdx == 0)
+                    {
+                        sb.Append(" Method:");
+                        sb.Append(localMethod.ToString());
+                    }
+                }
+                if (isBase)
+                {
+                    sb.Append("|Base");
+                    sb.Append(" Method:");
+                    sb.Append(baseMethod.ToString());
+                }
+
+                System.Diagnostics.Debug.Print(sb.ToString());
+            }
+
+            for (var i = stack.ValueTypeStackBase; i > stack.ValueTypeStackPointer;)
+            {
+                var vt = domain.GetType(i->Value);
+                var cnt = i->ValueLow;
+                bool leak = leakVObj.Contains((long)i);
+                System.Diagnostics.Debug.Print("----------------------------------------------");
+                System.Diagnostics.Debug.Print(string.Format("{2}(0x{0:X8}){1}", (long)i, vt, leak ? "*" : ""));
+                for (int j = 0; j < cnt; j++)
+                {
+                    StringBuilder sb = new StringBuilder();
+                    var ptr = Minus(i, j + 1);
+                    sb.Append(string.Format("(0x{0:X8}) Type:{1} ", (long)ptr, ptr->ObjectType));
+                    GetStackObjectText(sb, ptr, mStack, valuePointerEnd);
+                    System.Diagnostics.Debug.Print(sb.ToString());
+                }
+                i = Minus(i, i->ValueLow + 1);
+            }
+            System.Diagnostics.Debug.Print("Managed Objects:");
+            for (int i = 0; i < mStack.Count; i++)
+            {
+                System.Diagnostics.Debug.Print(string.Format("({0}){1}", i, mStack[i]));
+            }
+#endif
+        }
+
+        unsafe void GetStackObjectText(StringBuilder sb, StackObject* esp, IList<object> mStack, StackObject* valueTypeEnd)
+        {
+            string text = "null";
+            switch (esp->ObjectType)
+            {
+                case ObjectTypes.StackObjectReference:
+                    {
+                        sb.Append(string.Format("Value:0x{0:X8}", (long)*(StackObject**)&esp->Value));
+                    }
+                    break;
+                case ObjectTypes.ValueTypeObjectReference:
+                    {
+                        object obj = null;
+                        var dst = *(StackObject**)&esp->Value;
+                        if (dst > valueTypeEnd)
+                            obj = StackObject.ToObject(esp, domain, mStack);
+                        if (obj != null)
+                            text = obj.ToString();
+
+                        text += string.Format("({0})", domain.GetType(dst->Value));
+                    }
+                    sb.Append(string.Format("Value:0x{0:X8} Text:{1} ", (long)*(StackObject**)&esp->Value, text));
+                    break;
+                default:
+                    {
+                        if (esp->ObjectType >= ObjectTypes.Null && esp->ObjectType <= ObjectTypes.ArrayReference)
+                        {
+                            if (esp->ObjectType < ObjectTypes.Object || esp->Value < mStack.Count)
+                            {
+                                var obj = StackObject.ToObject(esp, domain, mStack);
+                                if (obj != null)
+                                    text = obj.ToString();
+                            }
+                        }
+
+                        sb.Append(string.Format("Value:{0} ValueLow:{1} Text:{2} ", esp->Value, esp->ValueLow, text));
+                    }
+                    break;
+
+            }
+        }
+
+        unsafe void VisitValueTypeReference(StackObject* esp, HashSet<long> leak)
+        {
+            leak.Remove((long)esp);
+            for (int i = 0; i < esp->ValueLow; i++)
+            {
+                var ptr = Minus(esp, i + 1);
+                if (ptr->ObjectType == ObjectTypes.ValueTypeObjectReference)
+                {
+                    VisitValueTypeReference(*(StackObject**)&ptr->Value, leak);
+                }
+            }
+        }
     }
 }

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebugService.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: bca0b6c7c373ab74b96df13b5517171c
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebugSocket.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: e514adc780b8fd94d94c8bedf0cdc91f
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/DebuggerServer/DebuggerServer.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 52306472508bb034f8fd1b68d450ce8e
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSBindBreakpoint.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: aa0ea609114467a41941ebad10e2c081
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSDeleteBreakpoint.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 58263d5697f506248a2a9fe66a69f3b1
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSExecute.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 3a64e6abaa6367e4c86c71f47955ef15
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSResolveVariable.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 04bf766da67e49947812303010492217
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/CSStep.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 58bb0ff22cedb204ba27ae8a3653c925
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCAttachResult.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 4a95d12ad4b5f1e48b98c5dde9dcabf8
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCBindBreakpointResult.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 1a7539c200fc96b439bf2ecc8e06cb98
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCBreakpointHit.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 22bab0c3783302649afbacc7867f772a
-timeCreated: 1503890050
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCModuleLoaded.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 35a24baf8e5f2bd46a4a2a0352dc0bb8
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCResolveVariableResult.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: fd3187a64b8594444922906ec3e35098
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCStepComplete.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 0ed50f6dc3504124992baf704ff5bc3d
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/Protocol/SCThreadStarted.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 16dba5b2425526c41b18b579235f963a
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/StackFrameInfo.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 1990fb3b0c78d1344b541383b5b4f514
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/StepTypes.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: a9a918bf142c65744901f224ebcabd4d
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Debugger/VariableInfo.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: ba46157c0b55fee46b03f075c5c7668e
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 13 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/AppDomain.cs

@@ -28,6 +28,7 @@ namespace ILRuntime.Runtime.Enviorment
         Queue<ILIntepreter> freeIntepreters = new Queue<ILIntepreter>();
         Dictionary<int, ILIntepreter> intepreters = new Dictionary<int, ILIntepreter>();
         Dictionary<Type, CrossBindingAdaptor> crossAdaptors = new Dictionary<Type, CrossBindingAdaptor>(new ByReferenceKeyComparer<Type>());
+        Dictionary<Type, ValueTypeBinder> valueTypeBinders = new Dictionary<Type, ValueTypeBinder>();
         ThreadSafeDictionary<string, IType> mapType = new ThreadSafeDictionary<string, IType>();
         Dictionary<Type, IType> clrTypeMapping = new Dictionary<Type, IType>(new ByReferenceKeyComparer<Type>());
         ThreadSafeDictionary<int, IType> mapTypeToken = new ThreadSafeDictionary<int, IType>();
@@ -141,6 +142,7 @@ namespace ILRuntime.Runtime.Enviorment
         internal Dictionary<Type, CLRCreateDefaultInstanceDelegate> CreateDefaultInstanceMap { get { return createDefaultInstanceMap; } }
         internal Dictionary<Type, CLRCreateArrayInstanceDelegate> CreateArrayInstanceMap { get { return createArrayInstanceMap; } }
         internal Dictionary<Type, CrossBindingAdaptor> CrossBindingAdaptors { get { return crossAdaptors; } }
+        internal Dictionary<Type, ValueTypeBinder> ValueTypeBinders { get { return valueTypeBinders; } }
         public DebugService DebugService { get { return debugService; } }
         internal Dictionary<int, ILIntepreter> Intepreters { get { return intepreters; } }
         internal Queue<ILIntepreter> FreeIntepreters { get { return freeIntepreters; } }
@@ -437,6 +439,15 @@ namespace ILRuntime.Runtime.Enviorment
                 createArrayInstanceMap[t] = createArray;
         }
 
+        public void RegisterValueTypeBinder(Type t, ValueTypeBinder binder)
+        {
+            if (!valueTypeBinders.ContainsKey(t))
+            {
+                valueTypeBinders[t] = binder;
+                binder.RegisterCLRRedirection(this);
+            }
+        }
+
         /// <summary>
         /// 更近类型名称返回类型
         /// </summary>
@@ -1091,7 +1102,7 @@ namespace ILRuntime.Runtime.Enviorment
                 method = type.GetConstructor(paramList);
             else
             {
-                method = type.GetMethod(methodname, paramList, genericArguments, returnType);
+                method = type.GetMethod(methodname, paramList, genericArguments, returnType, true);
             }
 
             if (method == null)
@@ -1193,6 +1204,7 @@ namespace ILRuntime.Runtime.Enviorment
         public void RegisterCrossBindingAdaptor(CrossBindingAdaptor adaptor)
         {
             var bType = adaptor.BaseCLRType;
+            
             if (bType != null)
             {
                 if (!crossAdaptors.ContainsKey(bType))

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/AppDomain.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 7e82484243e934c46b52e732ea60be5a
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/CLRRedirections.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: f69628ad8b7de48438cc264443cb5c7c
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 12 - 4
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/CrossBindingAdaptor.cs

@@ -42,14 +42,14 @@ namespace ILRuntime.Runtime.Enviorment
 
         #region IType Members
 
-        public IMethod GetMethod(string name, int paramCount)
+        public IMethod GetMethod(string name, int paramCount, bool declaredOnly = false)
         {
-            return type.GetMethod(name, paramCount);
+            return type.GetMethod(name, paramCount, declaredOnly);
         }
 
-        public IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null)
+        public IMethod GetMethod(string name, List<IType> param, IType[] genericArguments, IType returnType = null, bool declaredOnly = false)
         {
-            return type.GetMethod(name, param, genericArguments, returnType);
+            return type.GetMethod(name, param, genericArguments, returnType, declaredOnly);
         }
 
         public List<IMethod> GetMethods()
@@ -180,6 +180,14 @@ namespace ILRuntime.Runtime.Enviorment
             }
         }
 
+        public bool IsPrimitive
+        {
+            get
+            {
+                return type.IsPrimitive;
+            }
+        }
+
         public bool IsDelegate
         {
             get

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/CrossBindingAdaptor.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 89b5db64481707c44b294daa538d54df
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/DelegateManager.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: ea8e4e6294992d0489b4f3671c3a7b5e
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 114 - 0
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/ValueTypeBinder.cs

@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ILRuntime.CLR.Method;
+using ILRuntime.CLR.TypeSystem;
+using ILRuntime.Runtime.Enviorment;
+using ILRuntime.Runtime.Stack;
+
+namespace ILRuntime.Runtime.Enviorment
+{
+    public unsafe abstract class ValueTypeBinder
+    {
+        CLRType clrType;
+        Enviorment.AppDomain domain;
+
+        public CLRType CLRType
+        {
+            get { return clrType; }
+            set
+            {
+                if (clrType == null)
+                {
+                    clrType = value;
+                    domain = value.AppDomain;
+                }
+                else
+                    throw new NotSupportedException();
+            }
+        }
+
+        public abstract void CopyValueTypeToStack(object ins, StackObject* ptr, IList<object> mStack);
+
+        public abstract object ToObject(StackObject* esp, IList<object> managedStack);
+
+        public virtual void RegisterCLRRedirection(Enviorment.AppDomain appdomain)
+        {
+
+        }
+
+        protected void CopyValueTypeToStack<K>(ref K ins, StackObject* esp, IList<object> mStack)
+            where K : struct
+        {
+            switch (esp->ObjectType)
+            {
+                case ObjectTypes.ValueTypeObjectReference:
+                    {
+                        var dst = *(StackObject**)&esp->Value;
+                        var vb = ((CLRType)domain.GetType(dst->Value)).ValueTypeBinder as ValueTypeBinder<K>;
+                        if (vb != null)
+                        {
+                            vb.CopyValueTypeToStack(ref ins, dst, mStack);
+                        }
+                        else
+                            throw new NotSupportedException();
+                    }
+                    break;
+                case ObjectTypes.Object:
+                    mStack[esp->Value] = ins;
+                    break;
+                default:
+                    throw new NotImplementedException();
+            }
+        }
+
+        protected void AssignFromStack<K>(ref K ins, StackObject* esp, IList<object> mStack)
+            where K : struct
+        {
+            switch (esp->ObjectType)
+            {
+                case ObjectTypes.Null:
+                    throw new NullReferenceException();
+                case ObjectTypes.Object:
+                    ins = (K)mStack[esp->Value];
+                    break;
+                case ObjectTypes.ValueTypeObjectReference:
+                    {
+                        var dst = *(StackObject**)&esp->Value;
+                        var vb = ((CLRType)domain.GetType(dst->Value)).ValueTypeBinder as ValueTypeBinder<K>;
+                        if (vb != null)
+                        {
+                            vb.AssignFromStack(ref ins, dst, mStack);
+                        }
+                        else
+                            throw new NotSupportedException();
+                    }
+                    break;
+                default:
+                    throw new NotImplementedException();
+            }
+        }        
+    }
+
+    public unsafe abstract class ValueTypeBinder<T> : ValueTypeBinder
+        where T : struct
+    {
+        public override unsafe void CopyValueTypeToStack(object ins, StackObject* ptr, IList<object> mStack)
+        {
+            T obj = (T)ins;
+            CopyValueTypeToStack(ref obj, ptr, mStack);
+        }
+
+        public abstract void CopyValueTypeToStack(ref T ins, StackObject* ptr, IList<object> mStack);
+
+        public override unsafe object ToObject(StackObject* esp, IList<object> managedStack)
+        {
+            T obj = new T();
+            AssignFromStack(ref obj, esp, managedStack);
+            return obj;
+        }
+
+        public abstract void AssignFromStack(ref T ins, StackObject* ptr, IList<object> mStack);
+    }
+}

+ 2 - 2
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.Mdb/mdb/Mono.Cecil.Mdb/MdbReaderProvider.cs.meta → Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Enviorment/ValueTypeBinder.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
-guid: 060825de908097b40b85436fd816af4c
-timeCreated: 1503890049
+guid: da1fec14f676a0444b5f6b09e4bf0bfd
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Extensions.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: cd8de1ae799f1ca47a32ba07ea2a5bf8
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/DelegateAdapter.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: a6dd5ad6790a01b468a803875deb4a3f
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 439 - 237
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILIntepreter.cs

@@ -27,6 +27,7 @@ namespace ILRuntime.Runtime.Intepreter
         public StepTypes CurrentStepType { get; set; }
         public StackObject* LastStepFrameBase { get; set; }
         public int LastStepInstructionIndex { get; set; }
+        StackObject* ValueTypeBasePointer;
         public ILIntepreter(Enviorment.AppDomain domain)
         {
             this.domain = domain;
@@ -65,6 +66,7 @@ namespace ILRuntime.Runtime.Intepreter
             IList<object> mStack = stack.ManagedStack;
             int mStackBase = mStack.Count;
             StackObject* esp = stack.StackBase;
+            stack.ResetValueTypePointer();
             if (method.HasThis)
             {
                 if (instance is CrossBindingAdaptorType)
@@ -131,6 +133,9 @@ namespace ILRuntime.Runtime.Intepreter
                         a->Value = mStack.Count;
                         mStack.Add(null);
                         break;
+                    case ObjectTypes.ValueTypeObjectReference:
+                        CloneStackValueType(a, a, mStack);
+                        break;
                     case ObjectTypes.Object:
                     case ObjectTypes.FieldReference:
                     case ObjectTypes.ArrayReference:
@@ -143,6 +148,11 @@ namespace ILRuntime.Runtime.Intepreter
 
             int locBase = mStack.Count;
             //Managed Stack reserved for local variable
+            for (int i = 0; i < method.LocalVariableCount; i++)
+            {
+                mStack.Add(null);
+            }
+
             for (int i = 0; i < method.LocalVariableCount; i++)
             {
                 var v = method.Variables[i];
@@ -151,19 +161,30 @@ namespace ILRuntime.Runtime.Intepreter
                     var t = AppDomain.GetType(v.VariableType, method.DeclearingType, method);
                     if (t is ILType)
                     {
-                        var obj = ((ILType)t).Instantiate(false);
+                        //var obj = ((ILType)t).Instantiate(false);
                         var loc = Add(v1, i);
-                        loc->ObjectType = ObjectTypes.Object;
+                        stack.AllocValueType(loc, t);
+
+                        /*loc->ObjectType = ObjectTypes.Object;
                         loc->Value = mStack.Count;
-                        mStack.Add(obj);
+                        mStack.Add(obj);*/
+
                     }
                     else
                     {
-                        var obj = ((CLRType) t).CreateDefaultInstance();
+                        CLRType cT = (CLRType)t;
                         var loc = Add(v1, i);
-                        loc->ObjectType = ObjectTypes.Object;
-                        loc->Value = mStack.Count;
-                        mStack.Add(obj);
+                        if (cT.ValueTypeBinder != null)
+                        {
+                            stack.AllocValueType(loc, t);
+                        }
+                        else
+                        {
+                            var obj = ((CLRType)t).CreateDefaultInstance();
+                            loc->ObjectType = ObjectTypes.Object;
+                            loc->Value = locBase + i;
+                            mStack[locBase + i] = obj;
+                        }
                     }
                 }
                 else
@@ -172,17 +193,18 @@ namespace ILRuntime.Runtime.Intepreter
                     {
                         var t = AppDomain.GetType(v.VariableType, method.DeclearingType, method);
                         var loc = Add(v1, i);
-                        StackObject.Initialized(loc, t.TypeForCLR);
+                        StackObject.Initialized(loc, t);
                     }
                     else
                     {
                         var loc = Add(v1, i);
                         loc->ObjectType = ObjectTypes.Object;
-                        loc->Value = mStack.Count;
+                        loc->Value = locBase + i;
                     }
-                    mStack.Add(null);
                 }
             }
+            var bp = stack.ValueTypeStackPointer;
+            ValueTypeBasePointer = bp;
             fixed (OpCode* ptr = body)
             {
                 OpCode* ip = ptr;
@@ -265,26 +287,8 @@ namespace ILRuntime.Runtime.Intepreter
                             case OpCodeEnum.Stloc_0:
                                 {
                                     esp--;
-                                    *v1 = *esp;
                                     int idx = locBase;
-                                    switch (esp->ObjectType)
-                                    {
-                                        case ObjectTypes.Null:
-                                            v1->ObjectType = ObjectTypes.Object;
-                                            v1->Value = idx;
-                                            mStack[idx] = null;
-                                            break;
-                                        case ObjectTypes.Object:
-                                        case ObjectTypes.FieldReference:
-                                        case ObjectTypes.ArrayReference:
-                                            mStack[idx] = CheckAndCloneValueType(mStack[v1->Value], domain);
-                                            v1->Value = idx;
-                                            Free(esp);
-                                            break;
-                                        default:
-                                            mStack[idx] = null;
-                                            break;
-                                    }
+                                    StLocSub(esp, v1, bp, idx, mStack);
                                 }
                                 break;
                             case OpCodeEnum.Ldloc_0:
@@ -294,26 +298,8 @@ namespace ILRuntime.Runtime.Intepreter
                             case OpCodeEnum.Stloc_1:
                                 {
                                     esp--;
-                                    *v2 = *esp;
                                     int idx = locBase + 1;
-                                    switch (esp->ObjectType)
-                                    {
-                                        case ObjectTypes.Null:
-                                            v2->ObjectType = ObjectTypes.Object;
-                                            v2->Value = idx;
-                                            mStack[idx] = null;
-                                            break;
-                                        case ObjectTypes.Object:
-                                        case ObjectTypes.FieldReference:
-                                        case ObjectTypes.ArrayReference:
-                                            mStack[idx] = CheckAndCloneValueType(mStack[v2->Value], domain);
-                                            v2->Value = idx;
-                                            Free(esp);
-                                            break;
-                                        default:
-                                            mStack[idx] = null;
-                                            break;
-                                    }
+                                    StLocSub(esp, v2, bp, idx, mStack);
                                 }
                                 break;
                             case OpCodeEnum.Ldloc_1:
@@ -323,26 +309,8 @@ namespace ILRuntime.Runtime.Intepreter
                             case OpCodeEnum.Stloc_2:
                                 {
                                     esp--;
-                                    *v3 = *esp;
                                     int idx = locBase + 2;
-                                    switch (esp->ObjectType)
-                                    {
-                                        case ObjectTypes.Null:
-                                            v3->ObjectType = ObjectTypes.Object;
-                                            v3->Value = idx;
-                                            mStack[idx] = null;
-                                            break;
-                                        case ObjectTypes.Object:
-                                        case ObjectTypes.FieldReference:
-                                        case ObjectTypes.ArrayReference:
-                                            mStack[idx] = CheckAndCloneValueType(mStack[v3->Value], domain);
-                                            v3->Value = idx;
-                                            Free(esp);
-                                            break;
-                                        default:
-                                            mStack[idx] = null;
-                                            break;
-                                    }
+                                    StLocSub(esp, v3, bp, idx, mStack);
                                     break;
                                 }
                             case OpCodeEnum.Ldloc_2:
@@ -352,26 +320,9 @@ namespace ILRuntime.Runtime.Intepreter
                             case OpCodeEnum.Stloc_3:
                                 {
                                     esp--;
-                                    *v4 = *esp;
                                     int idx = locBase + 3;
-                                    switch (esp->ObjectType)
-                                    {
-                                        case ObjectTypes.Null:
-                                            v4->ObjectType = ObjectTypes.Object;
-                                            v4->Value = idx;
-                                            mStack[idx] = null;
-                                            break;
-                                        case ObjectTypes.Object:
-                                        case ObjectTypes.FieldReference:
-                                        case ObjectTypes.ArrayReference:
-                                            mStack[idx] = CheckAndCloneValueType(mStack[v4->Value], domain);
-                                            v4->Value = idx;
-                                            Free(esp);
-                                            break;
-                                        default:
-                                            mStack[idx] = null;
-                                            break;
-                                    }
+
+                                    StLocSub(esp, v4, bp, idx, mStack);
                                 }
                                 break;
                             case OpCodeEnum.Ldloc_3:
@@ -383,26 +334,8 @@ namespace ILRuntime.Runtime.Intepreter
                                 {
                                     esp--;
                                     var v = Add(frame.LocalVarPointer, ip->TokenInteger);
-                                    *v = *esp;
                                     int idx = locBase + ip->TokenInteger;
-                                    switch (esp->ObjectType)
-                                    {
-                                        case ObjectTypes.Null:
-                                            v->ObjectType = ObjectTypes.Object;
-                                            v->Value = idx;
-                                            mStack[idx] = null;
-                                            break;
-                                        case ObjectTypes.Object:
-                                        case ObjectTypes.FieldReference:
-                                        case ObjectTypes.ArrayReference:
-                                            mStack[idx] = CheckAndCloneValueType(mStack[v->Value], domain);
-                                            v->Value = idx;
-                                            Free(esp);
-                                            break;
-                                        default:
-                                            mStack[idx] = null;
-                                            break;
-                                    }
+                                    StLocSub(esp, v, bp, idx, mStack);
                                 }
                                 break;
                             case OpCodeEnum.Ldloc:
@@ -1715,6 +1648,7 @@ namespace ILRuntime.Runtime.Intepreter
                                                     ilm = ((ILTypeInstance)obj).Type.GetVirtualMethod(ilm) as ILMethod;
                                                 }
                                                 esp = Execute(ilm, esp, out unhandledException);
+                                                ValueTypeBasePointer = bp;
                                                 if (unhandledException)
                                                     returned = true;
                                             }
@@ -1793,73 +1727,85 @@ namespace ILRuntime.Runtime.Intepreter
                             case OpCodeEnum.Stfld:
                                 {
                                     var objRef = GetObjectAndResolveReference(esp - 1 - 1);
-                                    object obj = RetriveObject(objRef, mStack);
-
-                                    if (obj != null)
+                                    if (objRef->ObjectType == ObjectTypes.ValueTypeObjectReference)
                                     {
-                                        if (obj is ILTypeInstance)
-                                        {
-                                            ILTypeInstance instance = obj as ILTypeInstance;
-                                            StackObject* val = esp - 1;
-                                            instance.AssignFromStack((int)ip->TokenLong, val, AppDomain, mStack);
-                                        }
+                                        StackObject* dst = *(StackObject**)&objRef->Value;
+                                        var ft = domain.GetType(dst->Value);
+                                        if (ft is ILType)
+                                            CopyToValueTypeField(dst, (int)ip->TokenLong, esp - 1, mStack);
                                         else
+                                            CopyToValueTypeField(dst, ((CLRType)ft).FieldIndexMapping[(int)ip->TokenLong], esp - 1, mStack);
+                                    }
+                                    else
+                                    {
+                                        object obj = RetriveObject(objRef, mStack);
+
+                                        if (obj != null)
                                         {
-                                            var t = obj.GetType();
-                                            var type = AppDomain.GetType((int)(ip->TokenLong >> 32));
-                                            if (type != null)
+                                            if (obj is ILTypeInstance)
                                             {
-                                                var val = esp - 1;
-                                                var fieldToken = (int)ip->TokenLong;
-                                                var f = ((CLRType)type).GetField(fieldToken);
-                                                ((CLRType)type).SetFieldValue(fieldToken, ref obj, f.FieldType.CheckCLRTypes(CheckAndCloneValueType(StackObject.ToObject(val, domain, mStack), domain)));
-                                                //Writeback
-                                                if (t.IsValueType)
+                                                ILTypeInstance instance = obj as ILTypeInstance;
+                                                StackObject* val = esp - 1;
+                                                instance.AssignFromStack((int)ip->TokenLong, val, AppDomain, mStack);
+                                            }
+                                            else
+                                            {
+                                                var t = obj.GetType();
+                                                var type = AppDomain.GetType((int)(ip->TokenLong >> 32));
+                                                if (type != null)
                                                 {
-                                                    switch (objRef->ObjectType)
+                                                    var val = esp - 1;
+                                                    var fieldToken = (int)ip->TokenLong;
+                                                    var f = ((CLRType)type).GetField(fieldToken);
+                                                    ((CLRType)type).SetFieldValue(fieldToken, ref obj, f.FieldType.CheckCLRTypes(CheckAndCloneValueType(StackObject.ToObject(val, domain, mStack), domain)));
+                                                    //Writeback
+                                                    if (t.IsValueType)
                                                     {
-                                                        case ObjectTypes.Object:
-                                                            break;
-                                                        case ObjectTypes.FieldReference:
-                                                            {
-                                                                var oldObj = mStack[objRef->Value];
-                                                                int idx = objRef->ValueLow;
-                                                                if (oldObj is ILTypeInstance)
-                                                                {
-                                                                    ((ILTypeInstance)oldObj)[idx] = obj;
-                                                                }
-                                                                else
-                                                                {
-                                                                    var it = AppDomain.GetType(oldObj.GetType());
-                                                                    ((CLRType)it).SetFieldValue(idx, ref oldObj, obj);
-                                                                }
-                                                            }
-                                                            break;
-                                                        case ObjectTypes.StaticFieldReference:
-                                                            {
-                                                                var it = AppDomain.GetType(objRef->Value);
-                                                                int idx = objRef->ValueLow;
-                                                                if (it is ILType)
+                                                        switch (objRef->ObjectType)
+                                                        {
+                                                            case ObjectTypes.Object:
+                                                                break;
+                                                            case ObjectTypes.FieldReference:
                                                                 {
-                                                                    ((ILType)it).StaticInstance[idx] = obj;
+                                                                    var oldObj = mStack[objRef->Value];
+                                                                    int idx = objRef->ValueLow;
+                                                                    if (oldObj is ILTypeInstance)
+                                                                    {
+                                                                        ((ILTypeInstance)oldObj)[idx] = obj;
+                                                                    }
+                                                                    else
+                                                                    {
+                                                                        var it = AppDomain.GetType(oldObj.GetType());
+                                                                        ((CLRType)it).SetFieldValue(idx, ref oldObj, obj);
+                                                                    }
                                                                 }
-                                                                else
+                                                                break;
+                                                            case ObjectTypes.StaticFieldReference:
                                                                 {
-                                                                    ((CLRType)it).SetStaticFieldValue(idx, obj);
+                                                                    var it = AppDomain.GetType(objRef->Value);
+                                                                    int idx = objRef->ValueLow;
+                                                                    if (it is ILType)
+                                                                    {
+                                                                        ((ILType)it).StaticInstance[idx] = obj;
+                                                                    }
+                                                                    else
+                                                                    {
+                                                                        ((CLRType)it).SetStaticFieldValue(idx, obj);
+                                                                    }
                                                                 }
-                                                            }
-                                                            break;
-                                                        default:
-                                                            throw new NotImplementedException();
+                                                                break;
+                                                            default:
+                                                                throw new NotImplementedException();
+                                                        }
                                                     }
                                                 }
+                                                else
+                                                    throw new TypeLoadException();
                                             }
-                                            else
-                                                throw new TypeLoadException();
                                         }
+                                        else
+                                            throw new NullReferenceException();
                                     }
-                                    else
-                                        throw new NullReferenceException();
                                     Free(esp - 1);
                                     Free(esp - 1 - 1);
                                     esp = esp - 1 - 1;
@@ -1868,61 +1814,92 @@ namespace ILRuntime.Runtime.Intepreter
                             case OpCodeEnum.Ldfld:
                                 {
                                     StackObject* objRef = GetObjectAndResolveReference(esp - 1);
-                                    object obj = RetriveObject(objRef, mStack);
-                                    Free(esp - 1);
-                                    if (obj != null)
+                                    if (objRef->ObjectType == ObjectTypes.ValueTypeObjectReference)
                                     {
-                                        if (obj is ILTypeInstance)
-                                        {
-                                            ILTypeInstance instance = obj as ILTypeInstance;
-                                            instance.PushToStack((int)ip->TokenLong, esp - 1, AppDomain, mStack);
-                                        }
+                                        var dst = *(StackObject**)&objRef->Value;
+                                        var ft = domain.GetType(dst->Value);
+                                        if (ft is ILType)
+                                            dst = Minus(dst, (int)ip->TokenLong + 1);
                                         else
+                                            dst = Minus(dst, ((CLRType)ft).FieldIndexMapping[(int)ip->TokenLong] + 1);
+                                        CopyToStack(objRef, dst, mStack);
+                                    }
+                                    else
+                                    {
+                                        object obj = RetriveObject(objRef, mStack);
+                                        Free(esp - 1);
+                                        if (obj != null)
                                         {
-                                            //var t = obj.GetType();
-                                            var type = AppDomain.GetType((int)(ip->TokenLong >> 32));
-                                            if (type != null)
+                                            if (obj is ILTypeInstance)
                                             {
-                                                var token = (int)ip->TokenLong;
-                                                var ft = ((CLRType)type).GetField(token);
-                                                var val = ((CLRType)type).GetFieldValue(token, obj);
-                                                if (val is CrossBindingAdaptorType)
-                                                    val = ((CrossBindingAdaptorType)val).ILInstance;
-                                                PushObject(esp - 1, mStack, val, ft.FieldType == typeof(object));
+                                                ILTypeInstance instance = obj as ILTypeInstance;
+                                                instance.PushToStack((int)ip->TokenLong, esp - 1, AppDomain, mStack);
                                             }
                                             else
-                                                throw new TypeLoadException();
+                                            {
+                                                //var t = obj.GetType();
+                                                var type = AppDomain.GetType((int)(ip->TokenLong >> 32));
+                                                if (type != null)
+                                                {
+                                                    var token = (int)ip->TokenLong;
+                                                    var ft = ((CLRType)type).GetField(token);
+                                                    var val = ((CLRType)type).GetFieldValue(token, obj);
+                                                    if (val is CrossBindingAdaptorType)
+                                                        val = ((CrossBindingAdaptorType)val).ILInstance;
+                                                    PushObject(esp - 1, mStack, val, ft.FieldType == typeof(object));
+                                                }
+                                                else
+                                                    throw new TypeLoadException();
+                                            }
                                         }
+                                        else
+                                            throw new NullReferenceException();
                                     }
-                                    else
-                                        throw new NullReferenceException();
-
                                 }
                                 break;
                             case OpCodeEnum.Ldflda:
                                 {
                                     StackObject* objRef = GetObjectAndResolveReference(esp - 1);
-                                    object obj = RetriveObject(objRef, mStack);
-
-                                    Free(esp - 1);
-                                    if (obj != null)
+                                    if (objRef->ObjectType == ObjectTypes.ValueTypeObjectReference)
                                     {
-                                        if (obj is ILTypeInstance)
+                                        var dst = esp - 1;
+                                        var ft = domain.GetType((int)(ip->TokenLong >> 32));
+                                        StackObject* fieldAddr;
+                                        if (ft is ILType)
                                         {
-                                            ILTypeInstance instance = obj as ILTypeInstance;
-                                            instance.PushFieldAddress((int)ip->TokenLong, esp - 1, mStack);
+                                            fieldAddr = Minus(*(StackObject**)&objRef->Value, (int)ip->TokenLong + 1);                                            
                                         }
                                         else
                                         {
-                                            objRef = esp - 1;
-                                            objRef->ObjectType = ObjectTypes.FieldReference;
-                                            objRef->Value = mStack.Count;
-                                            mStack.Add(obj);
-                                            objRef->ValueLow = (int)ip->TokenLong;
+                                            fieldAddr = Minus(*(StackObject**)&objRef->Value, ((CLRType)ft).FieldIndexMapping[(int)ip->TokenLong] + 1);
                                         }
+                                        dst->ObjectType = ObjectTypes.StackObjectReference;
+                                        *(StackObject**)&dst->Value = fieldAddr;
                                     }
                                     else
-                                        throw new NullReferenceException();
+                                    {
+                                        object obj = RetriveObject(objRef, mStack);
+
+                                        Free(esp - 1);
+                                        if (obj != null)
+                                        {
+                                            if (obj is ILTypeInstance)
+                                            {
+                                                ILTypeInstance instance = obj as ILTypeInstance;
+                                                instance.PushFieldAddress((int)ip->TokenLong, esp - 1, mStack);
+                                            }
+                                            else
+                                            {
+                                                objRef = esp - 1;
+                                                objRef->ObjectType = ObjectTypes.FieldReference;
+                                                objRef->Value = mStack.Count;
+                                                mStack.Add(obj);
+                                                objRef->ValueLow = (int)ip->TokenLong;
+                                            }
+                                        }
+                                        else
+                                            throw new NullReferenceException();
+                                    }
                                 }
                                 break;
                             case OpCodeEnum.Stsfld:
@@ -2141,16 +2118,16 @@ namespace ILRuntime.Runtime.Intepreter
                                     switch (obj1->ObjectType)
                                     {
                                         case ObjectTypes.Integer:
-                                            res = (uint)obj1->Value < (uint)obj2->Value;
+                                            res = (uint)obj1->Value < (uint)obj2->Value && obj2->ObjectType != ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Long:
-                                            res = (ulong)*(long*)&obj1->Value < (ulong)*(long*)&obj2->Value;
+                                            res = (ulong)*(long*)&obj1->Value < (ulong)*(long*)&obj2->Value && obj2->ObjectType != ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Float:
-                                            res = *(float*)&obj1->Value < *(float*)&obj2->Value;
+                                            res = *(float*)&obj1->Value < *(float*)&obj2->Value && obj2->ObjectType != ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Double:
-                                            res = *(double*)&obj1->Value < *(double*)&obj2->Value;
+                                            res = *(double*)&obj1->Value < *(double*)&obj2->Value && obj2->ObjectType != ObjectTypes.Null;
                                             break;
                                         default:
                                             throw new NotImplementedException();
@@ -2169,16 +2146,16 @@ namespace ILRuntime.Runtime.Intepreter
                                     switch (obj1->ObjectType)
                                     {
                                         case ObjectTypes.Integer:
-                                            res = obj1->Value > obj2->Value;
+                                            res = obj1->Value > obj2->Value || obj2->ObjectType == ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Long:
-                                            res = *(long*)&obj1->Value > *(long*)&obj2->Value;
+                                            res = *(long*)&obj1->Value > *(long*)&obj2->Value || obj2->ObjectType == ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Float:
-                                            res = *(float*)&obj1->Value > *(float*)&obj2->Value;
+                                            res = *(float*)&obj1->Value > *(float*)&obj2->Value || obj2->ObjectType == ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Double:
-                                            res = *(double*)&obj1->Value > *(double*)&obj2->Value;
+                                            res = *(double*)&obj1->Value > *(double*)&obj2->Value || obj2->ObjectType == ObjectTypes.Null;
                                             break;
                                         default:
                                             throw new NotImplementedException();
@@ -2197,16 +2174,16 @@ namespace ILRuntime.Runtime.Intepreter
                                     switch (obj1->ObjectType)
                                     {
                                         case ObjectTypes.Integer:
-                                            res = (uint)obj1->Value > (uint)obj2->Value;
+                                            res = ((uint)obj1->Value > (uint)obj2->Value) || obj2->ObjectType == ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Long:
-                                            res = (ulong)*(long*)&obj1->Value > (ulong)*(long*)&obj2->Value;
+                                            res = (ulong)*(long*)&obj1->Value > (ulong)*(long*)&obj2->Value || obj2->ObjectType == ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Float:
-                                            res = *(float*)&obj1->Value > *(float*)&obj2->Value;
+                                            res = *(float*)&obj1->Value > *(float*)&obj2->Value || obj2->ObjectType == ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Double:
-                                            res = *(double*)&obj1->Value > *(double*)&obj2->Value;
+                                            res = *(double*)&obj1->Value > *(double*)&obj2->Value || obj2->ObjectType == ObjectTypes.Null;
                                             break;
                                         case ObjectTypes.Object:
                                             res = mStack[obj1->Value] != null && obj2->ObjectType == ObjectTypes.Null;
@@ -2271,9 +2248,23 @@ namespace ILRuntime.Runtime.Intepreter
                                         }
                                         else
                                         {
-                                            var obj = type.Instantiate(false);
                                             var a = esp - m.ParameterCount;
-                                            var objRef = PushObject(esp, mStack, obj);//this parameter for constructor
+                                            StackObject* objRef;
+                                            ILTypeInstance obj = null;
+                                            bool isValueType = type.IsValueType;
+                                            if (isValueType)
+                                            {
+                                                stack.AllocValueType(esp, type);
+                                                objRef = esp + 1;
+                                                objRef->ObjectType = ObjectTypes.StackObjectReference;
+                                                *(StackObject**)&objRef->Value = esp;
+                                                objRef++;
+                                            }
+                                            else
+                                            {
+                                                obj = type.Instantiate(false);
+                                                objRef = PushObject(esp, mStack, obj);//this parameter for constructor
+                                            }
                                             esp = objRef;
                                             for (int i = 0; i < m.ParameterCount; i++)
                                             {
@@ -2281,7 +2272,15 @@ namespace ILRuntime.Runtime.Intepreter
                                                 esp++;
                                             }
                                             esp = Execute((ILMethod)m, esp, out unhandledException);
-                                            esp = PushObject(a, mStack, obj);//new constructedObj
+                                            ValueTypeBasePointer = bp;
+                                            if (isValueType)
+                                            {
+                                                var ins = objRef - 1 - 1;
+                                                *a = *ins;
+                                                esp = a + 1;
+                                            }
+                                            else
+                                                esp = PushObject(a, mStack, obj);//new constructedObj
                                         }
                                         if (unhandledException)
                                             returned = true;
@@ -2450,23 +2449,37 @@ namespace ILRuntime.Runtime.Intepreter
                                             }
                                             else
                                             {
-                                                if (obj->ObjectType != ObjectTypes.Null)
+                                                switch (obj->ObjectType)
                                                 {
-                                                    var val = mStack[obj->Value];
-                                                    Free(obj);
-                                                    ILTypeInstance ins = (ILTypeInstance)val;
-                                                    if (ins != null)
-                                                    {
-                                                        if (ins.IsValueType)
+                                                    case ObjectTypes.Null:
+                                                        break;
+                                                    case ObjectTypes.ValueTypeObjectReference:
                                                         {
-                                                            ins.Boxed = true;
+                                                            ILTypeInstance ins = ((ILType)type).Instantiate(false);
+                                                            ins.AssignFromStack(obj, domain, mStack);
+                                                            FreeStackValueType(obj);
+                                                            esp = PushObject(obj, mStack, ins, true);
                                                         }
-                                                        esp = PushObject(obj, mStack, ins, true);
-                                                    }
-                                                    else
-                                                    {
-                                                        esp = PushNull(obj);
-                                                    }
+                                                        break;
+                                                    default:
+                                                        {
+                                                            var val = mStack[obj->Value];
+                                                            Free(obj);
+                                                            ILTypeInstance ins = (ILTypeInstance)val;
+                                                            if (ins != null)
+                                                            {
+                                                                if (ins.IsValueType)
+                                                                {
+                                                                    ins.Boxed = true;
+                                                                }
+                                                                esp = PushObject(obj, mStack, ins, true);
+                                                            }
+                                                            else
+                                                            {
+                                                                esp = PushNull(obj);
+                                                            }
+                                                        }
+                                                        break;
                                                 }
                                             }
                                         }
@@ -2651,6 +2664,16 @@ namespace ILRuntime.Runtime.Intepreter
                                             }
                                             else
                                             {
+                                                if(obj->ObjectType== ObjectTypes.ValueTypeObjectReference)
+                                                {
+                                                    var dst = *(StackObject**)&obj->Value;
+                                                    var vt = domain.GetType(dst->Value);
+                                                    if (vt != type)
+                                                        throw new InvalidCastException();
+                                                    object ins = ((CLRType)vt).ValueTypeBinder.ToObject(dst, mStack);
+                                                    FreeStackValueType(obj);
+                                                    esp = PushObject(obj, mStack, ins, true);
+                                                }
                                                 //nothing to do for CLR type boxing
                                             }
                                         }
@@ -2800,24 +2823,33 @@ namespace ILRuntime.Runtime.Intepreter
                                         ILType it = (ILType)type;
                                         if (it.IsValueType)
                                         {
-                                            if (objRef->ObjectType == ObjectTypes.Object)
+                                            switch (objRef->ObjectType)
                                             {
-                                                var obj = mStack[objRef->Value];
-                                                if (obj != null)
-                                                {
-                                                    if (obj is ILTypeInstance)
+                                                case ObjectTypes.Null:
+                                                    throw new NullReferenceException();
+                                                case ObjectTypes.ValueTypeObjectReference:
+                                                    stack.ClearValueTypeObject(type, *(StackObject**)&objRef->Value);
+                                                    break;
+                                                case ObjectTypes.Object:
                                                     {
-                                                        ILTypeInstance instance = obj as ILTypeInstance;
-                                                        instance.Clear();
+                                                        var obj = mStack[objRef->Value];
+                                                        if (obj != null)
+                                                        {
+                                                            if (obj is ILTypeInstance)
+                                                            {
+                                                                ILTypeInstance instance = obj as ILTypeInstance;
+                                                                instance.Clear();
+                                                            }
+                                                            else
+                                                                throw new NotSupportedException();
+                                                        }
+                                                        else
+                                                            throw new NullReferenceException();
                                                     }
-                                                    else
-                                                        throw new NotSupportedException();
-                                                }
-                                                else
-                                                    throw new NullReferenceException();
+                                                    break;
+                                                default:
+                                                    throw new NotImplementedException();
                                             }
-                                            else
-                                                throw new NullReferenceException();
 
                                             Free(esp - 1);
                                             esp--;
@@ -2854,7 +2886,12 @@ namespace ILRuntime.Runtime.Intepreter
                                     }
                                     else
                                     {
-                                        //nothing to do for clr value Types
+                                        if (objRef->ObjectType == ObjectTypes.ValueTypeObjectReference)
+                                        {
+                                            stack.ClearValueTypeObject(type, *(StackObject**)&objRef->Value);
+                                        }
+                                        Free(esp - 1);
+                                        esp--;
                                     }
                                 }
                                 break;
@@ -3770,7 +3807,7 @@ namespace ILRuntime.Runtime.Intepreter
                                 while (stack.Frames.Peek().BasePointer != frame.BasePointer)
                                 {
                                     var f = stack.Frames.Peek();
-                                    esp = stack.PopFrame(ref f, esp, mStack);
+                                    esp = stack.PopFrame(ref f, esp);
                                     if (f.Method.ReturnType != AppDomain.VoidType)
                                     {
                                         Free(esp - 1);
@@ -3809,7 +3846,158 @@ namespace ILRuntime.Runtime.Intepreter
 #endif
 #endif
             //ClearStack
-            return stack.PopFrame(ref frame, esp, mStack);
+            return stack.PopFrame(ref frame, esp);
+        }
+
+        void DumpStack(StackObject* esp)
+        {
+            AppDomain.DebugService.DumpStack(esp, stack);
+        }
+
+        void CloneStackValueType(StackObject* src, StackObject* dst, IList<object> mStack)
+        {
+            StackObject* descriptor = *(StackObject**)&src->Value;
+            stack.AllocValueType(dst, AppDomain.GetType(descriptor->Value));
+            StackObject* dstDescriptor = *(StackObject**)&dst->Value;
+            int cnt = descriptor->ValueLow;
+            for(int i = 0; i < cnt; i++)
+            {
+                StackObject* val = Minus(descriptor, i + 1);
+                CopyToValueTypeField(dstDescriptor, i, val, mStack);
+            }
+        }
+
+        void CopyStackValueType(StackObject* src, StackObject* dst, IList<object> mStack)
+        {
+            StackObject* descriptor = *(StackObject**)&src->Value;
+            StackObject* dstDescriptor = *(StackObject**)&dst->Value;
+            if (descriptor->Value != dstDescriptor->Value)
+                throw new InvalidCastException();
+            int cnt = descriptor->ValueLow;
+            for(int i = 0; i < cnt; i++)
+            {
+                StackObject* srcVal = Minus(descriptor, i + 1);
+                StackObject* dstVal = Minus(dstDescriptor, i + 1);
+                if (srcVal->ObjectType != dstVal->ObjectType)
+                    throw new NotSupportedException();
+                switch (dstVal->ObjectType)
+                {
+                    case ObjectTypes.Object:
+                    case ObjectTypes.ArrayReference:
+                    case ObjectTypes.FieldReference:
+                        mStack[dstVal->Value] = mStack[srcVal->Value];
+                        break;
+                    case ObjectTypes.ValueTypeObjectReference:
+                        CopyStackValueType(srcVal, dstVal, mStack);
+                        break;
+                    default:
+                        *dstVal = *srcVal;
+                        break;
+                }
+            }
+        }
+
+        void CopyToValueTypeField(StackObject* obj, int idx, StackObject* val, IList<object> mStack)
+        {
+            StackObject* dst = Minus(obj, idx + 1);
+            switch (val->ObjectType)
+            {
+                case ObjectTypes.Null:
+                    {
+                        mStack[dst->Value] = null;
+                    }
+                    break;
+                case ObjectTypes.Object:
+                case ObjectTypes.FieldReference:
+                case ObjectTypes.ArrayReference:
+                    {
+                        if (dst->ObjectType == ObjectTypes.ValueTypeObjectReference)
+                        {
+                            var ins = mStack[val->Value];
+                            dst = *(StackObject**)&dst->Value;
+
+                            if (ins is ILTypeInstance)
+                            {
+                                ((ILTypeInstance)ins).CopyValueTypeToStack(dst, mStack);
+                            }
+                            else
+                            {
+                                var vb = ((CLRType)domain.GetType(dst->Value)).ValueTypeBinder;
+                                vb.CopyValueTypeToStack(ins, dst, mStack);
+                            }
+                        }
+                        else
+                        {
+                            mStack[dst->Value] = CheckAndCloneValueType(mStack[val->Value], domain);                            
+                        }
+                    }
+                    break;
+                case ObjectTypes.ValueTypeObjectReference:
+                    {
+                        if (dst->ObjectType == ObjectTypes.ValueTypeObjectReference)
+                        {
+                            CopyStackValueType(val, dst, mStack);
+                        }
+                        else
+                            throw new NotImplementedException();
+                    }
+                    break;
+                default:
+                    *dst = *val;
+                    break;
+            }
+        }
+
+        void StLocSub(StackObject* esp, StackObject* v, StackObject* bp, int idx, IList<object> mStack)
+        {
+            switch (esp->ObjectType)
+            {
+                case ObjectTypes.Null:
+                    v->ObjectType = ObjectTypes.Object;
+                    v->Value = idx;
+                    mStack[idx] = null;
+                    break;
+                case ObjectTypes.Object:
+                case ObjectTypes.FieldReference:
+                case ObjectTypes.ArrayReference:
+                    if (v->ObjectType == ObjectTypes.ValueTypeObjectReference)
+                    {
+                        var obj = mStack[esp->Value];
+                        if (obj is ILTypeInstance)
+                        {
+                            var dst = *(StackObject**)&v->Value;
+                            ((ILTypeInstance)obj).CopyValueTypeToStack(dst, mStack);
+                        }
+                        else
+                        {
+                            var dst = *(StackObject**)&v->Value;
+                            var ct = domain.GetType(dst->Value) as CLRType;
+                            var binder = ct.ValueTypeBinder;
+                            binder.CopyValueTypeToStack(obj, dst, mStack);
+                        }                            
+                    }
+                    else
+                    {
+                        *v = *esp;
+                        mStack[idx] = CheckAndCloneValueType(mStack[v->Value], domain);
+                        v->Value = idx;
+                    }
+                    Free(esp);
+                    break;
+                case ObjectTypes.ValueTypeObjectReference:
+                    if (v->ObjectType == ObjectTypes.ValueTypeObjectReference)
+                    {
+                        CopyStackValueType(esp, v, mStack);
+                    }
+                    else
+                        throw new NotImplementedException();
+                    FreeStackValueType(esp);
+                    break;
+                default:
+                    *v = *esp;
+                    mStack[idx] = null;
+                    break;
+            }
         }
 
         object RetriveObject(StackObject* esp, IList<object> mStack)
@@ -4384,5 +4572,19 @@ namespace ILRuntime.Runtime.Intepreter
             esp->ValueLow = 0;
 #endif
         }
+        public void FreeStackValueType(StackObject* esp)
+        {
+            if (esp->ObjectType == ObjectTypes.ValueTypeObjectReference)
+            {
+                var addr = *(StackObject**)&esp->Value;
+                if (addr <= ValueTypeBasePointer)//Only Stack allocation after base pointer should be freed, local variable are freed automatically
+                    stack.FreeValueTypeObject(esp);
+            }
+        }
+
+        public void AllocValueType(StackObject* ptr, IType type)
+        {
+            stack.AllocValueType(ptr, type);
+        }
     }
 }

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILIntepreter.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: a0bb99f039f2a6f418e5af5bef359bf5
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILRuntimeException.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: ebae8830490e95743a6bf3332b2ee263
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 82 - 5
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILTypeInstance.cs

@@ -280,6 +280,44 @@ namespace ILRuntime.Runtime.Intepreter
             }
         }
 
+        internal unsafe void CopyValueTypeToStack(StackObject* ptr, IList<object> mStack)
+        {
+            ptr->ObjectType = ObjectTypes.ValueTypeDescriptor;
+            ptr->Value = type.GetHashCode();
+            ptr->ValueLow = type.TotalFieldCount;
+            for(int i = 0; i < fields.Length; i++)
+            {
+                var val = ILIntepreter.Minus(ptr, i + 1);
+                switch (val->ObjectType)
+                {
+                    case ObjectTypes.Object:
+                    case ObjectTypes.FieldReference:
+                    case ObjectTypes.ArrayReference:
+                        mStack[val->Value] = managedObjs[i];
+                        val->ValueLow = fields[i].ValueLow;
+                        break;
+                    case ObjectTypes.ValueTypeObjectReference:
+                        {
+                            var obj = managedObjs[i];
+                            var dst = *(StackObject**)&val->Value;
+                            var vt = type.AppDomain.GetType(dst->Value);
+                            if (vt is ILType)
+                            {
+                                ((ILTypeInstance)obj).CopyValueTypeToStack(dst, mStack);
+                            }
+                            else
+                            {
+                                ((CLRType)vt).ValueTypeBinder.CopyValueTypeToStack(obj, dst, mStack);
+                            }
+                        }
+                        break;
+                    default:
+                        *val = fields[i];
+                        break;
+                }                
+            }
+        }
+
         internal void Clear()
         {   
             InitializeFields(type);
@@ -302,17 +340,56 @@ namespace ILRuntime.Runtime.Intepreter
             }
         }
 
+        internal unsafe void AssignFromStack(StackObject* esp, Enviorment.AppDomain appdomain, IList<object> managedStack)
+        {
+            StackObject* val = *(StackObject**)&esp->Value;
+            int cnt = val->ValueLow;
+            for (int i = 0; i < cnt; i++)
+            {
+                var addr = ILIntepreter.Minus(val, i + 1);
+                AssignFromStack(i, addr, type.AppDomain, managedStack);
+            }
+        }
+
         unsafe void AssignFromStackSub(ref StackObject field, int fieldIdx, StackObject* esp, IList<object> managedStack)
         {
             esp = ILIntepreter.GetObjectAndResolveReference(esp);
             field = *esp;
-            if (field.ObjectType >= ObjectTypes.Object)
+            switch (field.ObjectType)
             {
-                field.Value = fieldIdx;
-                managedObjs[fieldIdx] = ILIntepreter.CheckAndCloneValueType(managedStack[esp->Value], Type.AppDomain);
+                case ObjectTypes.Object:
+                case ObjectTypes.ArrayReference:
+                case ObjectTypes.FieldReference:
+                    field.Value = fieldIdx;
+                    managedObjs[fieldIdx] = ILIntepreter.CheckAndCloneValueType(managedStack[esp->Value], Type.AppDomain);
+                    break;
+                case ObjectTypes.ValueTypeObjectReference:
+                    {
+                        var domain = type.AppDomain;
+                        field.ObjectType = ObjectTypes.Object;
+                        field.Value = fieldIdx;
+                        var dst = *(StackObject**)&esp->Value;
+                        var vt = domain.GetType(dst->Value);
+                        if(vt is ILType)
+                        {
+                            var ins = managedObjs[fieldIdx];
+                            if (ins == null)
+                                throw new NullReferenceException();
+                            ILTypeInstance child = (ILTypeInstance)ins;
+                            child.AssignFromStack(esp, domain, managedStack);
+                        }
+                        else
+                        {
+                            managedObjs[fieldIdx] = ((CLRType)vt).ValueTypeBinder.ToObject(dst, managedStack);
+                        }
+                        
+                    }
+                    break;
+                default:
+                    if (managedObjs != null)
+                        managedObjs[fieldIdx] = null;
+                    break;
             }
-            else if (managedObjs != null)
-                managedObjs[fieldIdx] = null;
         }
 
         public override string ToString()

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/ILTypeInstance.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 8e3c8c218911bc64b836907739e04af8
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/OpCodes/OpCode.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 2ef7583a5c2cabb4499ec0d948f9c7bb
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Intepreter/OpCodes/OpCodeEnum.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 7332c8f3285dcec4cbc6bd1494a4d846
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 294 - 6
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/RuntimeStack.cs

@@ -2,8 +2,8 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-
 using ILRuntime.CLR.Method;
+using ILRuntime.CLR.TypeSystem;
 using ILRuntime.Other;
 using ILRuntime.Runtime.Intepreter;
 
@@ -14,6 +14,7 @@ namespace ILRuntime.Runtime.Stack
         ILIntepreter intepreter;
         StackObject* pointer;
         StackObject* endOfMemory;
+        StackObject* valueTypePtr;
 
         IntPtr nativePointer;
 
@@ -34,6 +35,7 @@ namespace ILRuntime.Runtime.Stack
             nativePointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(StackObject) * MAXIMAL_STACK_OBJECTS);
             pointer = (StackObject*)nativePointer.ToPointer();
             endOfMemory = Add(pointer, MAXIMAL_STACK_OBJECTS);
+            valueTypePtr = endOfMemory - 1;
         }
 
         ~RuntimeStack()
@@ -49,8 +51,29 @@ namespace ILRuntime.Runtime.Stack
             }
         }
 
+        public StackObject* ValueTypeStackPointer
+        {
+            get
+            {
+                return valueTypePtr;
+            }
+        }
+
+        public StackObject* ValueTypeStackBase
+        {
+            get
+            {
+                return endOfMemory - 1;
+            }
+        }
+
         public IList<object> ManagedStack { get { return managedStack; } }
 
+        public void ResetValueTypePointer()
+        {
+            valueTypePtr = endOfMemory - 1;
+        }
+
         public void InitializeFrame(ILMethod method, StackObject* esp, out StackFrame res)
         {
             if (esp < pointer || esp >= endOfMemory)
@@ -70,6 +93,7 @@ namespace ILRuntime.Runtime.Stack
 #endif
             res.BasePointer = method.LocalVariableCount > 0 ? Add(esp, method.LocalVariableCount + 1) : esp;
             res.ManagedStackBase = managedStack.Count;
+            res.ValueTypeBasePointer = valueTypePtr;
             //frames.Push(res);
         }
         public void PushFrame(ref StackFrame frame)
@@ -77,7 +101,7 @@ namespace ILRuntime.Runtime.Stack
             frames.Push(frame);
         }
 
-        public StackObject* PopFrame(ref StackFrame frame, StackObject* esp, IList<object> mStack)
+        public StackObject* PopFrame(ref StackFrame frame, StackObject* esp)
         {
             if (frames.Count > 0 && frames.Peek().BasePointer == frame.BasePointer)
                 frames.Pop();
@@ -95,20 +119,284 @@ namespace ILRuntime.Runtime.Stack
                 if(ret->ObjectType == ObjectTypes.Object)
                 {
                     ret->Value = mStackBase;
-                    mStack[mStackBase] = mStack[returnVal->Value];
+                    managedStack[mStackBase] = managedStack[returnVal->Value];
                     mStackBase++;
                 }
+                else if(ret->ObjectType == ObjectTypes.ValueTypeObjectReference)
+                {
+                    StackObject* oriAddr = frame.ValueTypeBasePointer;
+                    RelocateValueType(ret, ref frame.ValueTypeBasePointer, ref mStackBase);
+                    *(StackObject**)&ret->Value = oriAddr;
+                }
                 ret++;
             }
 #if DEBUG
-            ((List<object>)mStack).RemoveRange(mStackBase, mStack.Count - mStackBase);
+            ((List<object>)managedStack).RemoveRange(mStackBase, managedStack.Count - mStackBase);
 #else
-            ((UncheckedList<object>)mStack).RemoveRange(mStackBase, mStack.Count - mStackBase);
+            ((UncheckedList<object>)managedStack).RemoveRange(mStackBase, managedStack.Count - mStackBase);
 #endif
+            valueTypePtr = frame.ValueTypeBasePointer;
             return ret;
         }
 
-        
+        void RelocateValueType(StackObject* src, ref StackObject* dst, ref int mStackBase)
+        {
+            StackObject* descriptor = *(StackObject**)&src->Value;
+            if (descriptor > dst)
+                throw new StackOverflowException();
+            *dst = *descriptor;
+            int cnt = descriptor->ValueLow;
+            StackObject* endAddr = ILIntepreter.Minus(dst, cnt + 1);
+            for(int i = 0; i < cnt; i++)
+            {
+                StackObject* addr = ILIntepreter.Minus(descriptor, i + 1);
+                StackObject* tarVal = ILIntepreter.Minus(dst, i + 1);
+                *tarVal = *addr;
+                switch (addr->ObjectType)
+                {
+                    case ObjectTypes.Object:
+                    case ObjectTypes.ArrayReference:
+                    case ObjectTypes.FieldReference:
+                        if (tarVal->Value >= mStackBase)
+                        {
+                            int oldIdx = addr->Value;
+                            tarVal->Value = mStackBase;
+                            managedStack[mStackBase] = managedStack[oldIdx];
+                            mStackBase++;
+                        }
+                        break;
+                    case ObjectTypes.ValueTypeObjectReference:
+                        var newAddr = endAddr;
+                        RelocateValueType(addr, ref endAddr, ref mStackBase);
+                        *(StackObject**)&tarVal->Value = newAddr;
+                        break;
+                }
+            }
+            dst = endAddr;
+        }
+
+        public void AllocValueType(StackObject* ptr, IType type)
+        {
+            if (type.IsValueType)
+            {
+                int fieldCount = 0;
+                if(type is ILType)
+                {
+                    fieldCount = ((ILType)type).TotalFieldCount;
+                }
+                else
+                {
+                    fieldCount = ((CLRType)type).TotalFieldCount;
+                }
+                ptr->ObjectType = ObjectTypes.ValueTypeObjectReference;
+                var dst = valueTypePtr;
+                *(StackObject**)&ptr->Value = dst;
+                dst->ObjectType = ObjectTypes.ValueTypeDescriptor;
+                dst->Value = type.GetHashCode();
+                dst->ValueLow = fieldCount;
+                valueTypePtr = ILIntepreter.Minus(valueTypePtr, fieldCount + 1);
+                if (valueTypePtr <= StackBase)
+                    throw new StackOverflowException();
+                InitializeValueTypeObject(type, dst);
+            }
+            else
+                throw new ArgumentException(type.FullName + " is not a value type.", "type");
+        }
+
+        void InitializeValueTypeObject(IType type, StackObject* ptr)
+        {
+            if (type is ILType)
+            {
+                ILType t = (ILType)type;
+                for (int i = 0; i < t.FieldTypes.Length; i++)
+                {
+                    var ft = t.FieldTypes[i];
+                    StackObject* val = ILIntepreter.Minus(ptr, t.FieldStartIndex + i + 1);
+                    if (ft.IsPrimitive)
+                        StackObject.Initialized(val, ft);
+                    else
+                    {
+                        if (ft.IsValueType)
+                        {
+                            AllocValueType(val, ft);
+                        }
+                        else
+                        {
+                            val->ObjectType = ObjectTypes.Object;
+                            val->Value = managedStack.Count;
+                            managedStack.Add(null);
+                        }
+                    }
+                }
+                if (type.BaseType != null && type.BaseType is ILType)
+                    InitializeValueTypeObject((ILType)type.BaseType, ptr);
+            }
+            else
+            {
+                CLRType t = (CLRType)type;
+                var cnt = t.TotalFieldCount;
+                for(int i = 0; i < cnt; i++)
+                {
+                    var it = t.OrderedFieldTypes[i] as CLRType;
+                    StackObject* val = ILIntepreter.Minus(ptr, i + 1);
+                    if (it.IsPrimitive)
+                        StackObject.Initialized(val, it);
+                    else
+                    {
+                        if (it.IsValueType)
+                        {
+                            if (it.ValueTypeBinder != null)
+                                AllocValueType(val, it);
+                            else
+                            {
+                                val->ObjectType = ObjectTypes.Object;
+                                val->Value = managedStack.Count;
+                                managedStack.Add(it.CreateDefaultInstance());
+                            }
+                        }
+                        else
+                        {
+                            val->ObjectType = ObjectTypes.Object;
+                            val->Value = managedStack.Count;
+                            managedStack.Add(null);
+                        }
+                    }
+                }
+            }
+        }
+
+        public void ClearValueTypeObject(IType type, StackObject* ptr)
+        {
+            if (type is ILType)
+            {
+                ILType t = (ILType)type;
+                for (int i = 0; i < t.FieldTypes.Length; i++)
+                {
+                    var ft = t.FieldTypes[i];
+                    StackObject* val = ILIntepreter.Minus(ptr, t.FieldStartIndex + i + 1);
+                    if (ft.IsPrimitive)
+                        StackObject.Initialized(val, ft);
+                    else
+                    {
+                        switch (val->ObjectType)
+                        {
+                            case ObjectTypes.ValueTypeObjectReference:
+                                ClearValueTypeObject(ft, *(StackObject**)&val->Value);
+                                break;
+                            default:
+                                if (ft.IsValueType)
+                                {
+                                    if(ft is ILType)
+                                    {
+                                        throw new NotImplementedException();
+                                    }
+                                    else
+                                    {
+                                        managedStack[val->Value] = ((CLRType)ft).CreateDefaultInstance();
+                                    }
+                                }
+                                else
+                                    managedStack[val->Value] = null;
+                                break;
+                        }
+                    }
+                }
+                if (type.BaseType != null && type.BaseType is ILType)
+                    ClearValueTypeObject((ILType)type.BaseType, ptr);
+            }
+            else
+            {
+                CLRType t = (CLRType)type;
+                var cnt = t.TotalFieldCount;
+                for (int i = 0; i < cnt; i++)
+                {
+                    var vt = t.OrderedFieldTypes[i] as CLRType;
+                    StackObject* val = ILIntepreter.Minus(ptr, i + 1);
+                    if (vt.IsPrimitive)
+                        StackObject.Initialized(val, vt);
+                    else
+                    {
+                        switch (val->ObjectType)
+                        {
+                            case ObjectTypes.ValueTypeObjectReference:
+                                {
+                                    var dst = *(StackObject**)&val->Value;
+                                    ClearValueTypeObject(vt, *(StackObject**)&val->Value);
+                                }
+                                break;
+                            default:
+                                if (vt.IsValueType)
+                                {
+                                    managedStack[val->Value] = vt.CreateDefaultInstance();
+                                }
+                                else
+                                    managedStack[val->Value] = null;
+                                break;
+                        }
+                    }
+                }
+            }
+        }
+
+        public void FreeValueTypeObject(StackObject* esp)
+        {
+            int start = int.MaxValue;
+            int end = int.MinValue;
+            StackObject* endAddr;
+            CountValueTypeManaged(esp, ref start, ref end, &endAddr);
+
+            if (endAddr == valueTypePtr)
+                valueTypePtr = *(StackObject**)&esp->Value;
+            else
+                throw new NotSupportedException();
+            if (start != int.MaxValue)
+            {
+                if (end == managedStack.Count - 1)
+                {
+#if DEBUG
+                    ((List<object>)managedStack).RemoveRange(start, managedStack.Count - start);
+#else
+                    ((UncheckedList<object>)managedStack).RemoveRange(start, managedStack.Count - start);
+#endif
+                }
+                else
+                    throw new NotSupportedException();
+            }
+        }
+
+        void CountValueTypeManaged(StackObject* esp, ref int start, ref int end, StackObject** endAddr)
+        {
+            StackObject* descriptor = *(StackObject**)&esp->Value;
+            int cnt = descriptor->ValueLow;
+            *endAddr = ILIntepreter.Minus(descriptor, cnt + 1);
+            for (int i = 0; i < cnt; i++)
+            {
+                StackObject* addr = ILIntepreter.Minus(descriptor, i + 1);
+                switch (addr->ObjectType)
+                {
+                    case ObjectTypes.Object:
+                    case ObjectTypes.ArrayReference:
+                    case ObjectTypes.FieldReference:
+                        {
+                            if (start == int.MaxValue)
+                            {
+                                start = addr->Value;
+                                end = start;
+                            }
+                            else if (addr->Value == end + 1)
+                                end++;
+                            else
+                                throw new NotSupportedException();
+                        }
+                        break;
+                    case ObjectTypes.ValueTypeObjectReference:
+                        CountValueTypeManaged(addr, ref start, ref end, endAddr);
+                        break;
+                }
+
+            }
+        }
+
         public void Dispose()
         {
             if (nativePointer != IntPtr.Zero)

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/RuntimeStack.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 55de1685a7e4efa41b7f1f73a81aa07c
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 0
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/StackFrame.cs

@@ -16,6 +16,7 @@ namespace ILRuntime.Runtime.Stack
         public ILMethod Method;
         public StackObject* LocalVarPointer;
         public StackObject* BasePointer;
+        public StackObject* ValueTypeBasePointer;
         public IntegerReference Address;
         public int ManagedStackBase;
     }

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/StackFrame.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 7394a29fd3deece4ea7c3d67f055faca
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 25 - 2
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/StackObject.cs

@@ -81,6 +81,26 @@ namespace ILRuntime.Runtime.Stack
                     {
                         return ToObject((*(StackObject**)&esp->Value), appdomain, mStack);
                     }
+                case ObjectTypes.ValueTypeObjectReference:
+                    {
+                        StackObject* dst = *(StackObject**)&esp->Value;
+                        IType type = appdomain.GetType(dst->Value);
+                        if (type is ILType)
+                        {
+                            ILType iltype = (ILType)type;
+                            var ins = iltype.Instantiate(false);
+                            for (int i = 0; i < dst->ValueLow; i++)
+                            {
+                                var addr = ILIntepreter.Minus(dst, i + 1);
+                                ins.AssignFromStack(i, addr, appdomain, mStack);
+                            }
+                            return ins;
+                        }
+                        else
+                        {
+                            return ((CLRType)type).ValueTypeBinder.ToObject(dst, mStack);
+                        }
+                    }
                 case ObjectTypes.Null:
                     return null;
                 default:
@@ -140,9 +160,10 @@ namespace ILRuntime.Runtime.Stack
         }
 
         //IL2CPP can't process esp->Initialized() properly, so I can only use static function for this
-        public unsafe static void Initialized(StackObject* esp, Type t)
+        public unsafe static void Initialized(StackObject* esp, IType type)
         {
-            if (t.IsPrimitive)
+            var t = type.TypeForCLR;
+            if (type.IsPrimitive)
             {
                 if (t == typeof(int) || t == typeof(uint) || t == typeof(short) || t == typeof(ushort) || t == typeof(byte) || t == typeof(sbyte) || t == typeof(char) || t == typeof(bool))
                 {
@@ -187,6 +208,8 @@ namespace ILRuntime.Runtime.Stack
         Double,
         StackObjectReference,//Value = pointer, 
         StaticFieldReference,
+        ValueTypeObjectReference,
+        ValueTypeDescriptor,
         Object,
         FieldReference,//Value = objIdx, ValueLow = fieldIdx
         ArrayReference,//Value = objIdx, ValueLow = elemIdx

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/ILRuntime/Runtime/Stack/StackObject.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 5b8d9c7d873701f46b5f31887c908e61
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Code.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 40bcd801e7a1d4c44a8a0fd2eb72617e
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeReader.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 132761467bbd32d4fa4a028592dca8fc
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/CodeWriter.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: d3ec49d880028814fa48da946e502290
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Document.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: e2b7c3598c4acd8468a789a015751a95
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ExceptionHandler.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 21a64ac0bb4ca454a97ca76de8e7e9d6
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/ILProcessor.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 4646551666f3dff4aab91bb8cecdc72d
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Instruction.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 4b72b64dc0086154682d81c571aca5c0
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/MethodBody.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 06e529fcda5f9094c9e3aef33b4579a7
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCode.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: b9eba3eb561bcaa4cbb4b7f1e45241e2
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/OpCodes.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 3860582dd6338404c99c8252ecc18d1a
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/SequencePoint.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: f391522e276e638409767fb562f8e320
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/Symbols.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 37a37139bedcb334ba1cbe9291260bfb
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableDefinition.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 649e2b8d9b4e1184b89a2b297f2ec453
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Cil/VariableReference.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: a1e5f85ddde180f4ca37f6fc14f7b888
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/BlobHeap.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 555efb6b67d765942ba119292afeeb5d
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Buffers.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 90d87ffd25c230e4e9483cb4406b6763
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/CodedIndex.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 9265deb103a79a149b2cd0567b36901f
-timeCreated: 1503890051
+timeCreated: 1509525194
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/ElementType.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 0b4fde6b99549df479e4380c17beb6a1
-timeCreated: 1503890049
+timeCreated: 1509525192
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/GuidHeap.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 77cfdee5f1fa44742ab45eefd8dc42fd
-timeCreated: 1503890050
+timeCreated: 1509525193
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/ThirdParty/ILRuntime/Mono.Cecil.20/MonoCecil/Mono.Cecil.Metadata/Heap.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: de5ee96256db27849bade83de6ef99ee
-timeCreated: 1503890052
+timeCreated: 1509525195
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini