Skip to content

Commit

Permalink
Merge pull request #1 from Ourpalm/master
Browse files Browse the repository at this point in the history
merge source
  • Loading branch information
linchenrr authored Feb 26, 2021
2 parents 7846c37 + 0539851 commit 8f16cc1
Show file tree
Hide file tree
Showing 16 changed files with 542 additions and 9 deletions.
10 changes: 10 additions & 0 deletions ILRuntime/Runtime/CLRBinding/BindingGeneratorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ internal static void AppendArgumentCode(this Type p, StringBuilder sb, int idx,
else
throw new NotSupportedException();
}
else if (p.GetElementType().IsEnum)
{
sb.AppendLine(string.Format(" {0} @{1} = ({0})__intp.RetriveInt32(ptr_of_this_method, __mStack);", realClsName, name));
}
else
{
sb.AppendLine(string.Format(" {0} @{1} = ({0})typeof({0}).CheckCLRTypes(__intp.RetriveObject(ptr_of_this_method, __mStack));", realClsName, name));
Expand Down Expand Up @@ -334,6 +338,12 @@ internal static void GetRefWriteBackValueCode(this Type type, StringBuilder sb,
else
throw new NotImplementedException();
}
else if(type.IsEnum)
{
sb.AppendLine(" ___dst->ObjectType = ObjectTypes.Integer;");
sb.Append(" ___dst->Value = (int)@" + paramName);
sb.AppendLine(";");
}
else
{
sb.Append(@" object ___obj = @");
Expand Down
26 changes: 26 additions & 0 deletions ILRuntime/Runtime/Intepreter/DelegateAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,32 @@ public override string ToString()
return method.ToString();
}

public override bool CanAssignTo(IType type)
{
if (type.IsDelegate)
{
var im = type.GetMethod("Invoke", method.ParameterCount);
if (im.IsDelegateInvoke)
{
if (im.ParameterCount == method.ParameterCount && im.ReturnType == method.ReturnType)
{
for (int i = 0; i < im.ParameterCount; i++)
{
if (im.Parameters[i] != method.Parameters[i])
return false;
}
return true;
}
else
return false;
}
else
return false;
}
else
return false;
}

public Delegate GetConvertor(Type type)
{
if (converters == null)
Expand Down
5 changes: 5 additions & 0 deletions ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5328,6 +5328,11 @@ public static void UnboxObject(StackObject* esp, object obj, IList<object> mStac
esp->ObjectType = ObjectTypes.Integer;
esp->Value = (sbyte)obj;
}
else if (obj is Enum)
{
esp->ObjectType = ObjectTypes.Integer;
esp->Value = Convert.ToInt32(obj);
}
else
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion ILRuntime/Runtime/Intepreter/ILTypeInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ public override int GetHashCode()
return base.GetHashCode();
}

public bool CanAssignTo(IType type)
public virtual bool CanAssignTo(IType type)
{
return this.type.CanAssignTo(type);
}
Expand Down
6 changes: 4 additions & 2 deletions ILRuntimeTest/AutoGenerate/CLRBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_Action_3_Int32_String_String_Binding.Register(app);
ILRuntimeTest_TestFramework_BaseClassTest_Binding.Register(app);
System_Action_1_String_Binding.Register(app);
System_Collections_Generic_List_1_Action_1_Int32_Binding.Register(app);
System_Collections_Generic_List_1_Func_2_Int32_Int32_Binding.Register(app);
System_Action_Binding.Register(app);
System_Math_Binding.Register(app);
ILRuntimeTest_TestFramework_TestStruct_Binding.Register(app);
ILRuntimeTest_TestFramework_TestClass3_Binding.Register(app);
System_Single_Binding.Register(app);
System_Byte_Binding.Register(app);
System_Char_Binding.Register(app);
System_Double_Binding.Register(app);
System_IO_File_Binding.Register(app);
System_IO_FileStream_Binding.Register(app);
System_IO_Stream_Binding.Register(app);
Expand All @@ -93,11 +96,11 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain 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);
ILRuntimeTest_TestFramework_TestCLREnumClass_Binding.Register(app);
System_Nullable_1_Int32_Binding.Register(app);
System_Collections_Generic_Dictionary_2_String_Int32_Binding_Enumerator_Binding.Register(app);
System_Collections_Generic_KeyValuePair_2_String_Int32_Binding.Register(app);
Expand Down Expand Up @@ -133,7 +136,6 @@ public static void Initialize(ILRuntime.Runtime.Enviorment.AppDomain app)
System_AccessViolationException_Binding.Register(app);
System_Func_1_TestVector3_Binding.Register(app);
System_Collections_Generic_Dictionary_2_Object_Object_Binding.Register(app);
ILRuntimeTest_TestFramework_TestCLREnumClass_Binding.Register(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
FieldInfo field;
Type[] args;
Type type = typeof(ILRuntimeTest.TestFramework.TestCLREnumClass);
args = new Type[]{typeof(System.UInt32).MakeByRefType(), typeof(ILRuntimeTest.TestFramework.TestCLREnum).MakeByRefType()};
method = type.GetMethod("TestCLREnumRef", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, TestCLREnumRef_0);
args = new Type[]{};
method = type.GetMethod("get_Test2", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Test2_0);
app.RegisterCLRMethodRedirection(method, get_Test2_1);

field = type.GetField("Test", flag);
app.RegisterCLRFieldGetter(field, get_Test_0);
Expand All @@ -36,7 +39,117 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
}


static StackObject* get_Test2_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
static StackObject* TestCLREnumRef_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.TestCLREnum @tag = (ILRuntimeTest.TestFramework.TestCLREnum)__intp.RetriveInt32(ptr_of_this_method, __mStack);

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.UInt32 @key = (System.UInt32)__intp.RetriveInt32(ptr_of_this_method, __mStack);


ILRuntimeTest.TestFramework.TestCLREnumClass.TestCLREnumRef(out @key, out @tag);

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);
___dst->ObjectType = ObjectTypes.Integer;
___dst->Value = (int)@tag;
}
break;
case ObjectTypes.FieldReference:
{
var ___obj = __mStack[ptr_of_this_method->Value];
if(___obj is ILTypeInstance)
{
((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = @tag;
}
else
{
var ___type = __domain.GetType(___obj.GetType()) as CLRType;
___type.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, @tag);
}
}
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] = @tag;
}
else
{
((CLRType)___type).SetStaticFieldValue(ptr_of_this_method->ValueLow, @tag);
}
}
break;
case ObjectTypes.ArrayReference:
{
var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as ILRuntimeTest.TestFramework.TestCLREnum[];
instance_of_arrayReference[ptr_of_this_method->ValueLow] = @tag;
}
break;
}

__intp.Free(ptr_of_this_method);
ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
switch(ptr_of_this_method->ObjectType)
{
case ObjectTypes.StackObjectReference:
{
var ___dst = ILIntepreter.ResolveReference(ptr_of_this_method);
___dst->ObjectType = ObjectTypes.Integer;
___dst->Value = (int)@key;
}
break;
case ObjectTypes.FieldReference:
{
var ___obj = __mStack[ptr_of_this_method->Value];
if(___obj is ILTypeInstance)
{
((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = @key;
}
else
{
var ___type = __domain.GetType(___obj.GetType()) as CLRType;
___type.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, @key);
}
}
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] = @key;
}
else
{
((CLRType)___type).SetStaticFieldValue(ptr_of_this_method->ValueLow, @key);
}
}
break;
case ObjectTypes.ArrayReference:
{
var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as System.UInt32[];
instance_of_arrayReference[ptr_of_this_method->ValueLow] = @key;
}
break;
}

__intp.Free(ptr_of_this_method);
return __ret;
}

static StackObject* get_Test2_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* __ret = ILIntepreter.Minus(__esp, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
args = new Type[]{};
method = type.GetMethod("get_LoadedTypes", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_LoadedTypes_0);
args = new Type[]{};
method = type.GetMethod("GetCurrentStackTrace", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, GetCurrentStackTrace_1);


}
Expand All @@ -45,6 +48,21 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}

static StackObject* GetCurrentStackTrace_1(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, 1);

ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
ILRuntime.Runtime.Enviorment.AppDomain instance_of_this_method = (ILRuntime.Runtime.Enviorment.AppDomain)typeof(ILRuntime.Runtime.Enviorment.AppDomain).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);

var result_of_this_method = instance_of_this_method.GetCurrentStackTrace();

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



}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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 System_Collections_Generic_List_1_Action_1_Int32_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(System.Collections.Generic.List<System.Action<System.Int32>>);
args = new Type[]{typeof(System.Action<System.Int32>)};
method = type.GetMethod("Add", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Add_0);
args = new Type[]{typeof(System.Int32)};
method = type.GetMethod("get_Item", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Item_1);

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

}


static StackObject* Add_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);
System.Action<System.Int32> @item = (System.Action<System.Int32>)typeof(System.Action<System.Int32>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Collections.Generic.List<System.Action<System.Int32>> instance_of_this_method = (System.Collections.Generic.List<System.Action<System.Int32>>)typeof(System.Collections.Generic.List<System.Action<System.Int32>>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);

instance_of_this_method.Add(@item);

return __ret;
}

static StackObject* get_Item_1(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.Int32 @index = ptr_of_this_method->Value;

ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Collections.Generic.List<System.Action<System.Int32>> instance_of_this_method = (System.Collections.Generic.List<System.Action<System.Int32>>)typeof(System.Collections.Generic.List<System.Action<System.Int32>>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);

var result_of_this_method = instance_of_this_method[index];

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


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 System.Collections.Generic.List<System.Action<System.Int32>>();

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


}
}
Loading

0 comments on commit 8f16cc1

Please sign in to comment.