Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jiogao/ILRuntime
Browse files Browse the repository at this point in the history
  • Loading branch information
jiogao committed Mar 12, 2020
2 parents 0e731ba + 81e924b commit ec95952
Show file tree
Hide file tree
Showing 34 changed files with 823 additions and 1,580 deletions.
14 changes: 9 additions & 5 deletions ILRuntime/CLR/TypeSystem/ILType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ILType : IType
TypeReference typeRef;
TypeDefinition definition;
ILRuntime.Runtime.Enviorment.AppDomain appdomain;
bool staticConstructorCalled;
ILMethod staticConstructor;
List<ILMethod> constructors;
IType[] fieldTypes;
Expand Down Expand Up @@ -127,6 +128,14 @@ public ILTypeStaticInstance StaticInstance
InitializeFields();
if (methods == null)
InitializeMethods();
if (staticInstance != null && !staticConstructorCalled)
{
staticConstructorCalled = true;
if (staticConstructor != null && (!TypeReference.HasGenericParameters || IsGenericInstance))
{
appdomain.Invoke(staticConstructor, null, null);
}
}
return staticInstance;
}
}
Expand Down Expand Up @@ -677,11 +686,6 @@ void InitializeMethods()
lst.Add(m);
}
}

if (staticConstructor != null && (!TypeReference.HasGenericParameters || IsGenericInstance))
{
appdomain.Invoke(staticConstructor, null, null);
}
}

public IMethod GetVirtualMethod(IMethod method)
Expand Down
16 changes: 6 additions & 10 deletions ILRuntime/Runtime/Enviorment/CLRRedirections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,35 +829,31 @@ unsafe static class CLRRedirections
esp = ILIntepreter.PushObject(ret, mStack, obj);
else
esp = ret;
var ilmethod = ((ILRuntimeMethodInfo)instance).ILMethod;
if (p != null)
{
object[] arr = (object[])p;
foreach (var i in arr)
for(int i = 0; i < ilmethod.ParameterCount; i++)
{
esp = ILIntepreter.PushObject(esp, mStack, CheckCrossBindingAdapter(i));
esp = ILIntepreter.PushObject(esp, mStack, CheckCrossBindingAdapter(arr[i]));
}
}
bool unhandled;
var ilmethod = ((ILRuntimeMethodInfo)instance).ILMethod;
ret = intp.Execute(ilmethod, esp, out unhandled);
ILRuntimeMethodInfo imi = (ILRuntimeMethodInfo)instance;
var rt = imi.ReturnType;
var rt = imi.ILMethod.ReturnType;
if (rt != domain.VoidType)
{
var res = ret - 1;
if (res->ObjectType < ObjectTypes.Object)
{
if (rt is ILRuntimeWrapperType)
rt = ((ILRuntimeWrapperType)rt).CLRType.TypeForCLR;
if (rt is ILRuntimeType)
rt = ((ILRuntimeType)rt).ILType.TypeForCLR;
return ILIntepreter.PushObject(res, mStack, rt.CheckCLRTypes(StackObject.ToObject(res, domain, mStack)), true);
return ILIntepreter.PushObject(res, mStack, rt.TypeForCLR.CheckCLRTypes(StackObject.ToObject(res, domain, mStack)), true);
}
else
return ret;
}
else
return ret;
return ILIntepreter.PushNull(ret);
}
else
return ILIntepreter.PushObject(ret, mStack, ((MethodInfo)instance).Invoke(obj, (object[])p));
Expand Down
20 changes: 8 additions & 12 deletions ILRuntimeTest/AutoGenerate/CLRBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,12 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_Type_Binding.Register(app);
System_Runtime_CompilerServices_AsyncTaskMethodBuilder_Binding.Register(app);
System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_Int32_Binding.Register(app);
System_Runtime_CompilerServices_AsyncVoidMethodBuilder_Binding.Register(app);
System_Runtime_CompilerServices_AsyncTaskMethodBuilder_1_List_1_String_Binding.Register(app);
System_Threading_Tasks_Task_Binding.Register(app);
System_Runtime_CompilerServices_TaskAwaiter_Binding.Register(app);
System_Threading_Tasks_Task_1_Int32_Binding.Register(app);
System_Runtime_CompilerServices_TaskAwaiter_1_Int32_Binding.Register(app);
System_Exception_Binding.Register(app);
System_Collections_IDictionary_Binding.Register(app);
System_Threading_Tasks_Task_1_List_1_String_Binding.Register(app);
System_Runtime_CompilerServices_TaskAwaiter_1_List_1_String_Binding.Register(app);
System_Collections_Generic_List_1_Task_Binding.Register(app);
System_IO_File_Binding.Register(app);
System_Collections_Generic_List_1_String_Binding.Register(app);
System_IO_TextReader_Binding.Register(app);
System_Threading_Tasks_Task_1_String_Binding.Register(app);
System_Runtime_CompilerServices_TaskAwaiter_1_String_Binding.Register(app);
System_IDisposable_Binding.Register(app);
System_Collections_Generic_List_1_Int32_Binding.Register(app);
System_Linq_Enumerable_Binding.Register(app);
System_Collections_Generic_List_1_Dictionary_2_String_Object_Binding.Register(app);
Expand All @@ -57,6 +46,7 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_ArgumentException_Binding.Register(app);
ILRuntimeTest_TestBase_StaticGenericMethods_Binding.Register(app);
System_Action_1_ILTypeInstance_Binding.Register(app);
System_Array_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int32_ILTypeInstance_Binding.Register(app);
LitJson_JsonMapper_Binding.Register(app);
System_Collections_Generic_List_1_ILTypeInstance_Binding.Register(app);
Expand Down Expand Up @@ -89,18 +79,21 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
ILRuntimeTest_TestFramework_TestClass3_Binding.Register(app);
System_Byte_Binding.Register(app);
System_Char_Binding.Register(app);
System_IO_File_Binding.Register(app);
System_IO_FileStream_Binding.Register(app);
System_IO_Stream_Binding.Register(app);
System_IDisposable_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int64_Int32_Binding.Register(app);
System_Enum_Binding.Register(app);
System_Array_Binding.Register(app);
System_Collections_IEnumerator_Binding.Register(app);
System_Collections_Generic_Dictionary_2_String_Int64_Binding.Register(app);
System_Int32_Array_Binding.Register(app);
System_Int32_Array_Binding_Array_Binding.Register(app);
System_Double_Binding.Register(app);
ILRuntimeTest_TestFramework_TestVector3_Binding.Register(app);
System_Int32_Array3_Binding.Register(app);
System_Int32_Array2_Binding.Register(app);
ILRuntimeTest_TestFramework_TestClass4_Binding.Register(app);
System_Single_Binding.Register(app);
System_Nullable_1_Int32_Binding.Register(app);
System_Collections_Generic_Dictionary_2_String_Int32_Binding_Enumerator_Binding.Register(app);
Expand All @@ -116,9 +109,11 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_Collections_Generic_Dictionary_2_ILTypeInstance_Int32_Binding.Register(app);
System_Collections_Generic_List_1_Int32_Array_Binding.Register(app);
System_Collections_Generic_List_1_Object_Binding.Register(app);
System_Linq_IGrouping_2_Byte_Byte_Binding.Register(app);
System_Convert_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int32_ILTypeInstance_Binding_ValueCollection_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int32_ILTypeInstance_Binding_ValueCollection_Binding_Enumerator_Binding.Register(app);
System_Collections_Generic_List_1_String_Binding.Register(app);
System_Collections_Generic_List_1_String_Binding_Enumerator_Binding.Register(app);
System_NotSupportedException_Binding.Register(app);
System_Collections_Generic_List_1_ILTypeInstance_Binding_Enumerator_Binding.Register(app);
Expand All @@ -135,6 +130,7 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_IComparable_1_Int32_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int32_Int32_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int32_Int32_Binding_Enumerator_Binding.Register(app);
System_Collections_Generic_EqualityComparer_1_Int32_Binding.Register(app);

ILRuntime.CLR.TypeSystem.CLRType __clrType = null;
__clrType = (ILRuntime.CLR.TypeSystem.CLRType)app.GetType (typeof(ILRuntimeTest.TestFramework.TestVector3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
}
}
}
args = new Type[]{typeof(System.String), typeof(System.Collections.Generic.KeyValuePair<System.String, System.String[]>[])};
method = type.GetMethod("Method", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Method_8);


}
Expand Down Expand Up @@ -237,6 +240,26 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
return __ret;
}

static StackObject* Method_8(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 2);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Collections.Generic.KeyValuePair<System.String, System.String[]>[] @panels = (System.Collections.Generic.KeyValuePair<System.String, System.String[]>[])typeof(System.Collections.Generic.KeyValuePair<System.String, System.String[]>[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.String @name = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);


ILRuntimeTest.TestBase.StaticGenericMethods.Method(@name, @panels);

return __ret;
}



}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

using ILRuntime.CLR.TypeSystem;
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using ILRuntime.Runtime.Stack;
using ILRuntime.Reflection;
using ILRuntime.CLR.Utils;

namespace ILRuntime.Runtime.Generated
{
unsafe class ILRuntimeTest_TestFramework_TestClass4_Binding
{
public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
{
BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
MethodBase method;
Type[] args;
Type type = typeof(ILRuntimeTest.TestFramework.TestClass4);
args = new Type[]{typeof(ILRuntimeTest.TestFramework.TestStruct[]).MakeByRefType()};
method = type.GetMethod("TestArrayOut", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, TestArrayOut_0);

args = new Type[]{};
method = type.GetConstructor(flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Ctor_0);

}


static StackObject* TestArrayOut_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 2);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
ILRuntimeTest.TestFramework.TestStruct[] @arr = (ILRuntimeTest.TestFramework.TestStruct[])typeof(ILRuntimeTest.TestFramework.TestStruct[]).CheckCLRTypes(__intp.RetriveObject(ptr_of_this_method, __mStack));

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
ILRuntimeTest.TestFramework.TestClass4 instance_of_this_method = (ILRuntimeTest.TestFramework.TestClass4)typeof(ILRuntimeTest.TestFramework.TestClass4).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

instance_of_this_method.TestArrayOut(out @arr);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
switch(ptr_of_this_method->ObjectType)
{
case ObjectTypes.StackObjectReference:
{
var ___dst = ILIntepreter.ResolveReference(ptr_of_this_method);
object ___obj = @arr;
if (___dst->ObjectType >= ObjectTypes.Object)
{
if (___obj is CrossBindingAdaptorType)
___obj = ((CrossBindingAdaptorType)___obj).ILInstance;
__mStack[___dst->Value] = ___obj;
}
else
{
ILIntepreter.UnboxObject(___dst, ___obj, __mStack, __domain);
}
}
break;
case ObjectTypes.FieldReference:
{
var ___obj = __mStack[ptr_of_this_method->Value];
if(___obj is ILTypeInstance)
{
((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = @arr;
}
else
{
var ___type = __domain.GetType(___obj.GetType()) as CLRType;
___type.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, @arr);
}
}
break;
case ObjectTypes.StaticFieldReference:
{
var ___type = __domain.GetType(ptr_of_this_method->Value);
if(___type is ILType)
{
((ILType)___type).StaticInstance[ptr_of_this_method->ValueLow] = @arr;
}
else
{
((CLRType)___type).SetStaticFieldValue(ptr_of_this_method->ValueLow, @arr);
}
}
break;
case ObjectTypes.ArrayReference:
{
var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as ILRuntimeTest.TestFramework.TestStruct[][];
instance_of_arrayReference[ptr_of_this_method->ValueLow] = @arr;
}
break;
}

__intp.Free(ptr_of_this_method);
ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
__intp.Free(ptr_of_this_method);
return __ret;
}


static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* __ret = ILIntepreter.Minus(__esp, 0);

var result_of_this_method = new ILRuntimeTest.TestFramework.TestClass4();

return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}


}
}
15 changes: 15 additions & 0 deletions ILRuntimeTest/AutoGenerate/System_Activator_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)

var result_of_this_method = System.Activator.CreateInstance(@type, @args);

object obj_result_of_this_method = result_of_this_method;
if(obj_result_of_this_method is CrossBindingAdaptorType)
{
return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance, true);
}
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method, true);
}

Expand All @@ -133,6 +138,11 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)

var result_of_this_method = System.Activator.CreateInstance(@type);

object obj_result_of_this_method = result_of_this_method;
if(obj_result_of_this_method is CrossBindingAdaptorType)
{
return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance, true);
}
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method, true);
}

Expand Down Expand Up @@ -160,6 +170,11 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)

var result_of_this_method = System.Activator.CreateInstance<System.Object>();

object obj_result_of_this_method = result_of_this_method;
if(obj_result_of_this_method is CrossBindingAdaptorType)
{
return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance, true);
}
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method, true);
}

Expand Down
Loading

0 comments on commit ec95952

Please sign in to comment.