Skip to content

Commit

Permalink
Fixed #690 Fixed #691
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Oct 7, 2022
1 parent 92badbc commit b8cb257
Show file tree
Hide file tree
Showing 23 changed files with 1,110 additions and 189 deletions.
4 changes: 2 additions & 2 deletions ILRuntime/Runtime/CLRBinding/BindingGeneratorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ internal static bool ShouldSkipMethod(this Type type, MethodBase i)
if (i.IsSpecialName)
{
string[] t = i.Name.Split('_');
//if (t[0] == "add" || t[0] == "remove")
// return true;
if (t[0] == "add" || t[0] == "remove")
return false;
if (t[0] == "get" || t[0] == "set")
{
Type[] ts;
Expand Down
1 change: 1 addition & 0 deletions ILRuntimeTestBase/Adapters/helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static void Init(ILRuntime.Runtime.Enviorment.AppDomain app)
app.DelegateManager.RegisterMethodDelegate<ILRuntimeTest.TestFramework.TestVector3>();
app.DelegateManager.RegisterFunctionDelegate<System.Reflection.FieldInfo, System.String>();
app.DelegateManager.RegisterFunctionDelegate<ILRuntime.Runtime.Intepreter.ILTypeInstance, ILRuntime.Runtime.Intepreter.ILTypeInstance, System.Int32>();
app.DelegateManager.RegisterMethodDelegate<System.Single, System.Double, System.Int32>();
// delegate convertor
app.DelegateManager.RegisterDelegateConvertor<System.Comparison<ILRuntime.Runtime.Intepreter.ILTypeInstance>>((act) =>
{
Expand Down
13 changes: 13 additions & 0 deletions ILRuntimeTestBase/AutoGenerate/CLRBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static private void RegisterBindingAction()
internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<System.Collections.Generic.KeyValuePair<System.UInt32, ILRuntime.Runtime.Intepreter.ILTypeInstance>> s_System_Collections_Generic_KeyValuePair_2_UInt32_ILTypeInstance_Binding_Binder = null;
internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<ILRuntimeTest.TestFramework.TestStructA> s_ILRuntimeTest_TestFramework_TestStructA_Binding_Binder = null;
internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<ILRuntimeTest.TestFramework.TestStructB> s_ILRuntimeTest_TestFramework_TestStructB_Binding_Binder = null;
internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<ILRuntimeTest.TestFramework.Fixed64> s_ILRuntimeTest_TestFramework_Fixed64_Binding_Binder = null;
internal static ILRuntime.Runtime.Enviorment.ValueTypeBinder<ILRuntimeTest.TestFramework.Fixed64Vector2> s_ILRuntimeTest_TestFramework_Fixed64Vector2_Binding_Binder = null;

/// <summary>
/// Initialize the CLR binding, please invoke this AFTER CLR Redirection registration
Expand Down Expand Up @@ -103,6 +105,8 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_Reflection_ParameterInfo_Binding.Register(app);
System_Reflection_MethodInfo_Binding.Register(app);
ILRuntimeTest_TestFramework_BindableProperty_1_Int64_Binding.Register(app);
System_Threading_Interlocked_Binding.Register(app);
System_Action_3_Single_Double_Int32_Binding.Register(app);
System_Action_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int64_Int32_Binding.Register(app);
System_Enum_Binding.Register(app);
Expand Down Expand Up @@ -155,6 +159,7 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
ILRuntimeTest_TestFramework_TestCLRAttribute_Binding.Register(app);
System_Reflection_PropertyInfo_Binding.Register(app);
System_Collections_Generic_List_1_String_Binding.Register(app);
System_Collections_Generic_List_1_FieldInfo_Binding.Register(app);
ILRuntimeTest_TestFramework_TestCLREnumClass_Binding.Register(app);
System_Nullable_1_Int32_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Int32_List_1_String_Binding.Register(app);
Expand Down Expand Up @@ -195,6 +200,8 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_Collections_Generic_List_1_TestVector3NoBinding_Binding.Register(app);
ILRuntimeTest_TestFramework_TestStructA_Binding.Register(app);
ILRuntimeTest_TestFramework_TestStructB_Binding.Register(app);
ILRuntimeTest_TestFramework_Fixed64_Binding.Register(app);
ILRuntimeTest_TestFramework_Fixed64Vector2_Binding.Register(app);

ILRuntime.CLR.TypeSystem.CLRType __clrType = null;
__clrType = (ILRuntime.CLR.TypeSystem.CLRType)app.GetType (typeof(ILRuntimeTest.TestFramework.TestVector3));
Expand All @@ -209,6 +216,10 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
s_ILRuntimeTest_TestFramework_TestStructA_Binding_Binder = __clrType.ValueTypeBinder as ILRuntime.Runtime.Enviorment.ValueTypeBinder<ILRuntimeTest.TestFramework.TestStructA>;
__clrType = (ILRuntime.CLR.TypeSystem.CLRType)app.GetType (typeof(ILRuntimeTest.TestFramework.TestStructB));
s_ILRuntimeTest_TestFramework_TestStructB_Binding_Binder = __clrType.ValueTypeBinder as ILRuntime.Runtime.Enviorment.ValueTypeBinder<ILRuntimeTest.TestFramework.TestStructB>;
__clrType = (ILRuntime.CLR.TypeSystem.CLRType)app.GetType (typeof(ILRuntimeTest.TestFramework.Fixed64));
s_ILRuntimeTest_TestFramework_Fixed64_Binding_Binder = __clrType.ValueTypeBinder as ILRuntime.Runtime.Enviorment.ValueTypeBinder<ILRuntimeTest.TestFramework.Fixed64>;
__clrType = (ILRuntime.CLR.TypeSystem.CLRType)app.GetType (typeof(ILRuntimeTest.TestFramework.Fixed64Vector2));
s_ILRuntimeTest_TestFramework_Fixed64Vector2_Binding_Binder = __clrType.ValueTypeBinder as ILRuntime.Runtime.Enviorment.ValueTypeBinder<ILRuntimeTest.TestFramework.Fixed64Vector2>;
}

/// <summary>
Expand All @@ -222,6 +233,8 @@ public static void Shutdown(ILRuntime.Runtime.Enviorment.AppDomain app)
s_System_Collections_Generic_KeyValuePair_2_UInt32_ILTypeInstance_Binding_Binder = null;
s_ILRuntimeTest_TestFramework_TestStructA_Binding_Binder = null;
s_ILRuntimeTest_TestFramework_TestStructB_Binding_Binder = null;
s_ILRuntimeTest_TestFramework_Fixed64_Binding_Binder = null;
s_ILRuntimeTest_TestFramework_Fixed64Vector2_Binding_Binder = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
args = new Type[]{};
method = type.GetMethod("TestEnumDelegate2", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, TestEnumDelegate2_7);
args = new Type[]{typeof(System.Action<System.Single, System.Double, System.Int32>)};
method = type.GetMethod("add_OnIntEvent", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, add_OnIntEvent_8);
args = new Type[]{typeof(System.Single), typeof(System.Double), typeof(System.Int32)};
method = type.GetMethod("TestEvent3", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, TestEvent3_9);
args = new Type[]{typeof(System.Action<System.Single, System.Double, System.Int32>)};
method = type.GetMethod("remove_OnIntEvent", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, remove_OnIntEvent_10);
args = new Type[]{};
method = type.GetMethod("TestEvent4", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, TestEvent4_11);

field = type.GetField("IntDelegateTest", flag);
app.RegisterCLRFieldGetter(field, get_IntDelegateTest_0);
Expand Down Expand Up @@ -202,6 +214,72 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
return __ret;
}

static StackObject* add_OnIntEvent_8(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 1);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Action<System.Single, System.Double, System.Int32> @value = (System.Action<System.Single, System.Double, System.Int32>)typeof(System.Action<System.Single, System.Double, System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)8);
__intp.Free(ptr_of_this_method);


ILRuntimeTest.TestFramework.DelegateTest.OnIntEvent += value;

return __ret;
}

static StackObject* TestEvent3_9(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 3);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Int32 @c = ptr_of_this_method->Value;

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Double @b = *(double*)&ptr_of_this_method->Value;

ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
System.Single @a = *(float*)&ptr_of_this_method->Value;


ILRuntimeTest.TestFramework.DelegateTest.TestEvent3(@a, @b, @c);

return __ret;
}

static StackObject* remove_OnIntEvent_10(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 1);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Action<System.Single, System.Double, System.Int32> @value = (System.Action<System.Single, System.Double, System.Int32>)typeof(System.Action<System.Single, System.Double, System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)8);
__intp.Free(ptr_of_this_method);


ILRuntimeTest.TestFramework.DelegateTest.OnIntEvent -= value;

return __ret;
}

static StackObject* TestEvent4_11(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* __ret = ILIntepreter.Minus(__esp, 0);


var result_of_this_method = ILRuntimeTest.TestFramework.DelegateTest.TestEvent4();

__ret->ObjectType = ObjectTypes.Integer;
__ret->Value = result_of_this_method ? 1 : 0;
return __ret + 1;
}


static object get_IntDelegateTest_0(ref object o)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
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;
#if DEBUG && !DISABLE_ILRUNTIME_DEBUG
using AutoList = System.Collections.Generic.List<object>;
#else
using AutoList = ILRuntime.Other.UncheckedList<object>;
#endif
namespace ILRuntime.Runtime.Generated
{
unsafe class ILRuntimeTest_TestFramework_Fixed64Vector2_Binding
{
public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
{
BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
MethodBase method;
FieldInfo field;
Type[] args;
Type type = typeof(ILRuntimeTest.TestFramework.Fixed64Vector2);

field = type.GetField("x", flag);
app.RegisterCLRFieldGetter(field, get_x_0);
app.RegisterCLRFieldSetter(field, set_x_0);
app.RegisterCLRFieldBinding(field, CopyToStack_x_0, AssignFromStack_x_0);

app.RegisterCLRMemberwiseClone(type, PerformMemberwiseClone);

app.RegisterCLRCreateDefaultInstance(type, () => new ILRuntimeTest.TestFramework.Fixed64Vector2());

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

}

static void WriteBackInstance(ILRuntime.Runtime.Enviorment.AppDomain __domain, StackObject* ptr_of_this_method, AutoList __mStack, ref ILRuntimeTest.TestFramework.Fixed64Vector2 instance_of_this_method)
{
ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
switch(ptr_of_this_method->ObjectType)
{
case ObjectTypes.Object:
{
__mStack[ptr_of_this_method->Value] = instance_of_this_method;
}
break;
case ObjectTypes.FieldReference:
{
var ___obj = __mStack[ptr_of_this_method->Value];
if(___obj is ILTypeInstance)
{
((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method;
}
else
{
var t = __domain.GetType(___obj.GetType()) as CLRType;
t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method);
}
}
break;
case ObjectTypes.StaticFieldReference:
{
var t = __domain.GetType(ptr_of_this_method->Value);
if(t is ILType)
{
((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method;
}
else
{
((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method);
}
}
break;
case ObjectTypes.ArrayReference:
{
var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as ILRuntimeTest.TestFramework.Fixed64Vector2[];
instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method;
}
break;
}
}


static object get_x_0(ref object o)
{
return ((ILRuntimeTest.TestFramework.Fixed64Vector2)o).x;
}

static StackObject* CopyToStack_x_0(ref object o, ILIntepreter __intp, StackObject* __ret, AutoList __mStack)
{
var result_of_this_method = ((ILRuntimeTest.TestFramework.Fixed64Vector2)o).x;
if (ILRuntime.Runtime.Generated.CLRBindings.s_ILRuntimeTest_TestFramework_Fixed64_Binding_Binder != null) {
ILRuntime.Runtime.Generated.CLRBindings.s_ILRuntimeTest_TestFramework_Fixed64_Binding_Binder.PushValue(ref result_of_this_method, __intp, __ret, __mStack);
return __ret + 1;
} else {
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}
}

static void set_x_0(ref object o, object v)
{
ILRuntimeTest.TestFramework.Fixed64Vector2 ins =(ILRuntimeTest.TestFramework.Fixed64Vector2)o;
ins.x = (ILRuntimeTest.TestFramework.Fixed64)v;
o = ins;
}

static StackObject* AssignFromStack_x_0(ref object o, ILIntepreter __intp, StackObject* ptr_of_this_method, AutoList __mStack)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
ILRuntimeTest.TestFramework.Fixed64 @x = new ILRuntimeTest.TestFramework.Fixed64();
if (ILRuntime.Runtime.Generated.CLRBindings.s_ILRuntimeTest_TestFramework_Fixed64_Binding_Binder != null) {
ILRuntime.Runtime.Generated.CLRBindings.s_ILRuntimeTest_TestFramework_Fixed64_Binding_Binder.ParseValue(ref @x, __intp, ptr_of_this_method, __mStack, true);
} else {
@x = (ILRuntimeTest.TestFramework.Fixed64)typeof(ILRuntimeTest.TestFramework.Fixed64).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags)16);
}
ILRuntimeTest.TestFramework.Fixed64Vector2 ins =(ILRuntimeTest.TestFramework.Fixed64Vector2)o;
ins.x = @x;
o = ins;
return ptr_of_this_method;
}


static object PerformMemberwiseClone(ref object o)
{
var ins = new ILRuntimeTest.TestFramework.Fixed64Vector2();
ins = (ILRuntimeTest.TestFramework.Fixed64Vector2)o;
return ins;
}

static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, AutoList __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.Int32 @y = ptr_of_this_method->Value;

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Int32 @x = ptr_of_this_method->Value;


var result_of_this_method = new ILRuntimeTest.TestFramework.Fixed64Vector2(@x, @y);

if(!isNewObj)
{
__ret--;
if (ILRuntime.Runtime.Generated.CLRBindings.s_ILRuntimeTest_TestFramework_Fixed64Vector2_Binding_Binder != null) {
ILRuntime.Runtime.Generated.CLRBindings.s_ILRuntimeTest_TestFramework_Fixed64Vector2_Binding_Binder.WriteBackValue(__domain, __ret, __mStack, ref result_of_this_method);
} else {
WriteBackInstance(__domain, __ret, __mStack, ref result_of_this_method);
}
return __ret;
}

if (ILRuntime.Runtime.Generated.CLRBindings.s_ILRuntimeTest_TestFramework_Fixed64Vector2_Binding_Binder != null) {
ILRuntime.Runtime.Generated.CLRBindings.s_ILRuntimeTest_TestFramework_Fixed64Vector2_Binding_Binder.PushValue(ref result_of_this_method, __intp, __ret, __mStack);
return __ret + 1;
} else {
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}
}


}
}
Loading

0 comments on commit b8cb257

Please sign in to comment.