|
@@ -35,6 +35,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Func<TResult>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -99,7 +106,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Func<T1, TResult>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -167,7 +180,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Func<T1, T2, TResult>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -238,7 +257,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Func<T1, T2, T3, TResult>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -310,7 +335,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Func<T1, T2, T3, T4, TResult>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -380,6 +411,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Action<T1>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -444,7 +482,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Action<T1, T2>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -511,7 +555,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Action<T1, T2, T3>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -580,7 +630,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Action<T1, T2, T3, T4>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -652,7 +708,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Action<T1, T2, T3, T4, T5>);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -712,7 +774,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
action = InvokeILMethod;
|
|
action = InvokeILMethod;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ return typeof(Action);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -764,7 +832,13 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public override Type NativeDelegateType
|
|
|
|
|
+ {
|
|
|
|
|
+ get
|
|
|
|
|
+ {
|
|
|
|
|
+ throw new NotSupportedException();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public override Delegate Delegate
|
|
public override Delegate Delegate
|
|
|
{
|
|
{
|
|
|
get
|
|
get
|
|
@@ -817,6 +891,8 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
|
|
|
|
|
public abstract Delegate Delegate { get; }
|
|
public abstract Delegate Delegate { get; }
|
|
|
|
|
|
|
|
|
|
+ public abstract Type NativeDelegateType { get; }
|
|
|
|
|
+
|
|
|
public IDelegateAdapter Next { get { return next; } }
|
|
public IDelegateAdapter Next { get { return next; } }
|
|
|
|
|
|
|
|
public ILTypeInstance Instance { get { return instance; } }
|
|
public ILTypeInstance Instance { get { return instance; } }
|
|
@@ -863,6 +939,11 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
if (method.HasThis)
|
|
if (method.HasThis)
|
|
|
esp = ILIntepreter.PushObject(esp, mStack, instance);
|
|
esp = ILIntepreter.PushObject(esp, mStack, instance);
|
|
|
int paramCnt = method.ParameterCount;
|
|
int paramCnt = method.ParameterCount;
|
|
|
|
|
+ if (method.IsExtend)
|
|
|
|
|
+ {
|
|
|
|
|
+ esp = ILIntepreter.PushObject(esp, mStack, instance);
|
|
|
|
|
+ paramCnt--;
|
|
|
|
|
+ }
|
|
|
bool useRegister = method.ShouldUseRegisterVM;
|
|
bool useRegister = method.ShouldUseRegisterVM;
|
|
|
for (int i = paramCnt; i > 0; i--)
|
|
for (int i = paramCnt; i > 0; i--)
|
|
|
{
|
|
{
|
|
@@ -892,6 +973,10 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
unsafe StackObject* ClearStack(ILIntepreter intp, StackObject* esp, StackObject* ebp, IList<object> mStack)
|
|
unsafe StackObject* ClearStack(ILIntepreter intp, StackObject* esp, StackObject* ebp, IList<object> mStack)
|
|
|
{
|
|
{
|
|
|
int paramCnt = method.ParameterCount;
|
|
int paramCnt = method.ParameterCount;
|
|
|
|
|
+ if (method.IsExtend)//如果是拓展方法,退一位
|
|
|
|
|
+ {
|
|
|
|
|
+ paramCnt--;
|
|
|
|
|
+ }
|
|
|
object retObj = null;
|
|
object retObj = null;
|
|
|
StackObject retSObj = StackObject.Null;
|
|
StackObject retSObj = StackObject.Null;
|
|
|
bool hasReturn = method.ReturnType != appdomain.VoidType;
|
|
bool hasReturn = method.ReturnType != appdomain.VoidType;
|
|
@@ -1008,16 +1093,40 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
{
|
|
{
|
|
|
if (type.IsDelegate)
|
|
if (type.IsDelegate)
|
|
|
{
|
|
{
|
|
|
- var im = type.GetMethod("Invoke", method.ParameterCount);
|
|
|
|
|
|
|
+ var method_count = method.IsExtend ? method.ParameterCount - 1 : method.ParameterCount;
|
|
|
|
|
+ var im = type.GetMethod("Invoke", method_count);
|
|
|
|
|
+ if (im == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ var ret_type = im.ReturnType;
|
|
|
|
|
+ if (im.ReturnType != appdomain.VoidType && type.IsGenericInstance)
|
|
|
|
|
+ {
|
|
|
|
|
+ ret_type = type.GenericArguments[im.ParameterCount].Value;
|
|
|
|
|
+ }
|
|
|
if (im.IsDelegateInvoke)
|
|
if (im.IsDelegateInvoke)
|
|
|
{
|
|
{
|
|
|
- if (im.ParameterCount == method.ParameterCount && im.ReturnType == method.ReturnType)
|
|
|
|
|
|
|
+ if (im.ParameterCount == method_count && ret_type == method.ReturnType)
|
|
|
{
|
|
{
|
|
|
- for (int i = 0; i < im.ParameterCount; i++)
|
|
|
|
|
- {
|
|
|
|
|
- if (im.Parameters[i] != method.Parameters[i])
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < im.ParameterCount; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ var index = method.IsExtend ? i + 1 : i;
|
|
|
|
|
+ if (type.IsGenericInstance)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (method.Parameters[index] != type.GenericArguments[i].Value)
|
|
|
|
|
+ {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ if (im.Parameters[i] != method.Parameters[index])
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -1108,7 +1217,7 @@ namespace ILRuntime.Runtime.Intepreter
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
unsafe interface IDelegateAdapter
|
|
unsafe interface IDelegateAdapter
|
|
|
- {
|
|
|
|
|
|
|
+ { Type NativeDelegateType { get; }
|
|
|
Delegate Delegate { get; }
|
|
Delegate Delegate { get; }
|
|
|
IDelegateAdapter Next { get; }
|
|
IDelegateAdapter Next { get; }
|
|
|
ILTypeInstance Instance { get; }
|
|
ILTypeInstance Instance { get; }
|