Skip to content

Commit

Permalink
Refactor event keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Oct 7, 2022
1 parent c6715cc commit 7162f6b
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1997,24 +1997,7 @@ public object Run(ILMethod method, object instance, object[] p)
}
else if (ilm.IsEventAdd)
{
instance = null;
var dele = StackObject.ToObject(esp - 1, domain, mStack);
Free(esp - 1);
if (ilm.IsStatic)
{
instance = ((ILType)ilm.DeclearingType).StaticInstance;
objRef = esp - 1;
}
else
{
objRef = esp - 2;
instance = StackObject.ToObject(objRef, domain, mStack) as ILTypeInstance;
Free(objRef);
}
obj = instance[ilm.EventFieldIndex];

objRef = PushObject(objRef, mStack, obj);
objRef = PushObject(objRef, mStack, dele);
objRef = PrepareEventHandler(esp, ilm, mStack, out instance);

esp = CLRRedirections.DelegateCombine(this, objRef, mStack, null, false);
obj = StackObject.ToObject(esp - 1, domain, mStack);
Expand All @@ -2025,23 +2008,7 @@ public object Run(ILMethod method, object instance, object[] p)
}
else if (ilm.IsEventRemove)
{
instance = null;
var dele = StackObject.ToObject(esp - 1, domain, mStack);
Free(esp - 1);
if (ilm.IsStatic)
{
instance = ((ILType)ilm.DeclearingType).StaticInstance;
objRef = esp - 1;
}
else
{
objRef = esp - 2;
instance = StackObject.ToObject(objRef, domain, mStack) as ILTypeInstance;
Free(objRef);
}
obj = instance[ilm.EventFieldIndex];
objRef = PushObject(objRef, mStack, obj);
objRef = PushObject(objRef, mStack, dele);
objRef = PrepareEventHandler(esp, ilm, mStack, out instance);

esp = CLRRedirections.DelegateRemove(this, objRef, mStack, null, false);
obj = StackObject.ToObject(esp - 1, domain, mStack);
Expand Down Expand Up @@ -4713,6 +4680,30 @@ public object Run(ILMethod method, object instance, object[] p)
//ClearStack
return stack.PopFrame(ref frame, esp);
}

StackObject* PrepareEventHandler(StackObject* esp, ILMethod ilm, AutoList mStack, out ILTypeInstance instance)
{
instance = null;
StackObject* objRef;
var dele = StackObject.ToObject(esp - 1, domain, mStack);
Free(esp - 1);
if (ilm.IsStatic)
{
instance = ((ILType)ilm.DeclearingType).StaticInstance;
objRef = esp - 1;
}
else
{
objRef = esp - 2;
instance = StackObject.ToObject(objRef, domain, mStack) as ILTypeInstance;
Free(objRef);
}
var obj = instance[ilm.EventFieldIndex];

objRef = PushObject(objRef, mStack, obj);
objRef = PushObject(objRef, mStack, dele);
return objRef;
}
ExceptionHandler FindExceptionHandlerByBranchTarget(int addr, int branchTarget, ExceptionHandler[] ehs)
{
ExceptionHandler eh = null;
Expand Down

0 comments on commit 7162f6b

Please sign in to comment.